请帮助我解决以下问题 [英] Please help me in the following problem

查看:85
本文介绍了请帮助我解决以下问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 [ ^ ]

它将文件作为输入并播放包含h264数据的文件,即NAL单元,因此不是发送文件路径,而是解析文件并将nal单元转换为数组并给出数组而不是文件路径,

但文件没玩....

请帮帮我



他们正在做的代码

HRESULT hr = m_pPlayer-> AddClip(ofn.lpstrFile,& pClip);

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



剩余代码相同我提到我的代码失败,如果我给buffer


Rest code is same i have mentioned where my code fails if i give the buffer

推荐答案

如果你从某个地方下载代码,该网站就可以询问它是如何工作的。
If you downloaded code from somewhere, that site is the place to ask how it works.


不,它不会工作/播放。您正在向方法AddClip传递错误的参数。



此方法的第一个参数是''FileName''而不是缓冲区。这意味着在方法AddClip中,它将执行文件加载操作,并且通过传递缓冲区,它无法找到文件,因此无法执行该方法。你需要传递fileName而不是文件的内容。



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



上述方法的第一个参数必须是文件名而不是文件内容。

查看MSDN文档以获取 AddSourceFilter API [ ^ ]


这篇关于请帮助我解决以下问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆