1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
media / renderers / win / media_engine_notify_impl.h [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_RENDERERS_WIN_MEDIA_ENGINE_NOTIFY_IMPL_H_
#define MEDIA_RENDERERS_WIN_MEDIA_ENGINE_NOTIFY_IMPL_H_
#include <mfmediaengine.h>
#include <wrl.h>
#include <optional>
#include "base/functional/callback.h"
#include "base/synchronization/lock.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/buffering_state.h"
#include "media/base/pipeline_status.h"
#include "media/base/video_decoder_config.h"
namespace media {
// Implements IMFMediaEngineNotify required by IMFMediaEngine
// (https://docs.microsoft.com/en-us/windows/win32/api/mfmediaengine/nn-mfmediaengine-imfmediaengine).
//
class MediaEngineNotifyImpl
: public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags<
Microsoft::WRL::RuntimeClassType::ClassicCom>,
IMFMediaEngineNotify> {
public:
MediaEngineNotifyImpl();
~MediaEngineNotifyImpl() override;
using ErrorCB = base::RepeatingCallback<void(PipelineStatus, HRESULT)>;
using EndedCB = base::RepeatingClosure;
using FormatChangeCB = base::RepeatingClosure;
using LoadedDataCB = base::RepeatingClosure;
using CanPlayThroughCB = base::RepeatingClosure;
using PlayingCB = base::RepeatingClosure;
using WaitingCB = base::RepeatingClosure;
using FrameStepCompletedCB = base::RepeatingClosure;
using TimeUpdateCB = base::RepeatingClosure;
HRESULT RuntimeClassInitialize(
ErrorCB error_cb,
EndedCB ended_cb,
FormatChangeCB format_change_cb,
LoadedDataCB loaded_data_cb,
CanPlayThroughCB can_play_through_cb,
PlayingCB playing_cb,
WaitingCB waiting_cb,
FrameStepCompletedCB frame_step_completed_cb,
TimeUpdateCB time_update_cb,
std::optional<VideoDecoderConfig> video_decoder_config,
std::optional<AudioDecoderConfig> audio_decoder_config);
// IMFMediaEngineNotify implementation.
IFACEMETHODIMP EventNotify(DWORD event_code,
DWORD_PTR param1,
DWORD param2) override;
void Shutdown();
private:
// Callbacks are called on the MF threadpool thread and the creator of this
// object must make sure the callbacks are safe to be called on that thread,
// e.g. using base::BindPostTaskToCurrentDefault().
ErrorCB error_cb_;
EndedCB ended_cb_;
FormatChangeCB format_change_cb_;
LoadedDataCB loaded_data_cb_;
CanPlayThroughCB can_play_through_cb_;
PlayingCB playing_cb_;
WaitingCB waiting_cb_;
FrameStepCompletedCB frame_step_completed_cb_;
TimeUpdateCB time_update_cb_;
std::optional<AudioDecoderConfig> audio_decoder_config_;
std::optional<VideoDecoderConfig> video_decoder_config_;
// EventNotify is invoked from MF threadpool thread where the callbacks are
// called.
// Shutdown is invoked from media stack thread. When this object is shutting
// down, callbacks should not be called.
base::Lock lock_;
bool has_shutdown_ GUARDED_BY(lock_) = false;
};
} // namespace media
#endif // MEDIA_RENDERERS_WIN_MEDIA_ENGINE_NOTIFY_IMPL_H_