I downloaded a project named GMF bridge and play from the link
[
^]
It takes the file as input and plays it the file contain the h264 data i.e. the NAL units so instead of sending the file path i parsed the file and takes the nal unit into an array and give the array instead of file path,
But the file doesn't play....
Please help me
code that they are doing
HRESULT hr = m_pPlayer->AddClip(ofn.lpstrFile, &pClip);
ClipPlayer::AddClip(const char* path, ClipEntry** ppClip)
{
list<ClipEntry>::iterator it = m_Clips.insert(m_Clips.end(), ClipEntry());
ClipEntry* pClip = &(*it);
*ppClip = pClip;
HRESULT hr = pClip->Create(m_pController, path);
if ((hr == VFW_E_UNSUPPORTED_AUDIO) && (m_Clips.size() == 1))
{
m_pController.CreateInstance(__uuidof(GMFBridgeController));
m_pController->SetNotify(long(m_hwndApp), long(m_msgSegment));
m_pController->AddStream(true, eUncompressed, false);
m_pController->SetBufferMinimum(200);
hr = pClip->Create(m_pController, path);
}
if (SUCCEEDED(hr))
{
pClip->SetStartPosition(m_tDuration);
m_tDuration += pClip->Duration();
if (m_Clips.size() == 1)
{
m_pRenderGraph.CreateInstance(CLSID_FilterGraph);
hr = m_pController->CreateRenderGraph(pClip->SinkFilter(), m_pRenderGraph, &m_pRenderGraphSourceFilter);
if (SUCCEEDED(hr) && IsWindow(m_hwndApp))
{
IMediaEventExPtr pME = m_pRenderGraph;
if (pME != NULL)
{
pME->SetNotifyWindow(OAHWND(m_hwndApp), m_msgEvent, NULL);
}
}
}
} else {
m_Clips.erase(--m_Clips.end());
}
return hr;
}
ClipEntry::Create(IGMFBridgeController* pController, const char* path)
{
m_bPrimed = false;
m_pGraph.CreateInstance(CLSID_FilterGraph);
_bstr_t bstr = path;
HRESULT hr = pController->CreateSourceGraph(bstr, m_pGraph, &m_pSinkFilter);
STDMETHODIMP
BridgeController::CreateSourceGraph(BSTR strFile, IUnknown* pUnkGraph, IUnknown **pSinkFilter)
{
CAutoLock lock(&m_csBridge);
IUnknownPtr pUnkSink;
HRESULT hr = InsertSinkFilter(pUnkGraph, &pUnkSink);
IBridgeSinkPtr pSink = pUnkSink;
if (FAILED(hr) || (pSink == NULL))
{
return hr;
}
IGraphBuilderPtr pGraph = pUnkGraph;
if (pGraph == NULL)
{
return E_INVALIDARG;
}
IBaseFilterPtr pFile;
hr = pGraph->AddSourceFilter(strFile, strFile, &pFile);
if (FAILED(hr))
{
return hr;
}
for (int n = 0; n < StreamCount(); n++)
{
const GUID* pElemType;
if (m_Streams[n].IsVideo())
{
pElemType = &MEDIATYPE_Video;
} else
{
pElemType = &MEDIATYPE_Audio;
}
IPinPtr pOut;
bool bPinIsStream = true;
if (n == 0)
{
hr = FindUnconnectedPin(pFile, &pOut, PINDIR_OUTPUT, &MEDIATYPE_Stream);
if (FAILED(hr))
{
bPinIsStream = false;
hr = FindUnconnectedPin(pFile, &pOut, PINDIR_OUTPUT, pElemType);
if (FAILED(hr))
{
return hr;
}
}
} else
{
bPinIsStream = false;
hr = FindStreamSource(pFile, pElemType, &pOut);
if (hr != S_OK)
{
return VFW_E_UNSUPPORTED_AUDIO;
}
}
BridgeSinkInput* pPin;
hr = pSink->GetBridgePin(n, &pPin);
if (SUCCEEDED(hr))
{
hr = pGraph->Connect(pOut, pPin);
if (FAILED(hr))
{
hr = pGraph->Render(pOut);
if (SUCCEEDED(hr) && bPinIsStream)
{
break;
}
}
}
if (FAILED(hr))
{
return hr;
}
}
for (int n = 0; n < StreamCount(); n++)
{
BridgeSinkInput* pPin;
hr = pSink->GetBridgePin(n, &pPin);
if (SUCCEEDED(hr))
{
if (!pPin->IsConnected())
{
return E_INVALIDARG;
}
}
}
*pSinkFilter = pUnkSink.Detach();
return S_OK;
}
What am i doing is
char* path=ofn.lpstrFile;
FILE* infile;
infile= fopen(path, "rb");
if (infile == NULL) { fprintf( stderr, "!! Error: could not open file: %s \n", strerror(errno)); exit(EXIT_FAILURE); }
size_t rsz = 0;
long lSize;
char * buffer;
size_t result;
fseek (infile , 0 , SEEK_END);
lSize = ftell (infile);
rewind (infile);
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL)
{fputs ("Memory error",stderr); exit (2);}
result = fread (buffer,1,lSize,infile);
HRESULT hr = m_pPlayer->AddClip(buffer, &pClip);
Rest code is same i have mentioned where my code fails if i give the buffer