From 5db5c0c1a9d8b71f2819e08522982fd1862fa75f Mon Sep 17 00:00:00 2001 From: Rodeo Date: Sun, 23 Jun 2013 18:09:20 +0000 Subject: [PATCH] QSV: hb_qsv_info refactoring. Rename hb_qsv_info_t.features to hb_qsv_info_t.capabilities Group capabilities that are always found together to a single define. Detect CPU platform earlier to be able to check for hardware-specific capabilities later on. git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/qsv@5598 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/enc_qsv.c | 6 +-- libhb/hb.c | 102 +++++++++++++++++++++++------------------------- libhb/hb.h | 7 ++-- test/test.c | 17 +------- 4 files changed, 56 insertions(+), 76 deletions(-) diff --git a/libhb/enc_qsv.c b/libhb/enc_qsv.c index 6693b6f01..c8c0e66e6 100644 --- a/libhb/enc_qsv.c +++ b/libhb/enc_qsv.c @@ -349,7 +349,7 @@ int qsv_enc_init( av_qsv_context* qsv, hb_work_private_t * pv ){ } // version-specific encoder options - if (hb_qsv_info->features & HB_QSV_FEATURE_CODEC_OPTIONS_2) + if (hb_qsv_info->capabilities & HB_QSV_CAP_MSDK_1_6) { if ((entry = hb_dict_get(qsv_opts_dict, QSV_NAME_mbbrc)) != NULL && entry->value != NULL) { @@ -643,7 +643,7 @@ int encqsvInit( hb_work_object_t * w, hb_job_t * job ) // note: MKV only has PTS so it's unaffected if ((job->mux & HB_MUX_MASK_MP4) && (profile != PROFILE_BASELINE) && - (hb_qsv_info->features & HB_QSV_FEATURE_DECODE_TIMESTAMPS) == 0) + (hb_qsv_info->capabilities & HB_QSV_CAP_MSDK_1_6) == 0) { if (hb_qsv_info->cpu_platform == HB_CPU_PLATFORM_INTEL_SNB) { @@ -934,7 +934,7 @@ int encqsvWork( hb_work_object_t * w, hb_buffer_t ** buf_in, // renderOffset -> DTS buf->s.start = buf->s.renderOffset = task->bs->TimeStamp; buf->s.stop = buf->s.start + duration; - if (hb_qsv_info->features & HB_QSV_FEATURE_DECODE_TIMESTAMPS) + if (hb_qsv_info->capabilities & HB_QSV_CAP_MSDK_1_6) buf->s.renderOffset = task->bs->DecodeTimeStamp; if(pv->qsv_config.gop_ref_dist > 1) diff --git a/libhb/hb.c b/libhb/hb.c index 0664e08f8..2f88816f6 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -377,55 +377,7 @@ static int hb_qsv_info_init() return -1; } - mfxSession session; - hb_qsv_info->features = 0; - hb_qsv_info->minimum_version.Major = HB_QSV_MINVERSION_MAJOR; - hb_qsv_info->minimum_version.Minor = HB_QSV_MINVERSION_MINOR; - hb_qsv_info->software_available = hb_qsv_info->hardware_available = 0; - - // check for software fallback - if (MFXInit(MFX_IMPL_SOFTWARE, - &hb_qsv_info->minimum_version, &session) == MFX_ERR_NONE) - { - hb_qsv_info->software_available = 1; - // our minimum is supported, but query the actual version - MFXQueryVersion(session, &hb_qsv_info->software_version); - MFXClose(session); - } - - // check for actual hardware support, Hardware acceleration via any supported OS infrastructure - if (MFXInit(MFX_IMPL_HARDWARE_ANY|MFX_IMPL_VIA_ANY, - &hb_qsv_info->minimum_version, &session) == MFX_ERR_NONE) - { - hb_qsv_info->hardware_available = 1; - // our minimum is supported, but query the actual version - MFXQueryVersion(session, &hb_qsv_info->hardware_version); - MFXClose(session); - } - - // support either implementation (at least for now) - hb_qsv_info->qsv_available = (hb_qsv_info->hardware_available || - hb_qsv_info->software_available); - - // check for version-dependent features - // we only use software as a fallback, so check hardware first - if (hb_qsv_info->hardware_available) - { - if (HB_QSV_MIN_HARDWARE(1, 6)) - { - hb_qsv_info->features |= HB_QSV_FEATURE_DECODE_TIMESTAMPS; - hb_qsv_info->features |= HB_QSV_FEATURE_CODEC_OPTIONS_2; - } - } - else - { - if (HB_QSV_MIN_SOFTWARE(1, 6)) - { - hb_qsv_info->features |= HB_QSV_FEATURE_DECODE_TIMESTAMPS; - hb_qsv_info->features |= HB_QSV_FEATURE_CODEC_OPTIONS_2; - } - } - + // detect the CPU platform to check for hardware-specific capabilities if (av_get_cpu_flags() & AV_CPU_FLAG_SSE) { int eax, ebx, ecx, edx; @@ -457,7 +409,7 @@ static int hb_qsv_info_init() &hb_qsv_info->cpu_name[offset+8], &hb_qsv_info->cpu_name[offset+12]); } - + // Intel 64 and IA-32 Architectures Software Developer's Manual // Table 35-1. CPUID Signature Values of DisplayFamily_DisplayModel if (family == 0x06) @@ -468,17 +420,14 @@ static int hb_qsv_info_init() case 0x2D: hb_qsv_info->cpu_platform = HB_CPU_PLATFORM_INTEL_SNB; break; - case 0x3A: case 0x3E: hb_qsv_info->cpu_platform = HB_CPU_PLATFORM_INTEL_IVB; break; - case 0x3C: case 0x45: hb_qsv_info->cpu_platform = HB_CPU_PLATFORM_INTEL_HSW; break; - default: hb_qsv_info->cpu_platform = HB_CPU_PLATFORM_UNSPECIFIED; break; @@ -486,6 +435,53 @@ static int hb_qsv_info_init() } } + mfxSession session; + hb_qsv_info->capabilities = 0; + hb_qsv_info->minimum_version.Major = HB_QSV_MINVERSION_MAJOR; + hb_qsv_info->minimum_version.Minor = HB_QSV_MINVERSION_MINOR; + hb_qsv_info->software_available = hb_qsv_info->hardware_available = 0; + + // check for software fallback + if (MFXInit(MFX_IMPL_SOFTWARE, + &hb_qsv_info->minimum_version, &session) == MFX_ERR_NONE) + { + hb_qsv_info->software_available = 1; + // our minimum is supported, but query the actual version + MFXQueryVersion(session, &hb_qsv_info->software_version); + MFXClose(session); + } + + // check for actual hardware support, Hardware acceleration via any supported OS infrastructure + if (MFXInit(MFX_IMPL_HARDWARE_ANY|MFX_IMPL_VIA_ANY, + &hb_qsv_info->minimum_version, &session) == MFX_ERR_NONE) + { + hb_qsv_info->hardware_available = 1; + // our minimum is supported, but query the actual version + MFXQueryVersion(session, &hb_qsv_info->hardware_version); + MFXClose(session); + } + + // support either implementation (at least for now) + hb_qsv_info->qsv_available = (hb_qsv_info->hardware_available || + hb_qsv_info->software_available); + + // check for version-specific or hardware-specific capabilities + // we only use software as a fallback, so check hardware first + if (hb_qsv_info->hardware_available) + { + if (HB_QSV_MIN_HARDWARE(1, 6)) + { + hb_qsv_info->capabilities |= HB_QSV_CAP_MSDK_1_6; + } + } + else + { + if (HB_QSV_MIN_SOFTWARE(1, 6)) + { + hb_qsv_info->capabilities |= HB_QSV_CAP_MSDK_1_6; + } + } + // note: we pass a pointer to MFXInit but it never gets modified // let's make sure of it just to be safe though if (hb_qsv_info->minimum_version.Major != HB_QSV_MINVERSION_MAJOR || diff --git a/libhb/hb.h b/libhb/hb.h index eca9f0e84..bd6ba55e9 100644 --- a/libhb/hb.h +++ b/libhb/hb.h @@ -160,10 +160,9 @@ typedef struct hb_qsv_info_s // version information mfxVersion minimum_version, hardware_version, software_version; - // supported version-dependent features - int features; -#define HB_QSV_FEATURE_DECODE_TIMESTAMPS 0x0000001 -#define HB_QSV_FEATURE_CODEC_OPTIONS_2 0x0000002 // see mfxExtCodingOption2 + // supported version-specific or hardware-specific capabilities + int capabilities; +#define HB_QSV_CAP_MSDK_1_6 0x0000001 // if a feature depends on the cpu generation enum diff --git a/test/test.c b/test/test.c index 79381ab97..fc1c6cff7 100644 --- a/test/test.c +++ b/test/test.c @@ -4205,22 +4205,7 @@ static int ParseOptions( int argc, char ** argv ) if (hb_qsv_available()) { /* XXX: for testing workarounds */ - hb_qsv_info->features = 0; - hb_qsv_info->cpu_platform = HB_CPU_PLATFORM_UNSPECIFIED; - if (hb_qsv_info->hardware_available) - { - hb_qsv_info->hardware_version.Major = - hb_qsv_info->minimum_version.Major; - hb_qsv_info->hardware_version.Minor = - hb_qsv_info->minimum_version.Minor; - } - if (hb_qsv_info->software_available) - { - hb_qsv_info->software_version.Major = - hb_qsv_info->minimum_version.Major; - hb_qsv_info->software_version.Minor = - hb_qsv_info->minimum_version.Minor; - } + hb_qsv_info->capabilities &= ~HB_QSV_CAP_MSDK_1_6; } #endif break; -- 2.40.0