summaryrefslogtreecommitdiff
path: root/libavdevice
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2022-01-17 13:03:04 -0300
committerJames Almer <jamrial@gmail.com>2022-03-15 09:42:36 -0300
commitc218144748b1580991fc0d844448a460313a6b83 (patch)
tree10a648f6d55e3a35b19406c1cdeba04e40e256bc /libavdevice
parent67fb6c2200e1b4e15cd4e3b14f7240e4f152b5b0 (diff)
downloadffmpeg-c218144748b1580991fc0d844448a460313a6b83.tar.gz
pulseaudio: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavdevice')
-rw-r--r--libavdevice/pulse_audio_dec.c2
-rw-r--r--libavdevice/pulse_audio_enc.c66
2 files changed, 34 insertions, 34 deletions
diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
index b23d08e4d3..989fc6c689 100644
--- a/libavdevice/pulse_audio_dec.c
+++ b/libavdevice/pulse_audio_dec.c
@@ -259,7 +259,7 @@ static av_cold int pulse_read_header(AVFormatContext *s)
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = codec_id;
st->codecpar->sample_rate = pd->sample_rate;
- st->codecpar->channels = pd->channels;
+ st->codecpar->ch_layout.nb_channels = pd->channels;
avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */
pd->timefilter = ff_timefilter_new(1000000.0 / pd->sample_rate,
diff --git a/libavdevice/pulse_audio_enc.c b/libavdevice/pulse_audio_enc.c
index 4ff425d33f..05cd5ccee6 100644
--- a/libavdevice/pulse_audio_enc.c
+++ b/libavdevice/pulse_audio_enc.c
@@ -353,58 +353,58 @@ static int pulse_subscribe_events(PulseData *s)
return pulse_finish_context_operation(s, op, "pa_context_subscribe");
}
-static void pulse_map_channels_to_pulse(int64_t channel_layout, pa_channel_map *channel_map)
+static void pulse_map_channels_to_pulse(const AVChannelLayout *channel_layout, pa_channel_map *channel_map)
{
channel_map->channels = 0;
- if (channel_layout & AV_CH_FRONT_LEFT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_FRONT_LEFT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_FRONT_LEFT;
- if (channel_layout & AV_CH_FRONT_RIGHT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_FRONT_RIGHT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_FRONT_RIGHT;
- if (channel_layout & AV_CH_FRONT_CENTER)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_FRONT_CENTER) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_FRONT_CENTER;
- if (channel_layout & AV_CH_LOW_FREQUENCY)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_LOW_FREQUENCY) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_LFE;
- if (channel_layout & AV_CH_BACK_LEFT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_BACK_LEFT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_REAR_LEFT;
- if (channel_layout & AV_CH_BACK_RIGHT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_BACK_RIGHT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_REAR_RIGHT;
- if (channel_layout & AV_CH_FRONT_LEFT_OF_CENTER)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_FRONT_LEFT_OF_CENTER) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER;
- if (channel_layout & AV_CH_FRONT_RIGHT_OF_CENTER)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_FRONT_RIGHT_OF_CENTER) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER;
- if (channel_layout & AV_CH_BACK_CENTER)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_BACK_CENTER) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_REAR_CENTER;
- if (channel_layout & AV_CH_SIDE_LEFT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_SIDE_LEFT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_SIDE_LEFT;
- if (channel_layout & AV_CH_SIDE_RIGHT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_SIDE_RIGHT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_SIDE_RIGHT;
- if (channel_layout & AV_CH_TOP_CENTER)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_TOP_CENTER) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_TOP_CENTER;
- if (channel_layout & AV_CH_TOP_FRONT_LEFT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_TOP_FRONT_LEFT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_TOP_FRONT_LEFT;
- if (channel_layout & AV_CH_TOP_FRONT_CENTER)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_TOP_FRONT_CENTER) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_TOP_FRONT_CENTER;
- if (channel_layout & AV_CH_TOP_FRONT_RIGHT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_TOP_FRONT_RIGHT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_TOP_FRONT_RIGHT;
- if (channel_layout & AV_CH_TOP_BACK_LEFT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_TOP_BACK_LEFT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_TOP_REAR_LEFT;
- if (channel_layout & AV_CH_TOP_BACK_CENTER)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_TOP_BACK_CENTER) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_TOP_REAR_CENTER;
- if (channel_layout & AV_CH_TOP_BACK_RIGHT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_TOP_BACK_RIGHT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_TOP_REAR_RIGHT;
- if (channel_layout & AV_CH_STEREO_LEFT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_STEREO_LEFT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_FRONT_LEFT;
- if (channel_layout & AV_CH_STEREO_RIGHT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_STEREO_RIGHT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_FRONT_RIGHT;
- if (channel_layout & AV_CH_WIDE_LEFT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_WIDE_LEFT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_AUX0;
- if (channel_layout & AV_CH_WIDE_RIGHT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_WIDE_RIGHT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_AUX1;
- if (channel_layout & AV_CH_SURROUND_DIRECT_LEFT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_SURROUND_DIRECT_LEFT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_AUX2;
- if (channel_layout & AV_CH_SURROUND_DIRECT_RIGHT)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_SURROUND_DIRECT_RIGHT) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_AUX3;
- if (channel_layout & AV_CH_LOW_FREQUENCY_2)
+ if (av_channel_layout_index_from_channel(channel_layout, AV_CHAN_LOW_FREQUENCY_2) >= 0)
channel_map->map[channel_map->channels++] = PA_CHANNEL_POSITION_LFE;
}
@@ -469,7 +469,7 @@ static av_cold int pulse_write_header(AVFormatContext *h)
if (s->buffer_duration) {
int64_t bytes = s->buffer_duration;
- bytes *= st->codecpar->channels * st->codecpar->sample_rate *
+ bytes *= st->codecpar->ch_layout.nb_channels * st->codecpar->sample_rate *
av_get_bytes_per_sample(st->codecpar->format);
bytes /= 1000;
buffer_attributes.tlength = FFMAX(s->buffer_size, av_clip64(bytes, 0, UINT32_MAX - 1));
@@ -486,7 +486,7 @@ static av_cold int pulse_write_header(AVFormatContext *h)
sample_spec.format = ff_codec_id_to_pulse_format(st->codecpar->codec_id);
sample_spec.rate = st->codecpar->sample_rate;
- sample_spec.channels = st->codecpar->channels;
+ sample_spec.channels = st->codecpar->ch_layout.nb_channels;
if (!pa_sample_spec_valid(&sample_spec)) {
av_log(s, AV_LOG_ERROR, "Invalid sample spec.\n");
return AVERROR(EINVAL);
@@ -495,10 +495,10 @@ static av_cold int pulse_write_header(AVFormatContext *h)
if (sample_spec.channels == 1) {
channel_map.channels = 1;
channel_map.map[0] = PA_CHANNEL_POSITION_MONO;
- } else if (st->codecpar->channel_layout) {
- if (av_get_channel_layout_nb_channels(st->codecpar->channel_layout) != st->codecpar->channels)
+ } else if (st->codecpar->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
+ if (!av_channel_layout_check(&st->codecpar->ch_layout))
return AVERROR(EINVAL);
- pulse_map_channels_to_pulse(st->codecpar->channel_layout, &channel_map);
+ pulse_map_channels_to_pulse(&st->codecpar->ch_layout, &channel_map);
/* Unknown channel is present in channel_layout, let PulseAudio use its default. */
if (channel_map.channels != sample_spec.channels) {
av_log(s, AV_LOG_WARNING, "Unknown channel. Using defaul channel map.\n");
@@ -639,7 +639,7 @@ static int pulse_write_packet(AVFormatContext *h, AVPacket *pkt)
} else {
AVStream *st = h->streams[0];
AVRational r = { 1, st->codecpar->sample_rate };
- int64_t samples = pkt->size / (av_get_bytes_per_sample(st->codecpar->format) * st->codecpar->channels);
+ int64_t samples = pkt->size / (av_get_bytes_per_sample(st->codecpar->format) * st->codecpar->ch_layout.nb_channels);
s->timestamp += av_rescale_q(samples, r, st->time_base);
}
@@ -682,7 +682,7 @@ static int pulse_write_frame(AVFormatContext *h, int stream_index,
AVERROR(EINVAL) : 0;
pkt.data = (*frame)->data[0];
- pkt.size = (*frame)->nb_samples * av_get_bytes_per_sample((*frame)->format) * (*frame)->channels;
+ pkt.size = (*frame)->nb_samples * av_get_bytes_per_sample((*frame)->format) * (*frame)->ch_layout.nb_channels;
pkt.dts = (*frame)->pkt_dts;
pkt.duration = (*frame)->pkt_duration;
return pulse_write_packet(h, &pkt);