mf_codec.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* Copyright (C) 2013 Mamadou DIOP
  2. * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
  3. *
  4. * This file is part of Open Source Doubango Framework.
  5. *
  6. * DOUBANGO is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * DOUBANGO is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with DOUBANGO.
  18. */
  19. #ifndef PLUGIN_WIN_MF_CODEC_H
  20. #define PLUGIN_WIN_MF_CODEC_H
  21. #include "../plugin_win_mf_config.h"
  22. #include <new>
  23. #include <mfapi.h>
  24. #include <mfidl.h>
  25. #include <Mferror.h>
  26. #include <shlwapi.h>
  27. #include <strmif.h>
  28. class MFSampleQueue;
  29. typedef enum MFCodecId_e {
  30. MFCodecId_H264Base,
  31. MFCodecId_H264Main,
  32. MFCodecId_AAC
  33. }
  34. MFCodecId_t;
  35. typedef enum MFCodecType_e {
  36. MFCodecType_Encoder,
  37. MFCodecType_Decoder
  38. }
  39. MFCodecType_t;
  40. typedef enum MFCodecMediaType_e {
  41. MFCodecMediaType_Audio,
  42. MFCodecMediaType_Video
  43. }
  44. MFCodecMediaType_t;
  45. class MFCodec : IMFAsyncCallback
  46. {
  47. protected:
  48. MFCodec(MFCodecId_t eId, MFCodecType_t eType, IMFTransform *pMFT = NULL);
  49. virtual ~MFCodec();
  50. HRESULT ProcessInput(IMFSample* pSample);
  51. HRESULT ProcessOutput(IMFSample **ppSample);
  52. public:
  53. virtual bool IsValid();
  54. virtual bool IsReady();
  55. virtual HRESULT Process(const void* pcInputPtr, UINT32 nInputSize, IMFSample **ppSampleOut);
  56. static enum tmedia_chroma_e GetUncompressedChroma();
  57. inline IMFTransform* GetMFT() {
  58. return m_pMFT;
  59. }
  60. inline MFCodecId_t GetId() {
  61. return m_eId;
  62. }
  63. inline MFCodecType_t GetType() {
  64. return m_eType;
  65. }
  66. inline void setBundled(BOOL bBundled) {
  67. m_bIsBundled = bBundled;
  68. }
  69. // IUnknown
  70. STDMETHODIMP QueryInterface(REFIID iid, void** ppv);
  71. STDMETHODIMP_(ULONG) AddRef();
  72. STDMETHODIMP_(ULONG) Release();
  73. // IMFAsyncCallback
  74. STDMETHODIMP GetParameters(DWORD *pdwFlags, DWORD *pdwQueue);
  75. STDMETHODIMP Invoke(IMFAsyncResult *pAsyncResult);
  76. private:
  77. long m_nRefCount;
  78. protected:
  79. MFCodecId_t m_eId; // Codec Id
  80. MFCodecType_t m_eType; // Codec type.
  81. MFCodecMediaType_t m_eMediaType; // Codec Media type.
  82. DWORD m_dwInputID; // Input stream ID.
  83. DWORD m_dwOutputID; // Output stream ID.
  84. GUID m_guidCompressedFormat; // Compressed Media format (e.g. MFVideoFormat_H264)
  85. IMFTransform *m_pMFT; // Pointer to the encoder MFT.
  86. ICodecAPI *m_pCodecAPI; // Pointer to CodecAPI.
  87. IMFMediaType *m_pOutputType; // Output media type of the codec.
  88. IMFMediaType *m_pInputType; // Input media type of the codec.
  89. LONGLONG m_rtStart;
  90. UINT64 m_rtDuration;
  91. IMFSample *m_pSampleIn;
  92. IMFSample *m_pSampleOut;
  93. MFSampleQueue *m_pSampleQueueAsyncInput;
  94. BOOL m_bIsBundled; // Bundled with a producer or cosumer -> do not monitor events
  95. BOOL m_bIsAsync;
  96. IMFMediaEventGenerator *m_pEventGenerator;
  97. BOOL m_bIsFirstFrame;
  98. long m_nMETransformNeedInputCount, m_nMETransformHaveOutputCount;
  99. };
  100. class MFCodecVideo : public MFCodec
  101. {
  102. friend class MFCodec;
  103. protected:
  104. MFCodecVideo(MFCodecId_t eId, MFCodecType_t eType, IMFTransform *pMFT = NULL);
  105. virtual ~MFCodecVideo();
  106. public:
  107. virtual HRESULT Initialize(
  108. UINT32 nFrameRate,
  109. UINT32 nWidth,
  110. UINT32 nHeight,
  111. UINT32 nOutputBitRateInBps = 0 // Only for encoders
  112. );
  113. virtual HRESULT SetGOPSize(UINT32 nFramesCount);
  114. virtual HRESULT SetBitRate(UINT32 nBitRateInBps);
  115. virtual HRESULT SetSliceMaxSizeInBytes(UINT32 nSliceMaxSizeInBytes);
  116. virtual HRESULT RequestKeyFrame();
  117. virtual HRESULT IsSetSliceMaxSizeInBytesSupported(BOOL &supported);
  118. virtual inline UINT32 GetFrameRate() {
  119. return m_nFrameRate;
  120. }
  121. virtual inline UINT32 GetWidth() {
  122. return m_nWidth;
  123. }
  124. virtual inline UINT32 GetHeight() {
  125. return m_nHeight;
  126. }
  127. protected:
  128. UINT32 m_nFrameRate;
  129. UINT32 m_nWidth;
  130. UINT32 m_nHeight;
  131. };
  132. class MFCodecVideoH264 : public MFCodecVideo
  133. {
  134. protected:
  135. MFCodecVideoH264(MFCodecId_t eId, MFCodecType_t eType, IMFTransform *pMFT = NULL);
  136. public:
  137. virtual ~MFCodecVideoH264();
  138. static MFCodecVideoH264* CreateCodecH264Base(MFCodecType_t eType, IMFTransform *pMFT = NULL);
  139. static MFCodecVideoH264* CreateCodecH264Main(MFCodecType_t eType, IMFTransform *pMFT = NULL);
  140. protected:
  141. };
  142. #endif /* PLUGIN_WIN_MF_CODEC_H */