16 :
public MW::RuntimeClass<
17 MW::RuntimeClassFlags<
18 MW::RuntimeClassType::WinRtClassicComMix>
19 , AWM::IMediaExtension
25 InspectableClass(L
"MediaSink", BaseTrust)
30 _In_opt_ WMMp::AudioEncodingProperties^ audioProps,
31 _In_opt_ WMMp::VideoEncodingProperties^ videoProps,
37 MW::ComPtr<IMFMediaType> audioMT;
38 if (audioProps !=
nullptr)
40 CHK(MFCreateMediaTypeFromProperties(As<IUnknown>(audioProps).Get(), &audioMT));
41 _audioStreamSink = MW::Make<MediaStreamSink>(
49 MW::ComPtr<IMFMediaType> videoMT;
50 if (videoProps !=
nullptr)
52 CHK(MFCreateMediaTypeFromProperties(As<IUnknown>(videoProps).Get(), &videoMT));
53 _videoStreamSink = MW::Make<MediaStreamSink>(
62 void RequestAudioSample()
64 auto lock = _lock.LockExclusive();
68 _audioStreamSink->RequestSample();
71 void RequestVideoSample()
73 auto lock = _lock.LockExclusive();
77 _videoStreamSink->RequestSample();
80 void SetCurrentAudioMediaType(_In_ IMFMediaType* mt)
82 auto lock = _lock.LockExclusive();
86 _audioStreamSink->InternalSetCurrentMediaType(mt);
89 void SetCurrentVideoMediaType(_In_ IMFMediaType* mt)
91 auto lock = _lock.LockExclusive();
95 _videoStreamSink->InternalSetCurrentMediaType(mt);
102 IFACEMETHODIMP SetProperties(_In_ AWFC::IPropertySet * )
106 auto lock = _lock.LockExclusive();
108 _VerifyNotShutdown();
116 IFACEMETHODIMP GetCharacteristics(_Out_ DWORD *characteristics)
120 _VerifyNotShutdown();
123 *characteristics = MEDIASINK_RATELESS | MEDIASINK_FIXED_STREAMS;
127 IFACEMETHODIMP AddStreamSink(
129 _In_ IMFMediaType * ,
130 _COM_Outptr_ IMFStreamSink **streamSink
135 _VerifyNotShutdown();
138 *streamSink =
nullptr;
140 CHK(MF_E_STREAMSINKS_FIXED);
144 IFACEMETHODIMP RemoveStreamSink(DWORD )
148 _VerifyNotShutdown();
150 CHK(MF_E_STREAMSINKS_FIXED);
154 IFACEMETHODIMP GetStreamSinkCount(_Out_ DWORD *streamSinkCount)
160 _VerifyNotShutdown();
162 *streamSinkCount = (_audioStreamSink !=
nullptr) + (_videoStreamSink !=
nullptr);
166 IFACEMETHODIMP GetStreamSinkByIndex(DWORD index, _COM_Outptr_ IMFStreamSink **streamSink)
170 auto lock = _lock.LockExclusive();
173 *streamSink =
nullptr;
175 _VerifyNotShutdown();
180 if (_audioStreamSink !=
nullptr)
182 CHK(_audioStreamSink.CopyTo(streamSink));
186 CHK(_videoStreamSink.CopyTo(streamSink));
191 if ((_audioStreamSink !=
nullptr) && (_videoStreamSink !=
nullptr))
193 CHK(_videoStreamSink.CopyTo(streamSink));
207 IFACEMETHODIMP GetStreamSinkById(DWORD identifier, _COM_Outptr_ IMFStreamSink **streamSink)
211 auto lock = _lock.LockExclusive();
214 *streamSink =
nullptr;
216 _VerifyNotShutdown();
218 if ((identifier == 0) && (_audioStreamSink !=
nullptr))
220 CHK(_audioStreamSink.CopyTo(streamSink));
222 else if ((identifier == 1) && (_videoStreamSink !=
nullptr))
224 CHK(_videoStreamSink.CopyTo(streamSink));
233 IFACEMETHODIMP SetPresentationClock(_In_ IMFPresentationClock *clock)
237 auto lock = _lock.LockExclusive();
239 _VerifyNotShutdown();
241 if (_clock !=
nullptr)
243 CHK(_clock->RemoveClockStateSink(
this));
247 if (clock !=
nullptr)
249 CHK(clock->AddClockStateSink(
this));
255 IFACEMETHODIMP GetPresentationClock(_COM_Outptr_ IMFPresentationClock **clock)
259 auto lock = _lock.LockExclusive();
264 _VerifyNotShutdown();
266 if (_clock !=
nullptr)
268 CHK(_clock.CopyTo(clock))
273 IFACEMETHODIMP Shutdown()
277 auto lock = _lock.LockExclusive();
285 if (_audioStreamSink !=
nullptr)
287 _audioStreamSink->Shutdown();
288 _audioStreamSink =
nullptr;
291 if (_videoStreamSink !=
nullptr)
293 _videoStreamSink->Shutdown();
294 _videoStreamSink =
nullptr;
297 if (_clock !=
nullptr)
299 (void)_clock->RemoveClockStateSink(
this);
309 IFACEMETHODIMP OnClockStart(MFTIME , LONGLONG )
313 auto lock = _lock.LockExclusive();
315 _VerifyNotShutdown();
319 IFACEMETHODIMP OnClockStop(MFTIME )
323 auto lock = _lock.LockExclusive();
325 _VerifyNotShutdown();
329 IFACEMETHODIMP OnClockPause(MFTIME )
333 auto lock = _lock.LockExclusive();
335 _VerifyNotShutdown();
339 IFACEMETHODIMP OnClockRestart(MFTIME )
343 auto lock = _lock.LockExclusive();
345 _VerifyNotShutdown();
349 IFACEMETHODIMP OnClockSetRate(MFTIME ,
float )
353 auto lock = _lock.LockExclusive();
355 _VerifyNotShutdown();
363 void _VerifyNotShutdown()
371 MW::ComPtr<MediaStreamSink> _audioStreamSink;
372 MW::ComPtr<MediaStreamSink> _videoStreamSink;
373 MW::ComPtr<IMFPresentationClock> _clock;
#define CHKNULL(p)
Definition: MFIncludes.h:40
HRESULT ExceptionBoundary(Lambda &&lambda)
Definition: MFIncludes.h:125
#define CHK(statement)
Definition: MFIncludes.h:39