Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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;
}


C++
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);

C++
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
C++
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
Updated 1-Jan-13 21:38pm
v2
Comments
Jibesh 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 2-Jan-13 3:19am    
sir it says cannot add clip format not support
Jibesh 2-Jan-13 3:28am    
so its obvious that that application has no support for clip files. try running with supporting files?
Tarun Batra 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 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.

If you downloaded code from somewhere, that site is the place to ask how it works.
 
Share this answer
 
Comments
Tarun Batra 2-Jan-13 3:18am    
ya but there i found no place to ask so i tried here
Christian Graus 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 ?
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[^]
 
Share this answer
 
v2
Comments
Tarun Batra 2-Jan-13 4:35am    
What to do to make it work....plz suggest
Jibesh 2-Jan-13 4:50am    
pass the file name. this is what AddClip method expects.
Tarun Batra 2-Jan-13 5:04am    
Sir this is what i was trying to change that rather than passing file name pass the buffer
Jibesh 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 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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900