mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
Finally remove the AVCodecContext
This commit is contained in:
parent
6ea8efc0e9
commit
b35b351802
@ -390,7 +390,6 @@
|
|||||||
<ClInclude Include="..\ext\at3_standalone\atrac3data.h" />
|
<ClInclude Include="..\ext\at3_standalone\atrac3data.h" />
|
||||||
<ClInclude Include="..\ext\at3_standalone\atrac3plus.h" />
|
<ClInclude Include="..\ext\at3_standalone\atrac3plus.h" />
|
||||||
<ClInclude Include="..\ext\at3_standalone\atrac3plus_data.h" />
|
<ClInclude Include="..\ext\at3_standalone\atrac3plus_data.h" />
|
||||||
<ClInclude Include="..\ext\at3_standalone\avcodec.h" />
|
|
||||||
<ClInclude Include="..\ext\at3_standalone\compat.h" />
|
<ClInclude Include="..\ext\at3_standalone\compat.h" />
|
||||||
<ClInclude Include="..\ext\at3_standalone\fft.h" />
|
<ClInclude Include="..\ext\at3_standalone\fft.h" />
|
||||||
<ClInclude Include="..\ext\at3_standalone\float_dsp.h" />
|
<ClInclude Include="..\ext\at3_standalone\float_dsp.h" />
|
||||||
@ -609,7 +608,6 @@
|
|||||||
<ClCompile Include="..\ext\at3_standalone\float_dsp.cpp" />
|
<ClCompile Include="..\ext\at3_standalone\float_dsp.cpp" />
|
||||||
<ClCompile Include="..\ext\at3_standalone\mathematics.cpp" />
|
<ClCompile Include="..\ext\at3_standalone\mathematics.cpp" />
|
||||||
<ClCompile Include="..\ext\at3_standalone\mem.cpp" />
|
<ClCompile Include="..\ext\at3_standalone\mem.cpp" />
|
||||||
<ClCompile Include="..\ext\at3_standalone\avcodec.cpp" />
|
|
||||||
<ClCompile Include="..\ext\at3_standalone\sinewin.cpp" />
|
<ClCompile Include="..\ext\at3_standalone\sinewin.cpp" />
|
||||||
<ClCompile Include="..\ext\basis_universal\basisu_transcoder.cpp" />
|
<ClCompile Include="..\ext\basis_universal\basisu_transcoder.cpp" />
|
||||||
<ClCompile Include="..\ext\libpng17\png.c">
|
<ClCompile Include="..\ext\libpng17\png.c">
|
||||||
|
@ -551,9 +551,6 @@
|
|||||||
<ClInclude Include="..\ext\at3_standalone\intreadwrite.h">
|
<ClInclude Include="..\ext\at3_standalone\intreadwrite.h">
|
||||||
<Filter>ext\at3_standalone</Filter>
|
<Filter>ext\at3_standalone</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\ext\at3_standalone\avcodec.h">
|
|
||||||
<Filter>ext\at3_standalone</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\ext\at3_standalone\mathematics.h">
|
<ClInclude Include="..\ext\at3_standalone\mathematics.h">
|
||||||
<Filter>ext\at3_standalone</Filter>
|
<Filter>ext\at3_standalone</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@ -1044,9 +1041,6 @@
|
|||||||
<ClCompile Include="..\ext\at3_standalone\sinewin.cpp">
|
<ClCompile Include="..\ext\at3_standalone\sinewin.cpp">
|
||||||
<Filter>ext\at3_standalone</Filter>
|
<Filter>ext\at3_standalone</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\ext\at3_standalone\avcodec.cpp">
|
|
||||||
<Filter>ext\at3_standalone</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\ext\at3_standalone\atrac.cpp">
|
<ClCompile Include="..\ext\at3_standalone\atrac.cpp">
|
||||||
<Filter>ext\at3_standalone</Filter>
|
<Filter>ext\at3_standalone</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "SimpleAudioDec.h"
|
#include "SimpleAudioDec.h"
|
||||||
|
|
||||||
#include "ext/at3_standalone/at3_decoders.h"
|
#include "ext/at3_standalone/at3_decoders.h"
|
||||||
#include "ext/at3_standalone/avcodec.h"
|
|
||||||
|
|
||||||
inline int16_t clamp16(float f) {
|
inline int16_t clamp16(float f) {
|
||||||
if (f >= 1.0f)
|
if (f >= 1.0f)
|
||||||
@ -17,32 +16,23 @@ inline int16_t clamp16(float f) {
|
|||||||
class Atrac3Audio : public AudioDecoder {
|
class Atrac3Audio : public AudioDecoder {
|
||||||
public:
|
public:
|
||||||
Atrac3Audio(PSPAudioType audioType, int channels, size_t blockAlign, const uint8_t *extraData, size_t extraDataSize) : audioType_(audioType) {
|
Atrac3Audio(PSPAudioType audioType, int channels, size_t blockAlign, const uint8_t *extraData, size_t extraDataSize) : audioType_(audioType) {
|
||||||
|
blockAlign_ = blockAlign;
|
||||||
if (audioType == PSP_CODEC_AT3PLUS) {
|
if (audioType == PSP_CODEC_AT3PLUS) {
|
||||||
at3pCtx_ = atrac3p_alloc(blockAlign, channels);
|
at3pCtx_ = atrac3p_alloc(channels, blockAlign);
|
||||||
codecOpen_ = true;
|
if (at3pCtx_)
|
||||||
} else {
|
codecOpen_ = true;
|
||||||
ctx_ = avcodec_alloc_context3(&ff_atrac3_decoder);
|
} else if (audioType_ == PSP_CODEC_AT3) {
|
||||||
}
|
at3Ctx_ = atrac3_alloc(channels, blockAlign, extraData, extraDataSize);
|
||||||
if (audioType_ == PSP_CODEC_AT3) {
|
if (at3Ctx_)
|
||||||
_dbg_assert_(ctx_);
|
codecOpen_ = true;
|
||||||
_dbg_assert_(!codecOpen_);
|
|
||||||
ctx_->extradata = (uint8_t *)av_mallocz(extraDataSize);
|
|
||||||
ctx_->extradata_size = (int)extraDataSize;
|
|
||||||
ctx_->block_align = (int)blockAlign;
|
|
||||||
codecOpen_ = false;
|
|
||||||
if (extraData != nullptr) {
|
|
||||||
memcpy(ctx_->extradata, extraData, extraDataSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
buffers_[i] = new float[4096];
|
buffers_[i] = new float[4096];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
~Atrac3Audio() {
|
~Atrac3Audio() {
|
||||||
if (ctx_) {
|
if (at3Ctx_) {
|
||||||
avcodec_close(ctx_);
|
atrac3_free(at3Ctx_);
|
||||||
av_freep(&ctx_->extradata);
|
|
||||||
av_freep(&ctx_);
|
|
||||||
}
|
}
|
||||||
if (at3pCtx_) {
|
if (at3pCtx_) {
|
||||||
atrac3p_free(at3pCtx_);
|
atrac3p_free(at3pCtx_);
|
||||||
@ -54,21 +44,11 @@ public:
|
|||||||
|
|
||||||
bool Decode(const uint8_t *inbuf, int inbytes, uint8_t *outbuf, int *outbytes) override {
|
bool Decode(const uint8_t *inbuf, int inbytes, uint8_t *outbuf, int *outbytes) override {
|
||||||
if (!codecOpen_) {
|
if (!codecOpen_) {
|
||||||
int retval;
|
_dbg_assert_(false);
|
||||||
if (audioType_ == PSP_CODEC_AT3PLUS) {
|
}
|
||||||
_dbg_assert_(false);
|
if (inbytes != blockAlign_) {
|
||||||
} else {
|
WARN_LOG(ME, "Atrac3Audio::Decode: Unexpected block align %d (expected %d)", inbytes, blockAlign_);
|
||||||
ctx_->block_align = inbytes;
|
|
||||||
ctx_->channels = 2;
|
|
||||||
retval = avcodec_open2(ctx_, &ff_atrac3_decoder, nullptr);
|
|
||||||
}
|
|
||||||
_dbg_assert_(retval >= 0);
|
|
||||||
if (retval < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
codecOpen_ = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We just call the decode function directly without going through the whole packet machinery.
|
// We just call the decode function directly without going through the whole packet machinery.
|
||||||
int got_frame = 0;
|
int got_frame = 0;
|
||||||
int result;
|
int result;
|
||||||
@ -76,10 +56,8 @@ public:
|
|||||||
if (audioType_ == PSP_CODEC_AT3PLUS) {
|
if (audioType_ == PSP_CODEC_AT3PLUS) {
|
||||||
result = atrac3p_decode_frame(at3pCtx_, buffers_, &nb_samples, &got_frame, inbuf, inbytes);
|
result = atrac3p_decode_frame(at3pCtx_, buffers_, &nb_samples, &got_frame, inbuf, inbytes);
|
||||||
} else {
|
} else {
|
||||||
if (inbytes != ctx_->block_align) {
|
|
||||||
WARN_LOG(ME, "Atrac3Audio::Decode: Unexpected block align %d (expected %d)", inbytes, ctx_->block_align);
|
result = atrac3_decode_frame(at3Ctx_, buffers_, &nb_samples, &got_frame, inbuf, inbytes);
|
||||||
}
|
|
||||||
result = atrac3_decode_frame(ctx_, buffers_, &nb_samples, &got_frame, inbuf, inbytes);
|
|
||||||
}
|
}
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
*outbytes = 0;
|
*outbytes = 0;
|
||||||
@ -120,7 +98,9 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ATRAC3PContext *at3pCtx_ = nullptr;
|
ATRAC3PContext *at3pCtx_ = nullptr;
|
||||||
AVCodecContext* ctx_ = nullptr;
|
ATRAC3Context *at3Ctx_ = nullptr;
|
||||||
|
|
||||||
|
int blockAlign_ = 0;
|
||||||
|
|
||||||
int outSamples_ = 0;
|
int outSamples_ = 0;
|
||||||
int srcPos_ = 0;
|
int srcPos_ = 0;
|
||||||
|
@ -11,7 +11,6 @@ set(ALL_SOURCE_FILES
|
|||||||
${SRC_DIR}/atrac3plus.cpp
|
${SRC_DIR}/atrac3plus.cpp
|
||||||
${SRC_DIR}/atrac3plusdec.cpp
|
${SRC_DIR}/atrac3plusdec.cpp
|
||||||
${SRC_DIR}/atrac3plusdsp.cpp
|
${SRC_DIR}/atrac3plusdsp.cpp
|
||||||
${SRC_DIR}/avcodec.cpp
|
|
||||||
${SRC_DIR}/get_bits.cpp
|
${SRC_DIR}/get_bits.cpp
|
||||||
${SRC_DIR}/compat.cpp
|
${SRC_DIR}/compat.cpp
|
||||||
${SRC_DIR}/fft.cpp
|
${SRC_DIR}/fft.cpp
|
||||||
|
@ -2,17 +2,15 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
// The full external API for the standalone Atrac3/3+ decoder.
|
||||||
|
|
||||||
|
struct ATRAC3Context;
|
||||||
struct ATRAC3PContext;
|
struct ATRAC3PContext;
|
||||||
|
|
||||||
struct AVCodecContext;
|
ATRAC3Context *atrac3_alloc(int channels, int block_align, const uint8_t *extra_data, int extra_data_size);
|
||||||
struct AVFrame;
|
void atrac3_free(ATRAC3Context *ctx);
|
||||||
|
int atrac3_decode_frame(ATRAC3Context *ctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size);
|
||||||
|
|
||||||
#include "avcodec.h"
|
ATRAC3PContext *atrac3p_alloc(int channels, int block_align);
|
||||||
|
|
||||||
int atrac3_decode_frame(AVCodecContext *avctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size);
|
|
||||||
|
|
||||||
ATRAC3PContext *atrac3p_alloc(int block_align, int channels);
|
|
||||||
void atrac3p_free(ATRAC3PContext *ctx);
|
void atrac3p_free(ATRAC3PContext *ctx);
|
||||||
|
|
||||||
int atrac3p_decode_frame(ATRAC3PContext *ctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size);
|
int atrac3p_decode_frame(ATRAC3PContext *ctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size);
|
||||||
extern AVCodec ff_atrac3_decoder;
|
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "avcodec.h"
|
|
||||||
#include "atrac.h"
|
#include "atrac.h"
|
||||||
|
|
||||||
float ff_atrac_sf_table[64];
|
float ff_atrac_sf_table[64];
|
||||||
|
@ -40,10 +40,10 @@
|
|||||||
|
|
||||||
#include "float_dsp.h"
|
#include "float_dsp.h"
|
||||||
#include "fft.h"
|
#include "fft.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "get_bits.h"
|
#include "get_bits.h"
|
||||||
|
|
||||||
#include "avcodec.h"
|
|
||||||
#include "atrac.h"
|
#include "atrac.h"
|
||||||
#include "atrac3data.h"
|
#include "atrac3data.h"
|
||||||
|
|
||||||
@ -108,6 +108,9 @@ typedef struct ATRAC3Context {
|
|||||||
|
|
||||||
AtracGCContext gainc_ctx;
|
AtracGCContext gainc_ctx;
|
||||||
FFTContext mdct_ctx;
|
FFTContext mdct_ctx;
|
||||||
|
|
||||||
|
int block_align;
|
||||||
|
int channels;
|
||||||
} ATRAC3Context;
|
} ATRAC3Context;
|
||||||
|
|
||||||
static DECLARE_ALIGNED(32, float, mdct_window)[MDCT_SIZE];
|
static DECLARE_ALIGNED(32, float, mdct_window)[MDCT_SIZE];
|
||||||
@ -184,16 +187,13 @@ static void init_imdct_window(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int atrac3_decode_close(AVCodecContext *avctx)
|
void atrac3_free(ATRAC3Context *ctx)
|
||||||
{
|
{
|
||||||
ATRAC3Context *q = (ATRAC3Context * )avctx->priv_data;
|
av_freep(&ctx->units);
|
||||||
|
av_freep(&ctx->decoded_bytes_buffer);
|
||||||
|
|
||||||
av_freep(&q->units);
|
ff_mdct_end(&ctx->mdct_ctx);
|
||||||
av_freep(&q->decoded_bytes_buffer);
|
av_freep(&ctx);
|
||||||
|
|
||||||
ff_mdct_end(&q->mdct_ctx);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -729,14 +729,13 @@ static int decode_frame(ATRAC3Context *q, int block_align, int channels, const u
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int atrac3_decode_frame(AVCodecContext *avctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size)
|
int atrac3_decode_frame(ATRAC3Context *ctx, float *out_data[2], int *nb_samples, int *got_frame_ptr, const uint8_t *buf, int buf_size)
|
||||||
{
|
{
|
||||||
ATRAC3Context *q = (ATRAC3Context *)avctx->priv_data;
|
|
||||||
int ret;
|
int ret;
|
||||||
const uint8_t *databuf;
|
const uint8_t *databuf;
|
||||||
|
|
||||||
const int block_align = avctx->block_align;
|
const int block_align = ctx->block_align;
|
||||||
const int channels = avctx->channels;
|
const int channels = ctx->channels;
|
||||||
|
|
||||||
if (buf_size < block_align) {
|
if (buf_size < block_align) {
|
||||||
av_log(AV_LOG_ERROR,
|
av_log(AV_LOG_ERROR,
|
||||||
@ -748,14 +747,14 @@ int atrac3_decode_frame(AVCodecContext *avctx, float *out_data[2], int *nb_sampl
|
|||||||
*nb_samples = SAMPLES_PER_FRAME;
|
*nb_samples = SAMPLES_PER_FRAME;
|
||||||
|
|
||||||
/* Check if we need to descramble and what buffer to pass on. */
|
/* Check if we need to descramble and what buffer to pass on. */
|
||||||
if (q->scrambled_stream) {
|
if (ctx->scrambled_stream) {
|
||||||
decode_bytes(buf, q->decoded_bytes_buffer, block_align);
|
decode_bytes(buf, ctx->decoded_bytes_buffer, block_align);
|
||||||
databuf = q->decoded_bytes_buffer;
|
databuf = ctx->decoded_bytes_buffer;
|
||||||
} else {
|
} else {
|
||||||
databuf = buf;
|
databuf = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = decode_frame(q, block_align, channels, databuf, out_data);
|
ret = decode_frame(ctx, block_align, channels, databuf, out_data);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
av_log( AV_LOG_ERROR, "Frame decoding error!\n");
|
av_log( AV_LOG_ERROR, "Frame decoding error!\n");
|
||||||
return ret;
|
return ret;
|
||||||
@ -786,24 +785,27 @@ static void atrac3_init_static_data(void)
|
|||||||
|
|
||||||
static int static_init_done;
|
static int static_init_done;
|
||||||
|
|
||||||
static int atrac3_decode_init(AVCodecContext *avctx)
|
ATRAC3Context *atrac3_alloc(int channels, int block_align, const uint8_t *extra_data, int extra_data_size) {
|
||||||
{
|
|
||||||
int i, ret;
|
int i, ret;
|
||||||
int version, delay, samples_per_frame, frame_factor;
|
int version, delay, samples_per_frame, frame_factor;
|
||||||
const uint8_t *edata_ptr = avctx->extradata;
|
|
||||||
ATRAC3Context *q = (ATRAC3Context * )avctx->priv_data;
|
|
||||||
|
|
||||||
if (avctx->channels <= 0 || avctx->channels > 2) {
|
const uint8_t *edata_ptr = extra_data;
|
||||||
|
|
||||||
|
if (channels <= 0 || channels > 2) {
|
||||||
av_log(AV_LOG_ERROR, "Channel configuration error!\n");
|
av_log(AV_LOG_ERROR, "Channel configuration error!\n");
|
||||||
return AVERROR(EINVAL);
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ATRAC3Context *q = (ATRAC3Context *)av_mallocz(sizeof(ATRAC3Context));
|
||||||
|
q->channels = channels;
|
||||||
|
q->block_align = block_align;
|
||||||
|
|
||||||
if (!static_init_done)
|
if (!static_init_done)
|
||||||
atrac3_init_static_data();
|
atrac3_init_static_data();
|
||||||
static_init_done = 1;
|
static_init_done = 1;
|
||||||
|
|
||||||
/* Take care of the codec-specific extradata. */
|
/* Take care of the codec-specific extradata. */
|
||||||
if (avctx->extradata_size == 14) {
|
if (extra_data_size == 14) {
|
||||||
/* Parse the extradata, WAV format */
|
/* Parse the extradata, WAV format */
|
||||||
av_log(AV_LOG_DEBUG, "[0-1] %d\n",
|
av_log(AV_LOG_DEBUG, "[0-1] %d\n",
|
||||||
bytestream_get_le16(&edata_ptr)); // Unknown value always 1
|
bytestream_get_le16(&edata_ptr)); // Unknown value always 1
|
||||||
@ -816,21 +818,22 @@ static int atrac3_decode_init(AVCodecContext *avctx)
|
|||||||
bytestream_get_le16(&edata_ptr)); // Unknown always 0
|
bytestream_get_le16(&edata_ptr)); // Unknown always 0
|
||||||
|
|
||||||
/* setup */
|
/* setup */
|
||||||
samples_per_frame = SAMPLES_PER_FRAME * avctx->channels;
|
samples_per_frame = SAMPLES_PER_FRAME * channels;
|
||||||
version = 4;
|
version = 4;
|
||||||
delay = 0x88E;
|
delay = 0x88E;
|
||||||
q->coding_mode = q->coding_mode ? JOINT_STEREO : STEREO;
|
q->coding_mode = q->coding_mode ? JOINT_STEREO : STEREO;
|
||||||
q->scrambled_stream = 0;
|
q->scrambled_stream = 0;
|
||||||
|
|
||||||
if (avctx->block_align != 96 * avctx->channels * frame_factor &&
|
if (block_align != 96 * channels * frame_factor &&
|
||||||
avctx->block_align != 152 * avctx->channels * frame_factor &&
|
block_align != 152 * channels * frame_factor &&
|
||||||
avctx->block_align != 192 * avctx->channels * frame_factor) {
|
block_align != 192 * channels * frame_factor) {
|
||||||
av_log(AV_LOG_ERROR, "Unknown frame/channel/frame_factor "
|
av_log(AV_LOG_ERROR, "Unknown frame/channel/frame_factor "
|
||||||
"configuration %d/%d/%d\n", avctx->block_align,
|
"configuration %d/%d/%d\n", block_align,
|
||||||
avctx->channels, frame_factor);
|
channels, frame_factor);
|
||||||
return AVERROR_INVALIDDATA;
|
atrac3_free(q);
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
} else if (avctx->extradata_size == 12 || avctx->extradata_size == 10) {
|
} else if (extra_data_size == 12 || extra_data_size == 10) {
|
||||||
/* Parse the extradata, RM format. */
|
/* Parse the extradata, RM format. */
|
||||||
version = bytestream_get_be32(&edata_ptr);
|
version = bytestream_get_be32(&edata_ptr);
|
||||||
samples_per_frame = bytestream_get_be16(&edata_ptr);
|
samples_per_frame = bytestream_get_be16(&edata_ptr);
|
||||||
@ -840,56 +843,58 @@ static int atrac3_decode_init(AVCodecContext *avctx)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
av_log(AV_LOG_ERROR, "Unknown extradata size %d.\n",
|
av_log(AV_LOG_ERROR, "Unknown extradata size %d.\n",
|
||||||
avctx->extradata_size);
|
extra_data_size);
|
||||||
return AVERROR(EINVAL);
|
atrac3_free(q);
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check the extradata */
|
/* Check the extradata */
|
||||||
|
|
||||||
if (version != 4) {
|
if (version != 4) {
|
||||||
av_log(AV_LOG_ERROR, "Version %d != 4.\n", version);
|
av_log(AV_LOG_ERROR, "Version %d != 4.\n", version);
|
||||||
return AVERROR_INVALIDDATA;
|
atrac3_free(q);
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (samples_per_frame != SAMPLES_PER_FRAME &&
|
if (samples_per_frame != SAMPLES_PER_FRAME &&
|
||||||
samples_per_frame != SAMPLES_PER_FRAME * 2) {
|
samples_per_frame != SAMPLES_PER_FRAME * 2) {
|
||||||
av_log(AV_LOG_ERROR, "Unknown amount of samples per frame %d.\n",
|
av_log(AV_LOG_ERROR, "Unknown amount of samples per frame %d.\n",
|
||||||
samples_per_frame);
|
samples_per_frame);
|
||||||
return AVERROR_INVALIDDATA;
|
atrac3_free(q);
|
||||||
}
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (delay != 0x88E) {
|
if (delay != 0x88E) {
|
||||||
av_log(AV_LOG_ERROR, "Unknown amount of delay %x != 0x88E.\n",
|
av_log(AV_LOG_ERROR, "Unknown amount of delay %x != 0x88E.\n",
|
||||||
delay);
|
delay);
|
||||||
return AVERROR_INVALIDDATA;
|
atrac3_free(q);
|
||||||
}
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (q->coding_mode == STEREO)
|
if (q->coding_mode == STEREO)
|
||||||
av_log(AV_LOG_DEBUG, "Normal stereo detected.\n");
|
av_log(AV_LOG_DEBUG, "Normal stereo detected.\n");
|
||||||
else if (q->coding_mode == JOINT_STEREO) {
|
else if (q->coding_mode == JOINT_STEREO) {
|
||||||
if (avctx->channels != 2) {
|
if (channels != 2) {
|
||||||
av_log(AV_LOG_ERROR, "Invalid coding mode\n");
|
av_log(AV_LOG_ERROR, "Invalid coding mode\n");
|
||||||
return AVERROR_INVALIDDATA;
|
atrac3_free(q);
|
||||||
}
|
return nullptr;
|
||||||
|
}
|
||||||
av_log(AV_LOG_DEBUG, "Joint stereo detected.\n");
|
av_log(AV_LOG_DEBUG, "Joint stereo detected.\n");
|
||||||
} else {
|
} else {
|
||||||
av_log(AV_LOG_ERROR, "Unknown channel coding mode %x!\n",
|
av_log(AV_LOG_ERROR, "Unknown channel coding mode %x!\n",
|
||||||
q->coding_mode);
|
q->coding_mode);
|
||||||
return AVERROR_INVALIDDATA;
|
atrac3_free(q);
|
||||||
}
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (avctx->block_align >= UINT_MAX / 2)
|
q->decoded_bytes_buffer = (uint8_t *)av_mallocz(FFALIGN(block_align, 4) + AV_INPUT_BUFFER_PADDING_SIZE);
|
||||||
return AVERROR(EINVAL);
|
|
||||||
|
|
||||||
q->decoded_bytes_buffer = (uint8_t *)av_mallocz(FFALIGN(avctx->block_align, 4) + AV_INPUT_BUFFER_PADDING_SIZE);
|
|
||||||
if (!q->decoded_bytes_buffer)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
|
|
||||||
/* initialize the MDCT transform */
|
/* initialize the MDCT transform */
|
||||||
if ((ret = ff_mdct_init(&q->mdct_ctx, 9, 1, 1.0 / 32768)) < 0) {
|
if ((ret = ff_mdct_init(&q->mdct_ctx, 9, 1, 1.0 / 32768)) < 0) {
|
||||||
av_log(AV_LOG_ERROR, "Error initializing MDCT\n");
|
av_log(AV_LOG_ERROR, "Error initializing MDCT\n");
|
||||||
av_freep(&q->decoded_bytes_buffer);
|
av_freep(&q->decoded_bytes_buffer);
|
||||||
return ret;
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* init the joint-stereo decoding data */
|
/* init the joint-stereo decoding data */
|
||||||
@ -908,19 +913,6 @@ static int atrac3_decode_init(AVCodecContext *avctx)
|
|||||||
|
|
||||||
ff_atrac_init_gain_compensation(&q->gainc_ctx, 4, 3);
|
ff_atrac_init_gain_compensation(&q->gainc_ctx, 4, 3);
|
||||||
|
|
||||||
q->units = (ChannelUnit *)av_mallocz_array(avctx->channels, sizeof(*q->units));
|
q->units = (ChannelUnit *)av_mallocz_array(channels, sizeof(*q->units));
|
||||||
if (!q->units) {
|
return q;
|
||||||
atrac3_decode_close(avctx);
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AVCodec ff_atrac3_decoder = {
|
|
||||||
"atrac3",
|
|
||||||
AV_CODEC_ID_ATRAC3,
|
|
||||||
sizeof(ATRAC3Context),
|
|
||||||
&atrac3_decode_init,
|
|
||||||
&atrac3_decode_close,
|
|
||||||
};
|
|
||||||
|
@ -125,7 +125,7 @@ static int set_channel_params(ATRAC3PContext *ctx, int channels) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ATRAC3PContext *atrac3p_alloc(int block_align, int channels) {
|
ATRAC3PContext *atrac3p_alloc(int channels, int block_align) {
|
||||||
int i, ch, ret;
|
int i, ch, ret;
|
||||||
if (!block_align) {
|
if (!block_align) {
|
||||||
av_log(AV_LOG_ERROR, "block_align is not set\n");
|
av_log(AV_LOG_ERROR, "block_align is not set\n");
|
||||||
|
@ -29,7 +29,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "float_dsp.h"
|
#include "float_dsp.h"
|
||||||
#include "avcodec.h"
|
|
||||||
#include "sinewin.h"
|
#include "sinewin.h"
|
||||||
#include "fft.h"
|
#include "fft.h"
|
||||||
#include "atrac3plus.h"
|
#include "atrac3plus.h"
|
||||||
|
@ -1,128 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001 Fabrice Bellard
|
|
||||||
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* Options definition for AVCodecContext.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "avcodec.h"
|
|
||||||
#include "compat.h"
|
|
||||||
#include "mem.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <float.h>
|
|
||||||
|
|
||||||
AVCodecContext *avcodec_alloc_context3(const AVCodec *codec)
|
|
||||||
{
|
|
||||||
AVCodecContext *avctx = (AVCodecContext *)av_mallocz(sizeof(AVCodecContext));
|
|
||||||
if (!avctx)
|
|
||||||
return NULL;
|
|
||||||
int flags = 0;
|
|
||||||
memset(avctx, 0, sizeof(AVCodecContext));
|
|
||||||
|
|
||||||
if (codec) {
|
|
||||||
avctx->codec = codec;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (codec && codec->priv_data_size) {
|
|
||||||
if (!avctx->priv_data) {
|
|
||||||
avctx->priv_data = av_mallocz(codec->priv_data_size);
|
|
||||||
if (!avctx->priv_data) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return avctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
void avcodec_free_context(AVCodecContext **pavctx)
|
|
||||||
{
|
|
||||||
AVCodecContext *avctx = *pavctx;
|
|
||||||
|
|
||||||
if (!avctx)
|
|
||||||
return;
|
|
||||||
|
|
||||||
avcodec_close(avctx);
|
|
||||||
av_freep(&avctx->extradata);
|
|
||||||
av_freep(pavctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, void *options)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (codec->priv_data_size > 0) {
|
|
||||||
if (!avctx->priv_data) {
|
|
||||||
avctx->priv_data = av_mallocz(codec->priv_data_size);
|
|
||||||
if (!avctx->priv_data) {
|
|
||||||
ret = AVERROR(ENOMEM);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
avctx->priv_data = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
avctx->codec = codec;
|
|
||||||
|
|
||||||
if (avctx->codec->init) {
|
|
||||||
ret = avctx->codec->init(avctx);
|
|
||||||
if (ret < 0) {
|
|
||||||
goto free_and_end;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
end:
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
free_and_end:
|
|
||||||
if (avctx->codec)
|
|
||||||
avctx->codec->close(avctx);
|
|
||||||
|
|
||||||
av_freep(&avctx->priv_data);
|
|
||||||
avctx->codec = NULL;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
int avcodec_close(AVCodecContext *avctx)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!avctx)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (avctx->codec && avctx->codec->close)
|
|
||||||
avctx->codec->close(avctx);
|
|
||||||
av_freep(&avctx->priv_data);
|
|
||||||
avctx->codec = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void avcodec_flush_buffers(AVCodecContext *avctx)
|
|
||||||
{
|
|
||||||
if (avctx->codec->flush)
|
|
||||||
avctx->codec->flush(avctx);
|
|
||||||
}
|
|
@ -1,165 +0,0 @@
|
|||||||
/*
|
|
||||||
* copyright (c) 2001 Fabrice Bellard
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef AVCODEC_AVCODEC_H
|
|
||||||
#define AVCODEC_AVCODEC_H
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include "compat.h"
|
|
||||||
#include "mem.h"
|
|
||||||
|
|
||||||
enum AVCodecID {
|
|
||||||
AV_CODEC_ID_ATRAC3,
|
|
||||||
AV_CODEC_ID_ATRAC3P,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ingroup lavc_decoding
|
|
||||||
* Required number of additionally allocated bytes at the end of the input bitstream for decoding.
|
|
||||||
* This is mainly needed because some optimized bitstream readers read
|
|
||||||
* 32 or 64 bit at once and could read over the end.<br>
|
|
||||||
* Note: If the first 23 bits of the additional bytes are not 0, then damaged
|
|
||||||
* MPEG bitstreams could cause overread and segfault.
|
|
||||||
*/
|
|
||||||
#define AV_INPUT_BUFFER_PADDING_SIZE 32
|
|
||||||
|
|
||||||
/**
|
|
||||||
* main external API structure.
|
|
||||||
* New fields can be added to the end with minor version bumps.
|
|
||||||
* Removal, reordering and changes to existing fields require a major
|
|
||||||
* version bump.
|
|
||||||
* Please use AVOptions (av_opt* / av_set/get*()) to access these fields from user
|
|
||||||
* applications.
|
|
||||||
* sizeof(AVCodecContext) must not be used outside libav*.
|
|
||||||
*/
|
|
||||||
typedef struct AVCodecContext {
|
|
||||||
/**
|
|
||||||
* information on struct for av_log
|
|
||||||
* - set by avcodec_alloc_context3
|
|
||||||
*/
|
|
||||||
const struct AVCodec *codec;
|
|
||||||
|
|
||||||
void *priv_data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* some codecs need / can use extradata like Huffman tables.
|
|
||||||
* mjpeg: Huffman tables
|
|
||||||
* rv10: additional flags
|
|
||||||
* mpeg4: global headers (they can be in the bitstream or here)
|
|
||||||
* The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
|
|
||||||
* than extradata_size to avoid problems if it is read with the bitstream reader.
|
|
||||||
* The bytewise contents of extradata must not depend on the architecture or CPU endianness.
|
|
||||||
* - encoding: Set/allocated/freed by libavcodec.
|
|
||||||
* - decoding: Set/allocated/freed by user.
|
|
||||||
*/
|
|
||||||
uint8_t *extradata;
|
|
||||||
int extradata_size;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Codec delay.
|
|
||||||
*
|
|
||||||
* Encoding: Number of frames delay there will be from the encoder input to
|
|
||||||
* the decoder output. (we assume the decoder matches the spec)
|
|
||||||
* Decoding: Number of frames delay in addition to what a standard decoder
|
|
||||||
* as specified in the spec would produce.
|
|
||||||
*
|
|
||||||
* Video:
|
|
||||||
* Number of frames the decoded output will be delayed relative to the
|
|
||||||
* encoded input.
|
|
||||||
*
|
|
||||||
* Audio:
|
|
||||||
* For encoding, this field is unused (see initial_padding).
|
|
||||||
*
|
|
||||||
* For decoding, this is the number of samples the decoder needs to
|
|
||||||
* output before the decoder's output is valid. When seeking, you should
|
|
||||||
* start decoding this many samples prior to your desired seek point.
|
|
||||||
*
|
|
||||||
* - encoding: Set by libavcodec.
|
|
||||||
* - decoding: Set by libavcodec.
|
|
||||||
*/
|
|
||||||
int delay;
|
|
||||||
int channels; ///< number of audio channels
|
|
||||||
|
|
||||||
/**
|
|
||||||
* number of bytes per packet if constant and known or 0
|
|
||||||
* Used by some WAV based audio codecs.
|
|
||||||
*/
|
|
||||||
int block_align;
|
|
||||||
} AVCodecContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AVCodec.
|
|
||||||
*/
|
|
||||||
typedef struct AVCodec {
|
|
||||||
/**
|
|
||||||
* Name of the codec implementation.
|
|
||||||
* The name is globally unique among encoders and among decoders (but an
|
|
||||||
* encoder and a decoder can share the same name).
|
|
||||||
* This is the primary way to find a codec from the user perspective.
|
|
||||||
*/
|
|
||||||
const char *name;
|
|
||||||
enum AVCodecID id;
|
|
||||||
|
|
||||||
/*****************************************************************
|
|
||||||
* No fields below this line are part of the public API. They
|
|
||||||
* may not be used outside of libavcodec and can be changed and
|
|
||||||
* removed at will.
|
|
||||||
* New public fields should be added right above.
|
|
||||||
*****************************************************************
|
|
||||||
*/
|
|
||||||
int priv_data_size;
|
|
||||||
|
|
||||||
int (*init)(AVCodecContext *);
|
|
||||||
/**
|
|
||||||
* Encode data to an AVPacket.
|
|
||||||
*
|
|
||||||
* @param avctx codec context
|
|
||||||
* @param avpkt output AVPacket (may contain a user-provided buffer)
|
|
||||||
* @param[in] frame AVFrame containing the raw data to be encoded
|
|
||||||
* @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
|
|
||||||
* non-empty packet was returned in avpkt.
|
|
||||||
* @return 0 on success, negative error code on failure
|
|
||||||
*/
|
|
||||||
int (*close)(AVCodecContext *);
|
|
||||||
/**
|
|
||||||
* Flush buffers.
|
|
||||||
* Will be called when seeking
|
|
||||||
*/
|
|
||||||
void (*flush)(AVCodecContext *);
|
|
||||||
} AVCodec;
|
|
||||||
|
|
||||||
AVCodecContext *avcodec_alloc_context3(const AVCodec *codec);
|
|
||||||
void avcodec_free_context(AVCodecContext **avctx);
|
|
||||||
|
|
||||||
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, void *options);
|
|
||||||
int avcodec_close(AVCodecContext *avctx);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset the internal decoder state / flush internal buffers. Should be called
|
|
||||||
* e.g. when seeking or when switching to a different stream.
|
|
||||||
*
|
|
||||||
* @note when refcounted frames are not used (i.e. avctx->refcounted_frames is 0),
|
|
||||||
* this invalidates the frames previously returned from the decoder. When
|
|
||||||
* refcounted frames are used, the decoder just releases any references it might
|
|
||||||
* keep internally, but the caller's reference remains valid.
|
|
||||||
*/
|
|
||||||
void avcodec_flush_buffers(AVCodecContext *avctx);
|
|
||||||
|
|
||||||
#endif /* AVCODEC_AVCODEC_H */
|
|
@ -16,6 +16,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define AV_HAVE_FAST_UNALIGNED 0
|
#define AV_HAVE_FAST_UNALIGNED 0
|
||||||
|
#define AV_INPUT_BUFFER_PADDING_SIZE 32
|
||||||
|
|
||||||
#define LOCAL_ALIGNED(bits, type, name, subscript) type name subscript
|
#define LOCAL_ALIGNED(bits, type, name, subscript) type name subscript
|
||||||
#define av_restrict
|
#define av_restrict
|
||||||
|
@ -31,8 +31,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "avcodec.h"
|
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "mathematics.h"
|
#include "mathematics.h"
|
||||||
#include "get_bits.h"
|
#include "get_bits.h"
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
#define SINETABLE(size) \
|
#define SINETABLE(size) \
|
||||||
DECLARE_ALIGNED(32, float, ff_sine_##size)[size]
|
DECLARE_ALIGNED(32, float, ff_sine_##size)[size]
|
||||||
|
|
||||||
|
@ -259,6 +259,22 @@ SOURCES_C += \
|
|||||||
$(EXTDIR)/libchdr/src/libchdr_flac.c \
|
$(EXTDIR)/libchdr/src/libchdr_flac.c \
|
||||||
$(EXTDIR)/libchdr/src/libchdr_huffman.c
|
$(EXTDIR)/libchdr/src/libchdr_huffman.c
|
||||||
|
|
||||||
|
INCFLAGS += -I$(EXTDIR)/at3_standalone
|
||||||
|
|
||||||
|
SOURCES_C += \
|
||||||
|
${EXTDIR}/at3_standalone/atrac.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/atrac3.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/atrac3plus.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/atrac3plusdec.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/atrac3plusdsp.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/get_bits.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/compat.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/fft.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/float_dsp.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/mathematics.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/mem.cpp \
|
||||||
|
${EXTDIR}/at3_standalone/sinewin.cpp
|
||||||
|
|
||||||
ifeq ($(PLATFORM_EXT), android)
|
ifeq ($(PLATFORM_EXT), android)
|
||||||
COREFLAGS += -DHAVE_DLFCN_H
|
COREFLAGS += -DHAVE_DLFCN_H
|
||||||
else ifneq ($(PLATFORM_EXT), win32)
|
else ifneq ($(PLATFORM_EXT), win32)
|
||||||
|
Loading…
Reference in New Issue
Block a user