| 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 "media/filters/file_data_source.h" | 5 #include "media/filters/file_data_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| 11 namespace media { | 11 namespace media { |
| 12 | 12 |
| 13 FileDataSource::FileDataSource() | 13 FileDataSource::FileDataSource() |
| 14 : force_read_errors_(false), | 14 : force_read_errors_(false), |
| 15 force_streaming_(false) { | 15 force_streaming_(false) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 bool FileDataSource::Initialize(const base::FilePath& file_path) { | 18 bool FileDataSource::Initialize(const base::FilePath& file_path) { |
| 19 DCHECK(!file_.IsValid()); | 19 DCHECK(!file_.IsValid()); |
| 20 | 20 |
| 21 if (!file_.Initialize(file_path)) | 21 if (!file_.Initialize(file_path)) |
| 22 return false; | 22 return false; |
| 23 | 23 |
| 24 UpdateHostBytes(); | 24 UpdateHostBytes(); |
| 25 return true; | 25 return true; |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool FileDataSource::InitializeFromPlatformFile( |
| 29 const base::PlatformFile& file) { |
| 30 DCHECK(!file_.IsValid()); |
| 31 |
| 32 if (!file_.Initialize(file)) |
| 33 return false; |
| 34 |
| 35 UpdateHostBytes(); |
| 36 return true; |
| 37 } |
| 38 |
| 28 void FileDataSource::set_host(DataSourceHost* host) { | 39 void FileDataSource::set_host(DataSourceHost* host) { |
| 29 DataSource::set_host(host); | 40 DataSource::set_host(host); |
| 30 UpdateHostBytes(); | 41 UpdateHostBytes(); |
| 31 } | 42 } |
| 32 | 43 |
| 33 void FileDataSource::Stop(const base::Closure& callback) { | 44 void FileDataSource::Stop(const base::Closure& callback) { |
| 34 callback.Run(); | 45 callback.Run(); |
| 35 } | 46 } |
| 36 | 47 |
| 37 void FileDataSource::Read(int64 position, int size, uint8* data, | 48 void FileDataSource::Read(int64 position, int size, uint8* data, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 FileDataSource::~FileDataSource() {} | 80 FileDataSource::~FileDataSource() {} |
| 70 | 81 |
| 71 void FileDataSource::UpdateHostBytes() { | 82 void FileDataSource::UpdateHostBytes() { |
| 72 if (host() && file_.IsValid()) { | 83 if (host() && file_.IsValid()) { |
| 73 host()->SetTotalBytes(file_.length()); | 84 host()->SetTotalBytes(file_.length()); |
| 74 host()->AddBufferedByteRange(0, file_.length()); | 85 host()->AddBufferedByteRange(0, file_.length()); |
| 75 } | 86 } |
| 76 } | 87 } |
| 77 | 88 |
| 78 } // namespace media | 89 } // namespace media |
| OLD | NEW |