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_RENDERER_CONTROLLER_H_ | 5 #ifndef MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
6 #define MEDIA_REMOTING_REMOTING_RENDERER_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/remoting/remoting_interstitial_ui.h" |
11 #include "media/remoting/remoting_source_impl.h" | 12 #include "media/remoting/remoting_source_impl.h" |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 | 15 |
15 namespace remoting { | 16 namespace remoting { |
16 class RpcBroker; | 17 class RpcBroker; |
17 } | 18 } |
18 | 19 |
19 // This class: | 20 // This class: |
20 // 1) Implements the RemotingSourceImpl::Client; | 21 // 1) Implements the RemotingSourceImpl::Client; |
(...skipping 12 matching lines...) Expand all Loading... |
33 void OnSessionStateChanged() override; | 34 void OnSessionStateChanged() override; |
34 | 35 |
35 // MediaObserver implementations. | 36 // MediaObserver implementations. |
36 void OnEnteredFullscreen() override; | 37 void OnEnteredFullscreen() override; |
37 void OnExitedFullscreen() override; | 38 void OnExitedFullscreen() override; |
38 void OnSetCdm(CdmContext* cdm_context) override; | 39 void OnSetCdm(CdmContext* cdm_context) override; |
39 void OnMetadataChanged(const PipelineMetadata& metadata) override; | 40 void OnMetadataChanged(const PipelineMetadata& metadata) override; |
40 | 41 |
41 void SetSwitchRendererCallback(const base::Closure& cb); | 42 void SetSwitchRendererCallback(const base::Closure& cb); |
42 | 43 |
| 44 using ShowInterstitialCallback = base::Callback< |
| 45 void(const SkBitmap&, const gfx::Size&, RemotingInterstitialType type)>; |
| 46 // Called by RemoteRendererImpl constructor to set the callback to draw and |
| 47 // show remoting interstial. |
| 48 void SetShowInterstitialCallback(const ShowInterstitialCallback& cb); |
| 49 |
43 base::WeakPtr<RemotingRendererController> GetWeakPtr() { | 50 base::WeakPtr<RemotingRendererController> GetWeakPtr() { |
44 return weak_factory_.GetWeakPtr(); | 51 return weak_factory_.GetWeakPtr(); |
45 } | 52 } |
46 | 53 |
47 // Used by RemotingRendererFactory to query whether to create Media Remoting | 54 // Used by RemotingRendererFactory to query whether to create Media Remoting |
48 // Renderer. | 55 // Renderer. |
49 bool remote_rendering_started() const { | 56 bool remote_rendering_started() const { |
50 DCHECK(thread_checker_.CalledOnValidThread()); | 57 DCHECK(thread_checker_.CalledOnValidThread()); |
51 return remote_rendering_started_; | 58 return remote_rendering_started_; |
52 } | 59 } |
53 | 60 |
54 void StartDataPipe( | 61 void StartDataPipe( |
55 std::unique_ptr<mojo::DataPipe> audio_data_pipe, | 62 std::unique_ptr<mojo::DataPipe> audio_data_pipe, |
56 std::unique_ptr<mojo::DataPipe> video_data_pipe, | 63 std::unique_ptr<mojo::DataPipe> video_data_pipe, |
57 const RemotingSourceImpl::DataPipeStartCallback& done_callback); | 64 const RemotingSourceImpl::DataPipeStartCallback& done_callback); |
58 | 65 |
59 // Used by RemotingRendererImpl to query the session state. | 66 // Used by RemotingRendererImpl to query the session state. |
60 RemotingSourceImpl* remoting_source() const { | 67 RemotingSourceImpl* remoting_source() const { |
61 DCHECK(thread_checker_.CalledOnValidThread()); | 68 DCHECK(thread_checker_.CalledOnValidThread()); |
62 return remoting_source_.get(); | 69 return remoting_source_.get(); |
63 } | 70 } |
64 | 71 |
65 base::WeakPtr<remoting::RpcBroker> GetRpcBroker() const; | 72 base::WeakPtr<remoting::RpcBroker> GetRpcBroker() const; |
66 | 73 |
67 PipelineMetadata pipeline_metadata() const { | |
68 DCHECK(thread_checker_.CalledOnValidThread()); | |
69 return pipeline_metadata_; | |
70 } | |
71 | |
72 private: | 74 private: |
73 bool has_audio() const { | 75 bool has_audio() const { |
74 return pipeline_metadata_.has_audio && | 76 return pipeline_metadata_.has_audio && |
75 pipeline_metadata_.audio_decoder_config.IsValidConfig(); | 77 pipeline_metadata_.audio_decoder_config.IsValidConfig(); |
76 } | 78 } |
77 | 79 |
78 bool has_video() const { | 80 bool has_video() const { |
79 return pipeline_metadata_.has_video && | 81 return pipeline_metadata_.has_video && |
80 pipeline_metadata_.video_decoder_config.IsValidConfig(); | 82 pipeline_metadata_.video_decoder_config.IsValidConfig(); |
81 } | 83 } |
82 | 84 |
83 bool IsVideoCodecSupported(); | 85 bool IsVideoCodecSupported(); |
84 bool IsAudioCodecSupported(); | 86 bool IsAudioCodecSupported(); |
85 | 87 |
86 // Helper to decide whether to enter or leave Remoting mode. | 88 // Helper to decide whether to enter or leave Remoting mode. |
87 bool ShouldBeRemoting(); | 89 bool ShouldBeRemoting(); |
88 | 90 |
89 // Determines whether to enter or leave Remoting mode and switches if | 91 // Determines whether to enter or leave Remoting mode and switches if |
90 // necessary. | 92 // necessary. |
91 void UpdateAndMaybeSwitch(); | 93 void UpdateAndMaybeSwitch(); |
92 | 94 |
| 95 // Called when any of the following happens: |
| 96 // 1. SetShowInterstitialCallback() is called (RemoteRendererImpl is |
| 97 // constructed); |
| 98 // 2. The remoting session is shut down (to update the status message in the |
| 99 // interstitial). |
| 100 // 3. The size of the canvas is changed (to update the background image and |
| 101 // the position of the status message). |
| 102 // TODO(xjz): Call this when poster url is set/changed. Download poster image |
| 103 // when available, and draw interstitial on it. |
| 104 void UpdateInterstitial(); |
| 105 |
93 // Indicates whether this media element or its ancestor is in full screen. | 106 // Indicates whether this media element or its ancestor is in full screen. |
94 bool is_fullscreen_ = false; | 107 bool is_fullscreen_ = false; |
95 | 108 |
96 // Indicates whether remoting is started. | 109 // Indicates whether remoting is started. |
97 bool remote_rendering_started_ = false; | 110 bool remote_rendering_started_ = false; |
98 | 111 |
99 // Indicates whether audio or video is encrypted. | 112 // Indicates whether audio or video is encrypted. |
100 bool is_encrypted_ = false; | 113 bool is_encrypted_ = false; |
101 | 114 |
102 // Current audio/video config. | |
103 VideoDecoderConfig video_decoder_config_; | |
104 AudioDecoderConfig audio_decoder_config_; | |
105 | |
106 // The callback to switch the media renderer. | 115 // The callback to switch the media renderer. |
107 base::Closure switch_renderer_cb_; | 116 base::Closure switch_renderer_cb_; |
108 | 117 |
109 // This is initially the RemotingSourceImpl passed to the ctor, and might be | 118 // This is initially the RemotingSourceImpl passed to the ctor, and might be |
110 // replaced with a different instance later if OnSetCdm() is called. | 119 // replaced with a different instance later if OnSetCdm() is called. |
111 scoped_refptr<RemotingSourceImpl> remoting_source_; | 120 scoped_refptr<RemotingSourceImpl> remoting_source_; |
112 | 121 |
113 // This is used to check all the methods are called on the current thread in | 122 // This is used to check all the methods are called on the current thread in |
114 // debug builds. | 123 // debug builds. |
115 base::ThreadChecker thread_checker_; | 124 base::ThreadChecker thread_checker_; |
116 | 125 |
117 PipelineMetadata pipeline_metadata_; | 126 PipelineMetadata pipeline_metadata_; |
118 | 127 |
| 128 // The callback to show remoting interstitial. It is set when entering the |
| 129 // remoting mode (RemotingRendererImpl is constructed) by calling |
| 130 // SetShowInterstitialCallback(), and is reset when leaving the remoting mode. |
| 131 ShowInterstitialCallback show_interstitial_cb_; |
| 132 |
119 base::WeakPtrFactory<RemotingRendererController> weak_factory_; | 133 base::WeakPtrFactory<RemotingRendererController> weak_factory_; |
120 | 134 |
121 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); | 135 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); |
122 }; | 136 }; |
123 | 137 |
124 } // namespace media | 138 } // namespace media |
125 | 139 |
126 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ | 140 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
OLD | NEW |