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 #include "media/remoting/remoting_renderer_controller.h" | 5 #include "media/remoting/remoting_renderer_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/threading/thread_checker.h" | 9 #include "base/threading/thread_checker.h" |
10 #include "media/base/video_renderer_sink.h" | |
11 #include "media/base/video_util.h" | |
10 #include "media/remoting/remoting_cdm_context.h" | 12 #include "media/remoting/remoting_cdm_context.h" |
13 #include "media/remoting/remoting_interstitial_ui.h" | |
14 #include "skia/ext/image_operations.h" | |
11 | 15 |
12 namespace media { | 16 namespace media { |
13 | 17 |
18 namespace { | |
19 | |
20 gfx::Size GetRotatedVideoSize(VideoRotation rotation, gfx::Size natural_size) { | |
21 if (rotation == VIDEO_ROTATION_90 || rotation == VIDEO_ROTATION_270) | |
22 return gfx::Size(natural_size.height(), natural_size.width()); | |
23 return natural_size; | |
24 } | |
25 | |
26 // Resizes |image| to fit in the center of |canvas_size| and preserves the | |
27 // image's aspect ratio as close as possible. | |
28 SkBitmap ResizeImage(const SkBitmap& image, const gfx::Size& canvas_size) { | |
miu
2016/12/03 01:05:31
This is view, not controller functionality. It sho
xjz
2016/12/06 19:50:55
Done.
| |
29 DCHECK(!canvas_size.IsEmpty()); | |
miu
2016/12/03 01:05:31
ditto here: Maybe this should be:
if (canvas_si
xjz
2016/12/06 19:50:55
Not applicable now. If canvas_size is empty, we wo
| |
30 | |
31 const gfx::Size image_size = gfx::Size(image.width(), image.height()); | |
32 if (image_size == canvas_size) | |
33 return image; | |
34 | |
35 gfx::Size scaled_size = ScaleSizeToFitWithinTarget(image_size, canvas_size); | |
36 if (scaled_size == image_size) | |
37 return image; | |
38 | |
39 return skia::ImageOperations::Resize( | |
40 image, skia::ImageOperations::RESIZE_BEST, scaled_size.width(), | |
41 scaled_size.height()); | |
42 } | |
43 | |
44 } // namespace | |
45 | |
14 RemotingRendererController::RemotingRendererController( | 46 RemotingRendererController::RemotingRendererController( |
15 scoped_refptr<RemotingSourceImpl> remoting_source) | 47 scoped_refptr<RemotingSourceImpl> remoting_source) |
16 : remoting_source_(remoting_source), weak_factory_(this) { | 48 : remoting_source_(remoting_source), weak_factory_(this) { |
17 remoting_source_->AddClient(this); | 49 remoting_source_->AddClient(this); |
18 } | 50 } |
19 | 51 |
20 RemotingRendererController::~RemotingRendererController() { | 52 RemotingRendererController::~RemotingRendererController() { |
21 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
22 remoting_source_->RemoveClient(this); | 54 remoting_source_->RemoveClient(this); |
23 } | 55 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 auto* remoting_cdm_context = RemotingCdmContext::From(cdm_context); | 98 auto* remoting_cdm_context = RemotingCdmContext::From(cdm_context); |
67 if (!remoting_cdm_context) | 99 if (!remoting_cdm_context) |
68 return; | 100 return; |
69 | 101 |
70 remoting_source_->RemoveClient(this); | 102 remoting_source_->RemoveClient(this); |
71 remoting_source_ = remoting_cdm_context->GetRemotingSource(); | 103 remoting_source_ = remoting_cdm_context->GetRemotingSource(); |
72 remoting_source_->AddClient(this); // Calls OnSessionStateChanged(). | 104 remoting_source_->AddClient(this); // Calls OnSessionStateChanged(). |
73 UpdateAndMaybeSwitch(); | 105 UpdateAndMaybeSwitch(); |
74 } | 106 } |
75 | 107 |
108 void RemotingRendererController::OnSetPoster(const GURL& poster) { | |
109 DCHECK(thread_checker_.CalledOnValidThread()); | |
110 | |
111 // Clear |post_image_| if url changes. | |
112 SkBitmap empty; | |
113 if (poster != poster_) | |
114 poster_image_.swap(empty); | |
115 | |
116 poster_ = poster; | |
miu
2016/12/03 01:05:31
If the URL has changed, we need to re-render a new
xjz
2016/12/06 19:50:55
Done.
| |
117 } | |
118 | |
76 void RemotingRendererController::SetSwitchRendererCallback( | 119 void RemotingRendererController::SetSwitchRendererCallback( |
77 const base::Closure& cb) { | 120 const base::Closure& cb) { |
78 DCHECK(thread_checker_.CalledOnValidThread()); | 121 DCHECK(thread_checker_.CalledOnValidThread()); |
79 DCHECK(!cb.is_null()); | 122 DCHECK(!cb.is_null()); |
80 | 123 |
81 switch_renderer_cb_ = cb; | 124 switch_renderer_cb_ = cb; |
82 UpdateAndMaybeSwitch(); | 125 UpdateAndMaybeSwitch(); |
83 } | 126 } |
84 | 127 |
85 base::WeakPtr<remoting::RpcBroker> RemotingRendererController::GetRpcBroker() | 128 base::WeakPtr<remoting::RpcBroker> RemotingRendererController::GetRpcBroker() |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 // For encrypted content, it's only valid to switch to remoting renderer, | 279 // For encrypted content, it's only valid to switch to remoting renderer, |
237 // and never back to the local renderer. The RemotingCdmController will | 280 // and never back to the local renderer. The RemotingCdmController will |
238 // force-stop the session when remoting has ended; so no need to call | 281 // force-stop the session when remoting has ended; so no need to call |
239 // StopRemoting() from here. | 282 // StopRemoting() from here. |
240 DCHECK(!is_encrypted_); | 283 DCHECK(!is_encrypted_); |
241 switch_renderer_cb_.Run(); | 284 switch_renderer_cb_.Run(); |
242 remoting_source_->StopRemoting(this); | 285 remoting_source_->StopRemoting(this); |
243 } | 286 } |
244 } | 287 } |
245 | 288 |
289 void RemotingRendererController::SetDownloadPosterCallback( | |
290 const DownloadPosterCallback& cb) { | |
291 DCHECK(thread_checker_.CalledOnValidThread()); | |
292 DCHECK(download_poster_cb_.is_null()); | |
293 download_poster_cb_ = cb; | |
294 } | |
295 | |
296 void RemotingRendererController::ShowInterstitial( | |
297 VideoRendererSink* video_renderer_sink) { | |
298 if (!video_renderer_sink) | |
miu
2016/12/03 01:05:31
Please add: DCHECK(thread_checker_.CalledOnValidTh
xjz
2016/12/06 19:50:55
Done.
| |
299 return; | |
300 | |
301 if (poster_image_.drawsNothing() && !poster_.is_empty() && | |
302 !download_poster_cb_.is_null()) { | |
303 download_poster_cb_.Run( | |
304 poster_, base::Bind(&RemotingRendererController::PosterImageDownloaded, | |
305 weak_factory_.GetWeakPtr(), video_renderer_sink)); | |
306 } else { | |
307 ShowInterstitialOnSink( | |
308 video_renderer_sink, SkBitmap(), | |
309 GetRotatedVideoSize(pipeline_metadata_.video_rotation, | |
310 pipeline_metadata_.natural_size), | |
311 remoting_source_->state() == RemotingSessionState::SESSION_STARTED); | |
312 } | |
313 } | |
314 | |
315 void RemotingRendererController::PosterImageDownloaded( | |
316 VideoRendererSink* video_renderer_sink, | |
317 const SkBitmap& image) { | |
318 DCHECK(poster_image_.drawsNothing()); | |
miu
2016/12/03 01:05:31
ditto: Please add DCHECK(thread_checker_.CalledOnV
xjz
2016/12/06 19:50:55
Done.
| |
319 DCHECK(video_renderer_sink); | |
320 | |
321 const gfx::Size canvas_size = GetRotatedVideoSize( | |
miu
2016/12/03 01:05:31
The rest of this method is view, not controller fu
xjz
2016/12/06 19:50:55
Done. Added a callback to RemotingRendererControll
| |
322 pipeline_metadata_.video_rotation, pipeline_metadata_.natural_size); | |
323 | |
324 if (!image.drawsNothing()) { | |
325 poster_image_ = ResizeImage(image, canvas_size); | |
326 } | |
327 | |
328 ShowInterstitialOnSink( | |
329 video_renderer_sink, poster_image_, canvas_size, | |
330 remoting_source_->state() == RemotingSessionState::SESSION_STARTED); | |
331 } | |
332 | |
246 } // namespace media | 333 } // namespace media |
OLD | NEW |