common_utils.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*****************************************************************************
  2. INTEL CORPORATION PROPRIETARY INFORMATION
  3. This software is supplied under the terms of a license agreement or
  4. nondisclosure agreement with Intel Corporation and may not be copied
  5. or disclosed except in accordance with the terms of that agreement.
  6. Copyright(c) 2005-2014 Intel Corporation. All Rights Reserved.
  7. *****************************************************************************/
  8. #pragma once
  9. #include <stdio.h>
  10. #include "mfxvideo++.h"
  11. // =================================================================
  12. // OS-specific definitions of types, macro, etc...
  13. // The following should be defined:
  14. // - mfxTime
  15. // - MSDK_FOPEN
  16. // - MSDK_SLEEP
  17. #if defined(_WIN32) || defined(_WIN64)
  18. #include "bits/windows_defs.h"
  19. #elif defined(__linux__)
  20. #include "bits/linux_defs.h"
  21. #endif
  22. // =================================================================
  23. // Helper macro definitions...
  24. #define MSDK_PRINT_RET_MSG(ERR) {PrintErrString(ERR, __FILE__, __LINE__);}
  25. #define MSDK_CHECK_RESULT(P, X, ERR) {if ((X) > (P)) {MSDK_PRINT_RET_MSG(ERR); return ERR;}}
  26. #define MSDK_CHECK_POINTER(P, ERR) {if (!(P)) {MSDK_PRINT_RET_MSG(ERR); return ERR;}}
  27. #define MSDK_CHECK_ERROR(P, X, ERR) {if ((X) == (P)) {MSDK_PRINT_RET_MSG(ERR); return ERR;}}
  28. #define MSDK_IGNORE_MFX_STS(P, X) {if ((X) == (P)) {P = MFX_ERR_NONE;}}
  29. #define MSDK_BREAK_ON_ERROR(P) {if (MFX_ERR_NONE != (P)) break;}
  30. #define MSDK_SAFE_DELETE_ARRAY(P) {if (P) {delete[] P; P = NULL;}}
  31. #define MSDK_ALIGN32(X) (((mfxU32)((X)+31)) & (~ (mfxU32)31))
  32. #define MSDK_ALIGN16(value) (((value + 15) >> 4) << 4)
  33. #define MSDK_SAFE_RELEASE(X) {if (X) { X->Release(); X = NULL; }}
  34. #define MSDK_MAX(A, B) (((A) > (B)) ? (A) : (B))
  35. // Usage of the following two macros are only required for certain Windows DirectX11 use cases
  36. #define WILL_READ 0x1000
  37. #define WILL_WRITE 0x2000
  38. // =================================================================
  39. // Intel Media SDK memory allocator entrypoints....
  40. // Implementation of this functions is OS/Memory type specific.
  41. mfxStatus simple_alloc(mfxHDL pthis, mfxFrameAllocRequest* request, mfxFrameAllocResponse* response);
  42. mfxStatus simple_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData* ptr);
  43. mfxStatus simple_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData* ptr);
  44. mfxStatus simple_gethdl(mfxHDL pthis, mfxMemId mid, mfxHDL* handle);
  45. mfxStatus simple_free(mfxHDL pthis, mfxFrameAllocResponse* response);
  46. // =================================================================
  47. // Utility functions, not directly tied to Media SDK functionality
  48. //
  49. void PrintErrString(int err,const char* filestr,int line);
  50. // LoadRawFrame: Reads raw frame from YUV file (YV12) into NV12 surface
  51. // - YV12 is a more common format for YUV files than NV12 (therefore the conversion during read and write)
  52. // - For the simulation case (fSource = NULL), the surface is filled with default image data
  53. // LoadRawRGBFrame: Reads raw RGB32 frames from file into RGB32 surface
  54. // - For the simulation case (fSource = NULL), the surface is filled with default image data
  55. mfxStatus LoadRawFrame(mfxFrameSurface1* pSurface, FILE* fSource);
  56. mfxStatus LoadRawRGBFrame(mfxFrameSurface1* pSurface, FILE* fSource);
  57. // Write raw YUV (NV12) surface to YUV (YV12) file
  58. mfxStatus WriteRawFrame(mfxFrameSurface1* pSurface, FILE* fSink);
  59. // Write bit stream data for frame to file
  60. mfxStatus WriteBitStreamFrame(mfxBitstream* pMfxBitstream, FILE* fSink);
  61. // Read bit stream data from file. Stream is read as large chunks (= many frames)
  62. mfxStatus ReadBitStreamData(mfxBitstream* pBS, FILE* fSource);
  63. void ClearYUVSurfaceSysMem(mfxFrameSurface1* pSfc, mfxU16 width, mfxU16 height);
  64. void ClearYUVSurfaceVMem(mfxMemId memId);
  65. void ClearRGBSurfaceVMem(mfxMemId memId);
  66. // Get free raw frame surface
  67. int GetFreeSurfaceIndex(mfxFrameSurface1** pSurfacesPool, mfxU16 nPoolSize);
  68. // For use with asynchronous task management
  69. typedef struct {
  70. mfxBitstream mfxBS;
  71. mfxSyncPoint syncp;
  72. } Task;
  73. // Get free task
  74. int GetFreeTaskIndex(Task* pTaskPool, mfxU16 nPoolSize);
  75. // Initialize Intel Media SDK Session, device/display and memory manager
  76. mfxStatus Initialize(mfxIMPL impl, mfxVersion ver, MFXVideoSession* pSession, mfxFrameAllocator* pmfxAllocator, bool bCreateSharedHandles = false, bool dx9hack = false);
  77. // Release resources (device/display)
  78. void Release();
  79. // Convert frame type to string
  80. char mfxFrameTypeString(mfxU16 FrameType);
  81. void mfxGetTime(mfxTime* timestamp);
  82. //void mfxInitTime(); might need this for Windows
  83. double TimeDiffMsec(mfxTime tfinish, mfxTime tstart);