Welcome to mirror list, hosted at ThFree Co, Russian Federation.

wmv9mft.h « decoders « LAVVideo « decoder - github.com/mpc-hc/LAVFilters.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 82aa269082e33bc3976b4eac9d4762bf9470c18c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 *      Copyright (C) 2010-2015 Hendrik Leppkes
 *      http://www.1f0.de
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#pragma once
#include "DecBase.h"

#include <mfidl.h>

#include <vector>
#include <queue>

////////////////////////////////////////////////////////////////////////////////
// Dynlink types
////////////////////////////////////////////////////////////////////////////////
typedef HRESULT STDAPICALLTYPE tMFStartup(ULONG Version, DWORD dwFlags);
typedef HRESULT STDAPICALLTYPE tMFShutdown();

typedef HRESULT STDAPICALLTYPE tMFCreateMediaType(IMFMediaType**  ppMFType);
typedef HRESULT STDAPICALLTYPE tMFCreateSample(IMFSample **ppIMFSample);
typedef HRESULT STDAPICALLTYPE tMFCreateAlignedMemoryBuffer(DWORD cbMaxLength, DWORD cbAligment, IMFMediaBuffer **ppBuffer);

typedef HRESULT STDAPICALLTYPE tMFAverageTimePerFrameToFrameRate(UINT64 unAverageTimePerFrame, UINT32 *punNumerator, UINT32 *punDenominator);

#define MFMETHOD(name) tMF##name *##name

////////////////////////////////////////////////////////////////////////////////
// Class
////////////////////////////////////////////////////////////////////////////////

class CVC1HeaderParser;

typedef struct _Buffer {
  IMFMediaBuffer *pBuffer = nullptr;
  size_t size             = 0;
  bool used               = false;
} Buffer;

class CDecWMV9MFT : public CDecBase
{
public:
  CDecWMV9MFT(void);
  virtual ~CDecWMV9MFT(void);

  // ILAVDecoder
  STDMETHODIMP InitDecoder(AVCodecID codec, const CMediaType *pmt);
  STDMETHODIMP Decode(const BYTE *buffer, int buflen, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, BOOL bSyncPoint, BOOL bDiscontinuity);
  STDMETHODIMP Flush();
  STDMETHODIMP EndOfStream();
  STDMETHODIMP GetPixelFormat(LAVPixelFormat *pPix, int *pBpp);
  STDMETHODIMP_(BOOL) IsInterlaced();
  STDMETHODIMP_(const WCHAR*) GetDecoderName() { return L"wmv9 mft"; }
  STDMETHODIMP HasThreadSafeBuffers() { return S_OK; }

  // CDecBase
  STDMETHODIMP Init();

private:
  STDMETHODIMP DestroyDecoder(bool bFull);
  STDMETHODIMP ProcessOutput();
  STDMETHODIMP SelectOutputType();

  IMFMediaBuffer * CreateMediaBuffer(const BYTE * pData, DWORD dwDataLen);

  static void wmv9_buffer_destruct(LAVFrame *pFrame);

  IMFMediaBuffer *GetBuffer(size_t sRequiredSize);
  void ReleaseBuffer(IMFMediaBuffer *pBuffer);

private:
  IMFTransform *m_pMFT = nullptr;

  BOOL m_bInterlaced     = TRUE;

  LAVPixelFormat m_OutPixFmt = LAVPixFmt_None;
  AVCodecID m_nCodecId       = AV_CODEC_ID_NONE;

  CCritSec m_BufferCritSec;
  std::vector<Buffer *> m_BufferQueue;

  BOOL m_bNeedKeyFrame             = TRUE;
  BOOL m_bManualReorder            = FALSE;
  BOOL m_bReorderBufferValid       = FALSE;
  REFERENCE_TIME m_rtReorderBuffer = AV_NOPTS_VALUE;
  std::queue<REFERENCE_TIME> m_timestampQueue;

  CVC1HeaderParser *m_vc1Header = nullptr;

  struct {
    HMODULE mfplat = NULL;
    MFMETHOD(Startup);
    MFMETHOD(Shutdown);
    MFMETHOD(CreateAlignedMemoryBuffer);
    MFMETHOD(CreateSample);
    MFMETHOD(CreateMediaType);
    MFMETHOD(AverageTimePerFrameToFrameRate);
  } MF;
};