From: tommyw@google.com Date: Mon, 2 Jul 2012 17:24:24 +0000 (+0000) Subject: MediaStream API: Update MediaStreamTrackList to match the specification X-Git-Tag: 070512121124~205 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d0e4be3316ec8a057363a6a5ecf39dcb4ba4d611;p=profile%2Fivi%2Fwebkit-efl.git MediaStream API: Update MediaStreamTrackList to match the specification https://bugs.webkit.org/show_bug.cgi?id=90171 Reviewed by Adam Barth. Source/Platform: The latest update to the specification added add and remove methods with corresponding callbacks. The callbacks can be triggered both from JS and from the platform layer. * chromium/public/WebMediaStreamCenterClient.h: (WebKit): (WebMediaStreamCenterClient): Source/WebCore: The latest update to the specification added add and remove methods with corresponding callbacks. The callbacks can be triggered both from JS and from the platform layer. Test: fast/mediastream/MediaStreamTrackList.html * CMakeLists.txt: * GNUmakefile.list.am: * Modules/mediastream/MediaStream.cpp: (WebCore::MediaStream::MediaStream): (WebCore::MediaStream::~MediaStream): (WebCore::MediaStream::streamEnded): (WebCore::MediaStream::addTrack): (WebCore): (WebCore::MediaStream::removeTrack): * Modules/mediastream/MediaStream.h: (MediaStream): * Modules/mediastream/MediaStreamTrackEvent.cpp: Copied from Source/WebCore/Modules/mediastream/MediaStreamTrackList.cpp. (WebCore): (WebCore::MediaStreamTrackEvent::create): (WebCore::MediaStreamTrackEvent::MediaStreamTrackEvent): (WebCore::MediaStreamTrackEvent::~MediaStreamTrackEvent): (WebCore::MediaStreamTrackEvent::track): (WebCore::MediaStreamTrackEvent::interfaceName): * Modules/mediastream/MediaStreamTrackEvent.h: Copied from Source/WebCore/Modules/mediastream/MediaStreamTrackList.h. (WebCore): (MediaStreamTrackEvent): * Modules/mediastream/MediaStreamTrackEvent.idl: Copied from Source/WebCore/Modules/mediastream/MediaStreamTrackList.idl. * Modules/mediastream/MediaStreamTrackList.cpp: (WebCore::MediaStreamTrackList::create): (WebCore::MediaStreamTrackList::MediaStreamTrackList): (WebCore::MediaStreamTrackList::detachOwner): (WebCore): (WebCore::MediaStreamTrackList::add): (WebCore::MediaStreamTrackList::remove): (WebCore::MediaStreamTrackList::stop): (WebCore::MediaStreamTrackList::interfaceName): (WebCore::MediaStreamTrackList::scriptExecutionContext): (WebCore::MediaStreamTrackList::eventTargetData): (WebCore::MediaStreamTrackList::ensureEventTargetData): * Modules/mediastream/MediaStreamTrackList.h: (MediaStreamTrackList): * Modules/mediastream/MediaStreamTrackList.idl: * WebCore.gypi: * dom/EventNames.h: (WebCore): * dom/EventNames.in: * dom/EventTargetFactory.in: * platform/mediastream/MediaStreamCenter.cpp: (WebCore::MediaStreamCenter::addMediaStreamTrack): (WebCore): (WebCore::MediaStreamCenter::removeMediaStreamTrack): * platform/mediastream/MediaStreamCenter.h: (MediaStreamCenter): * platform/mediastream/MediaStreamDescriptor.h: (MediaStreamDescriptorOwner): * platform/mediastream/chromium/MediaStreamCenterChromium.cpp: (WebCore::MediaStreamCenterChromium::didAddMediaStreamTrack): (WebCore): (WebCore::MediaStreamCenterChromium::didRemoveMediaStreamTrack): (WebCore::MediaStreamCenterChromium::addMediaStreamTrack): (WebCore::MediaStreamCenterChromium::removeMediaStreamTrack): * platform/mediastream/chromium/MediaStreamCenterChromium.h: (WebKit): (MediaStreamCenterChromium): * platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp: (WebCore::MediaStreamCenterGStreamer::didAddMediaStreamTrack): (WebCore): (WebCore::MediaStreamCenterGStreamer::didRemoveMediaStreamTrack): * platform/mediastream/gstreamer/MediaStreamCenterGStreamer.h: (MediaStreamCenterGStreamer): LayoutTests: * fast/mediastream/MediaStreamTrackList-expected.txt: Added. * fast/mediastream/MediaStreamTrackList.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121691 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 6aaa5c1..aca3d4f 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,13 @@ +2012-07-02 Tommy Widenflycht + + MediaStream API: Update MediaStreamTrackList to match the specification + https://bugs.webkit.org/show_bug.cgi?id=90171 + + Reviewed by Adam Barth. + + * fast/mediastream/MediaStreamTrackList-expected.txt: Added. + * fast/mediastream/MediaStreamTrackList.html: Added. + 2012-07-02 Emil A Eklund Unreviewed chromium expectations update. diff --git a/LayoutTests/fast/mediastream/MediaStreamTrackList-expected.txt b/LayoutTests/fast/mediastream/MediaStreamTrackList-expected.txt new file mode 100644 index 0000000..ab72526 --- /dev/null +++ b/LayoutTests/fast/mediastream/MediaStreamTrackList-expected.txt @@ -0,0 +1,13 @@ +Tests MediaStreamTrackList callbacks. + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS Add track callback succeeded. +PASS Remove track callback succeeded. +PASS stream1.videoTracks.add(stream2.videoTracks[0]) threw exception Error: INVALID_STATE_ERR: DOM Exception 11. +PASS stream1.videoTracks.remove(stream2.videoTracks[0]) threw exception Error: INVALID_STATE_ERR: DOM Exception 11. +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/mediastream/MediaStreamTrackList.html b/LayoutTests/fast/mediastream/MediaStreamTrackList.html new file mode 100644 index 0000000..c145256 --- /dev/null +++ b/LayoutTests/fast/mediastream/MediaStreamTrackList.html @@ -0,0 +1,67 @@ + + + + + + + +

+
+ + + + diff --git a/Source/Platform/ChangeLog b/Source/Platform/ChangeLog index abc39fb..07e4052 100644 --- a/Source/Platform/ChangeLog +++ b/Source/Platform/ChangeLog @@ -1,3 +1,17 @@ +2012-07-02 Tommy Widenflycht + + MediaStream API: Update MediaStreamTrackList to match the specification + https://bugs.webkit.org/show_bug.cgi?id=90171 + + Reviewed by Adam Barth. + + The latest update to the specification added add and remove methods with corresponding callbacks. + The callbacks can be triggered both from JS and from the platform layer. + + * chromium/public/WebMediaStreamCenterClient.h: + (WebKit): + (WebMediaStreamCenterClient): + 2012-07-01 Keishi Hattori Unreviewed, rolling out r121650. diff --git a/Source/Platform/chromium/public/WebMediaStreamCenterClient.h b/Source/Platform/chromium/public/WebMediaStreamCenterClient.h index 8a0825f..c6685b0 100644 --- a/Source/Platform/chromium/public/WebMediaStreamCenterClient.h +++ b/Source/Platform/chromium/public/WebMediaStreamCenterClient.h @@ -33,6 +33,7 @@ namespace WebKit { +class WebMediaStreamComponent; class WebMediaStreamDescriptor; class WebMediaStreamCenterClient { @@ -40,6 +41,8 @@ public: virtual ~WebMediaStreamCenterClient() { } virtual void stopLocalMediaStream(const WebMediaStreamDescriptor&) = 0; + virtual void addMediaStreamTrack(const WebMediaStreamDescriptor&, const WebMediaStreamComponent&) = 0; + virtual void removeMediaStreamTrack(const WebMediaStreamDescriptor&, const WebMediaStreamComponent&) = 0; }; } // namespace WebKit diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt index 6cf7242..350eb6f 100644 --- a/Source/WebCore/CMakeLists.txt +++ b/Source/WebCore/CMakeLists.txt @@ -2507,6 +2507,7 @@ IF (ENABLE_MEDIA_STREAM) Modules/mediastream/MediaStreamEvent.idl Modules/mediastream/MediaStreamList.idl Modules/mediastream/MediaStreamTrack.idl + Modules/mediastream/MediaStreamTrackEvent.idl Modules/mediastream/MediaStreamTrackList.idl Modules/mediastream/NavigatorMediaStream.idl Modules/mediastream/NavigatorUserMediaError.idl @@ -2525,6 +2526,7 @@ IF (ENABLE_MEDIA_STREAM) Modules/mediastream/MediaStreamList.cpp Modules/mediastream/MediaStreamRegistry.cpp Modules/mediastream/MediaStreamTrack.cpp + Modules/mediastream/MediaStreamTrackEvent.cpp Modules/mediastream/MediaStreamTrackList.cpp Modules/mediastream/NavigatorMediaStream.cpp Modules/mediastream/PeerConnection00.cpp diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index da13d15..4e577dc 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,81 @@ +2012-07-02 Tommy Widenflycht + + MediaStream API: Update MediaStreamTrackList to match the specification + https://bugs.webkit.org/show_bug.cgi?id=90171 + + Reviewed by Adam Barth. + + The latest update to the specification added add and remove methods with corresponding callbacks. + The callbacks can be triggered both from JS and from the platform layer. + + Test: fast/mediastream/MediaStreamTrackList.html + + * CMakeLists.txt: + * GNUmakefile.list.am: + * Modules/mediastream/MediaStream.cpp: + (WebCore::MediaStream::MediaStream): + (WebCore::MediaStream::~MediaStream): + (WebCore::MediaStream::streamEnded): + (WebCore::MediaStream::addTrack): + (WebCore): + (WebCore::MediaStream::removeTrack): + * Modules/mediastream/MediaStream.h: + (MediaStream): + * Modules/mediastream/MediaStreamTrackEvent.cpp: Copied from Source/WebCore/Modules/mediastream/MediaStreamTrackList.cpp. + (WebCore): + (WebCore::MediaStreamTrackEvent::create): + (WebCore::MediaStreamTrackEvent::MediaStreamTrackEvent): + (WebCore::MediaStreamTrackEvent::~MediaStreamTrackEvent): + (WebCore::MediaStreamTrackEvent::track): + (WebCore::MediaStreamTrackEvent::interfaceName): + * Modules/mediastream/MediaStreamTrackEvent.h: Copied from Source/WebCore/Modules/mediastream/MediaStreamTrackList.h. + (WebCore): + (MediaStreamTrackEvent): + * Modules/mediastream/MediaStreamTrackEvent.idl: Copied from Source/WebCore/Modules/mediastream/MediaStreamTrackList.idl. + * Modules/mediastream/MediaStreamTrackList.cpp: + (WebCore::MediaStreamTrackList::create): + (WebCore::MediaStreamTrackList::MediaStreamTrackList): + (WebCore::MediaStreamTrackList::detachOwner): + (WebCore): + (WebCore::MediaStreamTrackList::add): + (WebCore::MediaStreamTrackList::remove): + (WebCore::MediaStreamTrackList::stop): + (WebCore::MediaStreamTrackList::interfaceName): + (WebCore::MediaStreamTrackList::scriptExecutionContext): + (WebCore::MediaStreamTrackList::eventTargetData): + (WebCore::MediaStreamTrackList::ensureEventTargetData): + * Modules/mediastream/MediaStreamTrackList.h: + (MediaStreamTrackList): + * Modules/mediastream/MediaStreamTrackList.idl: + * WebCore.gypi: + * dom/EventNames.h: + (WebCore): + * dom/EventNames.in: + * dom/EventTargetFactory.in: + * platform/mediastream/MediaStreamCenter.cpp: + (WebCore::MediaStreamCenter::addMediaStreamTrack): + (WebCore): + (WebCore::MediaStreamCenter::removeMediaStreamTrack): + * platform/mediastream/MediaStreamCenter.h: + (MediaStreamCenter): + * platform/mediastream/MediaStreamDescriptor.h: + (MediaStreamDescriptorOwner): + * platform/mediastream/chromium/MediaStreamCenterChromium.cpp: + (WebCore::MediaStreamCenterChromium::didAddMediaStreamTrack): + (WebCore): + (WebCore::MediaStreamCenterChromium::didRemoveMediaStreamTrack): + (WebCore::MediaStreamCenterChromium::addMediaStreamTrack): + (WebCore::MediaStreamCenterChromium::removeMediaStreamTrack): + * platform/mediastream/chromium/MediaStreamCenterChromium.h: + (WebKit): + (MediaStreamCenterChromium): + * platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp: + (WebCore::MediaStreamCenterGStreamer::didAddMediaStreamTrack): + (WebCore): + (WebCore::MediaStreamCenterGStreamer::didRemoveMediaStreamTrack): + * platform/mediastream/gstreamer/MediaStreamCenterGStreamer.h: + (MediaStreamCenterGStreamer): + 2012-07-02 Andrey Kosyakov Web Inspector: incorrect height of main timeline pane after switching to memory mode diff --git a/Source/WebCore/GNUmakefile.list.am b/Source/WebCore/GNUmakefile.list.am index fcaccac..de7bcc6 100644 --- a/Source/WebCore/GNUmakefile.list.am +++ b/Source/WebCore/GNUmakefile.list.am @@ -391,6 +391,8 @@ webcore_built_sources += \ DerivedSources/WebCore/JSMediaStreamList.h \ DerivedSources/WebCore/JSMediaStreamTrack.cpp \ DerivedSources/WebCore/JSMediaStreamTrack.h \ + DerivedSources/WebCore/JSMediaStreamTrackEvent.cpp \ + DerivedSources/WebCore/JSMediaStreamTrackEvent.h \ DerivedSources/WebCore/JSMediaStreamTrackList.cpp \ DerivedSources/WebCore/JSMediaStreamTrackList.h \ DerivedSources/WebCore/JSMediaQueryList.cpp \ @@ -699,6 +701,7 @@ dom_binding_idls += \ $(WebCore)/Modules/mediastream/MediaStreamEvent.idl \ $(WebCore)/Modules/mediastream/MediaStreamList.idl \ $(WebCore)/Modules/mediastream/MediaStreamTrack.idl \ + $(WebCore)/Modules/mediastream/MediaStreamTrackEvent.idl \ $(WebCore)/Modules/mediastream/MediaStreamTrackList.idl \ $(WebCore)/Modules/mediastream/NavigatorMediaStream.idl \ $(WebCore)/Modules/mediastream/NavigatorUserMediaError.idl \ @@ -1172,6 +1175,8 @@ webcore_modules_sources += \ Source/WebCore/Modules/mediastream/MediaStreamRegistry.h \ Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp \ Source/WebCore/Modules/mediastream/MediaStreamTrack.h \ + Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.cpp \ + Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.h \ Source/WebCore/Modules/mediastream/MediaStreamTrackList.cpp \ Source/WebCore/Modules/mediastream/MediaStreamTrackList.h \ Source/WebCore/Modules/mediastream/NavigatorMediaStream.cpp \ diff --git a/Source/WebCore/Modules/mediastream/MediaStream.cpp b/Source/WebCore/Modules/mediastream/MediaStream.cpp index 8a3f585..e4efc49 100644 --- a/Source/WebCore/Modules/mediastream/MediaStream.cpp +++ b/Source/WebCore/Modules/mediastream/MediaStream.cpp @@ -95,19 +95,21 @@ MediaStream::MediaStream(ScriptExecutionContext* context, PassRefPtraudioComponent(i))); - m_audioTracks = MediaStreamTrackList::create(audioTrackVector); + m_audioTracks = MediaStreamTrackList::create(this, audioTrackVector); MediaStreamTrackVector videoTrackVector; size_t numberOfVideoTracks = m_descriptor->numberOfVideoComponents(); videoTrackVector.reserveCapacity(numberOfVideoTracks); for (size_t i = 0; i < numberOfVideoTracks; i++) videoTrackVector.append(MediaStreamTrack::create(m_descriptor, m_descriptor->videoComponent(i))); - m_videoTracks = MediaStreamTrackList::create(videoTrackVector); + m_videoTracks = MediaStreamTrackList::create(this, videoTrackVector); } MediaStream::~MediaStream() { m_descriptor->setOwner(0); + m_audioTracks->detachOwner(); + m_videoTracks->detachOwner(); } MediaStream::ReadyState MediaStream::readyState() const @@ -121,6 +123,8 @@ void MediaStream::streamEnded() return; m_descriptor->setEnded(); + m_audioTracks->detachOwner(); + m_videoTracks->detachOwner(); dispatchEvent(Event::create(eventNames().endedEvent, false, false)); } @@ -145,6 +149,33 @@ EventTargetData* MediaStream::ensureEventTargetData() return &m_eventTargetData; } +void MediaStream::addTrack(MediaStreamComponent* component) +{ + RefPtr track = MediaStreamTrack::create(m_descriptor, component); + ExceptionCode ec = 0; + switch (component->source()->type()) { + case MediaStreamSource::TypeAudio: + m_audioTracks->add(track, ec); + break; + case MediaStreamSource::TypeVideo: + m_videoTracks->add(track, ec); + break; + } + ASSERT(!ec); +} + +void MediaStream::removeTrack(MediaStreamComponent* component) +{ + switch (component->source()->type()) { + case MediaStreamSource::TypeAudio: + m_audioTracks->remove(component); + break; + case MediaStreamSource::TypeVideo: + m_videoTracks->remove(component); + break; + } +} + } // namespace WebCore #endif // ENABLE(MEDIA_STREAM) diff --git a/Source/WebCore/Modules/mediastream/MediaStream.h b/Source/WebCore/Modules/mediastream/MediaStream.h index f6a98de..bcdd25d 100644 --- a/Source/WebCore/Modules/mediastream/MediaStream.h +++ b/Source/WebCore/Modules/mediastream/MediaStream.h @@ -39,7 +39,6 @@ namespace WebCore { class MediaStream : public RefCounted, public MediaStreamDescriptorOwner, public EventTarget, public ContextDestructionObserver { public: - // Must match the constants in the .idl file. enum ReadyState { LIVE = 1, ENDED = 2 @@ -57,7 +56,8 @@ public: MediaStreamTrackList* audioTracks() { return m_audioTracks.get(); } MediaStreamTrackList* videoTracks() { return m_videoTracks.get(); } - void streamEnded(); + // MediaStreamDescriptorOwner + virtual void streamEnded() OVERRIDE; MediaStreamDescriptor* descriptor() const { return m_descriptor.get(); } @@ -80,6 +80,10 @@ private: virtual void refEventTarget() OVERRIDE { ref(); } virtual void derefEventTarget() OVERRIDE { deref(); } + // MediaStreamDescriptorOwner + virtual void addTrack(MediaStreamComponent*) OVERRIDE; + virtual void removeTrack(MediaStreamComponent*) OVERRIDE; + EventTargetData m_eventTargetData; RefPtr m_audioTracks; diff --git a/Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.cpp b/Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.cpp new file mode 100644 index 0000000..f621002 --- /dev/null +++ b/Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#if ENABLE(MEDIA_STREAM) + +#include "MediaStreamTrackEvent.h" + +#include "EventNames.h" +#include "MediaStreamTrack.h" + +namespace WebCore { + +PassRefPtr MediaStreamTrackEvent::create() +{ + return adoptRef(new MediaStreamTrackEvent); +} + +PassRefPtr MediaStreamTrackEvent::create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr track) +{ + return adoptRef(new MediaStreamTrackEvent(type, canBubble, cancelable, track)); +} + + +MediaStreamTrackEvent::MediaStreamTrackEvent() +{ +} + +MediaStreamTrackEvent::MediaStreamTrackEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr track) + : Event(type, canBubble, cancelable) + , m_track(track) +{ +} + +MediaStreamTrackEvent::~MediaStreamTrackEvent() +{ +} + +MediaStreamTrack* MediaStreamTrackEvent::track() const +{ + return m_track.get(); +} + +const AtomicString& MediaStreamTrackEvent::interfaceName() const +{ + return eventNames().interfaceForMediaStreamTrackEvent; +} + +} // namespace WebCore + +#endif // ENABLE(MEDIA_STREAM) + diff --git a/Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.h b/Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.h new file mode 100644 index 0000000..6014913 --- /dev/null +++ b/Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef MediaStreamTrackEvent_h +#define MediaStreamTrackEvent_h + +#if ENABLE(MEDIA_STREAM) + +#include "Event.h" +#include + +namespace WebCore { + +class MediaStreamTrack; + +class MediaStreamTrackEvent : public Event { +public: + virtual ~MediaStreamTrackEvent(); + + static PassRefPtr create(); + static PassRefPtr create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr); + + MediaStreamTrack* track() const; + + // Event + virtual const AtomicString& interfaceName() const OVERRIDE; + +private: + MediaStreamTrackEvent(); + MediaStreamTrackEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr); + + RefPtr m_track; +}; + +} // namespace WebCore + +#endif // ENABLE(MEDIA_STREAM) + +#endif // MediaStreamTrackEvent_h diff --git a/Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.idl b/Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.idl new file mode 100644 index 0000000..320c603 --- /dev/null +++ b/Source/WebCore/Modules/mediastream/MediaStreamTrackEvent.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +module events { + + interface [ + Conditional=MEDIA_STREAM, + ] MediaStreamTrackEvent : Event { + readonly attribute MediaStreamTrack track; + }; + +} diff --git a/Source/WebCore/Modules/mediastream/MediaStreamTrackList.cpp b/Source/WebCore/Modules/mediastream/MediaStreamTrackList.cpp index b63bcef..e987d01 100644 --- a/Source/WebCore/Modules/mediastream/MediaStreamTrackList.cpp +++ b/Source/WebCore/Modules/mediastream/MediaStreamTrackList.cpp @@ -24,19 +24,29 @@ */ #include "config.h" +#if ENABLE(MEDIA_STREAM) + #include "MediaStreamTrackList.h" -#if ENABLE(MEDIA_STREAM) +#include "ExceptionCode.h" +#include "MediaStream.h" +#include "MediaStreamCenter.h" +#include "MediaStreamTrackEvent.h" namespace WebCore { -PassRefPtr MediaStreamTrackList::create(const MediaStreamTrackVector& trackVector) +PassRefPtr MediaStreamTrackList::create(MediaStream* owner, const MediaStreamTrackVector& trackVector) { - return adoptRef(new MediaStreamTrackList(trackVector)); + ASSERT(owner); + RefPtr trackList = adoptRef(new MediaStreamTrackList(owner, trackVector)); + trackList->suspendIfNeeded(); + return trackList.release(); } -MediaStreamTrackList::MediaStreamTrackList(const MediaStreamTrackVector& trackVector) - : m_trackVector(trackVector) +MediaStreamTrackList::MediaStreamTrackList(MediaStream* owner, const MediaStreamTrackVector& trackVector) + : ActiveDOMObject(owner->scriptExecutionContext(), this) + , m_owner(owner) + , m_trackVector(trackVector) { } @@ -44,6 +54,11 @@ MediaStreamTrackList::~MediaStreamTrackList() { } +void MediaStreamTrackList::detachOwner() +{ + m_owner = 0; +} + unsigned MediaStreamTrackList::length() const { return m_trackVector.size(); @@ -56,6 +71,96 @@ MediaStreamTrack* MediaStreamTrackList::item(unsigned index) const return m_trackVector[index].get(); } +void MediaStreamTrackList::add(PassRefPtr prpTrack, ExceptionCode& ec) +{ + if (!m_owner || m_owner->readyState() == MediaStream::ENDED) { + ec = INVALID_STATE_ERR; + return; + } + + RefPtr track = prpTrack; + if (!track) { + ec = TYPE_MISMATCH_ERR; + return; + } + + if (m_trackVector.contains(track)) + return; + + m_trackVector.append(track); + MediaStreamCenter::instance().didAddMediaStreamTrack(m_owner->descriptor(), track->component()); + dispatchEvent(MediaStreamTrackEvent::create(eventNames().addtrackEvent, false, false, track)); +} + +void MediaStreamTrackList::remove(PassRefPtr prpTrack, ExceptionCode& ec) +{ + if (!m_owner || m_owner->readyState() == MediaStream::ENDED) { + ec = INVALID_STATE_ERR; + return; + } + + RefPtr track = prpTrack; + if (!track) { + ec = TYPE_MISMATCH_ERR; + return; + } + + size_t index = m_trackVector.find(track); + if (index == notFound) + return; + + m_trackVector.remove(index); + MediaStreamCenter::instance().didRemoveMediaStreamTrack(m_owner->descriptor(), track->component()); + dispatchEvent(MediaStreamTrackEvent::create(eventNames().removetrackEvent, false, false, track)); +} + +void MediaStreamTrackList::remove(MediaStreamComponent* component) +{ + if (!m_owner || m_owner->readyState() == MediaStream::ENDED) + return; + + size_t index = notFound; + for (unsigned i = 0; i < m_trackVector.size(); ++i) { + if (m_trackVector[i]->component() == component) { + index = i; + break; + } + } + + if (index == notFound) + return; + + RefPtr track = m_trackVector[index]; + m_trackVector.remove(index); + MediaStreamCenter::instance().didRemoveMediaStreamTrack(m_owner->descriptor(), component); + dispatchEvent(MediaStreamTrackEvent::create(eventNames().removetrackEvent, false, false, track)); +} + +void MediaStreamTrackList::stop() +{ + detachOwner(); +} + +const AtomicString& MediaStreamTrackList::interfaceName() const +{ + return eventNames().interfaceForMediaStreamTrackList; +} + +ScriptExecutionContext* MediaStreamTrackList::scriptExecutionContext() const +{ + return ActiveDOMObject::scriptExecutionContext(); +} + +EventTargetData* MediaStreamTrackList::eventTargetData() +{ + return &m_eventTargetData; +} + +EventTargetData* MediaStreamTrackList::ensureEventTargetData() +{ + return &m_eventTargetData; +} + } // namespace WebCore #endif // ENABLE(MEDIA_STREAM) diff --git a/Source/WebCore/Modules/mediastream/MediaStreamTrackList.h b/Source/WebCore/Modules/mediastream/MediaStreamTrackList.h index 4d61f85e..d5a37b6 100644 --- a/Source/WebCore/Modules/mediastream/MediaStreamTrackList.h +++ b/Source/WebCore/Modules/mediastream/MediaStreamTrackList.h @@ -27,21 +27,53 @@ #if ENABLE(MEDIA_STREAM) +#include "ActiveDOMObject.h" +#include "EventTarget.h" #include "MediaStreamTrack.h" namespace WebCore { -class MediaStreamTrackList : public RefCounted { +class MediaStreamTrackList : public RefCounted, public ActiveDOMObject, public EventTarget { public: - static PassRefPtr create(const MediaStreamTrackVector&); + static PassRefPtr create(MediaStream*, const MediaStreamTrackVector&); virtual ~MediaStreamTrackList(); + void detachOwner(); + // DOM methods & attributes for MediaStreamTrackList unsigned length() const; MediaStreamTrack* item(unsigned index) const; + void add(PassRefPtr, ExceptionCode&); + void remove(PassRefPtr, ExceptionCode&); + + DEFINE_ATTRIBUTE_EVENT_LISTENER(addtrack); + DEFINE_ATTRIBUTE_EVENT_LISTENER(removetrack); + + void remove(MediaStreamComponent*); + + // ActiveDOMObject + virtual void stop() OVERRIDE; + + // EventTarget + virtual const AtomicString& interfaceName() const OVERRIDE; + virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE; + + using RefCounted::ref; + using RefCounted::deref; + private: - MediaStreamTrackList(const MediaStreamTrackVector&); + MediaStreamTrackList(MediaStream*, const MediaStreamTrackVector&); + + // EventTarget + virtual EventTargetData* eventTargetData() OVERRIDE; + virtual EventTargetData* ensureEventTargetData() OVERRIDE; + virtual void refEventTarget() OVERRIDE { ref(); } + virtual void derefEventTarget() OVERRIDE { deref(); } + EventTargetData m_eventTargetData; + + // m_owner can become zero. + MediaStream* m_owner; MediaStreamTrackVector m_trackVector; }; diff --git a/Source/WebCore/Modules/mediastream/MediaStreamTrackList.idl b/Source/WebCore/Modules/mediastream/MediaStreamTrackList.idl index 4dd9c29..957655d 100644 --- a/Source/WebCore/Modules/mediastream/MediaStreamTrackList.idl +++ b/Source/WebCore/Modules/mediastream/MediaStreamTrackList.idl @@ -26,11 +26,29 @@ module core { interface [ Conditional=MEDIA_STREAM, - IndexedGetter + IndexedGetter, + EventTarget ] MediaStreamTrackList { + readonly attribute unsigned long length; MediaStreamTrack item(in [IsIndex] unsigned long index); - readonly attribute unsigned long length; + void add(in MediaStreamTrack track) + raises(DOMException); + void remove(in MediaStreamTrack track) + raises(DOMException); + + attribute EventListener onaddtrack; + attribute EventListener onremovetrack; + + // EventTarget interface + void addEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + void removeEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + boolean dispatchEvent(in Event event) + raises(EventException); }; } diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi index 1be3022..ab051ae 100644 --- a/Source/WebCore/WebCore.gypi +++ b/Source/WebCore/WebCore.gypi @@ -833,6 +833,7 @@ 'Modules/mediastream/MediaStreamEvent.idl', 'Modules/mediastream/MediaStreamList.idl', 'Modules/mediastream/MediaStreamTrack.idl', + 'Modules/mediastream/MediaStreamTrackEvent.idl', 'Modules/mediastream/MediaStreamTrackList.idl', 'Modules/mediastream/NavigatorMediaStream.idl', 'Modules/mediastream/NavigatorUserMediaError.idl', @@ -1549,6 +1550,8 @@ 'Modules/mediastream/MediaStreamRegistry.h', 'Modules/mediastream/MediaStreamTrack.cpp', 'Modules/mediastream/MediaStreamTrack.h', + 'Modules/mediastream/MediaStreamTrackEvent.cpp', + 'Modules/mediastream/MediaStreamTrackEvent.h', 'Modules/mediastream/MediaStreamTrackList.cpp', 'Modules/mediastream/MediaStreamTrackList.h', 'Modules/mediastream/NavigatorMediaStream.cpp', diff --git a/Source/WebCore/dom/EventNames.h b/Source/WebCore/dom/EventNames.h index 598bcdd..836e630 100644 --- a/Source/WebCore/dom/EventNames.h +++ b/Source/WebCore/dom/EventNames.h @@ -216,6 +216,7 @@ namespace WebCore { macro(addstream) \ macro(removestream) \ macro(statechange) \ + macro(removetrack) \ \ macro(show) \ \ diff --git a/Source/WebCore/dom/EventNames.in b/Source/WebCore/dom/EventNames.in index f42b4b4..9c0ac55 100644 --- a/Source/WebCore/dom/EventNames.in +++ b/Source/WebCore/dom/EventNames.in @@ -30,6 +30,7 @@ XMLHttpRequestProgressEvent AudioProcessingEvent conditional=WEB_AUDIO OfflineAudioCompletionEvent conditional=WEB_AUDIO MediaStreamEvent conditional=MEDIA_STREAM +MediaStreamTrackEvent conditional=MEDIA_STREAM SpeechInputEvent conditional=INPUT_SPEECH SpeechRecognitionError conditional=SCRIPTED_SPEECH SpeechRecognitionEvent conditional=SCRIPTED_SPEECH diff --git a/Source/WebCore/dom/EventTargetFactory.in b/Source/WebCore/dom/EventTargetFactory.in index 3ec6db9..821717b 100644 --- a/Source/WebCore/dom/EventTargetFactory.in +++ b/Source/WebCore/dom/EventTargetFactory.in @@ -17,6 +17,7 @@ JavaScriptAudioNode conditional=WEB_AUDIO LocalMediaStream conditional=MEDIA_STREAM MediaController conditional=VIDEO MediaStream conditional=MEDIA_STREAM +MediaStreamTrackList conditional=MEDIA_STREAM MessagePort NetworkInfoConnection conditional=NETWORK_INFO Node diff --git a/Source/WebCore/platform/mediastream/MediaStreamCenter.cpp b/Source/WebCore/platform/mediastream/MediaStreamCenter.cpp index 9dd4bb1..f4f9822 100644 --- a/Source/WebCore/platform/mediastream/MediaStreamCenter.cpp +++ b/Source/WebCore/platform/mediastream/MediaStreamCenter.cpp @@ -56,6 +56,20 @@ void MediaStreamCenter::endLocalMediaStream(MediaStreamDescriptor* streamDescrip streamDescriptor->setEnded(); } +void MediaStreamCenter::addMediaStreamTrack(MediaStreamDescriptor* streamDescriptor, MediaStreamComponent* component) +{ + MediaStreamDescriptorOwner* owner = streamDescriptor->owner(); + if (owner) + owner->addTrack(component); +} + +void MediaStreamCenter::removeMediaStreamTrack(MediaStreamDescriptor* streamDescriptor, MediaStreamComponent* component) +{ + MediaStreamDescriptorOwner* owner = streamDescriptor->owner(); + if (owner) + owner->removeTrack(component); +} + } // namespace WebCore #endif // ENABLE(MEDIA_STREAM) diff --git a/Source/WebCore/platform/mediastream/MediaStreamCenter.h b/Source/WebCore/platform/mediastream/MediaStreamCenter.h index b3278c7..c8a51de 100644 --- a/Source/WebCore/platform/mediastream/MediaStreamCenter.h +++ b/Source/WebCore/platform/mediastream/MediaStreamCenter.h @@ -57,9 +57,10 @@ public: // Calls from the DOM objects to notify the platform virtual void didSetMediaStreamTrackEnabled(MediaStreamDescriptor*, MediaStreamComponent*) = 0; + virtual void didAddMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*) = 0; + virtual void didRemoveMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*) = 0; virtual void didStopLocalMediaStream(MediaStreamDescriptor*) = 0; virtual void didCreateMediaStream(MediaStreamDescriptor*) = 0; - virtual String constructSDP(IceCandidateDescriptor*) = 0; virtual String constructSDP(SessionDescriptionDescriptor*) = 0; @@ -67,6 +68,8 @@ protected: MediaStreamCenter(); void endLocalMediaStream(MediaStreamDescriptor*); + void addMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*); + void removeMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*); }; } // namespace WebCore diff --git a/Source/WebCore/platform/mediastream/MediaStreamDescriptor.h b/Source/WebCore/platform/mediastream/MediaStreamDescriptor.h index 46332af..c606105 100644 --- a/Source/WebCore/platform/mediastream/MediaStreamDescriptor.h +++ b/Source/WebCore/platform/mediastream/MediaStreamDescriptor.h @@ -45,6 +45,8 @@ public: virtual ~MediaStreamDescriptorOwner() { } virtual void streamEnded() = 0; + virtual void addTrack(MediaStreamComponent*) = 0; + virtual void removeTrack(MediaStreamComponent*) = 0; }; class MediaStreamDescriptor : public RefCounted { diff --git a/Source/WebCore/platform/mediastream/chromium/MediaStreamCenterChromium.cpp b/Source/WebCore/platform/mediastream/chromium/MediaStreamCenterChromium.cpp index 1317d2d..3c82f5f 100644 --- a/Source/WebCore/platform/mediastream/chromium/MediaStreamCenterChromium.cpp +++ b/Source/WebCore/platform/mediastream/chromium/MediaStreamCenterChromium.cpp @@ -83,6 +83,14 @@ void MediaStreamCenterChromium::didSetMediaStreamTrackEnabled(MediaStreamDescrip } } +void MediaStreamCenterChromium::didAddMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*) +{ +} + +void MediaStreamCenterChromium::didRemoveMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*) +{ +} + void MediaStreamCenterChromium::didStopLocalMediaStream(MediaStreamDescriptor* stream) { if (m_private) @@ -115,6 +123,16 @@ void MediaStreamCenterChromium::stopLocalMediaStream(const WebKit::WebMediaStrea endLocalMediaStream(stream); } +void MediaStreamCenterChromium::addMediaStreamTrack(const WebKit::WebMediaStreamDescriptor& stream, const WebKit::WebMediaStreamComponent& component) +{ + MediaStreamCenter::addMediaStreamTrack(stream, component); +} + +void MediaStreamCenterChromium::removeMediaStreamTrack(const WebKit::WebMediaStreamDescriptor& stream, const WebKit::WebMediaStreamComponent& component) +{ + MediaStreamCenter::removeMediaStreamTrack(stream, component); +} + } // namespace WebCore #endif // ENABLE(MEDIA_STREAM) diff --git a/Source/WebCore/platform/mediastream/chromium/MediaStreamCenterChromium.h b/Source/WebCore/platform/mediastream/chromium/MediaStreamCenterChromium.h index d284a86..e3fff8a 100644 --- a/Source/WebCore/platform/mediastream/chromium/MediaStreamCenterChromium.h +++ b/Source/WebCore/platform/mediastream/chromium/MediaStreamCenterChromium.h @@ -42,6 +42,7 @@ namespace WebKit { class WebMediaStreamCenter; +class WebMediaStreamComponent; class WebMediaStreamDescriptor; } @@ -61,6 +62,8 @@ public: // MediaStreamCenter virtual void queryMediaStreamSources(PassRefPtr) OVERRIDE; virtual void didSetMediaStreamTrackEnabled(MediaStreamDescriptor*, MediaStreamComponent*) OVERRIDE; + virtual void didAddMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*) OVERRIDE; + virtual void didRemoveMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*) OVERRIDE; virtual void didStopLocalMediaStream(MediaStreamDescriptor*) OVERRIDE; virtual void didCreateMediaStream(MediaStreamDescriptor*) OVERRIDE; virtual String constructSDP(IceCandidateDescriptor*) OVERRIDE; @@ -68,6 +71,8 @@ public: // WebKit::WebMediaStreamCenterClient virtual void stopLocalMediaStream(const WebKit::WebMediaStreamDescriptor&) OVERRIDE; + virtual void addMediaStreamTrack(const WebKit::WebMediaStreamDescriptor&, const WebKit::WebMediaStreamComponent&) OVERRIDE; + virtual void removeMediaStreamTrack(const WebKit::WebMediaStreamDescriptor&, const WebKit::WebMediaStreamComponent&) OVERRIDE; private: OwnPtr m_private; diff --git a/Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp b/Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp index fe8bb46..dc483ff 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp +++ b/Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp @@ -68,6 +68,14 @@ void MediaStreamCenterGStreamer::didSetMediaStreamTrackEnabled(MediaStreamDescri { } +void MediaStreamCenterGStreamer::didAddMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*) +{ +} + +void MediaStreamCenterGStreamer::didRemoveMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*) +{ +} + void MediaStreamCenterGStreamer::didStopLocalMediaStream(MediaStreamDescriptor*) { } diff --git a/Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.h b/Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.h index 1564e33..7641fb5 100644 --- a/Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.h +++ b/Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.h @@ -55,6 +55,8 @@ public: // MediaStreamCenter virtual void queryMediaStreamSources(PassRefPtr) OVERRIDE; virtual void didSetMediaStreamTrackEnabled(MediaStreamDescriptor*, MediaStreamComponent*) OVERRIDE; + virtual void didAddMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*) OVERRIDE; + virtual void didRemoveMediaStreamTrack(MediaStreamDescriptor*, MediaStreamComponent*) OVERRIDE; virtual void didStopLocalMediaStream(MediaStreamDescriptor*) OVERRIDE; virtual void didCreateMediaStream(MediaStreamDescriptor*) OVERRIDE; virtual String constructSDP(IceCandidateDescriptor*) OVERRIDE;