OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <limits> | 5 #include <limits> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "media/base/filter_host.h" | 10 #include "media/base/filter_host.h" |
11 #include "media/base/filters.h" | 11 #include "media/base/filters.h" |
12 #include "media/base/pipeline.h" | 12 #include "media/base/pipeline.h" |
13 #include "media/filters/file_data_source.h" | 13 #include "media/filters/file_data_source.h" |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 FileDataSource::FileDataSource() | 17 FileDataSource::FileDataSource() |
18 : file_(NULL), | 18 : file_(NULL), |
19 file_size_(0) { | 19 file_size_(0), |
| 20 disable_file_size_(false) { |
| 21 } |
| 22 |
| 23 FileDataSource::FileDataSource(bool disable_file_size) |
| 24 : file_(NULL), |
| 25 file_size_(0), |
| 26 disable_file_size_(disable_file_size) { |
20 } | 27 } |
21 | 28 |
22 FileDataSource::~FileDataSource() { | 29 FileDataSource::~FileDataSource() { |
23 DCHECK(!file_); | 30 DCHECK(!file_); |
24 } | 31 } |
25 | 32 |
26 PipelineStatus FileDataSource::Initialize(const std::string& url) { | 33 PipelineStatus FileDataSource::Initialize(const std::string& url) { |
27 DCHECK(!file_); | 34 DCHECK(!file_); |
28 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
29 FilePath file_path(UTF8ToWide(url)); | 36 FilePath file_path(UTF8ToWide(url)); |
30 #else | 37 #else |
31 FilePath file_path(url); | 38 FilePath file_path(url); |
32 #endif | 39 #endif |
33 if (file_util::GetFileSize(file_path, &file_size_)) { | 40 if (file_util::GetFileSize(file_path, &file_size_)) { |
34 file_ = file_util::OpenFile(file_path, "rb"); | 41 file_ = file_util::OpenFile(file_path, "rb"); |
35 } | 42 } |
36 if (!file_) { | 43 if (!file_) { |
37 file_size_ = 0; | 44 file_size_ = 0; |
38 return PIPELINE_ERROR_URL_NOT_FOUND; | 45 return PIPELINE_ERROR_URL_NOT_FOUND; |
39 } | 46 } |
40 if (host()) { | 47 UpdateHostBytes(); |
41 host()->SetTotalBytes(file_size_); | |
42 host()->SetBufferedBytes(file_size_); | |
43 } | |
44 | 48 |
45 return PIPELINE_OK; | 49 return PIPELINE_OK; |
46 } | 50 } |
47 | 51 |
48 void FileDataSource::set_host(FilterHost* filter_host) { | 52 void FileDataSource::set_host(FilterHost* filter_host) { |
49 DataSource::set_host(filter_host); | 53 DataSource::set_host(filter_host); |
50 if (file_) { | 54 UpdateHostBytes(); |
| 55 } |
| 56 |
| 57 void FileDataSource::UpdateHostBytes() { |
| 58 if (host() && file_) { |
51 host()->SetTotalBytes(file_size_); | 59 host()->SetTotalBytes(file_size_); |
52 host()->SetBufferedBytes(file_size_); | 60 host()->SetBufferedBytes(file_size_); |
53 } | 61 } |
54 } | 62 } |
55 | 63 |
56 void FileDataSource::Stop(FilterCallback* callback) { | 64 void FileDataSource::Stop(FilterCallback* callback) { |
57 base::AutoLock l(lock_); | 65 base::AutoLock l(lock_); |
58 if (file_) { | 66 if (file_) { |
59 file_util::CloseFile(file_); | 67 file_util::CloseFile(file_); |
60 file_ = NULL; | 68 file_ = NULL; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 104 } |
97 | 105 |
98 callback->RunWithParams(Tuple1<size_t>(static_cast<size_t>(kReadError))); | 106 callback->RunWithParams(Tuple1<size_t>(static_cast<size_t>(kReadError))); |
99 } | 107 } |
100 | 108 |
101 bool FileDataSource::GetSize(int64* size_out) { | 109 bool FileDataSource::GetSize(int64* size_out) { |
102 DCHECK(size_out); | 110 DCHECK(size_out); |
103 DCHECK(file_); | 111 DCHECK(file_); |
104 base::AutoLock l(lock_); | 112 base::AutoLock l(lock_); |
105 *size_out = file_size_; | 113 *size_out = file_size_; |
106 return (NULL != file_); | 114 return (NULL != file_ && !disable_file_size_); |
107 } | 115 } |
108 | 116 |
109 bool FileDataSource::IsStreaming() { | 117 bool FileDataSource::IsStreaming() { |
110 return false; | 118 return false; |
111 } | 119 } |
112 | 120 |
113 void FileDataSource::SetPreload(Preload preload) {} | 121 void FileDataSource::SetPreload(Preload preload) { |
| 122 } |
| 123 |
| 124 void FileDataSource::SetBitrate(int bitrate) { |
| 125 } |
114 | 126 |
115 } // namespace media | 127 } // namespace media |
OLD | NEW |