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

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

Issue 155469: Splitting media filter's Initialize() into Create() + callback and Seek() + callback. (Closed)
Patch Set: Fixed valgrind errors Created 11 years, 5 months 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
« no previous file with comments | « media/filters/file_data_source.h ('k') | media/filters/file_data_source_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "media/base/filter_host.h" 7 #include "media/base/filter_host.h"
8 #include "media/base/filters.h" 8 #include "media/base/filters.h"
9 #include "media/base/pipeline.h" 9 #include "media/base/pipeline.h"
10 #include "media/filters/file_data_source.h" 10 #include "media/filters/file_data_source.h"
11 11
12 namespace media { 12 namespace media {
13 13
14 FileDataSource::FileDataSource() 14 FileDataSource::FileDataSource()
15 : file_(NULL), 15 : file_(NULL),
16 file_size_(0) { 16 file_size_(0) {
17 } 17 }
18 18
19 FileDataSource::~FileDataSource() { 19 FileDataSource::~FileDataSource() {
20 Stop(); 20 Stop();
21 } 21 }
22 22
23 bool FileDataSource::Initialize(const std::string& url) { 23 void FileDataSource::Initialize(const std::string& url,
24 FilterCallback* callback) {
24 DCHECK(!file_); 25 DCHECK(!file_);
26 scoped_ptr<FilterCallback> c(callback);
25 #if defined(OS_WIN) 27 #if defined(OS_WIN)
26 FilePath file_path(UTF8ToWide(url)); 28 FilePath file_path(UTF8ToWide(url));
27 #else 29 #else
28 FilePath file_path(url); 30 FilePath file_path(url);
29 #endif 31 #endif
30 if (file_util::GetFileSize(file_path, &file_size_)) { 32 if (file_util::GetFileSize(file_path, &file_size_)) {
31 file_ = file_util::OpenFile(file_path, "rb"); 33 file_ = file_util::OpenFile(file_path, "rb");
32 } 34 }
33 if (!file_) { 35 if (!file_) {
34 file_size_ = 0; 36 file_size_ = 0;
35 host()->Error(PIPELINE_ERROR_URL_NOT_FOUND); 37 host()->Error(PIPELINE_ERROR_URL_NOT_FOUND);
36 return false; 38 callback->Run();
39 return;
37 } 40 }
38 media_format_.SetAsString(MediaFormat::kMimeType, 41 media_format_.SetAsString(MediaFormat::kMimeType,
39 mime_type::kApplicationOctetStream); 42 mime_type::kApplicationOctetStream);
40 media_format_.SetAsString(MediaFormat::kURL, url); 43 media_format_.SetAsString(MediaFormat::kURL, url);
41 host()->SetTotalBytes(file_size_); 44 host()->SetTotalBytes(file_size_);
42 host()->SetBufferedBytes(file_size_); 45 host()->SetBufferedBytes(file_size_);
43 host()->InitializationComplete(); 46 callback->Run();
44 return true;
45 } 47 }
46 48
47 void FileDataSource::Stop() { 49 void FileDataSource::Stop() {
48 AutoLock l(lock_); 50 AutoLock l(lock_);
49 if (file_) { 51 if (file_) {
50 file_util::CloseFile(file_); 52 file_util::CloseFile(file_);
51 file_ = NULL; 53 file_ = NULL;
52 file_size_ = 0; 54 file_size_ = 0;
53 } 55 }
54 } 56 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 *size_out = file_size_; 112 *size_out = file_size_;
111 return (NULL != file_); 113 return (NULL != file_);
112 } 114 }
113 115
114 bool FileDataSource::IsSeekable() { 116 bool FileDataSource::IsSeekable() {
115 // A file data source is always seekable. 117 // A file data source is always seekable.
116 return true; 118 return true;
117 } 119 }
118 120
119 } // namespace media 121 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/file_data_source.h ('k') | media/filters/file_data_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698