Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Jackie Lou

Weird error on Direct Show

This topic is 5935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to create a program that convert an uncompressed .avi file to a compressed one(DV encoder) using a DirectShow. Currently, it does the conversion but only 320x240. So I use IDVEnc interface to specify the resolution(e.g. 720x480), it gives me a weird error during runtime. This is the IDVEnc interface that cases the error during run time: =================================== ((IDVEnc *) pDVEnc)->put_IFormatResolution(DVENCODERVIDEOFORMAT_NTSC,DVENCODERFORMAT_DVSD, DVENCODERRESOLUTION_720x480,false, 0); ==================================== This is the error message: ==================================== "The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention." ==================================== Here is the source code: ===================================== HRESULT AddFilter( IGraphBuilder *pGraph, // Pointer to the Filter Graph Manager. const GUID& clsid, // CLSID of the filter to create. LPCWSTR wszName, // A name for the filter. IBaseFilter **ppF) // Receives a pointer to the filter. { *ppF = 0; IBaseFilter *pF = 0; HRESULT hr = CoCreateInstance(clsid, 0, CLSCTX_INPROC_SERVER, IID_IBaseFilter, reinterpret_cast(&pF)); if (SUCCEEDED(hr)) { hr = pGraph->AddFilter(pF, wszName); if (SUCCEEDED(hr)) *ppF = pF; else pF->Release(); } return hr; } HRESULT GetUnconnectedPin( IBaseFilter *pFilter, // Pointer to the filter. PIN_DIRECTION PinDir, // Direction of the pin to find. IPin **ppPin) // Receives a pointer to the pin. { *ppPin = 0; IEnumPins *pEnum = 0; IPin *pPin = 0; HRESULT hr = pFilter->EnumPins(&pEnum); if (FAILED(hr)) { return hr; } while (pEnum->Next(1, &pPin, NULL) == S_OK) { PIN_DIRECTION ThisPinDir; pPin->QueryDirection(&ThisPinDir); if (ThisPinDir == PinDir) { IPin *pTmp = 0; hr = pPin->ConnectedTo(&pTmp); if (SUCCEEDED(hr)) // Already connected, not the pin we want. { pTmp->Release(); } else // Unconnected, this is the one we want. { pEnum->Release(); *ppPin = pPin; return S_OK; } } pPin->Release(); } pEnum->Release(); // Didn''t find a matching pin. return E_FAIL; } HRESULT ConnectFilters(IGraphBuilder *pGraph, IBaseFilter *pSrc, IBaseFilter *pDest) { IPin *pOut = 0, *pIn = 0; HRESULT hr = GetUnconnectedPin(pSrc, PINDIR_OUTPUT, &pOut); if (FAILED(hr)) { return hr; } hr = GetUnconnectedPin(pDest, PINDIR_INPUT, &pIn); if (FAILED(hr)) { pIn->Release(); return hr; } hr = pGraph->Connect(pOut, pIn); pOut->Release(); pIn->Release(); return hr; } bool StartDVConverter() { HRESULT hr; IGraphBuilder *pGraph; hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void**) (&pGraph)); if (hr != S_OK) return false; ///////////// Convert the char* to wchar_t* wchar_t outputString[1024]; MultiByteToWideChar(CP_ACP,0,(LPCSTR) _outputFilename.GetString(), _outputFilename.GetLength()+1,outputString,256); ///////////// ///////////// Convert the char* to wchar_t* wchar_t inputString[1024]; MultiByteToWideChar(CP_ACP,0,(LPCSTR) _inputFilename.GetString(), _inputFilename.GetLength()+1,inputString,256); IBaseFilter *pSrc = 0, *pMux = 0, *pWriter = 0, *pDVMux = 0, *pDVEnc; if ((hr = pGraph->AddSourceFilter(inputString, L"Source", &pSrc)) != S_OK) return false; if ((hr = AddFilter(pGraph, CLSID_DVVideoEnc, L"DV Video Enc", &pDVEnc)) != S_OK) return false; if ((hr = AddFilter(pGraph, CLSID_DVMux, L"DVMux", &pDVMux)) != S_OK) return false; if ((hr = AddFilter(pGraph, CLSID_AviDest , L"AVI Mux", &pMux)) != S_OK) return false; if ((hr = AddFilter(pGraph, CLSID_FileWriter, L"Writer", &pWriter)) != S_OK) return false; //////////////This is the part of the code that cause error ((IDVEnc *) pDVEnc)->put_IFormatResolution(DVENCODERVIDEOFORMAT_NTSC, DVENCODERFORMAT_DVSD, DVENCODERRESOLUTION_720x480,false, 0); /////////////end of the code that cause error // Initialize the File Writer filter. IFileSinkFilter2 *pSink = 0; hr = pWriter->QueryInterface(IID_IFileSinkFilter2, (void**) (&pSink)); if (hr != S_OK) return false; if ((hr = pSink->SetFileName(outputString, NULL)) != S_OK) return false; if ((hr = pSink->SetMode(AM_FILE_OVERWRITE)) != S_OK) return false; pSink->Release(); // Connect the Async File Source to the DV Splitter. This will // automatically insert the AVI Splitter between them. // (If this call fails, it''s not a type-1 DV file!) if ((hr = ConnectFilters(pGraph, pSrc, pDVEnc)) != S_OK) return false; if ((hr = ConnectFilters(pGraph, pDVEnc, pDVMux)) != S_OK) return false; if ((hr = ConnectFilters(pGraph, pDVMux, pMux)) != S_OK) return false; if ((hr = ConnectFilters(pGraph, pMux, pWriter)) != S_OK) return false; hr = pGraph->QueryInterface(IID_IMediaControl, (void**) &_mediaControl); if (hr != S_OK) { cerr << "7" << endl; WriteErrorMessage (hr); ReleaseObjects(); return false; } cerr hr = _mediaControl->Run(); if (hr != S_OK) return false; _percent = -1; getch (); _mediaControl->Stop(); _mediaControl->Release(); pDVMux->Release(); pDVEnc->Release(); pWriter->Release(); pSrc->Release(); pMux->Release(); pGraph->Release(); return true; } =================================== Any help is greatly appreciated! Jackie

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!