diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 04:47:31 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-10 04:47:31 +0000 |
commit | f1ca6dfe8f214f66dd7ab58d8bc30fe1e8553352 (patch) | |
tree | 5107ccd0d038153d126a1d3e842dd042944f31f3 | |
parent | c2e45bf3a3207e2072c78804b012309de511275a (diff) | |
download | chromium_src-f1ca6dfe8f214f66dd7ab58d8bc30fe1e8553352.zip chromium_src-f1ca6dfe8f214f66dd7ab58d8bc30fe1e8553352.tar.gz chromium_src-f1ca6dfe8f214f66dd7ab58d8bc30fe1e8553352.tar.bz2 |
Take advantage of the new Pass() machinery on scoped_ptr{,_malloc}.
Pass() was announced in
https://groups.google.com/a/chromium.org/d/topic/chromium-dev/RTd7rNxHjqk/discussion
This CL replaces comments about ownership transfer (in all files whose paths
contain media/) with the explicit passing of the appropriate scoper.
The exceptions that are not touched by this CL:
- scoped_refptr<> doesn't support Pass() and so is untouched.
- media/audio code defines its own callback machinery, mimicking the old-style
callbacks (pass by pointer, explicit deletes). I think that whole pile needs
to be replaced with new-style (Bind) callbacks, so left it alone for now.
BUG=none
TEST=trybots
Review URL: http://codereview.chromium.org/9015015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117009 0039d316-1c4b-4281-b951-d872f2087c98
49 files changed, 267 insertions, 254 deletions
diff --git a/content/renderer/media/render_media_log.cc b/content/renderer/media/render_media_log.cc index b5d701f..2081078 100644 --- a/content/renderer/media/render_media_log.cc +++ b/content/renderer/media/render_media_log.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -15,14 +15,13 @@ RenderMediaLog::RenderMediaLog() "RenderMediaLog must be constructed on the render thread"; } -void RenderMediaLog::AddEvent(media::MediaLogEvent* event) { - scoped_ptr<media::MediaLogEvent> e(event); - +void RenderMediaLog::AddEvent(scoped_ptr<media::MediaLogEvent> event) { if (RenderThreadImpl::current()) { - RenderThreadImpl::current()->Send(new ViewHostMsg_MediaLogEvent(*e)); + RenderThreadImpl::current()->Send( + new ViewHostMsg_MediaLogEvent(*event)); } else { - render_loop_->PostTask(FROM_HERE, - base::Bind(&RenderMediaLog::AddEvent, this, e.release())); + render_loop_->PostTask(FROM_HERE, base::Bind( + &RenderMediaLog::AddEvent, this, base::Passed(&event))); } } diff --git a/content/renderer/media/render_media_log.h b/content/renderer/media/render_media_log.h index 63032ae..f7c1746 100644 --- a/content/renderer/media/render_media_log.h +++ b/content/renderer/media/render_media_log.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -19,7 +19,7 @@ class RenderMediaLog : public media::MediaLog { RenderMediaLog(); // MediaLog implementation. - virtual void AddEvent(media::MediaLogEvent* event) OVERRIDE; + virtual void AddEvent(scoped_ptr<media::MediaLogEvent> event) OVERRIDE; private: virtual ~RenderMediaLog(); diff --git a/media/base/async_filter_factory_base.h b/media/base/async_filter_factory_base.h index 303bad9..4a9200e 100644 --- a/media/base/async_filter_factory_base.h +++ b/media/base/async_filter_factory_base.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -62,7 +62,7 @@ class MEDIA_EXPORT AsyncDataSourceFactoryBase : public DataSourceFactory { // NOTE: Nothing in this base class needs to be cloned because this class // only keeps track of pending requests, which are not part of the cloning // process. - virtual DataSourceFactory* Clone() const = 0; + virtual scoped_ptr<DataSourceFactory> Clone() const = 0; protected: class MEDIA_EXPORT BuildRequest { diff --git a/media/base/composite_data_source_factory.cc b/media/base/composite_data_source_factory.cc index e751505..c0c28e1 100644 --- a/media/base/composite_data_source_factory.cc +++ b/media/base/composite_data_source_factory.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -26,7 +26,7 @@ class CompositeDataSourceFactory::BuildRequest void CallNextFactory(); void OnBuildDone(PipelineStatus status, DataSource* data_source); - FactoryList factories_; + FactoryList factories_; // Not owned by this class. }; CompositeDataSourceFactory::CompositeDataSourceFactory() {} @@ -35,21 +35,25 @@ CompositeDataSourceFactory::~CompositeDataSourceFactory() { STLDeleteElements(&factories_); } -void CompositeDataSourceFactory::AddFactory(DataSourceFactory* factory) { - DCHECK(factory); - factories_.push_back(factory); +void CompositeDataSourceFactory::AddFactory( + scoped_ptr<DataSourceFactory> factory) { + DCHECK(factory.get()); + factories_.push_back(factory.release()); } -DataSourceFactory* CompositeDataSourceFactory::Clone() const { - CompositeDataSourceFactory* new_factory = new CompositeDataSourceFactory(); +scoped_ptr<DataSourceFactory> CompositeDataSourceFactory::Clone() const { + scoped_ptr<CompositeDataSourceFactory> new_factory( + new CompositeDataSourceFactory()); for (FactoryList::const_iterator itr = factories_.begin(); itr != factories_.end(); ++itr) { - new_factory->AddFactory((*itr)->Clone()); + new_factory->AddFactory((*itr)->Clone().Pass()); } - return new_factory; + // TODO(fischman): replace the extra scoped_ptr+release() with Pass() when + // http://crbug.com/109026 is fixed. + return scoped_ptr<DataSourceFactory>(new_factory.release()); } bool CompositeDataSourceFactory::AllowRequests() const { diff --git a/media/base/composite_data_source_factory.h b/media/base/composite_data_source_factory.h index 9f962d8..0118ce5 100644 --- a/media/base/composite_data_source_factory.h +++ b/media/base/composite_data_source_factory.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -19,11 +19,11 @@ class MEDIA_EXPORT CompositeDataSourceFactory CompositeDataSourceFactory(); virtual ~CompositeDataSourceFactory(); - // Add factory to this composite. Ownership is transferred here. - void AddFactory(DataSourceFactory* factory); + // Add factory to this composite. + void AddFactory(scoped_ptr<DataSourceFactory> factory); // DataSourceFactory method. - virtual DataSourceFactory* Clone() const OVERRIDE; + virtual scoped_ptr<DataSourceFactory> Clone() const OVERRIDE; protected: // AsyncDataSourceFactoryBase methods. diff --git a/media/base/data_buffer.cc b/media/base/data_buffer.cc index 31b3c1c..b82de51 100644 --- a/media/base/data_buffer.cc +++ b/media/base/data_buffer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -7,8 +7,8 @@ namespace media { -DataBuffer::DataBuffer(uint8* buffer, size_t buffer_size) - : data_(buffer), +DataBuffer::DataBuffer(scoped_array<uint8> buffer, size_t buffer_size) + : data_(buffer.Pass()), buffer_size_(buffer_size), data_size_(buffer_size) { } diff --git a/media/base/data_buffer.h b/media/base/data_buffer.h index bb010f3..6c5c8a9 100644 --- a/media/base/data_buffer.h +++ b/media/base/data_buffer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -17,9 +17,8 @@ namespace media { class MEDIA_EXPORT DataBuffer : public Buffer { public: - // Takes ownership of the passed |buffer|, assumes valid data of size - // |buffer_size|. - DataBuffer(uint8* buffer, size_t buffer_size); + // Assumes valid data of size |buffer_size|. + DataBuffer(scoped_array<uint8> buffer, size_t buffer_size); // Allocates buffer of size |buffer_size|. If |buffer_size| is 0, |data_| is // set to a NULL ptr. diff --git a/media/base/filter_collection.cc b/media/base/filter_collection.cc index ed2339f..42f42d0 100644 --- a/media/base/filter_collection.cc +++ b/media/base/filter_collection.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -12,9 +12,9 @@ FilterCollection::FilterCollection() {} FilterCollection::~FilterCollection() {} -void FilterCollection::SetDemuxerFactory(DemuxerFactory* factory) { - DCHECK(factory); - demuxer_factory_.reset(factory); +void FilterCollection::SetDemuxerFactory(scoped_ptr<DemuxerFactory> factory) { + DCHECK(factory.get()); + demuxer_factory_ = factory.Pass(); } DemuxerFactory* FilterCollection::GetDemuxerFactory() { diff --git a/media/base/filter_collection.h b/media/base/filter_collection.h index edf6b29..f129723 100644 --- a/media/base/filter_collection.h +++ b/media/base/filter_collection.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -21,8 +21,7 @@ class MEDIA_EXPORT FilterCollection { ~FilterCollection(); // DemuxerFactory accessor methods. - // FilterCollection takes ownership of the factory here. - void SetDemuxerFactory(DemuxerFactory* factory); + void SetDemuxerFactory(scoped_ptr<DemuxerFactory> factory); DemuxerFactory* GetDemuxerFactory(); // Adds a filter to the collection. diff --git a/media/base/filter_factories.h b/media/base/filter_factories.h index 8b27c11..6158ff4 100644 --- a/media/base/filter_factories.h +++ b/media/base/filter_factories.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -28,7 +28,7 @@ class MEDIA_EXPORT DataSourceFactory { // Makes a copy of this factory. // NOTE: Pending requests are not cloned. - virtual DataSourceFactory* Clone() const = 0; + virtual scoped_ptr<DataSourceFactory> Clone() const = 0; }; class Demuxer; @@ -46,7 +46,7 @@ class MEDIA_EXPORT DemuxerFactory { // Makes a copy of this factory. // NOTE: Pending requests are not cloned. - virtual DemuxerFactory* Clone() const = 0; + virtual scoped_ptr<DemuxerFactory> Clone() const = 0; }; } // namespace media diff --git a/media/base/media_log.cc b/media/base/media_log.cc index ea61682..d9ac529 100644 --- a/media/base/media_log.cc +++ b/media/base/media_log.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -150,81 +150,81 @@ MediaLog::MediaLog() { MediaLog::~MediaLog() {} -void MediaLog::AddEvent(MediaLogEvent* event) { - scoped_ptr<MediaLogEvent> e(event); +void MediaLog::AddEvent(scoped_ptr<MediaLogEvent> event) { } -MediaLogEvent* MediaLog::CreateEvent(MediaLogEvent::Type type) { +scoped_ptr<MediaLogEvent> MediaLog::CreateEvent(MediaLogEvent::Type type) { scoped_ptr<MediaLogEvent> event(new MediaLogEvent); event->id = id_; event->type = type; event->time = base::Time::Now(); - return event.release(); + return event.Pass(); } -MediaLogEvent* MediaLog::CreateBooleanEvent(MediaLogEvent::Type type, - const char* property, bool value) { +scoped_ptr<MediaLogEvent> MediaLog::CreateBooleanEvent( + MediaLogEvent::Type type, const char* property, bool value) { scoped_ptr<MediaLogEvent> event(CreateEvent(type)); event->params.SetBoolean(property, value); - return event.release(); + return event.Pass(); } -MediaLogEvent* MediaLog::CreateIntegerEvent(MediaLogEvent::Type type, - const char* property, int64 value) { +scoped_ptr<MediaLogEvent> MediaLog::CreateIntegerEvent( + MediaLogEvent::Type type, const char* property, int64 value) { scoped_ptr<MediaLogEvent> event(CreateEvent(type)); event->params.SetInteger(property, value); - return event.release(); + return event.Pass(); } -MediaLogEvent* MediaLog::CreateTimeEvent(MediaLogEvent::Type type, - const char* property, - base::TimeDelta value) { +scoped_ptr<MediaLogEvent> MediaLog::CreateTimeEvent( + MediaLogEvent::Type type, const char* property, base::TimeDelta value) { scoped_ptr<MediaLogEvent> event(CreateEvent(type)); event->params.SetDouble(property, value.InSecondsF()); - return event.release(); + return event.Pass(); } -MediaLogEvent* MediaLog::CreateLoadEvent(const std::string& url) { +scoped_ptr<MediaLogEvent> MediaLog::CreateLoadEvent(const std::string& url) { scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::LOAD)); event->params.SetString("url", url); - return event.release(); + return event.Pass(); } -MediaLogEvent* MediaLog::CreateSeekEvent(float seconds) { +scoped_ptr<MediaLogEvent> MediaLog::CreateSeekEvent(float seconds) { scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::SEEK)); event->params.SetDouble("seek_target", seconds); - return event.release(); + return event.Pass(); } -MediaLogEvent* MediaLog::CreatePipelineStateChangedEvent( +scoped_ptr<MediaLogEvent> MediaLog::CreatePipelineStateChangedEvent( PipelineImpl::State state) { scoped_ptr<MediaLogEvent> event( CreateEvent(MediaLogEvent::PIPELINE_STATE_CHANGED)); event->params.SetString("pipeline_state", PipelineStateToString(state)); - return event.release(); + return event.Pass(); } -MediaLogEvent* MediaLog::CreatePipelineErrorEvent(PipelineStatus error) { +scoped_ptr<MediaLogEvent> MediaLog::CreatePipelineErrorEvent( + PipelineStatus error) { scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::PIPELINE_ERROR)); event->params.SetString("pipeline_error", PipelineStatusToString(error)); - return event.release(); + return event.Pass(); } -MediaLogEvent* MediaLog::CreateVideoSizeSetEvent(size_t width, size_t height) { +scoped_ptr<MediaLogEvent> MediaLog::CreateVideoSizeSetEvent( + size_t width, size_t height) { scoped_ptr<MediaLogEvent> event(CreateEvent(MediaLogEvent::VIDEO_SIZE_SET)); event->params.SetInteger("width", width); event->params.SetInteger("height", height); - return event.release(); + return event.Pass(); } -MediaLogEvent* MediaLog::CreateBufferedExtentsChangedEvent( +scoped_ptr<MediaLogEvent> MediaLog::CreateBufferedExtentsChangedEvent( size_t start, size_t current, size_t end) { scoped_ptr<MediaLogEvent> event( CreateEvent(MediaLogEvent::BUFFERED_EXTENTS_CHANGED)); event->params.SetInteger("buffer_start", start); event->params.SetInteger("buffer_current", current); event->params.SetInteger("buffer_end", end); - return event.release(); + return event.Pass(); } void MediaLog::QueueStatisticsUpdatedEvent(PipelineStatistics stats) { @@ -255,7 +255,7 @@ void MediaLog::AddStatisticsUpdatedEvent() { last_statistics_.video_frames_decoded); event->params.SetInteger("video_frames_dropped", last_statistics_.video_frames_dropped); - AddEvent(event.release()); + AddEvent(event.Pass()); stats_update_pending_ = false; } diff --git a/media/base/media_log.h b/media/base/media_log.h index 9f5e668..236c533 100644 --- a/media/base/media_log.h +++ b/media/base/media_log.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -26,24 +26,25 @@ class MEDIA_EXPORT MediaLog : public base::RefCountedThreadSafe<MediaLog> { // Add an event to this log. Overriden by inheritors to actually do something // with it. - // Takes ownership of |event|. - virtual void AddEvent(MediaLogEvent* event); + virtual void AddEvent(scoped_ptr<MediaLogEvent> event); // Helper methods to create events and their parameters. - MediaLogEvent* CreateEvent(MediaLogEvent::Type type); - MediaLogEvent* CreateBooleanEvent(MediaLogEvent::Type type, - const char* property, bool value); - MediaLogEvent* CreateIntegerEvent(MediaLogEvent::Type type, - const char* property, int64 value); - MediaLogEvent* CreateTimeEvent(MediaLogEvent::Type type, - const char* property, base::TimeDelta value); - MediaLogEvent* CreateLoadEvent(const std::string& url); - MediaLogEvent* CreateSeekEvent(float seconds); - MediaLogEvent* CreatePipelineStateChangedEvent(PipelineImpl::State state); - MediaLogEvent* CreatePipelineErrorEvent(PipelineStatus error); - MediaLogEvent* CreateVideoSizeSetEvent(size_t width, size_t height); - MediaLogEvent* CreateBufferedExtentsChangedEvent(size_t start, size_t current, - size_t end); + scoped_ptr<MediaLogEvent> CreateEvent(MediaLogEvent::Type type); + scoped_ptr<MediaLogEvent> CreateBooleanEvent( + MediaLogEvent::Type type, const char* property, bool value); + scoped_ptr<MediaLogEvent> CreateIntegerEvent( + MediaLogEvent::Type type, const char* property, int64 value); + scoped_ptr<MediaLogEvent> CreateTimeEvent( + MediaLogEvent::Type type, const char* property, base::TimeDelta value); + scoped_ptr<MediaLogEvent> CreateLoadEvent(const std::string& url); + scoped_ptr<MediaLogEvent> CreateSeekEvent(float seconds); + scoped_ptr<MediaLogEvent> CreatePipelineStateChangedEvent( + PipelineImpl::State state); + scoped_ptr<MediaLogEvent> CreatePipelineErrorEvent(PipelineStatus error); + scoped_ptr<MediaLogEvent> CreateVideoSizeSetEvent( + size_t width, size_t height); + scoped_ptr<MediaLogEvent> CreateBufferedExtentsChangedEvent( + size_t start, size_t current, size_t end); // Called when the pipeline statistics have been updated. // This gets called every frame, so we send the most recent stats after 500ms. diff --git a/media/base/mock_filters.cc b/media/base/mock_filters.cc index a406620..44c0062 100644 --- a/media/base/mock_filters.cc +++ b/media/base/mock_filters.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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 "media/base/mock_filters.h" #include "base/logging.h" +#include "base/memory/scoped_ptr.h" #include "media/base/filter_host.h" using ::testing::_; @@ -65,8 +66,8 @@ void MockDemuxerFactory::RunBuildCallback(const std::string& url, callback.Run(status_, NULL); } -DemuxerFactory* MockDemuxerFactory::Clone() const { - return new MockDemuxerFactory(demuxer_.get()); +scoped_ptr<DemuxerFactory> MockDemuxerFactory::Clone() const { + return scoped_ptr<DemuxerFactory>(new MockDemuxerFactory(demuxer_.get())); } MockDemuxer::MockDemuxer() @@ -124,33 +125,36 @@ MockFilterCollection::MockFilterCollection() MockFilterCollection::~MockFilterCollection() {} -FilterCollection* MockFilterCollection::filter_collection( +scoped_ptr<FilterCollection> MockFilterCollection::filter_collection( bool include_demuxer, bool run_build_callback, bool run_build, PipelineStatus build_status) const { - FilterCollection* collection = new FilterCollection(); + scoped_ptr<FilterCollection> collection(new FilterCollection()); - MockDemuxerFactory* demuxer_factory = - new MockDemuxerFactory(include_demuxer ? demuxer_ : NULL); + scoped_ptr<MockDemuxerFactory> demuxer_factory( + new MockDemuxerFactory(include_demuxer ? demuxer_ : NULL)); if (build_status != PIPELINE_OK) demuxer_factory->SetError(build_status); if (run_build_callback) { ON_CALL(*demuxer_factory, Build(_, _)).WillByDefault(Invoke( - demuxer_factory, &MockDemuxerFactory::RunBuildCallback)); + demuxer_factory.get(), &MockDemuxerFactory::RunBuildCallback)); } // else ignore Build calls. if (run_build) EXPECT_CALL(*demuxer_factory, Build(_, _)); - collection->SetDemuxerFactory(demuxer_factory); + // TODO(fischman): replace the extra scoped_ptr+release() with Pass() when + // http://crbug.com/109026 is fixed. + collection->SetDemuxerFactory(scoped_ptr<DemuxerFactory>( + demuxer_factory.release())); collection->AddVideoDecoder(video_decoder_); collection->AddAudioDecoder(audio_decoder_); collection->AddVideoRenderer(video_renderer_); collection->AddAudioRenderer(audio_renderer_); - return collection; + return collection.Pass(); } void RunFilterCallback(::testing::Unused, const base::Closure& callback) { diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index 5f8a5d7..22a0ce59 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. // @@ -148,7 +148,7 @@ class MockDemuxerFactory : public DemuxerFactory { // DemuxerFactory methods. MOCK_METHOD2(Build, void(const std::string& url, const BuildCallback& callback)); - virtual DemuxerFactory* Clone() const; + virtual scoped_ptr<DemuxerFactory> Clone() const; private: scoped_refptr<MockDemuxer> demuxer_; @@ -294,14 +294,13 @@ class MockFilterCollection { MockVideoRenderer* video_renderer() const { return video_renderer_; } MockAudioRenderer* audio_renderer() const { return audio_renderer_; } - FilterCollection* filter_collection() const { - return filter_collection(true, true, true, PIPELINE_OK); + scoped_ptr<FilterCollection> filter_collection() const { + return filter_collection(true, true, true, PIPELINE_OK).Pass(); } - FilterCollection* filter_collection(bool include_demuxer, - bool run_build_callback, - bool run_build, - PipelineStatus build_status) const; + scoped_ptr<FilterCollection> filter_collection( + bool include_demuxer, bool run_build_callback, bool run_build, + PipelineStatus build_status) const; private: scoped_refptr<MockDemuxer> demuxer_; diff --git a/media/base/pipeline.h b/media/base/pipeline.h index cc38c4b..7d382d0 100644 --- a/media/base/pipeline.h +++ b/media/base/pipeline.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -50,8 +50,7 @@ class MEDIA_EXPORT Pipeline : public base::RefCountedThreadSafe<Pipeline> { // The parameter specifies the type of event that is being signaled. typedef base::Callback<void(NetworkEvent)> NetworkEventCB; - // Initializes pipeline. Pipeline takes ownership of all callbacks passed - // into this method. + // Initializes pipeline. // |ended_callback| will be executed when the media reaches the end. // |error_callback_| will be executed upon an error in the pipeline. // |network_callback_| will be executed when there's a network event. @@ -70,7 +69,7 @@ class MEDIA_EXPORT Pipeline : public base::RefCountedThreadSafe<Pipeline> { // This method is asynchronous and can execute a callback when completed. // If the caller provides a |start_callback|, it will be called when the // pipeline initialization completes. - virtual bool Start(FilterCollection* filter_collection, + virtual bool Start(scoped_ptr<FilterCollection> filter_collection, const std::string& url, const PipelineStatusCB& start_callback) = 0; diff --git a/media/base/pipeline_impl.cc b/media/base/pipeline_impl.cc index 5ea444c..7f709e4 100644 --- a/media/base/pipeline_impl.cc +++ b/media/base/pipeline_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. // @@ -98,11 +98,10 @@ void PipelineImpl::Init(const PipelineStatusCB& ended_callback, } // Creates the PipelineInternal and calls it's start method. -bool PipelineImpl::Start(FilterCollection* collection, +bool PipelineImpl::Start(scoped_ptr<FilterCollection> collection, const std::string& url, const PipelineStatusCB& start_callback) { base::AutoLock auto_lock(lock_); - scoped_ptr<FilterCollection> filter_collection(collection); if (running_) { VLOG(1) << "Media pipeline is already running"; @@ -118,7 +117,7 @@ bool PipelineImpl::Start(FilterCollection* collection, message_loop_->PostTask( FROM_HERE, base::Bind(&PipelineImpl::StartTask, this, - filter_collection.release(), + base::Passed(&collection), url, start_callback)); return true; @@ -626,12 +625,12 @@ void PipelineImpl::OnUpdateStatistics(const PipelineStatistics& stats) { media_log_->QueueStatisticsUpdatedEvent(statistics_); } -void PipelineImpl::StartTask(FilterCollection* filter_collection, +void PipelineImpl::StartTask(scoped_ptr<FilterCollection> filter_collection, const std::string& url, const PipelineStatusCB& start_callback) { DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK_EQ(kCreated, state_); - filter_collection_.reset(filter_collection); + filter_collection_ = filter_collection.Pass(); url_ = url; seek_callback_ = start_callback; diff --git a/media/base/pipeline_impl.h b/media/base/pipeline_impl.h index be55291..c7a8e9f 100644 --- a/media/base/pipeline_impl.h +++ b/media/base/pipeline_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -107,7 +107,7 @@ class MEDIA_EXPORT PipelineImpl virtual void Init(const PipelineStatusCB& ended_callback, const PipelineStatusCB& error_callback, const NetworkEventCB& network_callback) OVERRIDE; - virtual bool Start(FilterCollection* filter_collection, + virtual bool Start(scoped_ptr<FilterCollection> filter_collection, const std::string& uri, const PipelineStatusCB& start_callback) OVERRIDE; virtual void Stop(const PipelineStatusCB& stop_callback) OVERRIDE; @@ -231,7 +231,7 @@ class MEDIA_EXPORT PipelineImpl // The following "task" methods correspond to the public methods, but these // methods are run as the result of posting a task to the PipelineInternal's // message loop. - void StartTask(FilterCollection* filter_collection, + void StartTask(scoped_ptr<FilterCollection> filter_collection, const std::string& url, const PipelineStatusCB& start_callback); diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc index e27bdda..73b62b5 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -205,7 +205,7 @@ class PipelineImplTest : public ::testing::Test { pipeline_->Start(mocks_->filter_collection(true, true, true, - build_status), + build_status).Pass(), "", base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); @@ -328,7 +328,7 @@ TEST_F(PipelineImplTest, NeverInitializes) { pipeline_->Start(mocks_->filter_collection(false, false, true, - PIPELINE_OK), + PIPELINE_OK).Pass(), "", base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); @@ -352,12 +352,9 @@ TEST_F(PipelineImplTest, RequiredFilterMissing) { EXPECT_CALL(callbacks_, OnStart(PIPELINE_ERROR_REQUIRED_FILTER_MISSING)); // Create a filter collection with missing filter. - FilterCollection* collection = - mocks_->filter_collection(false, - true, - true, - PIPELINE_ERROR_REQUIRED_FILTER_MISSING); - pipeline_->Start(collection, "", + scoped_ptr<FilterCollection> collection(mocks_->filter_collection( + false, true, true, PIPELINE_ERROR_REQUIRED_FILTER_MISSING)); + pipeline_->Start(collection.Pass(), "", base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); message_loop_.RunAllPending(); diff --git a/media/base/test_data_util.cc b/media/base/test_data_util.cc index 45a3735..a7fb78e 100644 --- a/media/base/test_data_util.cc +++ b/media/base/test_data_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -42,7 +42,7 @@ void ReadTestDataFile(const std::string& name, scoped_refptr<Buffer>* buffer) { scoped_array<uint8> buf; int buf_size; ReadTestDataFile(name, &buf, &buf_size); - *buffer = new DataBuffer(buf.release(), buf_size); + *buffer = new DataBuffer(buf.Pass(), buf_size); } } // namespace media diff --git a/media/filters/audio_renderer_algorithm_base.h b/media/filters/audio_renderer_algorithm_base.h index 6ea8db5..33f5c31 100644 --- a/media/filters/audio_renderer_algorithm_base.h +++ b/media/filters/audio_renderer_algorithm_base.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -39,12 +39,10 @@ class MEDIA_EXPORT AudioRendererAlgorithmBase { AudioRendererAlgorithmBase(); ~AudioRendererAlgorithmBase(); - // Checks validity of audio parameters and takes ownership of |callback|. - void Initialize(int channels, - int sample_rate, - int sample_bits, - float initial_playback_rate, - const base::Closure& callback); + // Checks validity of audio parameters. + void Initialize( + int channels, int sample_rate, int sample_bits, + float initial_playback_rate, const base::Closure& callback); // Tries to fill |length| bytes of |dest| with possibly scaled data from // our |queue_|. Returns the number of bytes copied into |dest|. diff --git a/media/filters/audio_renderer_algorithm_base_unittest.cc b/media/filters/audio_renderer_algorithm_base_unittest.cc index d685816..5f1db40 100644 --- a/media/filters/audio_renderer_algorithm_base_unittest.cc +++ b/media/filters/audio_renderer_algorithm_base_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. // @@ -31,7 +31,8 @@ TEST(AudioRendererAlgorithmBaseTest, FillBuffer_NormalRate) { // Enqueue a buffer of any size since it doesn't matter. const size_t kDataSize = 1024; - algorithm.EnqueueBuffer(new DataBuffer(new uint8[kDataSize], kDataSize)); + algorithm.EnqueueBuffer(new DataBuffer( + scoped_array<uint8>(new uint8[kDataSize]), kDataSize)); EXPECT_EQ(kDataSize, algorithm.QueueSize()); // Read the same sized amount. @@ -62,7 +63,8 @@ TEST(AudioRendererAlgorithmBaseTest, FillBuffer_DoubleRate) { for (size_t i = 0u; i < arraysize(kTestData); ++i) { const size_t kDataSize = kTestData[i][0]; - algorithm.EnqueueBuffer(new DataBuffer(new uint8[kDataSize], kDataSize)); + algorithm.EnqueueBuffer(new DataBuffer( + scoped_array<uint8>(new uint8[kDataSize]), kDataSize)); EXPECT_EQ(kDataSize, algorithm.QueueSize()); const size_t kExpectedSize = kTestData[i][1]; @@ -94,7 +96,8 @@ TEST(AudioRendererAlgorithmBaseTest, FillBuffer_HalfRate) { for (size_t i = 0u; i < arraysize(kTestData); ++i) { const size_t kDataSize = kTestData[i][0]; - algorithm.EnqueueBuffer(new DataBuffer(new uint8[kDataSize], kDataSize)); + algorithm.EnqueueBuffer(new DataBuffer( + scoped_array<uint8>(new uint8[kDataSize]), kDataSize)); EXPECT_EQ(kDataSize, algorithm.QueueSize()); const size_t kExpectedSize = kTestData[i][1]; @@ -126,7 +129,8 @@ TEST(AudioRendererAlgorithmBaseTest, FillBuffer_QuarterRate) { for (size_t i = 0u; i < arraysize(kTestData); ++i) { const size_t kDataSize = kTestData[i][0]; - algorithm.EnqueueBuffer(new DataBuffer(new uint8[kDataSize], kDataSize)); + algorithm.EnqueueBuffer(new DataBuffer(scoped_array<uint8>( + new uint8[kDataSize]), kDataSize)); EXPECT_EQ(kDataSize, algorithm.QueueSize()); const size_t kExpectedSize = kTestData[i][1]; diff --git a/media/filters/chunk_demuxer.cc b/media/filters/chunk_demuxer.cc index 64fad53..79f6178 100644 --- a/media/filters/chunk_demuxer.cc +++ b/media/filters/chunk_demuxer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -56,7 +56,9 @@ static const uint8 kEmptyCluster[] = { }; // Create an "end of stream" buffer. -static Buffer* CreateEOSBuffer() { return new DataBuffer(0, 0); } +static Buffer* CreateEOSBuffer() { + return new DataBuffer(0); +} class ChunkDemuxerStream : public DemuxerStream { public: diff --git a/media/filters/chunk_demuxer_factory.cc b/media/filters/chunk_demuxer_factory.cc index 0f6920f..aa37221 100644 --- a/media/filters/chunk_demuxer_factory.cc +++ b/media/filters/chunk_demuxer_factory.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -19,11 +19,12 @@ static void InitDone(MessageLoop* message_loop, message_loop->PostTask(FROM_HERE, base::Bind(cb, status, demuxer)); } -ChunkDemuxerFactory::ChunkDemuxerFactory(const std::string& url, - DemuxerFactory* delegate_factory, - ChunkDemuxerClient* client) +ChunkDemuxerFactory::ChunkDemuxerFactory( + const std::string& url, + scoped_ptr<DemuxerFactory> delegate_factory, + ChunkDemuxerClient* client) : url_(url), - delegate_factory_(delegate_factory), + delegate_factory_(delegate_factory.Pass()), client_(client) { DCHECK(delegate_factory_.get()); } @@ -45,8 +46,9 @@ void ChunkDemuxerFactory::Build(const std::string& url, demuxer->Init(base::Bind(&InitDone, MessageLoop::current(), cb, demuxer)); } -DemuxerFactory* ChunkDemuxerFactory::Clone() const { - return new ChunkDemuxerFactory(url_, delegate_factory_->Clone(), client_); +scoped_ptr<DemuxerFactory> ChunkDemuxerFactory::Clone() const { + return scoped_ptr<DemuxerFactory>(new ChunkDemuxerFactory( + url_, delegate_factory_->Clone().Pass(), client_)); } } // namespace media diff --git a/media/filters/chunk_demuxer_factory.h b/media/filters/chunk_demuxer_factory.h index 2cad897..9b9b824 100644 --- a/media/filters/chunk_demuxer_factory.h +++ b/media/filters/chunk_demuxer_factory.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -22,14 +22,14 @@ class ChunkDemuxerClient; // ChunkDemuxer should be used for playback. class MEDIA_EXPORT ChunkDemuxerFactory : public DemuxerFactory { public: - // Takes ownership of |delegate_factory|. - ChunkDemuxerFactory(const std::string& url, DemuxerFactory* delegate_factory, + ChunkDemuxerFactory(const std::string& url, + scoped_ptr<DemuxerFactory> delegate_factory, ChunkDemuxerClient* client); virtual ~ChunkDemuxerFactory(); // DemuxerFactory methods. virtual void Build(const std::string& url, const BuildCallback& cb) OVERRIDE; - virtual DemuxerFactory* Clone() const OVERRIDE; + virtual scoped_ptr<DemuxerFactory> Clone() const OVERRIDE; private: std::string url_; diff --git a/media/filters/dummy_demuxer_factory.cc b/media/filters/dummy_demuxer_factory.cc index 735cf59..e1e924a 100644 --- a/media/filters/dummy_demuxer_factory.cc +++ b/media/filters/dummy_demuxer_factory.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -26,8 +26,9 @@ void DummyDemuxerFactory::Build(const std::string& url, cb.Run(PIPELINE_OK, demuxer.get()); } -DemuxerFactory* DummyDemuxerFactory::Clone() const { - return new DummyDemuxerFactory(has_video_, has_audio_, local_source_); +scoped_ptr<DemuxerFactory> DummyDemuxerFactory::Clone() const { + return scoped_ptr<DemuxerFactory>( + new DummyDemuxerFactory(has_video_, has_audio_, local_source_)); } } // namespace media diff --git a/media/filters/dummy_demuxer_factory.h b/media/filters/dummy_demuxer_factory.h index 0d8a6f7..64e359a 100644 --- a/media/filters/dummy_demuxer_factory.h +++ b/media/filters/dummy_demuxer_factory.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -19,7 +19,7 @@ class MEDIA_EXPORT DummyDemuxerFactory : public DemuxerFactory { // DemuxerFactory methods. virtual void Build(const std::string& url, const BuildCallback& cb) OVERRIDE; - virtual DemuxerFactory* Clone() const OVERRIDE; + virtual scoped_ptr<DemuxerFactory> Clone() const OVERRIDE; private: bool has_video_; diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc index f85d3f3..158f116 100644 --- a/media/filters/ffmpeg_demuxer.cc +++ b/media/filters/ffmpeg_demuxer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -26,9 +26,10 @@ namespace media { // class AVPacketBuffer : public Buffer { public: - AVPacketBuffer(AVPacket* packet, const base::TimeDelta& timestamp, + AVPacketBuffer(scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet, + const base::TimeDelta& timestamp, const base::TimeDelta& duration) - : packet_(packet) { + : packet_(packet.Pass()) { SetTimestamp(timestamp); SetDuration(duration); } @@ -98,7 +99,8 @@ bool FFmpegDemuxerStream::HasPendingReads() { return !read_queue_.empty(); } -void FFmpegDemuxerStream::EnqueuePacket(AVPacket* packet) { +void FFmpegDemuxerStream::EnqueuePacket( + scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet) { DCHECK_EQ(MessageLoop::current(), demuxer_->message_loop()); base::TimeDelta timestamp = ConvertStreamTimestamp(stream_->time_base, packet->pts); @@ -113,13 +115,13 @@ void FFmpegDemuxerStream::EnqueuePacket(AVPacket* packet) { // Convert if the packet if there is bitstream filter. if (packet->data && bitstream_converter_.get() && - !bitstream_converter_->ConvertPacket(packet)) { + !bitstream_converter_->ConvertPacket(packet.get())) { LOG(ERROR) << "Format converstion failed."; } // Enqueue the callback and attempt to satisfy a read immediately. scoped_refptr<Buffer> buffer( - new AVPacketBuffer(packet, timestamp, duration)); + new AVPacketBuffer(packet.Pass(), timestamp, duration)); if (!buffer) { NOTREACHED() << "Unable to allocate AVPacketBuffer"; return; @@ -671,8 +673,7 @@ void FFmpegDemuxer::DemuxTask() { // not refer to inner memory from FFmpeg. av_dup_packet(packet.get()); - // The stream takes ownership of the AVPacket. - demuxer_stream->EnqueuePacket(packet.release()); + demuxer_stream->EnqueuePacket(packet.Pass()); } // Create a loop by posting another task. This allows seek and message loop @@ -723,9 +724,9 @@ void FFmpegDemuxer::StreamHasEnded() { for (iter = streams_.begin(); iter != streams_.end(); ++iter) { if (!*iter) continue; - AVPacket* packet = new AVPacket(); - memset(packet, 0, sizeof(*packet)); - (*iter)->EnqueuePacket(packet); + scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet(new AVPacket()); + memset(packet.get(), 0, sizeof(*packet.get())); + (*iter)->EnqueuePacket(packet.Pass()); } } diff --git a/media/filters/ffmpeg_demuxer.h b/media/filters/ffmpeg_demuxer.h index 5db09b33..66c6ac5 100644 --- a/media/filters/ffmpeg_demuxer.h +++ b/media/filters/ffmpeg_demuxer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -40,6 +40,7 @@ struct AVFormatContext; struct AVPacket; struct AVRational; struct AVStream; +class ScopedPtrAVFreePacket; namespace media { @@ -57,8 +58,8 @@ class FFmpegDemuxerStream : public DemuxerStream { // Safe to call on any thread. bool HasPendingReads(); - // Enqueues and takes ownership over the given AVPacket. - void EnqueuePacket(AVPacket* packet); + // Enqueues the given AVPacket. + void EnqueuePacket(scoped_ptr_malloc<AVPacket, ScopedPtrAVFreePacket> packet); // Signals to empty the buffer queue and mark next packet as discontinuous. void FlushBuffers(); diff --git a/media/filters/ffmpeg_demuxer_factory.cc b/media/filters/ffmpeg_demuxer_factory.cc index dddda76b..439c9d8 100644 --- a/media/filters/ffmpeg_demuxer_factory.cc +++ b/media/filters/ffmpeg_demuxer_factory.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -11,9 +11,9 @@ namespace media { FFmpegDemuxerFactory::FFmpegDemuxerFactory( - DataSourceFactory* data_source_factory, + scoped_ptr<DataSourceFactory> data_source_factory, MessageLoop* loop) - : data_source_factory_(data_source_factory), loop_(loop) {} + : data_source_factory_(data_source_factory.Pass()), loop_(loop) {} FFmpegDemuxerFactory::~FFmpegDemuxerFactory() {} @@ -52,8 +52,9 @@ void FFmpegDemuxerFactory::Build(const std::string& url, cb, loop_, local_source)); } -DemuxerFactory* FFmpegDemuxerFactory::Clone() const { - return new FFmpegDemuxerFactory(data_source_factory_->Clone(), loop_); +scoped_ptr<DemuxerFactory> FFmpegDemuxerFactory::Clone() const { + return scoped_ptr<DemuxerFactory>( + new FFmpegDemuxerFactory(data_source_factory_->Clone(), loop_)); } } // namespace media diff --git a/media/filters/ffmpeg_demuxer_factory.h b/media/filters/ffmpeg_demuxer_factory.h index 8921531..a93f512 100644 --- a/media/filters/ffmpeg_demuxer_factory.h +++ b/media/filters/ffmpeg_demuxer_factory.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -17,14 +17,13 @@ namespace media { class MEDIA_EXPORT FFmpegDemuxerFactory : public DemuxerFactory { public: - // Takes ownership of |data_source_factory|, but not of |loop|. - FFmpegDemuxerFactory(DataSourceFactory* data_source_factory, + FFmpegDemuxerFactory(scoped_ptr<DataSourceFactory> data_source_factory, MessageLoop* loop); virtual ~FFmpegDemuxerFactory(); // DemuxerFactory methods. virtual void Build(const std::string& url, const BuildCallback& cb) OVERRIDE; - virtual DemuxerFactory* Clone() const OVERRIDE; + virtual scoped_ptr<DemuxerFactory> Clone() const OVERRIDE; private: scoped_ptr<DataSourceFactory> data_source_factory_; diff --git a/media/filters/file_data_source_factory.cc b/media/filters/file_data_source_factory.cc index a2109a9..48b917b 100644 --- a/media/filters/file_data_source_factory.cc +++ b/media/filters/file_data_source_factory.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -31,8 +31,8 @@ void FileDataSourceFactory::Build(const std::string& url, callback.Run(status, data_source); } -DataSourceFactory* FileDataSourceFactory::Clone() const { - return new FileDataSourceFactory(); +scoped_ptr<DataSourceFactory> FileDataSourceFactory::Clone() const { + return scoped_ptr<DataSourceFactory>(new FileDataSourceFactory()); } } // namespace media diff --git a/media/filters/file_data_source_factory.h b/media/filters/file_data_source_factory.h index 696df19..f6328ae 100644 --- a/media/filters/file_data_source_factory.h +++ b/media/filters/file_data_source_factory.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -17,7 +17,7 @@ class MEDIA_EXPORT FileDataSourceFactory : public DataSourceFactory { // DataSourceFactory methods. virtual void Build(const std::string& url, const BuildCallback& callback) OVERRIDE; - virtual DataSourceFactory* Clone() const OVERRIDE; + virtual scoped_ptr<DataSourceFactory> Clone() const OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(FileDataSourceFactory); diff --git a/media/filters/gpu_video_decoder.cc b/media/filters/gpu_video_decoder.cc index 9208e4c..442f16f 100644 --- a/media/filters/gpu_video_decoder.cc +++ b/media/filters/gpu_video_decoder.cc @@ -41,9 +41,9 @@ GpuVideoDecoder::BufferTimeData::~BufferTimeData() {} GpuVideoDecoder::GpuVideoDecoder( MessageLoop* message_loop, - Factories* factories) + scoped_ptr<Factories> factories) : message_loop_(message_loop), - factories_(factories), + factories_(factories.Pass()), flush_in_progress_(false), demuxer_read_in_progress_(false), next_picture_buffer_id_(0), diff --git a/media/filters/gpu_video_decoder.h b/media/filters/gpu_video_decoder.h index 3534d92..ea10251 100644 --- a/media/filters/gpu_video_decoder.h +++ b/media/filters/gpu_video_decoder.h @@ -50,8 +50,7 @@ class MEDIA_EXPORT GpuVideoDecoder virtual base::SharedMemory* CreateSharedMemory(size_t size) = 0; }; - // Takes ownership of |factories| but not |message_loop|. - GpuVideoDecoder(MessageLoop* message_loop, Factories* factories); + GpuVideoDecoder(MessageLoop* message_loop, scoped_ptr<Factories> factories); virtual ~GpuVideoDecoder(); // Filter implementation. diff --git a/media/tools/player_wtl/movie.cc b/media/tools/player_wtl/movie.cc index 043932e..44b20b2 100644 --- a/media/tools/player_wtl/movie.cc +++ b/media/tools/player_wtl/movie.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -72,8 +72,10 @@ bool Movie::Open(const wchar_t* url, VideoRendererBase* video_renderer) { // Create filter collection. scoped_ptr<FilterCollection> collection(new FilterCollection()); - collection->SetDemuxerFactory(new FFmpegDemuxerFactory( - new FileDataSourceFactory(), pipeline_loop)); + collection->SetDemuxerFactory( + scoped_ptr<DemuxerFactory>(new FFmpegDemuxerFactory( + scoped_ptr<DataSourceFactory>(new FileDataSourceFactory()), + pipeline_loop))); collection->AddAudioDecoder(new FFmpegAudioDecoder( message_loop_factory_->GetMessageLoop("AudioDecoderThread"))); collection->AddVideoDecoder(new FFmpegVideoDecoder( @@ -89,7 +91,7 @@ bool Movie::Open(const wchar_t* url, VideoRendererBase* video_renderer) { // Create and start our pipeline. media::PipelineStatusNotification note; - pipeline_->Start(collection.release(), WideToUTF8(std::wstring(url)), + pipeline_->Start(collection.Pass(), WideToUTF8(string16(url)), note.Callback()); // Wait until the pipeline is fully initialized. note.Wait(); diff --git a/media/tools/player_x11/player_x11.cc b/media/tools/player_x11/player_x11.cc index ee4d9ab..11188db 100644 --- a/media/tools/player_x11/player_x11.cc +++ b/media/tools/player_x11/player_x11.cc @@ -113,8 +113,9 @@ bool InitPipeline(MessageLoop* message_loop, scoped_ptr<media::FilterCollection> collection( new media::FilterCollection()); collection->SetDemuxerFactory( - new media::FFmpegDemuxerFactory( - new media::FileDataSourceFactory(), message_loop)); + scoped_ptr<media::DemuxerFactory>( + new media::FFmpegDemuxerFactory(scoped_ptr<media::DataSourceFactory>( + new media::FileDataSourceFactory()), message_loop))); collection->AddAudioDecoder(new media::FFmpegAudioDecoder( message_loop_factory->GetMessageLoop("AudioDecoderThread"))); collection->AddVideoDecoder(new media::FFmpegVideoDecoder( @@ -136,7 +137,7 @@ bool InitPipeline(MessageLoop* message_loop, // Create the pipeline and start it. *pipeline = new media::PipelineImpl(message_loop, new media::MediaLog()); media::PipelineStatusNotification note; - (*pipeline)->Start(collection.release(), filename, note.Callback()); + (*pipeline)->Start(collection.Pass(), filename, note.Callback()); // Wait until the pipeline is fully initialized. note.Wait(); diff --git a/media/webm/cluster_builder.cc b/media/webm/cluster_builder.cc index 44c87c8..4c951ad 100644 --- a/media/webm/cluster_builder.cc +++ b/media/webm/cluster_builder.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -31,7 +31,8 @@ const int kSimpleBlockSizeOffset = 1; const int kInitialBufferSize = 32768; -Cluster::Cluster(const uint8* data, int size) : data_(data), size_(size) {} +Cluster::Cluster(scoped_array<uint8> data, int size) + : data_(data.Pass()), size_(size) {} Cluster::~Cluster() {} ClusterBuilder::ClusterBuilder() { Reset(); } @@ -84,14 +85,14 @@ void ClusterBuilder::AddSimpleBlock(int track_num, int64 timecode, int flags, bytes_used_ += bytes_needed; } -Cluster* ClusterBuilder::Finish() { +scoped_ptr<Cluster> ClusterBuilder::Finish() { DCHECK_NE(cluster_timecode_, -1); UpdateUInt64(kClusterSizeOffset, bytes_used_ - (kClusterSizeOffset + 8)); - scoped_ptr<Cluster> ret(new Cluster(buffer_.release(), bytes_used_)); + scoped_ptr<Cluster> ret(new Cluster(buffer_.Pass(), bytes_used_)); Reset(); - return ret.release(); + return ret.Pass(); } void ClusterBuilder::Reset() { diff --git a/media/webm/cluster_builder.h b/media/webm/cluster_builder.h index 132da8a..39cd0d0 100644 --- a/media/webm/cluster_builder.h +++ b/media/webm/cluster_builder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -13,15 +13,14 @@ namespace media { class Cluster { public: - // Takes ownership of |data| - Cluster(const uint8* data, int size); + Cluster(scoped_array<uint8> data, int size); ~Cluster(); const uint8* data() const { return data_.get(); } int size() const { return size_; } private: - scoped_array<const uint8> data_; + scoped_array<uint8> data_; int size_; DISALLOW_IMPLICIT_CONSTRUCTORS(Cluster); @@ -36,7 +35,7 @@ class ClusterBuilder { void AddSimpleBlock(int track_num, int64 timecode, int flags, const uint8* data, int size); - Cluster* Finish(); + scoped_ptr<Cluster> Finish(); private: void Reset(); diff --git a/media/webm/webm_cluster_parser.cc b/media/webm/webm_cluster_parser.cc index 2d84405..8151ec6 100644 --- a/media/webm/webm_cluster_parser.cc +++ b/media/webm/webm_cluster_parser.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -13,7 +13,7 @@ namespace media { static Buffer* CreateBuffer(const uint8* data, size_t size) { scoped_array<uint8> buf(new uint8[size]); memcpy(buf.get(), data, size); - return new DataBuffer(buf.release(), size); + return new DataBuffer(buf.Pass(), size); } WebMClusterParser::WebMClusterParser(int64 timecode_scale, diff --git a/media/webm/webm_parser_unittest.cc b/media/webm/webm_parser_unittest.cc index bfb5624..751af9e 100644 --- a/media/webm/webm_parser_unittest.cc +++ b/media/webm/webm_parser_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -46,9 +46,9 @@ static void AddSimpleBlock(ClusterBuilder* cb, int track_num, cb->AddSimpleBlock(track_num, timecode, 0, data, sizeof(data)); } -static Cluster* CreateCluster(int timecode, - const SimpleBlockInfo* block_info, - int block_count) { +static scoped_ptr<Cluster> CreateCluster(int timecode, + const SimpleBlockInfo* block_info, + int block_count) { ClusterBuilder cb; cb.SetClusterTimecode(0); diff --git a/webkit/media/active_loader.cc b/webkit/media/active_loader.cc index e10098f..767ddff 100644 --- a/webkit/media/active_loader.cc +++ b/webkit/media/active_loader.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -9,8 +9,8 @@ namespace webkit_media { -ActiveLoader::ActiveLoader(WebKit::WebURLLoader* loader) - : loader_(loader), +ActiveLoader::ActiveLoader(scoped_ptr<WebKit::WebURLLoader> loader) + : loader_(loader.Pass()), deferred_(false) { } diff --git a/webkit/media/active_loader.h b/webkit/media/active_loader.h index 8a63ed0..b7300fc 100644 --- a/webkit/media/active_loader.h +++ b/webkit/media/active_loader.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -21,9 +21,7 @@ class ActiveLoader { public: // Creates an ActiveLoader with the given loader. It is assumed that the // initial state of |loader| is loading and not deferred. - // - // ActiveLoader takes ownership of |loader|. - explicit ActiveLoader(WebKit::WebURLLoader* loader); + explicit ActiveLoader(scoped_ptr<WebKit::WebURLLoader> loader); ~ActiveLoader(); // Starts or stops deferring the resource load. diff --git a/webkit/media/buffered_data_source_unittest.cc b/webkit/media/buffered_data_source_unittest.cc index 9150fd0..b63a2c5 100644 --- a/webkit/media/buffered_data_source_unittest.cc +++ b/webkit/media/buffered_data_source_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -54,8 +54,11 @@ class MockBufferedDataSource : public BufferedDataSource { .WillByDefault(Assign(&loading_, true)); ON_CALL(*url_loader, cancel()) .WillByDefault(Assign(&loading_, false)); - - loader->SetURLLoaderForTest(url_loader); + scoped_ptr<NiceMock<MockWebURLLoader> > mwul(url_loader); + // TODO(fischman): replace the extra scoped_ptr+release() with Pass() when + // http://crbug.com/109026 is fixed. + scoped_ptr<WebURLLoader> wul(mwul.release()); + loader->SetURLLoaderForTest(wul.Pass()); return loader; } diff --git a/webkit/media/buffered_resource_loader.cc b/webkit/media/buffered_resource_loader.cc index b1a4003..afac0db 100644 --- a/webkit/media/buffered_resource_loader.cc +++ b/webkit/media/buffered_resource_loader.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -169,20 +169,20 @@ void BufferedResourceLoader::Start( WebString::fromUTF8("identity;q=1, *;q=0")); // Check for our test WebURLLoader. - WebURLLoader* loader = NULL; + scoped_ptr<WebURLLoader> loader; if (test_loader_.get()) { - loader = test_loader_.release(); + loader = test_loader_.Pass(); } else { WebURLLoaderOptions options; options.allowCredentials = true; options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPolicyAllow; - loader = frame->createAssociatedURLLoader(options); + loader.reset(frame->createAssociatedURLLoader(options)); } // Start the resource loading. loader->loadAsynchronously(request, this); - active_loader_.reset(new ActiveLoader(loader)); + active_loader_.reset(new ActiveLoader(loader.Pass())); } void BufferedResourceLoader::Stop() { @@ -317,8 +317,9 @@ const GURL& BufferedResourceLoader::url() { return url_; } -void BufferedResourceLoader::SetURLLoaderForTest(WebURLLoader* test_loader) { - test_loader_.reset(test_loader); +void BufferedResourceLoader::SetURLLoaderForTest( + scoped_ptr<WebURLLoader> test_loader) { + test_loader_ = test_loader.Pass(); } ///////////////////////////////////////////////////////////////////////////// diff --git a/webkit/media/buffered_resource_loader.h b/webkit/media/buffered_resource_loader.h index 28815c3..64db97d 100644 --- a/webkit/media/buffered_resource_loader.h +++ b/webkit/media/buffered_resource_loader.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -125,11 +125,9 @@ class BufferedResourceLoader : public WebKit::WebURLLoaderClient { // Returns resulting URL. virtual const GURL& url(); - // Transfer ownership of an existing WebURLLoader instance for - // testing purposes. - // // |test_loader| will get used the next time Start() is called. - virtual void SetURLLoaderForTest(WebKit::WebURLLoader* test_loader); + virtual void SetURLLoaderForTest( + scoped_ptr<WebKit::WebURLLoader> test_loader); // WebKit::WebURLLoaderClient implementation. virtual void willSendRequest( diff --git a/webkit/media/buffered_resource_loader_unittest.cc b/webkit/media/buffered_resource_loader_unittest.cc index 9416f0f..212b90b 100644 --- a/webkit/media/buffered_resource_loader_unittest.cc +++ b/webkit/media/buffered_resource_loader_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -86,7 +86,7 @@ class BufferedResourceLoaderTest : public testing::Test { gurl_, first_position_, last_position_, BufferedResourceLoader::kThresholdDefer, 0, 0, new media::MediaLog())); - loader_->SetURLLoaderForTest(url_loader_); + loader_->SetURLLoaderForTest(scoped_ptr<WebKit::WebURLLoader>(url_loader_)); } void SetLoaderBuffer(size_t forward_capacity, size_t backward_capacity) { diff --git a/webkit/media/web_data_source_factory.cc b/webkit/media/web_data_source_factory.cc index 4df0dcf..fd50145 100644 --- a/webkit/media/web_data_source_factory.cc +++ b/webkit/media/web_data_source_factory.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -50,9 +50,9 @@ WebDataSourceFactory::WebDataSourceFactory( WebDataSourceFactory::~WebDataSourceFactory() {} -media::DataSourceFactory* WebDataSourceFactory::Clone() const { - return new WebDataSourceFactory(render_loop_, frame_, media_log_, - factory_function_, build_observer_); +scoped_ptr<media::DataSourceFactory> WebDataSourceFactory::Clone() const { + return scoped_ptr<media::DataSourceFactory>(new WebDataSourceFactory( + render_loop_, frame_, media_log_, factory_function_, build_observer_)); } bool WebDataSourceFactory::AllowRequests() const { diff --git a/webkit/media/web_data_source_factory.h b/webkit/media/web_data_source_factory.h index aa8b744..c3ef79d 100644 --- a/webkit/media/web_data_source_factory.h +++ b/webkit/media/web_data_source_factory.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -34,7 +34,7 @@ class WebDataSourceFactory : public media::AsyncDataSourceFactoryBase { virtual ~WebDataSourceFactory(); // DataSourceFactory method. - virtual media::DataSourceFactory* Clone() const OVERRIDE; + virtual scoped_ptr<media::DataSourceFactory> Clone() const OVERRIDE; protected: // AsyncDataSourceFactoryBase methods. diff --git a/webkit/media/webmediaplayer_impl.cc b/webkit/media/webmediaplayer_impl.cc index d2ec3be..c9aa47f 100644 --- a/webkit/media/webmediaplayer_impl.cc +++ b/webkit/media/webmediaplayer_impl.cc @@ -197,26 +197,28 @@ bool WebMediaPlayerImpl::Initialize( new media::CompositeDataSourceFactory()); if (use_simple_data_source) { - data_source_factory->AddFactory(simple_data_source_factory.release()); - data_source_factory->AddFactory(buffered_data_source_factory.release()); + data_source_factory->AddFactory(simple_data_source_factory.Pass()); + data_source_factory->AddFactory(buffered_data_source_factory.Pass()); } else { - data_source_factory->AddFactory(buffered_data_source_factory.release()); - data_source_factory->AddFactory(simple_data_source_factory.release()); + data_source_factory->AddFactory(buffered_data_source_factory.Pass()); + data_source_factory->AddFactory(simple_data_source_factory.Pass()); } scoped_ptr<media::DemuxerFactory> demuxer_factory( - new media::FFmpegDemuxerFactory(data_source_factory.release(), - pipeline_message_loop)); + // TODO(fischman): replace the extra scoped_ptr+release() with Pass() when + // http://crbug.com/109026 is fixed. + new media::FFmpegDemuxerFactory(scoped_ptr<media::DataSourceFactory>( + data_source_factory.release()), pipeline_message_loop)); std::string source_url = GetClient()->sourceURL().spec(); if (!source_url.empty()) { demuxer_factory.reset( new media::ChunkDemuxerFactory(source_url, - demuxer_factory.release(), + demuxer_factory.Pass(), proxy_)); } - filter_collection_->SetDemuxerFactory(demuxer_factory.release()); + filter_collection_->SetDemuxerFactory(demuxer_factory.Pass()); // Add in the default filter factories. filter_collection_->AddAudioDecoder(new media::FFmpegAudioDecoder( @@ -301,8 +303,8 @@ void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { // that the MediaStream represents a local webcam. This will need to // change in the future when GetVideoDecoder is no longer hardcoded to // only return CaptureVideoDecoders. - filter_collection_->SetDemuxerFactory( - new media::DummyDemuxerFactory(has_video, has_audio, true)); + filter_collection_->SetDemuxerFactory(scoped_ptr<media::DemuxerFactory>( + new media::DummyDemuxerFactory(has_video, has_audio, true))); } } @@ -315,7 +317,7 @@ void WebMediaPlayerImpl::load(const WebKit::WebURL& url) { SetNetworkState(WebKit::WebMediaPlayer::Loading); SetReadyState(WebKit::WebMediaPlayer::HaveNothing); pipeline_->Start( - filter_collection_.release(), + filter_collection_.Pass(), url.spec(), base::Bind(&WebMediaPlayerProxy::PipelineInitializationCallback, proxy_.get())); |