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 FileDataSource::FileDataSource(base::File file) | 18 FileDataSource::FileDataSource(base::File file) |
19 : force_read_errors_(false), | 19 : force_read_errors_(false), |
20 force_streaming_(false) { | 20 force_streaming_(false) { |
21 if (!file_.Initialize(file.Pass())) | 21 file_.Initialize(file.Pass()); |
22 return; | |
23 | |
24 UpdateHostBytes(); | |
25 } | 22 } |
26 | 23 |
27 bool FileDataSource::Initialize(const base::FilePath& file_path) { | 24 bool FileDataSource::Initialize(const base::FilePath& file_path) { |
28 DCHECK(!file_.IsValid()); | 25 DCHECK(!file_.IsValid()); |
29 | 26 return file_.Initialize(file_path); |
30 if (!file_.Initialize(file_path)) | |
31 return false; | |
32 | |
33 UpdateHostBytes(); | |
34 return true; | |
35 } | |
36 | |
37 void FileDataSource::set_host(DataSourceHost* host) { | |
38 DataSource::set_host(host); | |
39 UpdateHostBytes(); | |
40 } | 27 } |
41 | 28 |
42 void FileDataSource::Stop(const base::Closure& callback) { | 29 void FileDataSource::Stop(const base::Closure& callback) { |
43 callback.Run(); | 30 callback.Run(); |
44 } | 31 } |
45 | 32 |
46 void FileDataSource::Read(int64 position, int size, uint8* data, | 33 void FileDataSource::Read(int64 position, int size, uint8* data, |
47 const DataSource::ReadCB& read_cb) { | 34 const DataSource::ReadCB& read_cb) { |
48 if (force_read_errors_ || !file_.IsValid()) { | 35 if (force_read_errors_ || !file_.IsValid()) { |
49 read_cb.Run(kReadError); | 36 read_cb.Run(kReadError); |
(...skipping 20 matching lines...) Expand all Loading... |
70 } | 57 } |
71 | 58 |
72 bool FileDataSource::IsStreaming() { | 59 bool FileDataSource::IsStreaming() { |
73 return force_streaming_; | 60 return force_streaming_; |
74 } | 61 } |
75 | 62 |
76 void FileDataSource::SetBitrate(int bitrate) {} | 63 void FileDataSource::SetBitrate(int bitrate) {} |
77 | 64 |
78 FileDataSource::~FileDataSource() {} | 65 FileDataSource::~FileDataSource() {} |
79 | 66 |
80 void FileDataSource::UpdateHostBytes() { | |
81 if (host() && file_.IsValid()) { | |
82 host()->SetTotalBytes(file_.length()); | |
83 host()->AddBufferedByteRange(0, file_.length()); | |
84 } | |
85 } | |
86 | |
87 } // namespace media | 67 } // namespace media |
OLD | NEW |