Skip to content

Commit

Permalink
Add video width and height to the incoming stream track stats
Browse files Browse the repository at this point in the history
  • Loading branch information
murillo128 committed May 12, 2023
1 parent 7e4654d commit b314638
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/IncomingStreamTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ function getStatsFromIncomingSource(source)
frameCaptureDelayMax : source.frameCaptureDelayMax,
layers : [],
};

//Check if we have width and height
if (source.width && source.height)
{
stats.width = source.width;
stats.height = source.height;
}

//Get layers
const layers = source.layers();
Expand Down Expand Up @@ -236,6 +243,8 @@ class IncomingStreamTrack extends Emitter
* - frameDelayMax : Max frame delay during the last second
* - frameCaptureDelay : Average bewtween local reception time and sender capture one (Absolute capture time must be negotiated)
* - frameCaptureDelayMax : Max bewtween local reception time and sender capture one (Absolute capture time must be negotiated)
* - width : video width
* - height : video height
* - layers : Information about each spatial/temporal layer (if present)
* * spatialLayerId : Spatial layer id
* * temporalLayerId : Temporatl layer id
Expand Down Expand Up @@ -285,6 +294,13 @@ class IncomingStreamTrack extends Emitter
this.stats[encoding.id].numPacketsDelta = this.stats[encoding.id].media.numPacketsDelta + this.stats[encoding.id].rtx.numPacketsDelta;
this.stats[encoding.id].lostPacketsRatio= this.stats[encoding.id].numPackets? this.stats[encoding.id].lostPackets / this.stats[encoding.id].numPackets : 0;
this.stats[encoding.id].remb = encoding.remoteBitrateEstimation;
//If we have dimenstions
if (this.stats[encoding.id].media.width && this.stats[encoding.id].media.height)
{
//set it on encoding
this.stats[encoding.id].width = this.stats[encoding.id].media.width;
this.stats[encoding.id].height = this.stats[encoding.id].media.height;
}
//Add timestamps
this.stats[encoding.id].timestamp = Date.now();

Expand Down Expand Up @@ -343,6 +359,14 @@ class IncomingStreamTrack extends Emitter
bitrate : stats[id].bitrate,
layers : []
};

//Check if we have width and height
if (stats[id].media.width && stats[id].media.height)
{
//Set them
encoding.width = stats[id].width;
encoding.height = stats[id].height;
}

//Get layers
const layers = stats[id].media.layers;
Expand Down
3 changes: 3 additions & 0 deletions src/RTPIncomingSource.i
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ struct RTPIncomingSource : public RTPSource
int64_t skew;
double drift;
bool aggregatedLayers;

uint16_t width;
uint16_t height;

%extend
{
Expand Down
121 changes: 121 additions & 0 deletions src/media-server_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2422,6 +2422,13 @@ SWIGV8_VALUE SWIG_From_double (double val)
return SWIGV8_NUMBER_NEW(val);
}


SWIGINTERNINLINE SWIGV8_VALUE
SWIG_From_unsigned_SS_short (unsigned short value)
{
return SWIG_From_unsigned_SS_long (value);
}

SWIGINTERN LayerSources RTPIncomingSource_layers__SWIG(RTPIncomingSource *self){
LayerSources layers;
for(auto it = self->layers.begin(); it != self->layers.end(); ++it )
Expand Down Expand Up @@ -8756,6 +8763,118 @@ static SwigV8ReturnValue _wrap_RTPIncomingSource_aggregatedLayers_get(v8::Local<
}


static void _wrap_RTPIncomingSource_width_set(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid &info) {
SWIGV8_HANDLESCOPE();

RTPIncomingSource *arg1 = (RTPIncomingSource *) 0 ;
uint16_t arg2 ;
void *argp1 = 0 ;
int res1 = 0 ;
unsigned short val2 ;
int ecode2 = 0 ;

res1 = SWIG_ConvertPtr(info.Holder(), &argp1,SWIGTYPE_p_RTPIncomingSource, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "RTPIncomingSource_width_set" "', argument " "1"" of type '" "RTPIncomingSource *""'");
}
arg1 = reinterpret_cast< RTPIncomingSource * >(argp1);
ecode2 = SWIG_AsVal_unsigned_SS_short(value, &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "RTPIncomingSource_width_set" "', argument " "2"" of type '" "uint16_t""'");
}
arg2 = static_cast< uint16_t >(val2);
if (arg1) (arg1)->width = arg2;



goto fail;
fail:
return;
}


static SwigV8ReturnValue _wrap_RTPIncomingSource_width_get(v8::Local<v8::Name> property, const SwigV8PropertyCallbackInfo &info) {
SWIGV8_HANDLESCOPE();

SWIGV8_VALUE jsresult;
RTPIncomingSource *arg1 = (RTPIncomingSource *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
uint16_t result;

res1 = SWIG_ConvertPtr(info.Holder(), &argp1,SWIGTYPE_p_RTPIncomingSource, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "RTPIncomingSource_width_get" "', argument " "1"" of type '" "RTPIncomingSource *""'");
}
arg1 = reinterpret_cast< RTPIncomingSource * >(argp1);
result = (uint16_t) ((arg1)->width);
jsresult = SWIG_From_unsigned_SS_short(static_cast< unsigned short >(result));


SWIGV8_RETURN_INFO(jsresult, info);

goto fail;
fail:
SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info);
}


static void _wrap_RTPIncomingSource_height_set(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid &info) {
SWIGV8_HANDLESCOPE();

RTPIncomingSource *arg1 = (RTPIncomingSource *) 0 ;
uint16_t arg2 ;
void *argp1 = 0 ;
int res1 = 0 ;
unsigned short val2 ;
int ecode2 = 0 ;

res1 = SWIG_ConvertPtr(info.Holder(), &argp1,SWIGTYPE_p_RTPIncomingSource, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "RTPIncomingSource_height_set" "', argument " "1"" of type '" "RTPIncomingSource *""'");
}
arg1 = reinterpret_cast< RTPIncomingSource * >(argp1);
ecode2 = SWIG_AsVal_unsigned_SS_short(value, &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "RTPIncomingSource_height_set" "', argument " "2"" of type '" "uint16_t""'");
}
arg2 = static_cast< uint16_t >(val2);
if (arg1) (arg1)->height = arg2;



goto fail;
fail:
return;
}


static SwigV8ReturnValue _wrap_RTPIncomingSource_height_get(v8::Local<v8::Name> property, const SwigV8PropertyCallbackInfo &info) {
SWIGV8_HANDLESCOPE();

SWIGV8_VALUE jsresult;
RTPIncomingSource *arg1 = (RTPIncomingSource *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
uint16_t result;

res1 = SWIG_ConvertPtr(info.Holder(), &argp1,SWIGTYPE_p_RTPIncomingSource, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "RTPIncomingSource_height_get" "', argument " "1"" of type '" "RTPIncomingSource *""'");
}
arg1 = reinterpret_cast< RTPIncomingSource * >(argp1);
result = (uint16_t) ((arg1)->height);
jsresult = SWIG_From_unsigned_SS_short(static_cast< unsigned short >(result));


SWIGV8_RETURN_INFO(jsresult, info);

goto fail;
fail:
SWIGV8_RETURN_INFO(SWIGV8_UNDEFINED(), info);
}


static SwigV8ReturnValue _wrap_RTPIncomingSource_layers(const SwigV8Arguments &args) {
SWIGV8_HANDLESCOPE();

Expand Down Expand Up @@ -17407,6 +17526,8 @@ SWIGV8_AddMemberVariable(_exports_RTPIncomingSource_class, "frameCaptureDelayMax
SWIGV8_AddMemberVariable(_exports_RTPIncomingSource_class, "skew", _wrap_RTPIncomingSource_skew_get, _wrap_RTPIncomingSource_skew_set);
SWIGV8_AddMemberVariable(_exports_RTPIncomingSource_class, "drift", _wrap_RTPIncomingSource_drift_get, _wrap_RTPIncomingSource_drift_set);
SWIGV8_AddMemberVariable(_exports_RTPIncomingSource_class, "aggregatedLayers", _wrap_RTPIncomingSource_aggregatedLayers_get, _wrap_RTPIncomingSource_aggregatedLayers_set);
SWIGV8_AddMemberVariable(_exports_RTPIncomingSource_class, "width", _wrap_RTPIncomingSource_width_get, _wrap_RTPIncomingSource_width_set);
SWIGV8_AddMemberVariable(_exports_RTPIncomingSource_class, "height", _wrap_RTPIncomingSource_height_get, _wrap_RTPIncomingSource_height_set);
SWIGV8_AddMemberFunction(_exports_RTPIncomingSource_class, "layers", _wrap_RTPIncomingSource_layers);
SWIGV8_AddMemberVariable(_exports_RTPIncomingSourceGroup_class, "rid", _wrap_RTPIncomingSourceGroup_rid_get, _wrap_RTPIncomingSourceGroup_rid_set);
SWIGV8_AddMemberVariable(_exports_RTPIncomingSourceGroup_class, "mid", _wrap_RTPIncomingSourceGroup_mid_get, _wrap_RTPIncomingSourceGroup_mid_set);
Expand Down

0 comments on commit b314638

Please sign in to comment.