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" |
| 6 |
5 #include <limits> | 7 #include <limits> |
6 | 8 |
7 #include "base/file_util.h" | 9 #include "base/file_util.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
10 #include "media/base/pipeline.h" | |
11 #include "media/filters/file_data_source.h" | |
12 | 12 |
13 namespace media { | 13 namespace media { |
14 | 14 |
15 FileDataSource::FileDataSource() | 15 FileDataSource::FileDataSource() |
16 : file_(NULL), | 16 : file_(NULL), |
17 file_size_(0), | 17 file_size_(0), |
18 disable_file_size_(false) { | 18 disable_file_size_(false) { |
19 } | 19 } |
20 | 20 |
21 FileDataSource::FileDataSource(bool disable_file_size) | 21 FileDataSource::FileDataSource(bool disable_file_size) |
22 : file_(NULL), | 22 : file_(NULL), |
23 file_size_(0), | 23 file_size_(0), |
24 disable_file_size_(disable_file_size) { | 24 disable_file_size_(disable_file_size) { |
25 } | 25 } |
26 | 26 |
27 PipelineStatus FileDataSource::Initialize(const std::string& url) { | 27 bool FileDataSource::Initialize(const std::string& url) { |
28 DCHECK(!file_); | 28 DCHECK(!file_); |
29 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
30 FilePath file_path(UTF8ToWide(url)); | 30 FilePath file_path(UTF8ToWide(url)); |
31 #else | 31 #else |
32 FilePath file_path(url); | 32 FilePath file_path(url); |
33 #endif | 33 #endif |
34 if (file_util::GetFileSize(file_path, &file_size_)) { | 34 if (file_util::GetFileSize(file_path, &file_size_)) { |
35 file_ = file_util::OpenFile(file_path, "rb"); | 35 file_ = file_util::OpenFile(file_path, "rb"); |
36 } | 36 } |
37 if (!file_) { | 37 if (!file_) { |
38 file_size_ = 0; | 38 file_size_ = 0; |
39 return PIPELINE_ERROR_URL_NOT_FOUND; | 39 return false; |
40 } | 40 } |
41 UpdateHostBytes(); | 41 UpdateHostBytes(); |
42 | 42 |
43 return PIPELINE_OK; | 43 return true; |
44 } | 44 } |
45 | 45 |
46 void FileDataSource::set_host(DataSourceHost* host) { | 46 void FileDataSource::set_host(DataSourceHost* host) { |
47 DataSource::set_host(host); | 47 DataSource::set_host(host); |
48 UpdateHostBytes(); | 48 UpdateHostBytes(); |
49 } | 49 } |
50 | 50 |
51 void FileDataSource::Stop(const base::Closure& callback) { | 51 void FileDataSource::Stop(const base::Closure& callback) { |
52 base::AutoLock l(lock_); | 52 base::AutoLock l(lock_); |
53 if (file_) { | 53 if (file_) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 | 107 |
108 void FileDataSource::UpdateHostBytes() { | 108 void FileDataSource::UpdateHostBytes() { |
109 if (host() && file_) { | 109 if (host() && file_) { |
110 host()->SetTotalBytes(file_size_); | 110 host()->SetTotalBytes(file_size_); |
111 host()->AddBufferedByteRange(0, file_size_); | 111 host()->AddBufferedByteRange(0, file_size_); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 } // namespace media | 115 } // namespace media |
OLD | NEW |