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