Hi,
I am using the DirectShow Filter Graph with the ltmm try to play a video streaming file from your video site, but it can only play either video or audio. First, I can play the video (no audio) very well by using below code:
Declaration of the CLSID: static const GUID CLSID_LMNetSrc =
{ 0xE2B7DE03, 0x38C5, 0x11D5, { 0x91, 0xF6, 0x00, 0x10, 0x4B, 0xDB, 0x8F, 0xF9 } };
Code To play the video streaming:
HRESULT Result;
IBaseFilter* pFilterSource = NULL;
IBaseFilter* pFilterDestination = NULL;
IPin* pPinSrc = NULL;
IPin* pPinDst = NULL;
Result = CoCreateInstance(CLSID_LMNetSrc, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**) &pFilterSource);
if (SUCCEEDED(Result) && pFilterSource != NULL)
{
IFileSourceFilter* pFileSource = NULL;
Result = pFilterSource->QueryInterface(IID_IFileSourceFilter, (void**)&pFileSource);
if (pFileSource != NULL)
{
Result = pFileSource->Load(UTF8_To_UTF16(URL).c_str(), NULL);
SafeRelease(pFileSource);
}
Result = mpGraphBuilder->AddFilter(pFilterSource, UTF8_To_UTF16(URL).c_str());
}
std::string Extension(ToLower(GetFileExtension(URL)));
int PinIndex = 0;
while (FindOutputPinByIndex(pFilterSource, PinIndex, &mpPinVideoSource) == S_OK)
//if (FindOutputPinByIndex(pFilterSource, PinIndex, &mpPinVideoSource) == S_OK)
{
bool IsVideo = false;
AM_MEDIA_TYPE* pMediaType = NULL;
IEnumMediaTypes* pEnumMediaTypes = NULL;
mpPinVideoSource->EnumMediaTypes(&pEnumMediaTypes);
if (pEnumMediaTypes != NULL)
{
while (IsVideo == false && pEnumMediaTypes->Next(1, &pMediaType, NULL) == S_OK)
{
if (pMediaType->majortype == MEDIATYPE_Video || pMediaType->majortype == MEDIATYPE_Stream)
{
IsVideo = true;
}
DeleteMediaType(pMediaType);
pMediaType = NULL;
}
}
SafeRelease(pEnumMediaTypes);
if (IsVideo == false)
{
++PinIndex;
SafeRelease(mpPinVideoSource);
}
else
{
break;
}
}
SafeRelease(pFilterSource);
if (mpPinVideoSource != NULL) // && SUCCEEDED(mpPinVideoSource->ConnectedTo(&pPinDst))
{
mpSyncFilter = new c_SyncFilter("Sync Filter", &Result);
mpGraphBuilder->AddFilter(mpSyncFilter, L"Sync Filter");
IPin* pPin = NULL;
if (FindInputPinByIndex(mpSyncFilter, 0, &pPin) == S_OK)
{
Result = mpGraphBuilder->Connect(mpPinVideoSource, pPin);
//SafeRelease(pPin);
if (FindOutputPinByIndex(mpSyncFilter, 0, &pPin) == S_OK)
{
std::swap(mpPinVideoSource, pPin);
SafeRelease(pPin);
}
}
if (FindAudioOutputPinByIndex(mpFilterGraph, 0, &pPinSrc) == S_OK)
{
mpGraphBuilder->Render(pPinSrc);
}
SafeRelease(pPinSrc);
Result = mpGraphBuilder->QueryInterface(&(mpBasicVideo));
Result = mpGraphBuilder->QueryInterface(&(mpMediaControl));
Result = mpGraphBuilder->QueryInterface(&(mpMediaEvent));
Result = mpGraphBuilder->QueryInterface(&(mpMediaSeeking));
Result = mpGraphBuilder->QueryInterface(&(mpMediaEventSink));
Result = mpGraphBuilder->QueryInterface(&(mpMediaPosition));
Result = FindFilterInterfaceByIndex(mpFilterGraph, 0, IID_IQualProp, (void**)&(mpQuality));
Result = FindFilterInterfaceByIndex(mpFilterGraph, 0, IID_IBasicAudio, (void**)&(mpBasicAudio));
IMediaFilter* pMediaFilter = NULL;
mpFilterGraph->QueryInterface(IID_IMediaFilter, (void**)&pMediaFilter);
if (pMediaFilter != NULL)
{
SafeRelease(mpReferenceClock);
mpReferenceClock = GetSystemClock();
if (mpReferenceClock != NULL)
{
pMediaFilter->SetSyncSource(mpReferenceClock);
mSyncFileTime = gpTimeManager->LocalTimeAsFileTime();
mSyncPerformance = gpTimeManager->PerformanceTimeAsInt64();
mpReferenceClock->GetTime(&mSyncReference);
IAMClockAdjust* pClockAdjust = NULL;
mpReferenceClock->QueryInterface(IID_IAMClockAdjust, (void**)&pClockAdjust);
if (pClockAdjust != NULL)
{
SafeRelease(mpClockAdjust);
mpClockAdjust = pClockAdjust;
}
}
else
{
SafeRelease(mpReferenceClock);
pMediaFilter->GetSyncSource(&mpReferenceClock);
}
}
SafeRelease(pMediaFilter);
return true;
}
else
{
return false;
}
When I added the green and red part of code, the audio comes out well, but the video will go bad. So, for now, I can only either play the video or the audio, but not both. This happen even I copy the video file to local drive to play. However, I can always play well with other video files, such as mpeg or wmv, with these code.
Can anyone tell me how to get the video and audio play well together? Any Idea?
Thanks in advance.