Commit 97fc1238 authored by haraken@chromium.org's avatar haraken@chromium.org

Revert 182826 "Oilpan: Move MediaStreamSource, MediaStreamCompon..."

This CL caused https://code.google.com/p/chromium/issues/detail?id=420048

> Oilpan: Move MediaStreamSource, MediaStreamComponent and MediaStreamDescriptor
> to oilpan's heap
> 
> - MediaStreamSource, MediaStreamComponent and MediaStreamDescriptor must be moved
> to oilpan's heap in one go because their lifetime are tightly coupled.
> 
> - Removed m_descriptor->setClient(0) from MediaStream's destructor. This is OK
> because MediaStreamDescriptor has a strong Member back to the Client
> (i.e., MediaStream).
> 
> - Removed m_component->source()->removeObserver(this) from MediaStreamTrack's
> destructor. This is OK because this CL made the observers weak
> (i.e., MediaStreamSource::m_observers is a hash set of weak members to
> MediaStreamTrack objects).
> 
> - Removed WebMediaStreamTrack::ExtraData::m_owner because it's unused.
> 
> - Introduced MediaStreamComponentDisposer to delay the destruction of
> MediaStreamComponent::m_extraData. The ExtraData is exposed to the web
> and some Chromium objects inherit from the ExtraData. If we clear the
> m_extraData in the MediaStreamComponent's destructor, those Chromium-side
> objects are also destructed in the MediaStreamComponent's destructor.
> This is problematic because the destructors of the Chromium-side classes
> can touch other on-heap objects in the Blink side. To avoid the issue,
> we need to delay the destruction of the ExtraData to thread-specific
> weak processing. The disposer pattern actually makes the deletion of
> the extra data happen earlier and not later. The disposer makes sure
> that the extra data is destructed in weak processing which is run before
> sweeping and therefore all the objects are still alive and can be touched.
> 
> 
> - The same problem arises for MediaStreamDescriptor and MediaStreamSource.
> This CL adds MediaStreamDescriptorDisposer and MediaStreamSourceDisposer.
> 
> - This CL depends on https://codereview.chromium.org/543603003/ and https://codereview.chromium.org/549153002.
> 
> BUG=340522
> 
> Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=181702
> 
> Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=182399
> 
> Review URL: https://codereview.chromium.org/552653005

TBR=haraken@chromium.org

Review URL: https://codereview.chromium.org/650413003

git-svn-id: svn://svn.chromium.org/blink/trunk@183663 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d77f9555
......@@ -89,12 +89,12 @@ MediaStream* MediaStream::create(ExecutionContext* context, const MediaStreamTra
return new MediaStream(context, audioTracks, videoTracks);
}
MediaStream* MediaStream::create(ExecutionContext* context, MediaStreamDescriptor* streamDescriptor)
MediaStream* MediaStream::create(ExecutionContext* context, PassRefPtr<MediaStreamDescriptor> streamDescriptor)
{
return new MediaStream(context, streamDescriptor);
}
MediaStream::MediaStream(ExecutionContext* context, MediaStreamDescriptor* streamDescriptor)
MediaStream::MediaStream(ExecutionContext* context, PassRefPtr<MediaStreamDescriptor> streamDescriptor)
: ContextLifecycleObserver(context)
, m_stopped(false)
, m_descriptor(streamDescriptor)
......@@ -147,6 +147,7 @@ MediaStream::MediaStream(ExecutionContext* context, const MediaStreamTrackVector
MediaStream::~MediaStream()
{
m_descriptor->setClient(0);
}
bool MediaStream::ended() const
......@@ -391,9 +392,7 @@ void MediaStream::trace(Visitor* visitor)
visitor->trace(m_audioTracks);
visitor->trace(m_videoTracks);
visitor->trace(m_scheduledEvents);
visitor->trace(m_descriptor);
EventTargetWithInlineData::trace(visitor);
MediaStreamDescriptorClient::trace(visitor);
}
} // namespace blink
......@@ -45,12 +45,12 @@ class MediaStream final
, public ContextLifecycleObserver {
DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<MediaStream>);
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(MediaStream);
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaStream);
public:
static MediaStream* create(ExecutionContext*);
static MediaStream* create(ExecutionContext*, MediaStream*);
static MediaStream* create(ExecutionContext*, const MediaStreamTrackVector&);
static MediaStream* create(ExecutionContext*, MediaStreamDescriptor*);
static MediaStream* create(ExecutionContext*, PassRefPtr<MediaStreamDescriptor>);
virtual ~MediaStream();
// DEPRECATED
......@@ -91,7 +91,7 @@ public:
virtual void trace(Visitor*) override;
private:
MediaStream(ExecutionContext*, MediaStreamDescriptor*);
MediaStream(ExecutionContext*, PassRefPtr<MediaStreamDescriptor>);
MediaStream(ExecutionContext*, const MediaStreamTrackVector& audioTracks, const MediaStreamTrackVector& videoTracks);
// ContextLifecycleObserver
......@@ -108,7 +108,7 @@ private:
MediaStreamTrackVector m_audioTracks;
MediaStreamTrackVector m_videoTracks;
Member<MediaStreamDescriptor> m_descriptor;
RefPtr<MediaStreamDescriptor> m_descriptor;
Timer<MediaStream> m_scheduledEventTimer;
WillBeHeapVector<RefPtrWillBeMember<Event> > m_scheduledEvents;
......
......@@ -26,7 +26,6 @@
#define MediaStreamRegistry_h
#include "core/html/URLRegistry.h"
#include "platform/heap/Handle.h"
#include "wtf/HashMap.h"
#include "wtf/PassRefPtr.h"
#include "wtf/text/StringHash.h"
......@@ -51,7 +50,7 @@ public:
private:
MediaStreamRegistry();
PersistentHeapHashMap<String, Member<MediaStreamDescriptor> > m_streamDescriptors;
HashMap<String, RefPtr<MediaStreamDescriptor> > m_streamDescriptors;
};
} // namespace blink
......
......@@ -60,6 +60,7 @@ MediaStreamTrack::MediaStreamTrack(ExecutionContext* context, MediaStreamCompone
MediaStreamTrack::~MediaStreamTrack()
{
m_component->source()->removeObserver(this);
}
String MediaStreamTrack::kind() const
......@@ -152,9 +153,9 @@ void MediaStreamTrack::stopTrack(ExceptionState& exceptionState)
MediaStreamTrack* MediaStreamTrack::clone(ExecutionContext* context)
{
MediaStreamComponent* clonedComponent = MediaStreamComponent::create(component()->source());
MediaStreamTrack* clonedTrack = MediaStreamTrack::create(context, clonedComponent);
MediaStreamCenter::instance().didCreateMediaStreamTrack(clonedComponent);
RefPtr<MediaStreamComponent> clonedComponent = MediaStreamComponent::create(component()->source());
MediaStreamTrack* clonedTrack = MediaStreamTrack::create(context, clonedComponent.get());
MediaStreamCenter::instance().didCreateMediaStreamTrack(clonedComponent.get());
return clonedTrack;
}
......@@ -237,9 +238,7 @@ ExecutionContext* MediaStreamTrack::executionContext() const
void MediaStreamTrack::trace(Visitor* visitor)
{
visitor->trace(m_registeredMediaStreams);
visitor->trace(m_component);
EventTargetWithInlineData::trace(visitor);
MediaStreamSource::Observer::trace(visitor);
}
} // namespace blink
......@@ -47,7 +47,7 @@ class MediaStreamTrack final
, public MediaStreamSource::Observer {
DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<MediaStreamTrack>);
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(MediaStreamTrack);
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaStreamTrack);
public:
static MediaStreamTrack* create(ExecutionContext*, MediaStreamComponent*);
virtual ~MediaStreamTrack();
......@@ -100,7 +100,7 @@ private:
HeapHashSet<Member<MediaStream> > m_registeredMediaStreams;
bool m_isIteratingRegisteredMediaStreams;
bool m_stopped;
Member<MediaStreamComponent> m_component;
RefPtr<MediaStreamComponent> m_component;
};
typedef HeapVector<Member<MediaStreamTrack> > MediaStreamTrackVector;
......
......@@ -88,7 +88,6 @@ void RTCStatsRequestImpl::clear()
void RTCStatsRequestImpl::trace(Visitor* visitor)
{
visitor->trace(m_successCallback);
visitor->trace(m_component);
visitor->trace(m_requester);
RTCStatsRequest::trace(visitor);
}
......
......@@ -60,7 +60,7 @@ private:
void clear();
Member<RTCStatsCallback> m_successCallback;
Member<MediaStreamComponent> m_component;
RefPtr<MediaStreamComponent> m_component;
Member<RTCPeerConnection> m_requester;
};
......
......@@ -132,7 +132,7 @@ void UserMediaRequest::start()
m_controller->requestUserMedia(this);
}
void UserMediaRequest::succeed(MediaStreamDescriptor* streamDescriptor)
void UserMediaRequest::succeed(PassRefPtr<MediaStreamDescriptor> streamDescriptor)
{
if (!executionContext())
return;
......
......@@ -58,7 +58,7 @@ public:
void start();
void succeed(MediaStreamDescriptor*);
void succeed(PassRefPtr<MediaStreamDescriptor>);
void failPermissionDenied(const String& message);
void failConstraint(const String& constraintName, const String& message);
void failUASpecific(const String& name, const String& message, const String& constraintName);
......
......@@ -71,7 +71,6 @@ void MediaStreamAudioDestinationNode::dispose()
void MediaStreamAudioDestinationNode::trace(Visitor* visitor)
{
visitor->trace(m_source);
visitor->trace(m_stream);
AudioBasicInspectorNode::trace(visitor);
}
......
......@@ -60,7 +60,7 @@ private:
virtual bool propagatesSilence() const override { return false; }
Member<MediaStream> m_stream;
Member<MediaStreamSource> m_source;
RefPtr<MediaStreamSource> m_source;
RefPtr<AudioBus> m_mixBus;
};
......
......@@ -53,6 +53,11 @@ private:
} // namespace
WebMediaStream::WebMediaStream(const PassRefPtr<MediaStreamDescriptor>& mediaStreamDescriptor)
: m_private(mediaStreamDescriptor)
{
}
WebMediaStream::WebMediaStream(MediaStreamDescriptor* mediaStreamDescriptor)
: m_private(mediaStreamDescriptor)
{
......@@ -111,12 +116,17 @@ void WebMediaStream::removeTrack(const WebMediaStreamTrack& track)
m_private->removeRemoteTrack(track);
}
WebMediaStream& WebMediaStream::operator=(MediaStreamDescriptor* mediaStreamDescriptor)
WebMediaStream& WebMediaStream::operator=(const PassRefPtr<MediaStreamDescriptor>& mediaStreamDescriptor)
{
m_private = mediaStreamDescriptor;
return *this;
}
WebMediaStream::operator PassRefPtr<MediaStreamDescriptor>() const
{
return m_private.get();
}
WebMediaStream::operator MediaStreamDescriptor*() const
{
return m_private.get();
......
......@@ -69,7 +69,7 @@ void WebMediaStreamSource::ExtraData::setOwner(MediaStreamSource* owner)
m_owner = owner;
}
WebMediaStreamSource::WebMediaStreamSource(MediaStreamSource* mediaStreamSource)
WebMediaStreamSource::WebMediaStreamSource(const PassRefPtr<MediaStreamSource>& mediaStreamSource)
: m_private(mediaStreamSource)
{
}
......@@ -90,6 +90,11 @@ void WebMediaStreamSource::reset()
m_private.reset();
}
WebMediaStreamSource::operator PassRefPtr<MediaStreamSource>() const
{
return m_private.get();
}
WebMediaStreamSource::operator MediaStreamSource*() const
{
return m_private.get();
......
......@@ -49,6 +49,23 @@ private:
} // namespace
WebMediaStreamTrack WebMediaStreamTrack::ExtraData::owner()
{
ASSERT(m_owner);
return WebMediaStreamTrack(m_owner);
}
void WebMediaStreamTrack::ExtraData::setOwner(MediaStreamComponent* owner)
{
ASSERT(!m_owner);
m_owner = owner;
}
WebMediaStreamTrack::WebMediaStreamTrack(PassRefPtr<MediaStreamComponent> mediaStreamComponent)
: m_private(mediaStreamComponent)
{
}
WebMediaStreamTrack::WebMediaStreamTrack(MediaStreamComponent* mediaStreamComponent)
: m_private(mediaStreamComponent)
{
......@@ -75,6 +92,11 @@ void WebMediaStreamTrack::reset()
m_private.reset();
}
WebMediaStreamTrack::operator PassRefPtr<MediaStreamComponent>() const
{
return m_private.get();
}
WebMediaStreamTrack::operator MediaStreamComponent*() const
{
return m_private.get();
......@@ -115,6 +137,10 @@ WebMediaStreamTrack::ExtraData* WebMediaStreamTrack::extraData() const
void WebMediaStreamTrack::setExtraData(ExtraData* extraData)
{
ASSERT(!m_private.isNull());
if (extraData)
extraData->setOwner(m_private.get());
m_private->setExtraData(adoptPtr(new ExtraDataContainer(adoptPtr(extraData))));
}
......
......@@ -40,56 +40,23 @@
namespace blink {
MediaStreamComponent* MediaStreamComponent::create(MediaStreamSource* source)
PassRefPtr<MediaStreamComponent> MediaStreamComponent::create(PassRefPtr<MediaStreamSource> source)
{
return new MediaStreamComponent(createCanonicalUUIDString(), source);
return adoptRef(new MediaStreamComponent(createCanonicalUUIDString(), source));
}
MediaStreamComponent* MediaStreamComponent::create(const String& id, MediaStreamSource* source)
PassRefPtr<MediaStreamComponent> MediaStreamComponent::create(const String& id, PassRefPtr<MediaStreamSource> source)
{
return new MediaStreamComponent(id, source);
return adoptRef(new MediaStreamComponent(id, source));
}
// The disposer pattern actually makes the deletion of the extra data happen
// earlier and not later. The disposer makes sure that the extra data is
// destructed in weak processing which is run before sweeping and therefore
// all the objects are still alive and can be touched.
//
// FIXME: Oilpan: This disposer pattern is duplicated in a lot of places.
// We should create a good abstraction class for this and remove the code duplication.
class MediaStreamComponentDisposer {
public:
explicit MediaStreamComponentDisposer(MediaStreamComponent& component) : m_component(component) { }
~MediaStreamComponentDisposer()
{
m_component.dispose();
}
private:
MediaStreamComponent& m_component;
};
typedef HeapHashMap<WeakMember<MediaStreamComponent>, OwnPtr<MediaStreamComponentDisposer> > ComponentDisposers;
static ComponentDisposers& componentDisposers()
{
DEFINE_STATIC_LOCAL(Persistent<ComponentDisposers>, disposers, (new ComponentDisposers));
return *disposers;
}
MediaStreamComponent::MediaStreamComponent(const String& id, MediaStreamSource* source)
MediaStreamComponent::MediaStreamComponent(const String& id, PassRefPtr<MediaStreamSource> source)
: m_source(source)
, m_id(id)
, m_enabled(true)
, m_muted(false)
{
ASSERT(m_id.length());
componentDisposers().add(this, adoptPtr(new MediaStreamComponentDisposer(*this)));
}
void MediaStreamComponent::dispose()
{
m_extraData = nullptr;
}
#if ENABLE(WEB_AUDIO)
......@@ -121,10 +88,5 @@ void MediaStreamComponent::AudioSourceProviderImpl::provideInput(AudioBus* bus,
}
#endif // #if ENABLE(WEB_AUDIO)
void MediaStreamComponent::trace(Visitor* visitor)
{
visitor->trace(m_source);
}
} // namespace blink
......@@ -33,9 +33,9 @@
#define MediaStreamComponent_h
#include "platform/audio/AudioSourceProvider.h"
#include "platform/heap/Handle.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/ThreadingPrimitives.h"
#include "wtf/text/WTFString.h"
......@@ -44,15 +44,15 @@ namespace blink {
class MediaStreamSource;
class WebAudioSourceProvider;
class PLATFORM_EXPORT MediaStreamComponent final : public GarbageCollectedFinalized<MediaStreamComponent> {
class PLATFORM_EXPORT MediaStreamComponent final : public RefCounted<MediaStreamComponent> {
public:
class ExtraData {
public:
virtual ~ExtraData() { }
};
static MediaStreamComponent* create(MediaStreamSource*);
static MediaStreamComponent* create(const String& id, MediaStreamSource*);
static PassRefPtr<MediaStreamComponent> create(PassRefPtr<MediaStreamSource>);
static PassRefPtr<MediaStreamComponent> create(const String& id, PassRefPtr<MediaStreamSource>);
MediaStreamSource* source() const { return m_source.get(); }
......@@ -70,11 +70,8 @@ public:
ExtraData* extraData() const { return m_extraData.get(); }
void setExtraData(PassOwnPtr<ExtraData> extraData) { m_extraData = extraData; }
void trace(Visitor*);
void dispose();
private:
MediaStreamComponent(const String& id, MediaStreamSource*);
MediaStreamComponent(const String& id, PassRefPtr<MediaStreamSource>);
#if ENABLE(WEB_AUDIO)
// AudioSourceProviderImpl wraps a WebAudioSourceProvider::provideInput()
......@@ -103,14 +100,14 @@ private:
AudioSourceProviderImpl m_sourceProvider;
#endif // ENABLE(WEB_AUDIO)
Member<MediaStreamSource> m_source;
RefPtr<MediaStreamSource> m_source;
String m_id;
bool m_enabled;
bool m_muted;
OwnPtr<ExtraData> m_extraData;
};
typedef HeapVector<Member<MediaStreamComponent> > MediaStreamComponentVector;
typedef Vector<RefPtr<MediaStreamComponent> > MediaStreamComponentVector;
} // namespace blink
......
......@@ -37,22 +37,22 @@
namespace blink {
MediaStreamDescriptor* MediaStreamDescriptor::create(const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources)
PassRefPtr<MediaStreamDescriptor> MediaStreamDescriptor::create(const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources)
{
return new MediaStreamDescriptor(createCanonicalUUIDString(), audioSources, videoSources);
return adoptRef(new MediaStreamDescriptor(createCanonicalUUIDString(), audioSources, videoSources));
}
MediaStreamDescriptor* MediaStreamDescriptor::create(const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents)
PassRefPtr<MediaStreamDescriptor> MediaStreamDescriptor::create(const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents)
{
return new MediaStreamDescriptor(createCanonicalUUIDString(), audioComponents, videoComponents);
return adoptRef(new MediaStreamDescriptor(createCanonicalUUIDString(), audioComponents, videoComponents));
}
MediaStreamDescriptor* MediaStreamDescriptor::create(const String& id, const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents)
PassRefPtr<MediaStreamDescriptor> MediaStreamDescriptor::create(const String& id, const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents)
{
return new MediaStreamDescriptor(id, audioComponents, videoComponents);
return adoptRef(new MediaStreamDescriptor(id, audioComponents, videoComponents));
}
void MediaStreamDescriptor::addComponent(MediaStreamComponent* component)
void MediaStreamDescriptor::addComponent(PassRefPtr<MediaStreamComponent> component)
{
switch (component->source()->type()) {
case MediaStreamSource::TypeAudio:
......@@ -66,7 +66,7 @@ void MediaStreamDescriptor::addComponent(MediaStreamComponent* component)
}
}
void MediaStreamDescriptor::removeComponent(MediaStreamComponent* component)
void MediaStreamDescriptor::removeComponent(PassRefPtr<MediaStreamComponent> component)
{
size_t pos = kNotFound;
switch (component->source()->type()) {
......@@ -100,7 +100,7 @@ void MediaStreamDescriptor::removeRemoteTrack(MediaStreamComponent* component)
}
MediaStreamDescriptor::MediaStreamDescriptor(const String& id, const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources)
: m_client(nullptr)
: m_client(0)
, m_id(id)
, m_ended(false)
{
......@@ -112,35 +112,8 @@ MediaStreamDescriptor::MediaStreamDescriptor(const String& id, const MediaStream
m_videoComponents.append(MediaStreamComponent::create(videoSources[i]));
}
// The disposer pattern actually makes the deletion of the extra data happen
// earlier and not later. The disposer makes sure that the extra data is
// destructed in weak processing which is run before sweeping and therefore
// all the objects are still alive and can be touched.
//
// FIXME: Oilpan: This disposer pattern is duplicated in a lot of places.
// We should create a good abstraction class for this and remove the code duplication.
class MediaStreamDescriptorDisposer {
public:
explicit MediaStreamDescriptorDisposer(MediaStreamDescriptor& descriptor) : m_descriptor(descriptor) { }
~MediaStreamDescriptorDisposer()
{
m_descriptor.dispose();
}
private:
MediaStreamDescriptor& m_descriptor;
};
typedef HeapHashMap<WeakMember<MediaStreamDescriptor>, OwnPtr<MediaStreamDescriptorDisposer> > DescriptorDisposers;
static DescriptorDisposers& descriptorDisposers()
{
DEFINE_STATIC_LOCAL(Persistent<DescriptorDisposers>, disposers, (new DescriptorDisposers));
return *disposers;
}
MediaStreamDescriptor::MediaStreamDescriptor(const String& id, const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents)
: m_client(nullptr)
: m_client(0)
, m_id(id)
, m_ended(false)
{
......@@ -149,19 +122,6 @@ MediaStreamDescriptor::MediaStreamDescriptor(const String& id, const MediaStream
m_audioComponents.append((*iter));
for (MediaStreamComponentVector::const_iterator iter = videoComponents.begin(); iter != videoComponents.end(); ++iter)
m_videoComponents.append((*iter));
descriptorDisposers().add(this, adoptPtr(new MediaStreamDescriptorDisposer(*this)));
}
void MediaStreamDescriptor::dispose()
{
m_extraData = nullptr;
}
void MediaStreamDescriptor::trace(Visitor* visitor)
{
visitor->trace(m_audioComponents);
visitor->trace(m_videoComponents);
visitor->trace(m_client);
}
} // namespace blink
......
......@@ -32,25 +32,24 @@
#ifndef MediaStreamDescriptor_h
#define MediaStreamDescriptor_h
#include "platform/heap/Handle.h"
#include "platform/mediastream/MediaStreamComponent.h"
#include "platform/mediastream/MediaStreamSource.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/Vector.h"
namespace blink {
class MediaStreamDescriptorClient : public GarbageCollectedMixin {
class MediaStreamDescriptorClient {
public:
virtual ~MediaStreamDescriptorClient() { }
virtual void streamEnded() = 0;
virtual void addRemoteTrack(MediaStreamComponent*) = 0;
virtual void removeRemoteTrack(MediaStreamComponent*) = 0;
virtual void trace(Visitor*) { }
};
class PLATFORM_EXPORT MediaStreamDescriptor final : public GarbageCollectedFinalized<MediaStreamDescriptor> {
class PLATFORM_EXPORT MediaStreamDescriptor final : public RefCounted<MediaStreamDescriptor> {
public:
class ExtraData {
public:
......@@ -58,11 +57,11 @@ public:
};
// Only used for AudioDestinationNode.
static MediaStreamDescriptor* create(const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources);
static PassRefPtr<MediaStreamDescriptor> create(const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources);
static MediaStreamDescriptor* create(const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents);
static PassRefPtr<MediaStreamDescriptor> create(const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents);
static MediaStreamDescriptor* create(const String& id, const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents);
static PassRefPtr<MediaStreamDescriptor> create(const String& id, const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents);
MediaStreamDescriptorClient* client() const { return m_client; }
void setClient(MediaStreamDescriptorClient* client) { m_client = client; }
......@@ -75,8 +74,8 @@ public:
unsigned numberOfVideoComponents() const { return m_videoComponents.size(); }
MediaStreamComponent* videoComponent(unsigned index) const { return m_videoComponents[index].get(); }
void addComponent(MediaStreamComponent*);
void removeComponent(MediaStreamComponent*);
void addComponent(PassRefPtr<MediaStreamComponent>);
void removeComponent(PassRefPtr<MediaStreamComponent>);
void addRemoteTrack(MediaStreamComponent*);
void removeRemoteTrack(MediaStreamComponent*);
......@@ -87,22 +86,21 @@ public:
ExtraData* extraData() const { return m_extraData.get(); }
void setExtraData(PassOwnPtr<ExtraData> extraData) { m_extraData = extraData; }
void trace(Visitor*);
void dispose();
private:
MediaStreamDescriptor(const String& id, const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources);
MediaStreamDescriptor(const String& id, const MediaStreamComponentVector& audioComponents, const MediaStreamComponentVector& videoComponents);
Member<MediaStreamDescriptorClient> m_client;
MediaStreamDescriptorClient* m_client;
String m_id;
MediaStreamComponentVector m_audioComponents;
MediaStreamComponentVector m_videoComponents;
Vector<RefPtr<MediaStreamComponent> > m_audioComponents;
Vector<RefPtr<MediaStreamComponent> > m_videoComponents;
bool m_ended;
OwnPtr<ExtraData> m_extraData;
};
typedef Vector<RefPtr<MediaStreamDescriptor> > MediaStreamDescriptorVector;
} // namespace blink
#endif // MediaStreamDescriptor_h
......@@ -34,36 +34,9 @@
namespace blink {
// The disposer pattern actually makes the deletion of the extra data happen
// earlier and not later. The disposer makes sure that the extra data is
// destructed in weak processing which is run before sweeping and therefore
// all the objects are still alive and can be touched.
//
// FIXME: Oilpan: This disposer pattern is duplicated in a lot of places.
// We should create a good abstraction class for this and remove the code duplication.
class MediaStreamSourceDisposer {
public:
explicit MediaStreamSourceDisposer(MediaStreamSource& source) : m_source(source) { }
~MediaStreamSourceDisposer()
{
m_source.dispose();
}
private:
MediaStreamSource& m_source;
};
typedef HeapHashMap<WeakMember<MediaStreamSource>, OwnPtr<MediaStreamSourceDisposer> > SourceDisposers;
static SourceDisposers& sourceDisposers()
PassRefPtr<MediaStreamSource> MediaStreamSource::create(const String& id, Type type, const String& name, ReadyState readyState, bool requiresConsumer)
{
DEFINE_STATIC_LOCAL(Persistent<SourceDisposers>, disposers, (new SourceDisposers));
return *disposers;
}
MediaStreamSource* MediaStreamSource::create(const String& id, Type type, const String& name, ReadyState readyState, bool requiresConsumer)
{
return new MediaStreamSource(id, type, name, readyState, requiresConsumer);
return adoptRef(new MediaStreamSource(id, type, name, readyState, requiresConsumer));
}
MediaStreamSource::MediaStreamSource(const String& id, Type type, const String& name, ReadyState readyState, bool requiresConsumer)
......@@ -73,27 +46,27 @@ MediaStreamSource::MediaStreamSource(const String& id, Type type, const String&
, m_readyState(readyState)
, m_requiresConsumer(requiresConsumer)
{
sourceDisposers().add(this, adoptPtr(new MediaStreamSourceDisposer(*this)));
}
void MediaStreamSource::dispose()
{
m_extraData = nullptr;
}
void MediaStreamSource::setReadyState(ReadyState readyState)
{
if (m_readyState != ReadyStateEnded && m_readyState != readyState) {
m_readyState = readyState;
for (HeapHashSet<WeakMember<Observer> >::iterator i = m_observers.begin(); i != m_observers.end(); ++i)
for (Vector<Observer*>::iterator i = m_observers.begin(); i != m_observers.end(); ++i)
(*i)->sourceChangedState();
}
}
void MediaStreamSource::addObserver(MediaStreamSource::Observer* observer)
{
ASSERT(!m_observers.contains(observer));
m_observers.add(observer);
m_observers.append(observer);
}
void MediaStreamSource::removeObserver(MediaStreamSource::Observer* observer)
{
size_t pos = m_observers.find(observer);
if (pos != kNotFound)
m_observers.remove(pos);
}
void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer)
......@@ -130,11 +103,4 @@ void MediaStreamSource::consumeAudio(AudioBus* bus, size_t numberOfFrames)
(*it)->consumeAudio(bus, numberOfFrames);
}
void MediaStreamSource::trace(Visitor* visitor)
{
visitor->trace(m_observers);
visitor->trace(m_audioConsumers);
}
} // namespace blink
......@@ -34,23 +34,22 @@
#include "platform/PlatformExport.h"
#include "platform/audio/AudioDestinationConsumer.h"
#include "platform/heap/Handle.h"
#include "public/platform/WebMediaConstraints.h"
#include "wtf/OwnPtr.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/RefCounted.h"
#include "wtf/ThreadingPrimitives.h"
#include "wtf/Vector.h"
#include "wtf/text/WTFString.h"
namespace blink {
class PLATFORM_EXPORT MediaStreamSource final : public GarbageCollectedFinalized<MediaStreamSource> {
class PLATFORM_EXPORT MediaStreamSource final : public RefCounted<MediaStreamSource> {
public:
class Observer : public GarbageCollectedMixin {
class Observer {
public:
virtual ~Observer() { }
virtual void sourceChangedState() = 0;
virtual void trace(Visitor*) { }
};
class ExtraData {
......@@ -69,7 +68,7 @@ public:
ReadyStateEnded = 2
};
static MediaStreamSource* create(const String& id, Type, const String& name, ReadyState = ReadyStateLive, bool requiresConsumer = false);
static PassRefPtr<MediaStreamSource> create(const String& id, Type, const String& name, ReadyState = ReadyStateLive, bool requiresConsumer = false);
const String& id() const { return m_id; }
Type type() const { return m_type; }
......@@ -95,9 +94,6 @@ public:
bool removeAudioConsumer(AudioDestinationConsumer*);
const HeapHashSet<Member<AudioDestinationConsumer> >& audioConsumers() { return m_audioConsumers; }
void trace(Visitor*);
void dispose();
private:
MediaStreamSource(const String& id, Type, const String& name, ReadyState, bool requiresConsumer);
......@@ -106,14 +102,14 @@ private:
String m_name;
ReadyState m_readyState;
bool m_requiresConsumer;
HeapHashSet<WeakMember<Observer> > m_observers;
Vector<Observer*> m_observers;
Mutex m_audioConsumersLock;
HeapHashSet<Member<AudioDestinationConsumer> > m_audioConsumers;
PersistentHeapHashSet<Member<AudioDestinationConsumer> > m_audioConsumers;
OwnPtr<ExtraData> m_extraData;
blink::WebMediaConstraints m_constraints;
};
typedef HeapVector<Member<MediaStreamSource> > MediaStreamSourceVector;
typedef Vector<RefPtr<MediaStreamSource> > MediaStreamSourceVector;
} // namespace blink
......
......@@ -79,8 +79,10 @@ public:
#if INSIDE_BLINK
BLINK_PLATFORM_EXPORT WebMediaStream(MediaStreamDescriptor*);
BLINK_PLATFORM_EXPORT WebMediaStream(const WTF::PassRefPtr<MediaStreamDescriptor>&);
BLINK_PLATFORM_EXPORT operator WTF::PassRefPtr<MediaStreamDescriptor>() const;
BLINK_PLATFORM_EXPORT operator MediaStreamDescriptor*() const;
BLINK_PLATFORM_EXPORT WebMediaStream& operator=(MediaStreamDescriptor*);
BLINK_PLATFORM_EXPORT WebMediaStream& operator=(const WTF::PassRefPtr<MediaStreamDescriptor>&);
#endif
private:
......
......@@ -35,9 +35,6 @@
#include "WebNonCopyable.h"
#include "WebPrivatePtr.h"
#include "WebVector.h"
#if INSIDE_BLINK
#include "platform/heap/Handle.h"
#endif
namespace blink {
......@@ -60,9 +57,6 @@ public:
#endif
private:
#if INSIDE_BLINK
GC_PLUGIN_IGNORE("http://crbug.com/409526")
#endif
MediaStreamSource* m_owner;
};
......@@ -117,8 +111,9 @@ public:
BLINK_PLATFORM_EXPORT bool removeAudioConsumer(WebAudioDestinationConsumer*);
#if INSIDE_BLINK
BLINK_PLATFORM_EXPORT WebMediaStreamSource(MediaStreamSource*);
BLINK_PLATFORM_EXPORT WebMediaStreamSource(const WTF::PassRefPtr<MediaStreamSource>&);
BLINK_PLATFORM_EXPORT WebMediaStreamSource& operator=(MediaStreamSource*);
BLINK_PLATFORM_EXPORT operator WTF::PassRefPtr<MediaStreamSource>() const;
BLINK_PLATFORM_EXPORT operator MediaStreamSource*() const;
#endif
......
......@@ -41,8 +41,17 @@ class WebMediaStreamTrack {
public:
class ExtraData {
public:
ExtraData() { }
ExtraData() : m_owner(0) { }
virtual ~ExtraData() { }
BLINK_PLATFORM_EXPORT WebMediaStreamTrack owner();
#if INSIDE_BLINK
BLINK_PLATFORM_EXPORT void setOwner(MediaStreamComponent*);
#endif
private:
MediaStreamComponent* m_owner;
};
WebMediaStreamTrack() { }
......@@ -81,8 +90,10 @@ public:
BLINK_PLATFORM_EXPORT void setSourceProvider(WebAudioSourceProvider*);
#if INSIDE_BLINK
BLINK_PLATFORM_EXPORT WebMediaStreamTrack(PassRefPtr<MediaStreamComponent>);
BLINK_PLATFORM_EXPORT WebMediaStreamTrack(MediaStreamComponent*);
BLINK_PLATFORM_EXPORT WebMediaStreamTrack& operator=(MediaStreamComponent*);
BLINK_PLATFORM_EXPORT operator WTF::PassRefPtr<MediaStreamComponent>() const;
BLINK_PLATFORM_EXPORT operator MediaStreamComponent*() const;
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment