📄 flvdecoder.cpp
字号:
// FLVDecoder.cpp: implementation of CFLVDecoder class.
//
//////////////////////////////////////////////////////////////////////
//#include "stdafx.h"
#include <streams.h> // DirectShow
#include <initguid.h> // DEFINE_GUID to declare an EXTERN_C const.
#include <stdio.h>
#include "iFLVDecoder.h"
#include "FLVDecoder.h"
#include "FLVDecoderProp.h"
int ffmpegInit(void);
int ffmpegDecode(unsigned char *input, int inLen, unsigned char *buffer);
GUID CLSID_FLV1 = {0x31564C46, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71};
#define TRANSFORM_NAME L"FLVDecoder Filter"
// setup data - allows the self-registration to work.
const AMOVIESETUP_MEDIATYPE sudPinTypes =
{ &MEDIATYPE_Video // clsMajorType
, &CLSID_FLV1 }; // clsMinorType
// setup data - allows the self-registration to work.
const AMOVIESETUP_MEDIATYPE sudPinTypes2 =
{ &MEDIATYPE_Video // clsMajorType
, &MEDIASUBTYPE_RGB32 }; // clsMinorType
const AMOVIESETUP_PIN psudPins[] =
{ { L"Input" // strName
, FALSE // bRendered
, FALSE // bOutput
, FALSE // bZero
, FALSE // bMany
, &CLSID_NULL // clsConnectsToFilter
, L"" // strConnectsToPin
, 1 // nTypes
, &sudPinTypes // lpTypes
}
, { L"Output" // strName
, FALSE // bRendered
, TRUE // bOutput
, FALSE // bZero
, FALSE // bMany
, &CLSID_NULL // clsConnectsToFilter
, L"" // strConnectsToPin
, 1 // nTypes
, &sudPinTypes2 // lpTypes
}
};
const AMOVIESETUP_FILTER sudFLVDecoder =
{ &CLSID_FLVDecoder // clsID
, TRANSFORM_NAME // strName
, MERIT_DO_NOT_USE // dwMerit
, 2 // nPins
, psudPins }; // lpPin
// Needed for the CreateInstance mechanism
CFactoryTemplate g_Templates[]=
{ { TRANSFORM_NAME
, &CLSID_FLVDecoder
, CFLVDecoder::CreateInstance
, NULL
, &sudFLVDecoder },
{ TRANSFORM_NAME L" Properties"
, &CLSID_FLVDecoderProp
, CFLVDecoderProp::CreateInstance }
};
int g_cTemplates = sizeof(g_Templates)/sizeof(g_Templates[0]);
///////////////////////////////////////////////////////////////////////
// CreateInstance: for COM to create a CFLVDecoder object
///////////////////////////////////////////////////////////////////////
CUnknown * WINAPI CFLVDecoder::CreateInstance(LPUNKNOWN punk, HRESULT *phr) {
CFLVDecoder *pNewObject = new CFLVDecoder(NAME("FLVDecoder"), punk, phr );
if (pNewObject == NULL) {
*phr = E_OUTOFMEMORY;
}
ffmpegInit();
return pNewObject;
}
///////////////////////////////////////////////////////////////////////
// CFLVDecoder: Constructor
///////////////////////////////////////////////////////////////////////
CFLVDecoder::CFLVDecoder(TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr)
: CTransformFilter (tszName, punk, CLSID_FLVDecoder),
CPersistStream(punk, phr)
{
readConfig(); // read default value from registry
SetParams(&m_FLVDecoderParams); // Set Filter parameters
}
///////////////////////////////////////////////////////////////////////
// ~CFLVDecoder: Destructor
///////////////////////////////////////////////////////////////////////
CFLVDecoder::~CFLVDecoder()
{
}
///////////////////////////////////////////////////////////////////////
// saveConfig: write the parameters into the registry
///////////////////////////////////////////////////////////////////////
void CFLVDecoder::saveConfig()
{
char sz[STR_MAX_LENGTH];
// write int into registry
sprintf(sz, "%d", m_FLVDecoderParams.param1);
WriteProfileStringA("FLVDecoder", "Parameters1", sz);
// Write double value parameters
sprintf(sz, "%f", m_FLVDecoderParams.param2);
WriteProfileStringA("FLVDecoder", "Parameters2", sz);
}
///////////////////////////////////////////////////////////////////////
// readConfig: read the parameters from the registry
///////////////////////////////////////////////////////////////////////
void CFLVDecoder::readConfig()
{
// read integer from registry
m_FLVDecoderParams.param1 =
GetProfileInt("FLVDecoder", "Parameters1", 1);
// Read double value parameters
char sz[STR_MAX_LENGTH];
GetProfileStringA("FLVDecoder", "Parameters2", "0.5", sz, STR_MAX_LENGTH);
m_FLVDecoderParams.param2 = atof(sz);
}
///////////////////////////////////////////////////////////////////////
// CheckInputType: Check if the input type can be done
///////////////////////////////////////////////////////////////////////
HRESULT CFLVDecoder::CheckInputType(const CMediaType *mtIn)
{
if (canPerformTransform(mtIn))
return S_OK;
else
return VFW_E_TYPE_NOT_ACCEPTED;
}
///////////////////////////////////////////////////////////////////////
// Checktransform: Check a transform can be done between these formats
///////////////////////////////////////////////////////////////////////
HRESULT CFLVDecoder::CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut)
{
if (canPerformTransform(mtIn))
{
if (IsEqualGUID(*mtOut->Type(), MEDIATYPE_Video) && IsEqualGUID(*mtOut->Subtype(), MEDIASUBTYPE_RGB32) )
{
return NOERROR;
}
}
return E_FAIL;
}
///////////////////////////////////////////////////////////////////////
// DecideBufferSize: Tell the output pin's allocator what size buffers
// we require. Can only do this when the input is connected
///////////////////////////////////////////////////////////////////////
HRESULT CFLVDecoder::DecideBufferSize(IMemAllocator *pAlloc,
ALLOCATOR_PROPERTIES *pProperties)
{
HRESULT hr;
CheckPointer(pAlloc, E_POINTER);
CheckPointer(pProperties, E_POINTER);
// Ensure a minimum number of buffers
if (pProperties->cBuffers == 0)
{
pProperties->cBuffers = 2;
}
pProperties->cbBuffer = 320*240*4;
ALLOCATOR_PROPERTIES Actual;
hr = pAlloc->SetProperties(pProperties, &Actual);
if (FAILED(hr))
{
return hr;
}
// Is this allocator unsuitable?
if (Actual.cbBuffer < pProperties->cbBuffer)
{
return E_FAIL;
}
return S_OK;
}
///////////////////////////////////////////////////////////////////////
// GetMediaType: I support one type, namely the type of the input pin
// This type is only available if my input is connected
///////////////////////////////////////////////////////////////////////
HRESULT CFLVDecoder::GetMediaType(int iPosition, CMediaType *pMediaType)
{
// Is the input pin connected
if (m_pInput->IsConnected() == FALSE) {
return E_UNEXPECTED;
}
// This should never happen
if (iPosition < 0) {
return E_INVALIDARG;
}
// Do we have more items to offer
if (iPosition > 0) {
return VFW_S_NO_MORE_ITEMS;
}
//pMediaType = m_pInput->CurrentMediaType();
pMediaType->InitMediaType();
//
pMediaType->SetType(& MEDIATYPE_Video) ;
pMediaType->SetSubtype(& MEDIASUBTYPE_RGB32) ;
////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -