@@ -155,6 +155,7 @@ bool AudioLocation::is_near(AudioLocation location, int samples_per_frame, int64
155155
156156#if IS_FFMPEG_3_2
157157
158+ #if defined(__linux__)
158159static enum AVPixelFormat get_hw_dec_format_va (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
159160{
160161 const enum AVPixelFormat *p;
@@ -188,7 +189,9 @@ static enum AVPixelFormat get_hw_dec_format_cu(AVCodecContext *ctx, const enum A
188189 ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::ReadStream (Unable to decode this file using hardware decode.)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
189190 return AV_PIX_FMT_NONE;
190191 }
192+ #endif
191193
194+ #if defined(_WIN32)
192195static enum AVPixelFormat get_hw_dec_format_dx (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
193196{
194197 const enum AVPixelFormat *p;
@@ -222,7 +225,9 @@ static enum AVPixelFormat get_hw_dec_format_d3(AVCodecContext *ctx, const enum A
222225 ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::ReadStream (Unable to decode this file using hardware decode.)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
223226 return AV_PIX_FMT_NONE;
224227 }
228+ #endif
225229
230+ #if defined(__APPLE__)
226231static enum AVPixelFormat get_hw_dec_format_qs (AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts)
227232{
228233 const enum AVPixelFormat *p;
@@ -239,6 +244,7 @@ static enum AVPixelFormat get_hw_dec_format_qs(AVCodecContext *ctx, const enum A
239244 ZmqLogger::Instance ()->AppendDebugMethod (" FFmpegReader::ReadStream (Unable to decode this file using hardware decode.)" , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 , " " , -1 );
240245 return AV_PIX_FMT_NONE;
241246}
247+ #endif
242248
243249int FFmpegReader::is_hardware_decode_supported (int codecid)
244250{
@@ -345,7 +351,7 @@ void FFmpegReader::Open()
345351 char adapter[256 ];
346352 char *adapter_ptr = NULL ;
347353 int adapter_num;
348- dev_hw = getenv ( " HW_DE_DEVICE_SET" );
354+ dev_hw = getenv ( " HW_DE_DEVICE_SET" ); // The first card is 0
349355 if ( dev_hw != NULL ) {
350356 adapter_num = atoi (dev_hw);
351357 } else {
@@ -354,7 +360,6 @@ void FFmpegReader::Open()
354360 if (adapter_num < 3 && adapter_num >=0 ) {
355361 #if defined(__linux__)
356362 snprintf (adapter,sizeof (adapter)," /dev/dri/renderD%d" , adapter_num+128 );
357- // Maybe 127 is better because the first card would be 1?!
358363 adapter_ptr = adapter;
359364 #elif defined(_WIN32)
360365 adapter_ptr = NULL ;
@@ -380,8 +385,6 @@ void FFmpegReader::Open()
380385 }
381386 hw_device_ctx = NULL ;
382387 // Here the first hardware initialisations are made
383- // TODO: check for each format in an extra call
384- // Now only vaapi the first in the list is found
385388 #if defined(__linux__)
386389 hw_de_av_device_type = AV_HWDEVICE_TYPE_VAAPI;
387390 pCodecCtx->get_format = get_hw_dec_format_va;
@@ -401,7 +404,6 @@ void FFmpegReader::Open()
401404 }
402405 else {
403406 throw InvalidCodec (" Hardware device create failed." , path);
404-
405407 }
406408 }
407409 #endif
@@ -410,19 +412,29 @@ void FFmpegReader::Open()
410412 pCodecCtx->get_format = get_hw_dec_format_dx;
411413 if (av_hwdevice_ctx_create (&hw_device_ctx, hw_de_av_device_type, adapter_ptr, NULL , 0 ) >= 0 ) {
412414 if (!(pCodecCtx->hw_device_ctx = av_buffer_ref (hw_device_ctx))) {
413- throw InvalidCodec (" Hardware device reference create failed vaapi ." , path);
415+ throw InvalidCodec (" Hardware device reference create failed dxva2 ." , path);
414416 }
415417 }
416418 else {
417- throw InvalidCodec (" Hardware device create failed." , path);
418- }
419+ hw_de_av_device_type = AV_HWDEVICE_TYPE_D3D11;
420+ pCodecCtx->get_format = get_hw_dec_format_cu;
421+ hw_device_ctx = NULL ;
422+ if (av_hwdevice_ctx_create (&hw_device_ctx, hw_de_av_device_type, adapter_ptr, NULL , 0 ) >= 0 ) {
423+ if (!(pCodecCtx->hw_device_ctx = av_buffer_ref (hw_device_ctx))) {
424+ throw InvalidCodec (" Hardware device reference create failed d3d11." , path);
425+ }
426+ }
427+ else {
428+ throw InvalidCodec (" Hardware device create failed." , path);
429+ }
430+ }
419431 #endif
420432 #if defined(__APPLE__)
421433 hw_de_av_device_type = AV_HWDEVICE_TYPE_QSV;
422434 pCodecCtx->get_format = get_hw_dec_format_qs;
423435 if (av_hwdevice_ctx_create (&hw_device_ctx, hw_de_av_device_type, adapter_ptr, NULL , 0 ) >= 0 ) {
424436 if (!(pCodecCtx->hw_device_ctx = av_buffer_ref (hw_device_ctx))) {
425- throw InvalidCodec (" Hardware device reference create failed vaapi ." , path);
437+ throw InvalidCodec (" Hardware device reference create failed qsv ." , path);
426438 }
427439 }
428440 else {
0 commit comments