| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 media_format_.SetAsString(MediaFormat::kMimeType, | 44 media_format_.SetAsString(MediaFormat::kMimeType, |
| 45 mime_type::kApplicationOctetStream); | 45 mime_type::kApplicationOctetStream); |
| 46 media_format_.SetAsString(MediaFormat::kURL, url); | 46 media_format_.SetAsString(MediaFormat::kURL, url); |
| 47 host()->SetTotalBytes(file_size_); | 47 host()->SetTotalBytes(file_size_); |
| 48 host()->SetBufferedBytes(file_size_); | 48 host()->SetBufferedBytes(file_size_); |
| 49 callback->Run(); | 49 callback->Run(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void FileDataSource::Stop(FilterCallback* callback) { | 52 void FileDataSource::Stop(FilterCallback* callback) { |
| 53 AutoLock l(lock_); | 53 base::AutoLock l(lock_); |
| 54 if (file_) { | 54 if (file_) { |
| 55 file_util::CloseFile(file_); | 55 file_util::CloseFile(file_); |
| 56 file_ = NULL; | 56 file_ = NULL; |
| 57 file_size_ = 0; | 57 file_size_ = 0; |
| 58 } | 58 } |
| 59 if (callback) { | 59 if (callback) { |
| 60 callback->Run(); | 60 callback->Run(); |
| 61 delete callback; | 61 delete callback; |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 const MediaFormat& FileDataSource::media_format() { | 65 const MediaFormat& FileDataSource::media_format() { |
| 66 return media_format_; | 66 return media_format_; |
| 67 } | 67 } |
| 68 | 68 |
| 69 void FileDataSource::Read(int64 position, size_t size, uint8* data, | 69 void FileDataSource::Read(int64 position, size_t size, uint8* data, |
| 70 ReadCallback* read_callback) { | 70 ReadCallback* read_callback) { |
| 71 DCHECK(file_); | 71 DCHECK(file_); |
| 72 AutoLock l(lock_); | 72 base::AutoLock l(lock_); |
| 73 scoped_ptr<ReadCallback> callback(read_callback); | 73 scoped_ptr<ReadCallback> callback(read_callback); |
| 74 if (file_) { | 74 if (file_) { |
| 75 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
| 76 if (_fseeki64(file_, position, SEEK_SET)) { | 76 if (_fseeki64(file_, position, SEEK_SET)) { |
| 77 callback->RunWithParams( | 77 callback->RunWithParams( |
| 78 Tuple1<size_t>(static_cast<size_t>(DataSource::kReadError))); | 78 Tuple1<size_t>(static_cast<size_t>(DataSource::kReadError))); |
| 79 return; | 79 return; |
| 80 } | 80 } |
| 81 #else | 81 #else |
| 82 CHECK(position <= std::numeric_limits<int32>::max()); | 82 CHECK(position <= std::numeric_limits<int32>::max()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 return; | 94 return; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 callback->RunWithParams(Tuple1<size_t>(static_cast<size_t>(kReadError))); | 98 callback->RunWithParams(Tuple1<size_t>(static_cast<size_t>(kReadError))); |
| 99 } | 99 } |
| 100 | 100 |
| 101 bool FileDataSource::GetSize(int64* size_out) { | 101 bool FileDataSource::GetSize(int64* size_out) { |
| 102 DCHECK(size_out); | 102 DCHECK(size_out); |
| 103 DCHECK(file_); | 103 DCHECK(file_); |
| 104 AutoLock l(lock_); | 104 base::AutoLock l(lock_); |
| 105 *size_out = file_size_; | 105 *size_out = file_size_; |
| 106 return (NULL != file_); | 106 return (NULL != file_); |
| 107 } | 107 } |
| 108 | 108 |
| 109 bool FileDataSource::IsStreaming() { | 109 bool FileDataSource::IsStreaming() { |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace media | 113 } // namespace media |
| OLD | NEW |