| 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/video/capture/file_video_capture_device.h" | 5 #include "media/video/capture/file_video_capture_device.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 ParseY4MTags(header, video_format); | 117 ParseY4MTags(header, video_format); |
| 118 return header_end + kY4MSimpleFrameDelimiterSize; | 118 return header_end + kY4MSimpleFrameDelimiterSize; |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Opens a given file for reading, and returns the file to the caller, who is | 121 // Opens a given file for reading, and returns the file to the caller, who is |
| 122 // responsible for closing it. | 122 // responsible for closing it. |
| 123 // static | 123 // static |
| 124 base::File FileVideoCaptureDevice::OpenFileForRead( | 124 base::File FileVideoCaptureDevice::OpenFileForRead( |
| 125 const base::FilePath& file_path) { | 125 const base::FilePath& file_path) { |
| 126 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 126 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 127 DVLOG_IF(1, file.IsValid()) << file_path.value() << ", error: " | 127 DLOG_IF(ERROR, file.IsValid()) |
| 128 << base::File::ErrorToString(file.error_details()); | 128 << file_path.value() |
| 129 CHECK(file.IsValid()); | 129 << ", error: " << base::File::ErrorToString(file.error_details()); |
| 130 return file.Pass(); | 130 return file.Pass(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 FileVideoCaptureDevice::FileVideoCaptureDevice(const base::FilePath& file_path) | 133 FileVideoCaptureDevice::FileVideoCaptureDevice(const base::FilePath& file_path) |
| 134 : capture_thread_("CaptureThread"), | 134 : capture_thread_("CaptureThread"), |
| 135 file_path_(file_path), | 135 file_path_(file_path), |
| 136 frame_size_(0), | 136 frame_size_(0), |
| 137 current_byte_index_(0), | 137 current_byte_index_(0), |
| 138 first_frame_byte_index_(0) {} | 138 first_frame_byte_index_(0) {} |
| 139 | 139 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 void FileVideoCaptureDevice::OnAllocateAndStart( | 179 void FileVideoCaptureDevice::OnAllocateAndStart( |
| 180 const VideoCaptureParams& params, | 180 const VideoCaptureParams& params, |
| 181 scoped_ptr<VideoCaptureDevice::Client> client) { | 181 scoped_ptr<VideoCaptureDevice::Client> client) { |
| 182 DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current()); | 182 DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current()); |
| 183 | 183 |
| 184 client_ = client.Pass(); | 184 client_ = client.Pass(); |
| 185 | 185 |
| 186 // Open the file and parse the header. Get frame size and format. | 186 // Open the file and parse the header. Get frame size and format. |
| 187 DCHECK(!file_.IsValid()); | 187 DCHECK(!file_.IsValid()); |
| 188 file_ = OpenFileForRead(file_path_); | 188 file_ = OpenFileForRead(file_path_); |
| 189 if (!file_.IsValid()) { |
| 190 client_->OnError("Could not open Video file"); |
| 191 return; |
| 192 } |
| 189 first_frame_byte_index_ = | 193 first_frame_byte_index_ = |
| 190 ParseFileAndExtractVideoFormat(&file_, &capture_format_); | 194 ParseFileAndExtractVideoFormat(&file_, &capture_format_); |
| 191 current_byte_index_ = first_frame_byte_index_; | 195 current_byte_index_ = first_frame_byte_index_; |
| 192 DVLOG(1) << "Opened video file " << capture_format_.frame_size.ToString() | 196 DVLOG(1) << "Opened video file " << capture_format_.frame_size.ToString() |
| 193 << ", fps: " << capture_format_.frame_rate; | 197 << ", fps: " << capture_format_.frame_rate; |
| 194 | 198 |
| 195 frame_size_ = CalculateFrameSize(); | 199 frame_size_ = CalculateFrameSize(); |
| 196 video_frame_.reset(new uint8[frame_size_]); | 200 video_frame_.reset(new uint8[frame_size_]); |
| 197 | 201 |
| 198 capture_thread_.message_loop()->PostTask( | 202 capture_thread_.message_loop()->PostTask( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 next_on_capture_timedelta = frame_interval; | 253 next_on_capture_timedelta = frame_interval; |
| 250 } | 254 } |
| 251 base::MessageLoop::current()->PostDelayedTask( | 255 base::MessageLoop::current()->PostDelayedTask( |
| 252 FROM_HERE, | 256 FROM_HERE, |
| 253 base::Bind(&FileVideoCaptureDevice::OnCaptureTask, | 257 base::Bind(&FileVideoCaptureDevice::OnCaptureTask, |
| 254 base::Unretained(this)), | 258 base::Unretained(this)), |
| 255 next_on_capture_timedelta); | 259 next_on_capture_timedelta); |
| 256 } | 260 } |
| 257 | 261 |
| 258 } // namespace media | 262 } // namespace media |
| OLD | NEW |