You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
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@gmail.com>
This commit is contained in:
@@ -127,7 +127,8 @@ switch(format) {\
|
|||||||
case FORMAT_F32: s->reorder_func = alsa_reorder_f32_out_ ##layout; break;\
|
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;
|
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,
|
av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
|
||||||
unsigned int *sample_rate,
|
unsigned int *sample_rate,
|
||||||
int channels, enum AVCodecID *codec_id)
|
const AVChannelLayout *layout, enum AVCodecID *codec_id)
|
||||||
{
|
{
|
||||||
AlsaData *s = ctx->priv_data;
|
AlsaData *s = ctx->priv_data;
|
||||||
AVChannelLayout *layout = &ctx->streams[0]->codecpar->ch_layout;
|
|
||||||
const char *audio_device;
|
const char *audio_device;
|
||||||
int res, flags = 0;
|
int res, flags = 0;
|
||||||
snd_pcm_format_t format;
|
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);
|
av_log(ctx, AV_LOG_ERROR, "sample format 0x%04x is not supported\n", *codec_id);
|
||||||
return AVERROR(ENOSYS);
|
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) {
|
if (ctx->flags & AVFMT_FLAG_NONBLOCK) {
|
||||||
flags = SND_PCM_NONBLOCK;
|
flags = SND_PCM_NONBLOCK;
|
||||||
@@ -240,10 +240,10 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
|
|||||||
goto fail;
|
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) {
|
if (res < 0) {
|
||||||
av_log(ctx, AV_LOG_ERROR, "cannot set channel count to %d (%s)\n",
|
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;
|
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);
|
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) {
|
if (find_reorder_func(s, *codec_id, layout, mode == SND_PCM_STREAM_PLAYBACK) < 0) {
|
||||||
char name[128];
|
char name[128];
|
||||||
av_channel_layout_describe(layout, name, sizeof(name));
|
av_channel_layout_describe(layout, name, sizeof(name));
|
||||||
|
@@ -72,7 +72,7 @@ typedef struct AlsaData {
|
|||||||
* @param mode either SND_PCM_STREAM_CAPTURE or SND_PCM_STREAM_PLAYBACK
|
* @param mode either SND_PCM_STREAM_CAPTURE or SND_PCM_STREAM_PLAYBACK
|
||||||
* @param sample_rate in: requested sample rate;
|
* @param sample_rate in: requested sample rate;
|
||||||
* out: actually selected 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;
|
* @param codec_id in: requested AVCodecID or AV_CODEC_ID_NONE;
|
||||||
* out: actually selected AVCodecID, changed only if
|
* out: actually selected AVCodecID, changed only if
|
||||||
* AV_CODEC_ID_NONE was requested
|
* AV_CODEC_ID_NONE was requested
|
||||||
@@ -82,7 +82,7 @@ typedef struct AlsaData {
|
|||||||
av_warn_unused_result
|
av_warn_unused_result
|
||||||
int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,
|
int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,
|
||||||
unsigned int *sample_rate,
|
unsigned int *sample_rate,
|
||||||
int channels, enum AVCodecID *codec_id);
|
const AVChannelLayout *layout, enum AVCodecID *codec_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the ALSA PCM.
|
* Close the ALSA PCM.
|
||||||
|
@@ -80,7 +80,7 @@ static av_cold int audio_read_header(AVFormatContext *s1)
|
|||||||
}
|
}
|
||||||
#endif
|
#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);
|
&codec_id);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
|
@@ -66,7 +66,7 @@ static av_cold int audio_write_header(AVFormatContext *s1)
|
|||||||
sample_rate = st->codecpar->sample_rate;
|
sample_rate = st->codecpar->sample_rate;
|
||||||
codec_id = st->codecpar->codec_id;
|
codec_id = st->codecpar->codec_id;
|
||||||
res = ff_alsa_open(s1, SND_PCM_STREAM_PLAYBACK, &sample_rate,
|
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) {
|
if (sample_rate != st->codecpar->sample_rate) {
|
||||||
av_log(s1, AV_LOG_ERROR,
|
av_log(s1, AV_LOG_ERROR,
|
||||||
"sample rate %d not available, nearest is %d\n",
|
"sample rate %d not available, nearest is %d\n",
|
||||||
|
Reference in New Issue
Block a user