BOOL CSampleCGB::HasMediaType(IPin *pPin, REFGUID majorType ) { if(!pPin) { return FALSE; } SmartPtr<IEnumMediaTypes> pMediaTypes; HRESULT hr = pPin->EnumMediaTypes(&pMediaTypes); if(FAILED(hr))return FALSE; hr = pMediaTypes->Reset(); if(FAILED(hr))return FALSE; ULONG cFetched; AM_MEDIA_TYPE* pTempMediaType; while(S_OK == pMediaTypes->Next(1,&pTempMediaType,&cFetched)) { if(::IsEqualGUID(pTempMediaType->majortype,majorType)) { DeleteMediaType(pTempMediaType); return TRUE; } DeleteMediaType(pTempMediaType); } return FALSE; }
BOOL CSampleCGB::IsMPEG2Pin( IPin *pPin ) { if(!pPin)return FALSE; SmartPtr<IEnumMediaTypes> pMediaTypes; HRESULT hr = pPin->EnumMediaTypes(&pMediaTypes); if(FAILED(hr))return FALSE; hr = pMediaTypes->Reset(); if(FAILED(hr))return FALSE; ULONG fetched; AM_MEDIA_TYPE* pTempMediaType; while(S_OK == pMediaTypes->Next(1,&pTempMediaType,&fetched)) { if( ( ::IsEqualGUID(pTempMediaType->majortype,MEDIATYPE_Video) || ::IsEqualGUID(pTempMediaType->majortype,MEDIATYPE_Stream) ) && ( ::IsEqualGUID(pTempMediaType->subtype,MEDIASUBTYPE_MPEG2_VIDEO) || ::IsEqualGUID(pTempMediaType->subtype,MEDIASUBTYPE_MPEG2_PROGRAM) ) ) { DeleteMediaType(pTempMediaType); return TRUE; } DeleteMediaType(pTempMediaType); } return FALSE; }
//----------------------------------------------------------------------------- // GetPin // Find the pin of the specified format type on the given filter // This method leaves an outstanding reference on the pin if successful HRESULT CDSUtils::GetPin(IBaseFilter* pFilter, const GUID* pFormat, PIN_DIRECTION PinDir, IPin** ppPin) { HRESULT hr = S_OK; if (pFilter && pFormat && ppPin) { CComPtr<IEnumPins> pIEnumPins = NULL; hr = pFilter->EnumPins(&pIEnumPins); if (SUCCEEDED(hr)) { // find the pin with the specified format IPin* pIPin = NULL; while (S_OK == pIEnumPins->Next(1, &pIPin, NULL)) { // match the pin direction PIN_DIRECTION pinDir; pIPin->QueryDirection(&pinDir); if (pinDir == PinDir) { // match pin direction check the first media type returned from the upstream pin CComPtr<IEnumMediaTypes> pIEnumMT = NULL; hr = pIPin->EnumMediaTypes(&pIEnumMT); if (SUCCEEDED(hr)) { AM_MEDIA_TYPE* pmt = NULL; hr = pIEnumMT->Next(1, &pmt, NULL); if (S_OK == hr) { if (pmt->majortype == *pFormat) { // found the pin with the specified format *ppPin = pIPin; DeleteMediaType(pmt); break; } else { DeleteMediaType(pmt); } } } } SAFE_RELEASE(pIPin); } if (NULL == *ppPin) { // failed to find the named pin hr = E_FAIL; } } } else { hr = E_INVALIDARG; } return hr; }
STDMETHODIMP CStreamSwitcherFilter::Enable(long lIndex, DWORD dwFlags) { if (dwFlags != AMSTREAMSELECTENABLE_ENABLE) { return E_NOTIMPL; } PauseGraph; bool bFound = false; int i = 0; CStreamSwitcherInputPin* pNewInputPin = nullptr; POSITION pos = m_pInputs.GetHeadPosition(); while (pos && !bFound) { pNewInputPin = m_pInputs.GetNext(pos); if (pNewInputPin->IsConnected()) { if (CComPtr<IAMStreamSelect> pSSF = pNewInputPin->GetStreamSelectionFilter()) { DWORD cStreams = 0; HRESULT hr = pSSF->Count(&cStreams); if (SUCCEEDED(hr)) { for (i = 0; i < (int)cStreams; i++) { AM_MEDIA_TYPE* pmt = nullptr; hr = pSSF->Info(i, &pmt, nullptr, nullptr, NULL, nullptr, nullptr, nullptr); if (SUCCEEDED(hr) && pmt && pmt->majortype == MEDIATYPE_Audio) { if (lIndex == 0) { bFound = true; DeleteMediaType(pmt); break; } else { lIndex--; } } DeleteMediaType(pmt); } } } else if (lIndex == 0) { bFound = true; } else { lIndex--; } } } if (!bFound) { return E_INVALIDARG; } SelectInput(pNewInputPin); if (CComPtr<IAMStreamSelect> pSSF = pNewInputPin->GetStreamSelectionFilter()) { pSSF->Enable(i, dwFlags); } ResumeGraph; return S_OK; }
IPin* FindDecoderSubpictureOutputPin(IBaseFilter* pFilter) { IEnumPins* pEnum = NULL; HRESULT hr = pFilter->EnumPins(&pEnum); if (hr != NOERROR) return NULL; ULONG ulFound; IPin *pPin = NULL; hr = E_FAIL; while(S_OK == pEnum->Next(1, &pPin, &ulFound)) { PIN_INFO PinInfo; // // grab this, so we can examine its name field // hr = pPin->QueryPinInfo(&PinInfo); if(SUCCEEDED(hr)) { PinInfo.pFilter->Release(); // // check direction // if (PinInfo.dir == PINDIR_OUTPUT) { // Make sure its not connected yet and its a video type. IPin* dummyPin = NULL; hr = pPin->ConnectedTo(&dummyPin); SAFE_RELEASE(dummyPin); if (hr == VFW_E_NOT_CONNECTED) { IEnumMediaTypes *mtEnum = NULL; pPin->EnumMediaTypes(&mtEnum); AM_MEDIA_TYPE *pMT = NULL; while (S_OK == mtEnum->Next(1, &pMT, NULL)) { if (pMT->majortype == MEDIATYPE_Video) { DeleteMediaType(pMT); SAFE_RELEASE(mtEnum); SAFE_RELEASE(pEnum); return pPin; } DeleteMediaType(pMT); } SAFE_RELEASE(mtEnum); } } } pPin->Release(); } SAFE_RELEASE(pEnum); return NULL; }
/* 设置捕获图像帧的格式,遍历所有格式是否有预定格式,若没有则以默认格式捕获 */ HRESULT CVMR_Capture::InitVideoWindow(HWND hWnd,int width, int height) { HRESULT hr; RECT rcDest; IAMStreamConfig *pConfig; IEnumMediaTypes *pMedia; AM_MEDIA_TYPE *pmt = NULL, *pfnt = NULL; hr = m_pCamOutPin->EnumMediaTypes( &pMedia ); if(SUCCEEDED(hr)) { //把所有视频的所有格式遍历一遍,看是否有预定的格式 while(pMedia->Next(1, &pmt, 0) == S_OK) { if( pmt->formattype == FORMAT_VideoInfo ) { VIDEOINFOHEADER *vih = (VIDEOINFOHEADER *)pmt->pbFormat; // 当前的格式是否与预定格式相同,即宽和高相同 if( vih->bmiHeader.biWidth == width && vih->bmiHeader.biHeight == height ) { pfnt = pmt; break; } DeleteMediaType( pmt ); } } pMedia->Release(); } hr = m_pCamOutPin->QueryInterface( IID_IAMStreamConfig, (void **) &pConfig ); if(SUCCEEDED(hr)) { // 有预定的格式 if( pfnt != NULL ) { hr=pConfig->SetFormat( pfnt ); DeleteMediaType( pfnt ); } // 没有预定的格式,读取缺省媒体格式 hr = pConfig->GetFormat( &pfnt ); if(SUCCEEDED(hr)) { m_nWidth = ((VIDEOINFOHEADER *)pfnt->pbFormat)->bmiHeader.biWidth; //读取高 m_nHeight = ((VIDEOINFOHEADER *)pfnt->pbFormat)->bmiHeader.biHeight; //读取宽 DeleteMediaType( pfnt ); } } // 获取传入窗口的区域,以设置显示窗口 ::GetClientRect (hWnd,&rcDest); hr = m_pWC->SetVideoPosition(NULL, &rcDest); return hr; }
// // Receive // // Do something with this media sample // STDMETHODIMP CWasapiInputPin::Receive(IMediaSample *pSample) { // DebugPrintf(L"Receive\n"); CAutoLock lock(m_pReceiveLock); CheckPointer(pSample,E_POINTER); bool mediaTypeFailed=false; HRESULT hr = CBaseInputPin::Receive(pSample); if(hr!=S_OK) { DebugPrintf(L"CWasapiInputPin::Receive CBaseInputPin returned error. %d \n",hr); goto exit; } CMediaType* mediaType=NULL; hr=pSample->GetMediaType((AM_MEDIA_TYPE**)&mediaType); if(hr==S_OK) { hr = CBasePin::SetMediaType(mediaType); DeleteMediaType(mediaType); } hr= m_pManager->SampleReceived(pSample); if(hr==S_FALSE) //Media type rejected by Wasapi engine { DebugPrintf(L"CWasapiInputPin::Receive returning EC_ERRORABORT. \n"); CBasePin::EndOfStream(); m_pFilter->NotifyEvent(EC_ERRORABORT,NULL,NULL); goto exit; } exit: return hr; }
void DeviceSource::SetAudioInfo(AM_MEDIA_TYPE *audioMediaType, GUID &expectedAudioType) { expectedAudioType = audioMediaType->subtype; if(audioMediaType->formattype == FORMAT_WaveFormatEx) { WAVEFORMATEX *pFormat = reinterpret_cast<WAVEFORMATEX*>(audioMediaType->pbFormat); mcpy(&audioFormat, pFormat, sizeof(audioFormat)); Log(TEXT(" device audio info - bits per sample: %u, channels: %u, samples per sec: %u, block size: %u"), audioFormat.wBitsPerSample, audioFormat.nChannels, audioFormat.nSamplesPerSec, audioFormat.nBlockAlign); //avoid local resampling if possible /*if(pFormat->nSamplesPerSec != 44100) { pFormat->nSamplesPerSec = 44100; if(SUCCEEDED(audioConfig->SetFormat(audioMediaType))) { Log(TEXT(" also successfully set samples per sec to 44.1k")); audioFormat.nSamplesPerSec = 44100; } }*/ } else { AppWarning(TEXT("DShowAudioPlugin: Audio format was not a normal wave format")); soundOutputType = 0; } DeleteMediaType(audioMediaType); }
STDMETHODIMP CMediaSample::SetMediaType(AM_MEDIA_TYPE *pMediaType) { /* Delete the current media type */ if (m_pMediaType) { DeleteMediaType(m_pMediaType); m_pMediaType = NULL; } /* Mechanism for resetting the format type */ if (pMediaType == NULL) { m_dwFlags &= ~Sample_TypeChanged; return NOERROR; } ASSERT(pMediaType); ValidateReadPtr(pMediaType,sizeof(AM_MEDIA_TYPE)); /* Take a copy of the media type */ m_pMediaType = CreateMediaType(pMediaType); if (m_pMediaType == NULL) { m_dwFlags &= ~Sample_TypeChanged; return E_OUTOFMEMORY; } m_dwFlags |= Sample_TypeChanged; return NOERROR; }
HRESULT CBaseVideoFilter::Receive(IMediaSample* pIn) { #ifndef _WIN64 // TODOX64 : fixme! _mm_empty(); // just for safety #endif CAutoLock cAutoLock(&m_csReceive); HRESULT hr; AM_SAMPLE2_PROPERTIES* const pProps = m_pInput->SampleProps(); if (pProps->dwStreamId != AM_STREAM_MEDIA) { return m_pOutput->Deliver(pIn); } AM_MEDIA_TYPE* pmt; if (SUCCEEDED(pIn->GetMediaType(&pmt)) && pmt) { CMediaType mt(*pmt); m_pInput->SetMediaType(&mt); DeleteMediaType(pmt); } if (FAILED(hr = Transform(pIn))) { return hr; } return S_OK; }
HRESULT CBaseVideoFilter::GetDeliveryBuffer(int w, int h, IMediaSample** ppOut) { CheckPointer(ppOut, E_POINTER); HRESULT hr; if (FAILED(hr = ReconnectOutput(w, h))) { return hr; } if (FAILED(hr = m_pOutput->GetDeliveryBuffer(ppOut, NULL, NULL, 0))) { return hr; } AM_MEDIA_TYPE* pmt; if (SUCCEEDED((*ppOut)->GetMediaType(&pmt)) && pmt) { CMediaType mt = *pmt; m_pOutput->SetMediaType(&mt); DeleteMediaType(pmt); } (*ppOut)->SetDiscontinuity(FALSE); (*ppOut)->SetSyncPoint(TRUE); // FIXME: hell knows why but without this the overlay mixer starts very skippy // (don't enable this for other renderers, the old for example will go crazy if you do) if (GetCLSID(m_pOutput->GetConnected()) == CLSID_OverlayMixer) { (*ppOut)->SetDiscontinuity(TRUE); } return S_OK; }
STDMETHODIMP CStreamSwitcherFilter::Count(DWORD* pcStreams) { if (!pcStreams) { return E_POINTER; } CAutoLock cAutoLock(&m_csPins); *pcStreams = 0; POSITION pos = m_pInputs.GetHeadPosition(); while (pos) { CStreamSwitcherInputPin* pInputPin = m_pInputs.GetNext(pos); if (pInputPin->IsConnected()) { if (CComPtr<IAMStreamSelect> pSSF = pInputPin->GetStreamSelectionFilter()) { DWORD cStreams = 0; HRESULT hr = pSSF->Count(&cStreams); if (SUCCEEDED(hr)) { for (int i = 0; i < (int)cStreams; i++) { AM_MEDIA_TYPE* pmt = nullptr; hr = pSSF->Info(i, &pmt, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (SUCCEEDED(hr) && pmt && pmt->majortype == MEDIATYPE_Audio) { (*pcStreams)++; } DeleteMediaType(pmt); } } } else { (*pcStreams)++; } } } return S_OK; }
STDMETHODIMP TffdshowEncDshow::getDstBuffer(IMediaSample* *pOut, const TffPict &pict) { *pOut = NULL; BYTE *data; HRESULT hr; if (FAILED(hr = getDeliveryBuffer(pOut, &data))) { return hr; } if (pict.rtStart == REFTIME_INVALID || pict.rtStop == REFTIME_INVALID) { REFERENCE_TIME tStart = (params.framenum) * inpin->avgTimePerFrame; REFERENCE_TIME tStop = (params.framenum + 1) * inpin->avgTimePerFrame; setPropsTime(*pOut, tStart, tStop, m_pInput->SampleProps(), &m_bSampleSkipped); //DPRINTF("tStart:%i, tStop:%i, AVIfps:%i",int(tStart),int(tStop),timePerFrame); } else { (*pOut)->SetTime((REFERENCE_TIME*)&pict.rtStart, (REFERENCE_TIME*)&pict.rtStop); } AM_MEDIA_TYPE *mtOut; (*pOut)->GetMediaType(&mtOut); if (mtOut != NULL) { HRESULT result = S_OK; DeleteMediaType(mtOut); if (result != S_OK) { return result; } } return S_OK; }
CMediaSample::~CMediaSample() { if (m_pMediaType) { DeleteMediaType(m_pMediaType); } }
HRESULT CStreamSwitcherOutputPin::GetMediaType(int iPosition, CMediaType* pmt) { CStreamSwitcherInputPin* pIn = (static_cast<CStreamSwitcherFilter*>(m_pFilter))->GetInputPin(); if (!pIn || !pIn->IsConnected()) { return E_UNEXPECTED; } CComPtr<IEnumMediaTypes> pEM; if (FAILED(pIn->GetConnected()->EnumMediaTypes(&pEM))) { return VFW_S_NO_MORE_ITEMS; } if (iPosition > 0 && FAILED(pEM->Skip(iPosition))) { return VFW_S_NO_MORE_ITEMS; } AM_MEDIA_TYPE* tmp = nullptr; if (S_OK != pEM->Next(1, &tmp, nullptr) || !tmp) { return VFW_S_NO_MORE_ITEMS; } CopyMediaType(pmt, tmp); DeleteMediaType(tmp); /* if (iPosition < 0) return E_INVALIDARG; if (iPosition > 0) return VFW_S_NO_MORE_ITEMS; CopyMediaType(pmt, &pIn->CurrentMediaType()); */ return S_OK; }
void VideoCapture::EnumResolutions() { int iCount, iSize, iChosen=-1; IBaseFilter *pSource; CComPtr <ICaptureGraphBuilder2> pCaptB; VIDEO_STREAM_CONFIG_CAPS caps; HRESULT hr; bool response; IAMStreamConfig *pConfig; devices_resolutions = new DeviceResolutions[nDevices]; pCaptB.CoCreateInstance(CLSID_CaptureGraphBuilder2); for (unsigned int iDevice=0; iDevice<nDevices; iDevice++) { response = BindFilter(iDevice, &pSource); hr = pCaptB->FindInterface( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pSource, IID_IAMStreamConfig, (void**)&pConfig); if (!SUCCEEDED(hr)) { pSource->Release(); devices_resolutions[iDevice].nResolutions = 0; continue; } pConfig->GetNumberOfCapabilities(&iCount, &iSize); devices_resolutions[iDevice].SetNResolutions(iCount); for(int i=0; i < iCount; i++) { AM_MEDIA_TYPE *pmt; if( pConfig->GetStreamCaps(i, &pmt, reinterpret_cast<BYTE*>(&caps)) == S_OK ) { VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(pmt->pbFormat); devices_resolutions[iDevice].x[i] = caps.InputSize.cx; devices_resolutions[iDevice].y[i] = caps.InputSize.cy; devices_resolutions[iDevice].color_space[i] = pmt->subtype; devices_resolutions[iDevice].compression[i] = pVih->bmiHeader.biCompression; DeleteMediaType(pmt); } } pSource->Release(); pConfig->Release(); pSource = 0; } }
HRESULT CDeCSSFilter::Transform(IMediaSample* pIn, IMediaSample* pOut) { AM_MEDIA_TYPE* pmt; if (SUCCEEDED(pIn->GetMediaType(&pmt)) && pmt) { CMediaType mt = *pmt; m_pInput->SetMediaType(&mt); mt.majortype = m_pOutput->CurrentMediaType().majortype; m_pOutput->SetMediaType(&mt); pOut->SetMediaType(&mt); DeleteMediaType(pmt); } BYTE* pDataIn = NULL; BYTE* pDataOut = NULL; pIn->GetPointer(&pDataIn); pOut->GetPointer(&pDataOut); long len = pIn->GetActualDataLength(); long size = pOut->GetSize(); if (len == 0 || pDataIn == NULL) { // format changes do not carry any data pOut->SetActualDataLength(0); return S_OK; } if (m_pOutput->CurrentMediaType().majortype == MEDIATYPE_MPEG2_PES) { if (*(DWORD*)pDataIn == 0xBA010000) { len -= 14; pDataIn += 14; if (int stuffing = (pDataIn[-1] & 7)) { len -= stuffing; pDataIn += stuffing; } } if (len <= 0) { return S_FALSE; } if (*(DWORD*)pDataIn == 0xBB010000) { len -= 4; pDataIn += 4; int hdrlen = ((pDataIn[0] << 8) | pDataIn[1]) + 2; len -= hdrlen; pDataIn += hdrlen; } if (len <= 0) { return S_FALSE; } } if (!pDataIn || !pDataOut || len > size || len < 0) { return S_FALSE; } memcpy(pDataOut, pDataIn, min(len, size)); pOut->SetActualDataLength(min(len, size)); return S_OK; }
// Format negotiation HRESULT CTimeStretchFilter::NegotiateFormat(const WAVEFORMATEXTENSIBLE* pwfx, int nApplyChangesDepth, ChannelOrder* pChOrder) { if (!pwfx) return VFW_E_TYPE_NOT_ACCEPTED; #ifdef INTEGER_SAMPLES // only accept 16bit int if (pwfx->Format.wBitsPerSample != 16 || pwfx->SubFormat != KSDATAFORMAT_SUBTYPE_PCM) return VFW_E_TYPE_NOT_ACCEPTED; #else // only accept 32bit float if (pwfx->Format.wBitsPerSample != 32 || pwfx->SubFormat != KSDATAFORMAT_SUBTYPE_IEEE_FLOAT) return VFW_E_TYPE_NOT_ACCEPTED; #endif if (FormatsEqual(pwfx, m_pInputFormat)) { *pChOrder = m_chOrder; return S_OK; } bool bApplyChanges = (nApplyChangesDepth != 0); if (nApplyChangesDepth != INFINITE && nApplyChangesDepth > 0) nApplyChangesDepth--; HRESULT hr = m_pNextSink->NegotiateFormat(pwfx, nApplyChangesDepth, pChOrder); if (FAILED(hr)) return hr; hr = VFW_E_CANNOT_CONNECT; if (!pwfx) return SetFormat(NULL); if (bApplyChanges) { LogWaveFormat(pwfx, "TS - applying "); AM_MEDIA_TYPE tmp; HRESULT result = CreateAudioMediaType((WAVEFORMATEX*)pwfx, &tmp, true); if (SUCCEEDED(result)) { if (m_pMediaType) DeleteMediaType(m_pMediaType); m_pMediaType = CreateMediaType(&tmp); } SetInputFormat(pwfx); SetOutputFormat(pwfx); SetFormat(pwfx); } else LogWaveFormat(pwfx, "TS - "); m_chOrder = *pChOrder; return S_OK; }
HRESULT CTimeStretchFilter::CheckSample(IMediaSample* pSample) { if (!pSample) return S_OK; AM_MEDIA_TYPE *pmt = NULL; bool bFormatChanged = false; HRESULT hr = S_OK; if (SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt) bFormatChanged = !FormatsEqual((WAVEFORMATEXTENSIBLE*)pmt->pbFormat, m_pInputFormat); if (bFormatChanged) { uint unprocessedSamplesBefore = numUnprocessedSamples(); uint zeros = flushEx(); uint unprocessedSamplesAfter = numUnprocessedSamples(); UINT32 outFramesAfter = numSamples(); UINT32 totalSamples = zeros + unprocessedSamplesBefore; UINT32 totalProcessedSamples = totalSamples - unprocessedSamplesAfter; //double bias = (double)totalProcessedSamples / (double)outFramesAfter; REFERENCE_TIME estimatedSampleDuration = totalProcessedSamples * UNITS / m_pOutputFormat->Format.nSamplesPerSec; double bias = m_pClock->GetBias(); double adjustment = m_pClock->Adjustment(); double AVMult = m_pClock->SuggestedAudioMultiplier(estimatedSampleDuration, bias, adjustment); setTempoInternal(AVMult, 1.0); CreateOutput(totalProcessedSamples, outFramesAfter, bias, adjustment, AVMult, true); // Empty SoundTouch's buffers clear(); // Apply format change ChannelOrder chOrder; hr = NegotiateFormat((WAVEFORMATEXTENSIBLE*)pmt->pbFormat, 1, &chOrder); pSample->SetDiscontinuity(false); if (FAILED(hr)) { DeleteMediaType(pmt); Log("CTimeStretchFilter::CheckFormat failed to change format: 0x%08x", hr); return hr; } else { m_chOrder = chOrder; return S_FALSE; // format changed } } return S_OK; }
// // Loop through every media type supported by this pin // to see if there is one which can be considered MPEG2 // BOOL ISampleCaptureGraphBuilder::IsMPEG2Pin( IPin *pPin ) { if( !pPin ) { return FALSE; // NULL pointer } SmartPtr<IEnumMediaTypes> pMediaTypes; HRESULT hr = pPin->EnumMediaTypes( &pMediaTypes ); if( FAILED( hr ) ) { return FALSE; } hr = pMediaTypes->Reset(); if( FAILED( hr ) ) { return FALSE; } ULONG fetched; AM_MEDIA_TYPE *mediaType; while( S_OK == pMediaTypes->Next( 1, &mediaType, &fetched ) ) { if( ( ::IsEqualGUID( mediaType->majortype, MEDIATYPE_Video ) || ::IsEqualGUID( mediaType->majortype, MEDIATYPE_Stream ) ) && ( ::IsEqualGUID( mediaType->subtype, MEDIASUBTYPE_MPEG2_VIDEO ) || ::IsEqualGUID( mediaType->subtype, MEDIASUBTYPE_MPEG2_PROGRAM ) ) ) { DeleteMediaType( mediaType ); return TRUE; } DeleteMediaType( mediaType ); } return FALSE; }
void CCaptureDevice::SetCaptureBufferSize(void) { IPin * pCapturePin = GetPin(); if (pCapturePin) { DWORD dwBytesPerSec = 0; AM_MEDIA_TYPE * pmt = {0}; IAMStreamConfig * pCfg = NULL; HRESULT hr = pCapturePin->QueryInterface(IID_IAMStreamConfig, (void **)&pCfg); if ( hr==S_OK ) { hr = pCfg->GetFormat(&pmt); if ( hr==S_OK ) { WAVEFORMATEX *pWF = (WAVEFORMATEX *) pmt->pbFormat; dwBytesPerSec = pWF->nAvgBytesPerSec; pWF->nChannels = 1; pWF->wBitsPerSample = 8; pWF->nSamplesPerSec = 11025; pWF->nAvgBytesPerSec = pWF->nSamplesPerSec * pWF->nChannels * pWF->wBitsPerSample / 8; pWF->nBlockAlign = 1; /* info.cbSize = sizeof(WAVEFORMATEX); info.wFormatTag = 1; info.nChannels = 2; info.nSamplesPerSec = 44100; //info.nSamplesPerSec = 22050; 11025 info.wBitsPerSample = 16; info.nAvgBytesPerSec = info.nSamplesPerSec * info.nChannels * info.wBitsPerSample / 8; info.nBlockAlign = 4; */ pCfg->SetFormat( pmt ); DeleteMediaType(pmt); } pCfg->Release(); } /* if (dwBytesPerSec) { IAMBufferNegotiation * pNeg = NULL; hr = pCapturePin->QueryInterface(IID_IAMBufferNegotiation, (void **)&pNeg); if (SUCCEEDED(hr)) { ALLOCATOR_PROPERTIES AllocProp; AllocProp.cbAlign = -1; // -1 means no preference. AllocProp.cbBuffer = dwBytesPerSec * dwLatencyInMilliseconds / 1000; AllocProp.cbPrefix = -1; AllocProp.cBuffers = -1; hr = pNeg->SuggestAllocatorProperties(&AllocProp); pNeg->Release(); } }*/ } }
CClip::~CClip(void) { CAutoLock vectorVLock(&m_sectionVectorVideo); CAutoLock vectorALock(&m_sectionVectorAudio); FlushAudio(); FlushVideo(); DeleteMediaType(m_videoPmt); if (m_pSparseVideoPacket) delete m_pSparseVideoPacket; m_pSparseVideoPacket = NULL; }
STDMETHODIMP TffdshowVideoInputPin::Receive(IMediaSample* pSample) { AM_MEDIA_TYPE *pmt = NULL; if (SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt) { CAutoLock lock2(&m_csCodecs_and_imgFilters); CMediaType mt(*pmt); SetMediaType(&mt); allocator.mtChanged = false; DeleteMediaType(pmt); } return TinputPin::Receive(pSample); }
CTimeStretchFilter::~CTimeStretchFilter(void) { Log("CTimeStretchFilter - destructor - instance 0x%x", this); SetEvent(m_hStopThreadEvent); WaitForSingleObject(m_hThread, INFINITE); CAutoLock lock(&m_csResources); SetFormat(NULL); DeleteMediaType(m_pMediaType); Log("CTimeStretchFilter - destructor - instance 0x%x - end", this); }
HRESULT CWASAPIRenderFilter::CheckSample(IMediaSample* pSample, UINT32 framesToFlush) { if (!pSample) return S_OK; AM_MEDIA_TYPE *pmt = NULL; bool bFormatChanged = false; HRESULT hr = S_OK; if (SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt) bFormatChanged = !FormatsEqual((WAVEFORMATEXTENSIBLE*)pmt->pbFormat, m_pInputFormat); if (bFormatChanged) { // Release outstanding buffer hr = m_pRenderClient->ReleaseBuffer(framesToFlush, 0); if (FAILED(hr)) Log("CWASAPIRenderFilter::CheckFormat - ReleaseBuffer: 0x%08x", hr); // Apply format change ChannelOrder chOrder; hr = NegotiateFormat((WAVEFORMATEXTENSIBLE*)pmt->pbFormat, 1, &chOrder); pSample->SetDiscontinuity(false); if (FAILED(hr)) { DeleteMediaType(pmt); Log("CWASAPIRenderFilter::CheckFormat failed to change format: 0x%08x", hr); return hr; } else { m_chOrder = chOrder; return S_FALSE; } } else if (pSample->IsDiscontinuity() == S_OK) { hr = m_pRenderClient->ReleaseBuffer(framesToFlush, 0); if (FAILED(hr)) Log("CWASAPIRenderFilter::CheckFormat - discontinuity - ReleaseBuffer: 0x%08x", hr); pSample->SetDiscontinuity(false); m_nSampleNum = 0; return S_FALSE; } return S_OK; }
HRESULT CTimeStretchFilter::CheckSample(IMediaSample* pSample, REFERENCE_TIME* rtDrained) { if (!pSample) return S_OK; AM_MEDIA_TYPE *pmt = NULL; bool bFormatChanged = false; HRESULT hr = S_OK; if (SUCCEEDED(pSample->GetMediaType(&pmt)) && pmt) bFormatChanged = !FormatsEqual((WAVEFORMATEXTENSIBLE*)pmt->pbFormat, m_pInputFormat); if (bFormatChanged) { REFERENCE_TIME rtStart = 0; REFERENCE_TIME rtStop = 0; HRESULT hr = pSample->GetTime(&rtStart, &rtStop); if (SUCCEEDED(hr)) { Log("CTimeStretchFilter - CheckSample - resyncing in middle of stream on format change - rtStart: %6.3f m_rtInSampleTime: %6.3f", rtStart / 10000000.0, m_rtInSampleTime / 10000000.0); *rtDrained = DrainBuffers(pSample, rtStart); } else Log("CTimeStretchFilter::CheckFormat failed to get timestamps from sample: 0x%08x", hr); // Apply format change ChannelOrder chOrder; hr = NegotiateFormat((WAVEFORMATEXTENSIBLE*)pmt->pbFormat, 1, &chOrder); pSample->SetDiscontinuity(false); if (FAILED(hr)) { DeleteMediaType(pmt); Log("CTimeStretchFilter::CheckFormat failed to change format: 0x%08x", hr); return hr; } else { m_chOrder = chOrder; return S_FALSE; // format changed } } return S_OK; }
static HRESULT WINAPI VfwPin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum) { VfwPinImpl *This = impl_from_IPin(iface); AM_MEDIA_TYPE *pmt; HRESULT hr; hr = qcap_driver_get_format(This->parent->driver_info, &pmt); if (SUCCEEDED(hr)) { hr = BasePinImpl_EnumMediaTypes(iface, ppEnum); DeleteMediaType(pmt); } TRACE("%p -- %x\n", This, hr); return hr; }
static ULONG WINAPI QTOutPin_Release(IPin *iface) { QTOutPin *This = impl_QTOutPin_from_IPin(iface); ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount); TRACE("(%p)->() Release from %d\n", iface, refCount + 1); if (!refCount) { DeleteMediaType(This->pmt); FreeMediaType(&This->pin.pin.mtCurrent); CoTaskMemFree(This); return 0; } return refCount; }
BOOL ISampleCaptureGraphBuilder::HasMediaType(IPin *pPin, REFGUID majorType ) { if( !pPin ) { return FALSE; } SmartPtr<IEnumMediaTypes> pMediaTypes; HRESULT hr = pPin->EnumMediaTypes( &pMediaTypes ); if( FAILED( hr ) ) { return FALSE; } hr = pMediaTypes->Reset(); if( FAILED( hr ) ) { return FALSE; } ULONG fetched; AM_MEDIA_TYPE *mediaType; while( S_OK == pMediaTypes->Next( 1, &mediaType, &fetched ) ) { if( ::IsEqualGUID( mediaType->majortype, majorType ) ) { DeleteMediaType( mediaType ); return TRUE; } DeleteMediaType( mediaType ); } return FALSE; }
/// Make destination an identical copy of source HRESULT DShowIMediaSampleCopy(IMediaSample *pSource, IMediaSample *pDest, bool bCopyData) { CheckPointer(pSource, E_POINTER); CheckPointer(pDest, E_POINTER); if (bCopyData) { // Copy the sample data BYTE *pSourceBuffer, *pDestBuffer; long lSourceSize = pSource->GetActualDataLength(); #ifdef DEBUG long lDestSize = pDest->GetSize(); ASSERT(lDestSize >= lSourceSize); #endif pSource->GetPointer(&pSourceBuffer); pDest->GetPointer(&pDestBuffer); CopyMemory((PVOID) pDestBuffer,(PVOID) pSourceBuffer, lSourceSize); } // Copy the sample times REFERENCE_TIME TimeStart, TimeEnd; if(NOERROR == pSource->GetTime(&TimeStart, &TimeEnd)) { pDest->SetTime(&TimeStart, &TimeEnd); } LONGLONG MediaStart, MediaEnd; if(pSource->GetMediaTime(&MediaStart,&MediaEnd) == NOERROR) { pDest->SetMediaTime(&MediaStart,&MediaEnd); } // Copy the media type AM_MEDIA_TYPE *pMediaType; pSource->GetMediaType(&pMediaType); pDest->SetMediaType(pMediaType); DeleteMediaType(pMediaType); // Copy the actual data length long lDataLength = pSource->GetActualDataLength(); pDest->SetActualDataLength(lDataLength); return NOERROR; }