ffmpeg | branch: master | James Almer <jamr...@gmail.com> | Tue Jan 28 09:57:57 2025 -0300| [c6194b50b1b4001db23e8debab4ac4444e794f90] | committer: James Almer
avdevice/alsa_dec: add a ch_layout option Missed in ffc4fd3cc2ccb2cadb71f19849842b18ca1281c6, which after e78173557da898f18a78241cc3525b76694164b5 broke setting channel count. Should fix ticket #11434. Reviewed-by: Michael Niedermayer <mich...@niedermayer.cc> Signed-off-by: James Almer <jamr...@gmail.com> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c6194b50b1b4001db23e8debab4ac4444e794f90 --- libavdevice/alsa.h | 4 ++++ libavdevice/alsa_dec.c | 24 +++++++++++++++++++----- libavdevice/version_major.h | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/libavdevice/alsa.h b/libavdevice/alsa.h index 07783c983a..3e1ba31384 100644 --- a/libavdevice/alsa.h +++ b/libavdevice/alsa.h @@ -35,6 +35,7 @@ #include "libavutil/log.h" #include "timefilter.h" #include "avdevice.h" +#include "version.h" /* XXX: we make the assumption that the soundcard accepts this format */ /* XXX: find better solution with "preinit" method, needed also in @@ -51,7 +52,10 @@ typedef struct AlsaData { int frame_size; ///< bytes per sample * channels int period_size; ///< preferred size for reads and writes, in frames int sample_rate; ///< sample rate set by user +#if FF_API_ALSA_CHANNELS int channels; ///< number of channels set by user +#endif + AVChannelLayout ch_layout; ///< Channel layout set by user int last_period; TimeFilter *timefilter; void (*reorder_func)(const void *, void *, int); diff --git a/libavdevice/alsa_dec.c b/libavdevice/alsa_dec.c index 018afaef08..f0738e3dea 100644 --- a/libavdevice/alsa_dec.c +++ b/libavdevice/alsa_dec.c @@ -73,7 +73,14 @@ static av_cold int audio_read_header(AVFormatContext *s1) } codec_id = s1->audio_codec_id; - ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &s->sample_rate, s->channels, +#if FF_API_ALSA_CHANNELS + if (s->channels > 0) { + av_channel_layout_uninit(&s->ch_layout); + s->ch_layout.nb_channels = s->channels; + } +#endif + + ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &s->sample_rate, s->ch_layout.nb_channels, &codec_id); if (ret < 0) { return AVERROR(EIO); @@ -83,20 +90,24 @@ static av_cold int audio_read_header(AVFormatContext *s1) st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->codecpar->codec_id = codec_id; st->codecpar->sample_rate = s->sample_rate; - st->codecpar->ch_layout.nb_channels = s->channels; + ret = av_channel_layout_copy(&st->codecpar->ch_layout, &s->ch_layout); + if (ret < 0) + goto fail; st->codecpar->frame_size = s->frame_size; avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ /* microseconds instead of seconds, MHz instead of Hz */ s->timefilter = ff_timefilter_new(1000000.0 / s->sample_rate, s->period_size, 1.5E-6); - if (!s->timefilter) + if (!s->timefilter) { + ret = AVERROR(EIO); goto fail; + } return 0; fail: snd_pcm_close(s->h); - return AVERROR(EIO); + return ret; } static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt) @@ -146,7 +157,10 @@ static int audio_get_device_list(AVFormatContext *h, AVDeviceInfoList *device_li static const AVOption options[] = { { "sample_rate", "", offsetof(AlsaData, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, - { "channels", "", offsetof(AlsaData, channels), AV_OPT_TYPE_INT, {.i64 = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, +#if FF_API_ALSA_CHANNELS + { "channels", "", offsetof(AlsaData, channels), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_DEPRECATED }, +#endif + { "ch_layout", "", offsetof(AlsaData, ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "2C"}, INT_MIN, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, { NULL }, }; diff --git a/libavdevice/version_major.h b/libavdevice/version_major.h index f16abb6909..50f577f295 100644 --- a/libavdevice/version_major.h +++ b/libavdevice/version_major.h @@ -39,5 +39,6 @@ #define FF_API_OPENGL_DEVICE (LIBAVDEVICE_VERSION_MAJOR < 62) // reminder to remove the sdl2 device on next major bump #define FF_API_SDL2_DEVICE (LIBAVDEVICE_VERSION_MAJOR < 62) +#define FF_API_ALSA_CHANNELS (LIBAVDEVICE_VERSION_MAJOR < 62) #endif /* AVDEVICE_VERSION_MAJOR_H */ _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".