[FFmpeg-cvslog] avdevice/alsa: simplify passing ff_alsa_open a channel layout
James Almer
git at videolan.org
Wed Feb 12 23:51:20 EET 2025
ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Fri Feb 7 23:52:01 2025 -0300| [eb3d507b7f00141f06f63c5cbeaa0e2b3d72e8c0] | committer: James Almer
avdevice/alsa: simplify passing ff_alsa_open a channel layout
This also ensures the layout set during the indev init is used instead of the
blank one in st->codecpar.
Signed-off-by: James Almer <jamrial at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=eb3d507b7f00141f06f63c5cbeaa0e2b3d72e8c0
---
libavdevice/alsa.c | 14 +++++++-------
libavdevice/alsa.h | 4 ++--
libavdevice/alsa_dec.c | 2 +-
libavdevice/alsa_enc.c | 2 +-
4 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/libavdevice/alsa.c b/libavdevice/alsa.c
index d62ccc09c6..cfdb28ff49 100644
--- a/libavdevice/alsa.c
+++ b/libavdevice/alsa.c
@@ -127,7 +127,8 @@ switch(format) {\
case FORMAT_F32: s->reorder_func = alsa_reorder_f32_out_ ##layout; break;\
}
-static av_cold int find_reorder_func(AlsaData *s, int codec_id, AVChannelLayout *layout, int out)
+static av_cold int find_reorder_func(AlsaData *s, int codec_id,
+ const AVChannelLayout *layout, int out)
{
int format;
@@ -172,10 +173,9 @@ static av_cold int find_reorder_func(AlsaData *s, int codec_id, AVChannelLayout
av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
unsigned int *sample_rate,
- int channels, enum AVCodecID *codec_id)
+ const AVChannelLayout *layout, enum AVCodecID *codec_id)
{
AlsaData *s = ctx->priv_data;
- AVChannelLayout *layout = &ctx->streams[0]->codecpar->ch_layout;
const char *audio_device;
int res, flags = 0;
snd_pcm_format_t format;
@@ -193,7 +193,7 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
av_log(ctx, AV_LOG_ERROR, "sample format 0x%04x is not supported\n", *codec_id);
return AVERROR(ENOSYS);
}
- s->frame_size = av_get_bits_per_sample(*codec_id) / 8 * channels;
+ s->frame_size = av_get_bits_per_sample(*codec_id) / 8 * layout->nb_channels;
if (ctx->flags & AVFMT_FLAG_NONBLOCK) {
flags = SND_PCM_NONBLOCK;
@@ -240,10 +240,10 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
goto fail;
}
- res = snd_pcm_hw_params_set_channels(h, hw_params, channels);
+ res = snd_pcm_hw_params_set_channels(h, hw_params, layout->nb_channels);
if (res < 0) {
av_log(ctx, AV_LOG_ERROR, "cannot set channel count to %d (%s)\n",
- channels, snd_strerror(res));
+ layout->nb_channels, snd_strerror(res));
goto fail;
}
@@ -277,7 +277,7 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
snd_pcm_hw_params_free(hw_params);
- if (channels > 2 && layout->order != AV_CHANNEL_ORDER_UNSPEC) {
+ if (layout->nb_channels > 2 && layout->order != AV_CHANNEL_ORDER_UNSPEC) {
if (find_reorder_func(s, *codec_id, layout, mode == SND_PCM_STREAM_PLAYBACK) < 0) {
char name[128];
av_channel_layout_describe(layout, name, sizeof(name));
diff --git a/libavdevice/alsa.h b/libavdevice/alsa.h
index 3e1ba31384..d3dfa478c5 100644
--- a/libavdevice/alsa.h
+++ b/libavdevice/alsa.h
@@ -72,7 +72,7 @@ typedef struct AlsaData {
* @param mode either SND_PCM_STREAM_CAPTURE or SND_PCM_STREAM_PLAYBACK
* @param sample_rate in: requested sample rate;
* out: actually selected sample rate
- * @param channels number of channels
+ * @param layout channel layout
* @param codec_id in: requested AVCodecID or AV_CODEC_ID_NONE;
* out: actually selected AVCodecID, changed only if
* AV_CODEC_ID_NONE was requested
@@ -82,7 +82,7 @@ typedef struct AlsaData {
av_warn_unused_result
int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,
unsigned int *sample_rate,
- int channels, enum AVCodecID *codec_id);
+ const AVChannelLayout *layout, enum AVCodecID *codec_id);
/**
* Close the ALSA PCM.
diff --git a/libavdevice/alsa_dec.c b/libavdevice/alsa_dec.c
index f0738e3dea..63409a7785 100644
--- a/libavdevice/alsa_dec.c
+++ b/libavdevice/alsa_dec.c
@@ -80,7 +80,7 @@ static av_cold int audio_read_header(AVFormatContext *s1)
}
#endif
- ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &s->sample_rate, s->ch_layout.nb_channels,
+ ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &s->sample_rate, &s->ch_layout,
&codec_id);
if (ret < 0) {
return AVERROR(EIO);
diff --git a/libavdevice/alsa_enc.c b/libavdevice/alsa_enc.c
index 0b4c7834f7..971cff688c 100644
--- a/libavdevice/alsa_enc.c
+++ b/libavdevice/alsa_enc.c
@@ -66,7 +66,7 @@ static av_cold int audio_write_header(AVFormatContext *s1)
sample_rate = st->codecpar->sample_rate;
codec_id = st->codecpar->codec_id;
res = ff_alsa_open(s1, SND_PCM_STREAM_PLAYBACK, &sample_rate,
- st->codecpar->ch_layout.nb_channels, &codec_id);
+ &st->codecpar->ch_layout, &codec_id);
if (sample_rate != st->codecpar->sample_rate) {
av_log(s1, AV_LOG_ERROR,
"sample rate %d not available, nearest is %d\n",
More information about the ffmpeg-cvslog
mailing list