[FFmpeg-devel] [PATCH 1/3] refactor the actual aac decoding code into its own function
Janne Grunau
janne-ffmpeg
Mon Oct 18 19:37:13 CEST 2010
aac_decode_frame() remains as AVPacket handling a wrapper. The actual
decoding function takes a GetBitContext as input and will be used be the
AAC LATM decoder to avoid copying the unaligned AAC bitstream.
---
libavcodec/aacdec.c | 60 +++++++++++++++++++++++++++++++-------------------
libavcodec/aacdec.h | 35 +++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 23 deletions(-)
create mode 100644 libavcodec/aacdec.h
diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c
index 6138dac..4306483 100644
--- a/libavcodec/aacdec.c
+++ b/libavcodec/aacdec.c
@@ -84,6 +84,7 @@
#include "lpc.h"
#include "aac.h"
+#include "aacdec.h"
#include "aactab.h"
#include "aacdectab.h"
#include "cbrt_tablegen.h"
@@ -1918,24 +1919,17 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
return size;
}
-static int aac_decode_frame(AVCodecContext *avctx, void *data,
- int *data_size, AVPacket *avpkt)
+int ff_aac_decode_frame_int(AVCodecContext *avctx, void *data,
+ int *data_size, GetBitContext *gb)
{
- const uint8_t *buf = avpkt->data;
- int buf_size = avpkt->size;
AACContext *ac = avctx->priv_data;
ChannelElement *che = NULL, *che_prev = NULL;
- GetBitContext gb;
enum RawDataBlockType elem_type, elem_type_prev = TYPE_END;
int err, elem_id, data_size_tmp;
- int buf_consumed;
int samples = 0, multiplier;
- int buf_offset;
- init_get_bits(&gb, buf, buf_size * 8);
-
- if (show_bits(&gb, 12) == 0xfff) {
- if (parse_adts_frame_header(ac, &gb) < 0) {
+ if (show_bits(gb, 12) == 0xfff) {
+ if (parse_adts_frame_header(ac, gb) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n");
return -1;
}
@@ -1947,8 +1941,8 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
ac->tags_mapped = 0;
// parse
- while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {
- elem_id = get_bits(&gb, 4);
+ while ((elem_type = get_bits(gb, 3)) != TYPE_END) {
+ elem_id = get_bits(gb, 4);
if (elem_type < TYPE_DSE) {
if (!(che=get_che(ac, elem_type, elem_id))) {
@@ -1962,29 +1956,29 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
switch (elem_type) {
case TYPE_SCE:
- err = decode_ics(ac, &che->ch[0], &gb, 0, 0);
+ err = decode_ics(ac, &che->ch[0], gb, 0, 0);
break;
case TYPE_CPE:
- err = decode_cpe(ac, &gb, che);
+ err = decode_cpe(ac, gb, che);
break;
case TYPE_CCE:
- err = decode_cce(ac, &gb, che);
+ err = decode_cce(ac, gb, che);
break;
case TYPE_LFE:
- err = decode_ics(ac, &che->ch[0], &gb, 0, 0);
+ err = decode_ics(ac, &che->ch[0], gb, 0, 0);
break;
case TYPE_DSE:
- err = skip_data_stream_element(ac, &gb);
+ err = skip_data_stream_element(ac, gb);
break;
case TYPE_PCE: {
enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
- if ((err = decode_pce(ac, new_che_pos, &gb)))
+ if ((err = decode_pce(ac, new_che_pos, gb)))
break;
if (ac->output_configured > OC_TRIAL_PCE)
av_log(avctx, AV_LOG_ERROR,
@@ -1996,13 +1990,13 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
case TYPE_FIL:
if (elem_id == 15)
- elem_id += get_bits(&gb, 8) - 1;
- if (get_bits_left(&gb) < 8 * elem_id) {
+ elem_id += get_bits(gb, 8) - 1;
+ if (get_bits_left(gb) < 8 * elem_id) {
av_log(avctx, AV_LOG_ERROR, overread_err);
return -1;
}
while (elem_id > 0)
- elem_id -= decode_extension_payload(ac, &gb, elem_id, che_prev, elem_type_prev);
+ elem_id -= decode_extension_payload(ac, gb, elem_id, che_prev, elem_type_prev);
err = 0; /* FIXME */
break;
@@ -2017,7 +2011,7 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
if (err)
return err;
- if (get_bits_left(&gb) < 3) {
+ if (get_bits_left(gb) < 3) {
av_log(avctx, AV_LOG_ERROR, overread_err);
return -1;
}
@@ -2047,6 +2041,26 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
if (ac->output_configured)
ac->output_configured = OC_LOCKED;
+ return 0;
+}
+
+static int aac_decode_frame(AVCodecContext *avctx, void *data,
+ int *data_size, AVPacket *avpkt)
+{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+ GetBitContext gb;
+ int buf_consumed;
+ int buf_offset;
+ int err;
+
+ init_get_bits(&gb, buf, buf_size * 8);
+
+ err = ff_aac_decode_frame_int(avctx, data, data_size, &gb);
+
+ if (err < 0)
+ return err;
+
buf_consumed = (get_bits_count(&gb) + 7) >> 3;
for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)
if (buf[buf_offset])
diff --git a/libavcodec/aacdec.h b/libavcodec/aacdec.h
new file mode 100644
index 0000000..a16bfa0
--- /dev/null
+++ b/libavcodec/aacdec.h
@@ -0,0 +1,35 @@
+/*
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AAC decoder functions used by the AAC LATM decoder
+ */
+
+#ifndef AVCODEC_AACDEC_H
+#define AVCODEC_AACDEC_H
+
+#include "avcodec.h"
+#include "get_bits.h"
+
+
+int ff_aac_decode_frame_int(AVCodecContext *avctx, void *data,
+ int *data_size, GetBitContext *gb);
+
+#endif /* AVCODEC_AACDEC_H */
--
1.7.3.1
More information about the ffmpeg-devel
mailing list