OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | 5 #ifndef MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
6 #define MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | 6 #define MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "media/base/media_observer.h" | 10 #include "media/base/media_observer.h" |
11 #include "media/mojo/interfaces/remoting.mojom.h" | 11 #include "media/remoting/remoting_source_impl.h" |
12 #include "mojo/public/cpp/bindings/binding.h" | |
13 | 12 |
14 namespace base { | 13 namespace media { |
15 class SingleThreadTaskRunner; | 14 struct PipelineMetadata; |
16 } | 15 } |
17 | 16 |
18 // This class does the following: | 17 namespace media { |
19 // 1) Sends/Receives messages from/to Remoter; | 18 |
| 19 // This class: |
| 20 // 1) Implements the RemotingSourceImpl::Client; |
20 // 2) Monitors player events as a MediaObserver; | 21 // 2) Monitors player events as a MediaObserver; |
21 // 3) May trigger the switch of the media renderer between local playback | 22 // 3) May trigger the switch of the media renderer between local playback |
22 // and remoting. | 23 // and remoting. |
23 // | 24 class RemotingRendererController final : public RemotingSourceImpl::Client, |
24 namespace media { | 25 public MediaObserver { |
| 26 public: |
| 27 explicit RemotingRendererController( |
| 28 scoped_refptr<RemotingSourceImpl> remoting_source); |
| 29 ~RemotingRendererController() override; |
25 | 30 |
26 class RemotingController final : public MediaObserver, | 31 // RemotingSourceImpl::Client implemenations. |
27 public mojom::RemotingSource { | 32 void OnStarted(bool success) override; |
28 public: | 33 void OnSessionStateChanged() override; |
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 void OnStarted() override; | |
37 void OnStartFailed(mojom::RemotingStartFailReason reason) override; | |
38 void OnMessageFromSink(const std::vector<uint8_t>& message) override; | |
39 void OnStopped(mojom::RemotingStopReason reason) override; | |
40 | 34 |
41 // MediaObserver implementations. | 35 // MediaObserver implementations. |
42 // This is called when the video element or its ancestor enters full screen. | |
43 // We currently use this as an indicator for immersive playback. May add other | |
44 // criteria (e.g. the actual display width/height of the video element) in | |
45 // future. | |
46 void OnEnteredFullscreen() override; | 36 void OnEnteredFullscreen() override; |
47 void OnExitedFullscreen() override; | 37 void OnExitedFullscreen() override; |
48 void OnSetCdm(CdmContext* cdm_context) override; | 38 void OnSetCdm(CdmContext* cdm_context) override; |
49 void OnMetadataChanged(const PipelineMetadata& metadata) override; | 39 void OnMetadataChanged(const PipelineMetadata& metadata) override; |
50 | 40 |
51 using SwitchRendererCallback = base::Callback<void()>; | 41 void SetSwitchRendererCallback(const base::Closure& cb); |
52 void SetSwitchRendererCallback(const SwitchRendererCallback& cb); | |
53 | 42 |
54 // Tells which renderer should be used. | 43 base::WeakPtr<RemotingRendererController> GetWeakPtr() { |
55 bool is_remoting() const { | |
56 DCHECK(task_runner_->BelongsToCurrentThread()); | |
57 return is_remoting_; | |
58 } | |
59 | |
60 base::WeakPtr<RemotingController> GetWeakPtr() { | |
61 return weak_factory_.GetWeakPtr(); | 44 return weak_factory_.GetWeakPtr(); |
62 } | 45 } |
63 | 46 |
| 47 // Used by RemotingRendererFactory to query whether to create Media Remoting |
| 48 // Renderer. |
| 49 bool remote_rendering_started() const { |
| 50 DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 return remote_rendering_started_; |
| 52 } |
| 53 |
| 54 // Used by RemotingRendererImpl to query the session state. |
| 55 RemotingSourceImpl* remoting_source() const { |
| 56 DCHECK(thread_checker_.CalledOnValidThread()); |
| 57 return remoting_source_.get(); |
| 58 } |
| 59 |
64 private: | 60 private: |
65 bool IsVideoCodecSupported(); | 61 bool IsVideoCodecSupported(); |
66 bool IsAudioCodecSupported(); | 62 bool IsAudioCodecSupported(); |
67 | 63 |
68 // Helper to decide whether to enter or leave Remoting mode. | 64 // Helper to decide whether to enter or leave Remoting mode. |
69 bool ShouldBeRemoting(); | 65 bool ShouldBeRemoting(); |
70 | 66 |
71 // Determines whether to enter or leave Remoting mode and switches if | 67 // Determines whether to enter or leave Remoting mode and switches if |
72 // necessary. | 68 // necessary. |
73 void UpdateAndMaybeSwitch(); | 69 void UpdateAndMaybeSwitch(); |
74 | 70 |
75 // Indicates if this media element or its ancestor enters full screen. | 71 // Indicates whether this media element or its ancestor is in full screen. |
76 bool is_fullscreen_ = false; | 72 bool is_fullscreen_ = false; |
77 | 73 |
78 // Indicates the remoting sink availablity. | 74 // Indicates whether remoting is started. |
79 bool is_sink_available_ = false; | 75 bool remote_rendering_started_ = false; |
80 | |
81 // Indicates if remoting is started. | |
82 bool is_remoting_ = false; | |
83 | 76 |
84 // Indicates whether audio or video is encrypted. | 77 // Indicates whether audio or video is encrypted. |
85 bool is_encrypted_ = false; | 78 bool is_encrypted_ = false; |
86 | 79 |
87 // Current audio/video config. | 80 // Current audio/video config. |
88 VideoDecoderConfig video_decoder_config_; | 81 VideoDecoderConfig video_decoder_config_; |
89 AudioDecoderConfig audio_decoder_config_; | 82 AudioDecoderConfig audio_decoder_config_; |
90 bool has_audio_ = false; | 83 bool has_audio_ = false; |
91 bool has_video_ = false; | 84 bool has_video_ = false; |
92 | 85 |
93 // The callback to switch the media renderer. | 86 // The callback to switch the media renderer. |
94 SwitchRendererCallback switch_renderer_cb_; | 87 base::Closure switch_renderer_cb_; |
95 | 88 |
96 mojo::Binding<mojom::RemotingSource> binding_; | 89 // This is initially the RemotingSourceImpl passed to the ctor, and might be |
97 mojom::RemoterPtr remoter_; | 90 // replaced with a different instance later if OnSetCdm() is called. |
| 91 scoped_refptr<RemotingSourceImpl> remoting_source_; |
98 | 92 |
99 // TODO(xjz): Add a media thread task runner for the received RPC messages for | 93 // This is used to check all the methods are called on the current thread in |
100 // remoting media renderer in the up-coming change. | 94 // debug builds. |
101 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 95 base::ThreadChecker thread_checker_; |
102 | 96 |
103 base::WeakPtrFactory<RemotingController> weak_factory_; | 97 base::WeakPtrFactory<RemotingRendererController> weak_factory_; |
104 | 98 |
105 DISALLOW_COPY_AND_ASSIGN(RemotingController); | 99 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); |
106 }; | 100 }; |
107 | 101 |
108 } // namespace media | 102 } // namespace media |
109 | 103 |
110 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | 104 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
OLD | NEW |