cook.c File Reference

Cook compatible decoder. More...

#include "libavutil/lfg.h"
#include "avcodec.h"
#include "internal.h"
#include "get_bits.h"
#include "dsputil.h"
#include "bytestream.h"
#include "fft.h"
#include "libavutil/audioconvert.h"
#include "sinewin.h"
#include "cookdata.h"

Go to the source code of this file.

Data Structures

struct  cook_gains
struct  COOKSubpacket
struct  cook

Macros

#define MONO   0x1000001
#define STEREO   0x1000002
#define JOINT_STEREO   0x1000003
#define MC_COOK   0x2000000
#define SUBBAND_SIZE   20
#define MAX_SUBPACKETS   5
#define DECODE_BYTES_PAD1(bytes)   (3 - ((bytes) + 3) % 4)
#define DECODE_BYTES_PAD2(bytes)   ((bytes) % 4 + DECODE_BYTES_PAD1(2 * (bytes)))

Typedefs

typedef struct cook COOKContext

Functions

static av_cold void init_pow2table (void)
static av_cold void init_gain_table (COOKContext *q)
static av_cold int init_cook_vlc_tables (COOKContext *q)
static av_cold int init_cook_mlt (COOKContext *q)
static const float * maybe_reformat_buffer32 (COOKContext *q, const float *ptr, int n)
static av_cold void init_cplscales_table (COOKContext *q)
static int decode_bytes (const uint8_t *inbuffer, uint8_t *out, int bytes)
 Cook indata decoding, every 32 bits are XORed with 0x37c511f2.
static av_cold int cook_decode_close (AVCodecContext *avctx)
 Cook uninit.
static void decode_gain_info (GetBitContext *gb, int *gaininfo)
 Fill the gain array for the timedomain quantization.
static int decode_envelope (COOKContext *q, COOKSubpacket *p, int *quant_index_table)
 Create the quant index table needed for the envelope.
static void categorize (COOKContext *q, COOKSubpacket *p, int *quant_index_table, int *category, int *category_index)
 Calculate the category and category_index vector.
static void expand_category (COOKContext *q, int *category, int *category_index)
 Expand the category vector.
static void scalar_dequant_float (COOKContext *q, int index, int quant_index, int *subband_coef_index, int *subband_coef_sign, float *mlt_p)
 The real requantization of the mltcoefs.
static int unpack_SQVH (COOKContext *q, COOKSubpacket *p, int category, int *subband_coef_index, int *subband_coef_sign)
 Unpack the subband_coef_index and subband_coef_sign vectors.
static void decode_vectors (COOKContext *q, COOKSubpacket *p, int *category, int *quant_index_table, float *mlt_buffer)
 Fill the mlt_buffer with mlt coefficients.
static int mono_decode (COOKContext *q, COOKSubpacket *p, float *mlt_buffer)
 function for decoding mono data
static void interpolate_float (COOKContext *q, float *buffer, int gain_index, int gain_index_next)
 the actual requantization of the timedomain samples
static void imlt_window_float (COOKContext *q, float *inbuffer, cook_gains *gains_ptr, float *previous_buffer)
 Apply transform window, overlap buffers.
static void imlt_gain (COOKContext *q, float *inbuffer, cook_gains *gains_ptr, float *previous_buffer)
 The modulated lapped transform, this takes transform coefficients and transforms them into timedomain samples.
static void decouple_info (COOKContext *q, COOKSubpacket *p, int *decouple_tab)
 function for getting the jointstereo coupling information
static void decouple_float (COOKContext *q, COOKSubpacket *p, int subband, float f1, float f2, float *decode_buffer, float *mlt_buffer1, float *mlt_buffer2)
static int joint_decode (COOKContext *q, COOKSubpacket *p, float *mlt_buffer1, float *mlt_buffer2)
 function for decoding joint stereo data
static void decode_bytes_and_gain (COOKContext *q, COOKSubpacket *p, const uint8_t *inbuffer, cook_gains *gains_ptr)
 First part of subpacket decoding: decode raw stream bytes and read gain info.
static void saturate_output_float (COOKContext *q, int chan, float *out)
 Saturate the output signal and interleave.
static void mlt_compensate_output (COOKContext *q, float *decode_buffer, cook_gains *gains_ptr, float *previous_buffer, float *out, int chan)
 Final part of subpacket decoding: Apply modulated lapped transform, gain compensation, clip and convert to integer.
static int decode_subpacket (COOKContext *q, COOKSubpacket *p, const uint8_t *inbuffer, float *outbuffer)
 Cook subpacket decoding.
static int cook_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
 Cook frame decoding.
static av_cold int cook_count_channels (unsigned int mask)
static av_cold int cook_decode_init (AVCodecContext *avctx)
 Cook initialization.

Variables

static float pow2tab [127]
static float rootpow2tab [127]
AVCodec ff_cook_decoder

Detailed Description

Cook compatible decoder.

Bastardization of the G.722.1 standard. This decoder handles RealNetworks, RealAudio G2 data. Cook is identified by the codec name cook in RM files.

To use this decoder, a calling application must supply the extradata bytes provided from the RM container; 8+ bytes for mono streams and 16+ for stereo streams (maybe more).

Codec technicalities (all this assume a buffer length of 1024): Cook works with several different techniques to achieve its compression. In the timedomain the buffer is divided into 8 pieces and quantized. If two neighboring pieces have different quantization index a smooth quantization curve is used to get a smooth overlap between the different pieces. To get to the transformdomain Cook uses a modulated lapped transform. The transform domain has 50 subbands with 20 elements each. This means only a maximum of 50*20=1000 coefficients are used out of the 1024 available.

Definition in file cook.c.

Macro Definition Documentation

#define DECODE_BYTES_PAD1 (   bytes)    (3 - ((bytes) + 3) % 4)

Definition at line 258 of file cook.c.

Referenced by cook_decode_init().

#define DECODE_BYTES_PAD2 (   bytes)    ((bytes) % 4 + DECODE_BYTES_PAD1(2 * (bytes)))

Definition at line 259 of file cook.c.

#define JOINT_STEREO   0x1000003

Definition at line 60 of file cook.c.

Referenced by cook_decode_init().

#define MAX_SUBPACKETS   5

Definition at line 64 of file cook.c.

Referenced by cook_decode_init().

#define MC_COOK   0x2000000

Definition at line 61 of file cook.c.

Referenced by cook_decode_init().

#define MONO   0x1000001

Definition at line 58 of file cook.c.

Referenced by cook_decode_init(), and MP3lame_encode_init().

#define STEREO   0x1000002

Definition at line 59 of file cook.c.

Referenced by cook_decode_init().

#define SUBBAND_SIZE   20

Definition at line 63 of file cook.c.

Referenced by decode_vectors(), decouple_float(), joint_decode(), and scalar_dequant_float().

Typedef Documentation

typedef struct cook COOKContext

Function Documentation

static void categorize ( COOKContext q,
COOKSubpacket p,
int *  quant_index_table,
int *  category,
int *  category_index 
)
static

Calculate the category and category_index vector.

Parameters
qpointer to the COOKContext
quant_index_tablepointer to the array
categorypointer to the category array
category_indexpointer to the category_index array

Definition at line 411 of file cook.c.

Referenced by mono_decode().

static av_cold int cook_count_channels ( unsigned int  mask)
static

Definition at line 1071 of file cook.c.

Referenced by cook_decode_init().

static av_cold int cook_decode_close ( AVCodecContext avctx)
static

Cook uninit.

Definition at line 310 of file cook.c.

static int cook_decode_frame ( AVCodecContext avctx,
void data,
int *  got_frame_ptr,
AVPacket avpkt 
)
static

Cook frame decoding.

Parameters
avctxpointer to the AVCodecContext

Definition at line 978 of file cook.c.

static av_cold int cook_decode_init ( AVCodecContext avctx)
static

Cook initialization.

Parameters
avctxpointer to the AVCodecContext

Definition at line 1086 of file cook.c.

static int decode_bytes ( const uint8_t *  inbuffer,
uint8_t *  out,
int  bytes 
)
inlinestatic

Cook indata decoding, every 32 bits are XORed with 0x37c511f2.

Why? No idea, some checksum/error detection method maybe.

Out buffer size: extra bytes are needed to cope with padding/misalignment. Subpackets passed to the decoder can contain two, consecutive half-subpackets, of identical but arbitrary size. 1234 1234 1234 1234 extraA extraB Case 1: AAAA BBBB 0 0 Case 2: AAAA ABBB BB– 3 3 Case 3: AAAA AABB BBBB 2 2 Case 4: AAAA AAAB BBBB BB– 1 5

Nice way to waste CPU cycles.

Parameters
inbufferpointer to byte array of indata
outpointer to byte array of outdata
bytesnumber of bytes

Definition at line 281 of file cook.c.

Referenced by decode_bytes_and_gain().

static void decode_bytes_and_gain ( COOKContext q,
COOKSubpacket p,
const uint8_t *  inbuffer,
cook_gains gains_ptr 
)
inlinestatic

First part of subpacket decoding: decode raw stream bytes and read gain info.

Parameters
qpointer to the COOKContext
inbufferpointer to raw stream data
gains_ptrarray of current/prev gain pointers

Definition at line 870 of file cook.c.

Referenced by decode_subpacket().

static int decode_envelope ( COOKContext q,
COOKSubpacket p,
int *  quant_index_table 
)
static

Create the quant index table needed for the envelope.

Parameters
qpointer to the COOKContext
quant_index_tablepointer to the array

Definition at line 370 of file cook.c.

Referenced by mono_decode().

static void decode_gain_info ( GetBitContext gb,
int *  gaininfo 
)
static

Fill the gain array for the timedomain quantization.

Parameters
gbpointer to the GetBitContext
gaininfoarray[9] of gain indexes

Definition at line 342 of file cook.c.

Referenced by decode_bytes_and_gain().

static int decode_subpacket ( COOKContext q,
COOKSubpacket p,
const uint8_t *  inbuffer,
float *  outbuffer 
)
static

Cook subpacket decoding.

This function returns one decoded subpacket, usually 1024 samples per channel.

Parameters
qpointer to the COOKContext
inbufferpointer to the inbuffer
outbufferpointer to the outbuffer

Definition at line 932 of file cook.c.

Referenced by cook_decode_frame().

static void decode_vectors ( COOKContext q,
COOKSubpacket p,
int *  category,
int *  quant_index_table,
float *  mlt_buffer 
)
static

Fill the mlt_buffer with mlt coefficients.

Parameters
qpointer to the COOKContext
categorypointer to the category array
quant_index_tablepointer to the array
mlt_bufferpointer to mlt coefficients

Definition at line 609 of file cook.c.

Referenced by mono_decode().

static void decouple_float ( COOKContext q,
COOKSubpacket p,
int  subband,
float  f1,
float  f2,
float *  decode_buffer,
float *  mlt_buffer1,
float *  mlt_buffer2 
)
static

Definition at line 796 of file cook.c.

Referenced by cook_decode_init().

static void decouple_info ( COOKContext q,
COOKSubpacket p,
int *  decouple_tab 
)
static

function for getting the jointstereo coupling information

Parameters
qpointer to the COOKContext
decouple_tabdecoupling array

Definition at line 766 of file cook.c.

Referenced by joint_decode().

static void expand_category ( COOKContext q,
int *  category,
int *  category_index 
)
inlinestatic

Expand the category vector.

Parameters
qpointer to the COOKContext
categorypointer to the category array
category_indexpointer to the category_index array

Definition at line 514 of file cook.c.

Referenced by mono_decode().

static void imlt_gain ( COOKContext q,
float *  inbuffer,
cook_gains gains_ptr,
float *  previous_buffer 
)
static

The modulated lapped transform, this takes transform coefficients and transforms them into timedomain samples.

Apply transform window, overlap buffers, apply gain profile and buffer management.

Parameters
qpointer to the COOKContext
inbufferpointer to the mltcoefficients
gains_ptrcurrent and previous gains
previous_bufferpointer to the previous buffer to be used for overlapping

Definition at line 735 of file cook.c.

Referenced by mlt_compensate_output().

static void imlt_window_float ( COOKContext q,
float *  inbuffer,
cook_gains gains_ptr,
float *  previous_buffer 
)
static

Apply transform window, overlap buffers.

Parameters
qpointer to the COOKContext
inbufferpointer to the mltcoefficients
gains_ptrcurrent and previous gains
previous_bufferpointer to the previous buffer to be used for overlapping

Definition at line 707 of file cook.c.

Referenced by cook_decode_init().

static av_cold int init_cook_mlt ( COOKContext q)
static

Definition at line 219 of file cook.c.

Referenced by cook_decode_init().

static av_cold int init_cook_vlc_tables ( COOKContext q)
static

Definition at line 189 of file cook.c.

Referenced by cook_decode_init().

static av_cold void init_cplscales_table ( COOKContext q)
static

Definition at line 249 of file cook.c.

Referenced by cook_decode_init().

static av_cold void init_gain_table ( COOKContext q)
static

Definition at line 179 of file cook.c.

Referenced by cook_decode_init().

static av_cold void init_pow2table ( void  )
static

Definition at line 169 of file cook.c.

Referenced by cook_decode_init().

static void interpolate_float ( COOKContext q,
float *  buffer,
int  gain_index,
int  gain_index_next 
)
static

the actual requantization of the timedomain samples

Parameters
qpointer to the COOKContext
bufferpointer to the timedomain buffer
gain_indexindex for the block multiplier
gain_index_nextindex for the next block multiplier

Definition at line 680 of file cook.c.

Referenced by cook_decode_init().

static int joint_decode ( COOKContext q,
COOKSubpacket p,
float *  mlt_buffer1,
float *  mlt_buffer2 
)
static

function for decoding joint stereo data

Parameters
qpointer to the COOKContext
mlt_buffer1pointer to left channel mlt coefficients
mlt_buffer2pointer to right channel mlt coefficients

Definition at line 818 of file cook.c.

Referenced by decode_subpacket().

static const float* maybe_reformat_buffer32 ( COOKContext q,
const float *  ptr,
int  n 
)
static

Definition at line 243 of file cook.c.

Referenced by init_cplscales_table().

static void mlt_compensate_output ( COOKContext q,
float *  decode_buffer,
cook_gains gains_ptr,
float *  previous_buffer,
float *  out,
int  chan 
)
inlinestatic

Final part of subpacket decoding: Apply modulated lapped transform, gain compensation, clip and convert to integer.

Parameters
qpointer to the COOKContext
decode_bufferpointer to the mlt coefficients
gains_ptrarray of current/prev gain pointers
previous_bufferpointer to the previous buffer to be used for overlapping
outpointer to the output buffer
chan0: left or single channel, 1: right channel

Definition at line 914 of file cook.c.

Referenced by decode_subpacket().

static int mono_decode ( COOKContext q,
COOKSubpacket p,
float *  mlt_buffer 
)
static

function for decoding mono data

Parameters
qpointer to the COOKContext
mlt_bufferpointer to mlt coefficients

Definition at line 651 of file cook.c.

Referenced by decode_subpacket(), and joint_decode().

static void saturate_output_float ( COOKContext q,
int  chan,
float *  out 
)
static

Saturate the output signal and interleave.

Parameters
qpointer to the COOKContext
chanchannel to saturate
outpointer to the output vector

Definition at line 893 of file cook.c.

Referenced by cook_decode_init().

static void scalar_dequant_float ( COOKContext q,
int  index,
int  quant_index,
int *  subband_coef_index,
int *  subband_coef_sign,
float *  mlt_p 
)
static

The real requantization of the mltcoefs.

Parameters
qpointer to the COOKContext
indexindex
quant_indexquantisation index
subband_coef_indexarray of indexes to quant_centroid_tab
subband_coef_signsigns of coefficients
mlt_ppointer into the mlt buffer

Definition at line 536 of file cook.c.

Referenced by cook_decode_init().

static int unpack_SQVH ( COOKContext q,
COOKSubpacket p,
int  category,
int *  subband_coef_index,
int *  subband_coef_sign 
)
static

Unpack the subband_coef_index and subband_coef_sign vectors.

Parameters
qpointer to the COOKContext
categorypointer to the category array
subband_coef_indexarray of indexes to quant_centroid_tab
subband_coef_signsigns of coefficients

Definition at line 565 of file cook.c.

Referenced by decode_vectors().

Variable Documentation

AVCodec ff_cook_decoder
Initial value:
{
.name = "cook",
.priv_data_size = sizeof(COOKContext),
.capabilities = CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("COOK"),
}

Definition at line 1306 of file cook.c.

float pow2tab[127]
static

Definition at line 163 of file cook.c.

Referenced by imlt_window_float(), init_gain_table(), init_pow2table(), and interpolate_float().

float rootpow2tab[127]
static

Definition at line 164 of file cook.c.

Referenced by init_pow2table(), and scalar_dequant_float().