From 599401a7f9d0f4fb59ba0cc2d3717dd0b863f132 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Thu, 25 Mar 2010 11:48:46 +0000 Subject: [PATCH] aacparse: Fix bitrate calculation This patch adds the get_frame_overhead() vfunc so that baseparse can accurately calculate the min/avg/max bitrates for aacparse. Note: The bitrate was being incorrectly calculated for ADTS streams (it's not in the header as the code suggests). --- gst/audioparsers/gstaacparse.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/gst/audioparsers/gstaacparse.c b/gst/audioparsers/gstaacparse.c index d5a72d5..c1012ba 100644 --- a/gst/audioparsers/gstaacparse.c +++ b/gst/audioparsers/gstaacparse.c @@ -97,6 +97,8 @@ gboolean gst_aacparse_convert (GstBaseParse * parse, gboolean gst_aacparse_is_seekable (GstBaseParse * parse); +gint gst_aacparse_get_frame_overhead (GstBaseParse * parse, GstBuffer * buffer); + gboolean gst_aacparse_event (GstBaseParse * parse, GstEvent * event); #define _do_init(bla) \ @@ -160,6 +162,8 @@ gst_aacparse_class_init (GstAacParseClass * klass) parse_class->parse_frame = GST_DEBUG_FUNCPTR (gst_aacparse_parse_frame); parse_class->check_valid_frame = GST_DEBUG_FUNCPTR (gst_aacparse_check_valid_frame); + parse_class->get_frame_overhead = + GST_DEBUG_FUNCPTR (gst_aacparse_get_frame_overhead); } @@ -462,14 +466,12 @@ gst_aacparse_detect_stream (GstAacParse * aacparse, aacparse->mpegversion = (data[1] & 0x08) ? 2 : 4; aacparse->object_type = (data[2] & 0xc0) >> 6; aacparse->channels = ((data[2] & 0x01) << 2) | ((data[3] & 0xc0) >> 6); - aacparse->bitrate = ((data[5] & 0x1f) << 6) | ((data[6] & 0xfc) >> 2); gst_base_parse_set_frame_props (GST_BASE_PARSE (aacparse), aacparse->sample_rate, 1024, 50); - GST_DEBUG ("ADTS: samplerate %d, channels %d, bitrate %d, objtype %d", - aacparse->sample_rate, aacparse->channels, aacparse->bitrate, - aacparse->object_type); + GST_DEBUG ("ADTS: samplerate %d, channels %d, objtype %d", + aacparse->sample_rate, aacparse->channels, aacparse->object_type); return TRUE; } else if (need_data) { @@ -706,3 +708,32 @@ gst_aacparse_is_seekable (GstBaseParse * parse) /* Not seekable if ADIF header is found */ return (aacparse->header_type != DSPAAC_HEADER_ADIF); } + +/** + * gst_aacparse_get_frame_overhead: + * @parse: #GstBaseParse. + * @buffer: #GstBuffer. + * + * Implementation of "get_frame_overhead" vmethod in #GstBaseParse class. ADTS + * streams have a 7 byte header in each frame. MP4 and ADIF streams don't have + * a per-frame header. + * + * We're making a couple of simplifying assumptions: + * + * 1. We count Program Configuration Elements rather than searching for them + * in the streams to discount them - the overhead is negligible. + * + * 2. We ignore CRC. This has a worst-case impact of (num_raw_blocks + 1)*16 + * bits, which should still not be significant enough to warrant the + * additional parsing through the headers + */ +gint +gst_aacparse_get_frame_overhead (GstBaseParse * parse, GstBuffer * buffer) +{ + GstAacParse *aacparse = GST_AACPARSE (parse); + + if (aacparse->header_type == DSPAAC_HEADER_ADTS) + return 7; + else + return 0; +} -- 2.7.4