FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions
pcm.c File Reference

PCM codecs. More...

#include "libavutil/attributes.h"
#include "libavutil/float_dsp.h"
#include "avcodec.h"
#include "bytestream.h"
#include "internal.h"
#include "mathops.h"
#include "pcm_tablegen.h"

Go to the source code of this file.

Data Structures

struct  PCMDecode
 

Macros

#define ENCODE(type, endian, src, dst, n, shift, offset)
 Write PCM samples macro. More...
 
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
 
#define DECODE(size, endian, src, dst, n, shift, offset)
 Read PCM samples macro. More...
 
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)
 
#define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
 
#define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_)
 
#define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)   PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
 
#define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name)   PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
 
#define PCM_ENCODER(id, sample_fmt, name, long_name)   PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)
 
#define PCM_DECODER_0(id, sample_fmt, name, long_name)
 
#define PCM_DECODER_1(id_, sample_fmt_, name_, long_name_)
 
#define PCM_DECODER_2(cf, id, sample_fmt, name, long_name)   PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)
 
#define PCM_DECODER_3(cf, id, sample_fmt, name, long_name)   PCM_DECODER_2(cf, id, sample_fmt, name, long_name)
 
#define PCM_DECODER(id, sample_fmt, name, long_name)   PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)
 
#define PCM_CODEC(id, sample_fmt_, name, long_name_)
 

Functions

static av_cold int pcm_encode_init (AVCodecContext *avctx)
 
static int pcm_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 
static av_cold int pcm_decode_init (AVCodecContext *avctx)
 
static av_cold int pcm_decode_close (AVCodecContext *avctx)
 
static int pcm_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
 
 PCM_CODEC (PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw,"PCM A-law / G.711 A-law")
 
 PCM_DECODER (PCM_F16LE, AV_SAMPLE_FMT_FLT, pcm_f16le,"PCM 16.8 floating point little-endian")
 
 PCM_DECODER (PCM_F24LE, AV_SAMPLE_FMT_FLT, pcm_f24le,"PCM 24.0 floating point little-endian")
 
 PCM_CODEC (PCM_F32BE, AV_SAMPLE_FMT_FLT, pcm_f32be,"PCM 32-bit floating point big-endian")
 
 PCM_CODEC (PCM_F32LE, AV_SAMPLE_FMT_FLT, pcm_f32le,"PCM 32-bit floating point little-endian")
 
 PCM_CODEC (PCM_F64BE, AV_SAMPLE_FMT_DBL, pcm_f64be,"PCM 64-bit floating point big-endian")
 
 PCM_CODEC (PCM_F64LE, AV_SAMPLE_FMT_DBL, pcm_f64le,"PCM 64-bit floating point little-endian")
 
 PCM_DECODER (PCM_LXF, AV_SAMPLE_FMT_S32P, pcm_lxf,"PCM signed 20-bit little-endian planar")
 
 PCM_CODEC (PCM_MULAW, AV_SAMPLE_FMT_S16, pcm_mulaw,"PCM mu-law / G.711 mu-law")
 
 PCM_CODEC (PCM_S8, AV_SAMPLE_FMT_U8, pcm_s8,"PCM signed 8-bit")
 
 PCM_CODEC (PCM_S8_PLANAR, AV_SAMPLE_FMT_U8P, pcm_s8_planar,"PCM signed 8-bit planar")
 
 PCM_CODEC (PCM_S16BE, AV_SAMPLE_FMT_S16, pcm_s16be,"PCM signed 16-bit big-endian")
 
 PCM_CODEC (PCM_S16BE_PLANAR, AV_SAMPLE_FMT_S16P, pcm_s16be_planar,"PCM signed 16-bit big-endian planar")
 
 PCM_CODEC (PCM_S16LE, AV_SAMPLE_FMT_S16, pcm_s16le,"PCM signed 16-bit little-endian")
 
 PCM_CODEC (PCM_S16LE_PLANAR, AV_SAMPLE_FMT_S16P, pcm_s16le_planar,"PCM signed 16-bit little-endian planar")
 
 PCM_CODEC (PCM_S24BE, AV_SAMPLE_FMT_S32, pcm_s24be,"PCM signed 24-bit big-endian")
 
 PCM_CODEC (PCM_S24DAUD, AV_SAMPLE_FMT_S16, pcm_s24daud,"PCM D-Cinema audio signed 24-bit")
 
 PCM_CODEC (PCM_S24LE, AV_SAMPLE_FMT_S32, pcm_s24le,"PCM signed 24-bit little-endian")
 
 PCM_CODEC (PCM_S24LE_PLANAR, AV_SAMPLE_FMT_S32P, pcm_s24le_planar,"PCM signed 24-bit little-endian planar")
 
 PCM_CODEC (PCM_S32BE, AV_SAMPLE_FMT_S32, pcm_s32be,"PCM signed 32-bit big-endian")
 
 PCM_CODEC (PCM_S32LE, AV_SAMPLE_FMT_S32, pcm_s32le,"PCM signed 32-bit little-endian")
 
 PCM_CODEC (PCM_S32LE_PLANAR, AV_SAMPLE_FMT_S32P, pcm_s32le_planar,"PCM signed 32-bit little-endian planar")
 
 PCM_CODEC (PCM_U8, AV_SAMPLE_FMT_U8, pcm_u8,"PCM unsigned 8-bit")
 
 PCM_CODEC (PCM_U16BE, AV_SAMPLE_FMT_S16, pcm_u16be,"PCM unsigned 16-bit big-endian")
 
 PCM_CODEC (PCM_U16LE, AV_SAMPLE_FMT_S16, pcm_u16le,"PCM unsigned 16-bit little-endian")
 
 PCM_CODEC (PCM_U24BE, AV_SAMPLE_FMT_S32, pcm_u24be,"PCM unsigned 24-bit big-endian")
 
 PCM_CODEC (PCM_U24LE, AV_SAMPLE_FMT_S32, pcm_u24le,"PCM unsigned 24-bit little-endian")
 
 PCM_CODEC (PCM_U32BE, AV_SAMPLE_FMT_S32, pcm_u32be,"PCM unsigned 32-bit big-endian")
 
 PCM_CODEC (PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le,"PCM unsigned 32-bit little-endian")
 
 PCM_DECODER (PCM_ZORK, AV_SAMPLE_FMT_U8, pcm_zork,"PCM Zork")
 
 PCM_CODEC (PCM_S64BE, AV_SAMPLE_FMT_S64, pcm_s64be,"PCM signed 64-bit big-endian")
 
 PCM_CODEC (PCM_S64LE, AV_SAMPLE_FMT_S64, pcm_s64le,"PCM signed 64-bit little-endian")
 

Detailed Description

PCM codecs.

Definition in file pcm.c.

Macro Definition Documentation

#define ENCODE (   type,
  endian,
  src,
  dst,
  n,
  shift,
  offset 
)
Value:
samples_ ## type = (const type *) src; \
for (; n > 0; n--) { \
register type v = (*samples_ ## type++ >> shift) + offset; \
bytestream_put_ ## endian(&dst, v); \
}
static int shift(int a, int b)
Definition: sonic.c:82
#define src
Definition: vp8dsp.c:254
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
int n
Definition: avisynth_c.h:684
GLint GLenum type
Definition: opengl_enc.c:105
for(j=16;j >0;--j)

Write PCM samples macro.

Parameters
typeDatatype of native machine format
endianbytestream_put_xxx() suffix
srcSource pointer (variable name)
dstDestination pointer (variable name)
nTotal number of samples (variable name)
shiftBitshift (bits)
offsetSample value offset

Definition at line 66 of file pcm.c.

Referenced by pcm_encode_frame().

#define ENCODE_PLANAR (   type,
  endian,
  dst,
  n,
  shift,
  offset 
)
Value:
n /= avctx->channels; \
for (c = 0; c < avctx->channels; c++) { \
int i; \
samples_ ## type = (const type *) frame->extended_data[c]; \
for (i = n; i > 0; i--) { \
register type v = (*samples_ ## type++ >> shift) + offset; \
bytestream_put_ ## endian(&dst, v); \
} \
}
static int shift(int a, int b)
Definition: sonic.c:82
static AVFrame * frame
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
int n
Definition: avisynth_c.h:684
GLint GLenum type
Definition: opengl_enc.c:105
int
static double c[64]
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:248
for(j=16;j >0;--j)

Definition at line 73 of file pcm.c.

Referenced by pcm_encode_frame().

#define DECODE (   size,
  endian,
  src,
  dst,
  n,
  shift,
  offset 
)
Value:
for (; n > 0; n--) { \
uint ## size ## _t v = bytestream_get_ ## endian(&src); \
AV_WN ## size ## A(dst, (v - offset) << shift); \
dst += size / 8; \
}
static int shift(int a, int b)
Definition: sonic.c:82
#define src
Definition: vp8dsp.c:254
#define AV_WN(s, p, v)
Definition: intreadwrite.h:225
ptrdiff_t size
Definition: opengl_enc.c:101
#define A(x)
Definition: vp56_arith.h:28
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
int n
Definition: avisynth_c.h:684

Read PCM samples macro.

Parameters
sizeData size of native machine format
endianbytestream_get_xxx() endian suffix
srcSource pointer (variable name)
dstDestination pointer (variable name)
nTotal number of samples (variable name)
shiftBitshift (bits)
offsetSample value offset

Definition at line 290 of file pcm.c.

Referenced by pcm_decode_frame().

#define DECODE_PLANAR (   size,
  endian,
  src,
  dst,
  n,
  shift,
  offset 
)
Value:
n /= avctx->channels; \
for (c = 0; c < avctx->channels; c++) { \
int i; \
for (i = n; i > 0; i--) { \
uint ## size ## _t v = bytestream_get_ ## endian(&src); \
AV_WN ## size ## A(dst, (v - offset) << shift); \
dst += size / 8; \
} \
}
static int shift(int a, int b)
Definition: sonic.c:82
#define src
Definition: vp8dsp.c:254
#define AV_WN(s, p, v)
Definition: intreadwrite.h:225
static AVFrame * frame
ptrdiff_t size
Definition: opengl_enc.c:101
#define A(x)
Definition: vp56_arith.h:28
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
int n
Definition: avisynth_c.h:684
int
static double c[64]
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:248
for(j=16;j >0;--j)

Definition at line 297 of file pcm.c.

Referenced by pcm_decode_frame().

#define PCM_ENCODER_0 (   id_,
  sample_fmt_,
  name_,
  long_name_ 
)

Definition at line 534 of file pcm.c.

#define PCM_ENCODER_1 (   id_,
  sample_fmt_,
  name_,
  long_name_ 
)
Value:
AVCodec ff_ ## name_ ## _encoder = { \
.name = #name_, \
.long_name = NULL_IF_CONFIG_SMALL(long_name_), \
.type = AVMEDIA_TYPE_AUDIO, \
.id = AV_CODEC_ID_ ## id_, \
.init = pcm_encode_init, \
.encode2 = pcm_encode_frame, \
.sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
}
static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: pcm.c:84
AVCodec.
Definition: avcodec.h:3739
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
const char * name
Name of the codec implementation.
Definition: avcodec.h:3746
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: avcodec.h:1081
static av_cold int pcm_encode_init(AVCodecContext *avctx)
Definition: pcm.c:35
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58

Definition at line 535 of file pcm.c.

#define PCM_ENCODER_2 (   cf,
  id,
  sample_fmt,
  name,
  long_name 
)    PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)

Definition at line 548 of file pcm.c.

#define PCM_ENCODER_3 (   cf,
  id,
  sample_fmt,
  name,
  long_name 
)    PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)

Definition at line 550 of file pcm.c.

#define PCM_ENCODER (   id,
  sample_fmt,
  name,
  long_name 
)    PCM_ENCODER_3(CONFIG_ ## id ## _ENCODER, id, sample_fmt, name, long_name)

Definition at line 552 of file pcm.c.

#define PCM_DECODER_0 (   id,
  sample_fmt,
  name,
  long_name 
)

Definition at line 555 of file pcm.c.

#define PCM_DECODER_1 (   id_,
  sample_fmt_,
  name_,
  long_name_ 
)
Value:
AVCodec ff_ ## name_ ## _decoder = { \
.name = #name_, \
.long_name = NULL_IF_CONFIG_SMALL(long_name_), \
.type = AVMEDIA_TYPE_AUDIO, \
.id = AV_CODEC_ID_ ## id_, \
.priv_data_size = sizeof(PCMDecode), \
.close = pcm_decode_close, \
.capabilities = AV_CODEC_CAP_DR1, \
.sample_fmts = (const enum AVSampleFormat[]){ sample_fmt_, \
}
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AVCodec.
Definition: avcodec.h:3739
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
Definition: pcm.c:227
static av_cold int pcm_decode_close(AVCodecContext *avctx)
Definition: pcm.c:271
static int pcm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: pcm.c:309
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
const char * name
Name of the codec implementation.
Definition: avcodec.h:3746
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
static av_cold int pcm_decode_init(AVCodecContext *avctx)
Definition: pcm.c:233
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:1002

Definition at line 556 of file pcm.c.

#define PCM_DECODER_2 (   cf,
  id,
  sample_fmt,
  name,
  long_name 
)    PCM_DECODER_ ## cf(id, sample_fmt, name, long_name)

Definition at line 571 of file pcm.c.

#define PCM_DECODER_3 (   cf,
  id,
  sample_fmt,
  name,
  long_name 
)    PCM_DECODER_2(cf, id, sample_fmt, name, long_name)

Definition at line 573 of file pcm.c.

#define PCM_DECODER (   id,
  sample_fmt,
  name,
  long_name 
)    PCM_DECODER_3(CONFIG_ ## id ## _DECODER, id, sample_fmt, name, long_name)

Definition at line 575 of file pcm.c.

#define PCM_CODEC (   id,
  sample_fmt_,
  name,
  long_name_ 
)
Value:
PCM_ENCODER(id, sample_fmt_, name, long_name_); \
PCM_DECODER(id, sample_fmt_, name, long_name_)
#define PCM_DECODER(id, sample_fmt, name, long_name)
Definition: pcm.c:575
#define PCM_ENCODER(id, sample_fmt, name, long_name)
Definition: pcm.c:552
const char * name
Definition: opengl_enc.c:103

Definition at line 578 of file pcm.c.

Function Documentation

static av_cold int pcm_encode_init ( AVCodecContext avctx)
static

Definition at line 35 of file pcm.c.

static int pcm_encode_frame ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int got_packet_ptr 
)
static

Definition at line 84 of file pcm.c.

static av_cold int pcm_decode_init ( AVCodecContext avctx)
static

Definition at line 233 of file pcm.c.

static av_cold int pcm_decode_close ( AVCodecContext avctx)
static

Definition at line 271 of file pcm.c.

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

Definition at line 309 of file pcm.c.

PCM_CODEC ( PCM_ALAW  ,
AV_SAMPLE_FMT_S16  ,
pcm_alaw  ,
"PCM A-law / G.711 A-law"   
)
PCM_DECODER ( PCM_F16LE  ,
AV_SAMPLE_FMT_FLT  ,
pcm_f16le  ,
"PCM 16.8 floating point little-endian"   
)
PCM_DECODER ( PCM_F24LE  ,
AV_SAMPLE_FMT_FLT  ,
pcm_f24le  ,
"PCM 24.0 floating point little-endian"   
)
PCM_CODEC ( PCM_F32BE  ,
AV_SAMPLE_FMT_FLT  ,
pcm_f32be  ,
"PCM 32-bit floating point big-endian"   
)
PCM_CODEC ( PCM_F32LE  ,
AV_SAMPLE_FMT_FLT  ,
pcm_f32le  ,
"PCM 32-bit floating point little-endian"   
)
PCM_CODEC ( PCM_F64BE  ,
AV_SAMPLE_FMT_DBL  ,
pcm_f64be  ,
"PCM 64-bit floating point big-endian"   
)
PCM_CODEC ( PCM_F64LE  ,
AV_SAMPLE_FMT_DBL  ,
pcm_f64le  ,
"PCM 64-bit floating point little-endian"   
)
PCM_DECODER ( PCM_LXF  ,
AV_SAMPLE_FMT_S32P  ,
pcm_lxf  ,
"PCM signed 20-bit little-endian planar  
)
PCM_CODEC ( PCM_MULAW  ,
AV_SAMPLE_FMT_S16  ,
pcm_mulaw  ,
"PCM mu-law / G.711 mu-law"   
)
PCM_CODEC ( PCM_S8  ,
AV_SAMPLE_FMT_U8  ,
pcm_s8  ,
"PCM signed 8-bit"   
)
PCM_CODEC ( PCM_S8_PLANAR  ,
AV_SAMPLE_FMT_U8P  ,
pcm_s8_planar  ,
"PCM signed 8-bit planar  
)
PCM_CODEC ( PCM_S16BE  ,
AV_SAMPLE_FMT_S16  ,
pcm_s16be  ,
"PCM signed 16-bit big-endian"   
)
PCM_CODEC ( PCM_S16BE_PLANAR  ,
AV_SAMPLE_FMT_S16P  ,
pcm_s16be_planar  ,
"PCM signed 16-bit big-endian planar  
)
PCM_CODEC ( PCM_S16LE  ,
AV_SAMPLE_FMT_S16  ,
pcm_s16le  ,
"PCM signed 16-bit little-endian"   
)
PCM_CODEC ( PCM_S16LE_PLANAR  ,
AV_SAMPLE_FMT_S16P  ,
pcm_s16le_planar  ,
"PCM signed 16-bit little-endian planar  
)
PCM_CODEC ( PCM_S24BE  ,
AV_SAMPLE_FMT_S32  ,
pcm_s24be  ,
"PCM signed 24-bit big-endian"   
)
PCM_CODEC ( PCM_S24DAUD  ,
AV_SAMPLE_FMT_S16  ,
pcm_s24daud  ,
"PCM D-Cinema audio signed 24-bit"   
)
PCM_CODEC ( PCM_S24LE  ,
AV_SAMPLE_FMT_S32  ,
pcm_s24le  ,
"PCM signed 24-bit little-endian"   
)
PCM_CODEC ( PCM_S24LE_PLANAR  ,
AV_SAMPLE_FMT_S32P  ,
pcm_s24le_planar  ,
"PCM signed 24-bit little-endian planar  
)
PCM_CODEC ( PCM_S32BE  ,
AV_SAMPLE_FMT_S32  ,
pcm_s32be  ,
"PCM signed 32-bit big-endian"   
)
PCM_CODEC ( PCM_S32LE  ,
AV_SAMPLE_FMT_S32  ,
pcm_s32le  ,
"PCM signed 32-bit little-endian"   
)
PCM_CODEC ( PCM_S32LE_PLANAR  ,
AV_SAMPLE_FMT_S32P  ,
pcm_s32le_planar  ,
"PCM signed 32-bit little-endian planar  
)
PCM_CODEC ( PCM_U8  ,
AV_SAMPLE_FMT_U8  ,
pcm_u8  ,
"PCM unsigned 8-bit"   
)
PCM_CODEC ( PCM_U16BE  ,
AV_SAMPLE_FMT_S16  ,
pcm_u16be  ,
"PCM unsigned 16-bit big-endian"   
)
PCM_CODEC ( PCM_U16LE  ,
AV_SAMPLE_FMT_S16  ,
pcm_u16le  ,
"PCM unsigned 16-bit little-endian"   
)
PCM_CODEC ( PCM_U24BE  ,
AV_SAMPLE_FMT_S32  ,
pcm_u24be  ,
"PCM unsigned 24-bit big-endian"   
)
PCM_CODEC ( PCM_U24LE  ,
AV_SAMPLE_FMT_S32  ,
pcm_u24le  ,
"PCM unsigned 24-bit little-endian"   
)
PCM_CODEC ( PCM_U32BE  ,
AV_SAMPLE_FMT_S32  ,
pcm_u32be  ,
"PCM unsigned 32-bit big-endian"   
)
PCM_CODEC ( PCM_U32LE  ,
AV_SAMPLE_FMT_S32  ,
pcm_u32le  ,
"PCM unsigned 32-bit little-endian"   
)
PCM_DECODER ( PCM_ZORK  ,
AV_SAMPLE_FMT_U8  ,
pcm_zork  ,
"PCM Zork"   
)
PCM_CODEC ( PCM_S64BE  ,
AV_SAMPLE_FMT_S64  ,
pcm_s64be  ,
"PCM signed 64-bit big-endian"   
)
PCM_CODEC ( PCM_S64LE  ,
AV_SAMPLE_FMT_S64  ,
pcm_s64le  ,
"PCM signed 64-bit little-endian"   
)