Skip to content

Commit a52518f

Browse files
committed
Merge branch 'tim-janik-ffmpeg-7-ch_layout'
* tim-janik-ffmpeg-7-ch_layout: src/hlsoutputstream.*: migrate to use AVChannelLayout Fixes #62: #62 Starting ffmpeg-7, the old av_get_channel_layout() API is gone and use of AVChannelLayout is mandatory. Signed-off-by: Stefan Westerfeld <[email protected]>
2 parents adfb68c + a76dfbe commit a52518f

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

Diff for: src/hlsoutputstream.cc

+22-16
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,28 @@ HLSOutputStream::add_stream (const AVCodec **codec, enum AVCodecID codec_id)
113113
if (!match)
114114
return Error (string_printf ("no codec support for sample rate %d", m_sample_rate));
115115
}
116-
uint64_t want_layout = av_get_channel_layout (m_channel_layout.c_str());
117-
if (!want_layout)
116+
117+
118+
AVChannelLayout channel_layout = { AVChannelOrder (0), };
119+
if (av_channel_layout_from_string (&channel_layout, m_channel_layout.c_str()) != 0)
118120
return Error (string_printf ("bad channel layout '%s'", m_channel_layout.c_str()));
119-
m_enc->channel_layout = want_layout;
120-
if ((*codec)->channel_layouts)
121+
av_channel_layout_uninit (&m_enc->ch_layout);
122+
av_channel_layout_copy (&m_enc->ch_layout, &channel_layout);
123+
if ((*codec)->ch_layouts)
121124
{
122-
m_enc->channel_layout = (*codec)->channel_layouts[0];
123-
for (int i = 0; (*codec)->channel_layouts[i]; i++)
125+
av_channel_layout_uninit (&m_enc->ch_layout);
126+
av_channel_layout_copy (&m_enc->ch_layout, &(*codec)->ch_layouts[0]);
127+
for (int i = 0; (*codec)->ch_layouts[i].nb_channels; i++)
124128
{
125-
if ((*codec)->channel_layouts[i] == want_layout)
126-
m_enc->channel_layout = want_layout;
129+
if (av_channel_layout_compare (&(*codec)->ch_layouts[i], &channel_layout) == 0) {
130+
av_channel_layout_uninit (&m_enc->ch_layout);
131+
av_channel_layout_copy (&m_enc->ch_layout, &(*codec)->ch_layouts[i]);
132+
}
127133
}
128134
}
129-
if (want_layout != m_enc->channel_layout)
135+
if (av_channel_layout_compare (&channel_layout, &m_enc->ch_layout) != 0)
130136
return Error (string_printf ("codec: unsupported channel layout '%s'", m_channel_layout.c_str()));
131-
m_enc->channels = av_get_channel_layout_nb_channels (m_enc->channel_layout);
137+
av_channel_layout_uninit (&channel_layout);
132138
m_st->time_base = (AVRational){ 1, m_enc->sample_rate };
133139

134140
/* Some formats want stream headers to be separate. */
@@ -140,7 +146,7 @@ HLSOutputStream::add_stream (const AVCodec **codec, enum AVCodecID codec_id)
140146

141147

142148
AVFrame *
143-
HLSOutputStream::alloc_audio_frame (AVSampleFormat sample_fmt, uint64_t channel_layout, int sample_rate, int nb_samples, Error& err)
149+
HLSOutputStream::alloc_audio_frame (AVSampleFormat sample_fmt, const AVChannelLayout *channel_layout, int sample_rate, int nb_samples, Error& err)
144150
{
145151
AVFrame *frame = av_frame_alloc();
146152

@@ -151,7 +157,7 @@ HLSOutputStream::alloc_audio_frame (AVSampleFormat sample_fmt, uint64_t channel_
151157
}
152158

153159
frame->format = sample_fmt;
154-
frame->channel_layout = channel_layout;
160+
av_channel_layout_copy (&frame->ch_layout, channel_layout);
155161
frame->sample_rate = sample_rate;
156162
frame->nb_samples = nb_samples;
157163

@@ -189,11 +195,11 @@ HLSOutputStream::open_audio (const AVCodec *codec, AVDictionary *opt_arg)
189195
nb_samples = m_enc->frame_size;
190196

191197
Error err;
192-
m_frame = alloc_audio_frame (m_enc->sample_fmt, m_enc->channel_layout, m_enc->sample_rate, nb_samples, err);
198+
m_frame = alloc_audio_frame (m_enc->sample_fmt, &m_enc->ch_layout, m_enc->sample_rate, nb_samples, err);
193199
if (err)
194200
return err;
195201

196-
m_tmp_frame = alloc_audio_frame (AV_SAMPLE_FMT_FLT, m_enc->channel_layout, m_enc->sample_rate, nb_samples, err);
202+
m_tmp_frame = alloc_audio_frame (AV_SAMPLE_FMT_FLT, &m_enc->ch_layout, m_enc->sample_rate, nb_samples, err);
197203
if (err)
198204
return err;
199205

@@ -212,10 +218,10 @@ HLSOutputStream::open_audio (const AVCodec *codec, AVDictionary *opt_arg)
212218
return Error ("could not allocate resampler context");
213219

214220
/* set options */
215-
av_opt_set_int (m_swr_ctx, "in_channel_count", m_enc->channels, 0);
221+
av_opt_set_chlayout (m_swr_ctx, "in_chlayout", &m_enc->ch_layout, 0);
216222
av_opt_set_int (m_swr_ctx, "in_sample_rate", m_enc->sample_rate, 0);
217223
av_opt_set_sample_fmt (m_swr_ctx, "in_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
218-
av_opt_set_int (m_swr_ctx, "out_channel_count", m_enc->channels, 0);
224+
av_opt_set_chlayout (m_swr_ctx, "out_chlayout", &m_enc->ch_layout, 0);
219225
av_opt_set_int (m_swr_ctx, "out_sample_rate", m_enc->sample_rate, 0);
220226
av_opt_set_sample_fmt (m_swr_ctx, "out_sample_fmt", m_enc->sample_fmt, 0);
221227

Diff for: src/hlsoutputstream.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class HLSOutputStream : public AudioOutputStream {
7676
};
7777
EncResult write_audio_frame (Error& err);
7878
void close_stream();
79-
AVFrame *alloc_audio_frame (AVSampleFormat sample_fmt, uint64_t channel_layout, int sample_rate, int nb_samples, Error& err);
79+
AVFrame *alloc_audio_frame (AVSampleFormat sample_fmt, const AVChannelLayout *channel_layout, int sample_rate, int nb_samples, Error& err);
8080

8181
int write_frame (const AVRational *time_base, AVStream *st, AVPacket *pkt);
8282
public:

0 commit comments

Comments
 (0)