aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandra Hájková <alexandra.khirnova@gmail.com>2015-09-15 13:11:32 +0200
committerLuca Barbato <lu_zero@gentoo.org>2015-09-16 20:21:07 +0200
commit971177f751a6e2931232accceab438bce277bde8 (patch)
treed7ba7d64c32d38cab1f53facf43dea166b8c5673
parent22cc57da64bfd73f2206969486b0aa183ee76479 (diff)
downloadffmpeg-971177f751a6e2931232accceab438bce277bde8.tar.gz
dcadec: scan for extensions in a separate function
to make dca_decode_frame more readable Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
-rw-r--r--libavcodec/dcadec.c114
1 files changed, 62 insertions, 52 deletions
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index abf762d906..bc0b23683a 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -1142,60 +1142,10 @@ static float dca_dmix_code(unsigned code)
return ((ff_dca_dmixtable[code] ^ sign) - sign) * (1.0 / (1U << 15));
}
-/**
- * Main frame decoding function
- * FIXME add arguments
- */
-static int dca_decode_frame(AVCodecContext *avctx, void *data,
- int *got_frame_ptr, AVPacket *avpkt)
+static int scan_for_extensions(AVCodecContext *avctx)
{
- AVFrame *frame = data;
- const uint8_t *buf = avpkt->data;
- int buf_size = avpkt->size;
-
- int lfe_samples;
- int num_core_channels = 0;
- int i, ret;
- float **samples_flt;
DCAContext *s = avctx->priv_data;
- int channels, full_channels;
- int core_ss_end;
- int upsample = 0;
-
- s->exss_ext_mask = 0;
- s->xch_present = 0;
-
- s->dca_buffer_size = ff_dca_convert_bitstream(buf, buf_size, s->dca_buffer,
- DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE);
- if (s->dca_buffer_size == AVERROR_INVALIDDATA) {
- av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
- return AVERROR_INVALIDDATA;
- }
-
- if ((ret = dca_parse_frame_header(s)) < 0) {
- // seems like the frame is corrupt, try with the next one
- return ret;
- }
- // set AVCodec values with parsed data
- avctx->sample_rate = s->sample_rate;
- avctx->bit_rate = s->bit_rate;
-
- s->profile = FF_PROFILE_DTS;
-
- for (i = 0; i < (s->sample_blocks / 8); i++) {
- if ((ret = dca_decode_block(s, 0, i))) {
- av_log(avctx, AV_LOG_ERROR, "error decoding block\n");
- return ret;
- }
- }
-
- /* record number of core channels incase less than max channels are requested */
- num_core_channels = s->prim_channels;
-
- if (s->ext_coding)
- s->core_ext_mask = dca_ext_audio_descr_mask[s->ext_descr];
- else
- s->core_ext_mask = 0;
+ int core_ss_end, ret;
core_ss_end = FFMIN(s->frame_size, s->dca_buffer_size) * 8;
@@ -1211,6 +1161,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data,
while (core_ss_end - get_bits_count(&s->gb) >= 32) {
uint32_t bits = get_bits_long(&s->gb, 32);
+ int i;
switch (bits) {
case DCA_SYNCWORD_XCH: {
@@ -1290,6 +1241,65 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data,
get_bits_long(&s->gb, 32) == DCA_SYNCWORD_SUBSTREAM)
ff_dca_exss_parse_header(s);
+ return ret;
+}
+
+/**
+ * Main frame decoding function
+ * FIXME add arguments
+ */
+static int dca_decode_frame(AVCodecContext *avctx, void *data,
+ int *got_frame_ptr, AVPacket *avpkt)
+{
+ AVFrame *frame = data;
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+
+ int lfe_samples;
+ int num_core_channels = 0;
+ int i, ret;
+ float **samples_flt;
+ DCAContext *s = avctx->priv_data;
+ int channels, full_channels;
+ int upsample = 0;
+
+ s->exss_ext_mask = 0;
+ s->xch_present = 0;
+
+ s->dca_buffer_size = ff_dca_convert_bitstream(buf, buf_size, s->dca_buffer,
+ DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE);
+ if (s->dca_buffer_size == AVERROR_INVALIDDATA) {
+ av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if ((ret = dca_parse_frame_header(s)) < 0) {
+ // seems like the frame is corrupt, try with the next one
+ return ret;
+ }
+ // set AVCodec values with parsed data
+ avctx->sample_rate = s->sample_rate;
+ avctx->bit_rate = s->bit_rate;
+
+ s->profile = FF_PROFILE_DTS;
+
+ for (i = 0; i < (s->sample_blocks / 8); i++) {
+ if ((ret = dca_decode_block(s, 0, i))) {
+ av_log(avctx, AV_LOG_ERROR, "error decoding block\n");
+ return ret;
+ }
+ }
+
+ /* record number of core channels incase less than max channels are requested */
+ num_core_channels = s->prim_channels;
+
+ if (s->ext_coding)
+ s->core_ext_mask = dca_ext_audio_descr_mask[s->ext_descr];
+ else
+ s->core_ext_mask = 0;
+
+ ret = scan_for_extensions(avctx);
+
avctx->profile = s->profile;
full_channels = channels = s->prim_channels + !!s->lfe;