]> granicus.if.org Git - handbrake/commitdiff
DXVA2: cleanup decode support checks.
authorRodeo <tdskywalker@gmail.com>
Tue, 23 Jun 2015 17:09:34 +0000 (17:09 +0000)
committerRodeo <tdskywalker@gmail.com>
Tue, 23 Jun 2015 17:09:34 +0000 (17:09 +0000)
This should fix https://forum.handbrake.fr/viewtopic.php?f=11&t=32520

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7310 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/common.c
libhb/common.h
libhb/cropscale.c
libhb/decavcodec.c
libhb/scan.c
libhb/stream.c
libhb/work.c
test/test.c

index 8cc1dc65dd758fce04737cfb42860b86308bf6cb..526ee78743f76438641262a5594b8f28ce360c0d 100644 (file)
@@ -4532,15 +4532,3 @@ void hb_hexdump( hb_debug_level_t level, const char * label, const uint8_t * dat
         hb_deep_log( level, "    %-50s%20s", line, ascii );
     }
 }
-
-int hb_use_dxva( hb_title_t * title )
-{
-    return ( (title->video_codec_param == AV_CODEC_ID_MPEG2VIDEO
-              || title->video_codec_param == AV_CODEC_ID_H264
-              || title->video_codec_param == AV_CODEC_ID_VC1
-              || title->video_codec_param == AV_CODEC_ID_WMV3
-              || title->video_codec_param == AV_CODEC_ID_MPEG4 
-              || title->video_codec_param == AV_CODEC_ID_HEVC )
-             && title->opaque_priv );
-}
-
index 14faa31fd6aee2a9a791238405ee74cf03b36178..a96a3e4e77a5f83383eb1fecd7ed4d0ed70ef304 100644 (file)
@@ -962,8 +962,9 @@ struct hb_title_s
 
     // additional supported video decoders (e.g. HW-accelerated implementations)
     int           video_decode_support;
-#define HB_DECODE_SUPPORT_SW  0x01 // software (libavcodec or mpeg2dec)
-#define HB_DECODE_SUPPORT_QSV 0x02 // Intel Quick Sync Video
+#define HB_DECODE_SUPPORT_SW    0x01 // software (libavcodec or mpeg2dec)
+#define HB_DECODE_SUPPORT_QSV   0x02 // Intel Quick Sync Video
+#define HB_DECODE_SUPPORT_DXVA2 0x04 // Microsoft DXVA2
 
     hb_metadata_t * metadata;
 
@@ -979,7 +980,6 @@ struct hb_title_s
 
     // whether OpenCL scaling is supported for this source
     int             opencl_support;
-    int             hwd_support; // TODO: merge to video_decode_support
 };
 
 // Update win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_state_s.cs when changing this struct
@@ -1153,8 +1153,6 @@ extern hb_work_object_t hb_reader;
 #define HB_FILTER_DROP    3
 #define HB_FILTER_DONE    4
 
-int hb_use_dxva(hb_title_t *title);
-
 typedef struct hb_filter_init_s
 {
     hb_job_t    * job;
@@ -1163,7 +1161,6 @@ typedef struct hb_filter_init_s
     int           crop[4];
     hb_rational_t vrate;
     int           cfr;
-    int           use_dxva;
 } hb_filter_init_t;
 
 typedef struct hb_filter_info_s
index fc88e32a4d0d12ad8e91c565a989fb04e096a173..548bdcc2e193fc0edb4ffe808f2e0686f3d038fa 100644 (file)
@@ -71,7 +71,7 @@ static int hb_crop_scale_init( hb_filter_object_t * filter,
     pv->height_out = init->geometry.height - (init->crop[0] + init->crop[1]);
 
     /* OpenCL/DXVA2 */
-    pv->use_dxva       = init->use_dxva;
+    pv->use_dxva       = hb_hwd_enabled(init->job->h);
     pv->use_decomb     = init->job->use_decomb;
     pv->use_detelecine = init->job->use_detelecine;
 
index bdca1e1806bc780a2219bf98b01ffd84ada27e28..f81205ada76ee0aa71e2eaacb61ef836a64df442 100644 (file)
@@ -1669,8 +1669,7 @@ static int decavcodecvInit( hb_work_object_t * w, hb_job_t * job )
         pv->context->error_concealment = FF_EC_GUESS_MVS|FF_EC_DEBLOCK;
 #ifdef USE_HWD
         // QSV decoding is faster, so prefer it to DXVA2
-        if (pv->job != NULL && !pv->qsv.decode && pv->job->use_hwd &&
-            hb_use_dxva(pv->title))
+        if (pv->job != NULL && !pv->qsv.decode && hb_hwd_enabled(pv->job->h))
         {
             pv->dxva2 = hb_va_create_dxva2( pv->dxva2, w->codec_param );
             if( pv->dxva2 && pv->dxva2->do_job == HB_WORK_OK )
@@ -1685,6 +1684,10 @@ static int decavcodecvInit( hb_work_object_t * w, hb_job_t * job )
                 memset( pv->opencl_scale, 0, sizeof( hb_oclscale_t ) );
                 pv->threads = 1;
             }
+            else
+            {
+                hb_log("decavcodecvInit: hb_va_create_dxva2 failed, using software decoder");
+            }
         }
 #endif
 
@@ -2123,6 +2126,17 @@ static int decavcodecvInfo( hb_work_object_t *w, hb_work_info_t *info )
         default:
             break;
     }
+#ifdef USE_HWD
+    hb_va_dxva2_t *dxva2 = hb_va_create_dxva2(NULL, pv->context->codec_id);
+    if (dxva2 != NULL)
+    {
+        if (hb_check_hwd_fmt(pv->context->pix_fmt))
+        {
+            info->video_decode_support |= HB_DECODE_SUPPORT_DXVA2;
+        }
+        hb_va_close(dxva2);
+    }
+#endif
 
     return 1;
 }
index 3a19d9e19132915b0bfd220c4e3b90c7d799ea42..a446344cd20bde44943d8015f5d59497be833feb 100644 (file)
@@ -1039,6 +1039,14 @@ skip_preview:
                 aspect_to_string(&title->dar),
                 title->geometry.par.num, title->geometry.par.den);
 
+        if (title->video_decode_support != HB_DECODE_SUPPORT_SW)
+        {
+            hb_log("scan: supported video decoders:%s%s%s",
+                   !(title->video_decode_support & HB_DECODE_SUPPORT_SW)    ? "" : " avcodec",
+                   !(title->video_decode_support & HB_DECODE_SUPPORT_QSV)   ? "" : " qsv",
+                   !(title->video_decode_support & HB_DECODE_SUPPORT_DXVA2) ? "" : " dxva2");
+        }
+
         if( interlaced_preview_count >= ( npreviews / 2 ) )
         {
             hb_log("Title is likely interlaced or telecined (%i out of %i previews). You should do something about that.",
index be214c4bc0c3f4c8a954a09a3f99fc77ae997e55..cb669e52f42ab5998435c52166020655ca5a4404 100644 (file)
@@ -842,6 +842,8 @@ hb_stream_open(hb_handle_t *h, char *path, hb_title_t *title, int scan)
     d->path = strdup( path );
     if (d->path != NULL )
     {
+        // XXX: DXVA2 integration code requires an AVFormatContext
+        // use lavf instead of our MPEG demuxer when it's enabled
         if (!hb_hwd_enabled(d->h) && hb_stream_get_type( d ) != 0 )
         {
             if( !scan )
@@ -1104,20 +1106,6 @@ hb_title_t * hb_stream_title_scan(hb_stream_t *stream, hb_title_t * title)
     {
         hb_log( "transport stream missing PCRs - using video DTS instead" );
     }
-#ifdef USE_HWD
-    hb_va_dxva2_t * dxva2 = NULL;
-    dxva2 = hb_va_create_dxva2( dxva2, title->video_codec_param );
-    if ( dxva2 )
-    {
-        title->hwd_support = 1;
-        hb_va_close(dxva2);
-        dxva2 = NULL;
-    }
-    else
-        title->hwd_support = 0;
-#else
-    title->hwd_support = 0;
-#endif
 
     // Height, width, rate and aspect ratio information is filled in
     // when the previews are built
@@ -5594,24 +5582,6 @@ static hb_title_t *ffmpeg_title_scan( hb_stream_t *stream, hb_title_t *title )
         chapter->seconds = title->seconds;
         hb_list_add( title->list_chapter, chapter );
     }
-#ifdef USE_HWD
-    hb_va_dxva2_t * dxva2 = NULL;
-    dxva2 = hb_va_create_dxva2( dxva2, title->video_codec_param );
-    if (dxva2)
-    {
-        title->hwd_support = 1;
-        hb_va_close(dxva2);
-        dxva2 = NULL;
-    }
-    else
-        title->hwd_support = 0;
-   if ( hb_check_hwd_fmt(pix_fmt) == 0)
-       title->hwd_support = 0;
-#else
-    // Eliminate compiler warning "pix_fmt set but not used"
-    (void)pix_fmt;
-    title->hwd_support = 0;
-#endif
 
     return title;
 }
index 2ac218d27b0a13a77b3376297f6f247c4a051974..3d158862b34892b48c9c67894e9d3c28b7ecc5e8 100644 (file)
@@ -300,6 +300,13 @@ void hb_display_job_info(hb_job_t *job)
                hb_qsv_decode_get_codec_name(title->video_codec_param));
     }
     else
+#endif
+#ifdef USE_HWD
+    if (hb_hwd_enabled(job->h))
+    {
+        hb_log("   + decoder: %s (dxva2)", title->video_codec_name);
+    }
+    else
 #endif
     {
         hb_log("   + decoder: %s", title->video_codec_name);
@@ -909,6 +916,23 @@ static void do_job(hb_job_t *job)
     }
 #endif
 
+#ifdef USE_HWD
+    /*
+     * Check support for and enable DXVA2-accelerated when applicable; we need:
+     * - a compatible input bitstream (HB_DECODE_SUPPORT_DXVA2)
+     * - DXVA2-accelerated decoding enabled (job->use_hwd)
+     * - an AVFormatContext (title->opaque_priv) for now
+     */
+    if (title->video_decode_support & HB_DECODE_SUPPORT_DXVA2)
+    {
+        hb_hwd_set_enable(job->h, job->use_hwd && title->opaque_priv != NULL);
+    }
+    else
+#endif
+    {
+        hb_hwd_set_enable(job->h, 0);
+    }
+
     // Filters have an effect on settings.
     // So initialize the filters and update the job.
     if( job->list_filter && hb_list_count( job->list_filter ) )
@@ -920,9 +944,6 @@ static void do_job(hb_job_t *job)
         init.geometry.width = title->geometry.width;
         init.geometry.height = title->geometry.height;
 
-        /* DXVA2 */
-        init.use_dxva = hb_use_dxva(title);
-
         init.geometry.par = job->par;
         memcpy(init.crop, title->crop, sizeof(int[4]));
         init.vrate = title->vrate;
index 4d72283b94057c95be511264211e42131a34cc64..049be4d99a7f7cdc73633fdb8a9e0397a9241c8e 100644 (file)
@@ -542,11 +542,6 @@ static void PrintTitleInfo( hb_title_t * title, int feature )
              title->crop[1], title->crop[2], title->crop[3] );
 
     fprintf(stderr, "  + support opencl: %s\n", title->opencl_support ? "yes" : "no");
-#ifdef USE_HWD
-    fprintf(stderr, "  + support hwd: %s\n", title->hwd_support ? "yes" : "no");
-#else
-    fprintf(stderr, "  + support hwd: not built-in\n");
-#endif
 
     fprintf( stderr, "  + chapters:\n" );
     for( i = 0; i < hb_list_count( title->list_chapter ); i++ )