From b600b0b6ee42b588d04c40f71228ad9811784bc3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 2 Feb 2015 22:58:39 -0600 Subject: [PATCH] FS-7508: add avg duration into codec --- src/mod/codecs/mod_vpx/mod_vpx.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/mod/codecs/mod_vpx/mod_vpx.c b/src/mod/codecs/mod_vpx/mod_vpx.c index 3bfa7ba59c..92cc84f458 100644 --- a/src/mod/codecs/mod_vpx/mod_vpx.c +++ b/src/mod/codecs/mod_vpx/mod_vpx.c @@ -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); }