Update MediaStream to use WebCore platform interfaces

https://bugs.webkit.org/show_bug.cgi?id=68464

Patch by Adam Bergkvist <adam.bergkvist@ericsson.com> on 2011-10-19
Reviewed by Adam Barth.

Source/WebCore:

This is one in a series of patches that update the MediaStream feature
to use WebCore platform interfaces.

Tests will be provided by http://webkit.org/b/56587

* dom/LocalMediaStream.cpp:
(WebCore::LocalMediaStream::create):
(WebCore::LocalMediaStream::LocalMediaStream):
(WebCore::LocalMediaStream::stop):
(WebCore::LocalMediaStream::stopTimerFired):
(WebCore::LocalMediaStream::~LocalMediaStream):
(WebCore::LocalMediaStream::toLocalMediaStream):
* dom/LocalMediaStream.h:
* dom/LocalMediaStream.idl:
* dom/MediaStream.cpp:
(WebCore::MediaStream::create):
(WebCore::MediaStream::MediaStream):
(WebCore::MediaStream::~MediaStream):
(WebCore::MediaStream::readyState):
(WebCore::MediaStream::streamEnded):
(WebCore::MediaStream::scriptExecutionContext):
* dom/MediaStream.h:
(WebCore::MediaStream::label):
(WebCore::MediaStream::tracks):
(WebCore::MediaStream::descriptor):
* dom/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::create):
(WebCore::MediaStreamTrack::MediaStreamTrack):
(WebCore::MediaStreamTrack::kind):
(WebCore::MediaStreamTrack::label):
(WebCore::MediaStreamTrack::enabled):
(WebCore::MediaStreamTrack::setEnabled):
* dom/MediaStreamTrack.h:
* dom/MediaStreamTrack.idl:
* dom/MediaStreamTrackList.cpp:
(WebCore::MediaStreamTrackList::create):
(WebCore::MediaStreamTrackList::MediaStreamTrackList):
(WebCore::MediaStreamTrackList::length):
(WebCore::MediaStreamTrackList::item):
* dom/MediaStreamTrackList.h:
* p2p/PeerConnection.cpp:
(WebCore::PeerConnection::addStream):
(WebCore::PeerConnection::removeStream):
(WebCore::PeerConnection::remoteStreamAdded):
* page/MediaStreamClient.h:
* page/MediaStreamController.cpp:
(WebCore::MediaStreamController::unregisterFrameController):
(WebCore::MediaStreamController::streamGenerated):
* page/MediaStreamController.h:
* page/MediaStreamFrameController.cpp:
(WebCore::MediaStreamFrameController::enterDetachedState):
(WebCore::MediaStreamFrameController::disconnectFrame):
(WebCore::MediaStreamFrameController::streamGenerated):
* page/MediaStreamFrameController.h:

Source/WebKit/chromium:

Removed WebMediaStreamTrack* since they will no longer be needed.

* WebKit.gyp:
* public/WebMediaStreamTrack.h: Removed.
* public/WebMediaStreamTrackList.h: Removed.
* src/WebMediaStreamTrack.cpp: Removed.
* src/WebMediaStreamTrackList.cpp: Removed.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@97904 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e53d247c
2011-10-19 Adam Bergkvist <adam.bergkvist@ericsson.com>
Update MediaStream to use WebCore platform interfaces
https://bugs.webkit.org/show_bug.cgi?id=68464
Reviewed by Adam Barth.
This is one in a series of patches that update the MediaStream feature
to use WebCore platform interfaces.
Tests will be provided by http://webkit.org/b/56587
* dom/LocalMediaStream.cpp:
(WebCore::LocalMediaStream::create):
(WebCore::LocalMediaStream::LocalMediaStream):
(WebCore::LocalMediaStream::stop):
(WebCore::LocalMediaStream::stopTimerFired):
(WebCore::LocalMediaStream::~LocalMediaStream):
(WebCore::LocalMediaStream::toLocalMediaStream):
* dom/LocalMediaStream.h:
* dom/LocalMediaStream.idl:
* dom/MediaStream.cpp:
(WebCore::MediaStream::create):
(WebCore::MediaStream::MediaStream):
(WebCore::MediaStream::~MediaStream):
(WebCore::MediaStream::readyState):
(WebCore::MediaStream::streamEnded):
(WebCore::MediaStream::scriptExecutionContext):
* dom/MediaStream.h:
(WebCore::MediaStream::label):
(WebCore::MediaStream::tracks):
(WebCore::MediaStream::descriptor):
* dom/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::create):
(WebCore::MediaStreamTrack::MediaStreamTrack):
(WebCore::MediaStreamTrack::kind):
(WebCore::MediaStreamTrack::label):
(WebCore::MediaStreamTrack::enabled):
(WebCore::MediaStreamTrack::setEnabled):
* dom/MediaStreamTrack.h:
* dom/MediaStreamTrack.idl:
* dom/MediaStreamTrackList.cpp:
(WebCore::MediaStreamTrackList::create):
(WebCore::MediaStreamTrackList::MediaStreamTrackList):
(WebCore::MediaStreamTrackList::length):
(WebCore::MediaStreamTrackList::item):
* dom/MediaStreamTrackList.h:
* p2p/PeerConnection.cpp:
(WebCore::PeerConnection::addStream):
(WebCore::PeerConnection::removeStream):
(WebCore::PeerConnection::remoteStreamAdded):
* page/MediaStreamClient.h:
* page/MediaStreamController.cpp:
(WebCore::MediaStreamController::unregisterFrameController):
(WebCore::MediaStreamController::streamGenerated):
* page/MediaStreamController.h:
* page/MediaStreamFrameController.cpp:
(WebCore::MediaStreamFrameController::enterDetachedState):
(WebCore::MediaStreamFrameController::disconnectFrame):
(WebCore::MediaStreamFrameController::streamGenerated):
* page/MediaStreamFrameController.h:
2011-10-19 W. James MacLean <wjmaclean@chromium.org>
[chromium] Shorten animation time for ZoomAnimator.
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -27,88 +28,46 @@
#if ENABLE(MEDIA_STREAM)
#include "Event.h"
#include "EventNames.h"
#include "MediaStreamFrameController.h"
#include "ScriptExecutionContext.h"
#include "UUID.h"
namespace WebCore {
class LocalMediaStream::DispatchUpdateTask : public ScriptExecutionContext::Task {
public:
typedef void (LocalMediaStream::*Callback)();
static PassOwnPtr<DispatchUpdateTask> create(PassRefPtr<LocalMediaStream> object, Callback callback)
{
return adoptPtr(new DispatchUpdateTask(object, callback));
}
virtual void performTask(ScriptExecutionContext*)
{
(m_object.get()->*m_callback)();
}
public:
DispatchUpdateTask(PassRefPtr<LocalMediaStream> object, Callback callback)
: m_object(object)
, m_callback(callback) { }
RefPtr<LocalMediaStream> m_object;
Callback m_callback;
};
PassRefPtr<LocalMediaStream> LocalMediaStream::create(MediaStreamFrameController* frameController, const String& label, PassRefPtr<MediaStreamTrackList> tracks)
PassRefPtr<LocalMediaStream> LocalMediaStream::create(ScriptExecutionContext* context, const MediaStreamSourceVector& sources)
{
return adoptRef(new LocalMediaStream(frameController, label, tracks));
return adoptRef(new LocalMediaStream(context, sources));
}
LocalMediaStream::LocalMediaStream(MediaStreamFrameController* frameController, const String& label, PassRefPtr<MediaStreamTrackList> tracks)
: MediaStream(frameController, label, tracks, true)
LocalMediaStream::LocalMediaStream(ScriptExecutionContext* context, const MediaStreamSourceVector& sources)
: MediaStream(context, MediaStreamDescriptor::create(createCanonicalUUIDString(), sources))
, m_stopTimer(this, &LocalMediaStream::stopTimerFired)
{
}
LocalMediaStream::~LocalMediaStream()
void LocalMediaStream::stop()
{
if (!m_stopTimer.isActive())
m_stopTimer.startOneShot(0);
}
LocalMediaStream* LocalMediaStream::toLocalMediaStream()
void LocalMediaStream::stopTimerFired(Timer<LocalMediaStream>* timer)
{
return this;
}
ASSERT_UNUSED(timer, timer == &m_stopTimer);
void LocalMediaStream::detachEmbedder()
{
// Assuming we should stop any live streams when losing access to the embedder.
stop();
if (readyState() == ENDED)
return;
MediaStream::detachEmbedder();
}
// FIXME: tell the platform that the stream was stopped
void LocalMediaStream::streamEnded()
{
MediaStream::streamEnded();
streamEnded();
}
void LocalMediaStream::stop()
LocalMediaStream::~LocalMediaStream()
{
if (!mediaStreamFrameController() || m_readyState == ENDED)
return;
mediaStreamFrameController()->stopGeneratedStream(label());
m_readyState = ENDED;
// Don't assert since it can be null in degenerate cases like frames detached from their pages.
if (!scriptExecutionContext())
return;
ASSERT(scriptExecutionContext()->isContextThread());
scriptExecutionContext()->postTask(DispatchUpdateTask::create(this, &LocalMediaStream::onStop));
}
void LocalMediaStream::onStop()
LocalMediaStream* LocalMediaStream::toLocalMediaStream()
{
dispatchEvent(Event::create(eventNames().endedEvent, false, false));
return this;
}
} // namespace WebCore
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -28,33 +29,26 @@
#if ENABLE(MEDIA_STREAM)
#include "MediaStream.h"
#include <wtf/Forward.h>
#include "Timer.h"
namespace WebCore {
class LocalMediaStream : public MediaStream {
public:
static PassRefPtr<LocalMediaStream> create(MediaStreamFrameController*, const String& label, PassRefPtr<MediaStreamTrackList> tracks);
static PassRefPtr<LocalMediaStream> create(ScriptExecutionContext*, const MediaStreamSourceVector&);
virtual ~LocalMediaStream();
void stop();
// MediaStreamFrameController::StreamClient implementation.
virtual void detachEmbedder();
virtual void streamEnded();
// EventTarget.
virtual LocalMediaStream* toLocalMediaStream();
protected:
virtual bool isLocalMediaStream() const { return true; }
private:
LocalMediaStream(MediaStreamFrameController*, const String& label, PassRefPtr<MediaStreamTrackList> tracks);
class DispatchUpdateTask;
friend class DispatchUpdateTask;
LocalMediaStream(ScriptExecutionContext*, const MediaStreamSourceVector&);
void stopTimerFired(Timer<LocalMediaStream>*);
void onStop();
Timer<LocalMediaStream> m_stopTimer;
};
} // namespace WebCore
......
......@@ -27,7 +27,8 @@ module core {
interface [
Conditional=MEDIA_STREAM,
GenerateNativeConverter,
EventTarget
EventTarget,
GenerateToJS
] LocalMediaStream : MediaStream {
void stop();
};
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -32,20 +33,35 @@
namespace WebCore {
PassRefPtr<MediaStream> MediaStream::create(MediaStreamFrameController* frameController, const String& label, PassRefPtr<MediaStreamTrackList> tracks, bool isLocalMediaStream)
PassRefPtr<MediaStream> MediaStream::create(ScriptExecutionContext* context, PassRefPtr<MediaStreamDescriptor> streamDescriptor)
{
return adoptRef(new MediaStream(frameController, label, tracks, isLocalMediaStream));
return adoptRef(new MediaStream(context, streamDescriptor));
}
MediaStream::MediaStream(MediaStreamFrameController* frameController, const String& label, PassRefPtr<MediaStreamTrackList> tracks, bool isLocalMediaStream)
: MediaStreamClient(frameController, label, isLocalMediaStream)
, m_readyState(LIVE)
, m_tracks(tracks)
MediaStream::MediaStream(ScriptExecutionContext* context, PassRefPtr<MediaStreamDescriptor> streamDescriptor)
: m_scriptExecutionContext(context)
, m_descriptor(streamDescriptor)
{
m_descriptor->setOwner(this);
MediaStreamTrackVector trackVector;
size_t numberOfTracks = m_descriptor->numberOfComponents();
trackVector.reserveCapacity(numberOfTracks);
for (size_t i = 0; i < numberOfTracks; i++)
trackVector.append(MediaStreamTrack::create(m_descriptor, i));
m_tracks = MediaStreamTrackList::create(trackVector);
}
MediaStream::~MediaStream()
{
m_descriptor->setOwner(0);
}
MediaStream::ReadyState MediaStream::readyState() const
{
return m_descriptor->ended() ? ENDED : LIVE;
}
MediaStream* MediaStream::toMediaStream()
......@@ -55,14 +71,17 @@ MediaStream* MediaStream::toMediaStream()
void MediaStream::streamEnded()
{
ASSERT(m_readyState != ENDED);
m_readyState = ENDED;
if (readyState() == ENDED)
return;
m_descriptor->setEnded();
dispatchEvent(Event::create(eventNames().endedEvent, false, false));
}
ScriptExecutionContext* MediaStream::scriptExecutionContext() const
{
return mediaStreamFrameController() ? mediaStreamFrameController()->scriptExecutionContext() : 0;
return m_scriptExecutionContext.get();
}
EventTargetData* MediaStream::eventTargetData()
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -27,39 +28,37 @@
#if ENABLE(MEDIA_STREAM)
#include "EventNames.h"
#include "EventTarget.h"
#include "MediaStreamFrameController.h"
#include "MediaStreamDescriptor.h"
#include "MediaStreamTrackList.h"
#include "ScriptExecutionContext.h"
#include <wtf/Forward.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class MediaStream : public RefCounted<MediaStream>,
public EventTarget,
public MediaStreamFrameController::MediaStreamClient {
class ScriptExecutionContext;
class MediaStream : public RefCounted<MediaStream>, public EventTarget {
public:
// Must match the constants in the .idl file.
enum {
enum ReadyState {
LIVE = 1,
ENDED = 2
};
static PassRefPtr<MediaStream> create(MediaStreamFrameController*, const String& label, PassRefPtr<MediaStreamTrackList> tracks, bool isLocalMediaStream = false);
static PassRefPtr<MediaStream> create(ScriptExecutionContext*, PassRefPtr<MediaStreamDescriptor>);
virtual ~MediaStream();
DEFINE_ATTRIBUTE_EVENT_LISTENER(ended);
unsigned short readyState() const { return m_readyState; }
const String& label() const { return clientId(); }
ReadyState readyState() const;
String label() const { return m_descriptor->label(); }
MediaStreamTrackList* tracks() { return m_tracks.get(); }
PassRefPtr<MediaStreamTrackList> tracks() { return m_tracks; }
void streamEnded();
// MediaStreamFrameController::MediaStreamClient implementation.
virtual void streamEnded();
MediaStreamDescriptor* descriptor() const { return m_descriptor.get(); }
// EventTarget implementation.
virtual MediaStream* toMediaStream();
......@@ -69,24 +68,23 @@ public:
using RefCounted<MediaStream>::deref;
protected:
MediaStream(MediaStreamFrameController*, const String& label, PassRefPtr<MediaStreamTrackList> tracks, bool isLocalMediaStream);
MediaStream(ScriptExecutionContext*, PassRefPtr<MediaStreamDescriptor>);
// EventTarget implementation.
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
unsigned short m_readyState;
private:
void onEnded();
// EventTarget implementation.
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
EventTargetData m_eventTargetData;
RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
RefPtr<MediaStreamTrackList> m_tracks;
RefPtr<MediaStreamDescriptor> m_descriptor;
};
} // namespace WebCore
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -29,16 +30,14 @@
namespace WebCore {
PassRefPtr<MediaStreamTrack> MediaStreamTrack::create(const String& id, const String& kind, const String& label)
PassRefPtr<MediaStreamTrack> MediaStreamTrack::create(PassRefPtr<MediaStreamDescriptor> streamDescriptor, size_t trackIndex)
{
return adoptRef(new MediaStreamTrack(id, kind, label));
return adoptRef(new MediaStreamTrack(streamDescriptor, trackIndex));
}
MediaStreamTrack::MediaStreamTrack(const String& id, const String& kind, const String& label)
: m_id(id)
, m_kind(kind)
, m_label(label)
, m_enabled(true)
MediaStreamTrack::MediaStreamTrack(PassRefPtr<MediaStreamDescriptor> streamDescriptor, size_t trackIndex)
: m_streamDescriptor(streamDescriptor)
, m_trackIndex(trackIndex)
{
}
......@@ -46,27 +45,39 @@ MediaStreamTrack::~MediaStreamTrack()
{
}
const String& MediaStreamTrack::kind() const
String MediaStreamTrack::kind() const
{
return m_kind;
DEFINE_STATIC_LOCAL(String, audioKind, ("audio"));
DEFINE_STATIC_LOCAL(String, videoKind, ("video"));
switch (m_streamDescriptor->component(m_trackIndex)->source()->type()) {
case MediaStreamSource::TypeAudio:
return audioKind;
case MediaStreamSource::TypeVideo:
return videoKind;
}
ASSERT_NOT_REACHED();
}
const String& MediaStreamTrack::label() const
String MediaStreamTrack::label() const
{
return m_label;
return m_streamDescriptor->component(m_trackIndex)->source()->name();
}
bool MediaStreamTrack::enabled() const
{
return m_enabled;
return m_streamDescriptor->component(m_trackIndex)->enabled();
}
void MediaStreamTrack::setEnabled(bool enabled)
{
m_enabled = enabled;
if (enabled == m_streamDescriptor->component(m_trackIndex)->enabled())
return;
m_streamDescriptor->component(m_trackIndex)->setEnabled(enabled);
if (mediaStreamFrameController())
mediaStreamFrameController()->setMediaStreamTrackEnabled(m_id, enabled);
// FIXME: tell the platform that the track was enabled/disabled
}
} // namespace WebCore
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -27,36 +28,33 @@
#if ENABLE(MEDIA_STREAM)
#include "MediaStreamDescriptor.h"
#include "PlatformString.h"
#include "MediaStreamFrameController.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class MediaStreamTrack : public RefCounted<MediaStreamTrack>,
public MediaStreamFrameController::GenericClient {
class MediaStreamTrack : public RefCounted<MediaStreamTrack> {
public:
static PassRefPtr<MediaStreamTrack> create(const String& id, const String& kind, const String& label);
static PassRefPtr<MediaStreamTrack> create(PassRefPtr<MediaStreamDescriptor>, size_t trackIndex);
virtual ~MediaStreamTrack();
const String& kind() const;
const String& label() const;
String kind() const;
String label() const;
bool enabled() const;
void setEnabled(bool enabled);
void setEnabled(bool);
private:
MediaStreamTrack(const String& id, const String& kind, const String& label);
MediaStreamTrack(PassRefPtr<MediaStreamDescriptor>, size_t trackIndex);
String m_id;
String m_kind;
String m_label;
bool m_enabled;
RefPtr<MediaStreamDescriptor> m_streamDescriptor;
const size_t m_trackIndex;
};
typedef Vector<RefPtr<MediaStreamTrack> > TrackVector;
typedef Vector<RefPtr<MediaStreamTrack> > MediaStreamTrackVector;
} // namespace WebCore
......
......@@ -27,9 +27,9 @@ module core {
interface [
Conditional=MEDIA_STREAM,
] MediaStreamTrack {
readonly attribute DOMString kind;
readonly attribute DOMString label;
attribute boolean enabled;
readonly attribute DOMString kind;
readonly attribute DOMString label;
attribute boolean enabled;
};
}
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -29,13 +30,13 @@
namespace WebCore {
PassRefPtr<MediaStreamTrackList> MediaStreamTrackList::create(const TrackVector& tracks)
PassRefPtr<MediaStreamTrackList> MediaStreamTrackList::create(const MediaStreamTrackVector& trackVector)
{
return adoptRef(new MediaStreamTrackList(tracks));
return adoptRef(new MediaStreamTrackList(trackVector));
}
MediaStreamTrackList::MediaStreamTrackList(const TrackVector& tracks)
: m_tracks(tracks)
MediaStreamTrackList::MediaStreamTrackList(const MediaStreamTrackVector& trackVector)
: m_trackVector(trackVector)
{
}
......@@ -45,15 +46,13 @@ MediaStreamTrackList::~MediaStreamTrackList()
unsigned MediaStreamTrackList::length() const
{
return m_tracks.size();
return m_trackVector.size();
}
PassRefPtr<MediaStreamTrack> MediaStreamTrackList::item(unsigned index) const
MediaStreamTrack* MediaStreamTrackList::item(unsigned index) const
{
if (index < m_tracks.size())
return m_tracks.at(index);
else
return PassRefPtr<MediaStreamTrack>();
ASSERT(index < length());
return m_trackVector[index].get();
}
} // namespace WebCore
......
......@@ -28,28 +28,22 @@
#if ENABLE(MEDIA_STREAM)
#include "MediaStreamTrack.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class MediaStreamTrackList : public RefCounted<MediaStreamTrackList> {
public:
static PassRefPtr<MediaStreamTrackList> create(const TrackVector& m_tracks);
static PassRefPtr<MediaStreamTrackList> create(const MediaStreamTrackVector&);
virtual ~MediaStreamTrackList();
// DOM methods & attributes for MediaStreamTrackList
unsigned length() const;
PassRefPtr<MediaStreamTrack> item(unsigned index) const;
void associateStream(const String& label) { m_associatedStreamLabel = label; }
MediaStreamTrack* item(unsigned index) const;
private:
MediaStreamTrackList(const TrackVector& m_tracks);
MediaStreamTrackList(const MediaStreamTrackVector&);
TrackVector m_tracks;
String m_associatedStreamLabel;
MediaStreamTrackVector m_trackVector;
};
} // namespace WebCore
......
......@@ -129,8 +129,7 @@ void PeerConnection::addStream(PassRefPtr<MediaStream> prpStream, ExceptionCode&
m_localStreams->append(stream);
// FIXME: get from stream->descriptor() when it's available, see http://webkit.org/b/68464
MediaStreamDescriptor* streamDescriptor = 0;
MediaStreamDescriptor* streamDescriptor = stream->descriptor();
size_t i = m_pendingRemoveStreams.find(streamDescriptor);