OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/file_video_capture_device.h" | 5 #include "media/capture/video/file_video_capture_device.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
13 #include "media/base/video_capture_types.h" | 14 #include "media/base/video_capture_types.h" |
14 #include "media/filters/jpeg_parser.h" | 15 #include "media/filters/jpeg_parser.h" |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 | 18 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 std::string file_name(file_path.value().begin(), file_path.value().end()); | 278 std::string file_name(file_path.value().begin(), file_path.value().end()); |
278 | 279 |
279 if (base::EndsWith(file_name, "y4m", | 280 if (base::EndsWith(file_name, "y4m", |
280 base::CompareCase::INSENSITIVE_ASCII)) { | 281 base::CompareCase::INSENSITIVE_ASCII)) { |
281 file_parser.reset(new Y4mFileParser(file_path)); | 282 file_parser.reset(new Y4mFileParser(file_path)); |
282 } else if (base::EndsWith(file_name, "mjpeg", | 283 } else if (base::EndsWith(file_name, "mjpeg", |
283 base::CompareCase::INSENSITIVE_ASCII)) { | 284 base::CompareCase::INSENSITIVE_ASCII)) { |
284 file_parser.reset(new MjpegFileParser(file_path)); | 285 file_parser.reset(new MjpegFileParser(file_path)); |
285 } else { | 286 } else { |
286 LOG(ERROR) << "Unsupported file format."; | 287 LOG(ERROR) << "Unsupported file format."; |
287 return file_parser.Pass(); | 288 return file_parser; |
288 } | 289 } |
289 | 290 |
290 if (!file_parser->Initialize(video_format)) { | 291 if (!file_parser->Initialize(video_format)) { |
291 file_parser.reset(); | 292 file_parser.reset(); |
292 } | 293 } |
293 return file_parser.Pass(); | 294 return file_parser; |
294 } | 295 } |
295 | 296 |
296 FileVideoCaptureDevice::FileVideoCaptureDevice(const base::FilePath& file_path) | 297 FileVideoCaptureDevice::FileVideoCaptureDevice(const base::FilePath& file_path) |
297 : capture_thread_("CaptureThread"), file_path_(file_path) {} | 298 : capture_thread_("CaptureThread"), file_path_(file_path) {} |
298 | 299 |
299 FileVideoCaptureDevice::~FileVideoCaptureDevice() { | 300 FileVideoCaptureDevice::~FileVideoCaptureDevice() { |
300 DCHECK(thread_checker_.CalledOnValidThread()); | 301 DCHECK(thread_checker_.CalledOnValidThread()); |
301 // Check if the thread is running. | 302 // Check if the thread is running. |
302 // This means that the device have not been DeAllocated properly. | 303 // This means that the device have not been DeAllocated properly. |
303 CHECK(!capture_thread_.IsRunning()); | 304 CHECK(!capture_thread_.IsRunning()); |
(...skipping 20 matching lines...) Expand all Loading... |
324 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnStopAndDeAllocate, | 325 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnStopAndDeAllocate, |
325 base::Unretained(this))); | 326 base::Unretained(this))); |
326 capture_thread_.Stop(); | 327 capture_thread_.Stop(); |
327 } | 328 } |
328 | 329 |
329 void FileVideoCaptureDevice::OnAllocateAndStart( | 330 void FileVideoCaptureDevice::OnAllocateAndStart( |
330 const VideoCaptureParams& params, | 331 const VideoCaptureParams& params, |
331 scoped_ptr<VideoCaptureDevice::Client> client) { | 332 scoped_ptr<VideoCaptureDevice::Client> client) { |
332 DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current()); | 333 DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current()); |
333 | 334 |
334 client_ = client.Pass(); | 335 client_ = std::move(client); |
335 | 336 |
336 DCHECK(!file_parser_); | 337 DCHECK(!file_parser_); |
337 file_parser_ = GetVideoFileParser(file_path_, &capture_format_); | 338 file_parser_ = GetVideoFileParser(file_path_, &capture_format_); |
338 if (!file_parser_) { | 339 if (!file_parser_) { |
339 client_->OnError(FROM_HERE, "Could not open Video file"); | 340 client_->OnError(FROM_HERE, "Could not open Video file"); |
340 return; | 341 return; |
341 } | 342 } |
342 | 343 |
343 DVLOG(1) << "Opened video file " << capture_format_.frame_size.ToString() | 344 DVLOG(1) << "Opened video file " << capture_format_.frame_size.ToString() |
344 << ", fps: " << capture_format_.frame_rate; | 345 << ", fps: " << capture_format_.frame_rate; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 if (next_frame_time_ < current_time) | 381 if (next_frame_time_ < current_time) |
381 next_frame_time_ = current_time; | 382 next_frame_time_ = current_time; |
382 } | 383 } |
383 base::MessageLoop::current()->PostDelayedTask( | 384 base::MessageLoop::current()->PostDelayedTask( |
384 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnCaptureTask, | 385 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnCaptureTask, |
385 base::Unretained(this)), | 386 base::Unretained(this)), |
386 next_frame_time_ - current_time); | 387 next_frame_time_ - current_time); |
387 } | 388 } |
388 | 389 |
389 } // namespace media | 390 } // namespace media |
OLD | NEW |