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. | 98 video_renderer_sink_->PaintSingleFrame( |
108 if (interstitial_type_ != InterstitialType::BETWEEN_SESSIONS) { | 99 VideoFrame::CreateBlackFrame(gfx::Size(1280, 720))); |
109 scoped_refptr<VideoFrame> frame = | |
110 VideoFrame::CreateBlackFrame(gfx::Size(1280, 720)); | |
111 PaintInterstitial(frame, InterstitialType::BETWEEN_SESSIONS); | |
112 } | 100 } |
113 } | 101 } |
114 | 102 |
115 void CourierRenderer::Initialize(MediaResource* media_resource, | 103 void CourierRenderer::Initialize(MediaResource* media_resource, |
116 RendererClient* client, | 104 RendererClient* client, |
117 const PipelineStatusCB& init_cb) { | 105 const PipelineStatusCB& init_cb) { |
118 VLOG(2) << __func__; | 106 VLOG(2) << __func__; |
119 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 107 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
120 DCHECK(media_resource); | 108 DCHECK(media_resource); |
121 DCHECK(client); | 109 DCHECK(client); |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 // just run the callback without reporting error. | 678 // just run the callback without reporting error. |
691 if (!init_workflow_done_callback_.is_null()) { | 679 if (!init_workflow_done_callback_.is_null()) { |
692 base::ResetAndReturn(&init_workflow_done_callback_).Run(PIPELINE_OK); | 680 base::ResetAndReturn(&init_workflow_done_callback_).Run(PIPELINE_OK); |
693 return; | 681 return; |
694 } | 682 } |
695 | 683 |
696 if (!flush_cb_.is_null()) | 684 if (!flush_cb_.is_null()) |
697 base::ResetAndReturn(&flush_cb_).Run(); | 685 base::ResetAndReturn(&flush_cb_).Run(); |
698 } | 686 } |
699 | 687 |
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() { | 688 void CourierRenderer::OnMediaTimeUpdated() { |
730 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 689 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
731 if (!flush_cb_.is_null()) | 690 if (!flush_cb_.is_null()) |
732 return; // Don't manage and check the queue when Flush() is on-going. | 691 return; // Don't manage and check the queue when Flush() is on-going. |
733 | 692 |
734 base::TimeTicks current_time = clock_->NowTicks(); | 693 base::TimeTicks current_time = clock_->NowTicks(); |
735 if (current_time < ignore_updates_until_time_) | 694 if (current_time < ignore_updates_until_time_) |
736 return; // Not stable yet. | 695 return; // Not stable yet. |
737 | 696 |
738 media_time_queue_.push_back( | 697 media_time_queue_.push_back( |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 kBytesPerKilobit; | 820 kBytesPerKilobit; |
862 DCHECK_GE(kilobits_per_second, 0); | 821 DCHECK_GE(kilobits_per_second, 0); |
863 const base::CheckedNumeric<int> checked_kbps = kilobits_per_second; | 822 const base::CheckedNumeric<int> checked_kbps = kilobits_per_second; |
864 metrics_recorder_.OnVideoRateEstimate( | 823 metrics_recorder_.OnVideoRateEstimate( |
865 checked_kbps.ValueOrDefault(std::numeric_limits<int>::max())); | 824 checked_kbps.ValueOrDefault(std::numeric_limits<int>::max())); |
866 } | 825 } |
867 } | 826 } |
868 | 827 |
869 } // namespace remoting | 828 } // namespace remoting |
870 } // namespace media | 829 } // namespace media |
OLD | NEW |