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

MediaStream API: Update MediaStreamTrack to match the specification

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

Reviewed by Adam Barth.

Source/Platform:

* chromium/public/WebMediaStreamDescriptor.h:
(WebMediaStreamDescriptor):
* chromium/public/WebMediaStreamSource.h:
(WebMediaStreamSource):

Source/WebCore:

MediaStreamTracks are now required to show the status of the underlying source,
and trigger events when that status changes.

Test: fast/mediastream/MediaStreamTrack.html

* GNUmakefile.list.am:
* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::MediaStream):
(WebCore::MediaStream::addTrack):
* Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::create):
(WebCore::MediaStreamTrack::MediaStreamTrack):
(WebCore::MediaStreamTrack::~MediaStreamTrack):
(WebCore::MediaStreamTrack::setEnabled):
(WebCore::MediaStreamTrack::readyState):
(WebCore):
(WebCore::MediaStreamTrack::sourceChangedState):
(WebCore::MediaStreamTrack::stop):
(WebCore::MediaStreamTrack::interfaceName):
(WebCore::MediaStreamTrack::scriptExecutionContext):
(WebCore::MediaStreamTrack::eventTargetData):
(WebCore::MediaStreamTrack::ensureEventTargetData):
* Modules/mediastream/MediaStreamTrack.h:
* Modules/mediastream/MediaStreamTrack.idl:
* WebCore.gypi:
* dom/EventNames.h:
(WebCore):
* dom/EventTargetFactory.in:
* platform/chromium/support/WebMediaStreamDescriptor.cpp:
* platform/chromium/support/WebMediaStreamSource.cpp:
(WebKit::WebMediaStreamSource::setReadyState):
(WebKit):
(WebKit::WebMediaStreamSource::readyState):
* platform/mediastream/MediaStreamSource.cpp: Copied from Source/WebCore/platform/mediastream/MediaStreamSource.h.
(WebCore):
(WebCore::MediaStreamSource::create):
(WebCore::MediaStreamSource::MediaStreamSource):
(WebCore::MediaStreamSource::setReadyState):
(WebCore::MediaStreamSource::addObserver):
(WebCore::MediaStreamSource::removeObserver):
* platform/mediastream/MediaStreamSource.h:
(Observer):
(WebCore::MediaStreamSource::Observer::~Observer):
(MediaStreamSource):
(WebCore::MediaStreamSource::readyState):
* platform/mediastream/chromium/MediaStreamCenterChromium.cpp:
(WebCore::MediaStreamCenterChromium::queryMediaStreamSources):
(WebCore::MediaStreamCenterChromium::didCreateMediaStream):

Tools:

Adding a Mock WebMediaStreamCenter to enable better LayoutTests.

* DumpRenderTree/DumpRenderTree.gypi:
* DumpRenderTree/chromium/MockWebKitPlatformSupport.cpp:
(MockWebKitPlatformSupport::createMediaStreamCenter):
* DumpRenderTree/chromium/MockWebMediaStreamCenter.cpp: Added.
(WebKit):
(WebKit::MockWebMediaStreamCenter::MockWebMediaStreamCenter):
(WebKit::MockWebMediaStreamCenter::queryMediaStreamSources):
(WebKit::MockWebMediaStreamCenter::didEnableMediaStreamTrack):
(WebKit::MockWebMediaStreamCenter::didDisableMediaStreamTrack):
(WebKit::MockWebMediaStreamCenter::didStopLocalMediaStream):
(WebKit::MockWebMediaStreamCenter::didCreateMediaStream):
(WebKit::MockWebMediaStreamCenter::constructSDP):
* DumpRenderTree/chromium/MockWebMediaStreamCenter.h: Copied from Tools/DumpRenderTree/chromium/MockWebKitPlatformSupport.cpp.
(WebKit):
(MockWebMediaStreamCenter):
(WebKit::MockWebMediaStreamCenter::MockWebMediaStreamCenter):

LayoutTests:

* fast/mediastream/MediaStreamTrack-expected.txt: Added.
* fast/mediastream/MediaStreamTrack.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@123627 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 94168608
2012-07-25 Tommy Widenflycht <tommyw@google.com>
MediaStream API: Update MediaStreamTrack to match the specification
https://bugs.webkit.org/show_bug.cgi?id=90180
Reviewed by Adam Barth.
* fast/mediastream/MediaStreamTrack-expected.txt: Added.
* fast/mediastream/MediaStreamTrack.html: Added.
2012-07-25 Allan Sandfeld Jensen <allan.jensen@nokia.com>
NodesFromRect and area-based hit-testing can not handle CSS transforms.
Tests MediaStreamTrack callbacks.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS getUserMedia succeeded.
PASS Track onmute callback succeeded.
PASS Track onunmute callback succeeded.
PASS Track onended callback succeeded.
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 MediaStreamTrack callbacks.");
// Note that the below behaviour doesn't reflect how it works outside of LayoutTests.
// The underlying mock is modified to trigger the events when certain functions are called.
// This modified behaviour allows us to test the MediaStreamTrack class properly.
var stream;
var track;
function error() {
testFailed('Stream generation failed.');
finishJSTest();
}
function getUserMedia(constraints, callback) {
try {
navigator.webkitGetUserMedia(constraints, callback, error);
} catch (e) {
testFailed('webkitGetUserMedia threw exception :' + e);
finishJSTest();
}
}
function onTrackEnded() {
testPassed('Track onended callback succeeded.');
finishJSTest();
}
function onTrackUnmute() {
testPassed('Track onunmute callback succeeded.');
stream.stop();
}
function onTrackMute() {
testPassed('Track onmute callback succeeded.');
track.enabled = true;
}
function gotStream(s) {
testPassed('getUserMedia succeeded.');
stream = s;
track = stream.videoTracks[0];
track.onunmute = onTrackUnmute;
track.onmute = onTrackMute;
track.onended = onTrackEnded;
track.enabled = false;
}
getUserMedia({audio:true, video:true}, gotStream);
window.jsTestIsAsync = true;
window.successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
2012-07-25 Tommy Widenflycht <tommyw@google.com>
MediaStream API: Update MediaStreamTrack to match the specification
https://bugs.webkit.org/show_bug.cgi?id=90180
Reviewed by Adam Barth.
* chromium/public/WebMediaStreamDescriptor.h:
(WebMediaStreamDescriptor):
* chromium/public/WebMediaStreamSource.h:
(WebMediaStreamSource):
2012-07-24 Dave Tu <dtu@chromium.org>
[chromium] Add time spent painting to GPU benchmarking renderingStats() API.
......
......@@ -68,9 +68,6 @@ public:
WEBKIT_EXPORT WebString label() const;
// DEPRECATED
WEBKIT_EXPORT void sources(WebVector<WebMediaStreamSource>&) const;
WEBKIT_EXPORT void audioSources(WebVector<WebMediaStreamComponent>&) const;
WEBKIT_EXPORT void videoSources(WebVector<WebMediaStreamComponent>&) const;
......
......@@ -50,6 +50,12 @@ public:
TypeVideo
};
enum ReadyState {
ReadyStateLive = 0,
ReadyStateMuted = 1,
ReadyStateEnded = 2
};
WebMediaStreamSource() { }
WebMediaStreamSource(const WebMediaStreamSource& other) { assign(other); }
~WebMediaStreamSource() { reset(); }
......@@ -70,6 +76,9 @@ public:
WEBKIT_EXPORT Type type() const;
WEBKIT_EXPORT WebString name() const;
WEBKIT_EXPORT void setReadyState(ReadyState);
WEBKIT_EXPORT ReadyState readyState() const;
#if WEBKIT_IMPLEMENTATION
WebMediaStreamSource(const WTF::PassRefPtr<WebCore::MediaStreamSource>&);
WebMediaStreamSource& operator=(WebCore::MediaStreamSource*);
......
2012-07-25 Tommy Widenflycht <tommyw@google.com>
MediaStream API: Update MediaStreamTrack to match the specification
https://bugs.webkit.org/show_bug.cgi?id=90180
Reviewed by Adam Barth.
MediaStreamTracks are now required to show the status of the underlying source,
and trigger events when that status changes.
Test: fast/mediastream/MediaStreamTrack.html
* GNUmakefile.list.am:
* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::MediaStream):
(WebCore::MediaStream::addTrack):
* Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::create):
(WebCore::MediaStreamTrack::MediaStreamTrack):
(WebCore::MediaStreamTrack::~MediaStreamTrack):
(WebCore::MediaStreamTrack::setEnabled):
(WebCore::MediaStreamTrack::readyState):
(WebCore):
(WebCore::MediaStreamTrack::sourceChangedState):
(WebCore::MediaStreamTrack::stop):
(WebCore::MediaStreamTrack::interfaceName):
(WebCore::MediaStreamTrack::scriptExecutionContext):
(WebCore::MediaStreamTrack::eventTargetData):
(WebCore::MediaStreamTrack::ensureEventTargetData):
* Modules/mediastream/MediaStreamTrack.h:
* Modules/mediastream/MediaStreamTrack.idl:
* WebCore.gypi:
* dom/EventNames.h:
(WebCore):
* dom/EventTargetFactory.in:
* platform/chromium/support/WebMediaStreamDescriptor.cpp:
* platform/chromium/support/WebMediaStreamSource.cpp:
(WebKit::WebMediaStreamSource::setReadyState):
(WebKit):
(WebKit::WebMediaStreamSource::readyState):
* platform/mediastream/MediaStreamSource.cpp: Copied from Source/WebCore/platform/mediastream/MediaStreamSource.h.
(WebCore):
(WebCore::MediaStreamSource::create):
(WebCore::MediaStreamSource::MediaStreamSource):
(WebCore::MediaStreamSource::setReadyState):
(WebCore::MediaStreamSource::addObserver):
(WebCore::MediaStreamSource::removeObserver):
* platform/mediastream/MediaStreamSource.h:
(Observer):
(WebCore::MediaStreamSource::Observer::~Observer):
(MediaStreamSource):
(WebCore::MediaStreamSource::readyState):
* platform/mediastream/chromium/MediaStreamCenterChromium.cpp:
(WebCore::MediaStreamCenterChromium::queryMediaStreamSources):
(WebCore::MediaStreamCenterChromium::didCreateMediaStream):
2012-07-25 Allan Sandfeld Jensen <allan.jensen@nokia.com>
Incorrect rounding in ceiledLayoutUnit and roundedLayoutUnit.
......@@ -3546,6 +3546,7 @@ webcore_sources += \
Source/WebCore/platform/mediastream/MediaStreamCenter.h \
Source/WebCore/platform/mediastream/MediaStreamComponent.h \
Source/WebCore/platform/mediastream/MediaStreamDescriptor.h \
Source/WebCore/platform/mediastream/MediaStreamSource.cpp \
Source/WebCore/platform/mediastream/MediaStreamSource.h \
Source/WebCore/platform/mediastream/MediaStreamSourcesQueryClient.h \
Source/WebCore/platform/mediastream/PeerConnection00Handler.cpp \
......
......@@ -94,14 +94,14 @@ MediaStream::MediaStream(ScriptExecutionContext* context, PassRefPtr<MediaStream
size_t numberOfAudioTracks = m_descriptor->numberOfAudioComponents();
audioTrackVector.reserveCapacity(numberOfAudioTracks);
for (size_t i = 0; i < numberOfAudioTracks; i++)
audioTrackVector.append(MediaStreamTrack::create(m_descriptor, m_descriptor->audioComponent(i)));
audioTrackVector.append(MediaStreamTrack::create(context, m_descriptor, m_descriptor->audioComponent(i)));
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)));
videoTrackVector.append(MediaStreamTrack::create(context, m_descriptor, m_descriptor->videoComponent(i)));
m_videoTracks = MediaStreamTrackList::create(this, videoTrackVector);
}
......@@ -151,7 +151,7 @@ EventTargetData* MediaStream::ensureEventTargetData()
void MediaStream::addTrack(MediaStreamComponent* component)
{
RefPtr<MediaStreamTrack> track = MediaStreamTrack::create(m_descriptor, component);
RefPtr<MediaStreamTrack> track = MediaStreamTrack::create(scriptExecutionContext(), m_descriptor, component);
ExceptionCode ec = 0;
switch (component->source()->type()) {
case MediaStreamSource::TypeAudio:
......
......@@ -28,24 +28,31 @@
#if ENABLE(MEDIA_STREAM)
#include "Event.h"
#include "MediaStreamCenter.h"
#include "MediaStreamComponent.h"
namespace WebCore {
PassRefPtr<MediaStreamTrack> MediaStreamTrack::create(PassRefPtr<MediaStreamDescriptor> streamDescriptor, MediaStreamComponent* component)
PassRefPtr<MediaStreamTrack> MediaStreamTrack::create(ScriptExecutionContext* context, PassRefPtr<MediaStreamDescriptor> streamDescriptor, MediaStreamComponent* component)
{
return adoptRef(new MediaStreamTrack(streamDescriptor, component));
RefPtr<MediaStreamTrack> track = adoptRef(new MediaStreamTrack(context, streamDescriptor, component));
track->suspendIfNeeded();
return track.release();
}
MediaStreamTrack::MediaStreamTrack(PassRefPtr<MediaStreamDescriptor> streamDescriptor, MediaStreamComponent* component)
: m_streamDescriptor(streamDescriptor)
MediaStreamTrack::MediaStreamTrack(ScriptExecutionContext* context, PassRefPtr<MediaStreamDescriptor> streamDescriptor, MediaStreamComponent* component)
: ActiveDOMObject(context, this)
, m_stopped(false)
, m_streamDescriptor(streamDescriptor)
, m_component(component)
{
m_component->source()->addObserver(this);
}
MediaStreamTrack::~MediaStreamTrack()
{
m_component->source()->removeObserver(this);
}
String MediaStreamTrack::kind() const
......@@ -76,7 +83,7 @@ bool MediaStreamTrack::enabled() const
void MediaStreamTrack::setEnabled(bool enabled)
{
if (enabled == m_component->enabled())
if (m_stopped || enabled == m_component->enabled())
return;
m_component->setEnabled(enabled);
......@@ -87,11 +94,72 @@ void MediaStreamTrack::setEnabled(bool enabled)
MediaStreamCenter::instance().didSetMediaStreamTrackEnabled(m_streamDescriptor.get(), m_component.get());
}
MediaStreamTrack::ReadyState MediaStreamTrack::readyState() const
{
if (m_stopped)
return ENDED;
switch (m_component->source()->readyState()) {
case MediaStreamSource::ReadyStateLive:
return LIVE;
case MediaStreamSource::ReadyStateMuted:
return MUTED;
case MediaStreamSource::ReadyStateEnded:
return ENDED;
}
ASSERT_NOT_REACHED();
return ENDED;
}
void MediaStreamTrack::sourceChangedState()
{
if (m_stopped)
return;
switch (m_component->source()->readyState()) {
case MediaStreamSource::ReadyStateLive:
dispatchEvent(Event::create(eventNames().unmuteEvent, false, false));
break;
case MediaStreamSource::ReadyStateMuted:
dispatchEvent(Event::create(eventNames().muteEvent, false, false));
break;
case MediaStreamSource::ReadyStateEnded:
dispatchEvent(Event::create(eventNames().endedEvent, false, false));
break;
}
}
MediaStreamComponent* MediaStreamTrack::component()
{
return m_component.get();
}
void MediaStreamTrack::stop()
{
m_stopped = true;
}
const AtomicString& MediaStreamTrack::interfaceName() const
{
return eventNames().interfaceForMediaStreamTrack;
}
ScriptExecutionContext* MediaStreamTrack::scriptExecutionContext() const
{
return ActiveDOMObject::scriptExecutionContext();
}
EventTargetData* MediaStreamTrack::eventTargetData()
{
return &m_eventTargetData;
}
EventTargetData* MediaStreamTrack::ensureEventTargetData()
{
return &m_eventTargetData;
}
} // namespace WebCore
#endif // ENABLE(MEDIA_STREAM)
......@@ -28,7 +28,10 @@
#if ENABLE(MEDIA_STREAM)
#include "ActiveDOMObject.h"
#include "EventTarget.h"
#include "MediaStreamDescriptor.h"
#include "MediaStreamSource.h"
#include "PlatformString.h"
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
......@@ -38,9 +41,15 @@ namespace WebCore {
class MediaStreamComponent;
class MediaStreamTrack : public RefCounted<MediaStreamTrack> {
class MediaStreamTrack : public RefCounted<MediaStreamTrack>, public ActiveDOMObject, public EventTarget, public MediaStreamSource::Observer {
public:
static PassRefPtr<MediaStreamTrack> create(PassRefPtr<MediaStreamDescriptor>, MediaStreamComponent*);
enum ReadyState {
LIVE = 0,
MUTED = 1,
ENDED = 2
};
static PassRefPtr<MediaStreamTrack> create(ScriptExecutionContext*, PassRefPtr<MediaStreamDescriptor>, MediaStreamComponent*);
virtual ~MediaStreamTrack();
String kind() const;
......@@ -49,11 +58,38 @@ public:
bool enabled() const;
void setEnabled(bool);
ReadyState readyState() const;
DEFINE_ATTRIBUTE_EVENT_LISTENER(mute);
DEFINE_ATTRIBUTE_EVENT_LISTENER(unmute);
DEFINE_ATTRIBUTE_EVENT_LISTENER(ended);
MediaStreamComponent* component();
// EventTarget
virtual const AtomicString& interfaceName() const OVERRIDE;
virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
// ActiveDOMObject
virtual void stop() OVERRIDE;
using RefCounted<MediaStreamTrack>::ref;
using RefCounted<MediaStreamTrack>::deref;
private:
MediaStreamTrack(PassRefPtr<MediaStreamDescriptor>, MediaStreamComponent*);
MediaStreamTrack(ScriptExecutionContext*, PassRefPtr<MediaStreamDescriptor>, MediaStreamComponent*);
// EventTarget
virtual EventTargetData* eventTargetData() OVERRIDE;
virtual EventTargetData* ensureEventTargetData() OVERRIDE;
virtual void refEventTarget() OVERRIDE { ref(); }
virtual void derefEventTarget() OVERRIDE { deref(); }
EventTargetData m_eventTargetData;
// MediaStreamSourceObserver
virtual void sourceChangedState() OVERRIDE;
bool m_stopped;
RefPtr<MediaStreamDescriptor> m_streamDescriptor;
RefPtr<MediaStreamComponent> m_component;
};
......
......@@ -26,10 +26,31 @@ module core {
interface [
Conditional=MEDIA_STREAM,
EventTarget,
ActiveDOMObject
] MediaStreamTrack {
readonly attribute DOMString kind;
readonly attribute DOMString label;
attribute boolean enabled;
const unsigned short LIVE = 0;
const unsigned short MUTED = 1;
const unsigned short ENDED = 2;
readonly attribute unsigned short readyState;
attribute EventListener onmute;
attribute EventListener onunmute;
attribute EventListener onended;
// 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);
};
}
......@@ -447,6 +447,7 @@
'platform/mediastream/MediaStreamCenter.h',
'platform/mediastream/MediaStreamComponent.h',
'platform/mediastream/MediaStreamDescriptor.h',
'platform/mediastream/MediaStreamSource.cpp',
'platform/mediastream/MediaStreamSource.h',
'platform/mediastream/PeerConnection00Handler.h',
'platform/mediastream/PeerConnection00HandlerClient.h',
......
......@@ -219,6 +219,8 @@ namespace WebCore {
macro(removestream) \
macro(statechange) \
macro(removetrack) \
macro(mute) \
macro(unmute) \
\
macro(show) \
\
......
......@@ -17,6 +17,7 @@ JavaScriptAudioNode conditional=WEB_AUDIO
LocalMediaStream conditional=MEDIA_STREAM
MediaController conditional=VIDEO
MediaStream conditional=MEDIA_STREAM
MediaStreamTrack conditional=MEDIA_STREAM
MediaStreamTrackList conditional=MEDIA_STREAM
MessagePort
NetworkInfoConnection conditional=NETWORK_INFO
......
......@@ -91,20 +91,6 @@ void WebMediaStreamDescriptor::setExtraData(ExtraData* extraData)
m_private->setExtraData(adoptRef(new ExtraDataContainer(extraData)));
}
// FIXME: Cleanup when the chromium code has switched to the split sources implementation.
void WebMediaStreamDescriptor::sources(WebVector<WebMediaStreamSource>& webSources) const
{
size_t numberOfAudioSources = m_private->numberOfAudioComponents();
size_t numberOfVideoSources = m_private->numberOfVideoComponents();
WebVector<WebMediaStreamSource> result(numberOfAudioSources + numberOfVideoSources);
size_t i = 0;
for (size_t j = 0; j < numberOfAudioSources; ++i, ++j)
result[i] = m_private->audioComponent(j)->source();
for (size_t j = 0; j < numberOfVideoSources; ++i, ++j)
result[i] = m_private->videoComponent(j)->source();
webSources.swap(result);
}
void WebMediaStreamDescriptor::audioSources(WebVector<WebMediaStreamComponent>& webSources) const
{
size_t numberOfSources = m_private->numberOfAudioComponents();
......
......@@ -96,6 +96,18 @@ WebString WebMediaStreamSource::name() const
return m_private.get()->name();
}
void WebMediaStreamSource::setReadyState(ReadyState state)
{
ASSERT(!m_private.isNull());
m_private->setReadyState(static_cast<MediaStreamSource::ReadyState>(state));
}
WebMediaStreamSource::ReadyState WebMediaStreamSource::readyState() const
{
ASSERT(!m_private.isNull());
return static_cast<ReadyState>(m_private->readyState());
}
} // namespace WebKit
#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.
* 3. Neither the name of Google Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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 "MediaStreamSource.h"
namespace WebCore {
PassRefPtr<MediaStreamSource> MediaStreamSource::create(const String& id, Type type, const String& name, ReadyState readyState)
{
return adoptRef(new MediaStreamSource(id, type, name, readyState));
}
MediaStreamSource::MediaStreamSource(const String& id, Type type, const String& name, ReadyState readyState)
: m_id(id)
, m_type(type)
, m_name(name)
, m_readyState(readyState)
{
}
void MediaStreamSource::setReadyState(ReadyState readyState)
{
ASSERT(m_readyState != ReadyStateEnded);
if (m_readyState != readyState) {
m_readyState = readyState;
for (Vector<Observer*>::iterator i = m_observers.begin(); i != m_observers.end(); ++i)
(*i)->sourceChangedState();
}
}
void MediaStreamSource::addObserver(MediaStreamSource::Observer* observer)
{
m_observers.append(observer);
}
void MediaStreamSource::removeObserver(MediaStreamSource::Observer* observer)
{
size_t pos = m_observers.find(observer);
if (pos != notFound)
m_observers.remove(pos);
}
} // namespace WebCore
#endif // ENABLE(MEDIA_STREAM)
......@@ -41,36 +41,43 @@ namespace WebCore {
class MediaStreamSource : public RefCounted<MediaStreamSource> {
public:
class Observer {
public:
virtual ~Observer() { }