Chromium Code Reviews| 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/courier_renderer.h" | 5 #include "media/remoting/courier_renderer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 rpc_broker_(controller_->GetRpcBroker()), | 72 rpc_broker_(controller_->GetRpcBroker()), |
| 73 rpc_handle_(rpc_broker_->GetUniqueHandle()), | 73 rpc_handle_(rpc_broker_->GetUniqueHandle()), |
| 74 remote_renderer_handle_(RpcBroker::kInvalidHandle), | 74 remote_renderer_handle_(RpcBroker::kInvalidHandle), |
| 75 video_renderer_sink_(video_renderer_sink), | 75 video_renderer_sink_(video_renderer_sink), |
| 76 clock_(new base::DefaultTickClock()), | 76 clock_(new base::DefaultTickClock()), |
| 77 weak_factory_(this) { | 77 weak_factory_(this) { |
| 78 VLOG(2) << __func__; | 78 VLOG(2) << __func__; |
| 79 // Note: The constructor is running on the main thread, but will be destroyed | 79 // Note: The constructor is running on the main thread, but will be destroyed |
| 80 // on the media thread. Therefore, all weak pointers must be dereferenced on | 80 // on the media thread. Therefore, all weak pointers must be dereferenced on |
| 81 // the media thread. | 81 // the media thread. |
| 82 controller_->SetShowInterstitialCallback( | |
| 83 base::Bind(&CourierRenderer::RenderInterstitialAndShow, | |
| 84 media_task_runner_, weak_factory_.GetWeakPtr())); | |
| 85 const RpcBroker::ReceiveMessageCallback receive_callback = | 82 const RpcBroker::ReceiveMessageCallback receive_callback = |
| 86 base::Bind(&CourierRenderer::OnMessageReceivedOnMainThread, | 83 base::Bind(&CourierRenderer::OnMessageReceivedOnMainThread, |
| 87 media_task_runner_, weak_factory_.GetWeakPtr()); | 84 media_task_runner_, weak_factory_.GetWeakPtr()); |
| 88 rpc_broker_->RegisterMessageReceiverCallback(rpc_handle_, receive_callback); | 85 rpc_broker_->RegisterMessageReceiverCallback(rpc_handle_, receive_callback); |
| 89 } | 86 } |
| 90 | 87 |
| 91 CourierRenderer::~CourierRenderer() { | 88 CourierRenderer::~CourierRenderer() { |
| 92 VLOG(2) << __func__; | 89 VLOG(2) << __func__; |
| 93 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 90 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 94 | 91 |
| 95 // Post task on main thread to unset the interstial callback. | |
| 96 main_task_runner_->PostTask( | |
| 97 FROM_HERE, | |
| 98 base::Bind(&RendererController::SetShowInterstitialCallback, controller_, | |
| 99 RendererController::ShowInterstitialCallback())); | |
| 100 | |
| 101 // Post task on main thread to unregister message receiver. | 92 // Post task on main thread to unregister message receiver. |
| 102 main_task_runner_->PostTask( | 93 main_task_runner_->PostTask( |
| 103 FROM_HERE, base::Bind(&RpcBroker::UnregisterMessageReceiverCallback, | 94 FROM_HERE, base::Bind(&RpcBroker::UnregisterMessageReceiverCallback, |
| 104 rpc_broker_, rpc_handle_)); | 95 rpc_broker_, rpc_handle_)); |
| 105 | 96 |
| 106 // If the "between sessions" interstitial is not the one currently showing, | 97 if (video_renderer_sink_) { |
| 107 // paint a blank black frame to clear remoting messaging. | |
| 108 if (interstitial_type_ != InterstitialType::BETWEEN_SESSIONS) { | |
| 109 scoped_refptr<VideoFrame> frame = | 98 scoped_refptr<VideoFrame> frame = |
| 110 VideoFrame::CreateBlackFrame(gfx::Size(1280, 720)); | 99 VideoFrame::CreateBlackFrame(gfx::Size(1280, 720)); |
| 111 PaintInterstitial(frame, InterstitialType::BETWEEN_SESSIONS); | 100 video_renderer_sink_->PaintSingleFrame(frame); |
|
miu
2017/04/13 02:15:10
nit: One statement please (avoids an extra ref/der
xjz
2017/04/13 23:48:36
Done.
| |
| 112 } | 101 } |
| 113 } | 102 } |
| 114 | 103 |
| 115 void CourierRenderer::Initialize(MediaResource* media_resource, | 104 void CourierRenderer::Initialize(MediaResource* media_resource, |
| 116 RendererClient* client, | 105 RendererClient* client, |
| 117 const PipelineStatusCB& init_cb) { | 106 const PipelineStatusCB& init_cb) { |
| 118 VLOG(2) << __func__; | 107 VLOG(2) << __func__; |
| 119 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 108 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 120 DCHECK(media_resource); | 109 DCHECK(media_resource); |
| 121 DCHECK(client); | 110 DCHECK(client); |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 // just run the callback without reporting error. | 679 // just run the callback without reporting error. |
| 691 if (!init_workflow_done_callback_.is_null()) { | 680 if (!init_workflow_done_callback_.is_null()) { |
| 692 base::ResetAndReturn(&init_workflow_done_callback_).Run(PIPELINE_OK); | 681 base::ResetAndReturn(&init_workflow_done_callback_).Run(PIPELINE_OK); |
| 693 return; | 682 return; |
| 694 } | 683 } |
| 695 | 684 |
| 696 if (!flush_cb_.is_null()) | 685 if (!flush_cb_.is_null()) |
| 697 base::ResetAndReturn(&flush_cb_).Run(); | 686 base::ResetAndReturn(&flush_cb_).Run(); |
| 698 } | 687 } |
| 699 | 688 |
| 700 // static | |
| 701 void CourierRenderer::RenderInterstitialAndShow( | |
| 702 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, | |
| 703 base::WeakPtr<CourierRenderer> self, | |
| 704 const SkBitmap& background, | |
| 705 const gfx::Size& natural_size, | |
| 706 InterstitialType type) { | |
| 707 // Note: This is running on the main thread. |self| must only be dereferenced | |
| 708 // on the media thread. | |
| 709 scoped_refptr<VideoFrame> frame = | |
| 710 RenderInterstitialFrame(background, natural_size, type); | |
| 711 if (!frame) { | |
| 712 NOTREACHED(); | |
| 713 return; | |
| 714 } | |
| 715 media_task_runner->PostTask( | |
| 716 FROM_HERE, base::Bind(&CourierRenderer::PaintInterstitial, self, | |
| 717 std::move(frame), type)); | |
| 718 } | |
| 719 | |
| 720 void CourierRenderer::PaintInterstitial(scoped_refptr<VideoFrame> frame, | |
| 721 InterstitialType type) { | |
| 722 DCHECK(media_task_runner_->BelongsToCurrentThread()); | |
| 723 interstitial_type_ = type; | |
| 724 if (!video_renderer_sink_) | |
| 725 return; | |
| 726 video_renderer_sink_->PaintSingleFrame(frame); | |
| 727 } | |
| 728 | |
| 729 void CourierRenderer::OnMediaTimeUpdated() { | 689 void CourierRenderer::OnMediaTimeUpdated() { |
| 730 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 690 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 731 if (!flush_cb_.is_null()) | 691 if (!flush_cb_.is_null()) |
| 732 return; // Don't manage and check the queue when Flush() is on-going. | 692 return; // Don't manage and check the queue when Flush() is on-going. |
| 733 | 693 |
| 734 base::TimeTicks current_time = clock_->NowTicks(); | 694 base::TimeTicks current_time = clock_->NowTicks(); |
| 735 if (current_time < ignore_updates_until_time_) | 695 if (current_time < ignore_updates_until_time_) |
| 736 return; // Not stable yet. | 696 return; // Not stable yet. |
| 737 | 697 |
| 738 media_time_queue_.push_back( | 698 media_time_queue_.push_back( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 kBytesPerKilobit; | 821 kBytesPerKilobit; |
| 862 DCHECK_GE(kilobits_per_second, 0); | 822 DCHECK_GE(kilobits_per_second, 0); |
| 863 const base::CheckedNumeric<int> checked_kbps = kilobits_per_second; | 823 const base::CheckedNumeric<int> checked_kbps = kilobits_per_second; |
| 864 metrics_recorder_.OnVideoRateEstimate( | 824 metrics_recorder_.OnVideoRateEstimate( |
| 865 checked_kbps.ValueOrDefault(std::numeric_limits<int>::max())); | 825 checked_kbps.ValueOrDefault(std::numeric_limits<int>::max())); |
| 866 } | 826 } |
| 867 } | 827 } |
| 868 | 828 |
| 869 } // namespace remoting | 829 } // namespace remoting |
| 870 } // namespace media | 830 } // namespace media |
| OLD | NEW |