summaryrefslogtreecommitdiffstats
path: root/plugins/pluginWinMF/internals/mf_codec.h
blob: 51b06dc310b0908e846a2245cc040bb3cadae7de (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* Copyright (C) 2013 Mamadou DIOP
* Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
*	
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO 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 3 of the License, or
* (at your option) any later version.
*	
* DOUBANGO 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 DOUBANGO.
*/
#ifndef PLUGIN_WIN_MF_CODEC_H
#define PLUGIN_WIN_MF_CODEC_H

#include "../plugin_win_mf_config.h"

#include <new>
#include <mfapi.h>
#include <mfidl.h>
#include <Mferror.h>
#include <shlwapi.h>
#include <strmif.h>

class MFSampleQueue;

typedef enum MFCodecId_e
{
	MFCodecId_H264Base,
	MFCodecId_H264Main,
	MFCodecId_AAC
}
MFCodecId_t;

typedef enum MFCodecType_e
{
	MFCodecType_Encoder,
	MFCodecType_Decoder
}
MFCodecType_t;

typedef enum MFCodecMediaType_e
{
	MFCodecMediaType_Audio,
	MFCodecMediaType_Video
}
MFCodecMediaType_t;

class MFCodec : IMFAsyncCallback 
{
protected:
	MFCodec(MFCodecId_t eId, MFCodecType_t eType, IMFTransform *pMFT = NULL);
	virtual ~MFCodec();
	HRESULT ProcessInput(IMFSample* pSample);
	HRESULT ProcessOutput(IMFSample **ppSample);

public:
	virtual bool IsValid();
	virtual bool IsReady();
	virtual HRESULT Process(const void* pcInputPtr, UINT32 nInputSize, IMFSample **ppSampleOut);
	static enum tmedia_chroma_e GetUncompressedChroma();
	inline IMFTransform* GetMFT(){ return m_pMFT; }
	inline MFCodecId_t GetId() { return m_eId; }
	inline MFCodecType_t GetType() { return m_eType; }
	inline void setBundled(BOOL bBundled) { m_bIsBundled = bBundled; }

	// IUnknown
    STDMETHODIMP QueryInterface(REFIID iid, void** ppv);
    STDMETHODIMP_(ULONG) AddRef();
    STDMETHODIMP_(ULONG) Release();

	// IMFAsyncCallback
	STDMETHODIMP GetParameters(DWORD *pdwFlags, DWORD *pdwQueue);
	STDMETHODIMP Invoke(IMFAsyncResult *pAsyncResult);

private:
	long				m_nRefCount;

protected:
	MFCodecId_t			m_eId;			// Codec Id
	MFCodecType_t		m_eType;		// Codec type.
	MFCodecMediaType_t	m_eMediaType;	// Codec Media type.
	DWORD				m_dwInputID;     // Input stream ID.
    DWORD				m_dwOutputID;    // Output stream ID.

	GUID				m_guidCompressedFormat;	// Compressed Media format (e.g. MFVideoFormat_H264)
    IMFTransform		*m_pMFT;         // Pointer to the encoder MFT.
	ICodecAPI			*m_pCodecAPI;	// Pointer to CodecAPI.
    IMFMediaType		*m_pOutputType;  // Output media type of the codec.
	IMFMediaType		*m_pInputType;  // Input media type of the codec.

	LONGLONG m_rtStart;
    UINT64 m_rtDuration;

	IMFSample *m_pSampleIn;
	IMFSample *m_pSampleOut;

	MFSampleQueue *m_pSampleQueueAsyncInput;
	BOOL m_bIsBundled; // Bundled with a producer or cosumer -> do not monitor events
	BOOL m_bIsAsync;
	IMFMediaEventGenerator  *m_pEventGenerator;
	BOOL m_bIsFirstFrame;
	long m_nMETransformNeedInputCount, m_nMETransformHaveOutputCount;
};


class MFCodecVideo : public MFCodec
{
	friend class MFCodec;
protected:
	MFCodecVideo(MFCodecId_t eId, MFCodecType_t eType, IMFTransform *pMFT = NULL);
	virtual ~MFCodecVideo();

public:
	virtual HRESULT Initialize(
			UINT32 nFrameRate,
			UINT32 nWidth,
			UINT32 nHeight,
			UINT32 nOutputBitRateInBps = 0 // Only for encoders
		);
	virtual HRESULT SetGOPSize(UINT32 nFramesCount);
	virtual HRESULT SetBitRate(UINT32 nBitRateInBps);
	virtual HRESULT SetSliceMaxSizeInBytes(UINT32 nSliceMaxSizeInBytes);
	virtual HRESULT RequestKeyFrame();

	virtual HRESULT IsSetSliceMaxSizeInBytesSupported(BOOL &supported);
	virtual inline UINT32 GetFrameRate() { return m_nFrameRate; }
	virtual inline UINT32 GetWidth() { return m_nWidth; }
	virtual inline UINT32 GetHeight() { return m_nHeight; }

protected:
	UINT32 m_nFrameRate;
	UINT32 m_nWidth;
	UINT32 m_nHeight;
};

class MFCodecVideoH264 : public MFCodecVideo
{
protected:
	MFCodecVideoH264(MFCodecId_t eId, MFCodecType_t eType, IMFTransform *pMFT = NULL);

public:
	virtual ~MFCodecVideoH264();
	static MFCodecVideoH264* CreateCodecH264Base(MFCodecType_t eType, IMFTransform *pMFT = NULL);
	static MFCodecVideoH264* CreateCodecH264Main(MFCodecType_t eType, IMFTransform *pMFT = NULL);

protected:

};


#endif /* PLUGIN_WIN_MF_CODEC_H */
OpenPOWER on IntegriCloud