| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #else | 30 #else |
| 31 FilePath file_path(url); | 31 FilePath file_path(url); |
| 32 #endif | 32 #endif |
| 33 if (file_util::GetFileSize(file_path, &file_size_)) { | 33 if (file_util::GetFileSize(file_path, &file_size_)) { |
| 34 file_ = file_util::OpenFile(file_path, "rb"); | 34 file_ = file_util::OpenFile(file_path, "rb"); |
| 35 } | 35 } |
| 36 if (!file_) { | 36 if (!file_) { |
| 37 file_size_ = 0; | 37 file_size_ = 0; |
| 38 return PIPELINE_ERROR_URL_NOT_FOUND; | 38 return PIPELINE_ERROR_URL_NOT_FOUND; |
| 39 } | 39 } |
| 40 media_format_.SetAsString(MediaFormat::kURL, url); | |
| 41 | |
| 42 if (host()) { | 40 if (host()) { |
| 43 host()->SetTotalBytes(file_size_); | 41 host()->SetTotalBytes(file_size_); |
| 44 host()->SetBufferedBytes(file_size_); | 42 host()->SetBufferedBytes(file_size_); |
| 45 } | 43 } |
| 46 | 44 |
| 47 return PIPELINE_OK; | 45 return PIPELINE_OK; |
| 48 } | 46 } |
| 49 | 47 |
| 50 void FileDataSource::set_host(FilterHost* filter_host) { | 48 void FileDataSource::set_host(FilterHost* filter_host) { |
| 51 DataSource::set_host(filter_host); | 49 DataSource::set_host(filter_host); |
| 52 if (file_) { | 50 if (file_) { |
| 53 host()->SetTotalBytes(file_size_); | 51 host()->SetTotalBytes(file_size_); |
| 54 host()->SetBufferedBytes(file_size_); | 52 host()->SetBufferedBytes(file_size_); |
| 55 } | 53 } |
| 56 } | 54 } |
| 57 | 55 |
| 58 void FileDataSource::Stop(FilterCallback* callback) { | 56 void FileDataSource::Stop(FilterCallback* callback) { |
| 59 base::AutoLock l(lock_); | 57 base::AutoLock l(lock_); |
| 60 if (file_) { | 58 if (file_) { |
| 61 file_util::CloseFile(file_); | 59 file_util::CloseFile(file_); |
| 62 file_ = NULL; | 60 file_ = NULL; |
| 63 file_size_ = 0; | 61 file_size_ = 0; |
| 64 } | 62 } |
| 65 if (callback) { | 63 if (callback) { |
| 66 callback->Run(); | 64 callback->Run(); |
| 67 delete callback; | 65 delete callback; |
| 68 } | 66 } |
| 69 } | 67 } |
| 70 | 68 |
| 71 const MediaFormat& FileDataSource::media_format() { | |
| 72 return media_format_; | |
| 73 } | |
| 74 | |
| 75 void FileDataSource::Read(int64 position, size_t size, uint8* data, | 69 void FileDataSource::Read(int64 position, size_t size, uint8* data, |
| 76 ReadCallback* read_callback) { | 70 ReadCallback* read_callback) { |
| 77 DCHECK(file_); | 71 DCHECK(file_); |
| 78 base::AutoLock l(lock_); | 72 base::AutoLock l(lock_); |
| 79 scoped_ptr<ReadCallback> callback(read_callback); | 73 scoped_ptr<ReadCallback> callback(read_callback); |
| 80 if (file_) { | 74 if (file_) { |
| 81 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
| 82 if (_fseeki64(file_, position, SEEK_SET)) { | 76 if (_fseeki64(file_, position, SEEK_SET)) { |
| 83 callback->RunWithParams( | 77 callback->RunWithParams( |
| 84 Tuple1<size_t>(static_cast<size_t>(DataSource::kReadError))); | 78 Tuple1<size_t>(static_cast<size_t>(DataSource::kReadError))); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 112 return (NULL != file_); | 106 return (NULL != file_); |
| 113 } | 107 } |
| 114 | 108 |
| 115 bool FileDataSource::IsStreaming() { | 109 bool FileDataSource::IsStreaming() { |
| 116 return false; | 110 return false; |
| 117 } | 111 } |
| 118 | 112 |
| 119 void FileDataSource::SetPreload(Preload preload) {} | 113 void FileDataSource::SetPreload(Preload preload) {} |
| 120 | 114 |
| 121 } // namespace media | 115 } // namespace media |
| OLD | NEW |