Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: content/renderer/media/webrtc/media_stream_remote_video_source.cc

Issue 877283004: MediaStreamRemoteVideoSource: Wrap cricket::VideoFrame instead of copying. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduce |is_read_only_| to media::VideoFrame Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/base/video_frame.h » ('j') | media/base/video_frame.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/media/webrtc/media_stream_remote_video_source.h" 5 #include "content/renderer/media/webrtc/media_stream_remote_video_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/threading/thread_checker.h" 11 #include "base/threading/thread_checker.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "content/renderer/media/native_handle_impl.h" 13 #include "content/renderer/media/native_handle_impl.h"
14 #include "content/renderer/media/webrtc/track_observer.h" 14 #include "content/renderer/media/webrtc/track_observer.h"
15 #include "media/base/bind_to_current_loop.h" 15 #include "media/base/bind_to_current_loop.h"
16 #include "media/base/video_frame.h" 16 #include "media/base/video_frame.h"
17 #include "media/base/video_frame_pool.h"
18 #include "media/base/video_util.h" 17 #include "media/base/video_util.h"
19 #include "third_party/libjingle/source/talk/media/base/videoframe.h" 18 #include "third_party/libjingle/source/talk/media/base/videoframe.h"
20 19
21 namespace content { 20 namespace content {
22 21
23 // Internal class used for receiving frames from the webrtc track on a 22 // Internal class used for receiving frames from the webrtc track on a
24 // libjingle thread and forward it to the IO-thread. 23 // libjingle thread and forward it to the IO-thread.
25 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate 24 class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate
26 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>, 25 : public base::RefCountedThreadSafe<RemoteVideoSourceDelegate>,
27 public webrtc::VideoRendererInterface { 26 public webrtc::VideoRendererInterface {
(...skipping 13 matching lines...) Expand all
41 void RenderFrame(const cricket::VideoFrame* frame) override; 40 void RenderFrame(const cricket::VideoFrame* frame) override;
42 41
43 void DoRenderFrameOnIOThread( 42 void DoRenderFrameOnIOThread(
44 const scoped_refptr<media::VideoFrame>& video_frame); 43 const scoped_refptr<media::VideoFrame>& video_frame);
45 44
46 private: 45 private:
47 // Bound to the render thread. 46 // Bound to the render thread.
48 base::ThreadChecker thread_checker_; 47 base::ThreadChecker thread_checker_;
49 48
50 scoped_refptr<base::MessageLoopProxy> io_message_loop_; 49 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
51 // |frame_pool_| is only accessed on whatever
52 // thread webrtc::VideoRendererInterface::RenderFrame is called on.
53 media::VideoFramePool frame_pool_;
54 50
55 // |frame_callback_| is accessed on the IO thread. 51 // |frame_callback_| is accessed on the IO thread.
56 VideoCaptureDeliverFrameCB frame_callback_; 52 VideoCaptureDeliverFrameCB frame_callback_;
57 }; 53 };
58 54
59 MediaStreamRemoteVideoSource:: 55 MediaStreamRemoteVideoSource::
60 RemoteVideoSourceDelegate::RemoteVideoSourceDelegate( 56 RemoteVideoSourceDelegate::RemoteVideoSourceDelegate(
61 const scoped_refptr<base::MessageLoopProxy>& io_message_loop, 57 const scoped_refptr<base::MessageLoopProxy>& io_message_loop,
62 const VideoCaptureDeliverFrameCB& new_frame_callback) 58 const VideoCaptureDeliverFrameCB& new_frame_callback)
63 : io_message_loop_(io_message_loop), 59 : io_message_loop_(io_message_loop),
(...skipping 16 matching lines...) Expand all
80 frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec); 76 frame->GetElapsedTime() / rtc::kNumNanosecsPerMicrosec);
81 77
82 scoped_refptr<media::VideoFrame> video_frame; 78 scoped_refptr<media::VideoFrame> video_frame;
83 if (frame->GetNativeHandle() != NULL) { 79 if (frame->GetNativeHandle() != NULL) {
84 NativeHandleImpl* handle = 80 NativeHandleImpl* handle =
85 static_cast<NativeHandleImpl*>(frame->GetNativeHandle()); 81 static_cast<NativeHandleImpl*>(frame->GetNativeHandle());
86 video_frame = static_cast<media::VideoFrame*>(handle->GetHandle()); 82 video_frame = static_cast<media::VideoFrame*>(handle->GetHandle());
87 video_frame->set_timestamp(timestamp); 83 video_frame->set_timestamp(timestamp);
88 } else { 84 } else {
89 gfx::Size size(frame->GetWidth(), frame->GetHeight()); 85 gfx::Size size(frame->GetWidth(), frame->GetHeight());
90 video_frame = frame_pool_.CreateFrame(
91 media::VideoFrame::YV12, size, gfx::Rect(size), size, timestamp);
92 86
93 // Non-square pixels are unsupported. 87 // Non-square pixels are unsupported.
94 DCHECK_EQ(frame->GetPixelWidth(), 1u); 88 DCHECK_EQ(frame->GetPixelWidth(), 1u);
95 DCHECK_EQ(frame->GetPixelHeight(), 1u); 89 DCHECK_EQ(frame->GetPixelHeight(), 1u);
96 90
97 int y_rows = frame->GetHeight(); 91 // Make a shallow copy. Both |frame| and |video_frame| will share a single
98 int uv_rows = frame->GetChromaHeight(); 92 // reference counted frame buffer.
99 CopyYPlane( 93 video_frame = media::VideoFrame::WrapExternalYuvConstData(
100 frame->GetYPlane(), frame->GetYPitch(), y_rows, video_frame.get()); 94 media::VideoFrame::YV12, size, gfx::Rect(size), size,
101 CopyUPlane( 95 frame->GetYPitch(), frame->GetUPitch(), frame->GetVPitch(),
102 frame->GetUPlane(), frame->GetUPitch(), uv_rows, video_frame.get()); 96 frame->GetYPlane(), frame->GetUPlane(), frame->GetVPlane(), timestamp,
mcasas 2015/03/06 17:29:59 If I read correctly [1], there is a non-const vers
magjed_chromium 2015/03/07 14:15:10 Yes we can reuse WrapExternalYuvData, by const cas
103 CopyVPlane( 97 base::Bind(&base::DeletePointer<cricket::VideoFrame>, frame->Copy()));
104 frame->GetVPlane(), frame->GetVPitch(), uv_rows, video_frame.get());
105 } 98 }
106 99
107 io_message_loop_->PostTask( 100 io_message_loop_->PostTask(
108 FROM_HERE, 101 FROM_HERE,
109 base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread, 102 base::Bind(&RemoteVideoSourceDelegate::DoRenderFrameOnIOThread,
110 this, video_frame)); 103 this, video_frame));
111 } 104 }
112 105
113 void MediaStreamRemoteVideoSource:: 106 void MediaStreamRemoteVideoSource::
114 RemoteVideoSourceDelegate::DoRenderFrameOnIOThread( 107 RemoteVideoSourceDelegate::DoRenderFrameOnIOThread(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 case webrtc::MediaStreamTrackInterface::kEnded: 176 case webrtc::MediaStreamTrackInterface::kEnded:
184 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); 177 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded);
185 break; 178 break;
186 default: 179 default:
187 NOTREACHED(); 180 NOTREACHED();
188 break; 181 break;
189 } 182 }
190 } 183 }
191 184
192 } // namespace content 185 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | media/base/video_frame.h » ('j') | media/base/video_frame.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698