@@ -225,6 +225,7 @@ static int libavcodec_decompress(H264_CONTEXT* h264, const BYTE* pSrcData, UINT3
225
225
packet -> size = (int )MIN (SrcSize , INT32_MAX );
226
226
227
227
WINPR_ASSERT (sys -> codecDecoderContext );
228
+
228
229
/* avcodec_decode_video2 is deprecated with libavcodec 57.48.101 */
229
230
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (57 , 48 , 101 )
230
231
status = avcodec_send_packet (sys -> codecDecoderContext , packet );
@@ -264,7 +265,6 @@ static int libavcodec_decompress(H264_CONTEXT* h264, const BYTE* pSrcData, UINT3
264
265
}
265
266
266
267
#ifdef WITH_VAAPI
267
-
268
268
if (sys -> hwctx )
269
269
{
270
270
if (sys -> hwVideoFrame -> format == sys -> hw_pix_fmt )
@@ -287,7 +287,6 @@ static int libavcodec_decompress(H264_CONTEXT* h264, const BYTE* pSrcData, UINT3
287
287
av_err2str (status ));
288
288
goto fail ;
289
289
}
290
-
291
290
#endif
292
291
#if 0
293
292
WLog_Print (h264 -> log , WLOG_INFO ,
@@ -482,7 +481,6 @@ static void libavcodec_uninit(H264_CONTEXT* h264)
482
481
}
483
482
484
483
#ifdef WITH_VAAPI
485
-
486
484
if (sys -> hwVideoFrame )
487
485
{
488
486
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55 , 18 , 102 )
@@ -496,7 +494,6 @@ static void libavcodec_uninit(H264_CONTEXT* h264)
496
494
av_buffer_unref (& sys -> hwctx );
497
495
498
496
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT (57 , 80 , 100 )
499
-
500
497
if (sys -> hw_frames_ctx )
501
498
av_buffer_unref (& sys -> hw_frames_ctx );
502
499
@@ -621,29 +618,32 @@ static BOOL libavcodec_init(H264_CONTEXT* h264)
621
618
#endif
622
619
623
620
#ifdef WITH_VAAPI
624
-
625
- if (!sys -> hwctx )
621
+ if (h264 -> HardwareAccelerated != 0 )
626
622
{
627
- int ret =
628
- av_hwdevice_ctx_create (& sys -> hwctx , AV_HWDEVICE_TYPE_VAAPI , VAAPI_DEVICE , NULL , 0 );
629
-
630
- if (ret < 0 )
623
+ if (!sys -> hwctx )
631
624
{
632
- WLog_Print (h264 -> log , WLOG_ERROR ,
633
- "Could not initialize hardware decoder, falling back to software: %s" ,
634
- av_err2str (ret ));
635
- sys -> hwctx = NULL ;
636
- goto fail_hwdevice_create ;
625
+ int ret =
626
+ av_hwdevice_ctx_create (& sys -> hwctx , AV_HWDEVICE_TYPE_VAAPI , VAAPI_DEVICE , NULL , 0 );
627
+
628
+ if (ret < 0 )
629
+ {
630
+ WLog_Print (h264 -> log , WLOG_ERROR ,
631
+ "Could not initialize hardware decoder, falling back to software: %s" ,
632
+ av_err2str (ret ));
633
+ sys -> hwctx = NULL ;
634
+ goto fail_hwdevice_create ;
635
+ }
637
636
}
638
- }
639
- WLog_Print (h264 -> log , WLOG_INFO , "Using VAAPI for accelerated H264 decoding" );
637
+ WLog_Print (h264 -> log , WLOG_INFO , "Using VAAPI for accelerated H264 decoding" );
640
638
641
- sys -> codecDecoderContext -> get_format = libavcodec_get_format ;
642
- sys -> hw_pix_fmt = AV_PIX_FMT_VAAPI ;
639
+ sys -> codecDecoderContext -> get_format = libavcodec_get_format ;
640
+ sys -> hw_pix_fmt = AV_PIX_FMT_VAAPI ;
643
641
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (57 , 80 , 100 )
644
- sys -> codecDecoderContext -> hw_device_ctx = av_buffer_ref (sys -> hwctx );
642
+ sys -> codecDecoderContext -> hw_device_ctx = av_buffer_ref (sys -> hwctx );
645
643
#endif
646
- sys -> codecDecoderContext -> opaque = (void * )h264 ;
644
+ sys -> codecDecoderContext -> opaque = (void * )h264 ;
645
+ }
646
+
647
647
fail_hwdevice_create :
648
648
#endif
649
649
@@ -665,7 +665,10 @@ static BOOL libavcodec_init(H264_CONTEXT* h264)
665
665
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT (55 , 18 , 102 )
666
666
sys -> videoFrame = av_frame_alloc ();
667
667
#ifdef WITH_VAAPI
668
- sys -> hwVideoFrame = av_frame_alloc ();
668
+ if (h264 -> HardwareAccelerated != 0 )
669
+ {
670
+ sys -> hwVideoFrame = av_frame_alloc ();
671
+ }
669
672
#endif
670
673
#else
671
674
sys -> videoFrame = avcodec_alloc_frame ();
@@ -678,11 +681,13 @@ static BOOL libavcodec_init(H264_CONTEXT* h264)
678
681
}
679
682
680
683
#ifdef WITH_VAAPI
681
-
682
- if (!sys -> hwVideoFrame )
684
+ if (h264 -> HardwareAccelerated != 0 )
683
685
{
684
- WLog_Print (h264 -> log , WLOG_ERROR , "Failed to allocate libav hw frame" );
685
- goto EXCEPTION ;
686
+ if (!sys -> hwVideoFrame )
687
+ {
688
+ WLog_Print (h264 -> log , WLOG_ERROR , "Failed to allocate libav hw frame" );
689
+ goto EXCEPTION ;
690
+ }
686
691
}
687
692
688
693
#endif
0 commit comments