Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: media/remoting/remoting_controller.h

Issue 2406483002: WIP - Add EME (Closed)
Patch Set: Add EME. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_REMOTING_REMOTING_CONTROLLER_H_
6 #define MEDIA_REMOTING_REMOTING_CONTROLLER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "media/base/media_observer.h"
11 #include "media/mojo/interfaces/remoting.mojom.h"
12 #include "mojo/public/cpp/bindings/binding.h"
13
14 namespace base {
15 class SingleThreadTaskRunner;
16 }
17
18 namespace media {
19 struct PipelineMetadata;
20 }
21
22 // This class does the following:
miu 2016/10/08 01:06:16 This comment should be next to the class declarati
xjz 2016/10/20 21:25:28 Done.
23 // 1) Sends/Receives messages from/to Remoter;
24 // 2) Monitors player events as a MediaObserver;
25 // 3) May trigger the switch of the media renderer between local playback
26 // and remoting.
27 //
28 namespace media {
29
30 class RemotingController final : public MediaObserver,
miu 2016/10/08 01:06:16 I think you should consider splitting this class u
xjz 2016/10/20 21:25:28 Done.
31 public mojom::RemotingSource {
32 public:
33 RemotingController(mojom::RemotingSourceRequest source_request,
34 mojom::RemoterPtr remoter);
35 ~RemotingController() override;
36
37 // RemotingSource implementations.
38 void OnSinkAvailable() override;
39 void OnSinkGone() override;
40 void OnStarted() override;
41 void OnStartFailed(mojom::RemotingStartFailReason reason) override;
42 void OnMessageFromSink(const std::vector<uint8_t>& message) override;
43 void OnStopped(mojom::RemotingStopReason reason) override;
44
45 // MediaObserver implementations.
46 // This is called when the video element or its ancestor enters full screen.
47 // We currently use this as an indicator for immersive playback. May add other
48 // criteria (e.g. the actual display width/height of the video element) in
49 // future.
50 void OnEnteredFullscreen() override;
51 void OnExitedFullscreen() override;
52 void OnSetCdm(CdmContext* cdm_context) override;
53 void OnMetadataChanged(const PipelineMetadata& metadata) override;
54
55 using SwitchRendererCallback = base::Callback<void()>;
56 void SetSwitchRendererCallback(const SwitchRendererCallback& cb);
57
58 base::WeakPtr<RemotingController> GetWeakPtr() {
59 return weak_factory_.GetWeakPtr();
60 }
61
62 // The callback used to tell which CDM should be created.
miu 2016/10/08 01:06:16 This comment isn't really necessary. But, the meth
xjz 2016/10/20 21:25:28 Done.
63 using CdmCheckCallback = base::Callback<void(bool is_remoting)>;
64 void ShouldCreateRemotingCdm(const CdmCheckCallback& cb);
65
66 bool is_remoting() const {
67 DCHECK(task_runner_->BelongsToCurrentThread());
68
69 if (cdm_remoting_controller_)
70 return cdm_remoting_controller_->is_remoting();
71 return is_remoting_;
72 }
73
74 bool is_remoting_failed() const {
75 DCHECK(task_runner_->BelongsToCurrentThread());
76
77 if (cdm_remoting_controller_)
78 return cdm_remoting_controller_->is_remoting_failed();
79
80 // Always false for non-encrypted contents.
81 return false;
miu 2016/10/08 01:06:16 If this is the RemotingController owned by the CDM
xjz 2016/10/20 21:25:28 Not applicable.
82 }
83
84 private:
85 bool IsVideoCodecSupported();
86 bool IsAudioCodecSupported();
87
88 // Helper to decide whether to enter or leave Remoting mode.
89 bool ShouldBeRemoting();
90
91 // Determines whether to enter or leave Remoting mode and switches if
92 // necessary.
93 void UpdateAndMaybeSwitch();
94
95 // Indicates if this media element or its ancestor enters full screen.
96 bool is_fullscreen_ = false;
97
98 // Indicates the remoting sink availablity.
99 bool is_sink_available_ = false;
100
101 // Indicates if remoting is started.
102 bool is_remoting_ = false;
miu 2016/10/08 01:06:16 This is now "sort of" true because it will be fals
xjz 2016/10/20 21:25:28 Not applicable.
103
104 // Indicates whether audio or video is encrypted.
105 bool is_encrypted_ = false;
106
107 // Indicates if remoting cdm is created.
108 bool is_remoting_cdm_ = false;
miu 2016/10/08 01:06:16 This isn't necessary, because this can always be d
xjz 2016/10/20 21:25:28 Not applicable.
109
110 // Indicates that remoting was stopped after CDM is created remotely. In this
miu 2016/10/08 01:06:16 Suggested wording: // Indicates that the video st
xjz 2016/10/20 21:25:28 Add this comment to RemotingSessionState::SESSION_
111 // case, local playing back can't continue without reloading the page.
112 bool is_remoting_failed_ = false;
miu 2016/10/08 01:06:16 Actually, do you need this bool? Wouldn't it alway
miu 2016/10/08 01:06:16 naming: How about has_terminated_permanently_.
xjz 2016/10/20 21:25:28 Not applicable.
xjz 2016/10/20 21:25:28 Not applicable.
113
114 // Current audio/video config.
115 VideoDecoderConfig video_decoder_config_;
116 AudioDecoderConfig audio_decoder_config_;
117 bool has_audio_ = false;
118 bool has_video_ = false;
119
120 // The callback to switch the media renderer.
121 SwitchRendererCallback switch_renderer_cb_;
122
123 mojo::Binding<mojom::RemotingSource> binding_;
124 mojom::RemoterPtr remoter_;
125
126 // TODO(xjz): Add a media thread task runner for the received RPC messages for
127 // remoting media renderer in the up-coming change.
128 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
129
130 // The callback for checking whether remoting CDM should be created.
131 CdmCheckCallback cdm_check_cb_;
miu 2016/10/08 01:06:16 It seems like this is a "run once" callback. Is th
xjz 2016/10/20 21:25:28 Done.
132
133 // This is the RemotingController that was created when remoting CDM was
134 // created. It was set when OnSetCdm() is called. After it is set, the
135 // |switch_renderer_cb_| is passed to it, and the current object is only used
136 // as a proxy to pass |metadata_| and the query of |is_remoting_| to it.
137 std::unique_ptr<RemotingController> cdm_remoting_controller_;
miu 2016/10/08 01:06:16 It doesn't seem that you should be taking ownershi
xjz 2016/10/20 21:25:28 Not applicable.
138
139 PipelineMetadata metadata_;
140
141 base::WeakPtrFactory<RemotingController> weak_factory_;
142
143 DISALLOW_COPY_AND_ASSIGN(RemotingController);
144 };
145
146 } // namespace media
147
148 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698