| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "chrome/renderer/media/data_source_impl.h" | 7 #include "chrome/renderer/media/data_source_impl.h" |
| 8 #include "chrome/renderer/render_view.h" | 8 #include "chrome/renderer/render_view.h" |
| 9 #include "chrome/renderer/webmediaplayer_delegate_impl.h" | 9 #include "chrome/renderer/webmediaplayer_delegate_impl.h" |
| 10 #include "media/base/filter_host.h" | 10 #include "media/base/filter_host.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 stopped_ = true; | 38 stopped_ = true; |
| 39 | 39 |
| 40 // TODO(hclam): things to do here: | 40 // TODO(hclam): things to do here: |
| 41 // 1. Call to RenderView to cancel the streaming resource request. | 41 // 1. Call to RenderView to cancel the streaming resource request. |
| 42 // 2. Signal download_event_. | 42 // 2. Signal download_event_. |
| 43 download_event_.Signal(); | 43 download_event_.Signal(); |
| 44 | 44 |
| 45 // Post a close file stream task to IO message loop, it will signal the read | 45 // Post a close file stream task to IO message loop, it will signal the read |
| 46 // event. | 46 // event. |
| 47 io_loop_->PostTask( | 47 io_loop_->PostTask( |
| 48 FROM_HERE,NewRunnableMethod(this, &DataSourceImpl::OnCloseFileStream)); | 48 FROM_HERE, NewRunnableMethod(this, &DataSourceImpl::OnCloseFileStream)); |
| 49 | 49 |
| 50 // Wait for close to finish for FileStream. | 50 // Wait for close to finish for FileStream. |
| 51 close_event_.Wait(); | 51 close_event_.Wait(); |
| 52 | 52 |
| 53 // Make sure that when we wake up the stream is closed and destroyed. | 53 // Make sure that when we wake up the stream is closed and destroyed. |
| 54 DCHECK(stream_.get() == NULL); | 54 DCHECK(stream_.get() == NULL); |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool DataSourceImpl::Initialize(const std::string& url) { | 57 bool DataSourceImpl::Initialize(const std::string& url) { |
| 58 // TODO(hclam): call to RenderView by delegate_->view() to initiate a | 58 // TODO(hclam): call to RenderView by delegate_->view() to initiate a |
| 59 // streaming session in the browser process. Call to RenderView by | 59 // streaming session in the browser process. Call to RenderView by |
| 60 // delegate_->view() to initiate a streaming session in the browser process. | 60 // delegate_->view() to initiate a streaming session in the browser process. |
| 61 // We should get a call back at OnReceivedResponse(). | 61 // We should get a call back at OnReceivedResponse(). |
| 62 media_format_.SetAsString(media::MediaFormat::kMimeType, | 62 media_format_.SetAsString(media::MediaFormat::kMimeType, |
| 63 media::mime_type::kApplicationOctetStream); | 63 media::mime_type::kApplicationOctetStream); |
| 64 media_format_.SetAsString(media::MediaFormat::kURL, url); | 64 media_format_.SetAsString(media::MediaFormat::kURL, url); |
| 65 return true; | 65 return true; |
| 66 } | 66 } |
| 67 | 67 |
| 68 size_t DataSourceImpl::Read(char* data, size_t size) { | 68 size_t DataSourceImpl::Read(uint8* data, size_t size) { |
| 69 DCHECK(stream_.get()); | 69 DCHECK(stream_.get()); |
| 70 // Wait until we have downloaded the requested bytes. | 70 // Wait until we have downloaded the requested bytes. |
| 71 while(!stopped_) { | 71 while (!stopped_) { |
| 72 { | 72 { |
| 73 AutoLock auto_lock(lock_); | 73 AutoLock auto_lock(lock_); |
| 74 if (position_ + size <= downloaded_bytes_) | 74 if (position_ + size <= downloaded_bytes_) |
| 75 break; | 75 break; |
| 76 } | 76 } |
| 77 download_event_.Wait(); | 77 download_event_.Wait(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 last_read_size_ = media::DataSource::kReadError; | 80 last_read_size_ = media::DataSource::kReadError; |
| 81 if (!stopped_) { | 81 if (!stopped_) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool DataSourceImpl::GetPosition(int64* position_out) { | 94 bool DataSourceImpl::GetPosition(int64* position_out) { |
| 95 AutoLock auto_lock(lock_); | 95 AutoLock auto_lock(lock_); |
| 96 *position_out = position_; | 96 *position_out = position_; |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 bool DataSourceImpl::SetPosition(int64 position) { | 100 bool DataSourceImpl::SetPosition(int64 position) { |
| 101 DCHECK(stream_.get()); | 101 DCHECK(stream_.get()); |
| 102 while(!stopped_) { | 102 while (!stopped_) { |
| 103 { | 103 { |
| 104 AutoLock auto_lock(lock_); | 104 AutoLock auto_lock(lock_); |
| 105 if (position < downloaded_bytes_) | 105 if (position < downloaded_bytes_) |
| 106 break; | 106 break; |
| 107 } | 107 } |
| 108 download_event_.Wait(); | 108 download_event_.Wait(); |
| 109 } | 109 } |
| 110 if (!stopped_) { | 110 if (!stopped_) { |
| 111 if (logging::DEBUG_MODE) { | 111 if (logging::DEBUG_MODE) { |
| 112 AutoLock auto_lock_(lock_); | 112 AutoLock auto_lock_(lock_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 135 } | 135 } |
| 136 | 136 |
| 137 void DataSourceImpl::OnCreateFileStream(base::PlatformFile file) { | 137 void DataSourceImpl::OnCreateFileStream(base::PlatformFile file) { |
| 138 stream_.reset( | 138 stream_.reset( |
| 139 new net::FileStream( | 139 new net::FileStream( |
| 140 file, base::PLATFORM_FILE_READ | base::PLATFORM_FILE_ASYNC)); | 140 file, base::PLATFORM_FILE_READ | base::PLATFORM_FILE_ASYNC)); |
| 141 // TODO(hclam): maybe we should check the validity of the file handle. | 141 // TODO(hclam): maybe we should check the validity of the file handle. |
| 142 host_->InitializationComplete(); | 142 host_->InitializationComplete(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void DataSourceImpl::OnReadFileStream(char* data, size_t size) { | 145 void DataSourceImpl::OnReadFileStream(uint8* data, size_t size) { |
| 146 if (!stopped_ && stream_.get()) { | 146 if (!stopped_ && stream_.get()) { |
| 147 // net::FileStream::Read wants a char*, not uint8*. |
| 148 char* c_data = reinterpret_cast<char*>(data); |
| 149 COMPILE_ASSERT(sizeof(*c_data) == sizeof(*data), data_not_sizeof_char); |
| 150 |
| 147 // This method IO operation is asynchronous, it is expected to return | 151 // This method IO operation is asynchronous, it is expected to return |
| 148 // ERROR_IO_PENDING, when the operation is done, OnDidFileStreamRead() will | 152 // ERROR_IO_PENDING, when the operation is done, OnDidFileStreamRead() will |
| 149 // be called. | 153 // be called. Since the file handle is asynchronous, return value other |
| 150 int rv = stream_->Read(data, size, &read_callback_); | 154 // than ERROR_IO_PENDING is an error. |
| 151 | 155 if (stream_->Read(c_data, size, &read_callback_) != net::ERR_IO_PENDING) { |
| 152 // Since the file handle is asynchronous, return value other than | 156 // TODO(hclam): change to PipelineError::PIPELINE_ERROR_READ once ralphl |
| 153 // ERROR_IO_PENDING is an error. | 157 // gets the new pipeline CL checked in. |
| 154 if (rv != net::ERR_IO_PENDING) { | |
| 155 // TODO(hclam): using something like PipelineError::PIPELINE_READ_ERROR. | |
| 156 host_->Error(media::PIPELINE_ERROR_NETWORK); | 158 host_->Error(media::PIPELINE_ERROR_NETWORK); |
| 157 } | 159 } |
| 158 } | 160 } |
| 159 } | 161 } |
| 160 | 162 |
| 161 void DataSourceImpl::OnCloseFileStream() { | 163 void DataSourceImpl::OnCloseFileStream() { |
| 162 if (stream_.get()) { | 164 if (stream_.get()) { |
| 163 stream_->Close(); | 165 stream_->Close(); |
| 164 stream_.reset(); | 166 stream_.reset(); |
| 165 } | 167 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 downloaded_bytes_ += bytes; | 221 downloaded_bytes_ += bytes; |
| 220 if (!total_bytes_known_) | 222 if (!total_bytes_known_) |
| 221 total_bytes_ += bytes; | 223 total_bytes_ += bytes; |
| 222 } | 224 } |
| 223 download_event_.Signal(); | 225 download_event_.Signal(); |
| 224 } | 226 } |
| 225 | 227 |
| 226 const media::MediaFormat* DataSourceImpl::GetMediaFormat() { | 228 const media::MediaFormat* DataSourceImpl::GetMediaFormat() { |
| 227 return &media_format_; | 229 return &media_format_; |
| 228 } | 230 } |
| OLD | NEW |