OLD | NEW |
---|---|
(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 // This class does the following: | |
19 // 1) Sends/Receives messages from/to Remoter; | |
20 // 2) Monitors player events as a MediaObserver; | |
21 // 3) May trigger the switch of the media renderer between local playback | |
22 // and remoting. | |
23 // | |
24 namespace media { | |
25 | |
26 class RemotingController final : public MediaObserver, | |
27 public mojom::RemotingSource { | |
28 public: | |
29 RemotingController(mojom::RemotingSourceRequest source_request, | |
30 mojom::RemoterPtr remoter); | |
31 ~RemotingController() override; | |
32 | |
33 // RemotingSource implementations. | |
34 void OnSinkAvailable() override; | |
35 void OnSinkGone() override; | |
36 // This is called when remoting is started successfully. Note: Only one video | |
37 // element can start remoting successfully at one time. The current | |
38 // logic is the first come first serve. This logic might be changed in future. | |
xhwang
2016/10/05 05:27:53
Usually for overrides, we don't have extra comment
xjz
2016/10/05 17:24:24
Removed this comment here. This is controled by br
| |
39 void OnStarted() override; | |
40 void OnStartFailed(mojom::RemotingStartFailReason reason) override; | |
41 void OnMessageFromSink(const std::vector<uint8_t>& message) override; | |
42 void OnStopped(mojom::RemotingStopReason reason) override; | |
43 | |
44 // MediaObserver implementations. | |
45 // This is called when the video element or its ancestor enters full screen. | |
46 // We currently use this as an indicator for immersive playback. May add other | |
47 // criteria (e.g. the actual display width/height of the video element) in | |
48 // future. | |
49 void OnEnteredFullscreen() override; | |
50 void OnExitedFullscreen() override; | |
51 void OnSetCdm(CdmContext* cdm_context) override; | |
52 void OnMetadata(const PipelineMetadata& metadata) override; | |
53 | |
54 using SwitchRendererCallback = base::Callback<void()>; | |
55 void SetSwitchRendererCallback(const SwitchRendererCallback& cb); | |
56 | |
57 // Tells which renderer should be used. | |
58 bool is_remoting() const { | |
59 DCHECK(task_runner_->BelongsToCurrentThread()); | |
60 return is_remoting_; | |
61 } | |
62 | |
63 base::WeakPtr<RemotingController> GetWeakPtr() { | |
64 return weak_factory_.GetWeakPtr(); | |
65 } | |
66 | |
67 private: | |
68 bool IsVideoConfigSupported(); | |
69 bool IsAudioConfigSupported(); | |
70 | |
71 // Helper to decide whether to enter or leave Remoting mode. | |
72 bool ShouldBeRemoting(); | |
73 | |
74 // Determines whether to enter or leave Remoting mode and switches if | |
75 // necessary. | |
76 void UpdateAndMaybeSwitch(); | |
77 | |
78 // Indicates if this media element or its ancestor enters full screen. | |
79 bool is_fullscreen_ = false; | |
80 | |
81 // Indicates the remoting sink availablity. | |
82 bool is_sink_available_ = false; | |
83 | |
84 // Indicates if remoting is started. | |
85 bool is_remoting_ = false; | |
86 | |
87 // Current audio/video config. | |
88 VideoDecoderConfig video_decoder_config_; | |
89 AudioDecoderConfig audio_decoder_config_; | |
90 bool has_audio_ = false; | |
91 bool has_video_ = false; | |
92 | |
93 // The callback to switch the media renderer. | |
94 SwitchRendererCallback switch_renderer_cb_; | |
95 | |
96 mojo::Binding<mojom::RemotingSource> binding_; | |
97 mojom::RemoterPtr remoter_; | |
98 | |
99 // TODO(xjz): Add a media thread task runner for the received RPC messages for | |
100 // remoting media renderer in the up-coming change. | |
101 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
102 | |
103 base::WeakPtrFactory<RemotingController> weak_factory_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(RemotingController); | |
106 }; | |
107 | |
108 } // namespace media | |
109 | |
110 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | |
OLD | NEW |