samplefmt.c File Reference
#include "common.h"
#include "samplefmt.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for samplefmt.c:

Go to the source code of this file.

Data Structures

struct  SampleFmtInfo
 

Typedefs

typedef struct SampleFmtInfo SampleFmtInfo
 

Functions

const char * av_get_sample_fmt_name (enum AVSampleFormat sample_fmt)
 Return the name of sample_fmt, or NULL if sample_fmt is not recognized. More...
 
enum AVSampleFormat av_get_sample_fmt (const char *name)
 Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error. More...
 
enum AVSampleFormat av_get_alt_sample_fmt (enum AVSampleFormat sample_fmt, int planar)
 Return the planar<->packed alternative form of the given sample format, or AV_SAMPLE_FMT_NONE on error. More...
 
enum AVSampleFormat av_get_packed_sample_fmt (enum AVSampleFormat sample_fmt)
 Get the packed alternative form of the given sample format. More...
 
enum AVSampleFormat av_get_planar_sample_fmt (enum AVSampleFormat sample_fmt)
 Get the planar alternative form of the given sample format. More...
 
char * av_get_sample_fmt_string (char *buf, int buf_size, enum AVSampleFormat sample_fmt)
 Generate a string corresponding to the sample format with sample_fmt, or a header if sample_fmt is negative. More...
 
int av_get_bytes_per_sample (enum AVSampleFormat sample_fmt)
 Return number of bytes per sample. More...
 
int av_get_bits_per_sample_fmt (enum AVSampleFormat sample_fmt)
 
int av_sample_fmt_is_planar (enum AVSampleFormat sample_fmt)
 Check if the sample format is planar. More...
 
int av_samples_get_buffer_size (int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
 Get the required buffer size for the given audio parameters. More...
 
int av_samples_fill_arrays (uint8_t **audio_data, int *linesize, const uint8_t *buf, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
 Fill plane data pointers and linesize for samples with sample format sample_fmt. More...
 
int av_samples_alloc (uint8_t **audio_data, int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
 Allocate a samples buffer for nb_samples samples, and fill data pointers and linesize accordingly. More...
 
int av_samples_alloc_array_and_samples (uint8_t ***audio_data, int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
 Allocate a data pointers array, samples buffer for nb_samples samples, and fill data pointers and linesize accordingly. More...
 
int av_samples_copy (uint8_t **dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
 Copy samples from src to dst. More...
 
int av_samples_set_silence (uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
 Fill an audio buffer with silence. More...
 

Variables

static const SampleFmtInfo sample_fmt_info [AV_SAMPLE_FMT_NB]
 this table gives more information about formats More...
 

Typedef Documentation

typedef struct SampleFmtInfo SampleFmtInfo

Function Documentation

enum AVSampleFormat av_get_alt_sample_fmt ( enum AVSampleFormat  sample_fmt,
int  planar 
)

Return the planar<->packed alternative form of the given sample format, or AV_SAMPLE_FMT_NONE on error.

If the passed sample_fmt is already in the requested planar/packed format, the format returned is the same as the input.

Definition at line 64 of file samplefmt.c.

Referenced by get(), set(), and shift().

int av_get_bits_per_sample_fmt ( enum AVSampleFormat  sample_fmt)
Deprecated:
Use av_get_bytes_per_sample() instead.

Definition at line 111 of file samplefmt.c.

enum AVSampleFormat av_get_packed_sample_fmt ( enum AVSampleFormat  sample_fmt)

Get the packed alternative form of the given sample format.

If the passed sample_fmt is already in packed format, the format returned is the same as the input.

Returns
the packed alternative form of the given sample format or AV_SAMPLE_FMT_NONE on error.

Definition at line 73 of file samplefmt.c.

Referenced by auto_matrix(), cmp_audio_fmts(), ff_audio_convert_set_func(), ff_dither_alloc(), ff_volume_init_x86(), filter_frame(), PUT_FUNC(), swap_sample_fmts_on_filter(), swri_dither_init(), and volume_init().

enum AVSampleFormat av_get_planar_sample_fmt ( enum AVSampleFormat  sample_fmt)

Get the planar alternative form of the given sample format.

If the passed sample_fmt is already in planar format, the format returned is the same as the input.

Returns
the planar alternative form of the given sample format or AV_SAMPLE_FMT_NONE on error.

Definition at line 82 of file samplefmt.c.

Referenced by avcodec_open2(), avresample_open(), config_output(), swap_sample_fmts_on_filter(), and swr_init().

enum AVSampleFormat av_get_sample_fmt ( const char *  name)

Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.

Definition at line 54 of file samplefmt.c.

Referenced by av_opt_set(), ff_parse_sample_format(), init(), init_audio(), and new_audio_stream().

char* av_get_sample_fmt_string ( char *  buf,
int  buf_size,
enum AVSampleFormat  sample_fmt 
)

Generate a string corresponding to the sample format with sample_fmt, or a header if sample_fmt is negative.

Parameters
bufthe buffer where to write the string
buf_sizethe size of buf
sample_fmtthe number of the sample format to print the corresponding info string, or a negative value to print the corresponding header.
Returns
the pointer to the filled buffer or NULL if sample_fmt is unknown or in case of other errors

Definition at line 91 of file samplefmt.c.

Referenced by show_sample_fmts().

int av_samples_alloc ( uint8_t **  audio_data,
int *  linesize,
int  nb_channels,
int  nb_samples,
enum AVSampleFormat  sample_fmt,
int  align 
)

Allocate a samples buffer for nb_samples samples, and fill data pointers and linesize accordingly.

The allocated samples buffer can be freed by using av_freep(&audio_data[0]) Allocated data will be initialized to silence.

See also
enum AVSampleFormat The documentation for AVSampleFormat describes the data layout.
Parameters
[out]audio_dataarray to be filled with the pointer for each channel
[out]linesizealigned size for audio buffer(s), may be NULL
nb_channelsnumber of audio channels
nb_samplesnumber of samples per channel
alignbuffer size alignment (0 = default, 1 = no alignment)
Returns
>=0 on success or a negative error code on failure
Todo:
return the size of the allocated buffer in case of success at the next bump
See also
av_samples_fill_arrays()
av_samples_alloc_array_and_samples()

Definition at line 181 of file samplefmt.c.

Referenced by av_samples_alloc_array_and_samples(), decode_packet(), ff_audio_data_realloc(), and main().

int av_samples_alloc_array_and_samples ( uint8_t ***  audio_data,
int *  linesize,
int  nb_channels,
int  nb_samples,
enum AVSampleFormat  sample_fmt,
int  align 
)

Allocate a data pointers array, samples buffer for nb_samples samples, and fill data pointers and linesize accordingly.

This is the same as av_samples_alloc(), but also allocates the data pointers array.

See also
av_samples_alloc()

Definition at line 210 of file samplefmt.c.

Referenced by main().

int av_samples_copy ( uint8_t **  dst,
uint8_t *const *  src,
int  dst_offset,
int  src_offset,
int  nb_samples,
int  nb_channels,
enum AVSampleFormat  sample_fmt 
)

Copy samples from src to dst.

Parameters
dstdestination array of pointers to data planes
srcsource array of pointers to data planes
dst_offsetoffset in samples at which the data will be written to dst
src_offsetoffset in samples at which the data will be read from src
nb_samplesnumber of samples to be copied
nb_channelsnumber of audio channels
sample_fmtaudio sample format

Definition at line 225 of file samplefmt.c.

Referenced by av_frame_make_writable(), av_frame_ref(), avcodec_decode_audio4(), decode_packet(), ff_filter_frame_framed(), ff_filter_frame_needs_framing(), pad_last_frame(), and return_audio_frame().

int av_samples_fill_arrays ( uint8_t **  audio_data,
int *  linesize,
const uint8_t buf,
int  nb_channels,
int  nb_samples,
enum AVSampleFormat  sample_fmt,
int  align 
)

Fill plane data pointers and linesize for samples with sample format sample_fmt.

The audio_data array is filled with the pointers to the samples data planes: for planar, set the start point of each channel's data within the buffer, for packed, set the start point of the entire buffer only.

The value pointed to by linesize is set to the aligned size of each channel's data buffer for planar layout, or to the aligned size of the buffer for all channels for packed layout.

The buffer in buf must be big enough to contain all the samples (use av_samples_get_buffer_size() to compute its minimum size), otherwise the audio_data pointers will point to invalid data.

See also
enum AVSampleFormat The documentation for AVSampleFormat describes the data layout.
Parameters
[out]audio_dataarray to be filled with the pointer for each channel
[out]linesizecalculated linesize, may be NULL
bufthe pointer to a buffer containing the samples
nb_channelsthe number of channels
nb_samplesthe number of samples in a single channel
sample_fmtthe sample format
alignbuffer size alignment (0 = default, 1 = no alignment)
Returns
>=0 on success or a negative error code on failure
Todo:
return minimum size in bytes required for the buffer in case of success at the next bump

Definition at line 155 of file samplefmt.c.

Referenced by allocate_buffers(), av_samples_alloc(), avcodec_fill_audio_frame(), dca_decode_frame(), ff_audio_data_realloc(), main(), and tak_decode_frame().

int av_samples_get_buffer_size ( int *  linesize,
int  nb_channels,
int  nb_samples,
enum AVSampleFormat  sample_fmt,
int  align 
)

Get the required buffer size for the given audio parameters.

Parameters
[out]linesizecalculated linesize, may be NULL
nb_channelsthe number of channels
nb_samplesthe number of samples in a single channel
sample_fmtthe sample format
alignbuffer size alignment (0 = default, 1 = no alignment)
Returns
required buffer size, or negative error code on failure

Definition at line 125 of file samplefmt.c.

Referenced by allocate_buffers(), audio_decode_example(), audio_decode_frame(), audio_encode_example(), av_audio_fifo_alloc(), av_audio_fifo_realloc(), av_samples_alloc(), av_samples_fill_arrays(), avcodec_decode_audio3(), avcodec_encode_audio(), avcodec_fill_audio_frame(), dca_decode_frame(), decode_packet(), ff_audio_data_realloc(), ff_default_get_audio_buffer(), get_audio_buffer(), main(), pad_last_frame(), sdl_audio_callback(), stream_component_open(), tak_decode_frame(), and update_frame_pool().

int av_samples_set_silence ( uint8_t **  audio_data,
int  offset,
int  nb_samples,
int  nb_channels,
enum AVSampleFormat  sample_fmt 
)

Fill an audio buffer with silence.

Parameters
audio_dataarray of pointers to data planes
offsetoffset in samples at which to start filling
nb_samplesnumber of samples to fill
nb_channelsnumber of audio channels
sample_fmtaudio sample format

Definition at line 249 of file samplefmt.c.

Referenced by av_samples_alloc(), ff_audio_data_copy(), ff_audio_mix(), ff_default_get_audio_buffer(), filter_frame(), if(), pad_last_frame(), push_samples(), request_frame(), return_audio_frame(), and send_silence().

Variable Documentation

const SampleFmtInfo sample_fmt_info[AV_SAMPLE_FMT_NB]
static
Initial value:
= {
[AV_SAMPLE_FMT_U8] = { .name = "u8", .bits = 8, .planar = 0, .altform = AV_SAMPLE_FMT_U8P },
[AV_SAMPLE_FMT_S16] = { .name = "s16", .bits = 16, .planar = 0, .altform = AV_SAMPLE_FMT_S16P },
[AV_SAMPLE_FMT_S32] = { .name = "s32", .bits = 32, .planar = 0, .altform = AV_SAMPLE_FMT_S32P },
[AV_SAMPLE_FMT_FLT] = { .name = "flt", .bits = 32, .planar = 0, .altform = AV_SAMPLE_FMT_FLTP },
[AV_SAMPLE_FMT_DBL] = { .name = "dbl", .bits = 64, .planar = 0, .altform = AV_SAMPLE_FMT_DBLP },
[AV_SAMPLE_FMT_U8P] = { .name = "u8p", .bits = 8, .planar = 1, .altform = AV_SAMPLE_FMT_U8 },
[AV_SAMPLE_FMT_S16P] = { .name = "s16p", .bits = 16, .planar = 1, .altform = AV_SAMPLE_FMT_S16 },
[AV_SAMPLE_FMT_S32P] = { .name = "s32p", .bits = 32, .planar = 1, .altform = AV_SAMPLE_FMT_S32 },
[AV_SAMPLE_FMT_FLTP] = { .name = "fltp", .bits = 32, .planar = 1, .altform = AV_SAMPLE_FMT_FLT },
[AV_SAMPLE_FMT_DBLP] = { .name = "dblp", .bits = 64, .planar = 1, .altform = AV_SAMPLE_FMT_DBL },
}
signed 16 bits
Definition: samplefmt.h:52
AV_SAMPLE_FMT_U8
signed 32 bits, planar
Definition: samplefmt.h:59
float, planar
Definition: samplefmt.h:60
signed 32 bits
Definition: samplefmt.h:53
unsigned 8 bits, planar
Definition: samplefmt.h:57
signed 16 bits, planar
Definition: samplefmt.h:58
double, planar
Definition: samplefmt.h:61

this table gives more information about formats

Definition at line 34 of file samplefmt.c.