@@ -61,6 +61,9 @@ typedef AVCodec FeAVCodec;
61
61
#define FORMAT_CTX_URL m_imp->m_format_ctx->filename
62
62
#endif
63
63
64
+ #define HAVE_CH_LAYOUT (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57 , 28 , 100 ))
65
+ #define HAVE_DURATION (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(58 , 2 , 100 ))
66
+
64
67
void try_hw_accel ( AVCodecContext *&codec_ctx, FeAVCodec *&dec );
65
68
66
69
std::string g_decoder;
@@ -321,9 +324,15 @@ FeAudioImp::~FeAudioImp()
321
324
322
325
bool FeAudioImp::process_frame ( AVFrame *frame, sf::SoundStream::Chunk &data, int &offset )
323
326
{
327
+ #if HAVE_CH_LAYOUT
328
+ int nb_channels = codec_ctx->ch_layout .nb_channels ;
329
+ #else
330
+ int nb_channels = codec_ctx->channels ;
331
+ #endif
332
+
324
333
int data_size = av_samples_get_buffer_size (
325
334
NULL ,
326
- codec_ctx-> channels ,
335
+ nb_channels ,
327
336
frame->nb_samples ,
328
337
codec_ctx->sample_fmt , 1 );
329
338
@@ -349,17 +358,27 @@ bool FeAudioImp::process_frame( AVFrame *frame, sf::SoundStream::Chunk &data, in
349
358
return false ;
350
359
}
351
360
361
+ #if HAVE_CH_LAYOUT
362
+ AVChannelLayout layout;
363
+ av_channel_layout_copy (&layout, &frame->ch_layout );
364
+ if (!av_channel_layout_check (&layout)) {
365
+ av_channel_layout_default (&layout, codec_ctx->ch_layout .nb_channels );
366
+ }
367
+ av_opt_set_chlayout (resample_ctx, " in_chlayout" , &layout, 0 );
368
+ av_opt_set_chlayout (resample_ctx, " out_chlayout" , &layout, 0 );
369
+ #else
352
370
int64_t channel_layout = frame->channel_layout ;
353
371
if ( !channel_layout )
354
372
{
355
373
channel_layout = av_get_default_channel_layout (
356
374
codec_ctx->channels );
357
375
}
358
-
359
376
av_opt_set_int ( resample_ctx, " in_channel_layout" , channel_layout, 0 );
377
+ av_opt_set_int ( resample_ctx, " out_channel_layout" , channel_layout, 0 );
378
+ #endif
379
+
360
380
av_opt_set_int ( resample_ctx, " in_sample_fmt" , frame->format , 0 );
361
381
av_opt_set_int ( resample_ctx, " in_sample_rate" , frame->sample_rate , 0 );
362
- av_opt_set_int ( resample_ctx, " out_channel_layout" , channel_layout, 0 );
363
382
av_opt_set_int ( resample_ctx, " out_sample_fmt" , AV_SAMPLE_FMT_S16, 0 );
364
383
av_opt_set_int ( resample_ctx, " out_sample_rate" , frame->sample_rate , 0 );
365
384
@@ -382,9 +401,15 @@ bool FeAudioImp::process_frame( AVFrame *frame, sf::SoundStream::Chunk &data, in
382
401
if ( resample_ctx )
383
402
{
384
403
int out_linesize;
404
+ #if HAVE_CH_LAYOUT
405
+ int nb_channels = codec_ctx->ch_layout .nb_channels ;
406
+ #else
407
+ int nb_channels = codec_ctx->channels ;
408
+ #endif
409
+
385
410
av_samples_get_buffer_size (
386
411
&out_linesize,
387
- codec_ctx-> channels ,
412
+ nb_channels ,
388
413
frame->nb_samples ,
389
414
AV_SAMPLE_FMT_S16, 0 );
390
415
@@ -402,8 +427,9 @@ bool FeAudioImp::process_frame( AVFrame *frame, sf::SoundStream::Chunk &data, in
402
427
FeLog () << " Error performing audio conversion." << std::endl;
403
428
return false ;
404
429
}
405
- offset += out_samples * codec_ctx->channels ;
406
- data.sampleCount += out_samples * codec_ctx->channels ;
430
+
431
+ offset += out_samples * nb_channels;
432
+ data.sampleCount += out_samples * nb_channels;
407
433
data.samples = audio_buff;
408
434
}
409
435
}
@@ -752,15 +778,20 @@ void FeVideoImp::video_thread()
752
778
if ( raw_frame->pts == AV_NOPTS_VALUE )
753
779
raw_frame->pts = packet->dts ;
754
780
755
- // This only works on FFmpeg, exclude libav (it doesn't have pkt_duration
781
+
756
782
#if (LIBAVUTIL_VERSION_MICRO >= 100 )
783
+ // This only works on FFmpeg, exclude libav (it doesn't have pkt_duration
757
784
// Correct for out of bounds pts
758
785
if ( raw_frame->pts < prev_pts )
759
786
raw_frame->pts = prev_pts + prev_duration;
760
787
761
788
// Track pts and duration if we need to correct next frame
762
789
prev_pts = raw_frame->pts ;
790
+ #if HAVE_DURATION
791
+ prev_duration = raw_frame->duration ;
792
+ #else
763
793
prev_duration = raw_frame->pkt_duration ;
794
+ #endif
764
795
#endif
765
796
766
797
detached_frame = raw_frame;
@@ -1065,8 +1096,14 @@ bool FeMedia::open( const std::string &archive,
1065
1096
+ AV_INPUT_BUFFER_PADDING_SIZE
1066
1097
+ codec_ctx->sample_rate );
1067
1098
1099
+ #if HAVE_CH_LAYOUT
1100
+ int nb_channels = codec_ctx->ch_layout .nb_channels ;
1101
+ #else
1102
+ int nb_channels = codec_ctx->channels ;
1103
+ #endif
1104
+
1068
1105
sf::SoundStream::initialize (
1069
- codec_ctx-> channels ,
1106
+ nb_channels ,
1070
1107
codec_ctx->sample_rate );
1071
1108
1072
1109
sf::SoundStream::setLoop ( false );
0 commit comments