| 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 <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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 base::AutoLock l(lock_); | 65 base::AutoLock l(lock_); |
| 66 if (file_) { | 66 if (file_) { |
| 67 file_util::CloseFile(file_); | 67 file_util::CloseFile(file_); |
| 68 file_ = NULL; | 68 file_ = NULL; |
| 69 file_size_ = 0; | 69 file_size_ = 0; |
| 70 } | 70 } |
| 71 if (!callback.is_null()) | 71 if (!callback.is_null()) |
| 72 callback.Run(); | 72 callback.Run(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void FileDataSource::Read(int64 position, size_t size, uint8* data, | 75 void FileDataSource::Read(int64 position, int size, uint8* data, |
| 76 const DataSource::ReadCB& read_cb) { | 76 const DataSource::ReadCB& read_cb) { |
| 77 DCHECK(file_); | 77 DCHECK(file_); |
| 78 base::AutoLock l(lock_); | 78 base::AutoLock l(lock_); |
| 79 if (file_) { | 79 if (file_) { |
| 80 #if defined(OS_WIN) | 80 #if defined(OS_WIN) |
| 81 if (_fseeki64(file_, position, SEEK_SET)) { | 81 if (_fseeki64(file_, position, SEEK_SET)) { |
| 82 read_cb.Run(DataSource::kReadError); | 82 read_cb.Run(DataSource::kReadError); |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 #else | 85 #else |
| 86 CHECK(position <= std::numeric_limits<int32>::max()); | 86 CHECK(position <= std::numeric_limits<int32>::max()); |
| 87 // TODO(hclam): Change fseek() to support 64-bit position. | 87 // TODO(hclam): Change fseek() to support 64-bit position. |
| 88 if (fseek(file_, static_cast<int32>(position), SEEK_SET)) { | 88 if (fseek(file_, static_cast<int32>(position), SEEK_SET)) { |
| 89 read_cb.Run(DataSource::kReadError); | 89 read_cb.Run(DataSource::kReadError); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 #endif | 92 #endif |
| 93 size_t size_read = fread(data, 1, size, file_); | 93 int size_read = fread(data, 1, size, file_); |
| 94 if (size_read == size || !ferror(file_)) { | 94 if (size_read == size || !ferror(file_)) { |
| 95 read_cb.Run(size_read); | 95 read_cb.Run(size_read); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 read_cb.Run(kReadError); | 100 read_cb.Run(kReadError); |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool FileDataSource::GetSize(int64* size_out) { | 103 bool FileDataSource::GetSize(int64* size_out) { |
| 104 DCHECK(size_out); | 104 DCHECK(size_out); |
| 105 DCHECK(file_); | 105 DCHECK(file_); |
| 106 base::AutoLock l(lock_); | 106 base::AutoLock l(lock_); |
| 107 *size_out = file_size_; | 107 *size_out = file_size_; |
| 108 return (NULL != file_ && !disable_file_size_); | 108 return (NULL != file_ && !disable_file_size_); |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool FileDataSource::IsStreaming() { | 111 bool FileDataSource::IsStreaming() { |
| 112 return false; | 112 return false; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void FileDataSource::SetPreload(Preload preload) { | 115 void FileDataSource::SetPreload(Preload preload) { |
| 116 } | 116 } |
| 117 | 117 |
| 118 void FileDataSource::SetBitrate(int bitrate) { | 118 void FileDataSource::SetBitrate(int bitrate) { |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace media | 121 } // namespace media |
| OLD | NEW |