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 "content/browser/renderer_host/media/video_capture_host.h" | 5 #include "content/browser/renderer_host/media/video_capture_host.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/files/scoped_file.h" | 16 #include "base/files/scoped_file.h" |
17 #include "base/location.h" | 17 #include "base/location.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/ptr_util.h" |
19 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
21 #include "base/stl_util.h" | |
22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
25 #include "content/browser/browser_thread_impl.h" | 25 #include "content/browser/browser_thread_impl.h" |
26 #include "content/browser/renderer_host/media/media_stream_manager.h" | 26 #include "content/browser/renderer_host/media/media_stream_manager.h" |
27 #include "content/browser/renderer_host/media/media_stream_requester.h" | 27 #include "content/browser/renderer_host/media/media_stream_requester.h" |
28 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 28 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
29 #include "content/browser/renderer_host/media/video_capture_manager.h" | 29 #include "content/browser/renderer_host/media/video_capture_manager.h" |
30 #include "content/common/media/video_capture_messages.h" | 30 #include "content/common/media/video_capture_messages.h" |
31 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 while (handle) { | 159 while (handle) { |
160 this->OnRendererFinishedWithBuffer(device_id, handle, gpu::SyncToken(), | 160 this->OnRendererFinishedWithBuffer(device_id, handle, gpu::SyncToken(), |
161 -1.0); | 161 -1.0); |
162 handle = GetReceivedDib(); | 162 handle = GetReceivedDib(); |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 int GetReceivedDib() { | 166 int GetReceivedDib() { |
167 if (filled_dib_.empty()) | 167 if (filled_dib_.empty()) |
168 return 0; | 168 return 0; |
169 std::map<int, base::SharedMemory*>::iterator it = filled_dib_.begin(); | 169 auto it = filled_dib_.begin(); |
170 int h = it->first; | 170 int h = it->first; |
171 delete it->second; | |
172 filled_dib_.erase(it); | 171 filled_dib_.erase(it); |
173 | 172 |
174 return h; | 173 return h; |
175 } | 174 } |
176 | 175 |
177 private: | 176 private: |
178 ~MockVideoCaptureHost() override { | 177 ~MockVideoCaptureHost() override { |
179 base::STLDeleteContainerPairSecondPointers(filled_dib_.begin(), | |
180 filled_dib_.end()); | |
181 } | 178 } |
182 | 179 |
183 // This method is used to dispatch IPC messages to the renderer. We intercept | 180 // This method is used to dispatch IPC messages to the renderer. We intercept |
184 // these messages here and dispatch to our mock methods to verify the | 181 // these messages here and dispatch to our mock methods to verify the |
185 // conversation between this object and the renderer. | 182 // conversation between this object and the renderer. |
186 bool Send(IPC::Message* message) override { | 183 bool Send(IPC::Message* message) override { |
187 CHECK(message); | 184 CHECK(message); |
188 | 185 |
189 // In this method we dispatch the messages to the according handlers as if | 186 // In this method we dispatch the messages to the according handlers as if |
190 // we are the renderer. | 187 // we are the renderer. |
(...skipping 10 matching lines...) Expand all Loading... |
201 delete message; | 198 delete message; |
202 return true; | 199 return true; |
203 } | 200 } |
204 | 201 |
205 // These handler methods do minimal things and delegate to the mock methods. | 202 // These handler methods do minimal things and delegate to the mock methods. |
206 void OnNewBufferCreatedDispatch(int device_id, | 203 void OnNewBufferCreatedDispatch(int device_id, |
207 base::SharedMemoryHandle handle, | 204 base::SharedMemoryHandle handle, |
208 uint32_t length, | 205 uint32_t length, |
209 int buffer_id) { | 206 int buffer_id) { |
210 OnNewBufferCreated(device_id, handle, length, buffer_id); | 207 OnNewBufferCreated(device_id, handle, length, buffer_id); |
211 base::SharedMemory* dib = new base::SharedMemory(handle, false); | 208 std::unique_ptr<base::SharedMemory> dib = |
| 209 base::MakeUnique<base::SharedMemory>(handle, false); |
212 dib->Map(length); | 210 dib->Map(length); |
213 filled_dib_[buffer_id] = dib; | 211 filled_dib_[buffer_id] = std::move(dib); |
214 } | 212 } |
215 | 213 |
216 void OnBufferFreedDispatch(int device_id, int buffer_id) { | 214 void OnBufferFreedDispatch(int device_id, int buffer_id) { |
217 OnBufferFreed(device_id, buffer_id); | 215 OnBufferFreed(device_id, buffer_id); |
218 | 216 |
219 std::map<int, base::SharedMemory*>::iterator it = | 217 auto it = filled_dib_.find(buffer_id); |
220 filled_dib_.find(buffer_id); | |
221 ASSERT_TRUE(it != filled_dib_.end()); | 218 ASSERT_TRUE(it != filled_dib_.end()); |
222 delete it->second; | |
223 filled_dib_.erase(it); | 219 filled_dib_.erase(it); |
224 } | 220 } |
225 | 221 |
226 void OnBufferFilledDispatch( | 222 void OnBufferFilledDispatch( |
227 const VideoCaptureMsg_BufferReady_Params& params) { | 223 const VideoCaptureMsg_BufferReady_Params& params) { |
228 base::SharedMemory* dib = filled_dib_[params.buffer_id]; | 224 base::SharedMemory* dib = filled_dib_[params.buffer_id].get(); |
229 ASSERT_TRUE(dib != NULL); | 225 ASSERT_TRUE(dib != NULL); |
230 if (dump_video_) { | 226 if (dump_video_) { |
231 if (dumper_.coded_size().IsEmpty()) | 227 if (dumper_.coded_size().IsEmpty()) |
232 dumper_.StartDump(params.coded_size); | 228 dumper_.StartDump(params.coded_size); |
233 ASSERT_TRUE(dumper_.coded_size() == params.coded_size) | 229 ASSERT_TRUE(dumper_.coded_size() == params.coded_size) |
234 << "Dump format does not handle variable resolution."; | 230 << "Dump format does not handle variable resolution."; |
235 dumper_.NewVideoFrame(dib->memory()); | 231 dumper_.NewVideoFrame(dib->memory()); |
236 } | 232 } |
237 | 233 |
238 OnBufferFilled(params.device_id); | 234 OnBufferFilled(params.device_id); |
239 if (return_buffers_) { | 235 if (return_buffers_) { |
240 VideoCaptureHost::OnRendererFinishedWithBuffer( | 236 VideoCaptureHost::OnRendererFinishedWithBuffer( |
241 params.device_id, params.buffer_id, gpu::SyncToken(), -1.0); | 237 params.device_id, params.buffer_id, gpu::SyncToken(), -1.0); |
242 } | 238 } |
243 } | 239 } |
244 | 240 |
245 void OnStateChangedDispatch(int device_id, VideoCaptureState state) { | 241 void OnStateChangedDispatch(int device_id, VideoCaptureState state) { |
246 OnStateChanged(device_id, state); | 242 OnStateChanged(device_id, state); |
247 } | 243 } |
248 | 244 |
249 std::map<int, base::SharedMemory*> filled_dib_; | 245 std::map<int, std::unique_ptr<base::SharedMemory>> filled_dib_; |
250 bool return_buffers_; | 246 bool return_buffers_; |
251 bool dump_video_; | 247 bool dump_video_; |
252 media::VideoCaptureFormat format_; | 248 media::VideoCaptureFormat format_; |
253 DumpVideo dumper_; | 249 DumpVideo dumper_; |
254 }; | 250 }; |
255 | 251 |
256 ACTION_P2(ExitMessageLoop, task_runner, quit_closure) { | 252 ACTION_P2(ExitMessageLoop, task_runner, quit_closure) { |
257 task_runner->PostTask(FROM_HERE, quit_closure); | 253 task_runner->PostTask(FROM_HERE, quit_closure); |
258 } | 254 } |
259 | 255 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 #ifdef DUMP_VIDEO | 537 #ifdef DUMP_VIDEO |
542 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 538 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
543 CaptureAndDumpVideo(640, 480, 30); | 539 CaptureAndDumpVideo(640, 480, 30); |
544 } | 540 } |
545 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 541 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
546 CaptureAndDumpVideo(1280, 720, 30); | 542 CaptureAndDumpVideo(1280, 720, 30); |
547 } | 543 } |
548 #endif | 544 #endif |
549 | 545 |
550 } // namespace content | 546 } // namespace content |
OLD | NEW |