| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/protocol/webrtc_video_renderer_adapter.h" | 5 #include "remoting/protocol/webrtc_video_renderer_adapter.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 void WebrtcVideoRendererAdapter::OnFrame(const cricket::VideoFrame& frame) { | 55 void WebrtcVideoRendererAdapter::OnFrame(const cricket::VideoFrame& frame) { |
| 56 // TODO(sergeyu): WebRTC calls OnFrame on a separate thread it creates. | 56 // TODO(sergeyu): WebRTC calls OnFrame on a separate thread it creates. |
| 57 // FrameConsumer normally expects to be called on the network thread, so we | 57 // FrameConsumer normally expects to be called on the network thread, so we |
| 58 // cannot call FrameConsumer::AllocateFrame() here and instead | 58 // cannot call FrameConsumer::AllocateFrame() here and instead |
| 59 // BasicDesktopFrame is created directly. This will not work correctly with | 59 // BasicDesktopFrame is created directly. This will not work correctly with |
| 60 // all FrameConsumer implementations. Fix this somehow. | 60 // all FrameConsumer implementations. Fix this somehow. |
| 61 std::unique_ptr<webrtc::DesktopFrame> rgb_frame(new webrtc::BasicDesktopFrame( | 61 std::unique_ptr<webrtc::DesktopFrame> rgb_frame(new webrtc::BasicDesktopFrame( |
| 62 webrtc::DesktopSize(frame.width(), frame.height()))); | 62 webrtc::DesktopSize(frame.width(), frame.height()))); |
| 63 | 63 |
| 64 base::TimeDelta render_delay = std::max( |
| 65 base::TimeDelta(), base::TimeDelta::FromMicroseconds(static_cast<float>( |
| 66 frame.timestamp_us() - rtc::TimeMicros()))); |
| 67 |
| 64 frame.ConvertToRgbBuffer( | 68 frame.ConvertToRgbBuffer( |
| 65 output_format_fourcc_, rgb_frame->data(), | 69 output_format_fourcc_, rgb_frame->data(), |
| 66 std::abs(rgb_frame->stride()) * rgb_frame->size().height(), | 70 std::abs(rgb_frame->stride()) * rgb_frame->size().height(), |
| 67 rgb_frame->stride()); | 71 rgb_frame->stride()); |
| 68 rgb_frame->mutable_updated_region()->AddRect( | 72 rgb_frame->mutable_updated_region()->AddRect( |
| 69 webrtc::DesktopRect::MakeSize(rgb_frame->size())); | 73 webrtc::DesktopRect::MakeSize(rgb_frame->size())); |
| 70 task_runner_->PostTask( | 74 task_runner_->PostDelayedTask( |
| 71 FROM_HERE, | 75 FROM_HERE, |
| 72 base::Bind(&WebrtcVideoRendererAdapter::DrawFrame, | 76 base::Bind(&WebrtcVideoRendererAdapter::DrawFrame, |
| 73 weak_factory_.GetWeakPtr(), base::Passed(&rgb_frame))); | 77 weak_factory_.GetWeakPtr(), base::Passed(&rgb_frame)), |
| 78 render_delay); |
| 74 } | 79 } |
| 75 | 80 |
| 76 void WebrtcVideoRendererAdapter::DrawFrame( | 81 void WebrtcVideoRendererAdapter::DrawFrame( |
| 77 std::unique_ptr<webrtc::DesktopFrame> frame) { | 82 std::unique_ptr<webrtc::DesktopFrame> frame) { |
| 78 DCHECK(task_runner_->BelongsToCurrentThread()); | 83 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 79 frame_consumer_->DrawFrame(std::move(frame), base::Closure()); | 84 frame_consumer_->DrawFrame(std::move(frame), base::Closure()); |
| 80 } | 85 } |
| 81 | 86 |
| 82 } // namespace protocol | 87 } // namespace protocol |
| 83 } // namespace remoting | 88 } // namespace remoting |
| OLD | NEW |