@@ -301,19 +301,24 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
301
301
int sampleCount = frame->nb_samples ;
302
302
int dataSize = av_samples_get_buffer_size (NULL , channelCount, sampleCount,
303
303
sampleFormat, 1 );
304
- SwrContext *resampleContext;
305
- if (context->opaque ) {
306
- resampleContext = (SwrContext *)context->opaque ;
307
- } else {
308
- resampleContext = swr_alloc ();
309
- av_opt_set_chlayout (resampleContext, " in_chlayout" , &context->ch_layout , 0 );
310
- av_opt_set_chlayout (resampleContext, " out_chlayout" , &context->ch_layout , 0 );
311
- av_opt_set_int (resampleContext, " in_sample_rate" , sampleRate, 0 );
312
- av_opt_set_int (resampleContext, " out_sample_rate" , sampleRate, 0 );
313
- av_opt_set_int (resampleContext, " in_sample_fmt" , sampleFormat, 0 );
314
- // The output format is always the requested format.
315
- av_opt_set_int (resampleContext, " out_sample_fmt" ,
316
- context->request_sample_fmt , 0 );
304
+ SwrContext *resampleContext = static_cast <SwrContext *>(context->opaque );
305
+ if (!resampleContext) {
306
+ result = swr_alloc_set_opts2 (
307
+ &resampleContext, // ps
308
+ &context->ch_layout , // out_ch_layout
309
+ context->request_sample_fmt , // out_sample_fmt
310
+ sampleRate, // out_sample_rate
311
+ &context->ch_layout , // in_ch_layout
312
+ sampleFormat, // in_sample_fmt
313
+ sampleRate, // in_sample_rate
314
+ 0 , // log_offset
315
+ NULL // log_ctx
316
+ );
317
+ if (result < 0 ) {
318
+ logError (" swr_alloc_set_opts2" , result);
319
+ av_frame_free (&frame);
320
+ return transformError (result);
321
+ }
317
322
result = swr_init (resampleContext);
318
323
if (result < 0 ) {
319
324
logError (" swr_init" , result);
0 commit comments