@@ -57,6 +57,9 @@ const HWAccel hwaccels[] = {
5757#endif
5858#if CONFIG_VDA
5959 { "vda" , vda_init , HWACCEL_VDA , AV_PIX_FMT_VDA },
60+ #endif
61+ #if HAVE_QSV
62+ { "qsv" , qsv_init , HWACCEL_QSV , AV_PIX_FMT_QSV },
6063#endif
6164 { 0 },
6265};
@@ -70,6 +73,7 @@ extern int hardware_decode;
7073extern int use_cuvid ;
7174extern int use_vdpau ;
7275extern int use_dxva2 ;
76+ extern int use_qsv ;
7377int av_log_level = AV_LOG_INFO ;
7478
7579
@@ -351,7 +355,7 @@ static void signal_handler (int sig)
351355#define AUDIOBUFFER 1600000
352356
353357static double base_apts = 0.0 , apts , top_apts = 0.0 ;
354- static DECLARE_ALIGNED ( 16 , short , audio_buffer [AUDIOBUFFER ]) ;
358+ static short audio_buffer [AUDIOBUFFER ];
355359static short * audio_buffer_ptr = audio_buffer ;
356360static int audio_samples = 0 ;
357361#define ISSAME (T1 ,T2 ) (fabs((T1) - (T2)) < 0.001)
@@ -573,8 +577,14 @@ void sound_to_frames(VideoState *is, short **b, int s, int c, int format)
573577 for (l = 0 ;l < c ;l ++ ) volume += * ((fb [l ])++ ) * 64000 ;
574578 else
575579 for (l = 0 ;l < c ;l ++ ) volume += * ((fb [0 ])++ ) * 64000 ;
580+ #if LIBAVCODEC_BUILD >= AV_VERSION_INT (59 , 37 , 100 ) && \
581+ LIBAVUTIL_BUILD >= AV_VERSION_INT (57 , 28 , 100 )
582+ * audio_buffer_ptr ++ = volume / is -> audio_st -> codecpar -> ch_layout .nb_channels ;
583+ avg_volume += abs (volume / is -> audio_st -> codecpar -> ch_layout .nb_channels );
584+ #else
576585 * audio_buffer_ptr ++ = volume / is -> audio_st -> codecpar -> channels ;
577586 avg_volume += abs (volume / is -> audio_st -> codecpar -> channels );
587+ #endif
578588 }
579589 }
580590 else
@@ -590,8 +600,14 @@ void sound_to_frames(VideoState *is, short **b, int s, int c, int format)
590600 for (l = 0 ;l < c ;l ++ ) volume += * ((sb [l ])++ );
591601 else
592602 for (l = 0 ;l < c ;l ++ ) volume += * ((sb [0 ])++ );
603+ #if LIBAVCODEC_BUILD >= AV_VERSION_INT (59 , 37 , 100 ) && \
604+ LIBAVUTIL_BUILD >= AV_VERSION_INT (57 , 28 , 100 )
605+ * audio_buffer_ptr ++ = volume / is -> audio_st -> codecpar -> ch_layout .nb_channels ;
606+ avg_volume += abs (volume / is -> audio_st -> codecpar -> ch_layout .nb_channels );
607+ #else
593608 * audio_buffer_ptr ++ = volume / is -> audio_st -> codecpar -> channels ;
594609 avg_volume += abs (volume / is -> audio_st -> codecpar -> channels );
610+ #endif
595611 }
596612 }
597613 }
@@ -767,7 +783,19 @@ void audio_packet_process(VideoState *is, AVPacket *pkt)
767783 }
768784
769785
770-
786+ #if LIBAVCODEC_BUILD >= AV_VERSION_INT (59 , 37 , 100 ) && \
787+ LIBAVUTIL_BUILD >= AV_VERSION_INT (57 , 28 , 100 )
788+ data_size = av_samples_get_buffer_size (NULL , is -> frame -> ch_layout .nb_channels ,
789+ is -> frame -> nb_samples ,
790+ is -> frame -> format , 1 );
791+ if (data_size > 0 )
792+ {
793+ sound_to_frames (is , (short * * )is -> frame -> data , is -> frame -> nb_samples ,is -> frame -> ch_layout .nb_channels , is -> frame -> format );
794+ }
795+ is -> audio_clock += (double )data_size /
796+ (is -> frame -> ch_layout .nb_channels * is -> frame -> sample_rate * av_get_bytes_per_sample (is -> frame -> format ));
797+ av_frame_unref (is -> frame );
798+ #else
771799 data_size = av_samples_get_buffer_size (NULL , is -> frame -> channels ,
772800 is -> frame -> nb_samples ,
773801 is -> frame -> format , 1 );
@@ -778,6 +806,7 @@ void audio_packet_process(VideoState *is, AVPacket *pkt)
778806 is -> audio_clock += (double )data_size /
779807 (is -> frame -> channels * is -> frame -> sample_rate * av_get_bytes_per_sample (is -> frame -> format ));
780808 av_frame_unref (is -> frame );
809+ #endif
781810 }
782811
783812 if (ALIGN_AC3_PACKETS && is -> audio_st -> codecpar -> codec_id == AV_CODEC_ID_AC3 ) {
@@ -1036,6 +1065,10 @@ void DoSeekRequest(VideoState *is)
10361065 if (ret < 0 )
10371066 {
10381067 char * error_text ;
1068+ #if LIBAVCODEC_BUILD >= AV_VERSION_INT (59 , 37 , 100 ) && \
1069+ LIBAVUTIL_BUILD >= AV_VERSION_INT (57 , 28 , 100 )
1070+ error_text = "Generic" ;
1071+ #else
10391072 if (is -> pFormatCtx -> iformat -> read_seek )
10401073 {
10411074 error_text = "Format specific" ;
@@ -1048,6 +1081,7 @@ void DoSeekRequest(VideoState *is)
10481081 {
10491082 error_text = "Generic" ;
10501083 }
1084+ #endif
10511085
10521086 fprintf (stderr , "%s error while seeking. target=%6.3f, \"%s\"\n" , error_text ,is -> seek_pts , is -> pFormatCtx -> url );
10531087
@@ -1674,12 +1708,24 @@ int stream_component_open(VideoState *is, int stream_index)
16741708
16751709 codec = avcodec_find_decoder (codecPar -> codec_id );
16761710
1711+ if (use_qsv && !codec_hw ) {
1712+ if (codecPar -> codec_id == AV_CODEC_ID_MJPEG ) codec_hw = avcodec_find_decoder_by_name ("mjpeg_qsv" );
1713+ if (codecPar -> codec_id == AV_CODEC_ID_MPEG2VIDEO ) codec_hw = avcodec_find_decoder_by_name ("mpeg2_qsv" );
1714+ if (codecPar -> codec_id == AV_CODEC_ID_H264 ) codec_hw = avcodec_find_decoder_by_name ("h264_qsv" );
1715+ if (codecPar -> codec_id == AV_CODEC_ID_VC1 ) codec_hw = avcodec_find_decoder_by_name ("vc1_qsv" );
1716+ if (codecPar -> codec_id == AV_CODEC_ID_HEVC ) codec_hw = avcodec_find_decoder_by_name ("hevc_qsv" );
1717+ if (codecPar -> codec_id == AV_CODEC_ID_AV1 ) codec_hw = avcodec_find_decoder_by_name ("av1_qsv" );
1718+ if (codecPar -> codec_id == AV_CODEC_ID_VP8 ) codec_hw = avcodec_find_decoder_by_name ("vp8_qsv" );
1719+ if (codecPar -> codec_id == AV_CODEC_ID_VP9 ) codec_hw = avcodec_find_decoder_by_name ("vp9_qsv" );
1720+ }
1721+
16771722 if (use_dxva2 && !codec_hw ) {
16781723 if (codecPar -> codec_id == AV_CODEC_ID_MPEG2VIDEO ) codec_hw = avcodec_find_decoder_by_name ("mpeg2_dxva2" );
16791724 if (codecPar -> codec_id == AV_CODEC_ID_H264 ) codec_hw = avcodec_find_decoder_by_name ("h264_dxva2" );
16801725 if (codecPar -> codec_id == AV_CODEC_ID_MPEG4 ) codec_hw = avcodec_find_decoder_by_name ("mpeg4_dxva2" );
16811726 if (codecPar -> codec_id == AV_CODEC_ID_VC1 ) codec_hw = avcodec_find_decoder_by_name ("vc1_dxva2" );
16821727 if (codecPar -> codec_id == AV_CODEC_ID_HEVC ) codec_hw = avcodec_find_decoder_by_name ("hevc_dxva2" );
1728+ if (codecPar -> codec_id == AV_CODEC_ID_AV1 ) codec_hw = avcodec_find_decoder_by_name ("av1_dxva2" );
16831729 }
16841730
16851731 if (use_vdpau && !codec_hw ) {
@@ -1695,7 +1741,8 @@ int stream_component_open(VideoState *is, int stream_index)
16951741 if (codecPar -> codec_id == AV_CODEC_ID_H264 ) codec_hw = avcodec_find_decoder_by_name ("h264_cuvid" );
16961742 if (codecPar -> codec_id == AV_CODEC_ID_HEVC ) codec_hw = avcodec_find_decoder_by_name ("hevc_cuvid" );
16971743 if (codecPar -> codec_id == AV_CODEC_ID_MPEG4 ) codec_hw = avcodec_find_decoder_by_name ("mpeg4_cuvid" );
1698- if (codecPar -> codec_id == AV_CODEC_ID_VC1 ) codec_hw = avcodec_find_decoder_by_name ("vc1_cuvidl" );
1744+ if (codecPar -> codec_id == AV_CODEC_ID_VC1 ) codec_hw = avcodec_find_decoder_by_name ("vc1_cuvid" );
1745+ if (codecPar -> codec_id == AV_CODEC_ID_AV1 ) codec_hw = avcodec_find_decoder_by_name ("av1_cuvid" );
16991746 }
17001747
17011748 // If decoding in hardware try if running on a Raspberry Pi and then use it's decoder instead.
0 commit comments