| 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 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 bool Y4mFileParser::Initialize(media::VideoCaptureFormat* capture_format) { | 172 bool Y4mFileParser::Initialize(media::VideoCaptureFormat* capture_format) { |
| 173 file_.reset(new base::File(file_path_, | 173 file_.reset(new base::File(file_path_, |
| 174 base::File::FLAG_OPEN | base::File::FLAG_READ)); | 174 base::File::FLAG_OPEN | base::File::FLAG_READ)); |
| 175 if (!file_->IsValid()) { | 175 if (!file_->IsValid()) { |
| 176 DLOG(ERROR) << file_path_.value() << ", error: " | 176 DLOG(ERROR) << file_path_.value() << ", error: " |
| 177 << base::File::ErrorToString(file_->error_details()); | 177 << base::File::ErrorToString(file_->error_details()); |
| 178 return false; | 178 return false; |
| 179 } | 179 } |
| 180 | 180 |
| 181 std::string header(kY4MHeaderMaxSize, '\0'); | 181 std::string header(kY4MHeaderMaxSize, '\0'); |
| 182 file_->Read(0, &header[0], header.size()); | 182 file_->Read(0, &header[0], static_cast<int>(header.size())); |
| 183 const size_t header_end = header.find(kY4MSimpleFrameDelimiter); | 183 const size_t header_end = header.find(kY4MSimpleFrameDelimiter); |
| 184 CHECK_NE(header_end, header.npos); | 184 CHECK_NE(header_end, header.npos); |
| 185 | 185 |
| 186 ParseY4MTags(header, capture_format); | 186 ParseY4MTags(header, capture_format); |
| 187 first_frame_byte_index_ = header_end + kY4MSimpleFrameDelimiterSize; | 187 first_frame_byte_index_ = header_end + kY4MSimpleFrameDelimiterSize; |
| 188 current_byte_index_ = first_frame_byte_index_; | 188 current_byte_index_ = first_frame_byte_index_; |
| 189 frame_size_ = capture_format->ImageAllocationSize(); | 189 frame_size_ = static_cast<int>(capture_format->ImageAllocationSize()); |
| 190 return true; | 190 return true; |
| 191 } | 191 } |
| 192 | 192 |
| 193 const uint8_t* Y4mFileParser::GetNextFrame(int* frame_size) { | 193 const uint8_t* Y4mFileParser::GetNextFrame(int* frame_size) { |
| 194 if (!video_frame_) | 194 if (!video_frame_) |
| 195 video_frame_.reset(new uint8_t[frame_size_]); | 195 video_frame_.reset(new uint8_t[frame_size_]); |
| 196 int result = | 196 int result = |
| 197 file_->Read(current_byte_index_, | 197 file_->Read(current_byte_index_, |
| 198 reinterpret_cast<char*>(video_frame_.get()), frame_size_); | 198 reinterpret_cast<char*>(video_frame_.get()), frame_size_); |
| 199 | 199 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 223 | 223 |
| 224 if (!mapped_file_->Initialize(file_path_) || !mapped_file_->IsValid()) { | 224 if (!mapped_file_->Initialize(file_path_) || !mapped_file_->IsValid()) { |
| 225 LOG(ERROR) << "File memory map error: " << file_path_.value(); | 225 LOG(ERROR) << "File memory map error: " << file_path_.value(); |
| 226 return false; | 226 return false; |
| 227 } | 227 } |
| 228 | 228 |
| 229 JpegParseResult result; | 229 JpegParseResult result; |
| 230 if (!ParseJpegStream(mapped_file_->data(), mapped_file_->length(), &result)) | 230 if (!ParseJpegStream(mapped_file_->data(), mapped_file_->length(), &result)) |
| 231 return false; | 231 return false; |
| 232 | 232 |
| 233 frame_size_ = result.image_size; | 233 frame_size_ = static_cast<int>(result.image_size); |
| 234 if (frame_size_ > static_cast<int>(mapped_file_->length())) { | 234 if (frame_size_ > static_cast<int>(mapped_file_->length())) { |
| 235 LOG(ERROR) << "File is incomplete"; | 235 LOG(ERROR) << "File is incomplete"; |
| 236 return false; | 236 return false; |
| 237 } | 237 } |
| 238 | 238 |
| 239 VideoCaptureFormat format; | 239 VideoCaptureFormat format; |
| 240 format.pixel_format = media::PIXEL_FORMAT_MJPEG; | 240 format.pixel_format = media::PIXEL_FORMAT_MJPEG; |
| 241 format.frame_size.set_width(result.frame_header.visible_width); | 241 format.frame_size.set_width(result.frame_header.visible_width); |
| 242 format.frame_size.set_height(result.frame_header.visible_height); | 242 format.frame_size.set_height(result.frame_header.visible_height); |
| 243 format.frame_rate = kMJpegFrameRate; | 243 format.frame_rate = kMJpegFrameRate; |
| 244 if (!format.IsValid()) | 244 if (!format.IsValid()) |
| 245 return false; | 245 return false; |
| 246 *capture_format = format; | 246 *capture_format = format; |
| 247 return true; | 247 return true; |
| 248 } | 248 } |
| 249 | 249 |
| 250 const uint8_t* MjpegFileParser::GetNextFrame(int* frame_size) { | 250 const uint8_t* MjpegFileParser::GetNextFrame(int* frame_size) { |
| 251 const uint8_t* buf_ptr = mapped_file_->data() + current_byte_index_; | 251 const uint8_t* buf_ptr = mapped_file_->data() + current_byte_index_; |
| 252 | 252 |
| 253 JpegParseResult result; | 253 JpegParseResult result; |
| 254 if (!ParseJpegStream(buf_ptr, mapped_file_->length() - current_byte_index_, | 254 if (!ParseJpegStream(buf_ptr, mapped_file_->length() - current_byte_index_, |
| 255 &result)) { | 255 &result)) { |
| 256 return nullptr; | 256 return nullptr; |
| 257 } | 257 } |
| 258 *frame_size = frame_size_ = result.image_size; | 258 *frame_size = frame_size_ = static_cast<int>(result.image_size); |
| 259 current_byte_index_ += frame_size_; | 259 current_byte_index_ += frame_size_; |
| 260 // Reset the pointer to play repeatedly. | 260 // Reset the pointer to play repeatedly. |
| 261 if (current_byte_index_ >= mapped_file_->length()) | 261 if (current_byte_index_ >= mapped_file_->length()) |
| 262 current_byte_index_ = first_frame_byte_index_; | 262 current_byte_index_ = first_frame_byte_index_; |
| 263 return buf_ptr; | 263 return buf_ptr; |
| 264 } | 264 } |
| 265 | 265 |
| 266 // static | 266 // static |
| 267 bool FileVideoCaptureDevice::GetVideoCaptureFormat( | 267 bool FileVideoCaptureDevice::GetVideoCaptureFormat( |
| 268 const base::FilePath& file_path, | 268 const base::FilePath& file_path, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 if (next_frame_time_ < current_time) | 385 if (next_frame_time_ < current_time) |
| 386 next_frame_time_ = current_time; | 386 next_frame_time_ = current_time; |
| 387 } | 387 } |
| 388 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 388 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 389 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnCaptureTask, | 389 FROM_HERE, base::Bind(&FileVideoCaptureDevice::OnCaptureTask, |
| 390 base::Unretained(this)), | 390 base::Unretained(this)), |
| 391 next_frame_time_ - current_time); | 391 next_frame_time_ - current_time); |
| 392 } | 392 } |
| 393 | 393 |
| 394 } // namespace media | 394 } // namespace media |
| OLD | NEW |