Atrac: Add "flush_buffers" api. The ffmpeg atrac decoder was missing this.

This commit is contained in:
Henrik Rydgård 2024-04-11 16:35:27 +02:00
parent 3f09e43c4e
commit 45936e8826
5 changed files with 23 additions and 0 deletions

View File

@ -46,6 +46,15 @@ public:
return codecOpen_;
}
void FlushBuffers() {
if (at3Ctx_) {
atrac3_flush_buffers(at3Ctx_);
}
if (at3pCtx_) {
atrac3p_flush_buffers(at3pCtx_);
}
}
bool Decode(const uint8_t *inbuf, int inbytes, uint8_t *outbuf, int *outbytes) override {
if (!codecOpen_) {
_dbg_assert_(false);

View File

@ -48,6 +48,8 @@ public:
virtual void SetChannels(int channels) = 0;
virtual void FlushBuffers() {}
// Just metadata.
void SetCtxPtr(uint32_t ptr) { ctxPtr = ptr; }
uint32_t GetCtxPtr() const { return ctxPtr; }

View File

@ -8,11 +8,14 @@ struct ATRAC3Context;
struct ATRAC3PContext;
// If the block_align passed in is 0, tries to audio detect.
// flush_buffers should be called when seeking before the next decode_frame.
ATRAC3Context *atrac3_alloc(int channels, int *block_align, const uint8_t *extra_data, int extra_data_size);
void atrac3_free(ATRAC3Context *ctx);
void atrac3_flush_buffers(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);
ATRAC3PContext *atrac3p_alloc(int channels, int *block_align);
void atrac3p_free(ATRAC3PContext *ctx);
void atrac3p_flush_buffers(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);

View File

@ -765,6 +765,11 @@ int atrac3_decode_frame(ATRAC3Context *ctx, float *out_data[2], int *nb_samples,
return block_align;
}
void atrac3_flush_buffers(ATRAC3Context *c) {
// There's no known correct way to do this, so let's just reset some stuff.
memset(c->temp_buf, 0, sizeof(c->temp_buf));
}
static void atrac3_init_static_data(void)
{
int i;

View File

@ -357,3 +357,7 @@ int atrac3p_decode_frame(ATRAC3PContext *ctx, float *out_data[2], int *nb_sample
return FFMIN(ctx->block_align, avpkt_size);
}
void atrac3p_flush_buffers(ATRAC3PContext *ctx) {
// TODO: Not sure what should be zeroed here.
}