Commit d0e4be33 authored by tommyw@google.com's avatar tommyw@google.com

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
parent 82d10f7d
2012-07-02 Tommy Widenflycht <tommyw@google.com>
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 <eae@chromium.org>
Unreviewed chromium expectations update.
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
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Tests MediaStreamTrackList callbacks.");
var stream1;
var stream2;
function error() {
testFailed('Stream generation failed.');
finishJSTest();
}
function getUserMedia(dictionary, callback) {
try {
navigator.webkitGetUserMedia(dictionary, callback, error);
} catch (e) {
testFailed('webkitGetUserMedia threw exception :' + e);
finishJSTest();
}
}
function onRemoveTrack(e) {
testPassed('Remove track callback succeeded.');
// Now test that add failes when the parent stream has been stopped.
stream1.stop();
shouldThrow('stream1.videoTracks.add(stream2.videoTracks[0])');
shouldThrow('stream1.videoTracks.remove(stream2.videoTracks[0])');
finishJSTest();
}
function onAddTrack(e) {
testPassed('Add track callback succeeded.');
stream1.videoTracks.onremovetrack = onRemoveTrack;
stream1.videoTracks.remove(e.track);
}
function gotStream2(s) {
stream2 = s;
stream1.videoTracks.onaddtrack = onAddTrack;
stream1.videoTracks.add(stream2.videoTracks[0]);
}
function gotStream1(s) {
stream1 = s;
getUserMedia({audio:true, video:true}, gotStream2);
}
getUserMedia({audio:true, video:true}, gotStream1);
window.jsTestIsAsync = true;
window.successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
2012-07-02 Tommy Widenflycht <tommyw@google.com>
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 <keishi@webkit.org>
Unreviewed, rolling out r121650.
......
......@@ -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
......
......@@ -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
......
2012-07-02 Tommy Widenflycht <tommyw@google.com>
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 <caseq@chromium.org>
Web Inspector: incorrect height of main timeline pane after switching to memory mode
......@@ -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 \
......
......@@ -95,19 +95,21 @@ MediaStream::MediaStream(ScriptExecutionContext* context, PassRefPtr<MediaStream
audioTrackVector.reserveCapacity(numberOfAudioTracks);
for (size_t i = 0; i < numberOfAudioTracks; i++)
audioTrackVector.append(MediaStreamTrack::create(m_descriptor, m_descriptor->audioComponent(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<MediaStreamTrack> 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)
......@@ -39,7 +39,6 @@ namespace WebCore {
class MediaStream : public RefCounted<MediaStream>, 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<MediaStreamTrackList> m_audioTracks;
......
/*
* 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> MediaStreamTrackEvent::create()
{
return adoptRef(new MediaStreamTrackEvent);
}
PassRefPtr<MediaStreamTrackEvent> MediaStreamTrackEvent::create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<MediaStreamTrack> track)
{
return adoptRef(new MediaStreamTrackEvent(type, canBubble, cancelable, track));
}
MediaStreamTrackEvent::MediaStreamTrackEvent()
{
}
MediaStreamTrackEvent::MediaStreamTrackEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<MediaStreamTrack> 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)
/*
* 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 <wtf/text/AtomicString.h>
namespace WebCore {
class MediaStreamTrack;
class MediaStreamTrackEvent : public Event {
public:
virtual ~MediaStreamTrackEvent();
static PassRefPtr<MediaStreamTrackEvent> create();
static PassRefPtr<MediaStreamTrackEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<MediaStreamTrack>);
MediaStreamTrack* track() const;
// Event
virtual const AtomicString& interfaceName() const OVERRIDE;
private:
MediaStreamTrackEvent();
MediaStreamTrackEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<MediaStreamTrack>);
RefPtr<MediaStreamTrack> m_track;
};
} // namespace WebCore
#endif // ENABLE(MEDIA_STREAM)
#endif // MediaStreamTrackEvent_h
/*
* 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;
};
}
......@@ -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> MediaStreamTrackList::create(const MediaStreamTrackVector& trackVector)
PassRefPtr<MediaStreamTrackList> MediaStreamTrackList::create(MediaStream* owner, const MediaStreamTrackVector& trackVector)
{
return adoptRef(new MediaStreamTrackList(trackVector));
ASSERT(owner);
RefPtr<MediaStreamTrackList> 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<MediaStreamTrack> prpTrack, ExceptionCode& ec)
{
if (!m_owner || m_owner->readyState() == MediaStream::ENDED) {
ec = INVALID_STATE_ERR;
return;
}
RefPtr<MediaStreamTrack> 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<MediaStreamTrack> prpTrack, ExceptionCode& ec)
{
if (!m_owner || m_owner->readyState() == MediaStream::ENDED) {
ec = INVALID_STATE_ERR;
return;
}
RefPtr<MediaStreamTrack> 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;