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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 | 39 |
40 if (video_tracks.size() > 1U) { | 40 if (video_tracks.size() > 1U) { |
41 LOG(WARNING) << "Received media stream with multiple video tracks."; | 41 LOG(WARNING) << "Received media stream with multiple video tracks."; |
42 } | 42 } |
43 | 43 |
44 video_tracks[0]->AddOrUpdateSink(this, rtc::VideoSinkWants()); | 44 video_tracks[0]->AddOrUpdateSink(this, rtc::VideoSinkWants()); |
45 } | 45 } |
46 | 46 |
47 WebrtcVideoRendererAdapter::~WebrtcVideoRendererAdapter() { | 47 WebrtcVideoRendererAdapter::~WebrtcVideoRendererAdapter() { |
48 DCHECK(task_runner_->BelongsToCurrentThread()); | 48 DCHECK(task_runner_->BelongsToCurrentThread()); |
49 | |
50 webrtc::VideoTrackVector video_tracks = media_stream_->GetVideoTracks(); | |
51 if (video_tracks.empty()) | |
Sergey Ulanov
2016/03/31 22:06:19
I think this can be replaced with a DCHECK()
Irfan
2016/04/05 21:23:28
Done.
| |
52 return; | |
53 video_tracks[0]->RemoveSink(this); | |
49 } | 54 } |
50 | 55 |
51 void WebrtcVideoRendererAdapter::OnFrame(const cricket::VideoFrame& frame) { | 56 void WebrtcVideoRendererAdapter::OnFrame(const cricket::VideoFrame& frame) { |
52 // TODO(sergeyu): WebRTC calls OnFrame on a separate thread it creates. | 57 // TODO(sergeyu): WebRTC calls OnFrame on a separate thread it creates. |
53 // FrameConsumer normally expects to be called on the network thread, so we | 58 // FrameConsumer normally expects to be called on the network thread, so we |
54 // cannot call FrameConsumer::AllocateFrame() here and instead | 59 // cannot call FrameConsumer::AllocateFrame() here and instead |
55 // BasicDesktopFrame is created directly. This will not work correctly with | 60 // BasicDesktopFrame is created directly. This will not work correctly with |
56 // all FrameConsumer implementations. Fix this somehow. | 61 // all FrameConsumer implementations. Fix this somehow. |
57 scoped_ptr<webrtc::DesktopFrame> rgb_frame(new webrtc::BasicDesktopFrame( | 62 scoped_ptr<webrtc::DesktopFrame> rgb_frame(new webrtc::BasicDesktopFrame( |
58 webrtc::DesktopSize(frame.GetWidth(), frame.GetHeight()))); | 63 webrtc::DesktopSize(frame.GetWidth(), frame.GetHeight()))); |
59 | 64 |
60 frame.ConvertToRgbBuffer( | 65 frame.ConvertToRgbBuffer( |
61 output_format_fourcc_, rgb_frame->data(), | 66 output_format_fourcc_, rgb_frame->data(), |
62 std::abs(rgb_frame->stride()) * rgb_frame->size().height(), | 67 std::abs(rgb_frame->stride()) * rgb_frame->size().height(), |
63 rgb_frame->stride()); | 68 rgb_frame->stride()); |
64 rgb_frame->mutable_updated_region()->AddRect( | 69 rgb_frame->mutable_updated_region()->AddRect( |
65 webrtc::DesktopRect::MakeSize(rgb_frame->size())); | 70 webrtc::DesktopRect::MakeSize(rgb_frame->size())); |
66 task_runner_->PostTask( | 71 task_runner_->PostTask( |
67 FROM_HERE, | 72 FROM_HERE, |
68 base::Bind(&WebrtcVideoRendererAdapter::DrawFrame, | 73 base::Bind(&WebrtcVideoRendererAdapter::DrawFrame, |
69 weak_factory_.GetWeakPtr(), base::Passed(&rgb_frame))); | 74 weak_factory_.GetWeakPtr(), base::Passed(&rgb_frame))); |
70 } | 75 } |
71 | 76 |
72 void WebrtcVideoRendererAdapter::DrawFrame( | 77 void WebrtcVideoRendererAdapter::DrawFrame( |
73 scoped_ptr<webrtc::DesktopFrame> frame) { | 78 scoped_ptr<webrtc::DesktopFrame> frame) { |
74 DCHECK(task_runner_->BelongsToCurrentThread()); | 79 DCHECK(task_runner_->BelongsToCurrentThread()); |
75 frame_consumer_->DrawFrame(std::move(frame), base::Closure()); | 80 frame_consumer_->DrawFrame(std::move(frame), base::Closure()); |
76 } | 81 } |
77 | 82 |
83 } // namespace protocol | |
78 } // namespace remoting | 84 } // namespace remoting |
79 } // namespace protocol | |
OLD | NEW |