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

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: 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()
DaleCurtis 2012/11/13 03:42:28 Might be worth just replacing most of this a FileU
scherkus (not reviewing) 2012/11/13 18:19:13 I'll do a follow up CL
16 : file_(NULL), 16 : file_(NULL),
17 file_size_(0), 17 file_size_(0),
18 disable_file_size_(false) { 18 disable_file_size_(false),
19 } 19 force_read_errors_(false),
20 20 force_streaming_(false) {
21 FileDataSource::FileDataSource(bool disable_file_size)
22 : file_(NULL),
23 file_size_(0),
24 disable_file_size_(disable_file_size) {
25 } 21 }
26 22
27 bool FileDataSource::Initialize(const std::string& url) { 23 bool FileDataSource::Initialize(const std::string& url) {
28 DCHECK(!file_); 24 DCHECK(!file_);
29 #if defined(OS_WIN) 25 #if defined(OS_WIN)
30 FilePath file_path(UTF8ToWide(url)); 26 FilePath file_path(UTF8ToWide(url));
31 #else 27 #else
32 FilePath file_path(url); 28 FilePath file_path(url);
33 #endif 29 #endif
34 if (file_util::GetFileSize(file_path, &file_size_)) { 30 if (file_util::GetFileSize(file_path, &file_size_)) {
(...skipping 21 matching lines...) Expand all
56 file_size_ = 0; 52 file_size_ = 0;
57 } 53 }
58 if (!callback.is_null()) 54 if (!callback.is_null())
59 callback.Run(); 55 callback.Run();
60 } 56 }
61 57
62 void FileDataSource::Read(int64 position, int size, uint8* data, 58 void FileDataSource::Read(int64 position, int size, uint8* data,
63 const DataSource::ReadCB& read_cb) { 59 const DataSource::ReadCB& read_cb) {
64 DCHECK(file_); 60 DCHECK(file_);
65 base::AutoLock l(lock_); 61 base::AutoLock l(lock_);
66 if (file_) { 62
63 if (!force_read_errors_ && file_) {
67 #if defined(OS_WIN) 64 #if defined(OS_WIN)
68 if (_fseeki64(file_, position, SEEK_SET)) { 65 if (_fseeki64(file_, position, SEEK_SET)) {
69 read_cb.Run(DataSource::kReadError); 66 read_cb.Run(DataSource::kReadError);
70 return; 67 return;
71 } 68 }
72 #else 69 #else
73 CHECK(position <= std::numeric_limits<int32>::max()); 70 CHECK(position <= std::numeric_limits<int32>::max());
74 // TODO(hclam): Change fseek() to support 64-bit position. 71 // TODO(hclam): Change fseek() to support 64-bit position.
75 if (fseek(file_, static_cast<int32>(position), SEEK_SET)) { 72 if (fseek(file_, static_cast<int32>(position), SEEK_SET)) {
76 read_cb.Run(DataSource::kReadError); 73 read_cb.Run(DataSource::kReadError);
77 return; 74 return;
78 } 75 }
79 #endif 76 #endif
80 int size_read = fread(data, 1, size, file_); 77 int size_read = fread(data, 1, size, file_);
81 if (size_read == size || !ferror(file_)) { 78 if (size_read == size || !ferror(file_)) {
82 read_cb.Run(size_read); 79 read_cb.Run(size_read);
83 return; 80 return;
84 } 81 }
85 } 82 }
86 83
87 read_cb.Run(kReadError); 84 read_cb.Run(kReadError);
88 } 85 }
89 86
90 bool FileDataSource::GetSize(int64* size_out) { 87 bool FileDataSource::GetSize(int64* size_out) {
91 DCHECK(size_out); 88 DCHECK(size_out);
92 DCHECK(file_); 89 DCHECK(file_);
93 base::AutoLock l(lock_); 90 base::AutoLock l(lock_);
94 *size_out = file_size_; 91 *size_out = file_size_;
95 return (NULL != file_ && !disable_file_size_); 92 return (file_ && !disable_file_size_);
96 } 93 }
97 94
98 bool FileDataSource::IsStreaming() { 95 bool FileDataSource::IsStreaming() {
99 return false; 96 return force_streaming_;
100 } 97 }
101 98
102 void FileDataSource::SetBitrate(int bitrate) {} 99 void FileDataSource::SetBitrate(int bitrate) {}
103 100
104 FileDataSource::~FileDataSource() { 101 FileDataSource::~FileDataSource() {
105 DCHECK(!file_); 102 DCHECK(!file_);
106 } 103 }
107 104
108 void FileDataSource::UpdateHostBytes() { 105 void FileDataSource::UpdateHostBytes() {
109 if (host() && file_) { 106 if (host() && file_) {
110 host()->SetTotalBytes(file_size_); 107 host()->SetTotalBytes(file_size_);
111 host()->AddBufferedByteRange(0, file_size_); 108 host()->AddBufferedByteRange(0, file_size_);
112 } 109 }
113 } 110 }
114 111
115 } // namespace media 112 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698