You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avdevice/alsa_dec: add a ch_layout option
Missed inffc4fd3cc2
, which aftere78173557d
broke setting channel count. Should fix ticket #11434. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include "libavutil/log.h"
|
#include "libavutil/log.h"
|
||||||
#include "timefilter.h"
|
#include "timefilter.h"
|
||||||
#include "avdevice.h"
|
#include "avdevice.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
/* XXX: we make the assumption that the soundcard accepts this format */
|
/* XXX: we make the assumption that the soundcard accepts this format */
|
||||||
/* XXX: find better solution with "preinit" method, needed also in
|
/* 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 frame_size; ///< bytes per sample * channels
|
||||||
int period_size; ///< preferred size for reads and writes, in frames
|
int period_size; ///< preferred size for reads and writes, in frames
|
||||||
int sample_rate; ///< sample rate set by user
|
int sample_rate; ///< sample rate set by user
|
||||||
|
#if FF_API_ALSA_CHANNELS
|
||||||
int channels; ///< number of channels set by user
|
int channels; ///< number of channels set by user
|
||||||
|
#endif
|
||||||
|
AVChannelLayout ch_layout; ///< Channel layout set by user
|
||||||
int last_period;
|
int last_period;
|
||||||
TimeFilter *timefilter;
|
TimeFilter *timefilter;
|
||||||
void (*reorder_func)(const void *, void *, int);
|
void (*reorder_func)(const void *, void *, int);
|
||||||
|
@@ -73,7 +73,14 @@ static av_cold int audio_read_header(AVFormatContext *s1)
|
|||||||
}
|
}
|
||||||
codec_id = s1->audio_codec_id;
|
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);
|
&codec_id);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return AVERROR(EIO);
|
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_type = AVMEDIA_TYPE_AUDIO;
|
||||||
st->codecpar->codec_id = codec_id;
|
st->codecpar->codec_id = codec_id;
|
||||||
st->codecpar->sample_rate = s->sample_rate;
|
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;
|
st->codecpar->frame_size = s->frame_size;
|
||||||
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
|
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
|
||||||
/* microseconds instead of seconds, MHz instead of Hz */
|
/* microseconds instead of seconds, MHz instead of Hz */
|
||||||
s->timefilter = ff_timefilter_new(1000000.0 / s->sample_rate,
|
s->timefilter = ff_timefilter_new(1000000.0 / s->sample_rate,
|
||||||
s->period_size, 1.5E-6);
|
s->period_size, 1.5E-6);
|
||||||
if (!s->timefilter)
|
if (!s->timefilter) {
|
||||||
|
ret = AVERROR(EIO);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
snd_pcm_close(s->h);
|
snd_pcm_close(s->h);
|
||||||
return AVERROR(EIO);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
|
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[] = {
|
static const AVOption options[] = {
|
||||||
{ "sample_rate", "", offsetof(AlsaData, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
|
{ "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 },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -39,5 +39,6 @@
|
|||||||
#define FF_API_OPENGL_DEVICE (LIBAVDEVICE_VERSION_MAJOR < 62)
|
#define FF_API_OPENGL_DEVICE (LIBAVDEVICE_VERSION_MAJOR < 62)
|
||||||
// reminder to remove the sdl2 device on next major bump
|
// reminder to remove the sdl2 device on next major bump
|
||||||
#define FF_API_SDL2_DEVICE (LIBAVDEVICE_VERSION_MAJOR < 62)
|
#define FF_API_SDL2_DEVICE (LIBAVDEVICE_VERSION_MAJOR < 62)
|
||||||
|
#define FF_API_ALSA_CHANNELS (LIBAVDEVICE_VERSION_MAJOR < 62)
|
||||||
|
|
||||||
#endif /* AVDEVICE_VERSION_MAJOR_H */
|
#endif /* AVDEVICE_VERSION_MAJOR_H */
|
||||||
|
Reference in New Issue
Block a user