xine-lib: xine-lib-1.2.13/src/audio_dec/latm.c File Reference

xine-lib 1.2.13-20230125hg15249

Data Structures | Macros | Enumerations | Functions | Variables
latm.c File Reference
`#include <sys/types.h>`
`#include <string.h>`
`#include <stdlib.h>`

Go to the source code of this file.

## Data Structures
struct | bebf_t
struct | bebf_latm_t

## Macros
#define | LOG_MODULE "latm"
#define | LOG_VERBOSE
#define | bebf_UNUSED
#define | bebf_ADJ32(v) (((v) >> 24) | (((v) & 0xff0000) >> 8) | (((v) & 0xff00) << 8) | ((v) << 24))
#define | bebf_shift(nn)
#define | AOTF_SHORT 0x0001 /* frameLengthFlag */
#define | AOTF_CORE 0x0002 /* dependsOnCoreCoder */
#define | AOTF_EXT1 0x0004 /* extensionFlag1 */
#define | AOTF_LAYER 0x0008 /* layerNr */
#define | AOTF_CHAN 0x0010 /* custom channel layout */
#define | AOTF_SUBFR 0x0020 /* subFrames */
#define | AOTF_RESIL 0x0040 /* errorResilienceFlags */
#define | AOTF_LDSBR 0x0080 /* lowDelaySbr */
#define | AOTF_ELD 0x0100 /* enhancedLowDelay */
#define | AOTF_EPCNF 0x0200 /* epConfig */
#define | BEBF_LATM_GOT_CONF 1
#define | BEBF_LATM_GOT_FRAME 2
#define | BEBF_TEST_MAX (2 * (0x1fff + 3))

## Enumerations
enum | bebf_aot_t { AOT_AAC_MAIN = 1 , AOT_AAC_LC = 2 , AOT_AAC_SSR = 3 , AOT_AAC_LTP = 4 , AOT_SBR = 5 , AOT_AAC_SCALABLE = 6 , AOT_TWINVQ = 7 , AOT_CELP = 8 , AOT_HVXC = 9 , AOT_ER_AAC_LC = 17 , AOT_ER_AAC_LTP = 19 , AOT_ER_AAC_SCALABLE = 20 , AOT_ER_TWINVQ = 21 , AOT_ER_BSAC = 22 , AOT_ER_AAC_LD = 23 , AOT_ER_CELP = 24 , AOT_ER_HVXC = 25 , AOT_ER_HILN = 26 , AOT_ER_PARAM = 27 , AOT_SSC = 28 , AOT_PS = 29 , AOT_L1 = 32 , AOT_L2 = 33 , AOT_L3 = 34 , AOT_ALS = 36 , AOT_ER_AAC_ELD = 39 }
enum | bebf_latm_parser_status_t { BEBF_LATM_NEED_MORE_DATA , BEBF_LATM_IS_RAW , BEBF_LATM_IS_ADTS , BEBF_LATM_IS_LATM , BEBF_LATM_IS_UNKNOWN }

## Functions
static void | bebf_seek (bebf_t *bebf, uint32_t nbits)
static void | bebf_align (bebf_t *bebf)
static void | bebf_set_read (bebf_t *bebf, const uint8_t *rp, uint32_t nbytes)
static void | bebf_set_write (bebf_t *bebf, uint8_t *wp)
static uint32_t | bebf_get (bebf_t *bebf, uint32_t nbits)
static uint32_t | bebf_sniff (bebf_t *bebf, uint32_t nbits)
static void | bebf_skip (bebf_t *bebf, uint32_t nbits)
static uint32_t | bebf_tell (bebf_t *bebf)
static int | bebf_sync (bebf_t *bebf, uint32_t pattern, uint32_t pbits)
static void | bebf_put (bebf_t *bebf, uint32_t bits, uint32_t nbits)
static size_t | bebf_flush (bebf_t *bebf)
static void | bebf_copy (bebf_t *bebf, uint32_t nbits)
static int | bebf_latm_configure (bebf_latm_t *latm, uint32_t nbits)
static int | bebf_latm_demux (bebf_latm_t *latm, const uint8_t *in, uint32_t nbytes)
static void | bebf_latm_open (bebf_latm_t *latm)
static void | bebf_latm_close (bebf_latm_t *latm)
static bebf_latm_parser_status_t | bebf_latm_test (const uint8_t *in, int nbytes)
static int | bebf_latm_parse (bebf_latm_t *latm, const uint8_t *in, int *nbytes)

## Variables
static const uint32_t | bebf_latm_flags [40]

## Macro Definition Documentation

## ◆ AOTF_CHAN

#define AOTF_CHAN 0x0010 /* custom channel layout */

Referenced by bebf_latm_configure().

## ◆ AOTF_CORE

#define AOTF_CORE 0x0002 /* dependsOnCoreCoder */

Referenced by bebf_latm_configure().

## ◆ AOTF_ELD

#define AOTF_ELD 0x0100 /* enhancedLowDelay */

Referenced by bebf_latm_configure().

## ◆ AOTF_EPCNF

#define AOTF_EPCNF 0x0200 /* epConfig */

Referenced by bebf_latm_configure().

## ◆ AOTF_EXT1

#define AOTF_EXT1 0x0004 /* extensionFlag1 */

Referenced by bebf_latm_configure().

## ◆ AOTF_LAYER

#define AOTF_LAYER 0x0008 /* layerNr */

Referenced by bebf_latm_configure().

## ◆ AOTF_LDSBR

#define AOTF_LDSBR 0x0080 /* lowDelaySbr */

Referenced by bebf_latm_configure().

## ◆ AOTF_RESIL

#define AOTF_RESIL 0x0040 /* errorResilienceFlags */

Referenced by bebf_latm_configure().

## ◆ AOTF_SHORT

#define AOTF_SHORT 0x0001 /* frameLengthFlag */

Referenced by bebf_latm_configure().

## ◆ AOTF_SUBFR

#define AOTF_SUBFR 0x0020 /* subFrames */

Referenced by bebf_latm_configure().

## ◆ bebf_ADJ32

#define bebf_ADJ32 | ( |  | v | ) | (((v) >> 24) | (((v) & 0xff0000) >> 8) | (((v) & 0xff00) << 8) | ((v) << 24))

Referenced by bebf_copy(), bebf_flush(), bebf_get(), bebf_put(), bebf_seek(), bebf_skip(), bebf_sniff(), bebf_sync(), faad_apply_conf(), and faad_decode_audio().

## ◆ BEBF_LATM_GOT_CONF

#define BEBF_LATM_GOT_CONF 1

Referenced by bebf_latm_configure(), and faad_decode_audio().

## ◆ BEBF_LATM_GOT_FRAME

#define BEBF_LATM_GOT_FRAME 2

Referenced by bebf_latm_demux(), and faad_decode_audio().

## ◆ bebf_shift

#define bebf_shift | ( |  | nn | ) |

Value:
{ \
uint64_t b = bebf->readcache; \
do {*q++ = bebf_ADJ32 (b >> 32); b <<= nn; b |= bebf_ADJ32 (*p++); b <<= 32 - nn;} while (--words); \
bebf->readcache = b; \
}
bebf_ADJ32
#define bebf_ADJ32(v)
Definition latm.c:56
nn
#define nn

Referenced by bebf_copy().

## ◆ BEBF_TEST_MAX

#define BEBF_TEST_MAX (2 * (0x1fff + 3))

Referenced by bebf_latm_test().

## ◆ bebf_UNUSED

#define bebf_UNUSED

## ◆ LOG_MODULE

#define LOG_MODULE "latm"

## ◆ LOG_VERBOSE

#define LOG_VERBOSE

## Enumeration Type Documentation

## ◆ bebf_aot_t

enum bebf_aot_t

Enumerator
AOT_AAC_MAIN |
AOT_AAC_LC |
AOT_AAC_SSR |
AOT_AAC_LTP |
AOT_SBR |
AOT_AAC_SCALABLE |
AOT_TWINVQ |
AOT_CELP |
AOT_HVXC |
AOT_ER_AAC_LC |
AOT_ER_AAC_LTP |
AOT_ER_AAC_SCALABLE |
AOT_ER_TWINVQ |
AOT_ER_BSAC |
AOT_ER_AAC_LD |
AOT_ER_CELP |
AOT_ER_HVXC |
AOT_ER_HILN |
AOT_ER_PARAM |
AOT_SSC |
AOT_PS |
AOT_L1 |
AOT_L2 |
AOT_L3 |
AOT_ALS |
AOT_ER_AAC_ELD |

## ◆ bebf_latm_parser_status_t

enum bebf_latm_parser_status_t

Enumerator
BEBF_LATM_NEED_MORE_DATA |
BEBF_LATM_IS_RAW |
BEBF_LATM_IS_ADTS |
BEBF_LATM_IS_LATM |
BEBF_LATM_IS_UNKNOWN |

## Function Documentation

## ◆ bebf_align()

static void bebf_align | ( | bebf_t * | bebf | ) |
| static

Align to next byte boundary.

Parameters

  bebf | pointer to bebf_t struct to use.

References bebf_t::readbits, and bebf_t::readcache.

Referenced by bebf_latm_configure().

## ◆ bebf_copy()

static void bebf_copy | ( | bebf_t * | bebf,
|  | uint32_t | nbits )
| static

Copy bits from read stream to write stream verbatim, and try to be fast.

Parameters

  bebf | pointer to bebf_t struct to use.
  nbits | bit count.

References bebf_ADJ32, bebf_shift, bebf_t::readbits, bebf_t::readcache, bebf_t::readptr, bebf_t::writebits, bebf_t::writecache, and bebf_t::writeptr.

Referenced by bebf_latm_configure(), and bebf_latm_demux().

## ◆ bebf_flush()

static size_t bebf_flush | ( | bebf_t * | bebf | ) |
| static

Flush out any unsaved data to write stream.

Parameters

  bebf | pointer to bebf_t struct to use.

Returns
  byte count of write buffer so far.

References bebf_ADJ32, bebf_t::writebits, bebf_t::writecache, bebf_t::writeptr, and bebf_t::writestart.

Referenced by bebf_latm_configure(), and bebf_latm_demux().

## ◆ bebf_get()

static uint32_t bebf_get | ( | bebf_t * | bebf,
|  | uint32_t | nbits )
| static

Get 1 .. 32 bits of data from read stream.

Parameters

  bebf | pointer to bebf_t struct to use.
  nbits | bit count.

Returns
  the requested data, right justified.

References bebf_ADJ32, bebf_t::readbits, bebf_t::readcache, bebf_t::readptr, bebf_t::readstop, and v.

Referenced by bebf_latm_configure(), and bebf_latm_demux().

## ◆ bebf_latm_close()

static void bebf_latm_close | ( | bebf_latm_t * | latm | ) |
| static

References bebf_latm_t::config, bebf_latm_t::fbuflen, bebf_latm_t::frame, bebf_latm_t::framelen, and NULL.

Referenced by faad_dispose(), and faad_reset().

## ◆ bebf_latm_configure()

static int bebf_latm_configure | ( | bebf_latm_t * | latm,
|  | uint32_t | nbits )
| static

Parse and export AAC configuration data.

Parameters

  latm | pointer to bebf_latm_t struct.
  nbits | count of input bits or 0.

Returns
  BEBF_LATM_GOT_CONF or 0.

References AOT_AAC_LC, AOT_ALS, AOT_ER_BSAC, AOT_PS, AOT_SBR, AOTF_CHAN, AOTF_CORE, AOTF_ELD, AOTF_EPCNF, AOTF_EXT1, AOTF_LAYER, AOTF_LDSBR, AOTF_RESIL, AOTF_SHORT, AOTF_SUBFR, bebf_latm_t::bebf, bebf_align(), bebf_copy(), bebf_flush(), bebf_get(), bebf_latm_flags, BEBF_LATM_GOT_CONF, bebf_seek(), bebf_set_write(), bebf_skip(), bebf_sniff(), bebf_tell(), bebf_latm_t::channel_conf, bebf_latm_t::channel_conf2, bebf_latm_t::confbuflen, bebf_latm_t::config, bebf_latm_t::conflen, bebf_latm_t::numchannels, bebf_latm_t::object_type, bebf_latm_t::object_type2, bebf_latm_t::ps, bebf_latm_t::samplerate, bebf_latm_t::samplerate2, bebf_latm_t::samplerate_index, bebf_latm_t::samplerate_index2, bebf_latm_t::samples, and bebf_latm_t::sbr.

Referenced by bebf_latm_demux().

## ◆ bebf_latm_demux()

static int bebf_latm_demux | ( | bebf_latm_t * | latm,
|  | const uint8_t * | in,
|  | uint32_t | nbytes )
| static

Demultiplex 1 LATM packet.

Parameters

  latm | pointer to bebf_latm_t struct.
  in | pointer to packet.
  nbytes | byte length of packet.

Returns
  BEBF_LATM_GOT_* flags.

References bebf_latm_t::bebf, bebf_copy(), bebf_flush(), bebf_get(), bebf_latm_configure(), BEBF_LATM_GOT_FRAME, bebf_set_read(), bebf_set_write(), bebf_skip(), bebf_tell(), bebf_latm_t::conflen, bebf_latm_t::fbuflen, bebf_latm_t::frame, bebf_latm_t::frame_len, bebf_latm_t::frame_len_type, bebf_latm_t::framelen, and bebf_latm_t::version.

Referenced by bebf_latm_parse().

## ◆ bebf_latm_open()

static void bebf_latm_open | ( | bebf_latm_t * | latm | ) |
| static

Referenced by faad_reset(), and open_plugin().

## ◆ bebf_latm_parse()

static int bebf_latm_parse | ( | bebf_latm_t * | latm,
|  | const uint8_t * | in,
|  | int * | nbytes )
| static

Parse and demux LATM.

Parameters

  latm | pointer to bebf_latm_t struct.
  in | pointer to input data.
  nbytes | pointer to byte count, will be adjusted to consumed.

Returns
  BEBF_LATM_GOT_* flags.

References bebf_latm_demux().

Referenced by faad_decode_audio().

## ◆ bebf_latm_test()

static bebf_latm_parser_status_t bebf_latm_test | ( | const uint8_t * | in,
|  | int | nbytes )
| static

Test if really LATM.

Parameters

  in | pointer to input data.
  nbytes | byte count.

Returns
  status.

References BEBF_LATM_IS_ADTS, BEBF_LATM_IS_LATM, BEBF_LATM_IS_UNKNOWN, BEBF_LATM_NEED_MORE_DATA, and BEBF_TEST_MAX.

Referenced by faad_decode_data().

## ◆ bebf_put()

static void bebf_put | ( | bebf_t * | bebf,
|  | uint32_t | bits,
|  | uint32_t | nbits )
| static

Write 1 .. 32 bits of data to write stream.

Parameters

  bebf | pointer to bebf_t struct to use.
  bits | The data to write, right justified.
  nbits | bit count.

References bebf_ADJ32, bits, bebf_t::writebits, bebf_t::writecache, and bebf_t::writeptr.

## ◆ bebf_seek()

static void bebf_seek | ( | bebf_t * | bebf,
|  | uint32_t | nbits )
| static

Jump to stream reader bit position.

Parameters

  bebf | pointer to bebf_t struct to use.
  nbits | new position in bits from the beginning.

References bebf_ADJ32, bebf_t::readbits, bebf_t::readcache, bebf_t::readptr, bebf_t::readstart, and bebf_t::readstop.

Referenced by bebf_latm_configure(), and bebf_set_read().

## ◆ bebf_set_read()

static void bebf_set_read | ( | bebf_t * | bebf,
|  | const uint8_t * | rp,
|  | uint32_t | nbytes )
| static

Initialize big endian bit stream reader.

Parameters

  bebf | pointer to bebf_t struct to use.
  rp | pointer to read stream, padded by at least 8 bytes.
  nbytes | byte length of input.

References bebf_seek(), bebf_t::readstart, and bebf_t::readstop.

Referenced by bebf_latm_demux().

## ◆ bebf_set_write()

static void bebf_set_write | ( | bebf_t * | bebf,
|  | uint8_t * | wp )
| static

Initialize big endian bit stream writer.

Parameters

  bebf | pointer to bebf_t struct to use.
  wp | pointer to 4 byte aligned write buffer.

References bebf_t::writebits, bebf_t::writecache, bebf_t::writeptr, and bebf_t::writestart.

Referenced by bebf_latm_configure(), and bebf_latm_demux().

## ◆ bebf_skip()

static void bebf_skip | ( | bebf_t * | bebf,
|  | uint32_t | nbits )
| static

Discard 1 .. 32 bits of data from read stream.

Parameters

  bebf | pointer to bebf_t struct to use.
  nbits | bit count.

References bebf_ADJ32, bebf_t::readbits, bebf_t::readcache, bebf_t::readptr, bebf_t::readstop, and v.

Referenced by bebf_latm_configure(), and bebf_latm_demux().

## ◆ bebf_sniff()

static uint32_t bebf_sniff | ( | bebf_t * | bebf,
|  | uint32_t | nbits )
| static

Sniff 1 .. 32 bits of data from read stream, not changing the stream position.

Parameters

  bebf | pointer to bebf_t struct to use.
  nbits | bit count.

Returns
  the requested data, right justified.

References bebf_ADJ32, bebf_t::readbits, bebf_t::readcache, bebf_t::readptr, bebf_t::readstop, and v.

Referenced by bebf_latm_configure().

## ◆ bebf_sync()

static int bebf_sync | ( | bebf_t * | bebf,
|  | uint32_t | pattern,
|  | uint32_t | pbits )
| static

Seek forward to right after next appearence of sync pattern.

Parameters

  bebf | pointer to bebf_t struct to use.
  pattern | the sync pattern to search for, right justified.
  pbits | bit length of pattern.

Returns
  1 (found), 0 (end of bitfile reached).

References bebf_ADJ32, bebf_t::readbits, bebf_t::readcache, bebf_t::readptr, bebf_t::readstop, and v.

## ◆ bebf_tell()

static uint32_t bebf_tell | ( | bebf_t * | bebf | ) |
| static

Tell current read stream position.

Parameters

  bebf | pointer to bebf_t struct to use.

Returns
  stream position in bits.

References bebf_t::readbits, bebf_t::readptr, and bebf_t::readstart.

Referenced by bebf_latm_configure(), and bebf_latm_demux().

## Variable Documentation

## ◆ bebf_latm_flags

const uint32_t bebf_latm_flags[40]
| static

Referenced by bebf_latm_configure().