home *** CD-ROM | disk | FTP | other *** search
- //==========================================================================;
- //
- // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
- // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
- // PURPOSE.
- //
- // Copyright (c) 1992 - 1996 Microsoft Corporation. All Rights Reserved.
- //
- //--------------------------------------------------------------------------;
-
- /*
- * Dump Filter - A renderer that dumps its output into a file
- */
-
- #include <windows.h>
- #include <commdlg.h>
- #include <streams.h>
-
- #include <initguid.h>
-
- #include "dumpuids.h"
- #include "dump.h"
-
-
- // setup data
-
- AMOVIESETUP_MEDIATYPE sudPinTypes = { &MEDIATYPE_NULL // clsMajorType
- , &MEDIASUBTYPE_NULL } ; // clsMinorType
-
- AMOVIESETUP_PIN sudPins = { L"Input" // strName
- , FALSE // bRendered
- , FALSE // bOutput
- , FALSE // bZero
- , FALSE // bMany
- , &CLSID_NULL // clsConnectsToFilter
- , L"Output" // strConnectsToPin
- , 1 // nTypes
- , &sudPinTypes } ; // lpTypes
-
-
- AMOVIESETUP_FILTER sudDump = { &CLSID_Dump // clsID
- , L"Dump filter" // strName
- , MERIT_DO_NOT_USE // dwMerit
- , 1 // nPins
- , &sudPins }; // lpPin
-
- //
- // Object creation stuff
- //
-
- CFactoryTemplate g_Templates[]= {L"Dump filter", &CLSID_Dump, CDump::CreateInstance};
- int g_cTemplates = 1;
-
- //
- // Definition of CDumpFilter
- //
-
-
- CDumpFilter::CDumpFilter(CDump *pDump,
- LPUNKNOWN pUnk,
- CCritSec *pLock,
- HRESULT *phr) :
- CBaseFilter(NAME("CDumpFilter"), pUnk, pLock, CLSID_Dump, phr),
- m_pDump(pDump)
- {
- }
-
- CBasePin * CDumpFilter::GetPin(int n)
- {
- if (n == 0) {
- return m_pDump->m_pPin;
- } else {
- return NULL;
- }
- }
-
-
- int CDumpFilter::GetPinCount()
- {
- return 1;
- }
-
- //
- // Definition of CDumpInputPin
- //
-
- CDumpInputPin::CDumpInputPin(CDump *pDump,
- LPUNKNOWN pUnk,
- CBaseFilter *pFilter,
- CCritSec *pLock,
- CCritSec *pReceiveLock,
- HRESULT *phr) :
- CRenderedInputPin(NAME("CDumpInputPin"),
- pFilter, // Filter
- pLock, // Locking
- phr, // Return code
- L"Input"), // Pin name
- m_pReceiveLock(pReceiveLock),
- m_pDump(pDump),
- m_tLast(0)
- {
- }
-
- // check if the pin can support this specific proposed type and format
- HRESULT CDumpInputPin::CheckMediaType(const CMediaType *)
- {
- return S_OK;
- }
-
- // Break a connection
- HRESULT CDumpInputPin::BreakConnect()
- {
- if (m_pDump->m_pPosition != NULL) {
- m_pDump->m_pPosition->ForceRefresh();
- }
- return CBaseInputPin::BreakConnect();
- }
-
- // do something with this media sample
- STDMETHODIMP CDumpInputPin::Receive(IMediaSample *pSample)
- {
- CAutoLock lck(m_pReceiveLock);
- #if 0
- if (m_pFilter->IsStopped()) {
- return VFW_E_WRONG_STATE;
- }
- #endif
-
- REFERENCE_TIME tStart, tStop;
- pSample->GetTime(&tStart, &tStop);
- DbgLog((LOG_TRACE, 1, TEXT("tStart(%s), tStop(%s), Diff(%d ms), Bytes(%d)"),
- (LPCTSTR)CDisp(tStart),
- (LPCTSTR)CDisp(tStop),
- (LONG)((tStart - m_tLast) / 10000),
- pSample->GetActualDataLength()));
- m_tLast = tStart;
-
-
- /* Copy the data to the file */
- PBYTE pbData;
- HRESULT hr = pSample->GetPointer(&pbData);
- if (FAILED(hr)) {
- return hr;
- }
- return m_pDump->Write(pbData, pSample->GetActualDataLength());
- }
-
- STDMETHODIMP CDumpInputPin::EndOfStream(void)
- {
- CAutoLock lck(m_pReceiveLock);
- return CRenderedInputPin::EndOfStream();
- }
-
- STDMETHODIMP CDumpInputPin::NewSegment(
- REFERENCE_TIME tStart,
- REFERENCE_TIME tStop,
- double dRate)
- {
- m_tLast = 0;
- return S_OK;
- }
-
- //
- // CDump class
- //
-
- CDump::CDump(LPUNKNOWN pUnk, HRESULT *phr) :
- CUnknown(NAME("CDump"), pUnk, phr),
- m_pFilter(NULL),
- m_pPin(NULL),
- m_pPosition(NULL),
- m_hFile(INVALID_HANDLE_VALUE),
- m_pFileName(0)
- {
- /* Filter */
- m_pFilter = new CDumpFilter(this, GetOwner(), &m_Lock, phr);
- if (m_pFilter == NULL) {
- *phr = E_OUTOFMEMORY;
- return;
- }
- m_pPin = new CDumpInputPin(this,
- GetOwner(),
- m_pFilter,
- &m_Lock,
- &m_ReceiveLock,
- phr);
- if (m_pPin == NULL) {
- *phr = E_OUTOFMEMORY;
- return;
- }
- }
-
- STDMETHODIMP CDump::SetFileName(LPCOLESTR pszFileName,const AM_MEDIA_TYPE *pmt)
- {
- if(wcslen(pszFileName) > MAX_PATH)
- return ERROR_FILENAME_EXCED_RANGE;
-
- m_pFileName = new WCHAR[1+lstrlenW(pszFileName)];
- if (m_pFileName == 0)
- return E_OUTOFMEMORY;
- lstrcpyW(m_pFileName, pszFileName);
-
- HRESULT hr = S_OK;
-
- # if defined(WIN32) && !defined(UNICODE)
- {
- char bufA[MAX_PATH];
- if(!WideCharToMultiByte(CP_ACP, 0, pszFileName, -1, bufA, MAX_PATH, 0, 0))
- return ERROR_INVALID_NAME;
-
- hr = Open (bufA) ;
-
- }
- # else
- {
- hr = Open (pszFileName, &hr);
- }
- # endif
-
- if(FAILED(hr))
- {
- DbgLog(( LOG_ERROR, 2,
- TEXT("CDump:: Open file failed")));
- return hr;
- }
- return NOERROR ;
-
- }
-
- STDMETHODIMP CDump::GetCurFile(
- LPOLESTR * ppszFileName,
- AM_MEDIA_TYPE *pmt)
- {
- CheckPointer(ppszFileName, E_POINTER);
- *ppszFileName = NULL;
- if (m_pFileName!=NULL)
- {
- *ppszFileName = (LPOLESTR)
- QzTaskMemAlloc(sizeof(WCHAR) * (1+lstrlenW(m_pFileName)));
- if (*ppszFileName!=NULL) {
- lstrcpyW(*ppszFileName, m_pFileName);
- }
- }
-
- if(pmt)
- {
- ZeroMemory(pmt, sizeof(*pmt));
- pmt->majortype = MEDIATYPE_NULL;
- pmt->subtype = MEDIASUBTYPE_NULL;
- }
-
- return S_OK;
- }
-
-
- //
- // GetSetupData
- //
- LPAMOVIESETUP_FILTER CDump::GetSetupData()
- {
- return &sudDump;
- }
-
- CDump::~CDump()
- {
- if (m_hFile != INVALID_HANDLE_VALUE) {
- CloseHandle(m_hFile);
- }
- delete m_pPin;
- delete m_pFilter;
- delete m_pPosition;
- delete m_pFileName;
- }
-
- //
- // CreateInstance
- //
- // Provide the way for COM to create a CDump object
- CUnknown *CDump::CreateInstance(LPUNKNOWN punk, HRESULT *phr) {
-
- CDump *pNewObject = new CDump(punk, phr);
- if (pNewObject == NULL) {
- *phr = E_OUTOFMEMORY;
- }
-
- return pNewObject;
- }
-
-
- // override this to say what interfaces we support where
- STDMETHODIMP CDump::NonDelegatingQueryInterface(REFIID riid, void ** ppv)
- {
- CheckPointer(ppv,E_POINTER);
- CAutoLock lck(&m_Lock);
-
- /* Do we have this interface */
-
- if (riid == IID_IFileSinkFilter)
- {
- return GetInterface((IFileSinkFilter *) this, ppv);
- }
-
- else if (riid == IID_IFilter ||
- riid == IID_IMediaFilter ||
- riid == IID_IPersist) {
- return m_pFilter->NonDelegatingQueryInterface(riid, ppv);
- } else if (riid == IID_IMediaPosition || riid == IID_IMediaSelection) {
- if (m_pPosition == NULL) {
-
- HRESULT hr = S_OK;
- m_pPosition = new CPosPassThru(NAME("CDump CPosPassThru"),
- GetOwner(),
- &hr,
- m_pPin);
- if (m_pPosition == NULL) {
- return E_OUTOFMEMORY;
- }
-
- if (FAILED(hr)) {
- delete m_pPosition;
- m_pPosition = NULL;
- return hr;
- }
- }
- return m_pPosition->NonDelegatingQueryInterface(riid, ppv);
- } else {
- return CUnknown::NonDelegatingQueryInterface(riid, ppv);
- }
- }
-
-
- HRESULT CDump::Open(TCHAR *szFile)
- {
- // Try to open the file
- m_hFile = CreateFile(szFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
- if (m_hFile == INVALID_HANDLE_VALUE) {
- DWORD dwErr = GetLastError();
- return HRESULT_FROM_WIN32(dwErr);
- }
- return S_OK;
- }
-
-
- // Write stuff to the file
- HRESULT CDump::Write(PBYTE pbData, LONG lData)
- {
- DWORD dwWritten;
-
- if (!WriteFile(m_hFile, (PVOID)pbData, (DWORD)lData, &dwWritten, NULL)) {
- DWORD dwErr = GetLastError();
- return HRESULT_FROM_WIN32(dwErr);
- }
- return S_OK;
- }
-
- /******************************Public*Routine******************************\
- * exported entry points for registration and
- * unregistration (in this case they only call
- * through to default implmentations).
- *
- *
- *
- * History:
- *
- \**************************************************************************/
- HRESULT
- DllRegisterServer()
- {
- return AMovieDllRegisterServer();
- }
-
- HRESULT
- DllUnregisterServer()
- {
- return AMovieDllUnregisterServer();
- }
-
-