HRESULT HDMediaSource::SetRate(BOOL fThin,float flRate) { DbgLogPrintf(L"%s::SetRate... (Thin:%d, Rate:%.2f)",L"HDMediaSource",fThin,flRate); CritSec::AutoLock lock(_cs); HRESULT hr = CheckShutdown(); if (FAILED(hr)) return hr; if (fThin) return MF_E_THINNING_UNSUPPORTED; if (flRate < MIN_MFSOURCE_RATE_SUPPORT || flRate > MAX_MFSOURCE_RATE_SUPPORT) return MF_E_UNSUPPORTED_RATE; if (flRate == _currentRate) return _pEventQueue->QueueEventParamVar(MESourceRateChanged,GUID_NULL,S_OK,nullptr); ComPtr<SourceOperation> op; hr = SourceOperation::CreateSetRateOperation(fThin,flRate,op.GetAddressOf()); if (FAILED(hr)) return hr; DbgLogPrintf(L"%s::SetRate OK.",L"HDMediaSource"); return QueueOperation(op.Get()); }
IFACEMETHODIMP CGeometricMediaSource::SetRate(BOOL fThin, float flRate) { if (fThin) { return MF_E_THINNING_UNSUPPORTED; } if (!IsRateSupported(flRate, &flRate)) { return MF_E_UNSUPPORTED_RATE; } AutoLock lock(_critSec); HRESULT hr = S_OK; if (flRate == _flRate) { return S_OK; } ComPtr<CSourceOperation> spSetRateOp; spSetRateOp.Attach(new CSetRateOperation(fThin, flRate)); if (!spSetRateOp) { hr = E_OUTOFMEMORY; } if (SUCCEEDED(hr)) { // Queue asynchronous stop hr = QueueOperation(spSetRateOp.Get()); } return hr; }
HRESULT HDMediaSource::Start(IMFPresentationDescriptor *pPresentationDescriptor,const GUID *pguidTimeFormat,const PROPVARIANT *pvarStartPosition) { DbgLogPrintf(L"%s::Start...",L"HDMediaSource"); if (pPresentationDescriptor == nullptr || pvarStartPosition == nullptr) return E_INVALIDARG; if ((pguidTimeFormat != nullptr) && (*pguidTimeFormat != GUID_NULL)) return MF_E_UNSUPPORTED_TIME_FORMAT; //只支持100ns if (pvarStartPosition->vt != VT_I8 && pvarStartPosition->vt != VT_EMPTY) return MF_E_UNSUPPORTED_TIME_FORMAT; CritSec::AutoLock lock(_cs); HRESULT hr = CheckShutdown(); if (FAILED(hr)) return hr; hr = IsInitialized(); if (FAILED(hr)) return hr; hr = ValidatePresentationDescriptor(pPresentationDescriptor); if (FAILED(hr)) return hr; if (_state == STATE_STARTED) DbgLogPrintf(L"%s::was already started.",L"HDMediaSource"); ComPtr<SourceOperation> op; hr = SourceOperation::CreateStartOperation( pPresentationDescriptor, _start_op_seek_time, op.GetAddressOf()); if (FAILED(hr)) return hr; _start_op_seek_time = PACKET_NO_PTS; hr = op->SetData(*pvarStartPosition); if (FAILED(hr)) return hr; DbgLogPrintf(L"%s::Start OK.",L"HDMediaSource"); _enterReadPacketFlag = false; _network_buffering = false; return QueueOperation(op.Get()); }
IFACEMETHODIMP CGeometricMediaSource::Stop() { HRESULT hr = S_OK; ComPtr<CSourceOperation> spStopOp; spStopOp.Attach(new(std::nothrow) CSourceOperation(CSourceOperation::Operation_Stop)); if (!spStopOp) { hr = E_OUTOFMEMORY; } if (SUCCEEDED(hr)) { // Queue asynchronous stop hr = QueueOperation(spStopOp.Get()); } return hr; }
IFACEMETHODIMP CGeometricMediaSource::Start( IMFPresentationDescriptor *pPresentationDescriptor, const GUID *pguidTimeFormat, const PROPVARIANT *pvarStartPos ) { HRESULT hr = S_OK; // Check parameters. // Start position and presentation descriptor cannot be nullptr. if (pvarStartPos == nullptr || pPresentationDescriptor == nullptr) { return E_INVALIDARG; } // Check the time format. if ((pguidTimeFormat != nullptr) && (*pguidTimeFormat != GUID_NULL)) { // Unrecognized time format GUID. return MF_E_UNSUPPORTED_TIME_FORMAT; } // Check the data type of the start position. if (pvarStartPos->vt != VT_EMPTY && pvarStartPos->vt != VT_I8) { return MF_E_UNSUPPORTED_TIME_FORMAT; } AutoLock lock(_critSec); ComPtr<CStartOperation> spStartOp; if (_eSourceState != SourceState_Stopped && _eSourceState != SourceState_Started) { hr = MF_E_INVALIDREQUEST; } if (SUCCEEDED(hr)) { // Check if the presentation description is valid. hr = ValidatePresentationDescriptor(pPresentationDescriptor); } if (SUCCEEDED(hr)) { // Prepare asynchronous operation attributes spStartOp = new(std::nothrow) CStartOperation(pPresentationDescriptor); if (!spStartOp) { hr = E_OUTOFMEMORY; } if (SUCCEEDED(hr)) { hr = spStartOp->SetData(*pvarStartPos); } } if (SUCCEEDED(hr)) { // Queue asynchronous operation hr = QueueOperation(spStartOp.Get()); } return hr; }