]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7508: add avg duration into codec
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 3 Feb 2015 04:58:39 +0000 (22:58 -0600)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:46:57 +0000 (12:46 -0500)
src/mod/codecs/mod_vpx/mod_vpx.c

index 3bfa7ba59cd8533a67e6d9d0694544fb9cd478be..92cc84f458c268c8a081041a6eb8f32b4bd23a33 100644 (file)
@@ -76,6 +76,8 @@ struct vpx_context {
        switch_size_t last_received_timestamp;
        switch_bool_t last_received_complete_picture;
        int need_key_frame;
+       uint64_t framecount;
+       uint64_t framesum;
 };
 typedef struct vpx_context vpx_context_t;
 
@@ -374,7 +376,7 @@ static switch_status_t switch_vpx_encode(switch_codec_t *codec, switch_frame_t *
        int width = 0;
        int height = 0;
        vpx_enc_frame_flags_t vpx_flags = 0;
-       int32_t dur = 0;
+       int32_t diff = 0, dur = 0;
 
        if (frame->flags & SFF_SAME_IMAGE) {
                return consume_partition(context, frame);
@@ -419,18 +421,27 @@ static switch_status_t switch_vpx_encode(switch_codec_t *codec, switch_frame_t *
                }
        }
 
+       context->framecount++;
+
        if (context->last_ts) {
-               dur = frame->timestamp - context->last_ts;
-               if (dur < 0 || dur > 90000) {
-                       dur = 0;
+               diff = frame->timestamp - context->last_ts;
+               
+               if (diff < 0 || diff > 90000) {
+                       diff = 0;
                }
        }
 
 
-       if (!dur) {
-               dur = 1;
+       
+       if (diff) {
+               context->framesum += diff;
        }
 
+       if (context->framesum && context->framecount) {
+               dur = context->framesum / context->framecount;
+       } else {
+               dur = 1;
+       }
 
        if (vpx_codec_encode(&context->encoder, (vpx_image_t *) frame->img, frame->timestamp, dur, vpx_flags, VPX_DL_REALTIME) != VPX_CODEC_OK) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "VP8 encode error %d:%s\n",
@@ -443,6 +454,7 @@ static switch_status_t switch_vpx_encode(switch_codec_t *codec, switch_frame_t *
        context->iter = NULL;
        context->last_ts = frame->timestamp;
 
+               
        return consume_partition(context, frame);
 }