/*
* Faad decoder
- * Copyright (c) 2003 Zdenek Kabelac.
- * Copyright (c) 2004 Thomas Raivio.
+ * Copyright (c) 2003 Zdenek Kabelac
+ * Copyright (c) 2004 Thomas Raivio
*
* This file is part of FFmpeg.
*
*/
/**
- * @file faad.c
+ * @file libavcodec/libfaad.c
* AAC decoder.
*
* still a bit unfinished - but it plays something
#endif
/*
- * when CONFIG_LIBFAADBIN is defined the libfaad will be opened at runtime
+ * when CONFIG_LIBFAADBIN is true libfaad will be opened at runtime
*/
//#undef CONFIG_LIBFAADBIN
-//#define CONFIG_LIBFAADBIN
+//#define CONFIG_LIBFAADBIN 0
+//#define CONFIG_LIBFAADBIN 1
-#ifdef CONFIG_LIBFAADBIN
+#if CONFIG_LIBFAADBIN
#include <dlfcn.h>
-static const char* libfaadname = "libfaad.so";
+static const char* const libfaadname = "libfaad.so";
#else
#define dlopen(a)
#define dlclose(a)
#endif
}
-static int faac_init_mp4(AVCodecContext *avctx)
+static av_cold int faac_init_mp4(AVCodecContext *avctx)
{
FAACContext *s = avctx->priv_data;
unsigned long samplerate;
static int faac_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
- uint8_t *buf, int buf_size)
+ AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
FAACContext *s = avctx->priv_data;
#ifndef FAAD2_VERSION
unsigned long bytesconsumed;
unsigned char channels;
int r = s->faacDecInit(s->faac_handle, buf, buf_size, &srate, &channels);
if(r < 0){
- av_log(avctx, AV_LOG_ERROR, "faac: codec init failed: %s\n",
- s->faacDecGetErrorMessage(frame_info.error));
+ av_log(avctx, AV_LOG_ERROR, "libfaad: codec init failed.\n");
return -1;
}
avctx->sample_rate = srate;
out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf, (unsigned long)buf_size);
if (frame_info.error > 0) {
- av_log(avctx, AV_LOG_ERROR, "faac: frame decoding failed: %s\n",
+ av_log(avctx, AV_LOG_ERROR, "libfaad: frame decoding failed: %s\n",
s->faacDecGetErrorMessage(frame_info.error));
return -1;
}
-
+ if (!avctx->frame_size)
+ avctx->frame_size = frame_info.samples/avctx->channels;
frame_info.samples *= s->sample_size;
memcpy(data, out, frame_info.samples); // CHECKME - can we cheat this one
FAACContext *s = avctx->priv_data;
faacDecConfigurationPtr faac_cfg;
-#ifdef CONFIG_LIBFAADBIN
+#if CONFIG_LIBFAADBIN
const char* err = 0;
s->handle = dlopen(libfaadname, RTLD_LAZY);
#undef dfaac
-#ifdef CONFIG_LIBFAADBIN
+#if CONFIG_LIBFAADBIN
if (err) {
dlclose(s->handle);
av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot resolve %s in %s!\n",
faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle);
if (faac_cfg) {
- switch (avctx->bits_per_sample) {
- case 8: av_log(avctx, AV_LOG_ERROR, "FAADlib unsupported bps %d\n", avctx->bits_per_sample); break;
+ switch (avctx->bits_per_coded_sample) {
+ case 8: av_log(avctx, AV_LOG_ERROR, "FAADlib unsupported bps %d\n", avctx->bits_per_coded_sample); break;
default:
case 16:
#ifdef FAAD2_VERSION
if(!s->init && avctx->channels > 0)
channel_setup(avctx);
+ avctx->sample_fmt = SAMPLE_FMT_S16;
return 0;
}
-#define AAC_CODEC(id, name) \
-AVCodec name ## _decoder = { \
- #name, \
- CODEC_TYPE_AUDIO, \
- id, \
- sizeof(FAACContext), \
- faac_decode_init, \
- NULL, \
- faac_decode_end, \
- faac_decode_frame, \
-}
-
-// FIXME - raw AAC files - maybe just one entry will be enough
-AAC_CODEC(CODEC_ID_AAC, libfaad);
-#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0)
-// If it's mp4 file - usually embeded into Qt Mov
-AAC_CODEC(CODEC_ID_MPEG4AAC, mpeg4aac);
-#endif
-
-#undef AAC_CODEC
+AVCodec libfaad_decoder = {
+ "libfaad",
+ CODEC_TYPE_AUDIO,
+ CODEC_ID_AAC,
+ sizeof(FAACContext),
+ faac_decode_init,
+ NULL,
+ faac_decode_end,
+ faac_decode_frame,
+ .long_name = NULL_IF_CONFIG_SMALL("libfaad AAC (Advanced Audio Codec)"),
+};