Commit 931c85d0 authored by Thomas Raivio's avatar Thomas Raivio Committed by Michael Niedermayer

aac decoding patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)

Originally committed as revision 2986 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent b2e3c528
/* /*
* Faad decoder * Faad decoder
* Copyright (c) 2003 Zdenek Kabelac. * Copyright (c) 2003 Zdenek Kabelac.
* Copyright (c) 2004 Thomas Raivio.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -51,20 +52,42 @@ typedef struct { ...@@ -51,20 +52,42 @@ typedef struct {
/* faad calls */ /* faad calls */
faacDecHandle FAADAPI (*faacDecOpen)(void); faacDecHandle FAADAPI (*faacDecOpen)(void);
faacDecConfigurationPtr FAADAPI (*faacDecGetCurrentConfiguration)(faacDecHandle hDecoder); faacDecConfigurationPtr FAADAPI (*faacDecGetCurrentConfiguration)(faacDecHandle hDecoder);
unsigned char FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder, #ifndef FAAD2_VERSION
faacDecConfigurationPtr config); int FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder,
long FAADAPI (*faacDecInit)(faacDecHandle hDecoder, faacDecConfigurationPtr config);
int FAADAPI (*faacDecInit)(faacDecHandle hDecoder,
unsigned char *buffer, unsigned char *buffer,
unsigned long *samplerate, unsigned long *samplerate,
unsigned char *channels); unsigned long *channels);
char FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer, int FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer,
unsigned long SizeOfDecoderSpecificInfo,
unsigned long *samplerate, unsigned long *channels);
int FAADAPI (*faacDecDecode)(faacDecHandle hDecoder,
unsigned char *buffer,
unsigned long *bytesconsumed,
short *sample_buffer,
unsigned long *samples);
#else
unsigned char FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder,
faacDecConfigurationPtr config);
long FAADAPI (*faacDecInit)(faacDecHandle hDecoder,
unsigned char *buffer,
unsigned long buffer_size,
unsigned long *samplerate,
unsigned char *channels);
char FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer,
unsigned long SizeOfDecoderSpecificInfo, unsigned long SizeOfDecoderSpecificInfo,
unsigned long *samplerate, unsigned char *channels); unsigned long *samplerate, unsigned char *channels);
void *FAADAPI (*faacDecDecode)(faacDecHandle hDecoder,
faacDecFrameInfo *hInfo,
unsigned char *buffer,
unsigned long buffer_size);
unsigned char* FAADAPI (*faacDecGetErrorMessage)(unsigned char errcode);
#endif
void FAADAPI (*faacDecClose)(faacDecHandle hDecoder); void FAADAPI (*faacDecClose)(faacDecHandle hDecoder);
void* FAADAPI (*faacDecDecode)(faacDecHandle hDecoder,
faacDecFrameInfo *hInfo,
unsigned char *buffer);
unsigned char* FAADAPI (*faacDecGetErrorMessage)(unsigned char errcode);
} FAACContext; } FAACContext;
static const unsigned long faac_srates[] = static const unsigned long faac_srates[] =
...@@ -77,7 +100,11 @@ static int faac_init_mp4(AVCodecContext *avctx) ...@@ -77,7 +100,11 @@ static int faac_init_mp4(AVCodecContext *avctx)
{ {
FAACContext *s = (FAACContext *) avctx->priv_data; FAACContext *s = (FAACContext *) avctx->priv_data;
unsigned long samplerate; unsigned long samplerate;
#ifndef FAAD2_VERSION
unsigned long channels;
#else
unsigned char channels; unsigned char channels;
#endif
int r = 0; int r = 0;
if (avctx->extradata) if (avctx->extradata)
...@@ -87,15 +114,13 @@ static int faac_init_mp4(AVCodecContext *avctx) ...@@ -87,15 +114,13 @@ static int faac_init_mp4(AVCodecContext *avctx)
// else r = s->faacDecInit(s->faac_handle ... ); // else r = s->faacDecInit(s->faac_handle ... );
if (r < 0) if (r < 0)
av_log(avctx, AV_LOG_ERROR, "faacDecInit2 failed r:%d sr:%ld ch:%d s:%d\n", av_log(avctx, AV_LOG_ERROR, "faacDecInit2 failed r:%d sr:%ld ch:%ld s:%d\n",
r, samplerate, channels, avctx->extradata_size); r, samplerate, (long)channels, avctx->extradata_size);
return r; return r;
} }
static int faac_init_aac(AVCodecContext *avctx) static int faac_init_aac(AVCodecContext *avctx)
{ {
FAACContext *s = (FAACContext *) avctx->priv_data;
return 0; return 0;
} }
...@@ -104,9 +129,31 @@ static int faac_decode_frame(AVCodecContext *avctx, ...@@ -104,9 +129,31 @@ static int faac_decode_frame(AVCodecContext *avctx,
uint8_t *buf, int buf_size) uint8_t *buf, int buf_size)
{ {
FAACContext *s = (FAACContext *) avctx->priv_data; FAACContext *s = (FAACContext *) avctx->priv_data;
#ifndef FAAD2_VERSION
unsigned long bytesconsumed;
short *sample_buffer = NULL;
unsigned long samples;
int out;
#else
faacDecFrameInfo frame_info; faacDecFrameInfo frame_info;
void* out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf); void *out;
//printf("DECODE FRAME %d, %d, %d - %p\n", buf_size, frame_info.samples, frame_info.bytesconsumed, out); #endif
if(buf_size == 0)
return 0;
#ifndef FAAD2_VERSION
out = s->faacDecDecode(s->faac_handle,
(unsigned char*)buf,
&bytesconsumed,
data,
&samples);
samples *= s->sample_size;
if (data_size)
*data_size = samples;
return (buf_size < (int)bytesconsumed)
? buf_size : (int)bytesconsumed;
#else
out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf, (unsigned long)buf_size);
if (frame_info.error > 0) { if (frame_info.error > 0) {
av_log(avctx, AV_LOG_ERROR, "faac: frame decodinf failed: %s\n", av_log(avctx, AV_LOG_ERROR, "faac: frame decodinf failed: %s\n",
...@@ -122,6 +169,7 @@ static int faac_decode_frame(AVCodecContext *avctx, ...@@ -122,6 +169,7 @@ static int faac_decode_frame(AVCodecContext *avctx,
return (buf_size < (int)frame_info.bytesconsumed) return (buf_size < (int)frame_info.bytesconsumed)
? buf_size : (int)frame_info.bytesconsumed; ? buf_size : (int)frame_info.bytesconsumed;
#endif
} }
static int faac_decode_end(AVCodecContext *avctx) static int faac_decode_end(AVCodecContext *avctx)
...@@ -159,22 +207,33 @@ static int faac_decode_init(AVCodecContext *avctx) ...@@ -159,22 +207,33 @@ static int faac_decode_init(AVCodecContext *avctx)
#endif /* CONFIG_FAADBIN */ #endif /* CONFIG_FAADBIN */
// resolve all needed function calls // resolve all needed function calls
dfaac(Open, (faacDecHandle FAADAPI (*)(void))); dfaac(Open, (faacDecHandle FAADAPI (*)(void)));
dfaac(GetCurrentConfiguration, (faacDecConfigurationPtr dfaac(GetCurrentConfiguration, (faacDecConfigurationPtr
FAADAPI (*)(faacDecHandle))); FAADAPI (*)(faacDecHandle)));
dfaac(SetConfiguration, (unsigned char FAADAPI (*)(faacDecHandle, #ifndef FAAD2_VERSION
dfaac(SetConfiguration, (int FAADAPI (*)(faacDecHandle,
faacDecConfigurationPtr))); faacDecConfigurationPtr)));
dfaac(Init, (int FAADAPI (*)(faacDecHandle, unsigned char*,
unsigned long*, unsigned long*)));
dfaac(Init2, (int FAADAPI (*)(faacDecHandle, unsigned char*,
unsigned long, unsigned long*,
unsigned long*)));
dfaac(Close, (void FAADAPI (*)(faacDecHandle hDecoder)));
dfaac(Decode, (int FAADAPI (*)(faacDecHandle, unsigned char*,
unsigned long*, short*, unsigned long*)));
#else
dfaac(SetConfiguration, (unsigned char FAADAPI (*)(faacDecHandle,
faacDecConfigurationPtr)));
dfaac(Init, (long FAADAPI (*)(faacDecHandle, unsigned char*, dfaac(Init, (long FAADAPI (*)(faacDecHandle, unsigned char*,
unsigned long*, unsigned char*))); unsigned long, unsigned long*, unsigned char*)));
dfaac(Init2, (char FAADAPI (*)(faacDecHandle, unsigned char*, dfaac(Init2, (char FAADAPI (*)(faacDecHandle, unsigned char*,
unsigned long, unsigned long*, unsigned long, unsigned long*,
unsigned char*))); unsigned char*)));
dfaac(Close, (void FAADAPI (*)(faacDecHandle hDecoder))); dfaac(Decode, (void *FAADAPI (*)(faacDecHandle, faacDecFrameInfo*,
dfaac(Decode, (void* FAADAPI (*)(faacDecHandle, faacDecFrameInfo*, unsigned char*, unsigned long)));
unsigned char*)));
dfaac(GetErrorMessage, (unsigned char* FAADAPI (*)(unsigned char))); dfaac(GetErrorMessage, (unsigned char* FAADAPI (*)(unsigned char)));
#endif
#undef dfacc #undef dfacc
#ifdef CONFIG_FAADBIN #ifdef CONFIG_FAADBIN
...@@ -203,15 +262,21 @@ static int faac_decode_init(AVCodecContext *avctx) ...@@ -203,15 +262,21 @@ static int faac_decode_init(AVCodecContext *avctx)
case 8: av_log(avctx, AV_LOG_ERROR, "FAADlib unsupported bps %d\n", avctx->bits_per_sample); break; case 8: av_log(avctx, AV_LOG_ERROR, "FAADlib unsupported bps %d\n", avctx->bits_per_sample); break;
default: default:
case 16: case 16:
#ifdef FAAD2_VERSION
faac_cfg->outputFormat = FAAD_FMT_16BIT; faac_cfg->outputFormat = FAAD_FMT_16BIT;
#endif
s->sample_size = 2; s->sample_size = 2;
break; break;
case 24: case 24:
#ifdef FAAD2_VERSION
faac_cfg->outputFormat = FAAD_FMT_24BIT; faac_cfg->outputFormat = FAAD_FMT_24BIT;
#endif
s->sample_size = 3; s->sample_size = 3;
break; break;
case 32: case 32:
#ifdef FAAD2_VERSION
faac_cfg->outputFormat = FAAD_FMT_32BIT; faac_cfg->outputFormat = FAAD_FMT_32BIT;
#endif
s->sample_size = 4; s->sample_size = 4;
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment