Go to the documentation of this file.
28 #include "config_components.h"
44 #if !CONFIG_HARDCODED_TABLES
46 #if CONFIG_PCM_ALAW_ENCODER
53 #if CONFIG_PCM_MULAW_ENCODER
60 #if CONFIG_PCM_VIDC_ENCODER
89 #define ENCODE(type, endian, src, dst, n, shift, offset) \
90 samples_ ## type = (const type *) src; \
91 for (; n > 0; n--) { \
92 register type v = (*samples_ ## type++ >> shift) + offset; \
93 bytestream_put_ ## endian(&dst, v); \
96 #define ENCODE_PLANAR(type, endian, dst, n, shift, offset) \
97 n /= avctx->ch_layout.nb_channels; \
98 for (c = 0; c < avctx->ch_layout.nb_channels; c++) { \
100 samples_ ## type = (const type *) frame->extended_data[c]; \
101 for (i = n; i > 0; i--) { \
102 register type v = (*samples_ ## type++ >> shift) + offset; \
103 bytestream_put_ ## endian(&dst, v); \
110 int n,
c, sample_size, v,
ret;
113 const uint8_t *samples_uint8_t;
114 const int16_t *samples_int16_t;
115 const int32_t *samples_int32_t;
116 const int64_t *samples_int64_t;
117 const uint16_t *samples_uint16_t;
118 const uint32_t *samples_uint32_t;
155 bytestream_put_be24(&
dst,
tmp);
226 const uint8_t *
src =
frame->extended_data[
c];
230 #if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
234 *
dst++ = linear_to_alaw[(v + 32768) >> 2];
238 #if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
242 *
dst++ = linear_to_ulaw[(v + 32768) >> 2];
246 #if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
250 *
dst++ = linear_to_vidc[(v + 32768) >> 2];
269 static const struct {
273 uint8_t bits_per_sample;
274 } codec_id_to_samplefmt[] = {
275 #define ENTRY(CODEC_ID, SAMPLE_FMT, BITS_PER_SAMPLE) \
276 { AV_CODEC_ID_PCM_ ## CODEC_ID, AV_SAMPLE_FMT_ ## SAMPLE_FMT, \
277 BITS_PER_SAMPLE / 8, BITS_PER_SAMPLE }
279 ENTRY(S16BE, S16, 16),
ENTRY(S16BE_PLANAR, S16P, 16),
280 ENTRY(S16LE, S16, 16),
ENTRY(S16LE_PLANAR, S16P, 16),
281 ENTRY(S24DAUD, S16, 24),
ENTRY(S24BE, S32, 24),
282 ENTRY(S24LE, S32, 24),
ENTRY(S24LE_PLANAR, S32P, 24),
284 ENTRY(S32LE_PLANAR, S32P, 32),
297 s->sample_size = codec_id_to_samplefmt[
i].sample_size;
298 avctx->
sample_fmt = codec_id_to_samplefmt[
i].sample_fmt;
322 s->base.sample_size = 4;
348 av_unreachable(
"pcm_lut_decode_init() only used with alaw, mulaw and vidc");
349 #if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
351 for (
int i = 0;
i < 256;
i++)
352 s->table[
i] = alaw2linear(
i);
355 #if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
357 for (
int i = 0;
i < 256;
i++)
358 s->table[
i] = ulaw2linear(
i);
361 #if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
363 for (
int i = 0;
i < 256;
i++)
364 s->table[
i] = vidc2linear(
i);
370 s->base.sample_size = 1;
385 #define DECODE(size, endian, src, dst, n, shift, offset) \
386 for (; n > 0; n--) { \
387 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
388 AV_WN ## size ## A(dst, (uint ## size ## _t)(v - offset) << shift); \
392 #define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
394 for (c = 0; c < avctx->ch_layout.nb_channels; c++) { \
396 dst = frame->extended_data[c]; \
397 for (i = n; i > 0; i--) { \
398 uint ## size ## _t v = bytestream_get_ ## endian(&src); \
399 AV_WN ## size ## A(dst, (uint ## size ##_t)(v - offset) << shift); \
405 int *got_frame_ptr,
AVPacket *avpkt)
407 const uint8_t *
src = avpkt->
data;
408 int buf_size = avpkt->
size;
411 int sample_size =
s->sample_size;
412 int c, n,
ret, samples_per_block;
416 samples_per_block = 1;
419 samples_per_block = 2;
434 if (n && buf_size % n) {
437 "Invalid PCM packet, data has size %d but at least a size of %d was expected\n",
441 buf_size -= buf_size % n;
444 n = buf_size / sample_size;
476 uint32_t v = bytestream_get_be24(&
src);
495 int sign = *
src >> 7;
496 int magn = *
src & 0x7f;
497 *
samples++ = sign ? 128 - magn : 128 + magn;
506 for (
i = n;
i > 0;
i--)
573 #if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER || \
574 CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER || \
575 CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
580 int16_t *restrict samples_16 = (int16_t*)
samples;
583 *samples_16++ = lut[*
src++];
595 *dst_int32_t++ = ((uint32_t)
src[2]<<28) |
598 ((
src[2] & 0x0F) << 8) |
601 *dst_int32_t++ = ((uint32_t)
src[4]<<24) |
603 ((
src[2] & 0xF0) << 8) |
619 (
const float *)
frame->extended_data[0],
628 #define PCM_ENCODER_0(id_, sample_fmt_, name_, long_name_)
629 #define PCM_ENCODER_1(id_, sample_fmt_, name_, long_name_) \
630 const FFCodec ff_ ## name_ ## _encoder = { \
632 CODEC_LONG_NAME(long_name_), \
633 .p.type = AVMEDIA_TYPE_AUDIO, \
635 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_VARIABLE_FRAME_SIZE | \
636 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, \
637 .init = pcm_encode_init, \
638 FF_CODEC_ENCODE_CB(pcm_encode_frame), \
639 CODEC_SAMPLEFMTS(sample_fmt_), \
642 #define PCM_ENCODER_2(cf, id, sample_fmt, name, long_name) \
643 PCM_ENCODER_ ## cf(id, sample_fmt, name, long_name)
644 #define PCM_ENCODER_3(cf, id, sample_fmt, name, long_name) \
645 PCM_ENCODER_2(cf, id, sample_fmt, name, long_name)
646 #define PCM_ENCODER(id, sample_fmt, name, long_name) \
647 PCM_ENCODER_3(CONFIG_PCM_ ## id ## _ENCODER, AV_CODEC_ID_PCM_ ## id, \
648 AV_SAMPLE_FMT_ ## sample_fmt, pcm_ ## name, long_name)
650 #define PCM_DECODER_0(id, sample_fmt, name, long_name, Context, init_func)
651 #define PCM_DECODER_1(id_, sample_fmt, name_, long_name, Context, init_func)\
652 const FFCodec ff_ ## name_ ## _decoder = { \
654 CODEC_LONG_NAME(long_name), \
655 .p.type = AVMEDIA_TYPE_AUDIO, \
657 .priv_data_size = sizeof(Context), \
659 FF_CODEC_DECODE_CB(pcm_decode_frame), \
660 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_PARAM_CHANGE, \
663 #define PCM_DECODER_2(cf, id, sample_fmt, name, long_name, Context, init_func) \
664 PCM_DECODER_ ## cf(id, sample_fmt, name, long_name, Context, init_func)
665 #define PCM_DECODER_3(cf, id, sample_fmt, name, long_name, Context, init_func) \
666 PCM_DECODER_2(cf, id, sample_fmt, name, long_name, Context, init_func)
667 #define PCM_DEC_EXT(id, sample_fmt, name, long_name, Context, init_func) \
668 PCM_DECODER_3(CONFIG_PCM_ ## id ## _DECODER, AV_CODEC_ID_PCM_ ## id, \
669 AV_SAMPLE_FMT_ ## sample_fmt, pcm_ ## name, long_name, \
672 #define PCM_DECODER(id, sample_fmt, name, long_name) \
673 PCM_DEC_EXT(id, sample_fmt, name, long_name, PCMDecode, pcm_decode_init)
675 #define PCM_CODEC(id, sample_fmt_, name, long_name_) \
676 PCM_ENCODER(id, sample_fmt_, name, long_name_); \
677 PCM_DECODER(id, sample_fmt_, name, long_name_)
679 #define PCM_CODEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func) \
680 PCM_DEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func); \
681 PCM_ENCODER(id, sample_fmt, name, long_name)
687 #if CONFIG_PCM_ALAW_DECODER || CONFIG_PCM_ALAW_ENCODER
692 PCM_CODEC (F32BE, FLT, f32be,
"PCM 32-bit floating point big-endian");
693 PCM_CODEC (F32LE, FLT, f32le,
"PCM 32-bit floating point little-endian");
694 PCM_CODEC (F64BE, DBL, f64be,
"PCM 64-bit floating point big-endian");
695 PCM_CODEC (F64LE, DBL, f64le,
"PCM 64-bit floating point little-endian");
696 PCM_DECODER (LXF, S32P,lxf,
"PCM signed 20-bit little-endian planar");
697 #if CONFIG_PCM_MULAW_DECODER || CONFIG_PCM_MULAW_ENCODER
701 PCM_CODEC (S8_PLANAR, U8P, s8_planar,
"PCM signed 8-bit planar");
702 PCM_CODEC (S16BE, S16, s16be,
"PCM signed 16-bit big-endian");
703 PCM_CODEC (S16BE_PLANAR, S16P,s16be_planar,
"PCM signed 16-bit big-endian planar");
704 PCM_CODEC (S16LE, S16, s16le,
"PCM signed 16-bit little-endian");
705 PCM_CODEC (S16LE_PLANAR, S16P,s16le_planar,
"PCM signed 16-bit little-endian planar");
706 PCM_CODEC (S24BE, S32, s24be,
"PCM signed 24-bit big-endian");
707 PCM_CODEC (S24DAUD, S16, s24daud,
"PCM D-Cinema audio signed 24-bit");
708 PCM_CODEC (S24LE, S32, s24le,
"PCM signed 24-bit little-endian");
709 PCM_CODEC (S24LE_PLANAR, S32P,s24le_planar,
"PCM signed 24-bit little-endian planar");
710 PCM_CODEC (S32BE, S32, s32be,
"PCM signed 32-bit big-endian");
711 PCM_CODEC (S32LE, S32, s32le,
"PCM signed 32-bit little-endian");
712 PCM_CODEC (S32LE_PLANAR, S32P,s32le_planar,
"PCM signed 32-bit little-endian planar");
714 PCM_CODEC (U16BE, S16, u16be,
"PCM unsigned 16-bit big-endian");
715 PCM_CODEC (U16LE, S16, u16le,
"PCM unsigned 16-bit little-endian");
716 PCM_CODEC (U24BE, S32, u24be,
"PCM unsigned 24-bit big-endian");
717 PCM_CODEC (U24LE, S32, u24le,
"PCM unsigned 24-bit little-endian");
718 PCM_CODEC (U32BE, S32, u32be,
"PCM unsigned 32-bit big-endian");
719 PCM_CODEC (U32LE, S32, u32le,
"PCM unsigned 32-bit little-endian");
720 PCM_CODEC (S64BE, S64, s64be,
"PCM signed 64-bit big-endian");
721 PCM_CODEC (S64LE, S64, s64le,
"PCM signed 64-bit little-endian");
722 #if CONFIG_PCM_VIDC_DECODER || CONFIG_PCM_VIDC_ENCODER
int frame_size
Number of samples per channel in an audio frame.
#define PCM_CODEC_EXT(id, sample_fmt, name, long_name, DecContext, dec_init_func)
#define PCM_CODEC(id, sample_fmt_, name, long_name_)
uint64_t_TMPL AV_WL64 unsigned int_TMPL le32
static av_cold av_unused int pcm_decode_init(AVCodecContext *avctx)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define ENCODE(type, endian, src, dst, n, shift, offset)
Write PCM samples macro.
int sample_rate
samples per second
@ AV_CODEC_ID_PCM_S32LE_PLANAR
This structure describes decoded (raw) audio or video data.
@ AV_CODEC_ID_PCM_S16BE_PLANAR
const uint8_t ff_reverse[256]
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
int nb_channels
Number of channels in this layout.
@ AV_CODEC_ID_PCM_S16LE_PLANAR
const struct AVCodec * codec
AVChannelLayout ch_layout
Audio channel layout.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL be24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL le24
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
#define PCM_DECODER(id, sample_fmt, name, long_name)
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
static int ff_thread_once(char *control, void(*routine)(void))
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
#define ENTRY(CODEC_ID, SAMPLE_FMT, BITS_PER_SAMPLE)
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
int64_t bit_rate
the average bitrate
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL be64
static av_cold av_unused int pcm_lut_decode_init(AVCodecContext *avctx)
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset)
static int pcm_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL be32
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
@ AV_CODEC_ID_PCM_S24LE_PLANAR
AVCodecID
Identify the syntax and semantics of the bitstream.
static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
enum AVSampleFormat sample_fmt
audio sample format
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
#define ENCODE_PLANAR(type, endian, dst, n, shift, offset)
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
#define i(width, name, range_min, range_max)
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
@ AV_SAMPLE_FMT_S16
signed 16 bits
static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size)
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL be16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL le16
#define PCM_DEC_EXT(id, sample_fmt, name, long_name, Context, init_func)
main external API structure.
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Filter the word “frame” indicates either a video frame or a group of audio samples
@ AV_CODEC_ID_PCM_S24DAUD
static av_cold int pcm_encode_init(AVCodecContext *avctx)
This structure stores compressed data.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
@ AV_CODEC_ID_PCM_S8_PLANAR
static const uint32_t S8[256]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static av_cold av_unused int pcm_scale_decode_init(AVCodecContext *avctx)
@ AV_SAMPLE_FMT_S32
signed 32 bits