Go to the documentation of this file.
31 #include "config_components.h"
33 #include <alsa/asoundlib.h>
64 default:
return SND_PCM_FORMAT_UNKNOWN;
68 #define MAKE_REORDER_FUNC(NAME, TYPE, CHANNELS, LAYOUT, MAP) \
69 static void alsa_reorder_ ## NAME ## _ ## LAYOUT(const void *in_v, \
73 const TYPE *in = in_v; \
83 #define MAKE_REORDER_FUNCS(CHANNELS, LAYOUT, MAP) \
84 MAKE_REORDER_FUNC(int8, int8_t, CHANNELS, LAYOUT, MAP) \
85 MAKE_REORDER_FUNC(int16, int16_t, CHANNELS, LAYOUT, MAP) \
86 MAKE_REORDER_FUNC(int32, int32_t, CHANNELS, LAYOUT, MAP) \
87 MAKE_REORDER_FUNC(f32, float, CHANNELS, LAYOUT, MAP)
158 default:
return AVERROR(ENOSYS);
174 unsigned int *sample_rate,
179 const char *audio_device;
183 snd_pcm_hw_params_t *hw_params;
184 snd_pcm_uframes_t buffer_size, period_size;
186 if (
ctx->
url[0] == 0) audio_device =
"default";
187 else audio_device =
ctx->
url;
192 if (
format == SND_PCM_FORMAT_UNKNOWN) {
199 flags = SND_PCM_NONBLOCK;
201 res = snd_pcm_open(&
h, audio_device,
mode,
flags);
204 audio_device, snd_strerror(res));
208 res = snd_pcm_hw_params_malloc(&hw_params);
215 res = snd_pcm_hw_params_any(
h, hw_params);
222 res = snd_pcm_hw_params_set_access(
h, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
229 res = snd_pcm_hw_params_set_format(
h, hw_params,
format);
236 res = snd_pcm_hw_params_set_rate_near(
h, hw_params, sample_rate, 0);
243 res = snd_pcm_hw_params_set_channels(
h, hw_params,
channels);
250 snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_size);
253 res = snd_pcm_hw_params_set_buffer_size_near(
h, hw_params, &buffer_size);
260 snd_pcm_hw_params_get_period_size_min(hw_params, &period_size,
NULL);
262 period_size = buffer_size / 4;
263 res = snd_pcm_hw_params_set_period_size_near(
h, hw_params, &period_size,
NULL);
269 s->period_size = period_size;
271 res = snd_pcm_hw_params(
h, hw_params);
278 snd_pcm_hw_params_free(hw_params);
285 name,
mode == SND_PCM_STREAM_PLAYBACK ?
"playback" :
"capture");
287 if (
s->reorder_func) {
288 s->reorder_buf_size = buffer_size;
303 snd_pcm_hw_params_free(hw_params);
313 if (snd_pcm_stream(
s->h) == SND_PCM_STREAM_PLAYBACK) {
314 snd_pcm_nonblock(
s->h, 0);
318 if (CONFIG_ALSA_INDEV)
328 snd_pcm_t *handle =
s->h;
332 err = snd_pcm_prepare(handle);
334 av_log(s1,
AV_LOG_ERROR,
"cannot recover from underrun (snd_pcm_prepare failed: %s)\n", snd_strerror(err));
338 }
else if (err == -ESTRPIPE) {
348 int size =
s->reorder_buf_size;
352 while (
size < min_size)
358 s->reorder_buf_size =
size;
369 const char *
filter = stream_type == SND_PCM_STREAM_PLAYBACK ?
"Output" :
"Input";
371 if (snd_device_name_hint(-1,
"pcm", &hints) < 0)
375 name = snd_device_name_get_hint(*n,
"NAME");
376 descr = snd_device_name_get_hint(*n,
"DESC");
377 io = snd_device_name_get_hint(*n,
"IOID");
378 if (!io || !strcmp(io,
filter)) {
385 if ((
tmp = strrchr(descr,
'\n')) &&
tmp[1])
412 snd_device_name_free_hint(hints);
#define PICK_REORDER(layout)
#define AV_LOG_WARNING
Something somehow does not look correct.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
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
char * device_name
device name, format depends on device
#define ALSA_BUFFER_SIZE_MAX
#define AV_CHANNEL_LAYOUT_2_2
int nb_devices
number of autodetected devices
AVStream ** streams
A list of all streams in the file.
void(* filter)(uint8_t *src, int stride, int qscale)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
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 it should return
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
AVDeviceInfo ** devices
list of autodetected devices
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
#define AV_CHANNEL_LAYOUT_7POINT1
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
int flags
Flags modifying the (de)muxer behaviour.
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define AV_CHANNEL_LAYOUT_5POINT0_BACK
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define MAKE_REORDER_FUNCS(CHANNELS, LAYOUT, MAP)
av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, unsigned int *sample_rate, int channels, enum AVCodecID *codec_id)
Open an ALSA PCM.
int ff_alsa_extend_reorder_buf(AlsaData *s, int min_size)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVChannelLayout ch_layout
Audio only.
av_cold int ff_alsa_close(AVFormatContext *s1)
Close the ALSA PCM.
AVCodecID
Identify the syntax and semantics of the bitstream.
An AVChannelLayout holds information about the channel layout of audio data.
char * url
input or output URL.
Structure describes basic parameters of the device.
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
char * device_description
human friendly name
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
static av_cold snd_pcm_format_t codec_id_to_pcm_format(int codec_id)
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 layout
void ff_timefilter_destroy(TimeFilter *self)
Free all resources associated with the filter.
#define AV_CHANNEL_LAYOUT_QUAD
#define av_malloc_array(a, b)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
int default_device
index of default device or -1 if no default
int ff_alsa_xrun_recover(AVFormatContext *s1, int err)
Try to recover from ALSA buffer underrun.
char * av_strdup(const char *s)
Duplicate a string.
int ff_alsa_get_device_list(AVDeviceInfoList *device_list, snd_pcm_stream_t stream_type)
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
#define flags(name, subs,...)
#define AV_CHANNEL_LAYOUT_5POINT0
#define AV_CHANNEL_LAYOUT_5POINT1
void * priv_data
Format private data.