@@ -113,22 +113,28 @@ HLSOutputStream::add_stream (const AVCodec **codec, enum AVCodecID codec_id)
113
113
if (!match)
114
114
return Error (string_printf (" no codec support for sample rate %d" , m_sample_rate));
115
115
}
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 )
118
120
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 )
121
124
{
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++)
124
128
{
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
+ }
127
133
}
128
134
}
129
- if (want_layout != m_enc->channel_layout )
135
+ if (av_channel_layout_compare (&channel_layout, & m_enc->ch_layout ) != 0 )
130
136
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);
132
138
m_st->time_base = (AVRational){ 1 , m_enc->sample_rate };
133
139
134
140
/* Some formats want stream headers to be separate. */
@@ -140,7 +146,7 @@ HLSOutputStream::add_stream (const AVCodec **codec, enum AVCodecID codec_id)
140
146
141
147
142
148
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)
144
150
{
145
151
AVFrame *frame = av_frame_alloc ();
146
152
@@ -151,7 +157,7 @@ HLSOutputStream::alloc_audio_frame (AVSampleFormat sample_fmt, uint64_t channel_
151
157
}
152
158
153
159
frame->format = sample_fmt;
154
- frame->channel_layout = channel_layout;
160
+ av_channel_layout_copy (& frame->ch_layout , channel_layout) ;
155
161
frame->sample_rate = sample_rate;
156
162
frame->nb_samples = nb_samples;
157
163
@@ -189,11 +195,11 @@ HLSOutputStream::open_audio (const AVCodec *codec, AVDictionary *opt_arg)
189
195
nb_samples = m_enc->frame_size ;
190
196
191
197
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);
193
199
if (err)
194
200
return err;
195
201
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);
197
203
if (err)
198
204
return err;
199
205
@@ -212,10 +218,10 @@ HLSOutputStream::open_audio (const AVCodec *codec, AVDictionary *opt_arg)
212
218
return Error (" could not allocate resampler context" );
213
219
214
220
/* 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 );
216
222
av_opt_set_int (m_swr_ctx, " in_sample_rate" , m_enc->sample_rate , 0 );
217
223
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 );
219
225
av_opt_set_int (m_swr_ctx, " out_sample_rate" , m_enc->sample_rate , 0 );
220
226
av_opt_set_sample_fmt (m_swr_ctx, " out_sample_fmt" , m_enc->sample_fmt , 0 );
221
227
0 commit comments