各位老大给我看看
我仿照FilterQQSource,写了个读取TS(MPEG2)流的Push模式的Source filter,在GraPhEdit中能成功连接上:
MediaSent.mpg->MPEG-2 Demultiplexer
但是播放的时候,怎么也看不到图像。刚刚研究Dshow,搞了好久还是没能解决问题。。希望各位能给点建议或者意见啊。。万分感谢。
这是我的部分代码:
CTSOutPin::CTSOutPin(HRESULT *phr, CFilterTSSource * pFilter, LPCWSTR pPinName) :
CSourceStream(NAME("MPEG2 TS Stream"), phr, pFilter, pPinName)
{
mFilter = pFilter;
m_fp = NULL;
strcpy(mFilePath, "");
mPreferred.InitMediaType();
mPreferred.SetType(&MEDIATYPE_Stream);
mPreferred.SetSubtype(&MEDIASUBTYPE_MPEG2_TRANSPORT);
mSampleCount = 0;
}
HRESULT CTSOutPin::FillBuffer(IMediaSample * pSample)
{
CAutoLock lck(&mSharedState);
BYTE * pData = NULL;
pSample->GetPointer(&pData);
long bytes = fread(pData, 1, SAMPLE_SIZE, m_fp);
if (bytes < SAMPLE_SIZE && feof(m_fp))
{
return S_FALSE;
}
pSample->SetActualDataLength(bytes);
pSample->SetSyncPoint(FALSE);
LONGLONG start = mSampleCount++;
LONGLONG stop = mSampleCount;
pSample->SetMediaTime(&start, &stop);
return S_OK;
}
HRESULT CTSOutPin::DecideBufferSize(IMemAllocator *pAlloc,
ALLOCATOR_PROPERTIES *pProperties)
{
CAutoLock lck(m_pFilter->pStateLock());
ASSERT(pAlloc);
ASSERT(pProperties);
HRESULT hr = NOERROR;
pProperties->cBuffers = 1;
pProperties->cbBuffer = SAMPLE_SIZE;
ASSERT(pProperties->cbBuffer);
ALLOCATOR_PROPERTIES Actual;
hr = pAlloc->SetProperties(pProperties, &Actual);
if (FAILED(hr))
{
return hr;
}
if (Actual.cbBuffer < pProperties->cbBuffer)
{
return E_FAIL;
}
ASSERT( Actual.cBuffers == 1 );
return NOERROR;
}
HRESULT CTSOutPin::CheckMediaType(const CMediaType * inMediatype)
{
CAutoLock lck(m_pFilter->pStateLock());
if (inMediatype->majortype == MEDIATYPE_Stream &&
inMediatype->subtype == MEDIASUBTYPE_MPEG2_TRANSPORT)
{
return NOERROR;
}
return E_FAIL;
}
HRESULT CTSOutPin::GetMediaType(int iPosition, CMediaType *pmt)
{
CAutoLock lck(m_pFilter->pStateLock());
if (iPosition != 0)
{
return E_FAIL;
}
*pmt = mPreferred;
return NOERROR;
}
BOOL CTSOutPin::SetFileSource(const char * inFile)
{
CAutoLock lck(&mSharedState);
strcpy(mFilePath, inFile);
if (m_fp)
{
fclose(m_fp);
m_fp = NULL;
}
m_fp = fopen(mFilePath, "rb");
return (m_fp != NULL);
}
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
一般文件格式都不适合做实时流传输,AVI更不行,他没有时间戳标记,数据丢失了很难音视频同步,而且索引一般放在文件最后,一般需要读索引来定位每一包。推模式的filter基本没有。非要做的话就要自己写了。AVI的解析代码还是很多的。
H.264本来就是一种视频数据,何来音频之说。不知道LZ接收的是什么文件格式的数据。