⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htrencftr.h

📁 Freescale ARM11系列CPU MX31的WINCE 5.0下的BSP
💻 H
字号:
/*------------------------------------------------------------------------------
--                                                                            --
--       This software is confidential and proprietary and may be used        --
--        only as expressly authorized by a licensing agreement from          --
--                                                                            --
--                            Hantro Products Oy.                             --
--                                                                            --
--      In the event of publication, the following notice is applicable:      --
--                                                                            --
--                   (C) COPYRIGHT 2005 HANTRO PRODUCTS OY                    --
--                            ALL RIGHTS RESERVED                             --
--                                                                            --
--          The entire notice above must be reproduced on all copies.         --
--                                                                            --
--------------------------------------------------------------------------------
--
--  Abstract : Transform filter for Hantro HW encoder in DirectShow integration
--
-------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------

    Table of context

    1. Include headers
    2. Module defines
    3. CHtrEncFltr class
	4. IHtrAllocator class
    5. CHtrEncPhysicalAllocator class
    6. CHtrEncInputPin class
    7. CHtrEncOutputPin class

------------------------------------------------------------------------------*/

#ifndef CHTRENCFLTR
#define CHTRENCFLTR
#pragma once

/*------------------------------------------------------------------------------
    1. Include headers
------------------------------------------------------------------------------*/

#include "stdafx.h"
#include <initguid.h>
#include "htrencguids.h"
#include "htrencwrapper.h"

/*------------------------------------------------------------------------------
    2. Module defines
------------------------------------------------------------------------------*/

class CHtrEncInputPin;
class CHtrEncOutputPin;

/*------------------------------------------------------------------------------
    3. CHtrEncFltr class
------------------------------------------------------------------------------*/

// CHtrEncFltr
//
// This is a class that supports a encoding raw YCbCr 4:2:0 planar frames 
// into MPEG-4 or H.263 video bitstream with a single input and a single 
// output. It is derived from the CTransformFilter class, and it supports 
// the IBaseFilter interface from inheritance hierarchy.
//
// Each pin, declared as Friends in this class, supports the IPin interface 
// and uses the shared memory transport based on the IMemInputPin interface.
//
// The filter uses classes derived from the CBaseFilter class to support 
// IBaseFilter; the CHtrEncInputPin input pin class is derived from the 
// CTransformInputPin class, and the CHtrEncOutputPin output pin class is 
// derived from the CTransformOutputPin class.
class CHtrEncFltr : CTransformFilter
{
	friend class CHtrEncInputPin;
	friend class CHtrEncOutputPin;

public:
	// Constructor and destructor declared as public
	CHtrEncFltr(TCHAR* pObjectName, LPUNKNOWN pUnk, HRESULT *pHr);
	virtual ~CHtrEncFltr(void);
	static CUnknown* WINAPI CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr);

	// Pure virtual methods from CTransformFilter
	HRESULT CheckInputType(const CMediaType* mtIn);
	HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut);
	HRESULT DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* ppropInputRequest);
	HRESULT GetMediaType(int iPosition, CMediaType* pMediaType);
	HRESULT Transform(IMediaSample* pIn, IMediaSample* pOut);

	// Virtual methods from CTransformFilter
    HRESULT SetMediaType( PIN_DIRECTION direction, const CMediaType* pmt );
	HRESULT StartStreaming();
	HRESULT EndOfStream();
	CBasePin *GetPin(int n); // to obtain custom pins & allocator

private:
	CHantroEncoderWrapper* m_pWrapper;
    CHantroEncoderWrapper::Settings m_settings;
    REFERENCE_TIME m_cachedAvgFrameTime;
};


/*------------------------------------------------------------------------------
    4. IHtrAllocator class
------------------------------------------------------------------------------*/

// Interface for getting mappings to physical addresses once we know virtual
// address.
class IHtrAllocator : public IUnknown
{
public:
	virtual HRESULT MapToPhysicalAddr(LPVOID pVirAddr, DWORD* pPhysAddr) = 0;
};

/*------------------------------------------------------------------------------
    5. CHtrEncPhysicalAllocator class
------------------------------------------------------------------------------*/

// Class for allocating physical memory for encoder filter.
// CBaseAllocator exposes the IMemAllocator interface and in addition
// CHtrEncPhysicalAllocator exposes custom interface IHtrAllocator.
class CHtrEncPhysicalAllocator : public CBaseAllocator, IHtrAllocator
{
public:
	// Inner class for helping with bookkeeping
	class Mapping
	{
	public:
		Mapping( LPVOID p_VirAddr, DWORD p_PhysAddr )
		: pVirAddr(p_VirAddr), pPhysAddr(p_PhysAddr), p_next(NULL)
		{}

		LPVOID pVirAddr;
		DWORD pPhysAddr;
		Mapping* p_next;
	};

	// Constructor
	CHtrEncPhysicalAllocator(HRESULT* phr);

	// We have to expose IHtrAllocator through COM
DECLARE_IUNKNOWN
	STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);

	// From IHtrAllocator
	HRESULT MapToPhysicalAddr(LPVOID pVirAddr, DWORD* pPhysAddr);

protected:
	// Overridden virtual methods from CBaseAllocator
	HRESULT Alloc(void);
	void Free(void); 

private:
	// Bookkeeping members for physical & virtual address mapping
	CHtrEncPhysicalAllocator::Mapping* m_pMappingsList;
	HRESULT AddMapping(LPVOID pVirAddr, DWORD physAddr);
	CHtrEncPhysicalAllocator::Mapping* FindMapping(LPVOID pVirAddr);
	VOID ClearMappings();
};

/*------------------------------------------------------------------------------
    6. CHtrEncInputPin class
------------------------------------------------------------------------------*/

// Class for input pin of the encoder filter with custom allocator
class CHtrEncInputPin : public CTransformInputPin
{
public:
    // Constructor
    CHtrEncInputPin( TCHAR* pObjectName, CTransformFilter* pTransformFilter, HRESULT* phr, LPCWSTR pName );

	// From CBaseInputPin to provide custom allocator
	HRESULT STDMETHODCALLTYPE GetAllocator(IMemAllocator **ppAllocator);
	HRESULT STDMETHODCALLTYPE NotifyAllocator(IMemAllocator *pAllocator, BOOL bReadOnly);

	// Interface to custom allocator
	IHtrAllocator* m_pHtrAlloc;
};

/*------------------------------------------------------------------------------
    7. CHtrEncOutputPin class
------------------------------------------------------------------------------*/

// Class for output pin of the encoder filter with custom allocator
class CHtrEncOutputPin : public CTransformOutputPin, IAMStreamConfig, IAMVideoCompression
{
public:
    // Constructor
    CHtrEncOutputPin( TCHAR* pObjectName, CTransformFilter* pTransformFilter, HRESULT* phr, LPCWSTR pName );

	// From CBaseOutputPin to provide custom allocator
    HRESULT DecideAllocator(IMemInputPin *pPin, IMemAllocator **pAlloc);

	// We have to expose IAMStreamConfig and IAMVideoCompression through COM
DECLARE_IUNKNOWN
    STDMETHODIMP NonDelegatingQueryInterface(REFIID iid, void **ppv);

	// Methods from IAMStreamConfig
	HRESULT STDMETHODCALLTYPE GetFormat(AM_MEDIA_TYPE** pmt);
	HRESULT STDMETHODCALLTYPE SetFormat(AM_MEDIA_TYPE* pmt);
	HRESULT STDMETHODCALLTYPE GetNumberOfCapabilities(int* piCount, int* piSize);
	HRESULT STDMETHODCALLTYPE GetStreamCaps(int iIndex, AM_MEDIA_TYPE** pmt, BYTE* pSCC);

	// Methods from IAMVideoCompression
	HRESULT STDMETHODCALLTYPE put_KeyFrameRate(long KeyFrameRate);
	HRESULT STDMETHODCALLTYPE get_KeyFrameRate(long *pKeyFrameRate);
	HRESULT STDMETHODCALLTYPE GetInfo( WCHAR* pszVersion, int* pcbVersion, 
		LPWSTR pszDescription, int* pcbDescription, long* pDefaultKeyFrameRate,
		long* pDefaultPFramesPerKey, double* pDefaultQuality, long* pCapabilities );

    HRESULT STDMETHODCALLTYPE put_PFramesPerKeyFrame(long PFramesPerKeyFrame);
	HRESULT STDMETHODCALLTYPE get_PFramesPerKeyFrame(long *pPFramesPerKeyFrame);
    HRESULT STDMETHODCALLTYPE put_Quality(double Quality);
	HRESULT STDMETHODCALLTYPE get_Quality(double *pQuality);
	HRESULT STDMETHODCALLTYPE put_WindowSize(DWORDLONG WindowSize);
	HRESULT STDMETHODCALLTYPE get_WindowSize(DWORDLONG *pWindowSize);
	HRESULT STDMETHODCALLTYPE OverrideKeyFrame(long FrameNumber);
	HRESULT STDMETHODCALLTYPE OverrideFrameSize(long FrameNumber, long Size);

	// Interface to custom allocator
	IHtrAllocator* m_pHtrAlloc;
};

#endif // CHTRENCFLTR

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -