@@ -342,19 +342,24 @@ int decodePacket(AVCodecContext *context, AVPacket *packet,
342
342
int sampleCount = frame->nb_samples ;
343
343
int dataSize = av_samples_get_buffer_size (NULL , channelCount, sampleCount,
344
344
sampleFormat, 1 );
345
- SwrContext *resampleContext;
346
- if (context->opaque ) {
347
- resampleContext = (SwrContext *)context->opaque ;
348
- } else {
349
- resampleContext = swr_alloc ();
350
- av_opt_set_chlayout (resampleContext, " in_chlayout" , &context->ch_layout , 0 );
351
- av_opt_set_chlayout (resampleContext, " out_chlayout" , &context->ch_layout , 0 );
352
- av_opt_set_int (resampleContext, " in_sample_rate" , sampleRate, 0 );
353
- av_opt_set_int (resampleContext, " out_sample_rate" , sampleRate, 0 );
354
- av_opt_set_int (resampleContext, " in_sample_fmt" , sampleFormat, 0 );
355
- // The output format is always the requested format.
356
- av_opt_set_int (resampleContext, " out_sample_fmt" ,
357
- context->request_sample_fmt , 0 );
345
+ SwrContext *resampleContext = static_cast <SwrContext *>(context->opaque );
346
+ if (!resampleContext) {
347
+ result = swr_alloc_set_opts2 (
348
+ &resampleContext, // ps
349
+ &context->ch_layout , // out_ch_layout
350
+ context->request_sample_fmt , // out_sample_fmt
351
+ sampleRate, // out_sample_rate
352
+ &context->ch_layout , // in_ch_layout
353
+ sampleFormat, // in_sample_fmt
354
+ sampleRate, // in_sample_rate
355
+ 0 , // log_offset
356
+ NULL // log_ctx
357
+ );
358
+ if (result < 0 ) {
359
+ logError (" swr_alloc_set_opts2" , result);
360
+ av_frame_free (&frame);
361
+ return transformError (result);
362
+ }
358
363
result = swr_init (resampleContext);
359
364
if (result < 0 ) {
360
365
logError (" swr_init" , result);
0 commit comments