OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/capture/video/fake_video_capture_device.h" | 5 #include "media/capture/video/fake_video_capture_device.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 const int frame_count = elapsed_time.InMilliseconds() * frame_rate / 1000; | 66 const int frame_count = elapsed_time.InMilliseconds() * frame_rate / 1000; |
67 | 67 |
68 const std::string time_string = | 68 const std::string time_string = |
69 base::StringPrintf("%d:%02d:%02d:%03d %d", hours, minutes, seconds, | 69 base::StringPrintf("%d:%02d:%02d:%03d %d", hours, minutes, seconds, |
70 milliseconds, frame_count); | 70 milliseconds, frame_count); |
71 canvas.scale(3, 3); | 71 canvas.scale(3, 3); |
72 canvas.drawText(time_string.data(), time_string.length(), 30, 20, paint); | 72 canvas.drawText(time_string.data(), time_string.length(), 30, 20, paint); |
73 } | 73 } |
74 | 74 |
75 FakeVideoCaptureDevice::FakeVideoCaptureDevice(BufferOwnership buffer_ownership, | 75 FakeVideoCaptureDevice::FakeVideoCaptureDevice(BufferOwnership buffer_ownership, |
76 BufferPlanarity planarity, | |
77 float fake_capture_rate) | 76 float fake_capture_rate) |
78 : buffer_ownership_(buffer_ownership), | 77 : buffer_ownership_(buffer_ownership), |
79 planarity_(planarity), | |
80 fake_capture_rate_(fake_capture_rate), | 78 fake_capture_rate_(fake_capture_rate), |
81 weak_factory_(this) {} | 79 weak_factory_(this) {} |
82 | 80 |
83 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { | 81 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { |
84 DCHECK(thread_checker_.CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
85 } | 83 } |
86 | 84 |
87 void FakeVideoCaptureDevice::AllocateAndStart( | 85 void FakeVideoCaptureDevice::AllocateAndStart( |
88 const VideoCaptureParams& params, | 86 const VideoCaptureParams& params, |
89 scoped_ptr<VideoCaptureDevice::Client> client) { | 87 scoped_ptr<VideoCaptureDevice::Client> client) { |
90 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
91 | 89 |
92 client_ = std::move(client); | 90 client_ = std::move(client); |
93 | 91 |
94 // Incoming |params| can be none of the supported formats, so we get the | 92 // Incoming |params| can be none of the supported formats, so we get the |
95 // closest thing rounded up. TODO(mcasas): Use the |params|, if they belong to | 93 // closest thing rounded up. TODO(mcasas): Use the |params|, if they belong to |
96 // the supported ones, when http://crbug.com/309554 is verified. | 94 // the supported ones, when http://crbug.com/309554 is verified. |
97 capture_format_.frame_rate = fake_capture_rate_; | 95 capture_format_.frame_rate = fake_capture_rate_; |
98 if (params.requested_format.frame_size.width() > 1280) | 96 if (params.requested_format.frame_size.width() > 1280) |
99 capture_format_.frame_size.SetSize(1920, 1080); | 97 capture_format_.frame_size.SetSize(1920, 1080); |
100 else if (params.requested_format.frame_size.width() > 640) | 98 else if (params.requested_format.frame_size.width() > 640) |
101 capture_format_.frame_size.SetSize(1280, 720); | 99 capture_format_.frame_size.SetSize(1280, 720); |
102 else if (params.requested_format.frame_size.width() > 320) | 100 else if (params.requested_format.frame_size.width() > 320) |
103 capture_format_.frame_size.SetSize(640, 480); | 101 capture_format_.frame_size.SetSize(640, 480); |
104 else | 102 else |
105 capture_format_.frame_size.SetSize(320, 240); | 103 capture_format_.frame_size.SetSize(320, 240); |
106 | 104 |
107 if (buffer_ownership_ == BufferOwnership::CLIENT_BUFFERS) { | 105 if (buffer_ownership_ == BufferOwnership::CLIENT_BUFFERS) { |
108 if (planarity_ == BufferPlanarity::PACKED) { | 106 capture_format_.pixel_storage = PIXEL_STORAGE_CPU; |
109 capture_format_.pixel_storage = PIXEL_STORAGE_CPU; | 107 capture_format_.pixel_format = PIXEL_FORMAT_ARGB; |
110 capture_format_.pixel_format = PIXEL_FORMAT_ARGB; | 108 DVLOG(1) << "starting with client argb buffers"; |
111 DVLOG(1) << "starting with client argb buffers"; | |
112 } else if (planarity_ == BufferPlanarity::TRIPLANAR) { | |
113 capture_format_.pixel_storage = PIXEL_STORAGE_GPUMEMORYBUFFER; | |
114 capture_format_.pixel_format = PIXEL_FORMAT_I420; | |
115 DVLOG(1) << "starting with gmb I420 buffers"; | |
116 } | |
117 } else if (buffer_ownership_ == BufferOwnership::OWN_BUFFERS) { | 109 } else if (buffer_ownership_ == BufferOwnership::OWN_BUFFERS) { |
118 capture_format_.pixel_storage = PIXEL_STORAGE_CPU; | 110 capture_format_.pixel_storage = PIXEL_STORAGE_CPU; |
119 capture_format_.pixel_format = PIXEL_FORMAT_I420; | 111 capture_format_.pixel_format = PIXEL_FORMAT_I420; |
120 DVLOG(1) << "starting with own I420 buffers"; | 112 DVLOG(1) << "starting with own I420 buffers"; |
121 } | 113 } |
122 | 114 |
123 if (capture_format_.pixel_format == PIXEL_FORMAT_I420) { | 115 if (capture_format_.pixel_format == PIXEL_FORMAT_I420) { |
124 fake_frame_.reset(new uint8_t[VideoFrame::AllocationSize( | 116 fake_frame_.reset(new uint8_t[VideoFrame::AllocationSize( |
125 PIXEL_FORMAT_I420, capture_format_.frame_size)]); | 117 PIXEL_FORMAT_I420, capture_format_.frame_size)]); |
126 } | 118 } |
(...skipping 21 matching lines...) Expand all Loading... |
148 void FakeVideoCaptureDevice::CaptureUsingOwnBuffers( | 140 void FakeVideoCaptureDevice::CaptureUsingOwnBuffers( |
149 base::TimeTicks expected_execution_time) { | 141 base::TimeTicks expected_execution_time) { |
150 DCHECK(thread_checker_.CalledOnValidThread()); | 142 DCHECK(thread_checker_.CalledOnValidThread()); |
151 const size_t frame_size = capture_format_.ImageAllocationSize(); | 143 const size_t frame_size = capture_format_.ImageAllocationSize(); |
152 memset(fake_frame_.get(), 0, frame_size); | 144 memset(fake_frame_.get(), 0, frame_size); |
153 | 145 |
154 DrawPacman(false /* use_argb */, fake_frame_.get(), elapsed_time_, | 146 DrawPacman(false /* use_argb */, fake_frame_.get(), elapsed_time_, |
155 fake_capture_rate_, capture_format_.frame_size); | 147 fake_capture_rate_, capture_format_.frame_size); |
156 | 148 |
157 // Give the captured frame to the client. | 149 // Give the captured frame to the client. |
158 if (planarity_ == BufferPlanarity::PACKED) { | 150 client_->OnIncomingCapturedData(fake_frame_.get(), frame_size, |
159 client_->OnIncomingCapturedData(fake_frame_.get(), frame_size, | 151 capture_format_, 0 /* rotation */, |
160 capture_format_, 0 /* rotation */, | 152 base::TimeTicks::Now()); |
161 base::TimeTicks::Now()); | |
162 } else if (planarity_ == BufferPlanarity::TRIPLANAR) { | |
163 client_->OnIncomingCapturedYuvData( | |
164 fake_frame_.get(), | |
165 fake_frame_.get() + capture_format_.frame_size.GetArea(), | |
166 fake_frame_.get() + capture_format_.frame_size.GetArea() * 5 / 4, | |
167 capture_format_.frame_size.width(), | |
168 capture_format_.frame_size.width() / 2, | |
169 capture_format_.frame_size.width() / 2, capture_format_, | |
170 0 /* rotation */, base::TimeTicks::Now()); | |
171 } | |
172 BeepAndScheduleNextCapture( | 153 BeepAndScheduleNextCapture( |
173 expected_execution_time, | 154 expected_execution_time, |
174 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, | 155 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, |
175 weak_factory_.GetWeakPtr())); | 156 weak_factory_.GetWeakPtr())); |
176 } | 157 } |
177 | 158 |
178 void FakeVideoCaptureDevice::CaptureUsingClientBuffers( | 159 void FakeVideoCaptureDevice::CaptureUsingClientBuffers( |
179 base::TimeTicks expected_execution_time) { | 160 base::TimeTicks expected_execution_time) { |
180 DCHECK(thread_checker_.CalledOnValidThread()); | 161 DCHECK(thread_checker_.CalledOnValidThread()); |
181 | 162 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // Don't accumulate any debt if we are lagging behind - just post the next | 225 // Don't accumulate any debt if we are lagging behind - just post the next |
245 // frame immediately and continue as normal. | 226 // frame immediately and continue as normal. |
246 const base::TimeTicks next_execution_time = | 227 const base::TimeTicks next_execution_time = |
247 std::max(current_time, expected_execution_time + frame_interval); | 228 std::max(current_time, expected_execution_time + frame_interval); |
248 const base::TimeDelta delay = next_execution_time - current_time; | 229 const base::TimeDelta delay = next_execution_time - current_time; |
249 base::MessageLoop::current()->PostDelayedTask( | 230 base::MessageLoop::current()->PostDelayedTask( |
250 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); | 231 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); |
251 } | 232 } |
252 | 233 |
253 } // namespace media | 234 } // namespace media |
OLD | NEW |