Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1035)

Side by Side Diff: media/filters/file_data_source.cc

Issue 11410052: Refactor FFmpegURLProtocol code from FFmpegDemuxer into BlockingUrlProtocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 5 #include "media/filters/file_data_source.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.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 force_read_errors_(false),
19 } 19 force_streaming_(false) {
20
21 FileDataSource::FileDataSource(bool disable_file_size)
22 : file_(NULL),
23 file_size_(0),
24 disable_file_size_(disable_file_size) {
25 } 20 }
26 21
27 bool FileDataSource::Initialize(const std::string& url) { 22 bool FileDataSource::Initialize(const std::string& url) {
28 DCHECK(!file_); 23 DCHECK(!file_);
29 #if defined(OS_WIN) 24 #if defined(OS_WIN)
30 FilePath file_path(UTF8ToWide(url)); 25 FilePath file_path(UTF8ToWide(url));
31 #else 26 #else
32 FilePath file_path(url); 27 FilePath file_path(url);
33 #endif 28 #endif
34 if (file_util::GetFileSize(file_path, &file_size_)) { 29 if (file_util::GetFileSize(file_path, &file_size_)) {
(...skipping 21 matching lines...) Expand all
56 file_size_ = 0; 51 file_size_ = 0;
57 } 52 }
58 if (!callback.is_null()) 53 if (!callback.is_null())
59 callback.Run(); 54 callback.Run();
60 } 55 }
61 56
62 void FileDataSource::Read(int64 position, int size, uint8* data, 57 void FileDataSource::Read(int64 position, int size, uint8* data,
63 const DataSource::ReadCB& read_cb) { 58 const DataSource::ReadCB& read_cb) {
64 DCHECK(file_); 59 DCHECK(file_);
65 base::AutoLock l(lock_); 60 base::AutoLock l(lock_);
66 if (file_) { 61
62 if (!force_read_errors_ && file_) {
67 #if defined(OS_WIN) 63 #if defined(OS_WIN)
68 if (_fseeki64(file_, position, SEEK_SET)) { 64 if (_fseeki64(file_, position, SEEK_SET)) {
69 read_cb.Run(DataSource::kReadError); 65 read_cb.Run(DataSource::kReadError);
70 return; 66 return;
71 } 67 }
72 #else 68 #else
73 CHECK(position <= std::numeric_limits<int32>::max()); 69 CHECK(position <= std::numeric_limits<int32>::max());
74 // TODO(hclam): Change fseek() to support 64-bit position. 70 // TODO(hclam): Change fseek() to support 64-bit position.
75 if (fseek(file_, static_cast<int32>(position), SEEK_SET)) { 71 if (fseek(file_, static_cast<int32>(position), SEEK_SET)) {
76 read_cb.Run(DataSource::kReadError); 72 read_cb.Run(DataSource::kReadError);
77 return; 73 return;
78 } 74 }
79 #endif 75 #endif
80 int size_read = fread(data, 1, size, file_); 76 int size_read = fread(data, 1, size, file_);
81 if (size_read == size || !ferror(file_)) { 77 if (size_read == size || !ferror(file_)) {
82 read_cb.Run(size_read); 78 read_cb.Run(size_read);
83 return; 79 return;
84 } 80 }
85 } 81 }
86 82
87 read_cb.Run(kReadError); 83 read_cb.Run(kReadError);
88 } 84 }
89 85
90 bool FileDataSource::GetSize(int64* size_out) { 86 bool FileDataSource::GetSize(int64* size_out) {
91 DCHECK(size_out); 87 DCHECK(size_out);
92 DCHECK(file_); 88 DCHECK(file_);
93 base::AutoLock l(lock_); 89 base::AutoLock l(lock_);
94 *size_out = file_size_; 90 *size_out = file_size_;
95 return (NULL != file_ && !disable_file_size_); 91 return file_;
96 } 92 }
97 93
98 bool FileDataSource::IsStreaming() { 94 bool FileDataSource::IsStreaming() {
99 return false; 95 return force_streaming_;
100 } 96 }
101 97
102 void FileDataSource::SetBitrate(int bitrate) {} 98 void FileDataSource::SetBitrate(int bitrate) {}
103 99
104 FileDataSource::~FileDataSource() { 100 FileDataSource::~FileDataSource() {
105 DCHECK(!file_); 101 DCHECK(!file_);
106 } 102 }
107 103
108 void FileDataSource::UpdateHostBytes() { 104 void FileDataSource::UpdateHostBytes() {
109 if (host() && file_) { 105 if (host() && file_) {
110 host()->SetTotalBytes(file_size_); 106 host()->SetTotalBytes(file_size_);
111 host()->AddBufferedByteRange(0, file_size_); 107 host()->AddBufferedByteRange(0, file_size_);
112 } 108 }
113 } 109 }
114 110
115 } // namespace media 111 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698