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 "content/renderer/media/html_video_element_capturer_source.h" | 5 #include "content/renderer/media/html_video_element_capturer_source.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 if (bitmap.colorType() != kN32_SkColorType) { | 149 if (bitmap.colorType() != kN32_SkColorType) { |
150 DLOG(ERROR) << "Only supported capture format is ARGB"; | 150 DLOG(ERROR) << "Only supported capture format is ARGB"; |
151 return; | 151 return; |
152 } | 152 } |
153 | 153 |
154 scoped_refptr<media::VideoFrame> frame = frame_pool_.CreateFrame( | 154 scoped_refptr<media::VideoFrame> frame = frame_pool_.CreateFrame( |
155 media::PIXEL_FORMAT_I420, resolution, gfx::Rect(resolution), resolution, | 155 media::PIXEL_FORMAT_I420, resolution, gfx::Rect(resolution), resolution, |
156 base::TimeTicks::Now() - base::TimeTicks()); | 156 base::TimeTicks::Now() - base::TimeTicks()); |
157 DCHECK(frame); | 157 DCHECK(frame); |
158 | 158 |
159 #if defined(OS_ANDROID) | |
160 // See https://crbug.com/627983. | |
161 const uint32 source_pixel_format = libyuv::FOURCC_ABGR; | |
162 #else | |
163 const uint32 source_pixel_format = libyuv::FOURCC_ARGB; | |
164 #endif | |
165 | |
159 if (libyuv::ConvertToI420(static_cast<uint8*>(bitmap.getPixels()), | 166 if (libyuv::ConvertToI420(static_cast<uint8*>(bitmap.getPixels()), |
160 bitmap.getSize(), | 167 bitmap.getSize(), |
161 frame->data(media::VideoFrame::kYPlane), | 168 frame->data(media::VideoFrame::kYPlane), |
162 frame->stride(media::VideoFrame::kYPlane), | 169 frame->stride(media::VideoFrame::kYPlane), |
163 frame->data(media::VideoFrame::kUPlane), | 170 frame->data(media::VideoFrame::kUPlane), |
164 frame->stride(media::VideoFrame::kUPlane), | 171 frame->stride(media::VideoFrame::kUPlane), |
165 frame->data(media::VideoFrame::kVPlane), | 172 frame->data(media::VideoFrame::kVPlane), |
166 frame->stride(media::VideoFrame::kVPlane), | 173 frame->stride(media::VideoFrame::kVPlane), |
167 0 /* crop_x */, | 174 0 /* crop_x */, |
168 0 /* crop_y */, | 175 0 /* crop_y */, |
169 bitmap.info().width(), | 176 bitmap.info().width(), |
170 bitmap.info().height(), | 177 bitmap.info().height(), |
171 frame->coded_size().width(), | 178 frame->coded_size().width(), |
172 frame->coded_size().height(), | 179 frame->coded_size().height(), |
173 libyuv::kRotate0, | 180 libyuv::kRotate0, |
174 libyuv::FOURCC_ARGB) == 0) { | 181 source_pixel_format) == 0) { |
emircan
2016/07/14 18:16:00
I think the underlying problem is that bitmap.colo
mcasas
2016/07/14 18:33:08
Great suggestion! Done.
| |
175 // Success! | 182 // Success! |
176 io_task_runner_->PostTask( | 183 io_task_runner_->PostTask( |
177 FROM_HERE, base::Bind(new_frame_callback_, frame, current_time)); | 184 FROM_HERE, base::Bind(new_frame_callback_, frame, current_time)); |
178 } | 185 } |
179 | 186 |
180 // Calculate the time in the future where the next frame should be created. | 187 // Calculate the time in the future where the next frame should be created. |
181 const base::TimeDelta frame_interval = | 188 const base::TimeDelta frame_interval = |
182 base::TimeDelta::FromMicroseconds(1E6 / capture_frame_rate_); | 189 base::TimeDelta::FromMicroseconds(1E6 / capture_frame_rate_); |
183 if (next_capture_time_.is_null()) { | 190 if (next_capture_time_.is_null()) { |
184 next_capture_time_ = current_time + frame_interval; | 191 next_capture_time_ = current_time + frame_interval; |
185 } else { | 192 } else { |
186 next_capture_time_ += frame_interval; | 193 next_capture_time_ += frame_interval; |
187 // Don't accumulate any debt if we are lagging behind - just post next frame | 194 // Don't accumulate any debt if we are lagging behind - just post next frame |
188 // immediately and continue as normal. | 195 // immediately and continue as normal. |
189 if (next_capture_time_ < current_time) | 196 if (next_capture_time_ < current_time) |
190 next_capture_time_ = current_time; | 197 next_capture_time_ = current_time; |
191 } | 198 } |
192 // Schedule next capture. | 199 // Schedule next capture. |
193 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 200 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
194 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame, | 201 FROM_HERE, base::Bind(&HtmlVideoElementCapturerSource::sendNewFrame, |
195 weak_factory_.GetWeakPtr()), | 202 weak_factory_.GetWeakPtr()), |
196 next_capture_time_ - current_time); | 203 next_capture_time_ - current_time); |
197 } | 204 } |
198 | 205 |
199 } // namespace content | 206 } // namespace content |
OLD | NEW |