From fb4673cde9955b9c3c94efb9db79ecfd4141986f Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Thu, 25 Mar 2010 12:55:02 +0000 Subject: [PATCH] flacparse: Make bitrate estimation more accurate This implements the get_frame_overhead() vfunc so that baseparse can make more accurate bitrate estimates. --- gst/audioparsers/gstflacparse.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gst/audioparsers/gstflacparse.c b/gst/audioparsers/gstflacparse.c index 4e2fe53496..0c8aa904c5 100644 --- a/gst/audioparsers/gstflacparse.c +++ b/gst/audioparsers/gstflacparse.c @@ -86,6 +86,8 @@ static gboolean gst_flac_parse_check_valid_frame (GstBaseParse * parse, GstBuffer * buffer, guint * framesize, gint * skipsize); static GstFlowReturn gst_flac_parse_parse_frame (GstBaseParse * parse, GstBuffer * buffer); +static gint gst_flac_parse_get_frame_overhead (GstBaseParse * parse, + GstBuffer * buffer); GST_BOILERPLATE (GstFlacParse, gst_flac_parse, GstBaseParse, GST_TYPE_BASE_PARSE); @@ -122,6 +124,8 @@ gst_flac_parse_class_init (GstFlacParseClass * klass) baseparse_class->check_valid_frame = GST_DEBUG_FUNCPTR (gst_flac_parse_check_valid_frame); baseparse_class->parse_frame = GST_DEBUG_FUNCPTR (gst_flac_parse_parse_frame); + baseparse_class->get_frame_overhead = + GST_DEBUG_FUNCPTR (gst_flac_parse_get_frame_overhead); } static void @@ -1288,3 +1292,17 @@ gst_flac_parse_parse_frame (GstBaseParse * parse, GstBuffer * buffer) return GST_FLOW_OK; } } + +static gint +gst_flac_parse_get_frame_overhead (GstBaseParse * parse, GstBuffer * buffer) +{ + GstFlacParse *flacparse = GST_FLAC_PARSE (parse); + + if (flacparse->state != GST_FLAC_PARSE_STATE_DATA) + return -1; + else + /* To simplify, we just assume that it's a fixed size header and ignore + * subframe headers. The first could lead us to being off by 88 bits and + * the second even less, so the total inaccuracy is negligible. */ + return 7; +}