2022-02-24 17:57:08 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2023-03-25 08:37:51 +08:00
|
|
|
// WmfMediaEngine.cpp : Playback helper class.
|
2022-02-24 17:57:08 +08:00
|
|
|
//
|
|
|
|
// 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) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
#include "WmfMediaEngine.h"
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
|
|
|
|
|
|
|
|
# include <Shlwapi.h>
|
|
|
|
# include "MFUtils.h"
|
|
|
|
|
|
|
|
# include "ntcvt/ntcvt.hpp"
|
|
|
|
# include "yasio/detail/sz.hpp"
|
|
|
|
|
|
|
|
NS_AX_BEGIN
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
// IF_FAILED_GOTO macro.
|
|
|
|
// Jumps to 'label' on failure.
|
2023-03-25 08:37:51 +08:00
|
|
|
# ifndef IF_FAILED_GOTO
|
|
|
|
# define IF_FAILED_GOTO(hr, label) \
|
|
|
|
if (FAILED(hr)) \
|
|
|
|
{ \
|
|
|
|
goto label; \
|
|
|
|
}
|
|
|
|
# endif
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
# define CHECK_HR(hr) IF_FAILED_GOTO(hr, done)
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
// const UINT WM_APP_PLAYER_EVENT = ::RegisterWindowMessageW(L"mfmedia-event");
|
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// static MFOffset MakeOffset(float v)
|
|
|
|
//{
|
|
|
|
// // v = offset.value + (offset.fract / denominator), where denominator = 65536.0f.
|
|
|
|
// const int denominator = std::numeric_limits<WORD>::max() + 1;
|
|
|
|
// MFOffset offset;
|
|
|
|
// offset.value = short(v);
|
|
|
|
// offset.fract = WORD(denominator * (v - offset.value));
|
|
|
|
// return offset;
|
|
|
|
// }
|
|
|
|
|
2022-02-24 17:57:08 +08:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Name: CreateSourceStreamNode
|
|
|
|
// Description: Creates a source-stream node for a stream.
|
|
|
|
//
|
|
|
|
// pSource: Pointer to the media source that contains the stream.
|
|
|
|
// pSourcePD: Presentation descriptor for the media source.
|
|
|
|
// pSourceSD: Stream descriptor for the stream.
|
|
|
|
// ppNode: Receives a pointer to the new node.
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
static HRESULT CreateSourceStreamNode(IMFMediaSource* pSource,
|
|
|
|
IMFPresentationDescriptor* pSourcePD,
|
|
|
|
IMFStreamDescriptor* pSourceSD,
|
|
|
|
IMFTopologyNode** ppNode)
|
|
|
|
{
|
|
|
|
if (!pSource || !pSourcePD || !pSourceSD || !ppNode)
|
|
|
|
{
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
TComPtr<IMFTopologyNode> SourceNode;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
// Create the source-stream node.
|
|
|
|
CHECK_HR(hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, &SourceNode));
|
|
|
|
|
|
|
|
// Set attribute: Pointer to the media source.
|
|
|
|
CHECK_HR(hr = SourceNode->SetUnknown(MF_TOPONODE_SOURCE, pSource));
|
|
|
|
|
|
|
|
// Set attribute: Pointer to the presentation descriptor.
|
|
|
|
CHECK_HR(hr = SourceNode->SetUnknown(MF_TOPONODE_PRESENTATION_DESCRIPTOR, pSourcePD));
|
|
|
|
|
|
|
|
// Set attribute: Pointer to the stream descriptor.
|
|
|
|
CHECK_HR(hr = SourceNode->SetUnknown(MF_TOPONODE_STREAM_DESCRIPTOR, pSourceSD));
|
|
|
|
|
|
|
|
// Return the IMFTopologyNode pointer to the caller.
|
|
|
|
*ppNode = SourceNode.Get();
|
|
|
|
(*ppNode)->AddRef();
|
|
|
|
|
|
|
|
done:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a callback object for the MF video sample grabber sink.
|
|
|
|
*/
|
|
|
|
class MFVideoSampler : public IMFSampleGrabberSinkCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Default constructor. */
|
2023-03-25 08:37:51 +08:00
|
|
|
MFVideoSampler(WmfMediaEngine* owner) : RefCount(1), Owner(owner) {}
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
//~ IMFSampleGrabberSinkCallback interface
|
|
|
|
|
|
|
|
STDMETHODIMP OnClockPause(MFTIME SystemTime) { return S_OK; }
|
|
|
|
|
|
|
|
STDMETHODIMP OnClockRestart(MFTIME SystemTime) { return S_OK; }
|
|
|
|
|
|
|
|
STDMETHODIMP OnClockSetRate(MFTIME SystemTime, float flRate) { return S_OK; }
|
|
|
|
|
|
|
|
STDMETHODIMP OnClockStart(MFTIME SystemTime, LONGLONG llClockStartOffset) { return S_OK; }
|
|
|
|
|
|
|
|
STDMETHODIMP OnClockStop(MFTIME SystemTime) { return S_OK; }
|
|
|
|
|
|
|
|
STDMETHODIMP OnProcessSample(REFGUID MajorMediaType,
|
|
|
|
DWORD SampleFlags,
|
|
|
|
LONGLONG SampleTime,
|
|
|
|
LONGLONG SampleDuration,
|
|
|
|
const BYTE* SampleBuffer,
|
|
|
|
DWORD SampleSize)
|
|
|
|
{
|
2023-03-25 08:37:51 +08:00
|
|
|
Owner->HandleVideoSample(SampleBuffer, SampleSize);
|
2022-02-24 17:57:08 +08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP OnSetPresentationClock(IMFPresentationClock* Clock) { return S_OK; }
|
|
|
|
|
|
|
|
STDMETHODIMP OnShutdown() { return S_OK; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
//~ IUnknown interface
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) AddRef() { return InterlockedIncrement(&RefCount); }
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
# if _MSC_VER == 1900
|
|
|
|
# pragma warning(push)
|
|
|
|
# pragma warning(disable : 4838)
|
|
|
|
# endif
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
STDMETHODIMP QueryInterface(REFIID RefID, void** Object)
|
|
|
|
{
|
|
|
|
static const QITAB QITab[] = {QITABENT(MFVideoSampler, IMFSampleGrabberSinkCallback), {0}};
|
|
|
|
|
|
|
|
return QISearch(this, QITab, RefID, Object);
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
# if _MSC_VER == 1900
|
|
|
|
# pragma warning(pop)
|
|
|
|
# endif
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) Release()
|
|
|
|
{
|
|
|
|
auto CurrentRefCount = InterlockedDecrement(&RefCount);
|
|
|
|
|
|
|
|
if (CurrentRefCount == 0)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CurrentRefCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/** Hidden destructor (this class is reference counted). */
|
|
|
|
virtual ~MFVideoSampler() { assert(RefCount == 0); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
/** Holds a reference counter for this instance. */
|
|
|
|
long RefCount;
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
WmfMediaEngine* Owner; // weak ref to owner
|
2022-02-24 17:57:08 +08:00
|
|
|
};
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
# if 0
|
2022-02-24 17:57:08 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: CreateInstance
|
2023-03-25 08:37:51 +08:00
|
|
|
// Description: Static class method to create the WmfMediaEngine object.
|
2022-02-24 17:57:08 +08:00
|
|
|
//
|
|
|
|
// hVideo: Handle to the video window.
|
|
|
|
// hEvent: Handle to the window to receive notifications.
|
2023-03-25 08:37:51 +08:00
|
|
|
// ppPlayer: Receives an AddRef's pointer to the WmfMediaEngine object.
|
2022-02-24 17:57:08 +08:00
|
|
|
// The caller must release the pointer.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::CreateInstance(WmfMediaEngine** ppPlayer)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE((L"WmfMediaEngine::Create\n"));
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
if (ppPlayer == NULL)
|
|
|
|
{
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
auto pPlayer = new WmfMediaEngine();
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
if (pPlayer == NULL)
|
|
|
|
{
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = pPlayer->Initialize();
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
*ppPlayer = pPlayer;
|
|
|
|
else
|
|
|
|
pPlayer->Release();
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2023-03-25 08:37:51 +08:00
|
|
|
# endif
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
2023-03-25 08:37:51 +08:00
|
|
|
// WmfMediaEngine constructor
|
2022-02-24 17:57:08 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
WmfMediaEngine::WmfMediaEngine()
|
|
|
|
: m_nRefCount(1)
|
2022-02-24 17:57:08 +08:00
|
|
|
{}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
2023-03-25 08:37:51 +08:00
|
|
|
// WmfMediaEngine destructor
|
2022-02-24 17:57:08 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
WmfMediaEngine::~WmfMediaEngine()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
assert(m_pSession == NULL); // If FALSE, the app did not call Shutdown().
|
|
|
|
|
|
|
|
// Note: The application must call Shutdown() because the media
|
2023-03-25 08:37:51 +08:00
|
|
|
// session holds a reference count on the WmfMediaEngine object. (This happens
|
|
|
|
// when WmfMediaEngine calls IMediaEventGenerator::BeginGetEvent on the
|
2022-02-24 17:57:08 +08:00
|
|
|
// media session.) As a result, there is a circular reference count
|
2023-03-25 08:37:51 +08:00
|
|
|
// between the WmfMediaEngine object and the media session. Calling Shutdown()
|
2022-02-24 17:57:08 +08:00
|
|
|
// breaks the circular reference count.
|
|
|
|
|
|
|
|
// Note: If CreateInstance failed, the application will not call
|
|
|
|
// Shutdown(). To handle that case, we must call Shutdown() in the
|
|
|
|
// destructor. The circular ref-count problem does not occcur if
|
|
|
|
// CreateInstance has failed. Also, calling Shutdown() twice is
|
|
|
|
// harmless.
|
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
ClearPendingFrames();
|
|
|
|
|
2022-02-24 17:57:08 +08:00
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: Initialize
|
2023-03-25 08:37:51 +08:00
|
|
|
// Initializes the WmfMediaEngine object. This method is called by the
|
2022-02-24 17:57:08 +08:00
|
|
|
// CreateInstance method.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::Initialize()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (m_hCloseEvent)
|
|
|
|
{
|
|
|
|
return MF_E_ALREADY_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start up Media Foundation platform.
|
2023-03-25 08:37:51 +08:00
|
|
|
CHECK_HR(hr = MFUtils::InitializeMFOnce());
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
m_hOpenEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
|
|
if (m_hOpenEvent == NULL)
|
|
|
|
{
|
|
|
|
CHECK_HR(hr = HRESULT_FROM_WIN32(GetLastError()));
|
|
|
|
}
|
|
|
|
|
2022-02-24 17:57:08 +08:00
|
|
|
m_hCloseEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
|
|
|
if (m_hCloseEvent == NULL)
|
|
|
|
{
|
|
|
|
CHECK_HR(hr = HRESULT_FROM_WIN32(GetLastError()));
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// AddRef
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
ULONG WmfMediaEngine::AddRef()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
return InterlockedIncrement(&m_nRefCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Release
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
ULONG WmfMediaEngine::Release()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
ULONG uCount = InterlockedDecrement(&m_nRefCount);
|
|
|
|
if (uCount == 0)
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
// For thread safety, return a temporary variable.
|
|
|
|
return uCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// QueryInterface
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::QueryInterface(REFIID iid, void** ppv)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
if (!ppv)
|
|
|
|
{
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
if (iid == IID_IUnknown)
|
|
|
|
{
|
|
|
|
*ppv = static_cast<IUnknown*>(this);
|
|
|
|
}
|
|
|
|
else if (iid == IID_IMFAsyncCallback)
|
|
|
|
{
|
|
|
|
*ppv = static_cast<IMFAsyncCallback*>(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: OpenURL
|
|
|
|
// Description: Opens a URL for playback.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
bool WmfMediaEngine::Open(std::string_view sourceUri)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
Close();
|
|
|
|
|
|
|
|
if (sourceUri.empty())
|
|
|
|
return false;
|
2023-03-25 08:37:51 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("WmfMediaEngine::OpenURL\n");
|
|
|
|
AXME_TRACE("URL = %s\n", sourceUri.data());
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
// 1. Create a new media session.
|
|
|
|
// 2. Create the media source.
|
|
|
|
// 3. Create the topology.
|
|
|
|
// 4. Queue the topology [asynchronous]
|
|
|
|
// 5. Start playback [asynchronous - does not happen in this method.]
|
|
|
|
|
|
|
|
// Create the media session.
|
2023-04-02 01:51:36 +08:00
|
|
|
if (FAILED(CreateSession()))
|
|
|
|
return false;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// Set our state to "open pending"
|
|
|
|
m_state = MEMediaState::Preparing;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
TComPtr<IUnknown> sharedFromThis;
|
|
|
|
this->QueryInterface(IID_IUnknown, &sharedFromThis);
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
m_bOpenPending = true;
|
|
|
|
std::thread t([this, sharedFromThis, wsourceUri = ntcvt::from_chars(sourceUri)] {
|
|
|
|
TComPtr<IMFTopology> pTopology;
|
|
|
|
TComPtr<IMFClock> pClock;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Create the media source.
|
|
|
|
DX::ThrowIfFailed(CreateMediaSource(wsourceUri.c_str()));
|
|
|
|
if (!m_pSession)
|
|
|
|
DX::ThrowIfFailed(E_POINTER);
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// Create a partial topology.
|
|
|
|
DX::ThrowIfFailed(CreateTopologyFromSource(&pTopology));
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// Set the topology on the media session.
|
|
|
|
DX::ThrowIfFailed(m_pSession->SetTopology(0, pTopology.Get()));
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// If SetTopology succeeded, the media session will queue an
|
|
|
|
// MESessionTopologySet event.
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// ======> Read media properties
|
|
|
|
// Get the session capabilities.
|
|
|
|
DX::ThrowIfFailed(m_pSession->GetSessionCapabilities(&m_caps));
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// Get the duration from the presentation descriptor (optional)
|
|
|
|
(void)m_PresentDescriptor->GetUINT64(MF_PD_DURATION, (UINT64*)&m_hnsDuration);
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// Get the presentation clock (optional)
|
|
|
|
auto hr = m_pSession->GetClock(&pClock);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
DX::ThrowIfFailed(hr = pClock->QueryInterface(IID_PPV_ARGS(&m_pClock)));
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// Get the rate control interface (optional)
|
|
|
|
DX::ThrowIfFailed(MFGetService(m_pSession.Get(), MF_RATE_CONTROL_SERVICE, IID_PPV_ARGS(&m_RateControl)));
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
DX::ThrowIfFailed(MFGetService(m_pSession.Get(), MF_RATE_CONTROL_SERVICE, IID_PPV_ARGS(&m_RateSupport)));
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// Check if rate 0 (scrubbing) is supported.
|
|
|
|
if (SUCCEEDED(m_RateSupport->IsRateSupported(TRUE, 0, NULL)))
|
|
|
|
m_bCanScrub = TRUE;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// if m_pRate is NULL, m_bCanScrub must be FALSE.
|
|
|
|
assert(m_RateControl || !m_bCanScrub);
|
|
|
|
}
|
|
|
|
catch (const std::exception& ex)
|
|
|
|
{
|
|
|
|
AXME_TRACE("Exception occurred when Open Media: %s", ex.what());
|
|
|
|
m_state = MEMediaState::Error;
|
|
|
|
}
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
m_bOpenPending = false;
|
|
|
|
SetEvent(m_hOpenEvent);
|
|
|
|
});
|
|
|
|
t.detach();
|
|
|
|
|
|
|
|
return false;
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
bool WmfMediaEngine::Close()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
if (m_bOpenPending)
|
|
|
|
WaitForSingleObject(m_hOpenEvent, INFINITE);
|
|
|
|
|
|
|
|
ClearPendingFrames();
|
|
|
|
|
2022-02-24 17:57:08 +08:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
auto state = GetState();
|
2023-03-25 08:37:51 +08:00
|
|
|
if (state != MEMediaState::Closing && state != MEMediaState::Closed)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
Stop();
|
|
|
|
hr = CloseSession();
|
|
|
|
}
|
2023-03-25 08:37:51 +08:00
|
|
|
return SUCCEEDED(hr);
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: Invoke
|
|
|
|
// Description: Callback for asynchronous BeginGetEvent method.
|
|
|
|
//
|
|
|
|
// pAsyncResult: Pointer to the result.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::Invoke(IMFAsyncResult* pResult)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
::MediaEventType meType = MEUnknown; // Event type
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
TComPtr<IMFMediaEvent> pEvent;
|
|
|
|
|
|
|
|
// Get the event from the event queue.
|
|
|
|
CHECK_HR(hr = m_pSession->EndGetEvent(pResult, &pEvent));
|
|
|
|
|
|
|
|
// Get the event type.
|
|
|
|
CHECK_HR(hr = pEvent->GetType(&meType));
|
|
|
|
|
|
|
|
// If the session is closed, the application is waiting on the
|
|
|
|
// m_hCloseEvent event handle. Also, do not get any more
|
|
|
|
// events from the session.
|
|
|
|
|
|
|
|
if (meType == MESessionClosed)
|
|
|
|
{
|
|
|
|
SetEvent(m_hCloseEvent);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// For all other events, ask the media session for the
|
|
|
|
// next event in the queue.
|
|
|
|
CHECK_HR(hr = m_pSession->BeginGetEvent(this, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
// For most events, we post the event as a private window message to the
|
|
|
|
// application. This lets the application process the event on it's
|
|
|
|
// main thread.
|
|
|
|
|
|
|
|
// However, if call to IMFMediaSession::Close is pending, it means the
|
|
|
|
// application is waiting on the m_hCloseEvent event handle. (Blocking
|
|
|
|
// call.) In that case, we simply discard the event.
|
|
|
|
|
|
|
|
// NOTE: When IMFMediaSession::Close is called, MESessionClosed is NOT
|
|
|
|
// necessarily the next event that we will receive. We may receive
|
|
|
|
// any number of other events before receiving MESessionClosed.
|
2023-03-25 08:37:51 +08:00
|
|
|
if (m_state != MEMediaState::Closing)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2022-11-14 11:35:38 +08:00
|
|
|
HandleEvent(pEvent.Get());
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
// if (!m_hwndEvent)
|
|
|
|
// HandleEvent((WPARAM)pEvent.Get());
|
2022-05-07 20:21:22 +08:00
|
|
|
// else
|
2022-02-24 17:57:08 +08:00
|
|
|
// PostMessage(m_hwndEvent, WM_APP_PLAYER_EVENT, (WPARAM)pEvent.Get(), (LPARAM)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
// SAFE_RELEASE(pEvent);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
void WmfMediaEngine::HandleVideoSample(const uint8_t* buf, size_t len)
|
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
std::unique_lock<std::mutex> lck(m_framesQueueMtx);
|
|
|
|
m_framesQueue.emplace_back(buf, buf + len);
|
2023-03-25 08:37:51 +08:00
|
|
|
}
|
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
void WmfMediaEngine::ClearPendingFrames()
|
2023-03-25 08:37:51 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
std::unique_lock<std::mutex> lck(m_framesQueueMtx);
|
|
|
|
m_framesQueue.clear();
|
|
|
|
}
|
2023-03-25 08:37:51 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
bool WmfMediaEngine::TransferVideoFrame(std::function<void(const MEVideoFrame&)> callback)
|
|
|
|
{
|
|
|
|
if (m_state != MEMediaState::Playing || m_framesQueue.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> lck(m_framesQueueMtx);
|
|
|
|
if (!m_framesQueue.empty())
|
|
|
|
{
|
|
|
|
auto buffer = std::move(m_framesQueue.front());
|
|
|
|
m_framesQueue.pop_front();
|
|
|
|
lck.unlock(); // unlock immidiately before invoke user callback (maybe upload buffer to GPU)
|
|
|
|
|
|
|
|
auto cbcrData =
|
|
|
|
(m_videoPF == MEVideoPixelFormat::NV12) ? buffer.data() + m_frameExtent.x * m_frameExtent.y : nullptr;
|
|
|
|
MEVideoFrame frame{buffer.data(), cbcrData, buffer.size(),
|
|
|
|
MEVideoPixelDesc{m_videoPF, MEIntPoint{m_frameExtent.x, m_frameExtent.y}}, m_videoExtent};
|
|
|
|
# if defined(_DEBUG)
|
|
|
|
switch (m_videoPF)
|
2023-03-25 08:37:51 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
case MEVideoPixelFormat::YUY2:
|
|
|
|
assert(m_frameExtent.x == m_bIsH264 ? YASIO_SZ_ALIGN(m_frameExtent.x, 16) : m_frameExtent.x);
|
2023-03-25 08:37:51 +08:00
|
|
|
break;
|
2023-04-02 01:51:36 +08:00
|
|
|
case MEVideoPixelFormat::NV12:
|
|
|
|
{
|
|
|
|
// HEVC(H265) on Windows, both height width align 32
|
|
|
|
// refer to: https://community.intel.com/t5/Media-Intel-oneAPI-Video/32-byte-alignment-for-HEVC/m-p/1048275
|
|
|
|
auto& desc = frame._ycbcrDesc;
|
|
|
|
desc.YDim.x = YASIO_SZ_ALIGN(m_videoExtent.x, 32);
|
|
|
|
desc.YDim.y = m_bIsHEVC ? YASIO_SZ_ALIGN(m_videoExtent.y, 32) : m_videoExtent.y;
|
|
|
|
desc.CbCrDim.x = desc.YDim.x / 2;
|
|
|
|
desc.CbCrDim.y = desc.YDim.y / 2;
|
|
|
|
desc.YPitch = desc.YDim.x;
|
|
|
|
desc.CbCrPitch = desc.YPitch;
|
|
|
|
|
|
|
|
assert(frame._vpd._dim.x * frame._vpd._dim.y * 3 / 2 == static_cast<int>(frame._dataLen));
|
|
|
|
assert((desc.YPitch * desc.YDim.y + desc.CbCrPitch * desc.CbCrDim.y) == static_cast<int>(frame._dataLen));
|
2023-03-25 08:37:51 +08:00
|
|
|
break;
|
2023-04-02 01:51:36 +08:00
|
|
|
}
|
2023-03-25 08:37:51 +08:00
|
|
|
default:
|
2023-04-02 01:51:36 +08:00
|
|
|
assert(m_videoPF == MEVideoPixelFormat::RGB32 || m_videoPF == MEVideoPixelFormat::BGR32);
|
2023-03-25 08:37:51 +08:00
|
|
|
}
|
2023-04-02 01:51:36 +08:00
|
|
|
# endif
|
|
|
|
// check data
|
|
|
|
callback(frame);
|
2023-03-25 08:37:51 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-24 17:57:08 +08:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// HandleEvent
|
|
|
|
//
|
|
|
|
// Called by the application when it receives a WM_APP_PLAYER_EVENT
|
|
|
|
// message.
|
|
|
|
//
|
|
|
|
// This method is used to process media session events on the
|
|
|
|
// application's main thread.
|
|
|
|
//
|
|
|
|
// pUnkPtr: Pointer to the IUnknown interface of a media session
|
|
|
|
// event (IMFMediaEvent).
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::HandleEvent(IMFMediaEvent* pEvent)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
HRESULT hrStatus = S_OK; // Event status
|
2023-03-25 08:37:51 +08:00
|
|
|
::MediaEventType meType = MEUnknown; // Event type
|
2022-02-24 17:57:08 +08:00
|
|
|
MF_TOPOSTATUS TopoStatus = MF_TOPOSTATUS_INVALID; // Used with MESessionTopologyStatus event.
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
// auto pUnk = MFUtils::ReferencedPtrToComPtr((IUnknown*)pUnkPtr);
|
|
|
|
// TComPtr<IMFMediaEvent> pEvent;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
PROPVARIANT var;
|
|
|
|
|
2022-11-14 11:35:38 +08:00
|
|
|
if (!pEvent)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
// CHECK_HR(hr = pUnk->QueryInterface(__uuidof(IMFMediaEvent), (void**)&pEvent));
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
// Get the event type.
|
|
|
|
CHECK_HR(hr = pEvent->GetType(&meType));
|
|
|
|
|
|
|
|
// Get the event status. If the operation that triggered the event did
|
|
|
|
// not succeed, the status is a failure code.
|
|
|
|
CHECK_HR(hr = pEvent->GetStatus(&hrStatus));
|
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
// AXME_TRACE("Media event: %s\n", EventName(meType));
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
// Check if the async operation succeeded.
|
|
|
|
if (SUCCEEDED(hrStatus))
|
|
|
|
{
|
2023-03-25 08:37:51 +08:00
|
|
|
// Switch on the event type. Update the internal state of the WmfMediaEngine as needed.
|
2022-02-24 17:57:08 +08:00
|
|
|
switch (meType)
|
|
|
|
{
|
|
|
|
case MESessionTopologyStatus:
|
|
|
|
// Get the status code.
|
|
|
|
CHECK_HR(hr = pEvent->GetUINT32(MF_EVENT_TOPOLOGY_STATUS, (UINT32*)&TopoStatus));
|
|
|
|
switch (TopoStatus)
|
|
|
|
{
|
|
|
|
case MF_TOPOSTATUS_READY:
|
2022-11-14 11:35:38 +08:00
|
|
|
hr = OnTopologyReady(pEvent);
|
2022-02-24 17:57:08 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Nothing to do.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MEEndOfPresentation:
|
2022-11-14 11:35:38 +08:00
|
|
|
OnPlayEnded(pEvent);
|
2022-02-24 17:57:08 +08:00
|
|
|
break;
|
|
|
|
case MESessionStarted:
|
|
|
|
OnSessionStart(hrStatus);
|
2023-03-25 08:37:51 +08:00
|
|
|
FireMediaEvent(MEMediaEventType::Playing);
|
2022-02-24 17:57:08 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MESessionStopped:
|
|
|
|
OnSessionStop(hrStatus);
|
2023-03-25 08:37:51 +08:00
|
|
|
FireMediaEvent(MEMediaEventType::Stopped);
|
2022-02-24 17:57:08 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MESessionPaused:
|
|
|
|
OnSessionPause(hrStatus);
|
2023-03-25 08:37:51 +08:00
|
|
|
FireMediaEvent(MEMediaEventType::Paused);
|
2022-02-24 17:57:08 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MESessionRateChanged:
|
|
|
|
// If the rate change succeeded, we've already got the rate
|
|
|
|
// cached. If it failed, try to get the actual rate.
|
|
|
|
if (FAILED(hrStatus))
|
|
|
|
{
|
|
|
|
PropVariantInit(&var);
|
|
|
|
|
|
|
|
hr = pEvent->GetValue(&var);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr) && (var.vt == VT_R4))
|
|
|
|
{
|
|
|
|
m_nominal.fRate = var.fltVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MESessionEnded:
|
|
|
|
OnSessionEnded(hrStatus);
|
2023-03-25 08:37:51 +08:00
|
|
|
FireMediaEvent(MEMediaEventType::Completed);
|
2022-02-24 17:57:08 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MESessionCapabilitiesChanged:
|
|
|
|
// The session capabilities changed. Get the updated capabilities.
|
2022-11-14 11:35:38 +08:00
|
|
|
m_caps = MFGetAttributeUINT32(pEvent, MF_EVENT_SESSIONCAPS, m_caps);
|
2022-02-24 17:57:08 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = hrStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: ShutDown
|
|
|
|
// Description: Releases all resources held by this object.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::Shutdown()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("WmfMediaEngine::ShutDown\n");
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
// Close the session
|
|
|
|
hr = CloseSession();
|
|
|
|
|
|
|
|
if (m_hCloseEvent)
|
|
|
|
{
|
|
|
|
CloseHandle(m_hCloseEvent);
|
2023-04-02 01:51:36 +08:00
|
|
|
m_hCloseEvent = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_hOpenEvent)
|
|
|
|
{
|
|
|
|
CloseHandle(m_hOpenEvent);
|
|
|
|
m_hOpenEvent = nullptr;
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Protected methods
|
|
|
|
///
|
2023-03-25 08:37:51 +08:00
|
|
|
/// All methods that follow are private to the WmfMediaEngine class.
|
2022-02-24 17:57:08 +08:00
|
|
|
///
|
|
|
|
///
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: OnTopologyReady
|
|
|
|
// Description: Handler for MESessionTopologyReady event.
|
|
|
|
//
|
|
|
|
// Note:
|
|
|
|
// - The MESessionTopologySet event means the session queued the
|
|
|
|
// topology, but the topology is not ready yet. Generally, the
|
|
|
|
// applicationno need to respond to this event unless there is an
|
|
|
|
// error.
|
|
|
|
// - The MESessionTopologyReady event means the new topology is
|
|
|
|
// ready for playback. After this event is received, any calls to
|
|
|
|
// IMFGetService will get service interfaces from the new topology.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::OnTopologyReady(IMFMediaEvent* pEvent)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("WmfMediaEngine::OnTopologyReady\n");
|
|
|
|
|
|
|
|
UINT32 w = 0, h = 0;
|
|
|
|
MFGetAttributeSize(m_videoInputType.Get(), MF_MT_FRAME_SIZE, &w, &h);
|
|
|
|
m_frameExtent.x = w;
|
|
|
|
m_frameExtent.y = h;
|
|
|
|
|
|
|
|
DWORD cx = 0, cy = 0;
|
|
|
|
GetNativeVideoSize(&cx, &cy);
|
|
|
|
m_videoExtent.x = cx;
|
|
|
|
m_videoExtent.y = cy;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
if (m_bAutoPlay)
|
2022-02-24 17:57:08 +08:00
|
|
|
StartPlayback(nullptr);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Starts playback.
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
bool WmfMediaEngine::Play()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("WmfMediaEngine::Play\n");
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
if (m_state != MEMediaState::Paused && m_state != MEMediaState::Stopped)
|
|
|
|
MF_E_INVALIDREQUEST;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
if (m_pSession == NULL || m_pSource == NULL)
|
2023-03-25 08:37:51 +08:00
|
|
|
E_UNEXPECTED;
|
2022-05-07 20:21:22 +08:00
|
|
|
|
2022-02-24 17:57:08 +08:00
|
|
|
AutoLock lock(m_critsec);
|
|
|
|
|
|
|
|
// If another operation is pending, cache the request.
|
|
|
|
// Otherwise, start the media session.
|
|
|
|
if (m_bPending)
|
|
|
|
{
|
|
|
|
m_request.command = CmdStart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = StartPlayback(nullptr);
|
|
|
|
|
|
|
|
m_nominal.command = CmdStart;
|
|
|
|
m_bPending = CMD_PENDING;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
return SUCCEEDED(hr);
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pauses playback.
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
bool WmfMediaEngine::Pause()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (m_pSession == NULL || m_pSource == NULL)
|
2023-03-25 08:37:51 +08:00
|
|
|
E_UNEXPECTED;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
AutoLock lock(m_critsec);
|
|
|
|
|
|
|
|
// If another operation is pending, cache the request.
|
|
|
|
// Otherwise, pause the media session.
|
|
|
|
if (m_bPending)
|
|
|
|
{
|
|
|
|
m_request.command = CmdPause;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = m_pSession->Pause();
|
|
|
|
|
|
|
|
m_nominal.command = CmdPause;
|
|
|
|
m_bPending = CMD_PENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2023-03-25 08:37:51 +08:00
|
|
|
m_state = MEMediaState::Paused;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
return SUCCEEDED(hr);
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stops playback.
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
bool WmfMediaEngine::Stop()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (m_pSession == NULL || m_pSource == NULL)
|
2023-03-25 08:37:51 +08:00
|
|
|
return false; // E_UNEXPECTED;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
AutoLock lock(m_critsec);
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
if (m_state == MEMediaState::Stopped)
|
|
|
|
return false; // S_OK;
|
2022-11-14 11:35:38 +08:00
|
|
|
|
2022-02-24 17:57:08 +08:00
|
|
|
// If another operation is pending, cache the request.
|
|
|
|
// Otherwise, stop the media session.
|
|
|
|
if (m_bPending)
|
|
|
|
{
|
|
|
|
m_request.command = CmdStop;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = m_pSession->Stop();
|
|
|
|
|
|
|
|
m_nominal.command = CmdStop;
|
|
|
|
m_bPending = CMD_PENDING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2023-03-25 08:37:51 +08:00
|
|
|
m_state = MEMediaState::Stopped;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
return SUCCEEDED(hr);
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
BOOL WmfMediaEngine::CanSeek() const
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
bool bCanSeek = (((m_caps & MFSESSIONCAP_SEEK) == MFSESSIONCAP_SEEK) && (m_hnsDuration > 0) && (m_pClock != NULL));
|
|
|
|
return bCanSeek;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
MFTIME WmfMediaEngine::GetDuration() const
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
return m_hnsDuration;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
MFTIME WmfMediaEngine::GetCurrentPosition() const
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
AutoLock lock(m_critsec);
|
|
|
|
|
|
|
|
MFTIME hnsPosition = 0;
|
|
|
|
|
|
|
|
if (m_pClock == NULL)
|
|
|
|
{
|
|
|
|
return MF_E_NO_CLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return, in order:
|
|
|
|
// 1. Cached seek request (nominal position).
|
|
|
|
// 2. Pending seek operation (nominal position).
|
|
|
|
// 3. Presentation time (actual position).
|
|
|
|
|
|
|
|
if (m_request.command == CmdSeek)
|
|
|
|
{
|
|
|
|
hnsPosition = m_request.hnsStart;
|
|
|
|
}
|
|
|
|
else if (m_bPending & CMD_PENDING_SEEK)
|
|
|
|
{
|
|
|
|
hnsPosition = m_nominal.hnsStart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = m_pClock->GetTime(&hnsPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hnsPosition;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::SetPosition(MFTIME hnsPosition)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
AutoLock lock(m_critsec);
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (m_bPending)
|
|
|
|
{
|
|
|
|
// Currently seeking or changing rates, so cache this request.
|
|
|
|
m_request.command = CmdSeek;
|
|
|
|
m_request.hnsStart = hnsPosition;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = SetPositionInternal(hnsPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
BOOL WmfMediaEngine::CanScrub() const
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
return m_bCanScrub;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::Scrub(BOOL bScrub)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
// Scrubbing is implemented as rate = 0.
|
|
|
|
|
|
|
|
AutoLock lock(m_critsec);
|
|
|
|
|
|
|
|
if (!m_RateControl)
|
|
|
|
{
|
|
|
|
return MF_E_INVALIDREQUEST;
|
|
|
|
}
|
|
|
|
if (!m_bCanScrub)
|
|
|
|
{
|
|
|
|
return MF_E_INVALIDREQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (bScrub)
|
|
|
|
{
|
|
|
|
// Enter scrubbing mode. Cache the current rate.
|
|
|
|
|
|
|
|
if (GetNominalRate() != 0)
|
|
|
|
{
|
|
|
|
m_fPrevRate = m_nominal.fRate;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
hr = SetRate(0.0f) ? S_OK : E_FAIL;
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Leaving scrubbing mode. Restore the old rate.
|
|
|
|
|
|
|
|
if (GetNominalRate() == 0)
|
|
|
|
{
|
2023-03-25 08:37:51 +08:00
|
|
|
hr = SetRate(m_fPrevRate) ? S_OK : E_FAIL;
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
BOOL WmfMediaEngine::CanFastForward() const
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
BOOL bCanFF = ((m_caps & MFSESSIONCAP_RATE_FORWARD) == MFSESSIONCAP_RATE_FORWARD);
|
|
|
|
return bCanFF;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
BOOL WmfMediaEngine::CanRewind() const
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
BOOL bCanRewind = ((m_caps & MFSESSIONCAP_RATE_REVERSE) == MFSESSIONCAP_RATE_REVERSE);
|
|
|
|
return bCanRewind;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::FastForward()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
if (!m_RateControl)
|
|
|
|
{
|
|
|
|
return MF_E_INVALIDREQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
float fTarget = GetNominalRate() * 2;
|
|
|
|
|
|
|
|
if (fTarget <= 0.0f)
|
|
|
|
{
|
|
|
|
fTarget = 1.0f;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
hr = SetRate(fTarget) ? S_OK : E_FAIL;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::Rewind()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
if (!m_RateControl)
|
|
|
|
{
|
|
|
|
return MF_E_INVALIDREQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
float fTarget = GetNominalRate() * 2;
|
|
|
|
|
|
|
|
if (fTarget >= 0.0f)
|
|
|
|
{
|
|
|
|
fTarget = -1.0f;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
SetRate(fTarget);
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
bool WmfMediaEngine::SetRate(double lfRate)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
BOOL bThin = FALSE;
|
|
|
|
|
|
|
|
AutoLock lock(m_critsec);
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
const float fRate = static_cast<float>(lfRate);
|
|
|
|
|
2022-02-24 17:57:08 +08:00
|
|
|
if (fRate == GetNominalRate())
|
|
|
|
{
|
2023-03-25 08:37:51 +08:00
|
|
|
return true; // S_OK; // no-op
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_RateSupport == NULL)
|
|
|
|
{
|
2023-03-25 08:37:51 +08:00
|
|
|
return false; // MF_E_INVALIDREQUEST;
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if this rate is supported. Try non-thinned playback first,
|
|
|
|
// then fall back to thinned playback.
|
|
|
|
|
|
|
|
hr = m_RateSupport->IsRateSupported(FALSE, fRate, NULL);
|
|
|
|
if (FAILED(hr) && hr != MF_E_INVALIDREQUEST)
|
|
|
|
{
|
|
|
|
bThin = TRUE;
|
|
|
|
hr = m_RateSupport->IsRateSupported(TRUE, fRate, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr) && hr != MF_E_INVALIDREQUEST)
|
|
|
|
{
|
|
|
|
// Unsupported rate.
|
2023-03-25 08:37:51 +08:00
|
|
|
return SUCCEEDED(hr);
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there is an operation pending, cache the request.
|
|
|
|
if (m_bPending || hr == MF_E_INVALIDREQUEST)
|
|
|
|
{
|
|
|
|
m_bPending = CMD_PENDING_RATE;
|
|
|
|
|
|
|
|
m_request.fRate = fRate;
|
|
|
|
m_request.bThin = bThin;
|
|
|
|
|
|
|
|
// Remember the current transport state (play, paused, etc), so that we
|
|
|
|
// can restore it after the rate change, if necessary. However, if
|
|
|
|
// anothercommand is already pending, that one takes precedent.
|
|
|
|
|
|
|
|
if (m_request.command == CmdNone)
|
|
|
|
{
|
|
|
|
m_request.command = m_nominal.command;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No pending operation. Commit the new rate.
|
|
|
|
hr = CommitRateChange(fRate, bThin);
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
return SUCCEEDED(hr);
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::SetPositionInternal(const MFTIME& hnsPosition)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
assert(!m_bPending);
|
|
|
|
|
|
|
|
if (m_pSession == NULL)
|
|
|
|
{
|
|
|
|
return MF_E_INVALIDREQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = StartPlayback(&hnsPosition);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
// Store the pending state.
|
|
|
|
m_nominal.command = CmdStart;
|
|
|
|
m_nominal.hnsStart = hnsPosition;
|
|
|
|
m_bPending = CMD_PENDING_SEEK;
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
m_state = MEMediaState::Playing;
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::StartPlayback(const MFTIME* hnsPosition)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
PROPVARIANT varStart;
|
|
|
|
if (!hnsPosition)
|
|
|
|
varStart.vt = VT_EMPTY;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
varStart.vt = VT_I8;
|
|
|
|
varStart.hVal.QuadPart = *hnsPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try apply pending rate before start playback
|
|
|
|
if (m_bPending & CMD_PENDING_RATE && m_request.fRate != m_nominal.fRate)
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(m_RateControl->SetRate(m_request.bThin, m_request.fRate)))
|
|
|
|
{
|
|
|
|
m_bPending = FALSE;
|
|
|
|
m_request.command = CmdNone;
|
|
|
|
m_nominal.fRate = m_request.fRate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = m_pSession->Start(NULL, &varStart);
|
|
|
|
|
|
|
|
// Note: Start is an asynchronous operation. However, we
|
|
|
|
// can treat our state as being already started. If Start
|
|
|
|
// fails later, we'll get an MESessionStarted event with
|
|
|
|
// an error code, and we will update our state then.
|
|
|
|
if (SUCCEEDED(hr))
|
2023-03-25 08:37:51 +08:00
|
|
|
m_state = MEMediaState::Playing;
|
2022-02-24 17:57:08 +08:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::CommitRateChange(float fRate, BOOL bThin)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
assert(!m_bPending);
|
|
|
|
|
|
|
|
// Caller holds the lock.
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
MFTIME hnsSystemTime = 0;
|
|
|
|
MFTIME hnsClockTime = 0;
|
|
|
|
|
|
|
|
Command cmdNow = m_nominal.command;
|
|
|
|
|
|
|
|
TComPtr<IMFClock> pClock;
|
|
|
|
|
|
|
|
// Allowed rate transitions:
|
|
|
|
|
|
|
|
// Positive <-> negative: Stopped
|
|
|
|
// Negative <-> zero: Stopped
|
|
|
|
// Postive <-> zero: Paused or stopped
|
|
|
|
|
|
|
|
if ((fRate > 0 && m_nominal.fRate <= 0) || (fRate < 0 && m_nominal.fRate >= 0))
|
|
|
|
{
|
|
|
|
// Transition to stopped.
|
|
|
|
if (cmdNow == CmdStart)
|
|
|
|
{
|
|
|
|
// Get the current clock position. This will be the restart time.
|
|
|
|
hr = m_pSession->GetClock(&pClock);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)pClock->GetCorrelatedTime(0, &hnsClockTime, &hnsSystemTime);
|
|
|
|
|
|
|
|
assert(hnsSystemTime != 0);
|
|
|
|
|
|
|
|
// Stop and set the rate
|
2023-03-25 08:37:51 +08:00
|
|
|
if (!Stop())
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-03-25 08:37:51 +08:00
|
|
|
hr = E_FAIL;
|
2022-02-24 17:57:08 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache Request: Restart from stop.
|
|
|
|
m_request.command = CmdSeek;
|
|
|
|
m_request.hnsStart = hnsClockTime;
|
|
|
|
}
|
|
|
|
else if (cmdNow == CmdPause)
|
|
|
|
{
|
|
|
|
// The current state is paused.
|
|
|
|
|
|
|
|
// For this rate change, the session must be stopped. However, the
|
|
|
|
// session cannot transition back from stopped to paused.
|
|
|
|
// Therefore, this rate transition is not supported while paused.
|
|
|
|
|
|
|
|
hr = MF_E_UNSUPPORTED_STATE_TRANSITION;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fRate == 0 && m_nominal.fRate != 0)
|
|
|
|
{
|
|
|
|
if (cmdNow != CmdPause)
|
|
|
|
{
|
|
|
|
// Transition to paused.
|
|
|
|
|
|
|
|
// This transisition requires the paused state.
|
|
|
|
|
|
|
|
// Pause and set the rate.
|
2023-03-25 08:37:51 +08:00
|
|
|
if (!Pause())
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-03-25 08:37:51 +08:00
|
|
|
hr = E_FAIL;
|
2022-02-24 17:57:08 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request: Switch back to current state.
|
|
|
|
m_request.command = cmdNow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the rate.
|
|
|
|
hr = m_RateControl->SetRate(bThin, fRate);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust our current rate and requested rate.
|
|
|
|
m_request.fRate = m_nominal.fRate = fRate;
|
|
|
|
|
|
|
|
done:
|
|
|
|
return hr;
|
|
|
|
}
|
2023-03-25 08:37:51 +08:00
|
|
|
float WmfMediaEngine::GetNominalRate() const
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
return m_request.fRate;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::UpdatePendingCommands(Command cmd)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
PROPVARIANT varStart;
|
|
|
|
PropVariantInit(&varStart);
|
|
|
|
|
|
|
|
AutoLock lock(m_critsec);
|
|
|
|
|
|
|
|
if (m_bPending && m_nominal.command == cmd)
|
|
|
|
{
|
|
|
|
m_bPending = FALSE;
|
|
|
|
|
|
|
|
// The current pending command has completed.
|
|
|
|
|
|
|
|
// First look for rate changes.
|
|
|
|
if (m_request.fRate != m_nominal.fRate)
|
|
|
|
{
|
|
|
|
hr = CommitRateChange(m_request.fRate, m_request.bThin);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now look for seek requests.
|
|
|
|
if (!m_bPending)
|
|
|
|
{
|
|
|
|
switch (m_request.command)
|
|
|
|
{
|
|
|
|
case CmdNone:
|
|
|
|
// Nothing to do.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CmdStart:
|
|
|
|
Play();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CmdPause:
|
|
|
|
Pause();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CmdStop:
|
|
|
|
Stop();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CmdSeek:
|
|
|
|
SetPositionInternal(m_request.hnsStart);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_request.command = CmdNone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::OnPlayEnded(IMFMediaEvent* pEvent)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("WmfMediaEngine::OnPlayEnded\n");
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
// The session puts itself into the stopped state autmoatically.
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
m_state = MEMediaState::Stopped;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
if (m_bLooping)
|
|
|
|
{
|
|
|
|
SetPosition(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::OnSessionStart(HRESULT hrStatus)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (FAILED(hrStatus))
|
|
|
|
{
|
|
|
|
return hrStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The Media Session completed a start/seek operation. Check if there
|
|
|
|
// is another seek request pending.
|
|
|
|
UpdatePendingCommands(CmdStart);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::OnSessionStop(HRESULT hrStatus)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (FAILED(hrStatus))
|
|
|
|
{
|
|
|
|
return hrStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The Media Session completed a transition to stopped. This might occur
|
|
|
|
// because we are changing playback direction (forward/rewind). Check if
|
|
|
|
// there is a pending rate-change request.
|
|
|
|
|
|
|
|
UpdatePendingCommands(CmdStop);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::OnSessionPause(HRESULT hrStatus)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (FAILED(hrStatus))
|
|
|
|
{
|
|
|
|
return hrStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = UpdatePendingCommands(CmdPause);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::OnSessionEnded(HRESULT hrStatus)
|
2022-02-24 17:57:08 +08:00
|
|
|
{ // After the session ends, playback starts from position zero. But if the
|
|
|
|
// current playback rate is reversed, playback would end immediately
|
|
|
|
// (reversing from position 0). Therefore, reset the rate to 1x.
|
|
|
|
|
|
|
|
if (GetNominalRate() < 0.0f)
|
|
|
|
{
|
|
|
|
m_nominal.command = CmdStop;
|
|
|
|
|
|
|
|
hrStatus = CommitRateChange(1.0f, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hrStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: CreateSession
|
|
|
|
// Description: Creates a new instance of the media session.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::CreateSession()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("WmfMediaEngine::CreateSession\n");
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TComPtr<IMFAttributes> pAttributes;
|
|
|
|
// IMFActivate *pEnablerActivate = NULL;
|
|
|
|
|
|
|
|
// Close the old session, if any.
|
|
|
|
CHECK_HR(hr = CloseSession());
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
assert(m_state == MEMediaState::Closed);
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
// Create a new attribute store.
|
|
|
|
CHECK_HR(hr = MFCreateAttributes(&pAttributes, 2));
|
|
|
|
|
|
|
|
pAttributes->SetUINT32(MF_LOW_LATENCY, TRUE);
|
|
|
|
CHECK_HR(hr = MFCreateMediaSession(pAttributes.Get(), &m_pSession));
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
// If MFCreatePMPMediaSession fails it might return an IMFActivate pointer.
|
|
|
|
// This indicates that a trusted binary failed to load in the protected process.
|
|
|
|
// An application can use the IMFActivate pointer to create an enabler object, which
|
|
|
|
// provides revocation and renewal information for the component that failed to
|
|
|
|
// load.
|
|
|
|
|
|
|
|
// This sample does not demonstrate that feature. Instead, we simply treat this
|
|
|
|
// case as a playback failure.
|
|
|
|
|
|
|
|
// Start pulling events from the media session
|
|
|
|
CHECK_HR(hr = m_pSession->BeginGetEvent((IMFAsyncCallback*)this, NULL));
|
|
|
|
|
|
|
|
done:
|
|
|
|
// SAFE_RELEASE(pAttributes);
|
|
|
|
// SAFE_RELEASE(pEnablerActivate);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: CloseSession
|
|
|
|
// Description: Closes the media session.
|
|
|
|
//
|
|
|
|
// Note: The IMFMediaSession::Close method is asynchronous, but the
|
2023-03-25 08:37:51 +08:00
|
|
|
// WmfMediaEngine::CloseSession method waits on the MESessionClosed event.
|
2022-02-24 17:57:08 +08:00
|
|
|
// The MESessionClosed event is guaranteed to be the last event
|
|
|
|
// that the media session fires.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::CloseSession()
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
// SAFE_RELEASE(m_pVideoDisplay);
|
|
|
|
|
|
|
|
if (m_pSession)
|
|
|
|
{
|
|
|
|
DWORD dwWaitResult = 0;
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
m_state = MEMediaState::Closing;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
CHECK_HR(hr = m_pSession->Close());
|
|
|
|
|
|
|
|
// Wait for the close operation to complete
|
|
|
|
|
|
|
|
dwWaitResult = WaitForSingleObject(m_hCloseEvent, 5000);
|
|
|
|
|
|
|
|
if (dwWaitResult == WAIT_TIMEOUT)
|
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("CloseSession timed out!\n");
|
2022-02-24 17:57:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now there will be no more events from this session.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Complete shutdown operations.
|
|
|
|
|
|
|
|
// Shut down the media source. (Synchronous operation, no events.)
|
|
|
|
if (m_pSource)
|
|
|
|
{
|
|
|
|
m_pSource->Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shut down the media session. (Synchronous operation, no events.)
|
|
|
|
if (m_pSession)
|
|
|
|
{
|
|
|
|
m_pSession->Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_PresentDescriptor.Reset();
|
|
|
|
m_RateControl.Reset();
|
|
|
|
m_RateSupport.Reset();
|
|
|
|
m_pClock.Reset();
|
|
|
|
|
|
|
|
m_pSource.Reset();
|
|
|
|
m_pSession.Reset();
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
m_state = MEMediaState::Closed;
|
2022-11-14 11:35:38 +08:00
|
|
|
m_bPending = false;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: CreateMediaSource
|
|
|
|
// Description: Create a media source from a URL.
|
|
|
|
//
|
|
|
|
// sURL: The URL to open.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::CreateMediaSource(const WCHAR* sURL)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("WmfMediaEngine::CreateMediaSource\n");
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
MF_OBJECT_TYPE ObjectType = MF_OBJECT_INVALID;
|
|
|
|
|
|
|
|
TComPtr<IMFSourceResolver> pSourceResolver;
|
|
|
|
TComPtr<IUnknown> pSource;
|
|
|
|
|
|
|
|
m_pSource.Reset(); // SAFE_RELEASE(m_pSource);
|
|
|
|
|
|
|
|
// Create the source resolver.
|
|
|
|
CHECK_HR(hr = MFCreateSourceResolver(&pSourceResolver));
|
|
|
|
|
|
|
|
// Use the source resolver to create the media source.
|
|
|
|
|
|
|
|
// Note: For simplicity this sample uses the synchronous method on
|
|
|
|
// IMFSourceResolver to create the media source. However, creating a
|
|
|
|
// media source can take a noticeable amount of time, especially for
|
|
|
|
// a network source. For a more responsive UI, use the asynchronous
|
|
|
|
// BeginCreateObjectFromURL method.
|
|
|
|
|
|
|
|
CHECK_HR(hr = pSourceResolver->CreateObjectFromURL(sURL, // URL of the source.
|
|
|
|
MF_RESOLUTION_MEDIASOURCE, // Create a source object.
|
|
|
|
NULL, // Optional property store.
|
|
|
|
&ObjectType, // Receives the created object type.
|
|
|
|
&pSource // Receives a pointer to the media source.
|
|
|
|
));
|
|
|
|
|
|
|
|
// Get the IMFMediaSource interface from the media source.
|
|
|
|
CHECK_HR(hr = pSource->QueryInterface(__uuidof(IMFMediaSource), (void**)&m_pSource));
|
|
|
|
|
|
|
|
done:
|
|
|
|
// SAFE_RELEASE(pSourceResolver);
|
|
|
|
// SAFE_RELEASE(pSource);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// CreateTopologyFromSource
|
|
|
|
// Description: Create a playback topology from the media source.
|
|
|
|
//
|
|
|
|
// Pre-condition: The media source must be created already.
|
|
|
|
// Call CreateMediaSource() before calling this method.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::CreateTopologyFromSource(IMFTopology** ppTopology)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("WmfMediaEngine::CreateTopologyFromSource\n");
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
assert(m_pSession != NULL);
|
|
|
|
assert(m_pSource != NULL);
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TComPtr<IMFTopology> pTopology;
|
|
|
|
DWORD cSourceStreams = 0;
|
|
|
|
|
|
|
|
// Create a new topology.
|
|
|
|
CHECK_HR(hr = MFCreateTopology(&pTopology));
|
|
|
|
|
|
|
|
// Create the presentation descriptor for the media source.
|
|
|
|
CHECK_HR(hr = m_pSource->CreatePresentationDescriptor(&m_PresentDescriptor));
|
|
|
|
|
|
|
|
// Get the number of streams in the media source.
|
|
|
|
CHECK_HR(hr = m_PresentDescriptor->GetStreamDescriptorCount(&cSourceStreams));
|
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("Stream count: %d\n", cSourceStreams);
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
// For each stream, create the topology nodes and add them to the topology.
|
|
|
|
for (DWORD i = 0; i < cSourceStreams; ++i)
|
|
|
|
{
|
|
|
|
CHECK_HR(hr = AddBranchToPartialTopology(pTopology.Get(), m_PresentDescriptor.Get(), i));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the IMFTopology pointer to the caller.
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
*ppTopology = pTopology.Get();
|
|
|
|
(*ppTopology)->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: AddBranchToPartialTopology
|
|
|
|
// Description: Adds a topology branch for one stream.
|
|
|
|
//
|
|
|
|
// pTopology: Pointer to the topology object.
|
|
|
|
// pSourcePD: The source's presentation descriptor.
|
|
|
|
// iStream: Index of the stream to render.
|
|
|
|
//
|
|
|
|
// Pre-conditions: The topology must be created already.
|
|
|
|
//
|
|
|
|
// Notes: For each stream, we must do the following:
|
|
|
|
// 1. Create a source node associated with the stream.
|
|
|
|
// 2. Create an output node for the renderer.
|
|
|
|
// 3. Connect the two nodes.
|
|
|
|
// The media session will resolve the topology, so we do not have
|
|
|
|
// to worry about decoders or other transforms.
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::AddBranchToPartialTopology(IMFTopology* pTopology,
|
|
|
|
IMFPresentationDescriptor* pSourcePD,
|
|
|
|
DWORD iStream)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("WmfMediaEngine::AddBranchToPartialTopology\n");
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
assert(pTopology != NULL);
|
|
|
|
|
|
|
|
TComPtr<IMFStreamDescriptor> pSourceSD;
|
|
|
|
TComPtr<IMFTopologyNode> pSourceNode;
|
|
|
|
TComPtr<IMFTopologyNode> pOutputNode;
|
|
|
|
BOOL fSelected = FALSE;
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
// Get the stream descriptor for this stream.
|
|
|
|
CHECK_HR(hr = pSourcePD->GetStreamDescriptorByIndex(iStream, &fSelected, &pSourceSD));
|
|
|
|
|
|
|
|
// Create the topology branch only if the stream is selected.
|
|
|
|
// Otherwise, do nothing.
|
|
|
|
if (fSelected)
|
|
|
|
{
|
|
|
|
// Create a source node for this stream.
|
|
|
|
CHECK_HR(hr = CreateSourceStreamNode(m_pSource.Get(), pSourcePD, pSourceSD.Get(), &pSourceNode));
|
|
|
|
|
|
|
|
// Create the output node for the renderer.
|
|
|
|
CHECK_HR(hr = CreateOutputNode(pSourceSD.Get(), &pOutputNode));
|
|
|
|
|
|
|
|
// Add both nodes to the topology.
|
|
|
|
CHECK_HR(hr = pTopology->AddNode(pSourceNode.Get()));
|
|
|
|
|
|
|
|
CHECK_HR(hr = pTopology->AddNode(pOutputNode.Get()));
|
|
|
|
|
|
|
|
// Connect the source node to the output node.
|
|
|
|
CHECK_HR(hr = pSourceNode->ConnectOutput(0, pOutputNode.Get(), 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
// Clean up.
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Name: CreateOutputNode
|
|
|
|
// Description: Create an output node for a stream.
|
|
|
|
//
|
|
|
|
// pSourceSD: Stream descriptor for the stream.
|
|
|
|
// ppNode: Receives a pointer to the new node.
|
|
|
|
//
|
|
|
|
// Notes:
|
|
|
|
// This function does the following:
|
|
|
|
// 1. Chooses a renderer based on the media type of the stream.
|
|
|
|
// 2. Creates an IActivate object for the renderer.
|
|
|
|
// 3. Creates an output topology node.
|
|
|
|
// 4. Sets the IActivate pointer on the node.
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
HRESULT WmfMediaEngine::CreateOutputNode(IMFStreamDescriptor* pSourceSD, IMFTopologyNode** ppNode)
|
2022-02-24 17:57:08 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
TComPtr<IMFTopologyNode> OutputNode;
|
|
|
|
TComPtr<IMFMediaTypeHandler> pHandler;
|
|
|
|
TComPtr<IMFActivate> pRendererActivate;
|
|
|
|
|
|
|
|
GUID guidMajorType = GUID_NULL;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
// Get the stream ID.
|
|
|
|
DWORD streamID = 0;
|
|
|
|
pSourceSD->GetStreamIdentifier(&streamID); // Just for debugging, ignore any failures.
|
|
|
|
|
|
|
|
// Get the media type handler for the stream.
|
|
|
|
CHECK_HR(hr = pSourceSD->GetMediaTypeHandler(&pHandler));
|
|
|
|
|
|
|
|
// Get the major media type.
|
|
|
|
CHECK_HR(hr = pHandler->GetMajorType(&guidMajorType));
|
|
|
|
|
|
|
|
// Create a downstream node.
|
|
|
|
CHECK_HR(hr = MFCreateTopologyNode(MF_TOPOLOGY_OUTPUT_NODE, &OutputNode));
|
|
|
|
|
|
|
|
// Create an IMFActivate object for the renderer, based on the media type.
|
|
|
|
if (MFMediaType_Video == guidMajorType)
|
|
|
|
{
|
|
|
|
// Create the video renderer.
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("Stream %d: video stream\n", streamID);
|
2022-02-24 17:57:08 +08:00
|
|
|
// CHECK_HR(hr = MFCreateVideoRendererActivate(hwndVideo, &pRendererActivate));
|
2023-04-02 01:51:36 +08:00
|
|
|
auto Sampler = MFUtils::MakeComPtr<MFVideoSampler>(this);
|
|
|
|
TComPtr<IMFMediaType>& InputType = m_videoInputType;
|
|
|
|
CHECK_HR(hr = pHandler->GetCurrentMediaType(InputType.ReleaseAndGetAddressOf()));
|
2022-02-24 17:57:08 +08:00
|
|
|
|
|
|
|
// Create output type
|
|
|
|
GUID SubType;
|
|
|
|
CHECK_HR(hr = InputType->GetGUID(MF_MT_SUBTYPE, &SubType));
|
|
|
|
|
2022-05-07 20:21:22 +08:00
|
|
|
m_bIsH264 = SubType == MFVideoFormat_H264 || SubType == MFVideoFormat_H264_ES;
|
2023-04-02 01:51:36 +08:00
|
|
|
m_bIsHEVC = SubType == MFVideoFormat_HEVC || SubType == MFVideoFormat_HEVC_ES;
|
2022-02-24 17:57:08 +08:00
|
|
|
|
2022-05-07 20:21:22 +08:00
|
|
|
GUID VideoOutputFormat;
|
2022-02-24 17:57:08 +08:00
|
|
|
if ((SubType == MFVideoFormat_HEVC) || (SubType == MFVideoFormat_HEVC_ES) || (SubType == MFVideoFormat_NV12) ||
|
|
|
|
(SubType == MFVideoFormat_IYUV))
|
|
|
|
{
|
|
|
|
VideoOutputFormat = MFVideoFormat_NV12;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const bool Uncompressed = (SubType == MFVideoFormat_RGB555) || (SubType == MFVideoFormat_RGB565) ||
|
|
|
|
(SubType == MFVideoFormat_RGB24) || (SubType == MFVideoFormat_RGB32) ||
|
|
|
|
(SubType == MFVideoFormat_ARGB32);
|
|
|
|
|
|
|
|
VideoOutputFormat = Uncompressed ? MFVideoFormat_RGB32 : MFVideoFormat_YUY2;
|
|
|
|
}
|
|
|
|
|
2022-05-07 20:21:22 +08:00
|
|
|
TComPtr<IMFMediaType> OutputType;
|
|
|
|
CHECK_HR(hr = ::MFCreateMediaType(&OutputType));
|
|
|
|
CHECK_HR(hr = OutputType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE));
|
|
|
|
CHECK_HR(hr = OutputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
|
2022-02-24 17:57:08 +08:00
|
|
|
CHECK_HR(hr = OutputType->SetGUID(MF_MT_SUBTYPE, VideoOutputFormat));
|
|
|
|
|
|
|
|
CHECK_HR(hr = ::MFCreateSampleGrabberSinkActivate(OutputType.Get(), Sampler.Get(), &pRendererActivate));
|
|
|
|
|
|
|
|
m_VideoOutputFormat = VideoOutputFormat;
|
2023-03-25 08:37:51 +08:00
|
|
|
|
|
|
|
if (m_VideoOutputFormat == MFVideoFormat_YUY2)
|
2023-04-02 01:51:36 +08:00
|
|
|
m_videoPF = MEVideoPixelFormat::YUY2;
|
2023-03-25 08:37:51 +08:00
|
|
|
else if (m_VideoOutputFormat == MFVideoFormat_NV12)
|
2023-04-02 01:51:36 +08:00
|
|
|
m_videoPF = MEVideoPixelFormat::NV12;
|
2023-03-25 08:37:51 +08:00
|
|
|
else if (m_VideoOutputFormat == MFVideoFormat_RGB32)
|
2023-04-02 01:51:36 +08:00
|
|
|
m_videoPF = MEVideoPixelFormat::RGB32;
|
2022-02-24 17:57:08 +08:00
|
|
|
// To run as fast as possible, set this attribute (requires Windows 7):
|
|
|
|
// CHECK_HR(hr = pRendererActivate->SetUINT32(MF_SAMPLEGRABBERSINK_IGNORE_CLOCK, TRUE));
|
|
|
|
}
|
|
|
|
else if (MFMediaType_Audio == guidMajorType)
|
|
|
|
{
|
|
|
|
// Create the audio renderer.
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("Stream %d: audio stream\n", streamID);
|
2022-02-24 17:57:08 +08:00
|
|
|
CHECK_HR(hr = MFCreateAudioRendererActivate(&pRendererActivate));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-02 01:51:36 +08:00
|
|
|
AXME_TRACE("Stream %d: Unknown format\n", streamID);
|
2022-02-24 17:57:08 +08:00
|
|
|
CHECK_HR(hr = E_FAIL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the IActivate object on the output node.
|
|
|
|
CHECK_HR(hr = OutputNode->SetObject(pRendererActivate.Get()));
|
|
|
|
CHECK_HR(hr = OutputNode->SetUINT32(MF_TOPONODE_STREAMID, 0));
|
|
|
|
|
|
|
|
// Return the IMFTopologyNode pointer to the caller.
|
|
|
|
*ppNode = OutputNode.Get();
|
|
|
|
(*ppNode)->AddRef();
|
|
|
|
|
|
|
|
done:
|
|
|
|
return hr;
|
|
|
|
}
|
2023-03-25 08:37:51 +08:00
|
|
|
|
2023-04-02 01:51:36 +08:00
|
|
|
HRESULT WmfMediaEngine::GetNativeVideoSize(DWORD* cx, DWORD* cy)
|
|
|
|
{
|
|
|
|
if (!m_videoInputType || !cx || !cy)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
UINT32 width = 0, height = 0;
|
|
|
|
|
|
|
|
MFVideoArea mfArea = {0};
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
BOOL bPanScan = MFGetAttributeUINT32(m_videoInputType.Get(), MF_MT_PAN_SCAN_ENABLED, FALSE);
|
|
|
|
if (bPanScan)
|
|
|
|
{
|
|
|
|
hr = m_videoInputType->GetBlob(MF_MT_PAN_SCAN_APERTURE, (UINT8*)&mfArea, sizeof(MFVideoArea), nullptr);
|
|
|
|
AX_BREAK_IF(SUCCEEDED(hr));
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = m_videoInputType->GetBlob(MF_MT_MINIMUM_DISPLAY_APERTURE, (UINT8*)&mfArea, sizeof(MFVideoArea), nullptr);
|
|
|
|
AX_BREAK_IF(SUCCEEDED(hr));
|
|
|
|
|
|
|
|
hr = m_videoInputType->GetBlob(MF_MT_GEOMETRIC_APERTURE, (UINT8*)&mfArea, sizeof(MFVideoArea), nullptr);
|
|
|
|
|
|
|
|
} while (false);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
*cx = mfArea.Area.cx;
|
|
|
|
*cy = mfArea.Area.cy;
|
|
|
|
}
|
|
|
|
else // fallback to frame extent
|
|
|
|
{
|
|
|
|
*cx = m_frameExtent.x;
|
|
|
|
*cy = m_frameExtent.y;
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2023-03-25 08:37:51 +08:00
|
|
|
NS_AX_END
|
|
|
|
|
|
|
|
#endif
|