summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2014-02-14 12:39:06 +0100
committerSebastian Dröge <sebastian@centricular.com>2014-02-14 12:51:50 +0100
commit5b23cf694cccbfd7a5e13083b09274b8fd3bc6ce (patch)
tree39be860849b76a780ec8195826b113e45e97fda6 /sys
parentaeeeedd7c7bd11f05d3e79464c06dff54b1c7563 (diff)
downloadgstreamer-plugins-bad-5b23cf694cccbfd7a5e13083b09274b8fd3bc6ce.tar.gz
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.
Diffstat (limited to 'sys')
-rw-r--r--sys/androidmedia/gstamcaudiodec.c37
-rw-r--r--sys/androidmedia/gstamcaudiodec.h1
2 files changed, 33 insertions, 5 deletions
diff --git a/sys/androidmedia/gstamcaudiodec.c b/sys/androidmedia/gstamcaudiodec.c
index e8526752f..f8649e896 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 ee5218190..50500a862 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;