From 5b23cf694cccbfd7a5e13083b09274b8fd3bc6ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 14 Feb 2014 12:39:06 +0100 Subject: [PATCH] amcaudiodec: Calculate number of samples per frame for MP3 and use that Some audio decoders (at least the MP3 decoder on MTK based devices) outputs raw audio in batches of multiple audio frames. We need to handle that properly, otherwise the base class will be kind of unhappy. --- sys/androidmedia/gstamcaudiodec.c | 37 ++++++++++++++++++++++++++----- sys/androidmedia/gstamcaudiodec.h | 1 + 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/sys/androidmedia/gstamcaudiodec.c b/sys/androidmedia/gstamcaudiodec.c index e8526752f4..f8649e8960 100644 --- a/sys/androidmedia/gstamcaudiodec.c +++ b/sys/androidmedia/gstamcaudiodec.c @@ -612,6 +612,7 @@ retry: GstBuffer *outbuf; GstAmcBuffer *buf; GstMapInfo minfo; + gint nframes; /* This sometimes happens at EOS or if the input is not properly framed, * let's handle it gracefully by allocating a new buffer for the current @@ -661,12 +662,18 @@ retry: } gst_buffer_unmap (outbuf, &minfo); - /* FIXME: We should get one decoded input frame here for - * every buffer. If this is not the case somewhere, we will - * error out at some point and will need to add workarounds - */ + nframes = 1; + if (self->spf != -1) { + nframes = buffer_info.size / self->info.bpf; + if (nframes % self->spf != 0) + GST_WARNING_OBJECT (self, "Output buffer does not contain an integer " + "number of input frames (frames: %d, spf: %d)", nframes, self->spf); + nframes = (nframes + self->spf - 1) / self->spf; + } + flow_ret = - gst_audio_decoder_finish_frame (GST_AUDIO_DECODER (self), outbuf, 1); + gst_audio_decoder_finish_frame (GST_AUDIO_DECODER (self), outbuf, + nframes); } done: @@ -1008,6 +1015,26 @@ gst_amc_audio_dec_set_format (GstAudioDecoder * decoder, GstCaps * caps) return FALSE; } + self->spf = -1; + /* TODO: Implement for other codecs too */ + if (gst_structure_has_name (s, "audio/mpeg")) { + gint mpegversion = -1; + + gst_structure_get_int (s, "mpegversion", &mpegversion); + if (mpegversion == 1) { + gint layer = -1, mpegaudioversion = -1; + + gst_structure_get_int (s, "layer", &layer); + gst_structure_get_int (s, "mpegaudioversion", &mpegaudioversion); + if (layer == 1) + self->spf = 384; + else if (layer == 2) + self->spf = 1152; + else if (layer == 3 && mpegaudioversion != -1) + self->spf = (mpegaudioversion == 1 ? 1152 : 576); + } + } + self->started = TRUE; self->input_caps_changed = TRUE; diff --git a/sys/androidmedia/gstamcaudiodec.h b/sys/androidmedia/gstamcaudiodec.h index ee52181900..50500a862c 100644 --- a/sys/androidmedia/gstamcaudiodec.h +++ b/sys/androidmedia/gstamcaudiodec.h @@ -57,6 +57,7 @@ struct _GstAmcAudioDec GstCaps *input_caps; GList *codec_datas; gboolean input_caps_changed; + gint spf; /* Output format of the codec */ GstAudioInfo info;