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_source_impl.h" | 11 #include "media/remoting/remoting_source_impl.h" |
12 #include "third_party/skia/include/core/SkBitmap.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 |
20 class VideoRendererSink; | |
21 | |
19 // This class: | 22 // This class: |
20 // 1) Implements the RemotingSourceImpl::Client; | 23 // 1) Implements the RemotingSourceImpl::Client; |
21 // 2) Monitors player events as a MediaObserver; | 24 // 2) Monitors player events as a MediaObserver; |
22 // 3) May trigger the switch of the media renderer between local playback | 25 // 3) May trigger the switch of the media renderer between local playback |
23 // and remoting. | 26 // and remoting. |
24 class RemotingRendererController final : public RemotingSourceImpl::Client, | 27 class RemotingRendererController final : public RemotingSourceImpl::Client, |
25 public MediaObserver { | 28 public MediaObserver { |
26 public: | 29 public: |
27 explicit RemotingRendererController( | 30 explicit RemotingRendererController( |
28 scoped_refptr<RemotingSourceImpl> remoting_source); | 31 scoped_refptr<RemotingSourceImpl> remoting_source); |
29 ~RemotingRendererController() override; | 32 ~RemotingRendererController() override; |
30 | 33 |
31 // RemotingSourceImpl::Client implemenations. | 34 // RemotingSourceImpl::Client implemenations. |
32 void OnStarted(bool success) override; | 35 void OnStarted(bool success) override; |
33 void OnSessionStateChanged() override; | 36 void OnSessionStateChanged() override; |
34 | 37 |
35 // MediaObserver implementations. | 38 // MediaObserver implementations. |
36 void OnEnteredFullscreen() override; | 39 void OnEnteredFullscreen() override; |
37 void OnExitedFullscreen() override; | 40 void OnExitedFullscreen() override; |
38 void OnSetCdm(CdmContext* cdm_context) override; | 41 void OnSetCdm(CdmContext* cdm_context) override; |
39 void OnMetadataChanged(const PipelineMetadata& metadata) override; | 42 void OnMetadataChanged(const PipelineMetadata& metadata) override; |
43 void OnSetPoster(const GURL& poster) override; | |
40 | 44 |
41 void SetSwitchRendererCallback(const base::Closure& cb); | 45 void SetSwitchRendererCallback(const base::Closure& cb); |
42 | 46 |
47 using DownloadPosterCallback = | |
48 base::Callback<void(const GURL&, | |
49 const base::Callback<void(const SkBitmap& image)>&)>; | |
50 // Set the callback to download poster image. Can only be called once. | |
51 void SetDownloadPosterCallback(const DownloadPosterCallback& cb); | |
52 | |
53 // Called by RemoteRendererImpl to show remoting interstitial. | |
54 // Do nothing if |video_renderer_sink| is null. | |
55 void ShowInterstitial(VideoRendererSink* video_renderer_sink); | |
56 | |
43 base::WeakPtr<RemotingRendererController> GetWeakPtr() { | 57 base::WeakPtr<RemotingRendererController> GetWeakPtr() { |
44 return weak_factory_.GetWeakPtr(); | 58 return weak_factory_.GetWeakPtr(); |
45 } | 59 } |
46 | 60 |
47 // Used by RemotingRendererFactory to query whether to create Media Remoting | 61 // Used by RemotingRendererFactory to query whether to create Media Remoting |
48 // Renderer. | 62 // Renderer. |
49 bool remote_rendering_started() const { | 63 bool remote_rendering_started() const { |
50 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
51 return remote_rendering_started_; | 65 return remote_rendering_started_; |
52 } | 66 } |
53 | 67 |
54 void StartDataPipe( | 68 void StartDataPipe( |
55 std::unique_ptr<mojo::DataPipe> audio_data_pipe, | 69 std::unique_ptr<mojo::DataPipe> audio_data_pipe, |
56 std::unique_ptr<mojo::DataPipe> video_data_pipe, | 70 std::unique_ptr<mojo::DataPipe> video_data_pipe, |
57 const RemotingSourceImpl::DataPipeStartCallback& done_callback); | 71 const RemotingSourceImpl::DataPipeStartCallback& done_callback); |
58 | 72 |
59 // Used by RemotingRendererImpl to query the session state. | 73 // Used by RemotingRendererImpl to query the session state. |
60 RemotingSourceImpl* remoting_source() const { | 74 RemotingSourceImpl* remoting_source() const { |
61 DCHECK(thread_checker_.CalledOnValidThread()); | 75 DCHECK(thread_checker_.CalledOnValidThread()); |
62 return remoting_source_.get(); | 76 return remoting_source_.get(); |
63 } | 77 } |
64 | 78 |
65 base::WeakPtr<remoting::RpcBroker> GetRpcBroker() const; | 79 base::WeakPtr<remoting::RpcBroker> GetRpcBroker() const; |
66 | 80 |
67 PipelineMetadata pipeline_metadata() const { | |
68 DCHECK(thread_checker_.CalledOnValidThread()); | |
69 return pipeline_metadata_; | |
70 } | |
71 | |
72 private: | 81 private: |
73 bool has_audio() const { | 82 bool has_audio() const { |
74 return pipeline_metadata_.has_audio && | 83 return pipeline_metadata_.has_audio && |
75 pipeline_metadata_.audio_decoder_config.IsValidConfig(); | 84 pipeline_metadata_.audio_decoder_config.IsValidConfig(); |
76 } | 85 } |
77 | 86 |
78 bool has_video() const { | 87 bool has_video() const { |
79 return pipeline_metadata_.has_video && | 88 return pipeline_metadata_.has_video && |
80 pipeline_metadata_.video_decoder_config.IsValidConfig(); | 89 pipeline_metadata_.video_decoder_config.IsValidConfig(); |
81 } | 90 } |
82 | 91 |
83 bool IsVideoCodecSupported(); | 92 bool IsVideoCodecSupported(); |
84 bool IsAudioCodecSupported(); | 93 bool IsAudioCodecSupported(); |
85 | 94 |
86 // Helper to decide whether to enter or leave Remoting mode. | 95 // Helper to decide whether to enter or leave Remoting mode. |
87 bool ShouldBeRemoting(); | 96 bool ShouldBeRemoting(); |
88 | 97 |
89 // Determines whether to enter or leave Remoting mode and switches if | 98 // Determines whether to enter or leave Remoting mode and switches if |
90 // necessary. | 99 // necessary. |
91 void UpdateAndMaybeSwitch(); | 100 void UpdateAndMaybeSwitch(); |
92 | 101 |
102 // Called when poster image is downloaded. | |
103 void PosterImageDownloaded(VideoRendererSink* video_renderer_sink, | |
104 const SkBitmap& image); | |
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. | 115 // Current audio/video config. |
103 VideoDecoderConfig video_decoder_config_; | 116 VideoDecoderConfig video_decoder_config_; |
104 AudioDecoderConfig audio_decoder_config_; | 117 AudioDecoderConfig audio_decoder_config_; |
105 | 118 |
106 // The callback to switch the media renderer. | 119 // The callback to switch the media renderer. |
107 base::Closure switch_renderer_cb_; | 120 base::Closure switch_renderer_cb_; |
108 | 121 |
109 // This is initially the RemotingSourceImpl passed to the ctor, and might be | 122 // This is initially the RemotingSourceImpl passed to the ctor, and might be |
110 // replaced with a different instance later if OnSetCdm() is called. | 123 // replaced with a different instance later if OnSetCdm() is called. |
111 scoped_refptr<RemotingSourceImpl> remoting_source_; | 124 scoped_refptr<RemotingSourceImpl> remoting_source_; |
112 | 125 |
113 // This is used to check all the methods are called on the current thread in | 126 // This is used to check all the methods are called on the current thread in |
114 // debug builds. | 127 // debug builds. |
115 base::ThreadChecker thread_checker_; | 128 base::ThreadChecker thread_checker_; |
116 | 129 |
117 PipelineMetadata pipeline_metadata_; | 130 PipelineMetadata pipeline_metadata_; |
118 | 131 |
132 GURL poster_; | |
miu
2016/12/03 01:05:31
naming nit: poster_url_
xjz
2016/12/06 19:50:55
Done.
| |
133 | |
134 // The current poster image. Already scaled to fit in the canvas. | |
135 SkBitmap poster_image_; | |
miu
2016/12/03 01:05:31
Per our face-to-face discussion, you shouldn't nee
xjz
2016/12/06 19:50:55
Done.
| |
136 | |
137 DownloadPosterCallback download_poster_cb_; | |
138 | |
119 base::WeakPtrFactory<RemotingRendererController> weak_factory_; | 139 base::WeakPtrFactory<RemotingRendererController> weak_factory_; |
120 | 140 |
121 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); | 141 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); |
122 }; | 142 }; |
123 | 143 |
124 } // namespace media | 144 } // namespace media |
125 | 145 |
126 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ | 146 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
OLD | NEW |