void PTSMaker::PrintDumpInfo() { msdk_printf(MSDK_STRING("Error in PTS setting \n")); msdk_printf(MSDK_STRING("Input frame number is %d\n"), m_NumFrame_In); msdk_printf(MSDK_STRING("Output frame number is %d\n"), m_NumFrame_Out); msdk_printf(MSDK_STRING("Initial time offset is %f\n"), m_TimeOffset); msdk_printf(MSDK_STRING("PTS difference is %f\n"), m_CurrDiff); }
int main(int argc, char *argv[]) #endif { sInputParams Params; // input parameters from command line CDecodingPipeline Pipeline; // pipeline for decoding, includes input file reader, decoder and output file writer mfxStatus sts = MFX_ERR_NONE; // return value check sts = ParseInputString(argv, (mfxU8)argc, &Params); MSDK_CHECK_PARSE_RESULT(sts, MFX_ERR_NONE, 1); if (Params.bIsMVC) Pipeline.SetMultiView(); sts = Pipeline.Init(&Params); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1); // print stream info Pipeline.PrintInfo(); msdk_printf(MSDK_STRING("Decoding started\n")); for (;;) { sts = Pipeline.RunDecoding(); if (MFX_ERR_INCOMPATIBLE_VIDEO_PARAM == sts || MFX_ERR_DEVICE_LOST == sts || MFX_ERR_DEVICE_FAILED == sts) { if (MFX_ERR_INCOMPATIBLE_VIDEO_PARAM == sts) { msdk_printf(MSDK_STRING("\nERROR: Incompatible video parameters detected. Recovering...\n")); } else { msdk_printf(MSDK_STRING("\nERROR: Hardware device was lost or returned unexpected error. Recovering...\n")); sts = Pipeline.ResetDevice(); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1); } sts = Pipeline.ResetDecoder(&Params); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1); continue; } else { MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1); break; } } msdk_printf(MSDK_STRING("\nDecoding finished\n")); return 0; }
mfxStatus CVAAPIDeviceWayland::RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * /*pmfxAlloc*/) { uint32_t drm_format; int offsets[3], pitches[3]; mfxStatus mfx_res = MFX_ERR_NONE; vaapiMemId * memId = NULL; struct wl_buffer *m_wl_buffer = NULL; if(NULL==pSurface) { mfx_res = MFX_ERR_UNKNOWN; return mfx_res; } m_Wayland->Sync(); memId = (vaapiMemId*)(pSurface->Data.MemId); if (pSurface->Info.FourCC == MFX_FOURCC_NV12) { drm_format = WL_DRM_FORMAT_NV12; } else if(pSurface->Info.FourCC = MFX_FOURCC_RGB4) { drm_format = WL_DRM_FORMAT_ARGB8888; } offsets[0] = memId->m_image.offsets[0]; offsets[1] = memId->m_image.offsets[1]; offsets[2] = memId->m_image.offsets[2]; pitches[0] = memId->m_image.pitches[0]; pitches[1] = memId->m_image.pitches[1]; pitches[2] = memId->m_image.pitches[2]; m_wl_buffer = m_Wayland->CreatePrimeBuffer(memId->m_buffer_info.handle , pSurface->Info.CropW , pSurface->Info.CropH , drm_format , offsets , pitches); if(NULL == m_wl_buffer) { msdk_printf("\nCan't wrap flink to wl_buffer\n"); mfx_res = MFX_ERR_UNKNOWN; return mfx_res; } m_Wayland->RenderBuffer(m_wl_buffer, pSurface->Info.CropW, pSurface->Info.CropH); return mfx_res; }
mfxStatus CParametersDumper::DumpLibraryConfiguration(msdk_string fileName, MFXVideoDECODE* pMfxDec, MFXVideoVPP* pMfxVPP, MFXVideoENCODE* pMfxEnc, const mfxVideoParam* pDecoderPresetParams, const mfxVideoParam* pVPPPresetParams, const mfxVideoParam* pEncoderPresetParams) { try { msdk_fstream sstr(fileName.c_str(),std::fstream::out); sstr<<MSDK_STRING("Configuration settings (fields from API ") << MFX_VERSION_MAJOR << MSDK_STRING(".") << MFX_VERSION_MINOR << MSDK_STRING(")\n"); mfxVideoParam params; if(pMfxDec) { if (GetUnitParams(pMfxDec, pDecoderPresetParams,¶ms) == MFX_ERR_NONE) { SerializeVideoParamStruct(sstr, MSDK_STRING("*** Decoder ***"), params, false); ClearExtBuffs(¶ms); } } if(pMfxVPP) { if (GetUnitParams(pMfxVPP, pVPPPresetParams, ¶ms) == MFX_ERR_NONE) { SerializeVideoParamStruct(sstr, MSDK_STRING("*** VPP ***"), params, true); ClearExtBuffs(¶ms); } } if(pMfxEnc) { if (GetUnitParams(pMfxEnc, pEncoderPresetParams, ¶ms) == MFX_ERR_NONE) { SerializeVideoParamStruct(sstr, MSDK_STRING("*** Encoder ***"), params, false); ClearExtBuffs(¶ms); } } sstr.close(); } catch(...) { msdk_printf(MSDK_STRING("Cannot save library settings into file.\n")); return MFX_ERR_NULL_PTR; } return MFX_ERR_NONE; }
mfxStatus CVAAPIDeviceDRM::Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum) { if (0 == nViews) { return MFX_ERR_NONE; } if (1 == nViews) { if (m_DRMLibVA.getBackendType() == MFX_LIBVA_DRM_RENDERNODE) { return MFX_ERR_NONE; } mfxI32 * monitorType = (mfxI32*)hWindow; if (!monitorType) return MFX_ERR_INVALID_VIDEO_PARAM; try { m_rndr = new drmRenderer(m_DRMLibVA.getFD(), *monitorType); } catch(...) { msdk_printf(MSDK_STRING("vaapi_device: failed to initialize drmrender\n")); return MFX_ERR_UNKNOWN; } return MFX_ERR_NONE; } return MFX_ERR_UNSUPPORTED; }
void PrintHelp(msdk_char *strAppName, const msdk_char *strErrorMessage) { msdk_printf(MSDK_STRING("Decoding Sample Version %s\n\n"), MSDK_SAMPLE_VERSION); if (strErrorMessage) { msdk_printf(MSDK_STRING("Error: %s\n"), strErrorMessage); } msdk_printf(MSDK_STRING("Usage: %s <codecid> [<options>] -i InputBitstream\n"), strAppName); msdk_printf(MSDK_STRING(" or: %s <codecid> [<options>] -i InputBitstream -r\n"), strAppName); msdk_printf(MSDK_STRING(" or: %s <codecid> [<options>] -i InputBitstream -o OutputYUVFile\n"), strAppName); msdk_printf(MSDK_STRING("\n")); msdk_printf(MSDK_STRING("Supported codecs (<codecid>):\n")); msdk_printf(MSDK_STRING(" <codecid>=h264|mpeg2|vc1|mvc|jpeg - built-in Media SDK codecs\n")); msdk_printf(MSDK_STRING(" <codecid>=h265|capture - in-box Media SDK plugins (may require separate downloading and installation)\n")); msdk_printf(MSDK_STRING("\n")); msdk_printf(MSDK_STRING("Work models:\n")); msdk_printf(MSDK_STRING(" 1. Performance model: decoding on MAX speed, no rendering, no YUV dumping (no -r or -o option)\n")); msdk_printf(MSDK_STRING(" 2. Rendering model: decoding with rendering on the screen (-r option)\n")); msdk_printf(MSDK_STRING(" 3. Dump model: decoding with YUV dumping (-o option)\n")); msdk_printf(MSDK_STRING("\n")); msdk_printf(MSDK_STRING("Options:\n")); msdk_printf(MSDK_STRING(" [-hw] - use platform specific SDK implementation (default)\n")); msdk_printf(MSDK_STRING(" [-sw] - use software implementation, if not specified platform specific SDK implementation is used\n")); msdk_printf(MSDK_STRING(" [-p guid] - 32-character hexadecimal guid string\n")); msdk_printf(MSDK_STRING(" [-path path] - path to plugin (valid only in pair with -p option)\n")); msdk_printf(MSDK_STRING(" (optional for Media SDK in-box plugins, required for user-decoder ones)\n")); msdk_printf(MSDK_STRING(" [-f] - rendering framerate\n")); msdk_printf(MSDK_STRING(" [-w] - output width\n")); msdk_printf(MSDK_STRING(" [-h] - output height\n")); msdk_printf(MSDK_STRING(" [-di bob/adi] - enable deinterlacing BOB/ADI\n")); msdk_printf(MSDK_STRING("\n")); msdk_printf(MSDK_STRING("Output format parameters:\n")); msdk_printf(MSDK_STRING(" [-i420] - by default\n")); msdk_printf(MSDK_STRING(" [-rgb4]\n")); msdk_printf(MSDK_STRING(" [-p010]\n")); msdk_printf(MSDK_STRING(" [-a2rgb10]\n")); msdk_printf(MSDK_STRING("\n")); #if D3D_SURFACES_SUPPORT msdk_printf(MSDK_STRING(" [-d3d] - work with d3d9 surfaces\n")); msdk_printf(MSDK_STRING(" [-d3d11] - work with d3d11 surfaces\n")); msdk_printf(MSDK_STRING(" [-r] - render decoded data in a separate window \n")); msdk_printf(MSDK_STRING(" [-wall w h n m t tmo] - same as -r, and positioned rendering window in a particular cell on specific monitor \n")); msdk_printf(MSDK_STRING(" w - number of columns of video windows on selected monitor\n")); msdk_printf(MSDK_STRING(" h - number of rows of video windows on selected monitor\n")); msdk_printf(MSDK_STRING(" n(0,.,w*h-1) - order of video window in table that will be rendered\n")); msdk_printf(MSDK_STRING(" m(0,1..) - monitor id \n")); msdk_printf(MSDK_STRING(" t(0/1) - enable/disable window's title\n")); msdk_printf(MSDK_STRING(" tmo - timeout for -wall option\n")); msdk_printf(MSDK_STRING("Screen capture parameters:\n")); msdk_printf(MSDK_STRING(" [-scr:w] - screen resolution width\n")); msdk_printf(MSDK_STRING(" [-scr:h] - screen resolution height\n")); msdk_printf(MSDK_STRING("\n")); #endif #if defined(LIBVA_SUPPORT) msdk_printf(MSDK_STRING(" [-vaapi] - work with vaapi surfaces\n")); #endif #if defined(LIBVA_X11_SUPPORT) msdk_printf(MSDK_STRING(" [-r] - render decoded data in a separate X11 window \n")); #endif #if defined(LIBVA_WAYLAND_SUPPORT) msdk_printf(MSDK_STRING(" [-rwld] - render decoded data in a Wayland window \n")); msdk_printf(MSDK_STRING(" [-perf] - turn on asynchronous flipping for Wayland rendering \n")); #endif #if defined(LIBVA_DRM_SUPPORT) msdk_printf(MSDK_STRING(" [-rdrm] - render decoded data in a thru DRM frame buffer\n")); msdk_printf(MSDK_STRING(" [-window x y w h]\n")); #endif msdk_printf(MSDK_STRING(" [-low_latency] - configures decoder for low latency mode (supported only for H.264 and JPEG codec)\n")); msdk_printf(MSDK_STRING(" [-calc_latency] - calculates latency during decoding and prints log (supported only for H.264 and JPEG codec)\n")); msdk_printf(MSDK_STRING(" [-async] - depth of asynchronous pipeline. default value is 4. must be between 1 and 20\n")); msdk_printf(MSDK_STRING(" [-no_gpu_copy] - disable GPU Copy functionality\n")); #if !defined(_WIN32) && !defined(_WIN64) msdk_printf(MSDK_STRING(" [-threads_num] - number of mediasdk task threads\n")); msdk_printf(MSDK_STRING(" [-threads_schedtype] - scheduling type of mediasdk task threads\n")); msdk_printf(MSDK_STRING(" [-threads_priority] - priority of mediasdk task threads\n")); msdk_printf(MSDK_STRING("\n")); msdk_thread_printf_scheduling_help(); #endif #if defined(_WIN32) || defined(_WIN64) msdk_printf(MSDK_STRING(" [-jpeg_rotate n] - rotate jpeg frame n degrees \n")); msdk_printf(MSDK_STRING(" n(90,180,270) - number of degrees \n")); msdk_printf(MSDK_STRING("\nFeatures: \n")); msdk_printf(MSDK_STRING(" Press 1 to toggle fullscreen rendering on/off\n")); #endif msdk_printf(MSDK_STRING("\n")); msdk_printf(MSDK_STRING("Example:\n")); msdk_printf(MSDK_STRING(" %s h265 -i in.bit -o out.yuv -p 15dd936825ad475ea34e35f3f54217a6\n"), strAppName); }
mfxStatus ParseInputString(msdk_char* strInput[], mfxU8 nArgNum, sInputParams* pParams) { if (1 == nArgNum) { PrintHelp(strInput[0], NULL); return MFX_ERR_UNSUPPORTED; } MSDK_CHECK_POINTER(pParams, MFX_ERR_NULL_PTR); // set default implementation pParams->bUseHWLib = true; #if defined(LIBVA_SUPPORT) pParams->libvaBackend = MFX_LIBVA_DRM; #endif for (mfxU8 i = 1; i < nArgNum; i++) { if (MSDK_CHAR('-') != strInput[i][0]) { mfxStatus sts = StrFormatToCodecFormatFourCC(strInput[i], pParams->videoType); if (sts != MFX_ERR_NONE) { PrintHelp(strInput[0], MSDK_STRING("Unknown codec")); return MFX_ERR_UNSUPPORTED; } if (!IsDecodeCodecSupported(pParams->videoType)) { PrintHelp(strInput[0], MSDK_STRING("Unsupported codec")); return MFX_ERR_UNSUPPORTED; } if (pParams->videoType == CODEC_MVC) { pParams->videoType = MFX_CODEC_AVC; pParams->bIsMVC = true; } continue; } if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-sw"))) { pParams->bUseHWLib = false; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-hw"))) { pParams->bUseHWLib = true; } #if D3D_SURFACES_SUPPORT else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-d3d"))) { pParams->memType = D3D9_MEMORY; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-d3d11"))) { pParams->memType = D3D11_MEMORY; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-r"))) { pParams->mode = MODE_RENDERING; // use d3d9 rendering by default if (SYSTEM_MEMORY == pParams->memType) pParams->memType = D3D9_MEMORY; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-wall"))) { if(i + 6 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -wall key")); return MFX_ERR_UNSUPPORTED; } // use d3d9 rendering by default if (SYSTEM_MEMORY == pParams->memType) pParams->memType = D3D9_MEMORY; pParams->mode = MODE_RENDERING; msdk_opt_read(strInput[++i], pParams->nWallW); msdk_opt_read(strInput[++i], pParams->nWallH); msdk_opt_read(strInput[++i], pParams->nWallCell); msdk_opt_read(strInput[++i], pParams->nWallMonitor); mfxU32 nTitle; msdk_opt_read(strInput[++i], nTitle); pParams->bWallNoTitle = 0 == nTitle; msdk_opt_read(strInput[++i], pParams->nWallTimeout); } #endif #if defined(LIBVA_SUPPORT) else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-vaapi"))) { pParams->memType = D3D9_MEMORY; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-r"))) { pParams->memType = D3D9_MEMORY; pParams->mode = MODE_RENDERING; pParams->libvaBackend = MFX_LIBVA_X11; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-rwld"))) { pParams->memType = D3D9_MEMORY; pParams->mode = MODE_RENDERING; pParams->libvaBackend = MFX_LIBVA_WAYLAND; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-perf"))) { pParams->bPerfMode = true; } else if (0 == msdk_strncmp(strInput[i], MSDK_STRING("-rdrm"), 5)) { pParams->memType = D3D9_MEMORY; pParams->mode = MODE_RENDERING; pParams->libvaBackend = MFX_LIBVA_DRM_MODESET; if (strInput[i][5]) { if (strInput[i][5] != '-') { PrintHelp(strInput[0], MSDK_STRING("unsupported monitor type")); return MFX_ERR_UNSUPPORTED; } pParams->monitorType = getMonitorType(&strInput[i][6]); if (pParams->monitorType >= MFX_MONITOR_MAXNUMBER) { PrintHelp(strInput[0], MSDK_STRING("unsupported monitor type")); return MFX_ERR_UNSUPPORTED; } } else { pParams->monitorType = MFX_MONITOR_AUTO; // that's case of "-rdrm" pure option } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-window"))) { if(i +4 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -window key")); return MFX_ERR_UNSUPPORTED; } msdk_opt_read(strInput[++i], pParams->nRenderWinX); msdk_opt_read(strInput[++i], pParams->nRenderWinY); msdk_opt_read(strInput[++i], pParams->Width); msdk_opt_read(strInput[++i], pParams->Height); if (0 == pParams->Width) pParams->Width = 320; if (0 == pParams->Height) pParams->Height = 240; pParams->bRenderWin = true; } #endif else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-low_latency"))) { switch (pParams->videoType) { case MFX_CODEC_HEVC: case MFX_CODEC_AVC: case MFX_CODEC_JPEG: { pParams->bLowLat = true; if (!pParams->bIsMVC) break; } default: { PrintHelp(strInput[0], MSDK_STRING("-low_latency mode is suppoted only for H.264 and JPEG codecs")); return MFX_ERR_UNSUPPORTED; } } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-jpeg_rotate"))) { if(MFX_CODEC_JPEG != pParams->videoType) return MFX_ERR_UNSUPPORTED; if(i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -jpeg_rotate key")); return MFX_ERR_UNSUPPORTED; } msdk_opt_read(strInput[++i], pParams->nRotation); if((pParams->nRotation != 90)&&(pParams->nRotation != 180)&&(pParams->nRotation != 270)) { PrintHelp(strInput[0], MSDK_STRING("-jpeg_rotate is supported only for 90, 180 and 270 angles")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-calc_latency"))) { switch (pParams->videoType) { case MFX_CODEC_HEVC: case MFX_CODEC_AVC: case MFX_CODEC_JPEG: { pParams->bCalLat = true; if (!pParams->bIsMVC) break; } default: { PrintHelp(strInput[0], MSDK_STRING("-calc_latency mode is suppoted only for H.264 and JPEG codecs")); return MFX_ERR_UNSUPPORTED; } } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-async"))) { if(i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -async key")); return MFX_ERR_UNSUPPORTED; } if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nAsyncDepth)) { PrintHelp(strInput[0], MSDK_STRING("async is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-di"))) { if(i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -di key")); return MFX_ERR_UNSUPPORTED; } msdk_char diMode[4] = {}; if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], diMode)) { PrintHelp(strInput[0], MSDK_STRING("deinterlace value is not set")); return MFX_ERR_UNSUPPORTED; } if (0 == msdk_strcmp(diMode, MSDK_CHAR("bob"))) { pParams->eDeinterlace = MFX_DEINTERLACING_BOB; } else if (0 == msdk_strcmp(diMode, MSDK_CHAR("adi"))) { pParams->eDeinterlace = MFX_DEINTERLACING_ADVANCED; } else { PrintHelp(strInput[0], MSDK_STRING("deinterlace value is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-no_gpu_copy"))) { pParams->gpuCopy = MFX_GPUCOPY_OFF; } #if !defined(_WIN32) && !defined(_WIN64) else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-threads_num"))) { if(i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -threads_num key")); return MFX_ERR_UNSUPPORTED; } if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nThreadsNum)) { PrintHelp(strInput[0], MSDK_STRING("threads_num is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-threads_schedtype"))) { if(i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -threads_schedtype key")); return MFX_ERR_UNSUPPORTED; } if (MFX_ERR_NONE != msdk_thread_get_schedtype(strInput[++i], pParams->SchedulingType)) { PrintHelp(strInput[0], MSDK_STRING("threads_schedtype is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-threads_priority"))) { if(i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -threads_priority key")); return MFX_ERR_UNSUPPORTED; } if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->Priority)) { PrintHelp(strInput[0], MSDK_STRING("threads_priority is invalid")); return MFX_ERR_UNSUPPORTED; } } #endif // #if !defined(_WIN32) && !defined(_WIN64) else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-f"))) { if(i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -f key")); return MFX_ERR_UNSUPPORTED; } if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nMaxFPS)) { PrintHelp(strInput[0], MSDK_STRING("rendering frame rate is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-scr:w"))) { if (i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -scr:w key")); return MFX_ERR_UNSUPPORTED; } if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->scrWidth)) { PrintHelp(strInput[0], MSDK_STRING("screen width rate is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-scr:h"))) { if (i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -scr:h key")); return MFX_ERR_UNSUPPORTED; } if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->scrHeight)) { PrintHelp(strInput[0], MSDK_STRING("screen height is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-w"))) { if (i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -w key")); return MFX_ERR_UNSUPPORTED; } if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->Width)) { PrintHelp(strInput[0], MSDK_STRING("width is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-h"))) { if (i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -h key")); return MFX_ERR_UNSUPPORTED; } if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->Height)) { PrintHelp(strInput[0], MSDK_STRING("height is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-n"))) { if(i + 1 >= nArgNum) { PrintHelp(strInput[0], MSDK_STRING("Not enough parameters for -n key")); return MFX_ERR_UNSUPPORTED; } if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nFrames)) { PrintHelp(strInput[0], MSDK_STRING("rendering frame rate is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-i420"))) { pParams->fourcc = MFX_FOURCC_NV12; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-rgb4"))) { pParams->fourcc = MFX_FOURCC_RGB4; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-p010"))) { pParams->fourcc = MFX_FOURCC_P010; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-a2rgb10"))) { pParams->fourcc = MFX_FOURCC_A2RGB10; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-path"))) { i++; #if defined(_WIN32) || defined(_WIN64) msdk_char wchar[MSDK_MAX_FILENAME_LEN]; msdk_opt_read(strInput[i], wchar); std::wstring wstr(wchar); std::string str(wstr.begin(), wstr.end()); strcpy_s(pParams->pluginParams.strPluginPath, str.c_str()); #else msdk_opt_read(strInput[i], pParams->pluginParams.strPluginPath); #endif pParams->pluginParams.type = MFX_PLUGINLOAD_TYPE_FILE; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-i:null"))) { ; } else // 1-character options { switch (strInput[i][1]) { case MSDK_CHAR('p'): if (++i < nArgNum) { if (MFX_ERR_NONE == ConvertStringToGuid(strInput[i], pParams->pluginParams.pluginGuid)) { pParams->pluginParams.type = MFX_PLUGINLOAD_TYPE_GUID; } else { PrintHelp(strInput[0], MSDK_STRING("Unknown options")); } } else { msdk_printf(MSDK_STRING("error: option '-p' expects an argument\n")); } break; case MSDK_CHAR('i'): if (++i < nArgNum) { msdk_opt_read(strInput[i], pParams->strSrcFile); } else { msdk_printf(MSDK_STRING("error: option '-i' expects an argument\n")); } break; case MSDK_CHAR('o'): if (++i < nArgNum) { pParams->mode = MODE_FILE_DUMP; msdk_opt_read(strInput[i], pParams->strDstFile); } else { msdk_printf(MSDK_STRING("error: option '-o' expects an argument\n")); } break; case MSDK_CHAR('?'): PrintHelp(strInput[0], NULL); return MFX_ERR_UNSUPPORTED; default: { std::basic_stringstream<msdk_char> stream; stream << MSDK_STRING("Unknown option: ") << strInput[i]; PrintHelp(strInput[0], stream.str().c_str()); return MFX_ERR_UNSUPPORTED; } } } } if (0 == msdk_strlen(pParams->strSrcFile) && MFX_CODEC_CAPTURE != pParams->videoType) { msdk_printf(MSDK_STRING("error: source file name not found")); return MFX_ERR_UNSUPPORTED; } if (MFX_CODEC_CAPTURE == pParams->videoType) { if (!pParams->scrWidth || !pParams->scrHeight) { msdk_printf(MSDK_STRING("error: for screen capture, width and height must be specified manually (-w and -h)")); return MFX_ERR_UNSUPPORTED; } } else if (pParams->scrWidth || pParams->scrHeight) { msdk_printf(MSDK_STRING("error: width and height parameters are supported only by screen capture decoder")); return MFX_ERR_UNSUPPORTED; } if ((pParams->mode == MODE_FILE_DUMP) && (0 == msdk_strlen(pParams->strDstFile))) { msdk_printf(MSDK_STRING("error: destination file name not found")); return MFX_ERR_UNSUPPORTED; } if (MFX_CODEC_MPEG2 != pParams->videoType && MFX_CODEC_AVC != pParams->videoType && MFX_CODEC_HEVC != pParams->videoType && MFX_CODEC_VC1 != pParams->videoType && MFX_CODEC_JPEG != pParams->videoType && MFX_CODEC_CAPTURE != pParams->videoType && CODEC_VP8 != pParams->videoType) { PrintHelp(strInput[0], MSDK_STRING("Unknown codec")); return MFX_ERR_UNSUPPORTED; } if (pParams->nAsyncDepth == 0) { pParams->nAsyncDepth = 4; //set by default; } return MFX_ERR_NONE; }
int main(int argc, char *argv[]) #endif { sInputParams Params = {}; // input parameters from command line std::auto_ptr<CEncodingPipeline> pPipeline; mfxStatus sts = MFX_ERR_NONE; // return value check sts = ParseInputString(argv, (mfxU8)argc, &Params); MSDK_CHECK_PARSE_RESULT(sts, MFX_ERR_NONE, 1); // Choosing which pipeline to use pPipeline.reset(CreatePipeline(Params)); MSDK_CHECK_POINTER(pPipeline.get(), MFX_ERR_MEMORY_ALLOC); if (MVC_ENABLED & Params.MVC_flags) { pPipeline->SetMultiView(); pPipeline->SetNumView(Params.numViews); } sts = pPipeline->Init(&Params); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts); pPipeline->PrintInfo(); msdk_printf(MSDK_STRING("Processing started\n")); if (pPipeline->CaptureStartV4L2Pipeline() != MFX_ERR_NONE) { msdk_printf(MSDK_STRING("V4l2 failure terminating the program\n")); return 0; } for (;;) { sts = pPipeline->Run(); if (MFX_ERR_DEVICE_LOST == sts || MFX_ERR_DEVICE_FAILED == sts) { msdk_printf(MSDK_STRING("\nERROR: Hardware device was lost or returned an unexpected error. Recovering...\n")); sts = pPipeline->ResetDevice(); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1); sts = pPipeline->ResetMFXComponents(&Params); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1); continue; } else { MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1); break; } } pPipeline->CaptureStopV4L2Pipeline(); pPipeline->Close(); msdk_printf(MSDK_STRING("\nProcessing finished\n")); return 0; }
mfxStatus ParseInputString(msdk_char* strInput[], mfxU8 nArgNum, sInputParams* pParams) { if (1 == nArgNum) { PrintHelp(strInput[0], NULL); return MFX_ERR_UNSUPPORTED; } MSDK_CHECK_POINTER(pParams, MFX_ERR_NULL_PTR); msdk_opt_read(MSDK_CPU_ROTATE_PLUGIN, pParams->strPluginDLLPath); // default implementation pParams->bUseHWLib = true; pParams->isV4L2InputEnabled = false; pParams->nNumFrames = 0; #if defined (ENABLE_V4L2_SUPPORT) pParams->MipiPort = -1; pParams->MipiMode = NONE; pParams->v4l2Format = NO_FORMAT; #endif // parse command line parameters for (mfxU8 i = 1; i < nArgNum; i++) { MSDK_CHECK_POINTER(strInput[i], MFX_ERR_NULL_PTR); if (MSDK_CHAR('-') != strInput[i][0]) { mfxStatus sts = StrFormatToCodecFormatFourCC(strInput[i], pParams->CodecId); if (sts != MFX_ERR_NONE) { PrintHelp(strInput[0], MSDK_STRING("Unknown codec")); return MFX_ERR_UNSUPPORTED; } if (!IsEncodeCodecSupported(pParams->CodecId)) { PrintHelp(strInput[0], MSDK_STRING("Unsupported codec")); return MFX_ERR_UNSUPPORTED; } if (pParams->CodecId == CODEC_MVC) { pParams->CodecId = MFX_CODEC_AVC; pParams->MVC_flags |= MVC_ENABLED; } continue; } // process multi-character options if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-dstw"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nDstWidth)) { PrintHelp(strInput[0], MSDK_STRING("Destination picture Width is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-dsth"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nDstHeight)) { PrintHelp(strInput[0], MSDK_STRING("Destination picture Height is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-sw"))) { pParams->bUseHWLib = false; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-hw"))) { pParams->bUseHWLib = true; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-yuy2"))) { #if defined (ENABLE_V4L2_SUPPORT) pParams->v4l2Format = YUY2; #endif pParams->ColorFormat = MFX_FOURCC_YUY2; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-nv12"))) { pParams->ColorFormat = MFX_FOURCC_NV12; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-tff"))) { pParams->nPicStruct = MFX_PICSTRUCT_FIELD_TFF; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-bff"))) { pParams->nPicStruct = MFX_PICSTRUCT_FIELD_BFF; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-bref"))) { pParams->nBRefType = MFX_B_REF_PYRAMID; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-nobref"))) { pParams->nBRefType = MFX_B_REF_OFF; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-idr_interval"))) { if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nIdrInterval)) { PrintHelp(strInput[0], MSDK_STRING("IdrInterval is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-angle"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nRotationAngle)) { PrintHelp(strInput[0], MSDK_STRING("Rotation Angle is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-opencl"))) { msdk_opt_read(MSDK_OCL_ROTATE_PLUGIN, pParams->strPluginDLLPath); pParams->nRotationAngle = 180; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-viewoutput"))) { if (!(MVC_ENABLED & pParams->MVC_flags)) { PrintHelp(strInput[0], MSDK_STRING("-viewoutput option is supported only when mvc codec specified")); return MFX_ERR_UNSUPPORTED; } pParams->MVC_flags |= MVC_VIEWOUTPUT; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-la"))) { pParams->nRateControlMethod = MFX_RATECONTROL_LA; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-lad"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); pParams->nRateControlMethod = MFX_RATECONTROL_LA; if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nLADepth)) { PrintHelp(strInput[0], MSDK_STRING("Look Ahead Depth is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-mss"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nMaxSliceSize)) { PrintHelp(strInput[0], MSDK_STRING("MaxSliceSize is invalid")); return MFX_ERR_UNSUPPORTED; } } #if D3D_SURFACES_SUPPORT else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-d3d"))) { pParams->memType = D3D9_MEMORY; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-d3d11"))) { pParams->memType = D3D11_MEMORY; } #endif #ifdef LIBVA_SUPPORT else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-vaapi"))) { pParams->memType = D3D9_MEMORY; } #endif else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-async"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nAsyncDepth)) { PrintHelp(strInput[0], MSDK_STRING("Async Depth is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-gpucopy::on"))) { pParams->gpuCopy = MFX_GPUCOPY_ON; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-gpucopy::off"))) { pParams->gpuCopy = MFX_GPUCOPY_OFF; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-cqp"))) { pParams->nRateControlMethod = MFX_RATECONTROL_CQP; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-qpi"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nQPI)) { PrintHelp(strInput[0], MSDK_STRING("Quantizer for I frames is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-qpp"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nQPP)) { PrintHelp(strInput[0], MSDK_STRING("Quantizer for P frames is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-qpb"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nQPB)) { PrintHelp(strInput[0], MSDK_STRING("Quantizer for B frames is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-qsv-ff"))) { pParams->enableQSVFF=true; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-num_slice"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->nNumSlice)) { PrintHelp(strInput[0], MSDK_STRING("Number of slices is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-path"))) { i++; #if defined(_WIN32) || defined(_WIN64) msdk_char wchar[MSDK_MAX_FILENAME_LEN]; msdk_opt_read(strInput[i], wchar); std::wstring wstr(wchar); std::string str(wstr.begin(), wstr.end()); strcpy_s(pParams->pluginParams.strPluginPath, str.c_str()); #else msdk_opt_read(strInput[i], pParams->pluginParams.strPluginPath); #endif pParams->pluginParams.type = MFX_PLUGINLOAD_TYPE_FILE; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-re"))) { pParams->UseRegionEncode = true; } MOD_ENC_PARSE_INPUT #if defined (ENABLE_V4L2_SUPPORT) else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-d"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->DeviceName)) { PrintHelp(strInput[0], MSDK_STRING("Device name is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-uyvy"))) { pParams->v4l2Format = UYVY; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-p"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->MipiPort)) { PrintHelp(strInput[0], MSDK_STRING("Mipi-port is invalid")); return MFX_ERR_UNSUPPORTED; } } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-m"))) { VAL_CHECK(i+1 >= nArgNum, i, strInput[i]); if (MFX_ERR_NONE != msdk_opt_read(strInput[++i], pParams->MipiModeName)) { PrintHelp(strInput[0], MSDK_STRING("Device name is invalid")); return MFX_ERR_UNSUPPORTED; } if(strcasecmp(pParams->MipiModeName,"STILL") == 0) pParams->MipiMode = STILL; else if(strcasecmp(pParams->MipiModeName,"VIDEO") == 0) pParams->MipiMode = VIDEO; else if(strcasecmp(pParams->MipiModeName,"PREVIEW") == 0) pParams->MipiMode = PREVIEW; else if(strcasecmp(pParams->MipiModeName,"CONTINUOUS") == 0) pParams->MipiMode = CONTINUOUS; else pParams->MipiMode = NONE; } else if (0 == msdk_strcmp(strInput[i], MSDK_STRING("-i::v4l2"))) { pParams->isV4L2InputEnabled = true; } #endif else // 1-character options { switch (strInput[i][1]) { case MSDK_CHAR('u'): if (++i < nArgNum) { pParams->nTargetUsage = StrToTargetUsage(strInput[i]); } else { msdk_printf(MSDK_STRING("error: option '-u' expects an argument\n")); } break; case MSDK_CHAR('w'): if (++i < nArgNum) { if (MFX_ERR_NONE != msdk_opt_read(strInput[i], pParams->nWidth)) { PrintHelp(strInput[0], MSDK_STRING("Width is invalid")); return MFX_ERR_UNSUPPORTED; } } else { msdk_printf(MSDK_STRING("error: option '-w' expects an argument\n")); } break; case MSDK_CHAR('h'): if (++i < nArgNum) { if (MFX_ERR_NONE != msdk_opt_read(strInput[i], pParams->nHeight)) { PrintHelp(strInput[0], MSDK_STRING("Height is invalid")); return MFX_ERR_UNSUPPORTED; } } else { msdk_printf(MSDK_STRING("error: option '-h' expects an argument\n")); } break; case MSDK_CHAR('f'): if (++i < nArgNum) { if (MFX_ERR_NONE != msdk_opt_read(strInput[i], pParams->dFrameRate)) { PrintHelp(strInput[0], MSDK_STRING("Frame Rate is invalid")); return MFX_ERR_UNSUPPORTED; } } else { msdk_printf(MSDK_STRING("error: option '-f' expects an argument\n")); } break; case MSDK_CHAR('n'): if (++i < nArgNum) { if (MFX_ERR_NONE != msdk_opt_read(strInput[i], pParams->nNumFrames)) { PrintHelp(strInput[0], MSDK_STRING("Number of frames to process is invalid")); return MFX_ERR_UNSUPPORTED; } } else { msdk_printf(MSDK_STRING("error: option '-n' expects an argument\n")); } break; case MSDK_CHAR('b'): if (++i < nArgNum) { if (MFX_ERR_NONE != msdk_opt_read(strInput[i], pParams->nBitRate)) { PrintHelp(strInput[0], MSDK_STRING("Bit Rate is invalid")); return MFX_ERR_UNSUPPORTED; } } else { msdk_printf(MSDK_STRING("error: option '-b' expects an argument\n")); } break; case MSDK_CHAR('x'): if (++i < nArgNum) { if (MFX_ERR_NONE != msdk_opt_read(strInput[i], pParams->nNumRefFrame)) { PrintHelp(strInput[0], MSDK_STRING("Ref Num is invalid")); return MFX_ERR_UNSUPPORTED; } } else { msdk_printf(MSDK_STRING("error: option '-x' expects an argument\n")); } break; case MSDK_CHAR('g'): if (++i < nArgNum) { if (MFX_ERR_NONE != msdk_opt_read(strInput[i], pParams->nGopPicSize)) { PrintHelp(strInput[0], MSDK_STRING("Gop Size is invalid")); return MFX_ERR_UNSUPPORTED; } } else { msdk_printf(MSDK_STRING("error: option '-g' expects an argument\n")); } break; case MSDK_CHAR('r'): if (++i < nArgNum) { if (MFX_ERR_NONE != msdk_opt_read(strInput[i], pParams->nGopRefDist)) { PrintHelp(strInput[0], MSDK_STRING("Ref Dist is invalid")); return MFX_ERR_UNSUPPORTED; } } else { msdk_printf(MSDK_STRING("error: option '-r' expects an argument\n")); } break; case MSDK_CHAR('i'): if (++i < nArgNum) { msdk_opt_read(strInput[i], pParams->strSrcFile); if (MVC_ENABLED & pParams->MVC_flags) { pParams->srcFileBuff.push_back(strInput[i]); } } else { msdk_printf(MSDK_STRING("error: option '-i' expects an argument\n")); } break; case MSDK_CHAR('o'): if (++i < nArgNum) { pParams->dstFileBuff.push_back(strInput[i]); } else { msdk_printf(MSDK_STRING("error: option '-o' expects an argument\n")); } break; case MSDK_CHAR('q'): if (++i < nArgNum) { if (MFX_ERR_NONE != msdk_opt_read(strInput[i], pParams->nQuality)) { PrintHelp(strInput[0], MSDK_STRING("Quality is invalid")); return MFX_ERR_UNSUPPORTED; } } else { msdk_printf(MSDK_STRING("error: option '-q' expects an argument\n")); } break; case MSDK_CHAR('p'): if (++i < nArgNum) { if (MFX_ERR_NONE == ConvertStringToGuid(strInput[i], pParams->pluginParams.pluginGuid)) { pParams->pluginParams.type = MFX_PLUGINLOAD_TYPE_GUID; } else { PrintHelp(strInput[0], MSDK_STRING("Unknown options")); } } else { msdk_printf(MSDK_STRING("error: option '-p' expects an argument\n")); } break; case MSDK_CHAR('?'): PrintHelp(strInput[0], NULL); return MFX_ERR_UNSUPPORTED; default: PrintHelp(strInput[0], MSDK_STRING("Unknown options")); } } } #if defined (ENABLE_V4L2_SUPPORT) if (pParams->isV4L2InputEnabled) { if (0 == msdk_strlen(pParams->DeviceName)) { PrintHelp(strInput[0], MSDK_STRING("Device Name not found")); return MFX_ERR_UNSUPPORTED; } if ((pParams->MipiPort > -1 && pParams->MipiMode == NONE) || (pParams->MipiPort < 0 && pParams->MipiMode != NONE)) { PrintHelp(strInput[0], MSDK_STRING("Invalid Mipi Configuration\n")); return MFX_ERR_UNSUPPORTED; } if (pParams->v4l2Format == NO_FORMAT) { PrintHelp(strInput[0], MSDK_STRING("NO input v4l2 format\n")); return MFX_ERR_UNSUPPORTED; } } #endif // check if all mandatory parameters were set if (0 == msdk_strlen(pParams->strSrcFile) && !pParams->isV4L2InputEnabled) { PrintHelp(strInput[0], MSDK_STRING("Source file name not found")); return MFX_ERR_UNSUPPORTED; }; if (pParams->dstFileBuff.empty()) { PrintHelp(strInput[0], MSDK_STRING("Destination file name not found")); return MFX_ERR_UNSUPPORTED; }; if (0 == pParams->nWidth || 0 == pParams->nHeight) { PrintHelp(strInput[0], MSDK_STRING("-w, -h must be specified")); return MFX_ERR_UNSUPPORTED; } if (MFX_CODEC_MPEG2 != pParams->CodecId && MFX_CODEC_AVC != pParams->CodecId && MFX_CODEC_JPEG != pParams->CodecId && MFX_CODEC_VP8 != pParams->CodecId && MFX_CODEC_HEVC != pParams->CodecId) { PrintHelp(strInput[0], MSDK_STRING("Unknown codec")); return MFX_ERR_UNSUPPORTED; } if (MFX_CODEC_JPEG != pParams->CodecId && pParams->ColorFormat == MFX_FOURCC_YUY2 && !pParams->isV4L2InputEnabled) { PrintHelp(strInput[0], MSDK_STRING("-yuy2 option is supported only for JPEG encoder")); return MFX_ERR_UNSUPPORTED; } // check parameters validity if (pParams->nRotationAngle != 0 && pParams->nRotationAngle != 180) { PrintHelp(strInput[0], MSDK_STRING("Angles other than 180 degrees are not supported.")); return MFX_ERR_UNSUPPORTED; // other than 180 are not supported } if (pParams->nQuality && (MFX_CODEC_JPEG != pParams->CodecId)) { PrintHelp(strInput[0], MSDK_STRING("-q option is supported only for JPEG encoder")); return MFX_ERR_UNSUPPORTED; } if ((pParams->nTargetUsage || pParams->nBitRate) && (MFX_CODEC_JPEG == pParams->CodecId)) { PrintHelp(strInput[0], MSDK_STRING("-u and -b options are supported only for H.264, MPEG2 and MVC encoders. For JPEG encoder use -q")); return MFX_ERR_UNSUPPORTED; } // set default values for optional parameters that were not set or were set incorrectly mfxU32 nviews = (mfxU32)pParams->srcFileBuff.size(); if ((nviews <= 1) || (nviews > 2)) { if (!(MVC_ENABLED & pParams->MVC_flags)) { pParams->numViews = 1; } else { PrintHelp(strInput[0], MSDK_STRING("Only 2 views are supported right now in this sample.")); return MFX_ERR_UNSUPPORTED; } } else { pParams->numViews = nviews; } if (MFX_TARGETUSAGE_BEST_QUALITY != pParams->nTargetUsage && MFX_TARGETUSAGE_BEST_SPEED != pParams->nTargetUsage) { pParams->nTargetUsage = MFX_TARGETUSAGE_BALANCED; } if (pParams->dFrameRate <= 0) { pParams->dFrameRate = 30; } // if no destination picture width or height wasn't specified set it to the source picture size if (pParams->nDstWidth == 0) { pParams->nDstWidth = pParams->nWidth; } if (pParams->nDstHeight == 0) { pParams->nDstHeight = pParams->nHeight; } // calculate default bitrate based on the resolution (a parameter for encoder, so Dst resolution is used) if (pParams->nBitRate == 0) { pParams->nBitRate = CalculateDefaultBitrate(pParams->CodecId, pParams->nTargetUsage, pParams->nDstWidth, pParams->nDstHeight, pParams->dFrameRate); } // if nv12 option wasn't specified we expect input YUV file in YUV420 color format if (!pParams->ColorFormat) { pParams->ColorFormat = MFX_FOURCC_YV12; } if (!pParams->nPicStruct) { pParams->nPicStruct = MFX_PICSTRUCT_PROGRESSIVE; } if ((pParams->nRateControlMethod == MFX_RATECONTROL_LA) && (!pParams->bUseHWLib)) { PrintHelp(strInput[0], MSDK_STRING("Look ahead BRC is supported only with -hw option!")); return MFX_ERR_UNSUPPORTED; } if ((pParams->nMaxSliceSize) && (!pParams->bUseHWLib)) { PrintHelp(strInput[0], MSDK_STRING("MaxSliceSize option is supported only with -hw option!")); return MFX_ERR_UNSUPPORTED; } if ((pParams->nMaxSliceSize) && (pParams->nNumSlice)) { PrintHelp(strInput[0], MSDK_STRING("-mss and -num_slice options are not compatible!")); return MFX_ERR_UNSUPPORTED; } if ((pParams->nRateControlMethod == MFX_RATECONTROL_LA) && (pParams->CodecId != MFX_CODEC_AVC)) { PrintHelp(strInput[0], MSDK_STRING("Look ahead BRC is supported only with H.264 encoder!")); return MFX_ERR_UNSUPPORTED; } if ((pParams->nMaxSliceSize) && (pParams->CodecId != MFX_CODEC_AVC)) { PrintHelp(strInput[0], MSDK_STRING("MaxSliceSize option is supported only with H.264 encoder!")); return MFX_ERR_UNSUPPORTED; } if (pParams->nLADepth && (pParams->nLADepth < 10 || pParams->nLADepth > 100)) { if ((pParams->nLADepth != 1) || (!pParams->nMaxSliceSize)) { PrintHelp(strInput[0], MSDK_STRING("Unsupported value of -lad parameter, must be in range [10, 100] or 1 in case of -mss option!")); return MFX_ERR_UNSUPPORTED; } } // not all options are supported if rotate plugin is enabled if (pParams->nRotationAngle == 180 && ( MFX_PICSTRUCT_PROGRESSIVE != pParams->nPicStruct || pParams->nDstWidth != pParams->nWidth || pParams->nDstHeight != pParams->nHeight || MVC_ENABLED & pParams->MVC_flags || pParams->nRateControlMethod == MFX_RATECONTROL_LA)) { PrintHelp(strInput[0], MSDK_STRING("Some of the command line options are not supported with rotation plugin!")); return MFX_ERR_UNSUPPORTED; } if (pParams->nAsyncDepth == 0) { pParams->nAsyncDepth = 4; //set by default; } // Ignoring user-defined Async Depth for LA if (pParams->nMaxSliceSize) { pParams->nAsyncDepth = 1; } if (pParams->nRateControlMethod == 0) { pParams->nRateControlMethod = MFX_RATECONTROL_CBR; } if(pParams->UseRegionEncode) { if(pParams->CodecId != MFX_CODEC_HEVC) { msdk_printf(MSDK_STRING("Region encode option is compatible with h265(HEVC) encoder only.\nRegion encoding is disabled\n")); pParams->UseRegionEncode=false; } if (pParams->nWidth != pParams->nDstWidth || pParams->nHeight != pParams->nDstHeight || pParams->nRotationAngle!=0) { msdk_printf(MSDK_STRING("Region encode option is not compatible with VPP processing.\nRegion encoding is disabled\n")); pParams->UseRegionEncode=false; } } return MFX_ERR_NONE; }
void PrintHelp(msdk_char *strAppName, const msdk_char *strErrorMessage, ...) { msdk_printf(MSDK_STRING("Encoding Sample Version %s\n\n"), MSDK_SAMPLE_VERSION); if (strErrorMessage) { va_list args; msdk_printf(MSDK_STRING("ERROR: ")); va_start(args, strErrorMessage); msdk_vprintf(strErrorMessage, args); va_end(args); msdk_printf(MSDK_STRING("\n\n")); } msdk_printf(MSDK_STRING("Usage: %s <msdk-codecid> [<options>] -i InputYUVFile -o OutputEncodedFile -w width -h height\n"), strAppName); msdk_printf(MSDK_STRING("\n")); msdk_printf(MSDK_STRING("Supported codecs, <msdk-codecid>:\n")); msdk_printf(MSDK_STRING(" <codecid>=h264|mpeg2|vc1|mvc|jpeg - built-in Media SDK codecs\n")); msdk_printf(MSDK_STRING(" <codecid>=h265|vp8 - in-box Media SDK plugins (may require separate downloading and installation)\n")); msdk_printf(MSDK_STRING(" If codecid is jpeg, -q option is mandatory.)\n")); msdk_printf(MSDK_STRING("Options: \n")); MOD_ENC_PRINT_HELP; msdk_printf(MSDK_STRING(" [-nv12|yuy2] - input is in NV12 color format, if not specified YUV420 is expected. YUY2 are for JPEG encode only\n")); msdk_printf(MSDK_STRING(" [-tff|bff] - input stream is interlaced, top|bottom fielf first, if not specified progressive is expected\n")); msdk_printf(MSDK_STRING(" [-bref] - arrange B frames in B pyramid reference structure\n")); msdk_printf(MSDK_STRING(" [-nobref] - do not use B-pyramid (by default the decision is made by library)\n")); msdk_printf(MSDK_STRING(" [-idr_interval size] - idr interval, default 0 means every I is an IDR, 1 means every other I frame is an IDR etc\n")); msdk_printf(MSDK_STRING(" [-f frameRate] - video frame rate (frames per second)\n")); msdk_printf(MSDK_STRING(" [-n number] - number of frames to process\n")); msdk_printf(MSDK_STRING(" [-b bitRate] - encoded bit rate (Kbits per second), valid for H.264, H.265, MPEG2 and MVC encoders \n")); msdk_printf(MSDK_STRING(" [-u speed|quality|balanced] - target usage, valid for H.264, H.265, MPEG2 and MVC encoders\n")); msdk_printf(MSDK_STRING(" [-q quality] - mandatory quality parameter for JPEG encoder. In range [1,100]. 100 is the best quality. \n")); msdk_printf(MSDK_STRING(" [-r distance] - Distance between I- or P- key frames (1 means no B-frames) \n")); msdk_printf(MSDK_STRING(" [-g size] - GOP size (default 256)\n")); msdk_printf(MSDK_STRING(" [-x numRefs] - number of reference frames\n")); msdk_printf(MSDK_STRING(" [-la] - use the look ahead bitrate control algorithm (LA BRC) (by default constant bitrate control method is used)\n")); msdk_printf(MSDK_STRING(" for H.264, H.265 encoder. Supported only with -hw option on 4th Generation Intel Core processors. \n")); msdk_printf(MSDK_STRING(" [-lad depth] - depth parameter for the LA BRC, the number of frames to be analyzed before encoding. In range [10,100].\n")); msdk_printf(MSDK_STRING(" may be 1 in the case when -mss option is specified \n")); msdk_printf(MSDK_STRING(" [-dstw width] - destination picture width, invokes VPP resizing\n")); msdk_printf(MSDK_STRING(" [-dsth height] - destination picture height, invokes VPP resizing\n")); msdk_printf(MSDK_STRING(" [-hw] - use platform specific SDK implementation (default)\n")); msdk_printf(MSDK_STRING(" [-sw] - use software implementation, if not specified platform specific SDK implementation is used\n")); msdk_printf(MSDK_STRING(" [-p guid] - 32-character hexadecimal guid string\n")); msdk_printf(MSDK_STRING(" (optional for Media SDK in-box plugins, required for user-encoder ones)\n")); msdk_printf(MSDK_STRING(" [-path path] - path to plugin (valid only in pair with -p option)\n")); msdk_printf(MSDK_STRING(" [-async] - depth of asynchronous pipeline. default value is 4. must be between 1 and 20.\n")); msdk_printf(MSDK_STRING(" [-gpucopy::<on,off>] Enable or disable GPU copy mode\n")); msdk_printf(MSDK_STRING(" [-cqp] - constant quantization parameter (CQP BRC) bitrate control method\n")); msdk_printf(MSDK_STRING(" (by default constant bitrate control method is used), should be used along with -qpi, -qpp, -qpb.\n")); msdk_printf(MSDK_STRING(" [-qpi] - constant quantizer for I frames (if bitrace control method is CQP). In range [1,51]. 0 by default, i.e.no limitations on QP.\n")); msdk_printf(MSDK_STRING(" [-qpp] - constant quantizer for P frames (if bitrace control method is CQP). In range [1,51]. 0 by default, i.e.no limitations on QP.\n")); msdk_printf(MSDK_STRING(" [-qpb] - constant quantizer for B frames (if bitrace control method is CQP). In range [1,51]. 0 by default, i.e.no limitations on QP.\n")); msdk_printf(MSDK_STRING(" [-qsv-ff] Enable QSV-FF mode\n")); msdk_printf(MSDK_STRING(" [-num_slice] - number of slices in each video frame. 0 by default.\n")); msdk_printf(MSDK_STRING(" If num_slice equals zero, the encoder may choose any slice partitioning allowed by the codec standard.\n")); msdk_printf(MSDK_STRING(" [-mss] - maximum slice size in bytes. Supported only with -hw and h264 codec. This option is not compatible with -num_slice option.\n")); msdk_printf(MSDK_STRING(" [-re] - enable region encode mode. Works only with h265 encoder\n")); msdk_printf(MSDK_STRING("Example: %s h265 -i InputYUVFile -o OutputEncodedFile -w width -h height -hw -p 2fca99749fdb49aeb121a5b63ef568f7\n"), strAppName); #if D3D_SURFACES_SUPPORT msdk_printf(MSDK_STRING(" [-d3d] - work with d3d surfaces\n")); msdk_printf(MSDK_STRING(" [-d3d11] - work with d3d11 surfaces\n")); msdk_printf(MSDK_STRING("Example: %s h264|h265|mpeg2|jpeg -i InputYUVFile -o OutputEncodedFile -w width -h height -d3d -hw \n"), strAppName); msdk_printf(MSDK_STRING("Example for MVC: %s mvc -i InputYUVFile_1 -i InputYUVFile_2 -o OutputEncodedFile -w width -h height \n"), strAppName); #endif #ifdef LIBVA_SUPPORT msdk_printf(MSDK_STRING(" [-vaapi] - work with vaapi surfaces\n")); msdk_printf(MSDK_STRING("Example: %s h264|mpeg2|mvc -i InputYUVFile -o OutputEncodedFile -w width -h height -angle 180 -g 300 -r 1 \n"), strAppName); #endif #if defined (ENABLE_V4L2_SUPPORT) msdk_printf(MSDK_STRING(" [-d] - Device video node (eg: /dev/video0)\n")); msdk_printf(MSDK_STRING(" [-p] - Mipi Port number (eg: Port 0)\n")); msdk_printf(MSDK_STRING(" [-m] - Mipi Mode Configuration [PREVIEW/CONTINUOUS/STILL/VIDEO]\n")); msdk_printf(MSDK_STRING(" [-uyvy] - Input Raw format types V4L2 Encode\n")); msdk_printf(MSDK_STRING(" [-YUY2] - Input Raw format types V4L2 Encode\n")); msdk_printf(MSDK_STRING(" [-i::v4l2] - To enable v4l2 option\n")); msdk_printf(MSDK_STRING("Example: %s h264|mpeg2|mvc -i::v4l2 -o OutputEncodedFile -w width -h height -d /dev/video0 -uyvy -m preview -p 0\n"), strAppName); #endif msdk_printf(MSDK_STRING(" [-viewoutput] - instruct the MVC encoder to output each view in separate bitstream buffer. Depending on the number of -o options behaves as follows:\n")); msdk_printf(MSDK_STRING(" 1: two views are encoded in single file\n")); msdk_printf(MSDK_STRING(" 2: two views are encoded in separate files\n")); msdk_printf(MSDK_STRING(" 3: behaves like 2 -o opitons was used and then one -o\n\n")); msdk_printf(MSDK_STRING("Example: %s mvc -i InputYUVFile_1 -i InputYUVFile_2 -o OutputEncodedFile_1 -o OutputEncodedFile_2 -viewoutput -w width -h height \n"), strAppName); // user module options msdk_printf(MSDK_STRING("User module options: \n")); msdk_printf(MSDK_STRING(" [-angle 180] - enables 180 degrees picture rotation before encoding, CPU implementation by default. Rotation requires NV12 input. Options -tff|bff, -dstw, -dsth, -d3d are not effective together with this one, -nv12 is required.\n")); msdk_printf(MSDK_STRING(" [-opencl] - rotation implementation through OPENCL\n")); msdk_printf(MSDK_STRING("Example: %s h264|h265|mpeg2|mvc|jpeg -i InputYUVFile -o OutputEncodedFile -w width -h height -angle 180 -opencl \n"), strAppName); msdk_printf(MSDK_STRING("\n")); }
/* Custom methods */ mfxStatus Rotate::Init(mfxVideoParam *mfxParam) { MSDK_CHECK_POINTER(mfxParam, MFX_ERR_NULL_PTR); MSDK_CHECK_POINTER(m_pmfxCore, MFX_ERR_NULL_PTR); mfxStatus sts = MFX_ERR_NONE; // whether we use d3d memory on int bd3d[2] = { 0, // input 0}; // output m_VideoParam = *mfxParam; // map opaque surfaces array in case of opaque surfaces m_bIsInOpaque = (m_VideoParam.IOPattern & MFX_IOPATTERN_IN_OPAQUE_MEMORY) ? true : false; m_bIsOutOpaque = (m_VideoParam.IOPattern & MFX_IOPATTERN_OUT_OPAQUE_MEMORY) ? true : false; mfxExtOpaqueSurfaceAlloc* pluginOpaqueAlloc = NULL; if (m_bIsInOpaque || m_bIsOutOpaque) { pluginOpaqueAlloc = (mfxExtOpaqueSurfaceAlloc*)GetExtBuffer(m_VideoParam.ExtParam, m_VideoParam.NumExtParam, MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION); MSDK_CHECK_POINTER(pluginOpaqueAlloc, MFX_ERR_INVALID_VIDEO_PARAM); } // check existence of corresponding allocs if ((m_bIsInOpaque && ! pluginOpaqueAlloc->In.Surfaces) || (m_bIsOutOpaque && !pluginOpaqueAlloc->Out.Surfaces)) return MFX_ERR_INVALID_VIDEO_PARAM; if (m_bIsInOpaque) { sts = m_pmfxCore->MapOpaqueSurface(m_pmfxCore->pthis, pluginOpaqueAlloc->In.NumSurface, pluginOpaqueAlloc->In.Type, pluginOpaqueAlloc->In.Surfaces); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, MFX_ERR_MEMORY_ALLOC); bd3d[0] = pluginOpaqueAlloc->In.Type & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET); } else { bd3d[0] = m_VideoParam.IOPattern & MFX_IOPATTERN_IN_VIDEO_MEMORY; } if (m_bIsOutOpaque) { sts = m_pmfxCore->MapOpaqueSurface(m_pmfxCore->pthis, pluginOpaqueAlloc->Out.NumSurface, pluginOpaqueAlloc->Out.Type, pluginOpaqueAlloc->Out.Surfaces); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, MFX_ERR_MEMORY_ALLOC); bd3d[1] = pluginOpaqueAlloc->Out.Type & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET); } else { bd3d[1] = m_VideoParam.IOPattern & MFX_IOPATTERN_OUT_VIDEO_MEMORY; } m_MaxNumTasks = 1; m_pTasks = new RotateTask [m_MaxNumTasks]; MSDK_CHECK_POINTER(m_pTasks, MFX_ERR_MEMORY_ALLOC); memset(m_pTasks, 0, sizeof(RotateTask) * m_MaxNumTasks); m_NumChunks = 1; m_pChunks = new DataChunk [m_NumChunks]; MSDK_CHECK_POINTER(m_pChunks, MFX_ERR_MEMORY_ALLOC); memset(m_pChunks, 0, sizeof(DataChunk) * m_NumChunks); // divide frame into data chunks mfxU32 num_lines_in_chunk = mfxParam->vpp.In.CropH / m_NumChunks; // integer division mfxU32 remainder_lines = mfxParam->vpp.In.CropH % m_NumChunks; // get remainder // remaining lines are distributed among first chunks (+ extra 1 line each) for (mfxU32 i = 0; i < m_NumChunks; i++) { m_pChunks[i].StartLine = (i == 0) ? 0 : m_pChunks[i-1].EndLine + 1; m_pChunks[i].EndLine = (i < remainder_lines) ? (i + 1) * num_lines_in_chunk : (i + 1) * num_lines_in_chunk - 1; } // enable surface sharing in case both input and output are d3d surfaces if (bd3d[0] && bd3d[1]) m_bOpenCLSurfaceSharing = true; if (m_bOpenCLSurfaceSharing) { // init OpenCLFilter cl_int error = CL_SUCCESS; #if defined(_WIN32) || defined(_WIN64) if (MFX_IMPL_VIA_MASK(m_impl) == MFX_IMPL_VIA_D3D11) { m_OpenCLFilter.reset(new OpenCLFilterDX11()); } else { m_OpenCLFilter.reset(new OpenCLFilterDX9()); } error = m_OpenCLFilter.get()->AddKernel(readFile("ocl_rotate.cl").c_str(), "rotate_Y", "rotate_UV"); if (error) return MFX_ERR_DEVICE_FAILED; error = m_OpenCLFilter.get()->OCLInit(m_device); #else m_OpenCLFilter.reset(new OpenCLFilterVA()); error = m_OpenCLFilter.get()->AddKernel(readFile("ocl_rotate.cl").c_str(), "rotate_Y", "rotate_UV"); if (error) return MFX_ERR_DEVICE_FAILED; error = m_OpenCLFilter.get()->OCLInit(m_device); #endif if (error) { error = CL_SUCCESS; std::cout << "\nWARNING: Initializing plugin with media sharing failed" << std::endl; m_bOpenCLSurfaceSharing = false; // try init plugin without sharing } else { error = m_OpenCLFilter->SelectKernel(0); if (error) return MFX_ERR_DEVICE_FAILED; } } if (!m_bOpenCLSurfaceSharing) { try { m_pOpenCLRotator180Context.reset(new OpenCLRotator180Context(readFile("ocl_rotate.cl").c_str())); } catch (const std::exception &err) { std::cout << "Error: The readFile method throws an exception: " << err.what() << std::endl; return MFX_ERR_DEVICE_FAILED; } } if (m_bOpenCLSurfaceSharing) { msdk_printf(MSDK_STRING("info: using GPU OpenCL device with media sharing extension\n")); } else { msdk_printf(MSDK_STRING("info: using CPU OpenCL device without media sharing extension\n")); } m_bInited = true; return MFX_ERR_NONE; }
int main(int argc, char *argv[]) #endif { sInputParams Params; // input parameters from command line CCameraPipeline Pipeline; // pipeline for decoding, includes input file reader, decoder and output file writer mfxStatus sts = MFX_ERR_NONE; // return value check sts = ParseInputString(argv, (mfxU8)argc, &Params); MSDK_CHECK_PARSE_RESULT(sts, MFX_ERR_NONE, 1); sts = Pipeline.Init(&Params); MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1); // print stream info Pipeline.PrintInfo(); msdk_printf(MSDK_STRING("Camera pipe started\n")); #if defined(_WIN32) || defined(_WIN64) LARGE_INTEGER timeBegin, timeEnd, m_Freq; QueryPerformanceFrequency(&m_Freq); QueryPerformanceCounter(&timeBegin); #endif int resetNum = 0; for (;;) { sts = Pipeline.Run(); if (MFX_WRN_VIDEO_PARAM_CHANGED == sts) { sInputParams *pParams = &Params; if (resetNum >= (int)Params.resetParams.size()) break; msdk_strcopy(Params.strSrcFile, Params.resetParams[resetNum].strSrcFile); msdk_strcopy(pParams->strDstFile, Params.resetParams[resetNum].strDstFile); pParams->frameInfo[VPP_IN].nWidth = (mfxU16)Params.resetParams[resetNum].width; pParams->frameInfo[VPP_IN].nHeight = (mfxU16)Params.resetParams[resetNum].height; pParams->frameInfo[VPP_IN].CropW = pParams->frameInfo[VPP_IN].nWidth; if ( Params.resetParams[resetNum].cropW ) pParams->frameInfo[VPP_IN].CropW = Params.resetParams[resetNum].cropW; pParams->frameInfo[VPP_IN].CropH = pParams->frameInfo[VPP_IN].nHeight; if ( Params.resetParams[resetNum].cropH ) pParams->frameInfo[VPP_IN].CropH = Params.resetParams[resetNum].cropH; pParams->frameInfo[VPP_IN].CropX = align(Params.resetParams[resetNum].cropX); pParams->frameInfo[VPP_IN].CropY = Params.resetParams[resetNum].cropY; if ( ! pParams->frameInfo[VPP_IN].CropW ) { pParams->frameInfo[VPP_IN].CropW = pParams->frameInfo[VPP_IN].nWidth; } if ( ! pParams->frameInfo[VPP_IN].CropH ) { pParams->frameInfo[VPP_IN].CropH = pParams->frameInfo[VPP_IN].nHeight; } pParams->frameInfo[VPP_OUT].nWidth = pParams->frameInfo[VPP_IN].CropW; pParams->frameInfo[VPP_OUT].nHeight = pParams->frameInfo[VPP_IN].CropH; pParams->frameInfo[VPP_OUT].CropW = pParams->frameInfo[VPP_IN].CropW; pParams->frameInfo[VPP_OUT].CropH = pParams->frameInfo[VPP_IN].CropH; pParams->bayerType = Params.resetParams[resetNum].bayerType; pParams->bHP = Params.resetParams[resetNum].bHP; pParams->hp_diff = Params.resetParams[resetNum].hp_diff; pParams->hp_num = Params.resetParams[resetNum].hp_num; pParams->bBayerDenoise = Params.resetParams[resetNum].bDenoise; pParams->denoiseThreshold = Params.resetParams[resetNum].denoiseThreshold; pParams->bBlackLevel = Params.resetParams[resetNum].bBlackLevel; pParams->black_level_B = Params.resetParams[resetNum].black_level_B; pParams->black_level_G0= Params.resetParams[resetNum].black_level_G0; pParams->black_level_G1= Params.resetParams[resetNum].black_level_G1; pParams->black_level_R = Params.resetParams[resetNum].black_level_R; pParams->bWhiteBalance = Params.resetParams[resetNum].bWhiteBalance; pParams->white_balance_B = Params.resetParams[resetNum].white_balance_B; pParams->white_balance_G0= Params.resetParams[resetNum].white_balance_G0; pParams->white_balance_G1= Params.resetParams[resetNum].white_balance_G1; pParams->white_balance_R = Params.resetParams[resetNum].white_balance_R; pParams->bCCM = Params.resetParams[resetNum].bCCM; for (int k = 0; k < 3; k++) for (int z = 0; z < 3; z++) pParams->CCM[k][z] = Params.resetParams[resetNum].CCM[k][z]; //pParams->frameInfo[VPP_OUT].FourCC = MFX_FOURCC_ARGB16; //pParams->memTypeIn = pParams->memTypeOut = SYSTEM_MEMORY; sts = Pipeline.Reset(&Params); if (sts == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) { Pipeline.Close(); sts = Pipeline.Init(&Params); } if (sts != MFX_ERR_NONE) break; resetNum++; } else break; } #if defined(_WIN32) || defined(_WIN64) QueryPerformanceCounter(&timeEnd); double time = ((double)timeEnd.QuadPart - (double)timeBegin.QuadPart)/ (double)m_Freq.QuadPart; int frames = Pipeline.GetNumberProcessedFrames(); _tprintf(_T("Total frames %d \n"), frames); _tprintf(_T("Total time %.2lf sec\n"), time); _tprintf(_T("Total FPS %.2lf fps\n"), frames/time); #endif //Pipeline.Close(); if(MFX_ERR_ABORTED != sts) MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, 1); msdk_printf(MSDK_STRING("\nCamera pipe finished\n")); return 0; }
void PrintHelp(msdk_char *strAppName, const msdk_char *strErrorMessage) { msdk_printf(MSDK_STRING("Intel(R) Camera Expert SDK Sample Version %s\n\n"), MSDK_SAMPLE_VERSION); if (strErrorMessage) { msdk_printf(MSDK_STRING("Error: %s\n"), strErrorMessage); } msdk_printf(MSDK_STRING("Usage: %s [Options] -p PathToCameraPlugin -i InputFileNameBase -o OutputFileNameBase [numberOfFilesToDump]\n"), strAppName); msdk_printf(MSDK_STRING("Options: \n")); msdk_printf(MSDK_STRING(" [-plugin_version ver] - define camera plugin version\n")); msdk_printf(MSDK_STRING(" [-a asyncDepth] / [-asyncDepth asyncDepth] - set async depth, default %d \n"), CAM_SAMPLE_ASYNC_DEPTH); msdk_printf(MSDK_STRING(" [-b bitDepth] / [-bitDepth bitDepth] - set bit depth, default 10 \n")); msdk_printf(MSDK_STRING(" [-f format] / [-format format] - input Bayer format: rggb, bggr, grbg or gbrg\n")); msdk_printf(MSDK_STRING(" [-of format] / [-outFormat format] - output format: of argb16 or 16 meaning 16 bit ARGB, 8 bit ARGB otherwise\n")); msdk_printf(MSDK_STRING(" [-3DLUT_gamma] - use 3D LUT gamma correction\n")); msdk_printf(MSDK_STRING(" [-ng] / [-noGamma] - no gamma correction\n")); msdk_printf(MSDK_STRING(" [-gamma_points] - set specific gamma points (64 points expected)\n")); msdk_printf(MSDK_STRING(" [-gamma_corrected] - set specific gamma corrected values (64 values expected)\n")); msdk_printf(MSDK_STRING(" -gamma_points and -gamma_corrected options must be used together\n")); msdk_printf(MSDK_STRING(" [-bdn threshold] / [-bayerDenoise threshold] - bayer denoise on\n")); msdk_printf(MSDK_STRING(" [-hot_pixel Diff Num] - bayer hot pixel removal\n")); msdk_printf(MSDK_STRING(" [-bbl B G0 G1 R] / [-bayerBlackLevel B G0 G1 R] - bayer black level correction\n")); msdk_printf(MSDK_STRING(" [-bwb B G0 G1 R] / [-bayerWhiteBalance B G0 G1 R] - bayer white balance\n")); msdk_printf(MSDK_STRING(" [-ccm n00 n01 ... n33 ] - color correction 3x3 matrix\n")); msdk_printf(MSDK_STRING(" [-vignette maskfile ] - enable vignette correction using mask from specified file\n")); msdk_printf(MSDK_STRING(" [-lens a b c d ] - enable lens geometry distortion correction\n")); msdk_printf(MSDK_STRING(" [-chroma_aberration aR bR cR dR aG bG cG dG aB bB cB dB ] - enable chroma aberration correction\n")); msdk_printf(MSDK_STRING(" [-w width] / [-width width] - input width, default 4096\n")); msdk_printf(MSDK_STRING(" [-h height] / [-height height] - input height, default 2160\n")); msdk_printf(MSDK_STRING(" [-n numFrames] / [-numFramesToProcess numFrames] - number of frames to process\n")); msdk_printf(MSDK_STRING(" [-alpha alpha] - write value to alpha channel of output surface \n")); msdk_printf(MSDK_STRING(" [-pd] / [-padding] - do input surface padding \n")); msdk_printf(MSDK_STRING(" [-resetInterval resetInterval] - reset interval in frames, default 7 \n")); msdk_printf(MSDK_STRING(" [-reset -i ... -o ... -f ... -w ... -h ... -bbl ... -bwb ... -ccm ...] - params to be used after next reset.\n")); msdk_printf(MSDK_STRING(" Only params listed above are supported, if a param is not set here, the originally set value is used. \n")); msdk_printf(MSDK_STRING(" There can be any number of resets, applied in order of appearance in the command line, \n")); msdk_printf(MSDK_STRING(" after resetInterval frames are processed with the current params \n")); msdk_printf(MSDK_STRING(" [-imem] - input memory type (sys|video). Default is system\n")); #if D3D_SURFACES_SUPPORT msdk_printf(MSDK_STRING(" [-omem] - output memory type (sys|video). Default is system\n")); msdk_printf(MSDK_STRING(" [-accel] - type of acceleration device (d3d9|d3d11). Default is d3d9\n")); msdk_printf(MSDK_STRING(" [-r] / [-render] - render output in a separate window \n")); msdk_printf(MSDK_STRING(" [-wall w h n m f t tmo] - same as -r, and positioned rendering window in a particular cell on specific monitor \n")); msdk_printf(MSDK_STRING(" w - number of columns of video windows on selected monitor\n")); msdk_printf(MSDK_STRING(" h - number of rows of video windows on selected monitor\n")); msdk_printf(MSDK_STRING(" n(0,.,w*h-1) - order of video window in table that will be rendered\n")); msdk_printf(MSDK_STRING(" m(0,1..) - monitor id \n")); msdk_printf(MSDK_STRING(" f - rendering framerate\n")); msdk_printf(MSDK_STRING(" t(0/1) - enable/disable window's title\n")); msdk_printf(MSDK_STRING(" tmo - timeout for -wall option\n")); #endif #if defined(_WIN32) || defined(_WIN64) msdk_printf(MSDK_STRING("\nFeatures: \n")); msdk_printf(MSDK_STRING(" Press 1 to toggle fullscreen rendering on/off\n")); #endif msdk_printf(MSDK_STRING("\n")); }
mfxStatus D3DFrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response) { HRESULT hr; MSDK_CHECK_POINTER(request, MFX_ERR_NULL_PTR); if (request->NumFrameSuggested == 0) return MFX_ERR_UNKNOWN; D3DFORMAT format = ConvertMfxFourccToD3dFormat(request->Info.FourCC); if (format == D3DFMT_UNKNOWN) { msdk_printf(MSDK_STRING("D3D Allocator: invalid fourcc is provided (%#X), exitting\n"),request->Info.FourCC); return MFX_ERR_UNSUPPORTED; } DWORD target; if (MFX_MEMTYPE_DXVA2_DECODER_TARGET & request->Type) { target = DXVA2_VideoDecoderRenderTarget; } else if (MFX_MEMTYPE_DXVA2_PROCESSOR_TARGET & request->Type) { target = DXVA2_VideoProcessorRenderTarget; } else return MFX_ERR_UNSUPPORTED; IDirectXVideoAccelerationService* videoService = NULL; if (target == DXVA2_VideoProcessorRenderTarget) { if (!m_hProcessor) { hr = m_manager->OpenDeviceHandle(&m_hProcessor); if (FAILED(hr)) return MFX_ERR_MEMORY_ALLOC; hr = m_manager->GetVideoService(m_hProcessor, IID_IDirectXVideoProcessorService, (void**)&m_processorService); if (FAILED(hr)) return MFX_ERR_MEMORY_ALLOC; } videoService = m_processorService; } else { if (!m_hDecoder) { hr = m_manager->OpenDeviceHandle(&m_hDecoder); if (FAILED(hr)) return MFX_ERR_MEMORY_ALLOC; hr = m_manager->GetVideoService(m_hDecoder, IID_IDirectXVideoDecoderService, (void**)&m_decoderService); if (FAILED(hr)) return MFX_ERR_MEMORY_ALLOC; } videoService = m_decoderService; } mfxHDLPair *dxMids = NULL, **dxMidPtrs = NULL; dxMids = (mfxHDLPair*)calloc(request->NumFrameSuggested, sizeof(mfxHDLPair)); dxMidPtrs = (mfxHDLPair**)calloc(request->NumFrameSuggested, sizeof(mfxHDLPair*)); if (!dxMids || !dxMidPtrs) { MSDK_SAFE_FREE(dxMids); MSDK_SAFE_FREE(dxMidPtrs); return MFX_ERR_MEMORY_ALLOC; } response->mids = (mfxMemId*)dxMidPtrs; response->NumFrameActual = request->NumFrameSuggested; if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) { for (int i = 0; i < request->NumFrameSuggested; i++) { hr = videoService->CreateSurface(request->Info.Width, request->Info.Height, 0, format, D3DPOOL_DEFAULT, m_surfaceUsage, target, (IDirect3DSurface9**)&dxMids[i].first, &dxMids[i].second); if (FAILED(hr)) { ReleaseResponse(response); MSDK_SAFE_FREE(dxMids); return MFX_ERR_MEMORY_ALLOC; } dxMidPtrs[i] = &dxMids[i]; } } else { safe_array<IDirect3DSurface9*> dxSrf(new IDirect3DSurface9*[request->NumFrameSuggested]); if (!dxSrf.get()) { MSDK_SAFE_FREE(dxMids); return MFX_ERR_MEMORY_ALLOC; } hr = videoService->CreateSurface(request->Info.Width, request->Info.Height, request->NumFrameSuggested - 1, format, D3DPOOL_DEFAULT, m_surfaceUsage, target, dxSrf.get(), NULL); if (FAILED(hr)) { MSDK_SAFE_FREE(dxMids); return MFX_ERR_MEMORY_ALLOC; } for (int i = 0; i < request->NumFrameSuggested; i++) { dxMids[i].first = dxSrf.get()[i]; dxMidPtrs[i] = &dxMids[i]; } } return MFX_ERR_NONE; }
void v4l2Device::V4L2Init() { int ret; struct v4l2_format fmt; struct v4l2_capability caps; struct v4l2_streamparm parm; struct v4l2_requestbuffers rqbufs; CLEAR(parm); m_fd = open(m_devname, O_RDWR); BYE_ON(m_fd < 0, "failed to open %s: %s\n", m_devname, ERRSTR); CLEAR(caps); /* Specifically for setting up mipi configuration. DMABUFF is * also enable by default here. */ if (m_MipiPort > -1 && m_MipiMode != NONE) { parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; parm.parm.capture.capturemode = GetAtomISPModes(m_MipiMode); ret = blockIOCTL(m_fd, VIDIOC_S_INPUT, &m_MipiPort); BYE_ON(ret < 0, "VIDIOC_S_INPUT failed: %s\n", ERRSTR); ret = blockIOCTL(m_fd, VIDIOC_S_PARM, &parm); BYE_ON(ret < 0, "VIDIOC_S_PARAM failed: %s\n", ERRSTR); } ret = blockIOCTL(m_fd, VIDIOC_QUERYCAP, &caps); msdk_printf( "Driver Caps:\n" " Driver: \"%s\"\n" " Card: \"%s\"\n" " Bus: \"%s\"\n" " Version: %d.%d\n" " Capabilities: %08x\n", caps.driver, caps.card, caps.bus_info, (caps.version>>16)&&0xff, (caps.version>>24)&&0xff, caps.capabilities); BYE_ON(ret, "VIDIOC_QUERYCAP failed: %s\n", ERRSTR); BYE_ON(~caps.capabilities & V4L2_CAP_VIDEO_CAPTURE, "video: singleplanar capture is not supported\n"); CLEAR(fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; ret = blockIOCTL(m_fd, VIDIOC_G_FMT, &fmt); BYE_ON(ret < 0, "VIDIOC_G_FMT failed: %s\n", ERRSTR); msdk_printf("G_FMT(start): width = %u, height = %u, 4cc = %.4s, BPP = %u sizeimage = %d field = %d\n", fmt.fmt.pix.width, fmt.fmt.pix.height, (char*)&fmt.fmt.pix.pixelformat, fmt.fmt.pix.bytesperline, fmt.fmt.pix.sizeimage, fmt.fmt.pix.field); fmt.fmt.pix = m_format; msdk_printf("G_FMT(pre): width = %u, height = %u, 4cc = %.4s, BPP = %u sizeimage = %d field = %d\n", fmt.fmt.pix.width, fmt.fmt.pix.height, (char*)&fmt.fmt.pix.pixelformat, fmt.fmt.pix.bytesperline, fmt.fmt.pix.sizeimage, fmt.fmt.pix.field); ret = blockIOCTL(m_fd, VIDIOC_S_FMT, &fmt); BYE_ON(ret < 0, "VIDIOC_S_FMT failed: %s\n", ERRSTR); ret = blockIOCTL(m_fd, VIDIOC_G_FMT, &fmt); BYE_ON(ret < 0, "VIDIOC_G_FMT failed: %s\n", ERRSTR); msdk_printf("G_FMT(final): width = %u, height = %u, 4cc = %.4s, BPP = %u\n", fmt.fmt.pix.width, fmt.fmt.pix.height, (char*)&fmt.fmt.pix.pixelformat, fmt.fmt.pix.bytesperline); CLEAR(rqbufs); rqbufs.count = m_num_buffers; rqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; rqbufs.memory = V4L2_MEMORY_DMABUF; ret = blockIOCTL(m_fd, VIDIOC_REQBUFS, &rqbufs); BYE_ON(ret < 0, "VIDIOC_REQBUFS failed: %s\n", ERRSTR); BYE_ON(rqbufs.count < m_num_buffers, "video node allocated only " "%u of %u buffers\n", rqbufs.count, m_num_buffers); m_format = fmt.fmt.pix; }