diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-28 00:13:34 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-28 00:13:34 +0000 |
commit | 8bc72c0b5c0177e153f3fd809ec7ac81b3f91076 (patch) | |
tree | 3ab986f569bf459dd184ef3b201446bbd0038966 /chrome/renderer | |
parent | aed5215a8b568daef4dc9e6d8c501ce52c1eede9 (diff) | |
download | chromium_src-8bc72c0b5c0177e153f3fd809ec7ac81b3f91076.zip chromium_src-8bc72c0b5c0177e153f3fd809ec7ac81b3f91076.tar.gz chromium_src-8bc72c0b5c0177e153f3fd809ec7ac81b3f91076.tar.bz2 |
Remove DataSourceImpl from chrome/renderer/media
Since media in chrome renderer doesn't use file handle
anymore, and these two files are deprecated, remove
them from the tree.
Review URL: http://codereview.chromium.org/115841
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17046 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/media/data_source_impl.cc | 342 | ||||
-rw-r--r-- | chrome/renderer/media/data_source_impl.h | 196 |
2 files changed, 0 insertions, 538 deletions
diff --git a/chrome/renderer/media/data_source_impl.cc b/chrome/renderer/media/data_source_impl.cc deleted file mode 100644 index 68539e8..0000000 --- a/chrome/renderer/media/data_source_impl.cc +++ /dev/null @@ -1,342 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in the -// LICENSE file. - -#include "base/compiler_specific.h" -#include "base/message_loop.h" -#include "base/process_util.h" -#include "chrome/renderer/media/data_source_impl.h" -#include "chrome/renderer/render_view.h" -#include "chrome/renderer/webmediaplayer_delegate_impl.h" -#include "chrome/renderer/render_thread.h" -#include "media/base/filter_host.h" -#include "net/base/load_flags.h" -#include "net/base/net_errors.h" -#include "webkit/glue/webappcachecontext.h" - -DataSourceImpl::DataSourceImpl(WebMediaPlayerDelegateImpl* delegate) - : delegate_(delegate), - render_loop_(RenderThread::current()->message_loop()), - stopped_(false), - download_event_(false, false), - downloaded_bytes_(0), - total_bytes_(0), - total_bytes_known_(false), - download_completed_(false), - resource_loader_bridge_(NULL), - read_event_(false, false), - ALLOW_THIS_IN_INITIALIZER_LIST( - read_callback_(this, &DataSourceImpl::OnDidFileStreamRead)), - stream_(NULL), - last_read_size_(0), - position_(0), - io_loop_(delegate->view()->GetMessageLoopForIO()), - seek_event_(false, false) { -} - -DataSourceImpl::~DataSourceImpl() { -} - -void DataSourceImpl::Stop() { - AutoLock auto_lock(lock_); - if (stopped_) - return; - stopped_ = true; - - // Wakes up demuxer waiting on |read_event_| in Read(). - read_event_.Signal(); - // Wakes up demuxer waiting on |seek_event_| in SetPosition(). - seek_event_.Signal(); - // Wakes up demuxer waiting on |download_event_| in Read() or SetPosition(). - download_event_.Signal(); - - render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &DataSourceImpl::OnDestroy)); -} - -bool DataSourceImpl::Initialize(const std::string& url) { - media_format_.SetAsString(media::MediaFormat::kMimeType, - media::mime_type::kApplicationOctetStream); - media_format_.SetAsString(media::MediaFormat::kURL, url); - render_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &DataSourceImpl::OnInitialize, url)); - return true; -} - -size_t DataSourceImpl::Read(uint8* data, size_t size) { - DCHECK(stream_.get()); - // Wait until we have downloaded the requested bytes. - while (true) { - { - AutoLock auto_lock(lock_); - if (stopped_ || download_completed_ || - position_ + size <= downloaded_bytes_) - break; - } - download_event_.Wait(); - } - - last_read_size_ = media::DataSource::kReadError; - if (logging::DEBUG_MODE) { - AutoLock auto_lock(lock_); - DCHECK(stopped_ || download_completed_ || - position_ + size <= downloaded_bytes_); - } - - // Post a task to IO message loop to perform the actual reading. - bool task_posted = false; - { - AutoLock auto_lock(lock_); - if (!stopped_) { - io_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &DataSourceImpl::OnReadFileStream, - data, size)); - task_posted = true; - } - } - - if (task_posted) - read_event_.Wait(); - - { - AutoLock auto_lock(lock_); - if (!stopped_) - return last_read_size_; - return media::DataSource::kReadError; - } -} - -bool DataSourceImpl::GetPosition(int64* position_out) { - AutoLock auto_lock(lock_); - *position_out = position_; - return true; -} - -bool DataSourceImpl::SetPosition(int64 position) { - DCHECK(stream_.get()); - while (true) { - { - AutoLock auto_lock(lock_); - if (stopped_ || download_completed_ || position < downloaded_bytes_) - break; - } - download_event_.Wait(); - } - - if (logging::DEBUG_MODE) { - AutoLock auto_lock(lock_); - DCHECK(stopped_ || download_completed_ || position < downloaded_bytes_); - } - - // Perform the seek operation on IO message loop. - bool task_posted = false; - { - AutoLock auto_lock(lock_); - if (!stopped_) { - io_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, - &DataSourceImpl::OnSeekFileStream, net::FROM_BEGIN, position)); - task_posted = true; - } - } - if (task_posted) - seek_event_.Wait(); - - if (logging::DEBUG_MODE) { - AutoLock auto_lock_(lock_); - DCHECK(stopped_ || position == position_); - } - return true; -} - -bool DataSourceImpl::GetSize(int64* size_out) { - AutoLock auto_lock(lock_); - if (total_bytes_known_) { - *size_out = total_bytes_; - return true; - } - *size_out = 0; - return false; -} - -bool DataSourceImpl::IsSeekable() { - // If URI is file then it is seekable. - // TODO(hclam): make other protocols seekable. - return uri_.find("file:///") == 0; -} - -void DataSourceImpl::OnCreateFileStream(base::PlatformFile file) { - AutoLock auto_lock(lock_); - if (stopped_) - return; - stream_.reset( - new net::FileStream( - file, base::PLATFORM_FILE_READ | base::PLATFORM_FILE_ASYNC)); - // TODO(hclam): maybe we should check the validity of the file handle. - host_->InitializationComplete(); -} - -void DataSourceImpl::OnReadFileStream(uint8* data, size_t size) { - int error = net::ERR_IO_PENDING; - { - AutoLock auto_lock(lock_); - if (!stopped_) { - // net::FileStream::Read wants a char*, not uint8*. - char* c_data = reinterpret_cast<char*>(data); - COMPILE_ASSERT(sizeof(*c_data) == sizeof(*data), data_not_sizeof_char); - error = stream_->Read(c_data, size, &read_callback_); - } - } - - // Since the file handle is asynchronous, return value other than - // ERROR_IO_PENDING is an error. - if (error != net::ERR_IO_PENDING) { - HandleError(media::PIPELINE_ERROR_READ); - } -} - -void DataSourceImpl::OnSeekFileStream(net::Whence whence, int64 position) { - { - AutoLock auto_lock(lock_); - if (!stopped_) - position_ = stream_->Seek(whence, position); - } - seek_event_.Signal(); -} - -void DataSourceImpl::OnDidFileStreamRead(int size) { - if (size < 0) { - HandleError(media::PIPELINE_ERROR_READ); - } else { - AutoLock auto_lock(lock_); - position_ += size; - } - last_read_size_ = size; - read_event_.Signal(); -} - -void DataSourceImpl::OnInitialize(std::string uri) { - uri_ = uri; - // Create the resource loader bridge. - resource_loader_bridge_.reset( - RenderThread::current()->resource_dispatcher()->CreateBridge( - "GET", - GURL(uri), - GURL(uri), - GURL(), // TODO(hclam): provide referer here. - "null", // TODO(abarth): provide frame_origin - "null", // TODO(abarth): provide main_frame_origin - std::string(), // Provide no header. - // Prefer to load from cache, also enable downloading the file, the - // resource will be saved to a single response data file if it's possible. - net::LOAD_PREFERRING_CACHE | net::LOAD_ENABLE_DOWNLOAD_FILE, - base::GetCurrentProcId(), - ResourceType::MEDIA, - 0, - // TODO(michaeln): delegate->mediaplayer->frame-> - // app_cache_context()->context_id() - // For now don't service media resource requests from the appcache. - WebAppCacheContext::kNoAppCacheContextId, - delegate_->view()->routing_id())); - // Start the resource loading. - resource_loader_bridge_->Start(this); -} - -void DataSourceImpl::OnDestroy() { - DCHECK(MessageLoop::current() == render_loop_); - resource_loader_bridge_->Cancel(); - resource_loader_bridge_.reset(); -} - -void DataSourceImpl::OnDownloadProgress(uint64 position, uint64 size) { - { - AutoLock auto_lock(lock_); - downloaded_bytes_ = position; - if (!total_bytes_known_) { - if (size == kuint64max) { - // If we receive an invalid value for size, we keep on updating the - // total number of bytes. - total_bytes_ = position; - } else { - total_bytes_ = size; - total_bytes_known_ = true; - } - } - } - host_->SetBufferedBytes(downloaded_bytes_); - download_event_.Signal(); -} - -void DataSourceImpl::OnUploadProgress(uint64 position, uint64 size) { - // We don't care about upload progress. -} - -void DataSourceImpl::OnReceivedRedirect(const GURL& new_url) { - // TODO(hclam): what to do here? fire another resource request or show an - // error? -} - -void DataSourceImpl::OnReceivedResponse( - const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, - bool content_filtered) { -#if defined(OS_POSIX) - base::PlatformFile response_data_file = info.response_data_file.fd; -#elif defined(OS_WIN) - base::PlatformFile response_data_file = info.response_data_file; -#endif - - if (response_data_file != base::kInvalidPlatformFileValue) { - DCHECK(!position_ && !downloaded_bytes_); - if (info.content_length != -1) { - total_bytes_known_ = true; - total_bytes_ = info.content_length; - host_->SetTotalBytes(total_bytes_); - } - - { - // Post a task to the IO message loop to create the file stream. - // We don't want to post any more tasks once we are stopped. - AutoLock auto_lock(lock_); - if (!stopped_) { - io_loop_->PostTask(FROM_HERE, - NewRunnableMethod(this, &DataSourceImpl::OnCreateFileStream, - response_data_file)); - } - } - } else { - // TODO(hclam): handle the fallback case of using memory buffer here. - HandleError(media::PIPELINE_ERROR_NETWORK); - } -} - -void DataSourceImpl::OnReceivedData(const char* data, int len) { - // TODO(hclam): we will get this method call when browser process fails - // to provide us with a file handle, come up with some fallback mechanism. -} - -void DataSourceImpl::OnCompletedRequest(const URLRequestStatus& status, - const std::string& security_info) { - { - AutoLock auto_lock(lock_); - total_bytes_known_ = true; - download_completed_ = true; - } - if (status.status() != URLRequestStatus::SUCCESS) { - HandleError(media::PIPELINE_ERROR_NETWORK); - } -} - -void DataSourceImpl::HandleError(media::PipelineError error) { - AutoLock auto_lock(lock_); - if (!stopped_) { - host_->Error(error); - } -} - -std::string DataSourceImpl::GetURLForDebugging() { - return uri_; -} - -const media::MediaFormat& DataSourceImpl::media_format() { - return media_format_; -} diff --git a/chrome/renderer/media/data_source_impl.h b/chrome/renderer/media/data_source_impl.h deleted file mode 100644 index d76f0d4..0000000 --- a/chrome/renderer/media/data_source_impl.h +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in the -// LICENSE file. -// -// A Chrome specific data source for video stack pipeline. The actual resource -// loading would happen in the browser process. This class is given a file -// handle and will ask for progress of downloading from RenderView which -// delegates requests to browser process through IPC. Asynchronous IO will be -// performed on the file handle. -// -// This class is access by 4 different threads during it's lifetime, namely: -// 1. Render thread -// Thread that runs WebKit objects and construct this class. Updates about -// progress for resource loading also happens in this thread. -// 2. Pipeline thread -// Closing thread of the video stack pipeline, it initialized this class -// and performs stopping in an orderly fashion. -// 3. Demuxer thread -// Thread created by the pipeline and ask for data from this class. -// media::DataSource methods are called from this thread. -// 4. IO thread -// Performs file stream construction and callback of read completion also -// comes from this thread. -// -// Methods in the class categorized by the thread(s) they are running on: -// -// Render thread -// +-- DataSourceImpl() -// | Perform construction of this class. -// |-- static CreateFactory() -// | Called during construction of this class. -// |-- OnInitialize() -// | Task posted by Initialize() to kick start resource loading. -// |-- OnCancel() -// | Cancel the resource loading. -// |-- OnDownloadProgress() -// | Receives download progress information for the response data file. -// |-- OnUploadProgress() -// |-- OnReceivedRedirect() -// |-- OnReceivedResponse() -// |-- OnReceivedData() -// |-- OnCompletedRequest() -// |-- GetURLForDebugging() -// \-- OnDestroy() -// -// Pipeline thread -// +-- Initialize() -// | Performs initialization of data source in the pipeline. -// \-- Stop() -// Cease all activities during pipeline tear down. -// -// Demuxer thread -// +-- Read() -// | Called to read from the media file. -// |-- GetPosition() -// | Called to obtain current position in the file. -// |-- SetPosition() -// | Performs a seek operation. -// |-- GetSize() -// | Retrieve the size of the resource. -// \-- IsSeekable() -// Returns true if URL is file:/// or else false. -// -// IO thread -// +-- OnCreateFileStream() -// | Callback for construction of net::FileStream in an IO message loop. -// |-- OnReadFileStream() -// | Actual read operation on FileStream performs here. -// |-- OnSeekFileStream() -// | Actual seek operation happens here. -// \-- OnDidFileStreamRead() -// Callback for asynchronous file read completion. - - -#ifndef CHROME_RENDERER_MEDIA_DATA_SOURCE_IMPL_H_ -#define CHROME_RENDERER_MEDIA_DATA_SOURCE_IMPL_H_ - -#include <string> - -#include "base/lock.h" -#include "base/platform_file.h" -#include "base/scoped_ptr.h" -#include "base/waitable_event.h" -#include "media/base/factory.h" -#include "media/base/filters.h" -#include "media/base/media_format.h" -#include "media/base/pipeline.h" -#include "net/base/completion_callback.h" -#include "net/base/file_stream.h" -#include "webkit/glue/resource_loader_bridge.h" - -class WebMediaPlayerDelegateImpl; - -class DataSourceImpl : public media::DataSource, - public webkit_glue::ResourceLoaderBridge::Peer { - public: - // Methods called from render thread ---------------------------------------- - // Static methods for creating this class. - static media::FilterFactory* CreateFactory( - WebMediaPlayerDelegateImpl* delegate) { - return new media::FilterFactoryImpl1<DataSourceImpl, - WebMediaPlayerDelegateImpl*>(delegate); - } - - // webkit_glue::ResourceLoaderBridge::Peer implementations, receive events - // for resource loading. - virtual void OnDownloadProgress(uint64 position, uint64 size); - virtual void OnUploadProgress(uint64 position, uint64 size); - virtual void OnReceivedRedirect(const GURL& new_url); - virtual void OnReceivedResponse( - const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, - bool content_filtered); - virtual void OnReceivedData(const char* data, int len); - virtual void OnCompletedRequest(const URLRequestStatus& status, - const std::string& security_info); - virtual std::string GetURLForDebugging(); - - // Methods called from pipeline thread -------------------------------------- - virtual bool Initialize(const std::string& url); - // media::MediaFilter implementation. - virtual void Stop(); - - // Methods called from demuxer thread --------------------------------------- - // media::DataSource implementation. - virtual size_t Read(uint8* data, size_t size); - virtual bool GetPosition(int64* position_out); - virtual bool SetPosition(int64 position); - virtual bool GetSize(int64* size_out); - virtual bool IsSeekable(); - - const media::MediaFormat& media_format(); - - private: - friend class media::FilterFactoryImpl1<DataSourceImpl, - WebMediaPlayerDelegateImpl*>; - // Call to filter host to trigger an error, be sure not to call this method - // while the lock is acquired. - void HandleError(media::PipelineError error); - - // Methods called from render thread ---------------------------------------- - explicit DataSourceImpl(WebMediaPlayerDelegateImpl* delegate); - virtual ~DataSourceImpl(); - - // Tasks to be posted on render thread. - void OnInitialize(std::string uri); - void OnCancel(); - void OnDestroy(); - - // Methods called from IO thread -------------------------------------------- - // Handlers for file reading. - void OnCreateFileStream(base::PlatformFile file); - void OnReadFileStream(uint8* data, size_t size); - void OnSeekFileStream(net::Whence whence, int64 position); - void OnDidFileStreamRead(int size); - - media::MediaFormat media_format_; - - // Pointer to the delegate which provides access to RenderView, this is set - // in construction and can be accessed in all threads safely. - WebMediaPlayerDelegateImpl* delegate_; - - // Message loop of render thread. - MessageLoop* render_loop_; - - // A common lock for protecting members accessed by multiple threads. - Lock lock_; - bool stopped_; - - // URI to the resource being downloaded. - std::string uri_; - - // Members for keeping track of downloading progress. - base::WaitableEvent download_event_; - int64 downloaded_bytes_; - int64 total_bytes_; - bool total_bytes_known_; - bool download_completed_; - - // Members related to resource loading with RenderView. - scoped_ptr<webkit_glue::ResourceLoaderBridge> resource_loader_bridge_; - - // Members used for reading. - base::WaitableEvent read_event_; - net::CompletionCallbackImpl<DataSourceImpl> read_callback_; - scoped_ptr<net::FileStream> stream_; - size_t last_read_size_; - int64 position_; - MessageLoop* io_loop_; - - // Events for other operations on stream_. - base::WaitableEvent seek_event_; - - DISALLOW_COPY_AND_ASSIGN(DataSourceImpl); -}; - -#endif // CHROME_RENDERER_MEDIA_DATA_SOURCE_IMPL_H_ |