Currently, in gst-plugins-good/gst/rtpmanager/rtpsource.c, bitrate is estimated on the sender side. Would it be possible to estimate this on the receiver side? It would be delta "octets-received" over a given running time. I've tried to do it in my application but I have a health discrepancy between my estimation and that on the sender side (about 90000 bits less in mine). I get the stats every two seconds with the "get-internal-session" signal. Here's my code, which parses a source's rtp stats and tries to estimate the bitrate:

    const GValue *val = gst_structure_get_value(stats, "internal");
    if (g_value_get_boolean(val))   // is-internal
    GTimeVal currentTime;
    g_get_current_time (&currentTime);
    static GTimeVal previousTime = currentTime;
    guint64 elapsed = currentTime.tv_sec - previousTime.tv_sec;

    if (elapsed > 0)
        // in case we're not getting this in our receiver reports for a while (i.e. sender died)
        if (G_VALUE_HOLDS_UINT64(gst_structure_get_value(stats, "octets-received")))
            guint octets = g_value_get_uint64(gst_structure_get_value(stats, "octets-received"));
            static guint previousOctets = octets;
            guint diffOctets = octets - previousOctets;
            //LOG_INFO("Diff octets " << diffOctets);

            enum {BITS_PER_BYTE = 8};
            guint64 bitrate = BITS_PER_BYTE * (diffOctets / elapsed);

            LOG_INFO(sessionName_ << ":BITRATE:" << bitrate);
            previousOctets = octets;
    previousTime = currentTime;

One difference I noticed is that in the rtpsource.c code, the clocktime is determined from the running time passed to the function, not with g_get_current_time. Should i be calculating the time from my pipeline instead? Any other tips?

Tristan Matthews
email: tristan@sat.qc.ca
web: http://tristanswork.blogspot.com