Index: media/video/capture/file_video_capture_device.cc |
diff --git a/media/video/capture/file_video_capture_device.cc b/media/video/capture/file_video_capture_device.cc |
index e1c4f5216f76d656128590fcc90d9f5a6f17f356..7b7242e324080afcfb50a1c22f76766644a6f36b 100644 |
--- a/media/video/capture/file_video_capture_device.cc |
+++ b/media/video/capture/file_video_capture_device.cc |
@@ -110,10 +110,10 @@ void ParseY4MTags(const std::string& file_header, |
// video frame. |
// Restrictions: Only trivial per-frame headers are supported. |
int64 ParseFileAndExtractVideoFormat( |
- const base::PlatformFile& file, |
+ base::File* file, |
media::VideoCaptureFormat* video_format) { |
std::string header(kY4MHeaderMaxSize, 0); |
- base::ReadPlatformFile(file, 0, &header[0], kY4MHeaderMaxSize - 1); |
+ file->Read(0, &header[0], kY4MHeaderMaxSize - 1); |
size_t header_end = header.find(kY4MSimpleFrameDelimiter); |
CHECK_NE(header_end, header.npos); |
@@ -124,15 +124,10 @@ int64 ParseFileAndExtractVideoFormat( |
// Opens a given file for reading, and returns the file to the caller, who is |
// responsible for closing it. |
-base::PlatformFile OpenFileForRead(const base::FilePath& file_path) { |
- base::PlatformFileError file_error; |
- base::PlatformFile file = base::CreatePlatformFile( |
- file_path, |
- base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, |
- NULL, |
- &file_error); |
- CHECK_EQ(file_error, base::PLATFORM_FILE_OK); |
- return file; |
+base::File OpenFileForRead(const base::FilePath& file_path) { |
+ base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
+ CHECK(file.IsValid()); |
+ return file.Pass(); |
} |
// Inspects the command line and retrieves the file path parameter. |
@@ -160,12 +155,10 @@ void FileVideoCaptureDevice::GetDeviceNames(Names* const device_names) { |
void FileVideoCaptureDevice::GetDeviceSupportedFormats( |
const Name& device, |
VideoCaptureFormats* supported_formats) { |
- base::PlatformFile file = OpenFileForRead(GetFilePathFromCommandLine()); |
+ base::File file = OpenFileForRead(GetFilePathFromCommandLine()); |
VideoCaptureFormat capture_format; |
- ParseFileAndExtractVideoFormat(file, &capture_format); |
+ ParseFileAndExtractVideoFormat(&file, &capture_format); |
supported_formats->push_back(capture_format); |
- |
- CHECK(base::ClosePlatformFile(file)); |
} |
VideoCaptureDevice* FileVideoCaptureDevice::Create(const Name& device_name) { |
@@ -180,7 +173,6 @@ VideoCaptureDevice* FileVideoCaptureDevice::Create(const Name& device_name) { |
FileVideoCaptureDevice::FileVideoCaptureDevice(const base::FilePath& file_path) |
: capture_thread_("CaptureThread"), |
file_path_(file_path), |
- file_(base::kInvalidPlatformFileValue), |
frame_size_(0), |
current_byte_index_(0), |
first_frame_byte_index_(0) {} |
@@ -232,10 +224,10 @@ void FileVideoCaptureDevice::OnAllocateAndStart( |
client_ = client.Pass(); |
// Open the file and parse the header. Get frame size and format. |
- DCHECK_EQ(file_, base::kInvalidPlatformFileValue); |
+ DCHECK(file_.IsValid()); |
file_ = OpenFileForRead(file_path_); |
first_frame_byte_index_ = |
- ParseFileAndExtractVideoFormat(file_, &capture_format_); |
+ ParseFileAndExtractVideoFormat(&file_, &capture_format_); |
current_byte_index_ = first_frame_byte_index_; |
DVLOG(1) << "Opened video file " << capture_format_.frame_size.ToString() |
<< ", fps: " << capture_format_.frame_rate; |
@@ -251,7 +243,7 @@ void FileVideoCaptureDevice::OnAllocateAndStart( |
void FileVideoCaptureDevice::OnStopAndDeAllocate() { |
DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current()); |
- CHECK(base::ClosePlatformFile(file_)); |
+ file_.Close(); |
client_.reset(); |
current_byte_index_ = 0; |
first_frame_byte_index_ = 0; |
@@ -263,21 +255,18 @@ void FileVideoCaptureDevice::OnCaptureTask() { |
DCHECK_EQ(capture_thread_.message_loop(), base::MessageLoop::current()); |
if (!client_) |
return; |
- int result = |
- base::ReadPlatformFile(file_, |
- current_byte_index_, |
- reinterpret_cast<char*>(video_frame_.get()), |
- frame_size_); |
+ int result = file_.Read(current_byte_index_, |
+ reinterpret_cast<char*>(video_frame_.get()), |
+ frame_size_); |
- // If we passed EOF to PlatformFile, it will return 0 read characters. In that |
+ // If we passed EOF to base::File, it will return 0 read characters. In that |
// case, reset the pointer and read again. |
if (result != frame_size_) { |
CHECK_EQ(result, 0); |
current_byte_index_ = first_frame_byte_index_; |
- CHECK_EQ(base::ReadPlatformFile(file_, |
- current_byte_index_, |
- reinterpret_cast<char*>(video_frame_.get()), |
- frame_size_), |
+ CHECK_EQ(file_.Read(current_byte_index_, |
+ reinterpret_cast<char*>(video_frame_.get()), |
+ frame_size_), |
frame_size_); |
} else { |
current_byte_index_ += frame_size_ + kY4MSimpleFrameDelimiterSize; |