mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-29 22:00:58 +02:00
avcodec/aacdec: Split SBR context from ChannelElement
The AAC fixed-point and floating-point decoders have a lot of duplicated code; the main obstacle to deduplicating it is that several structures with the same name are actually different types, because they contain INTFLOATs (int or float) and AAC_FLOATs (SoftFloat or float). SoftFloat and float typically have different sizes, so dealing with it is the more complicated of the two. AAC_FLOAT is mainly used in the sbr code and structures, so one can still deduplicate the code by only exposing the common part of ChannelElement (without SBR context) to the common decoder part. One prerequisite of this is to move allocating the whole ChannelElement to code that will stay unduplicated. It is most natural to move said allocation to ff_aac_sbr_ctx_init(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
6975d965fc
commit
5bd7b8d999
@ -41,7 +41,6 @@
|
||||
#include "aac.h"
|
||||
#include "aac_defines.h"
|
||||
#include "mpeg4audio.h"
|
||||
#include "sbr.h"
|
||||
|
||||
/**
|
||||
* Output configuration status
|
||||
@ -153,7 +152,6 @@ typedef struct ChannelElement {
|
||||
SingleChannelElement ch[2];
|
||||
// CCE specific
|
||||
ChannelCoupling coup;
|
||||
SpectralBandReplication sbr;
|
||||
} ChannelElement;
|
||||
|
||||
typedef struct OutputConfiguration {
|
||||
|
@ -134,10 +134,7 @@ static av_cold int che_configure(AACDecContext *ac,
|
||||
return AVERROR_INVALIDDATA;
|
||||
if (che_pos) {
|
||||
if (!ac->che[type][id]) {
|
||||
int ret;
|
||||
if (!(ac->che[type][id] = av_mallocz(sizeof(ChannelElement))))
|
||||
return AVERROR(ENOMEM);
|
||||
ret = AAC_RENAME(ff_aac_sbr_ctx_init)(ac, ac->che[type][id], type);
|
||||
int ret = AAC_RENAME(ff_aac_sbr_ctx_alloc_init)(ac, &ac->che[type][id], type);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
@ -68,8 +68,11 @@ enum {
|
||||
|
||||
/** Initialize SBR. */
|
||||
void AAC_RENAME(ff_aac_sbr_init)(void);
|
||||
/** Initialize one SBR context. */
|
||||
int AAC_RENAME(ff_aac_sbr_ctx_init)(AACDecContext *ac, ChannelElement *che, int id_aac);
|
||||
/**
|
||||
* Allocate an ExtChannelElement (if necessary) and
|
||||
* initialize the SBR context contained in it.
|
||||
*/
|
||||
int AAC_RENAME(ff_aac_sbr_ctx_alloc_init)(AACDecContext *ac, ChannelElement **che, int id_aac);
|
||||
/** Close one SBR context. */
|
||||
void AAC_RENAME(ff_aac_sbr_ctx_close)(ChannelElement *che);
|
||||
/** Decode one SBR element. */
|
||||
|
@ -38,6 +38,16 @@
|
||||
#include "libavutil/qsort.h"
|
||||
#include "libavutil/mem.h"
|
||||
|
||||
typedef struct ExtChannelElement {
|
||||
ChannelElement ch;
|
||||
SpectralBandReplication sbr;
|
||||
} ExtChannelElement;
|
||||
|
||||
static inline SpectralBandReplication *get_sbr(ChannelElement *ch)
|
||||
{
|
||||
return &((ExtChannelElement*)ch)->sbr;
|
||||
}
|
||||
|
||||
static av_cold void aacsbr_tableinit(void)
|
||||
{
|
||||
int n;
|
||||
@ -65,14 +75,18 @@ static void sbr_turnoff(SpectralBandReplication *sbr) {
|
||||
memset(&sbr->spectrum_params, -1, sizeof(SpectrumParameters));
|
||||
}
|
||||
|
||||
av_cold int AAC_RENAME(ff_aac_sbr_ctx_init)(AACDecContext *ac, ChannelElement *che, int id_aac)
|
||||
av_cold int AAC_RENAME(ff_aac_sbr_ctx_alloc_init)(AACDecContext *ac,
|
||||
ChannelElement **che, int id_aac)
|
||||
{
|
||||
SpectralBandReplication *sbr = &che->sbr;
|
||||
SpectralBandReplication *sbr;
|
||||
ExtChannelElement *ext = av_mallocz(sizeof(*ext));
|
||||
int ret;
|
||||
float scale;
|
||||
|
||||
if (sbr->mdct)
|
||||
return 0;
|
||||
if (!ext)
|
||||
return AVERROR(ENOMEM);
|
||||
*che = &ext->ch;
|
||||
sbr = &ext->sbr;
|
||||
|
||||
sbr->kx[0] = sbr->kx[1];
|
||||
sbr->id_aac = id_aac;
|
||||
@ -106,7 +120,7 @@ av_cold int AAC_RENAME(ff_aac_sbr_ctx_init)(AACDecContext *ac, ChannelElement *c
|
||||
|
||||
av_cold void AAC_RENAME(ff_aac_sbr_ctx_close)(ChannelElement *che)
|
||||
{
|
||||
SpectralBandReplication *sbr = &che->sbr;
|
||||
SpectralBandReplication *sbr = get_sbr(che);
|
||||
av_tx_uninit(&sbr->mdct);
|
||||
av_tx_uninit(&sbr->mdct_ana);
|
||||
}
|
||||
@ -1097,7 +1111,7 @@ int AAC_RENAME(ff_aac_sbr_decode_extension)(AACDecContext *ac, ChannelElement *c
|
||||
GetBitContext *gb_host, int crc,
|
||||
int cnt, int id_aac)
|
||||
{
|
||||
SpectralBandReplication *sbr = &che->sbr;
|
||||
SpectralBandReplication *sbr = get_sbr(che);
|
||||
unsigned int num_sbr_bits = 0, num_align_bits;
|
||||
unsigned bytes_read;
|
||||
GetBitContext gbc = *gb_host, *gb = &gbc;
|
||||
@ -1464,7 +1478,7 @@ static void sbr_env_estimate(AAC_FLOAT (*e_curr)[48], INTFLOAT X_high[64][40][2]
|
||||
void AAC_RENAME(ff_aac_sbr_apply)(AACDecContext *ac, ChannelElement *che,
|
||||
int id_aac, INTFLOAT* L, INTFLOAT* R)
|
||||
{
|
||||
SpectralBandReplication *sbr = &che->sbr;
|
||||
SpectralBandReplication *sbr = get_sbr(che);
|
||||
int downsampled = ac->oc[1].m4ac.ext_sample_rate < sbr->sample_rate;
|
||||
int ch;
|
||||
int nch = (id_aac == TYPE_CPE) ? 2 : 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user