Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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;
	/*path="a.264";*/
	HRESULT hr = pClip->Create(m_pController, path);
 
	// if we expect both audio and video, then all clips
	// must have both audio and video. 
	// If the first clip is video only, then switch
	// to video-only automatically
	if ((hr == VFW_E_UNSUPPORTED_AUDIO) && (m_Clips.size() == 1))
	{
		// new controller, different options (only one video stream)
		m_pController.CreateInstance(__uuidof(GMFBridgeController));
		m_pController->SetNotify(long(m_hwndApp), long(m_msgSegment));
		m_pController->AddStream(true, eUncompressed, false);
		m_pController->SetBufferMinimum(200);
 
		// try again
		hr = pClip->Create(m_pController, path);
	}
 
	if (SUCCEEDED(hr))
	{
		pClip->SetStartPosition(m_tDuration);
		m_tDuration += pClip->Duration();
 
		// if this is the first clip, create the render graph
		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);
 
    // add the sink filter first
    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;
    }
 
    // render using AddSourceFilter and Connect, not Render so that
    // we don't get unwanted renderers for streams that we are not using

    IBaseFilterPtr pFile;
	 
    hr = pGraph->AddSourceFilter(strFile, strFile, &pFile);//if i give buffer my code fail here
    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)
        {
            // start with source filter for first pin
            // -- expect the source to expose a muxed type
            hr = FindUnconnectedPin(pFile, &pOut, PINDIR_OUTPUT, &MEDIATYPE_Stream);
            if (FAILED(hr))
            {
                // try unmuxed type
                bPinIsStream = false;
                hr = FindUnconnectedPin(pFile, &pOut, PINDIR_OUTPUT, pElemType);
                if (FAILED(hr))
                {
                    return hr;
                }
            }
        } else
        {
            // for subsequent pins, track downstream to find the unconnected
            // output (probably on splitter)
            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 we've used render on the stream pin, we've done all the elementary streams
                // at the same time
                if (SUCCEEDED(hr) && bPinIsStream)
                {
                    break;
                }
            }
        }
        if (FAILED(hr))
        {
            return hr;
        }
    }
 

    // check all pins were connected
    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;
	//byte buffer;
    size_t result;
 
	
	fseek (infile , 0 , SEEK_END);
   lSize = ftell (infile);
   rewind (infile);
   buffer = (char*) malloc (sizeof(char)*lSize);
   //buffer = (byte) malloc (sizeof(char)*lSize);
  if (buffer == NULL)
  {fputs ("Memory error",stderr); exit (2);}
 
  // copy the file into the buffer:
  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
Posted 1-Jan-13 20:56pm
Edited 1-Jan-13 21:38pm
v2
Comments
jibesh at 2-Jan-13 3:14am
   
you need to explain the real problem you are having.exception message or error code etc? file doesnt play can have many reasons. you need to debug the code and see what went wrong. without problem details we cannot provide a solution.
Tarun Batra at 2-Jan-13 3:19am
   
sir it says cannot add clip format not support
jibesh at 2-Jan-13 3:28am
   
so its obvious that that application has no support for clip files. try running with supporting files?
Tarun Batra at 2-Jan-13 3:30am
   
sir i am using the same file which it plays but now instead of giving the file path i am giving the array name which contain the data
jibesh at 2-Jan-13 3:32am
   
ok in that case can you copy paste the code that you tried. use the Improve Question link at the bottom right corner of your question to edit your query.
Tarun Batra at 2-Jan-13 3:38am
   
updated the code
Tarun Batra at 2-Jan-13 3:32am
   
i am reading the file into the buffer using fread and giving the buffer name instead of file name
jibesh at 2-Jan-13 3:45am
   
No it wont work. because you are confusing the method AddClip with a wrong input. check my solution for more details about the failure reason. though your code compiled successfully you are doing a wrong assumption.
jibesh at 2-Jan-13 3:55am
   
btw why you are passing buffer where you have the option to pass file name?
Tarun Batra at 2-Jan-13 4:41am
   
What to do to make it work....plz suggest
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you downloaded code from somewhere, that site is the place to ask how it works.
  Permalink  
Comments
Tarun Batra at 2-Jan-13 3:18am
   
ya but there i found no place to ask so i tried here
Christian Graus at 2-Jan-13 3:19am
   
We have no clue. You posted no code. Most of us have not used that library. How can we help, based on that ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

No it wont work/play. You are passing a wrong arguments to the method AddClip.
 
The first argument to this method is a 'FileName' and not the buffer. which means inside the method 'AddClip' it will be performing a file load operation and by passing a buffer it failed to locate the file and hence failed to execute the method. you need to pass the fileName and not the content of the file.
 
 hr = pGraph->AddSourceFilter(strFile, strFile, &pFile);//if i give buffer my code fail here
The first parameter to the above method must be a file name and not the file content.
Check the MSDN Document for AddSourceFilter API[^]
  Permalink  
v2
Comments
Tarun Batra at 2-Jan-13 4:35am
   
What to do to make it work....plz suggest
jibesh at 2-Jan-13 4:50am
   
pass the file name. this is what AddClip method expects.
Tarun Batra at 2-Jan-13 5:04am
   
Sir this is what i was trying to change that rather than passing file name pass the buffer
jibesh at 2-Jan-13 5:12am
   
look at the documentation of the AddSourceFilter API. its expecting a FileName and not file content. you cannot change it.
 
http://msdn.microsoft.com/en-us/library/windows/desktop/dd390087(v=vs.85).aspx
Tarun Batra at 2-Jan-13 5:14am
   
is there any other api or function on which i can give the buffer as data rather than the file
jibesh at 2-Jan-13 5:17am
   
I wonder why you do the extra work where its already taken care by Framework codes. just curious to know why you go for buffer?
Tarun Batra at 2-Jan-13 5:20am
   
sir i have a program that receive the network encrypted network stream decrypt it and save it in a buffer thats the reason i want to use the buffer and the buffer contain NAL unit can u give me some sample that take NAL unit as input
jibesh at 2-Jan-13 5:23am
   
Sorry I havent used that before, if it was the case you can save the buffer as a file in your application folder or temp path and pass the file name to this API, delete the file once you are done with the file. have you tried that?
Tarun Batra at 2-Jan-13 5:27am
   
sir the problem how can that be done at run time i mean at the same time we will be writing to file and reading from file

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CHill60 360
1 OriginalGriff 203
2 Sarvesh Kumar Gupta 168
3 RyanDev 145
4 Peter Leow 145


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid