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

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

Issue 282523003: Deliver video frames on libjingle worker thread to WebRtcVideoCapturerAdapter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed the last round. Created 6 years, 7 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 | Annotate | Revision Log
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/webrtc_video_capturer_adapter.h" 5 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/memory/aligned_memory.h" 9 #include "base/memory/aligned_memory.h"
10 #include "media/base/video_frame.h" 10 #include "media/base/video_frame.h"
11 #include "third_party/libyuv/include/libyuv/convert.h" 11 #include "third_party/libyuv/include/libyuv/convert.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 WebRtcVideoCapturerAdapter::WebRtcVideoCapturerAdapter(bool is_screencast) 15 WebRtcVideoCapturerAdapter::WebRtcVideoCapturerAdapter(bool is_screencast)
16 : is_screencast_(is_screencast), 16 : is_screencast_(is_screencast),
17 running_(false), 17 running_(false),
18 buffer_(NULL), 18 buffer_(NULL),
19 buffer_size_(0) { 19 buffer_size_(0) {
20 thread_checker_.DetachFromThread();
20 } 21 }
21 22
22 WebRtcVideoCapturerAdapter::~WebRtcVideoCapturerAdapter() { 23 WebRtcVideoCapturerAdapter::~WebRtcVideoCapturerAdapter() {
23 DVLOG(3) << " WebRtcVideoCapturerAdapter::dtor"; 24 DVLOG(3) << " WebRtcVideoCapturerAdapter::dtor";
24 base::AlignedFree(buffer_); 25 base::AlignedFree(buffer_);
25 } 26 }
26 27
27 cricket::CaptureState WebRtcVideoCapturerAdapter::Start( 28 cricket::CaptureState WebRtcVideoCapturerAdapter::Start(
28 const cricket::VideoFormat& capture_format) { 29 const cricket::VideoFormat& capture_format) {
30 DCHECK(thread_checker_.CalledOnValidThread());
29 DCHECK(!running_); 31 DCHECK(!running_);
30 DVLOG(3) << " WebRtcVideoCapturerAdapter::Start w = " << capture_format.width 32 DVLOG(3) << " WebRtcVideoCapturerAdapter::Start w = " << capture_format.width
31 << " h = " << capture_format.height; 33 << " h = " << capture_format.height;
32 34
33 running_ = true; 35 running_ = true;
34 return cricket::CS_RUNNING; 36 return cricket::CS_RUNNING;
35 } 37 }
36 38
37 void WebRtcVideoCapturerAdapter::Stop() { 39 void WebRtcVideoCapturerAdapter::Stop() {
40 DCHECK(thread_checker_.CalledOnValidThread());
38 DVLOG(3) << " WebRtcVideoCapturerAdapter::Stop "; 41 DVLOG(3) << " WebRtcVideoCapturerAdapter::Stop ";
39 DCHECK(running_); 42 DCHECK(running_);
40 running_ = false; 43 running_ = false;
41 SetCaptureFormat(NULL); 44 SetCaptureFormat(NULL);
42 SignalStateChange(this, cricket::CS_STOPPED); 45 SignalStateChange(this, cricket::CS_STOPPED);
43 } 46 }
44 47
45 bool WebRtcVideoCapturerAdapter::IsRunning() { 48 bool WebRtcVideoCapturerAdapter::IsRunning() {
49 DCHECK(thread_checker_.CalledOnValidThread());
46 return running_; 50 return running_;
47 } 51 }
48 52
49 bool WebRtcVideoCapturerAdapter::GetPreferredFourccs( 53 bool WebRtcVideoCapturerAdapter::GetPreferredFourccs(
50 std::vector<uint32>* fourccs) { 54 std::vector<uint32>* fourccs) {
55 DCHECK(thread_checker_.CalledOnValidThread());
51 if (!fourccs) 56 if (!fourccs)
52 return false; 57 return false;
53 fourccs->push_back(cricket::FOURCC_I420); 58 fourccs->push_back(cricket::FOURCC_I420);
54 return true; 59 return true;
55 } 60 }
56 61
57 bool WebRtcVideoCapturerAdapter::IsScreencast() const { 62 bool WebRtcVideoCapturerAdapter::IsScreencast() const {
58 return is_screencast_; 63 return is_screencast_;
59 } 64 }
60 65
61 bool WebRtcVideoCapturerAdapter::GetBestCaptureFormat( 66 bool WebRtcVideoCapturerAdapter::GetBestCaptureFormat(
62 const cricket::VideoFormat& desired, 67 const cricket::VideoFormat& desired,
63 cricket::VideoFormat* best_format) { 68 cricket::VideoFormat* best_format) {
69 DCHECK(thread_checker_.CalledOnValidThread());
64 DVLOG(3) << " GetBestCaptureFormat:: " 70 DVLOG(3) << " GetBestCaptureFormat:: "
65 << " w = " << desired.width 71 << " w = " << desired.width
66 << " h = " << desired.height; 72 << " h = " << desired.height;
67 73
68 // Capability enumeration is done in MediaStreamVideoSource. The adapter can 74 // Capability enumeration is done in MediaStreamVideoSource. The adapter can
69 // just use what is provided. 75 // just use what is provided.
70 // Use the desired format as the best format. 76 // Use the desired format as the best format.
71 best_format->width = desired.width; 77 best_format->width = desired.width;
72 best_format->height = desired.height; 78 best_format->height = desired.height;
73 best_format->fourcc = cricket::FOURCC_I420; 79 best_format->fourcc = cricket::FOURCC_I420;
74 best_format->interval = desired.interval; 80 best_format->interval = desired.interval;
75 return true; 81 return true;
76 } 82 }
77 83
78 void WebRtcVideoCapturerAdapter::OnFrameCaptured( 84 void WebRtcVideoCapturerAdapter::OnFrameCaptured(
79 const scoped_refptr<media::VideoFrame>& frame) { 85 const scoped_refptr<media::VideoFrame>& frame) {
86 DCHECK(thread_checker_.CalledOnValidThread());
80 DCHECK(media::VideoFrame::I420 == frame->format() || 87 DCHECK(media::VideoFrame::I420 == frame->format() ||
81 media::VideoFrame::YV12 == frame->format()); 88 media::VideoFrame::YV12 == frame->format());
82 if (first_frame_timestamp_ == media::kNoTimestamp()) 89 if (first_frame_timestamp_ == media::kNoTimestamp())
83 first_frame_timestamp_ = frame->timestamp(); 90 first_frame_timestamp_ = frame->timestamp();
84 91
85 cricket::CapturedFrame captured_frame; 92 cricket::CapturedFrame captured_frame;
86 captured_frame.width = frame->visible_rect().width(); 93 captured_frame.width = frame->visible_rect().width();
87 captured_frame.height = frame->visible_rect().height(); 94 captured_frame.height = frame->visible_rect().height();
88 // cricket::CapturedFrame time is in nanoseconds. 95 // cricket::CapturedFrame time is in nanoseconds.
89 captured_frame.elapsed_time = 96 captured_frame.elapsed_time =
(...skipping 23 matching lines...) Expand all
113 media::VideoFrame::AllocationSize(frame->format(), frame->coded_size()); 120 media::VideoFrame::AllocationSize(frame->format(), frame->coded_size());
114 } 121 }
115 122
116 // This signals to libJingle that a new VideoFrame is available. 123 // This signals to libJingle that a new VideoFrame is available.
117 // libJingle have no assumptions on what thread this signal come from. 124 // libJingle have no assumptions on what thread this signal come from.
118 SignalFrameCaptured(this, &captured_frame); 125 SignalFrameCaptured(this, &captured_frame);
119 } 126 }
120 127
121 void WebRtcVideoCapturerAdapter::UpdateI420Buffer( 128 void WebRtcVideoCapturerAdapter::UpdateI420Buffer(
122 const scoped_refptr<media::VideoFrame>& src) { 129 const scoped_refptr<media::VideoFrame>& src) {
130 DCHECK(thread_checker_.CalledOnValidThread());
123 const int src_width = src->coded_size().width(); 131 const int src_width = src->coded_size().width();
124 const int src_height = src->coded_size().height(); 132 const int src_height = src->coded_size().height();
125 const int dst_width = src->visible_rect().width(); 133 const int dst_width = src->visible_rect().width();
126 const int dst_height = src->visible_rect().height(); 134 const int dst_height = src->visible_rect().height();
127 DCHECK(src_width >= dst_width && src_height >= dst_height); 135 DCHECK(src_width >= dst_width && src_height >= dst_height);
128 136
129 const int horiz_crop = src->visible_rect().x(); 137 const int horiz_crop = src->visible_rect().x();
130 const int vert_crop = src->visible_rect().y(); 138 const int vert_crop = src->visible_rect().y();
131 139
132 const uint8* src_y = src->data(media::VideoFrame::kYPlane) + 140 const uint8* src_y = src->data(media::VideoFrame::kYPlane) +
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 dst_stride_y, 174 dst_stride_y,
167 dst_u, 175 dst_u,
168 dst_halfwidth, 176 dst_halfwidth,
169 dst_v, 177 dst_v,
170 dst_halfwidth, 178 dst_halfwidth,
171 dst_width, 179 dst_width,
172 dst_height); 180 dst_height);
173 } 181 }
174 182
175 } // namespace content 183 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698