[MediaStream] Cleanup platform interface

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

Reviewed by Jer Noble.

No new tests, tests will be updated in the next patch.

* CMakeLists.txt: Remove MediaStreamComponent.cpp.
* GNUmakefile.list.am: Remove MediaStreamComponent.h|cpp and MediaStreamSourcesQueryClient.h. 
    Add MediaStreamConstraintsValidationClient.h and MediaStreamCreationClient.h.

* Modules/mediastream/MediaStream.cpp:
(WebCore::processTrack): Duplicate MediaStreamSource when necessary to work around bug 121954.
(WebCore::createFromSourceVectors): MediaStreamCenter::instance -> MediaStream::sharedStreamCenter.
(WebCore::MediaStream::MediaStream): *Components -> *Streams.
(WebCore::MediaStream::setEnded): New.
(WebCore::MediaStream::stop):  MediaStreamCenter::instance -> MediaStream::sharedStreamCenter.
(WebCore::MediaStream::addTrack): Append the track parameter rather than duplicating it, as per spec.
(WebCore::MediaStream::removeTrack): *Components -> *Streams.
(WebCore::MediaStream::trackDidEnd): Renamed from trackEnded.
(WebCore::MediaStream::streamDidEnd): Renamed from streamEnded.
(WebCore::MediaStream::addRemoteSource): Renamed from addRemoteTrack. *Components -> *Streams.
(WebCore::MediaStream::removeRemoteSource): Renamed from removeRemoteTrack. *Components -> *Streams.
* Modules/mediastream/MediaStream.h:

* Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::create): *Component -> *Stream.
(WebCore::MediaStreamTrack::MediaStreamTrack): Don't assume source is valid.
(WebCore::MediaStreamTrack::~MediaStreamTrack): Ditto.
(WebCore::MediaStreamTrack::kind): Ditto. AtomicString -> const AtomicString&.
(WebCore::MediaStreamTrack::setSource): Moved from .h file.
(WebCore::MediaStreamTrack::id): Don't assume source is valid. Create ID when the source doesn't have one.
(WebCore::MediaStreamTrack::label): Don't assume source is valid.
(WebCore::MediaStreamTrack::enabled): 
(WebCore::MediaStreamTrack::setEnabled): *Component -> *Stream. MediaStreamCenter::instance -> MediaStreamCenter::shared.
(WebCore::MediaStreamTrack::readyState): "muted" is not a readyState, but "new" is.
(WebCore::MediaStreamTrack::getSources): MediaStreamCenter::instance -> MediaStreamCenter::shared.
(WebCore::MediaStreamTrack::ended): *Component -> *Stream.
(WebCore::MediaStreamTrack::sourceChangedState): Dispatch "started" and "unmuted" events.
(WebCore::MediaStreamTrack::trackDidEnd): Renamed from didEndTrack. m_component -> m_source.
* Modules/mediastream/MediaStreamTrack.h:

* Modules/mediastream/RTCDTMFSender.cpp:
(WebCore::RTCDTMFSender::create): track->component() -> track->source();

* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::didRemoveRemoteStream): Ditto.

* Modules/mediastream/RTCStatsRequestImpl.cpp:
(WebCore::RTCStatsRequestImpl::RTCStatsRequestImpl): Ditto.
(WebCore::RTCStatsRequestImpl::component): Removed, it was unused.
* Modules/mediastream/RTCStatsRequestImpl.h:

* Modules/mediastream/UserMediaClient.h:
* Modules/mediastream/UserMediaController.h:
(WebCore::UserMediaController::requestPermission): Renamed from requestUserMedia, get rid of source
    vector parameters.
(WebCore::UserMediaController::cancelRequest): Renamed from cancelUserMediaRequest.

* Modules/mediastream/UserMediaRequest.cpp:
(WebCore::parseOptions): MediaConstraintsImpl -> MediaConstraints.
(WebCore::UserMediaRequest::create): Ditto.
(WebCore::UserMediaRequest::UserMediaRequest): Ditto.
(WebCore::UserMediaRequest::securityOrigin): New.
(WebCore::UserMediaRequest::start): Request constraint validation.
(WebCore::UserMediaRequest::constraintsValidated): New. Callback from media engine when constraints
    can be supported.
(WebCore::UserMediaRequest::requestPermission): New. Ask user media client for permission to access media.
(WebCore::UserMediaRequest::userMediaAccessGranted): New. Access has been granted.
(WebCore::UserMediaRequest::createMediaStream): New. Allowed to access media, ask media engine
    to create stream sources.
(WebCore::UserMediaRequest::userMediaAccessDenied): New. User media client has denied access request.
(WebCore::UserMediaRequest::constraintsInvalid): New. Media engine can not support constraints.
(WebCore::UserMediaRequest::didCreateStream): New. Media engine has created stream sources.
(WebCore::UserMediaRequest::callSuccessHandler): New. Create stream from sources and call success handler.
(WebCore::UserMediaRequest::failedToCreateStreamWithConstraintsError): Renamed from constraintFailure.
(WebCore::UserMediaRequest::failedToCreateStreamWithPermissionError): Renamed from permissionFailure.
(WebCore::UserMediaRequest::callErrorHandler): 
(WebCore::UserMediaRequest::contextDestroyed): cancelUserMediaRequest -> cancelRequest.
* Modules/mediastream/UserMediaRequest.h:

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::createMediaStreamSource): localAudio->component()->source() -> localAudio->source().

* Modules/webaudio/MediaStreamAudioDestinationNode.cpp:
(WebCore::MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode): MediaStreamSource::TypeAudio ->
    MediaStreamSource::Audio, MediaStreamSource::ReadyStateLive -> MediaStreamSource::Live.
    MediaStreamCenter::instance -> MediaStreamCenter::shared.

* WebCore.exp.in: Export new symbols.

* WebCore.xcodeproj/project.pbxproj: Add new files and remove deleted files.

* dom/EventNames.h: Define "started" event.

* platform/mediastream/MediaStreamCenter.cpp:
(WebCore::mediaStreamCenterOverride): Make it possible to override the shared stream center. Will
    be used for testing in a later patch.
(WebCore::MediaStreamCenter::shared): Renamed from instance. Return current stream center.
(WebCore::MediaStreamCenter::setSharedStreamCenter): Override current stream center.
(WebCore::MediaStreamCenter::endLocalMediaStream): Never call the descriptor client, always call
    the descriptor and let it deal with the client.
* platform/mediastream/MediaStreamCenter.h:

* platform/mediastream/MediaStreamComponent.cpp: Removed.
* platform/mediastream/MediaStreamComponent.h: Removed.

* platform/mediastream/MediaStreamConstraintsValidationClient.h: Added.
* platform/mediastream/MediaStreamCreationClient.h: Added.

* platform/mediastream/MediaStreamDescriptor.cpp:
(WebCore::MediaStreamDescriptor::addSource): *Component -> *Source.
(WebCore::MediaStreamDescriptor::removeSource): Ditto.
(WebCore::MediaStreamDescriptor::addRemoteSource): Ditto.
(WebCore::MediaStreamDescriptor::removeRemoteSource): Ditto.
(WebCore::MediaStreamDescriptor::MediaStreamDescriptor): Ditto.
(WebCore::MediaStreamDescriptor::setEnded): Ditto. Set source readyStates to Ended.
* platform/mediastream/MediaStreamDescriptor.h:

* platform/mediastream/MediaStreamSource.cpp:
(WebCore::MediaStreamSource::MediaStreamSource): Initialize new member variables.
(WebCore::MediaStreamSource::setReadyState): Early return when the state hasn't changed.
(WebCore::MediaStreamSource::setStream): New.
(WebCore::MediaStreamSource::setMuted): New.
* platform/mediastream/MediaStreamSource.h:

* platform/mediastream/MediaStreamSourcesQueryClient.h: Removed.

* platform/mediastream/RTCPeerConnectionHandler.h:
* platform/mediastream/RTCStatsRequest.h:

* platform/mediastream/blackberry/MediaStreamCenterBlackBerry.cpp: Update for new MediaStreamCenter API.
* platform/mediastream/blackberry/MediaStreamCenterBlackBerry.h:

* platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp: Ditto.
* platform/mediastream/gstreamer/MediaStreamCenterGStreamer.h:

* platform/mediastream/mac/MediaStreamCenterMac.cpp: Ditto.
* platform/mediastream/mac/MediaStreamCenterMac.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156473 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 017ef58c
......@@ -2025,7 +2025,6 @@ set(WebCore_SOURCES
platform/leveldb/LevelDBWriteBatch.cpp
platform/mediastream/MediaStreamCenter.cpp
platform/mediastream/MediaStreamComponent.cpp
platform/mediastream/MediaStreamDescriptor.cpp
platform/mediastream/MediaStreamSource.cpp
platform/mediastream/RTCIceCandidateDescriptor.cpp
......
This diff is collapsed.
......@@ -5454,13 +5454,12 @@ webcore_platform_sources += \
Source/WebCore/platform/mediastream/MediaConstraints.h \
Source/WebCore/platform/mediastream/MediaStreamCenter.cpp \
Source/WebCore/platform/mediastream/MediaStreamCenter.h \
Source/WebCore/platform/mediastream/MediaStreamComponent.cpp \
Source/WebCore/platform/mediastream/MediaStreamComponent.h \
Source/WebCore/platform/mediastream/MediaStreamConstraintsValidationClient.h \
Source/WebCore/platform/mediastream/MediaStreamCreationClient.h \
Source/WebCore/platform/mediastream/MediaStreamDescriptor.cpp \
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/MediaStreamTrackSourcesRequestClient.h \
Source/WebCore/platform/mediastream/RTCConfiguration.h \
Source/WebCore/platform/mediastream/RTCDTMFSenderHandler.h \
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011, 2012 Ericsson AB. All rights reserved.
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -34,6 +35,7 @@
#include "MediaStreamRegistry.h"
#include "MediaStreamSource.h"
#include "MediaStreamTrackEvent.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
......@@ -51,15 +53,22 @@ static void processTrack(MediaStreamTrack* track, MediaStreamSourceVector& sourc
if (track->ended())
return;
MediaStreamSource* source = track->component()->source();
if (!containsSource(sourceVector, source))
sourceVector.append(source);
MediaStreamSource* source = track->source();
if (!containsSource(sourceVector, source)) {
if (source->stream()) {
// FIXME: this should not be necessary because tracks and streams must be able to share sources, but our code
// currenlty assumes each source is attached to just one track.
// https://bugs.webkit.org/show_bug.cgi?id=121954
sourceVector.append(MediaStreamSource::create(source->id(), source->type(), source->name(), source->readyState(), source->requiresAudioConsumer()).get());
} else
sourceVector.append(source);
}
}
static PassRefPtr<MediaStream> createFromSourceVectors(ScriptExecutionContext* context, const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources)
{
RefPtr<MediaStreamDescriptor> descriptor = MediaStreamDescriptor::create(audioSources, videoSources);
MediaStreamCenter::instance().didCreateMediaStream(descriptor.get());
MediaStreamCenter::shared().didCreateMediaStream(descriptor.get());
return MediaStream::create(context, descriptor.release());
}
......@@ -112,15 +121,15 @@ MediaStream::MediaStream(ScriptExecutionContext* context, PassRefPtr<MediaStream
{
m_descriptor->setClient(this);
size_t numberOfAudioTracks = m_descriptor->numberOfAudioComponents();
size_t numberOfAudioTracks = m_descriptor->numberOfAudioStreams();
m_audioTracks.reserveCapacity(numberOfAudioTracks);
for (size_t i = 0; i < numberOfAudioTracks; i++)
m_audioTracks.append(MediaStreamTrack::create(context, m_descriptor->audioComponent(i)));
m_audioTracks.append(MediaStreamTrack::create(context, m_descriptor->audioStreams(i)));
size_t numberOfVideoTracks = m_descriptor->numberOfVideoComponents();
size_t numberOfVideoTracks = m_descriptor->numberOfVideoStreams();
m_videoTracks.reserveCapacity(numberOfVideoTracks);
for (size_t i = 0; i < numberOfVideoTracks; i++)
m_videoTracks.append(MediaStreamTrack::create(context, m_descriptor->videoComponent(i)));
m_videoTracks.append(MediaStreamTrack::create(context, m_descriptor->videoStreams(i)));
}
MediaStream::~MediaStream()
......@@ -133,13 +142,20 @@ bool MediaStream::ended() const
return m_stopped || m_descriptor->ended();
}
void MediaStream::setEnded()
{
if (ended())
return;
m_descriptor->setEnded();
}
void MediaStream::stop()
{
if (ended())
return;
MediaStreamCenter::instance().didStopLocalMediaStream(descriptor());
streamEnded();
MediaStreamCenter::shared().didStopLocalMediaStream(descriptor());
setEnded();
}
void MediaStream::addTrack(PassRefPtr<MediaStreamTrack> prpTrack, ExceptionCode& ec)
......@@ -155,24 +171,19 @@ void MediaStream::addTrack(PassRefPtr<MediaStreamTrack> prpTrack, ExceptionCode&
}
RefPtr<MediaStreamTrack> track = prpTrack;
if (getTrackById(track->id()))
return;
RefPtr<MediaStreamComponent> component = MediaStreamComponent::create(m_descriptor.get(), track->component()->source());
RefPtr<MediaStreamTrack> newTrack = MediaStreamTrack::create(scriptExecutionContext(), component.get());
switch (component->source()->type()) {
case MediaStreamSource::TypeAudio:
m_audioTracks.append(newTrack);
switch (track->source()->type()) {
case MediaStreamSource::Audio:
m_audioTracks.append(track);
break;
case MediaStreamSource::TypeVideo:
m_videoTracks.append(newTrack);
case MediaStreamSource::Video:
m_videoTracks.append(track);
break;
}
m_descriptor->addComponent(component.release());
MediaStreamCenter::instance().didAddMediaStreamTrack(m_descriptor.get(), newTrack->component());
MediaStreamCenter::shared().didAddMediaStreamTrack(track->source());
}
void MediaStream::removeTrack(PassRefPtr<MediaStreamTrack> prpTrack, ExceptionCode& ec)
......@@ -190,13 +201,13 @@ void MediaStream::removeTrack(PassRefPtr<MediaStreamTrack> prpTrack, ExceptionCo
RefPtr<MediaStreamTrack> track = prpTrack;
size_t pos = notFound;
switch (track->component()->source()->type()) {
case MediaStreamSource::TypeAudio:
switch (track->source()->type()) {
case MediaStreamSource::Audio:
pos = m_audioTracks.find(track);
if (pos != notFound)
m_audioTracks.remove(pos);
break;
case MediaStreamSource::TypeVideo:
case MediaStreamSource::Video:
pos = m_videoTracks.find(track);
if (pos != notFound)
m_videoTracks.remove(pos);
......@@ -206,12 +217,12 @@ void MediaStream::removeTrack(PassRefPtr<MediaStreamTrack> prpTrack, ExceptionCo
if (pos == notFound)
return;
m_descriptor->removeComponent(track->component());
m_descriptor->removeSource(track->source());
if (!m_audioTracks.size() && !m_videoTracks.size())
m_descriptor->setEnded();
setEnded();
MediaStreamCenter::instance().didRemoveMediaStreamTrack(m_descriptor.get(), track->component());
MediaStreamCenter::shared().didRemoveMediaStreamTrack(track->source());
}
MediaStreamTrack* MediaStream::getTrackById(String id)
......@@ -229,7 +240,7 @@ MediaStreamTrack* MediaStream::getTrackById(String id)
return 0;
}
void MediaStream::trackEnded()
void MediaStream::trackDidEnd()
{
for (size_t i = 0; i < m_audioTracks.size(); ++i)
if (!m_audioTracks[i]->ended())
......@@ -239,15 +250,14 @@ void MediaStream::trackEnded()
if (!m_videoTracks[i]->ended())
return;
streamEnded();
setEnded();
}
void MediaStream::streamEnded()
void MediaStream::streamDidEnd()
{
if (ended())
return;
m_descriptor->setEnded();
scheduleDispatchEvent(Event::create(eventNames().endedEvent, false, false));
}
......@@ -257,46 +267,46 @@ void MediaStream::contextDestroyed()
m_stopped = true;
}
void MediaStream::addRemoteTrack(MediaStreamComponent* component)
void MediaStream::addRemoteSource(MediaStreamSource* source)
{
ASSERT(component && !component->stream());
ASSERT(source);
if (ended())
return;
component->setStream(descriptor());
source->setStream(descriptor());
RefPtr<MediaStreamTrack> track = MediaStreamTrack::create(scriptExecutionContext(), component);
switch (component->source()->type()) {
case MediaStreamSource::TypeAudio:
RefPtr<MediaStreamTrack> track = MediaStreamTrack::create(scriptExecutionContext(), source);
switch (source->type()) {
case MediaStreamSource::Audio:
m_audioTracks.append(track);
break;
case MediaStreamSource::TypeVideo:
case MediaStreamSource::Video:
m_videoTracks.append(track);
break;
}
m_descriptor->addComponent(component);
m_descriptor->addSource(source);
scheduleDispatchEvent(MediaStreamTrackEvent::create(eventNames().addtrackEvent, false, false, track));
}
void MediaStream::removeRemoteTrack(MediaStreamComponent* component)
void MediaStream::removeRemoteSource(MediaStreamSource* source)
{
if (ended())
return;
MediaStreamTrackVector* tracks = 0;
switch (component->source()->type()) {
case MediaStreamSource::TypeAudio:
switch (source->type()) {
case MediaStreamSource::Audio:
tracks = &m_audioTracks;
break;
case MediaStreamSource::TypeVideo:
case MediaStreamSource::Video:
tracks = &m_videoTracks;
break;
}
size_t index = notFound;
for (size_t i = 0; i < tracks->size(); ++i) {
if ((*tracks)[i]->component() == component) {
if ((*tracks)[i]->source() == source) {
index = i;
break;
}
......@@ -304,7 +314,7 @@ void MediaStream::removeRemoteTrack(MediaStreamComponent* component)
if (index == notFound)
return;
m_descriptor->removeComponent(component);
m_descriptor->removeSource(source);
RefPtr<MediaStreamTrack> track = (*tracks)[index];
tracks->remove(index);
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -41,6 +42,8 @@
namespace WebCore {
class MediaStreamCenter;
// FIXME: This class should be marked FINAL once <http://webkit.org/b/121747> is fixed.
class MediaStream : public RefCounted<MediaStream>, public URLRegistrable, public ScriptWrappable, public MediaStreamDescriptorClient, public EventTargetWithInlineData, public ContextDestructionObserver {
public:
......@@ -60,16 +63,13 @@ public:
MediaStreamTrackVector getVideoTracks() const { return m_videoTracks; }
bool ended() const;
void setEnded();
void stop();
DEFINE_ATTRIBUTE_EVENT_LISTENER(ended);
DEFINE_ATTRIBUTE_EVENT_LISTENER(addtrack);
DEFINE_ATTRIBUTE_EVENT_LISTENER(removetrack);
// MediaStreamDescriptorClient
virtual void trackEnded() OVERRIDE;
virtual void streamEnded() OVERRIDE;
MediaStreamDescriptor* descriptor() const { return m_descriptor.get(); }
// EventTarget
......@@ -89,25 +89,29 @@ protected:
virtual void contextDestroyed();
private:
// MediaStreamDescriptorClient
virtual void trackDidEnd() OVERRIDE;
virtual void streamDidEnd() OVERRIDE;
// EventTarget
virtual void refEventTarget() OVERRIDE FINAL { ref(); }
virtual void derefEventTarget() OVERRIDE FINAL { deref(); }
// MediaStreamDescriptorClient
virtual void addRemoteTrack(MediaStreamComponent*) OVERRIDE;
virtual void removeRemoteTrack(MediaStreamComponent*) OVERRIDE;
virtual void addRemoteSource(MediaStreamSource*) OVERRIDE;
virtual void removeRemoteSource(MediaStreamSource*) OVERRIDE;
void scheduleDispatchEvent(PassRefPtr<Event>);
void scheduledEventTimerFired(Timer<MediaStream>*);
bool m_stopped;
RefPtr<MediaStreamDescriptor> m_descriptor;
MediaStreamTrackVector m_audioTracks;
MediaStreamTrackVector m_videoTracks;
RefPtr<MediaStreamDescriptor> m_descriptor;
Timer<MediaStream> m_scheduledEventTimer;
Vector<RefPtr<Event> > m_scheduledEvents;
Vector<RefPtr<Event>> m_scheduledEvents;
};
typedef Vector<RefPtr<MediaStream> > MediaStreamVector;
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -28,45 +29,64 @@
#if ENABLE(MEDIA_STREAM)
#include "Dictionary.h"
#include "Event.h"
#include "ExceptionCode.h"
#include "MediaStream.h"
#include "MediaStreamCenter.h"
#include "MediaStreamComponent.h"
#include "MediaStreamDescriptor.h"
#include "MediaStreamTrackSourcesCallback.h"
#include "MediaStreamTrackSourcesRequest.h"
#include "UUID.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
PassRefPtr<MediaStreamTrack> MediaStreamTrack::create(ScriptExecutionContext* context, MediaStreamComponent* component)
PassRefPtr<MediaStreamTrack> MediaStreamTrack::create(ScriptExecutionContext* context, const Dictionary& videoConstraints)
{
RefPtr<MediaStreamTrack> track = adoptRef(new MediaStreamTrack(context, component));
track->suspendIfNeeded();
RefPtr<MediaStreamTrack> track = adoptRef(new MediaStreamTrack(context, 0, &videoConstraints));
return track.release();
}
MediaStreamTrack::MediaStreamTrack(ScriptExecutionContext* context, MediaStreamComponent* component)
PassRefPtr<MediaStreamTrack> MediaStreamTrack::create(ScriptExecutionContext* context, MediaStreamSource* source)
{
RefPtr<MediaStreamTrack> track = adoptRef(new MediaStreamTrack(context, source, 0));
return track.release();
}
MediaStreamTrack::MediaStreamTrack(ScriptExecutionContext* context, MediaStreamSource* source, const Dictionary*)
: ActiveDOMObject(context)
, m_component(component)
, m_source(source)
, m_readyState(MediaStreamSource::New)
, m_stopped(false)
, m_enabled(true)
, m_muted(false)
{
m_component->source()->addObserver(this);
suspendIfNeeded();
if (m_source) {
m_source->addObserver(this);
m_muted = m_source->muted();
}
}
MediaStreamTrack::~MediaStreamTrack()
{
m_component->source()->removeObserver(this);
if (m_source)
m_source->removeObserver(this);
}
AtomicString MediaStreamTrack::kind() const
const AtomicString& MediaStreamTrack::kind() const
{
if (!m_source)
return emptyAtom;
static NeverDestroyed<AtomicString> audioKind("audio", AtomicString::ConstructFromLiteral);
static NeverDestroyed<AtomicString> videoKind("video", AtomicString::ConstructFromLiteral);
switch (m_component->source()->type()) {
case MediaStreamSource::TypeAudio:
switch (m_source->type()) {
case MediaStreamSource::Audio:
return audioKind;
case MediaStreamSource::TypeVideo:
case MediaStreamSource::Video:
return videoKind;
}
......@@ -74,49 +94,81 @@ AtomicString MediaStreamTrack::kind() const
return emptyAtom;
}
String MediaStreamTrack::id() const
void MediaStreamTrack::setSource(MediaStreamSource* source)
{
return m_component->id();
ASSERT(source == m_source || !m_source);
m_source = source;
}
String MediaStreamTrack::label() const
const String& MediaStreamTrack::id() const
{
return m_component->source()->name();
if (!m_id.isEmpty())
return m_id;
if (!m_source)
return emptyString();
const String& id = m_source->id();
if (!id.isEmpty())
return id;
// The spec says:
// Unless a MediaStreamTrack object is created as a part a of special purpose algorithm that
// specifies how the track id must be initialized, the user agent must generate a globally
// unique identifier string and initialize the object's id attribute to that string.
// so generate a UUID if the source doesn't have an ID.
m_id = createCanonicalUUIDString();
return m_id;
}
const String& MediaStreamTrack::label() const
{
if (m_source)
return m_source->name();
return emptyString();
}
bool MediaStreamTrack::enabled() const
{
return m_component->enabled();
return m_enabled;
}
void MediaStreamTrack::setEnabled(bool enabled)
{
if (m_stopped || enabled == m_component->enabled())
if (m_stopped)
return;
m_enabled = enabled;
if (!m_source || enabled == m_source->enabled())
return;
m_component->setEnabled(enabled);
m_source->setEnabled(enabled);
if (m_component->stream()->ended())
if (m_source->stream()->ended())
return;
MediaStreamCenter::instance().didSetMediaStreamTrackEnabled(m_component->stream(), m_component.get());
MediaStreamCenter::shared().didSetMediaStreamTrackEnabled(m_source.get());
}
AtomicString MediaStreamTrack::readyState() const
const AtomicString& MediaStreamTrack::readyState() const
{
static NeverDestroyed<AtomicString> ended("ended", AtomicString::ConstructFromLiteral);
static NeverDestroyed<AtomicString> live("live", AtomicString::ConstructFromLiteral);
static NeverDestroyed<AtomicString> muted("muted", AtomicString::ConstructFromLiteral);
static NeverDestroyed<AtomicString> newState("new", AtomicString::ConstructFromLiteral);
if (!m_source)
return newState;
if (m_stopped)
return ended;
switch (m_component->source()->readyState()) {
case MediaStreamSource::ReadyStateLive:
switch (m_source->readyState()) {
case MediaStreamSource::Live:
return live;
case MediaStreamSource::ReadyStateMuted:
return muted;
case MediaStreamSource::ReadyStateEnded:
case MediaStreamSource::New:
return newState;
case MediaStreamSource::Ended:
return ended;
}
......@@ -127,13 +179,13 @@ AtomicString MediaStreamTrack::readyState() const
void MediaStreamTrack::getSources(ScriptExecutionContext* context, PassRefPtr<MediaStreamTrackSourcesCallback> callback, ExceptionCode& ec)
{
RefPtr<MediaStreamTrackSourcesRequest> request = MediaStreamTrackSourcesRequest::create(context, callback);
if (!MediaStreamCenter::instance().getMediaStreamTrackSources(request.release()))
if (!MediaStreamCenter::shared().getMediaStreamTrackSources(request.release()))
ec = NOT_SUPPORTED_ERR;
}
bool MediaStreamTrack::ended() const
{
return m_stopped || (m_component->source()->readyState() == MediaStreamSource::ReadyStateEnded);
return m_stopped || (m_source && m_source->readyState() == MediaStreamSource::Ended);
}
void MediaStreamTrack::sourceChangedState()
......@@ -141,32 +193,32 @@ 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:
MediaStreamSource::ReadyState oldReadyState = m_readyState;
m_readyState = m_source->readyState();
if (m_readyState >= MediaStreamSource::Live && oldReadyState == MediaStreamSource::New)
dispatchEvent(Event::create(eventNames().startedEvent, false, false));
if (m_readyState == MediaStreamSource::Ended && oldReadyState != MediaStreamSource::Ended)
dispatchEvent(Event::create(eventNames().endedEvent, false, false));
didEndTrack();
break;
}
if (m_muted == m_source->muted())
return;
m_muted = m_source->muted();
if (m_muted)
dispatchEvent(Event::create(eventNames().muteEvent, false, false));
else
dispatchEvent(Event::create(eventNames().unmuteEvent, false, false));
}
void MediaStreamTrack::didEndTrack()
void MediaStreamTrack::trackDidEnd()
{
MediaStreamDescriptorClient* client = m_component->stream()->client();
// FIXME: this is wrong, the track shouldn't have to call the descriptor's client!
MediaStreamDescriptorClient* client = m_source ? m_source->stream()->client() : 0;
if (!client)
return;
client->trackEnded();
}
MediaStreamComponent* MediaStreamTrack::component()
{
return m_component.get();
client->trackDidEnd();
}
void MediaStreamTrack::stop()
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
* Copyright (C) 2011 Ericsson AB. All rights reserved.
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -30,7 +31,6 @@
#include "ActiveDOMObject.h"
#include "EventTarget.h"
#include "MediaStreamDescriptor.h"
#include "MediaStreamSource.h"
#include "ScriptWrappable.h"
#include <wtf/RefCounted.h>
......@@ -40,33 +40,37 @@
namespace WebCore {
class MediaStreamComponent;
class Dictionary;
class MediaConstraints;
class MediaStreamTrackSourcesCallback;
// FIXME: This class should be marked FINAL once <http://webkit.org/b/121747> is fixed.
class MediaStreamTrack : public RefCounted<MediaStreamTrack>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithInlineData, public MediaStreamSource::Observer {
public:
static PassRefPtr<MediaStreamTrack> create(ScriptExecutionContext*, MediaStreamComponent*);
static PassRefPtr<MediaStreamTrack> create(ScriptExecutionContext*, const Dictionary&);
static PassRefPtr<MediaStreamTrack> create(ScriptExecutionContext*, MediaStreamSource*);
virtual ~MediaStreamTrack();
AtomicString kind() const;
String id() const;
String label() const;
const AtomicString& kind() const;
const String& id() const;
const String& label() const;
bool enabled() const;
void setEnabled(bool);
void didEndTrack();
AtomicString readyState() const;
const AtomicString& readyState() const;
static void getSources(ScriptExecutionContext*, PassRefPtr<MediaStreamTrackSourcesCallback>, ExceptionCode&);
MediaStreamSource* source() const { return m_source.get(); }
void setSource(MediaStreamSource*);