Changeset 157733 in webkit


Ignore:
Timestamp:
Oct 21, 2013 2:14:37 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

MediaStreamTrack now tracks its own state
https://bugs.webkit.org/show_bug.cgi?id=123025

Patch by Thiago de Barros Lacerda <thiago.lacerda@openbossa.org> on 2013-10-21
Reviewed by Jer Noble.

The spec says that a MediaStreamSource can be shared by different tracks,
so a track must have its own state tracking, synchronizing with its MediaStreamSource when
the underlying MediaStreamSource changes the readyState.
In the old implementation if a user invoked the stop method, its readyState method was still
returning the MediaStreamSource state, which was wrong.
This also adds a setEnabled method, which can be used to set the state of a track when a
remote peer ends it, for instance.

No new tests needed.

  • Modules/mediastream/MediaStreamTrack.cpp:

(WebCore::MediaStreamTrack::readyState):
(WebCore::MediaStreamTrack::setState):
(WebCore::MediaStreamTrack::stopProducingData):
(WebCore::MediaStreamTrack::ended):
(WebCore::MediaStreamTrack::sourceStateChanged):
(WebCore::MediaStreamTrack::trackDidEnd):

  • Modules/mediastream/MediaStreamTrack.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r157731 r157733  
     12013-10-21  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
     2
     3        MediaStreamTrack now tracks its own state
     4        https://bugs.webkit.org/show_bug.cgi?id=123025
     5
     6        Reviewed by Jer Noble.
     7
     8        The spec says that a MediaStreamSource can be shared by different tracks,
     9        so a track must have its own state tracking, synchronizing with its MediaStreamSource when
     10        the underlying MediaStreamSource changes the readyState.
     11        In the old implementation if a user invoked the stop method, its readyState method was still
     12        returning the MediaStreamSource state, which was wrong.
     13        This also adds a setEnabled method, which can be used to set the state of a track when a
     14        remote peer ends it, for instance.
     15
     16        No new tests needed.
     17
     18        * Modules/mediastream/MediaStreamTrack.cpp:
     19        (WebCore::MediaStreamTrack::readyState):
     20        (WebCore::MediaStreamTrack::setState):
     21        (WebCore::MediaStreamTrack::stopProducingData):
     22        (WebCore::MediaStreamTrack::ended):
     23        (WebCore::MediaStreamTrack::sourceStateChanged):
     24        (WebCore::MediaStreamTrack::trackDidEnd):
     25        * Modules/mediastream/MediaStreamTrack.h:
     26
    1272013-10-21  Tim Horton  <timothy_horton@apple.com>
    228
  • trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp

    r157068 r157733  
    205205    static NeverDestroyed<AtomicString> newState("new", AtomicString::ConstructFromLiteral);
    206206
    207     if (!m_source)
    208         return newState;
    209 
    210207    if (m_stopped)
    211208        return ended;
    212209
    213     switch (m_source->readyState()) {
     210    switch (m_readyState) {
    214211    case MediaStreamSource::Live:
    215212        return live;
     
    224221}
    225222
     223void MediaStreamTrack::setState(MediaStreamSource::ReadyState state)
     224{
     225    if (m_readyState == MediaStreamSource::Ended || m_readyState == state)
     226        return;
     227
     228    MediaStreamSource::ReadyState oldState = m_readyState;
     229    m_readyState = state;
     230
     231    if (m_readyState == MediaStreamSource::Live && oldState == MediaStreamSource::New)
     232        scheduleEventDispatch(Event::create(eventNames().startedEvent, false, false));
     233    if (m_readyState == MediaStreamSource::Ended && oldState != MediaStreamSource::Ended)
     234        scheduleEventDispatch(Event::create(eventNames().endedEvent, false, false));
     235}
     236
    226237void MediaStreamTrack::getSources(ScriptExecutionContext* context, PassRefPtr<MediaStreamTrackSourcesCallback> callback, ExceptionCode& ec)
    227238{
     
    276287    // Set m_stopped before stopping the source because that may result in a call to sourceChangedState
    277288    // and we only want to dispatch the 'ended' event if necessary.
     289    setState(MediaStreamSource::Ended);
    278290    m_stopped = true;
    279291    m_source->stop();
    280 
    281     if (m_readyState != MediaStreamSource::Ended)
    282         scheduleEventDispatch(Event::create(eventNames().endedEvent, false, false));
    283292}
    284293
    285294bool MediaStreamTrack::ended() const
    286295{
    287     return m_stopped || (m_source && m_source->readyState() == MediaStreamSource::Ended);
     296    return m_stopped || m_readyState == MediaStreamSource::Ended;
    288297}
    289298
     
    293302        return;
    294303
    295     MediaStreamSource::ReadyState oldReadyState = m_readyState;
    296     m_readyState = m_source->readyState();
    297 
    298     if (m_readyState >= MediaStreamSource::Live && oldReadyState == MediaStreamSource::New)
    299         scheduleEventDispatch(Event::create(eventNames().startedEvent, false, false));
    300     if (m_readyState == MediaStreamSource::Ended && oldReadyState != MediaStreamSource::Ended)
    301         scheduleEventDispatch(Event::create(eventNames().endedEvent, false, false));
     304    setState(m_source->readyState());
    302305}
    303306   
     
    351354   
    352355    client->trackDidEnd();
     356    setState(MediaStreamSource::Ended);
    353357}
    354358
  • trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h

    r157653 r157733  
    6464
    6565    const AtomicString& readyState() const;
     66    void setState(MediaStreamSource::ReadyState);
    6667
    6768    static void getSources(ScriptExecutionContext*, PassRefPtr<MediaStreamTrackSourcesCallback>, ExceptionCode&);
Note: See TracChangeset for help on using the changeset viewer.