⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 126946 in webkit


Ignore:
Timestamp:
Aug 28, 2012, 6:07:56 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

Make MediaSource event dispatch asynchronous.
https://bugs.webkit.org/show_bug.cgi?id=95217

Patch by Aaron Colwell <acolwell@chromium.org> on 2012-08-28
Reviewed by Eric Carlson.

Source/WebCore:

Update MediaSource & SourceBufferList to use a GenericEventQueue to dispatch events
instead of using synchronous dispatch.

Test: http/tests/media/media-source/video-media-source-async-events.html

  • Modules/mediasource/MediaSource.cpp:

(WebCore::MediaSource::MediaSource): Create GenericEventQueue & pass a pointer to SourceBufferList.
(WebCore::MediaSource::addSourceBuffer):
(WebCore::MediaSource::setReadyState): Updated to use new scheduleEvent() helper method.
(WebCore::MediaSource::scheduleEvent): New method for creating events and adding them to the event queue.
(WebCore):

  • Modules/mediasource/MediaSource.h: Added GenericEventQueue member and scheduleEvent() signature.

(MediaSource):

  • Modules/mediasource/SourceBufferList.cpp:

(WebCore::SourceBufferList::SourceBufferList):
(WebCore::SourceBufferList::remove):
(WebCore::SourceBufferList::createAndFireEvent): Updated to queue events instead of synchronously dispatch them.

  • Modules/mediasource/SourceBufferList.h:

(WebCore):
(WebCore::SourceBufferList::create):
(SourceBufferList):

LayoutTests:

  • Added a test to verify that MediaSource & SourceBufferList events are dispatched asynchronously.
  • Updated a few existing tests that were relying on the old synchronous dispatch.
  • http/tests/media/media-source/video-media-source-async-events-expected.txt: Added.
  • http/tests/media/media-source/video-media-source-async-events.html: Added.
  • http/tests/media/media-source/video-media-source-event-attributes.html:
  • http/tests/media/media-source/video-media-source-objects.html:
  • http/tests/media/media-source/video-media-source-seek-expected.txt:
  • http/tests/media/media-source/video-media-source-state-changes-expected.txt:
Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r126944 r126946  
     12012-08-28  Aaron Colwell  <acolwell@chromium.org>
     2
     3        Make MediaSource event dispatch asynchronous.
     4        https://bugs.webkit.org/show_bug.cgi?id=95217
     5
     6        Reviewed by Eric Carlson.
     7
     8        - Added a test to verify that MediaSource & SourceBufferList events are dispatched asynchronously.
     9        - Updated a few existing tests that were relying on the old synchronous dispatch.
     10
     11        * http/tests/media/media-source/video-media-source-async-events-expected.txt: Added.
     12        * http/tests/media/media-source/video-media-source-async-events.html: Added.
     13        * http/tests/media/media-source/video-media-source-event-attributes.html:
     14        * http/tests/media/media-source/video-media-source-objects.html:
     15        * http/tests/media/media-source/video-media-source-seek-expected.txt:
     16        * http/tests/media/media-source/video-media-source-state-changes-expected.txt:
     17
    1182012-08-28  Julien Chaffraix  <jchaffraix@webkit.org>
    219
  • trunk/LayoutTests/http/tests/media/media-source/video-media-source-event-attributes.html

    r125059 r126946  
    2020               consoleWrite("Setting src attribute to \"\" to trigger a webkitsourceclosed event.");
    2121               video.src = "";
    22                endTest();
    2322           }
    2423
  • trunk/LayoutTests/http/tests/media/media-source/video-media-source-objects.html

    r125682 r126946  
    2222
    2323                run("segmentHelper.addSourceBuffer()");
     24            }
    2425
     26            function afterSourceBufferAdded()
     27            {
    2528                consoleWrite("");
    2629                consoleWrite("Test SourceBuffer object type");
     
    6568
    6669                run("mediaSource.removeSourceBuffer(segmentHelper.sourceBuffer)");
     70            }
    6771
     72            function afterSourceBufferRemoved()
     73            {
    6874                consoleWrite("Test that addSourceBuffer() throws and error when the MediaSource is not associated with a media element.");
    6975                var mediaSource2 = new MediaSource();
     
    8490                endTest();
    8591            }
    86            
     92
    8793            function onSourceBufferAdded(event)
    8894            {
     
    9399                testExpected("mediaSource.sourceBuffers", event.target);
    94100                testExpected("mediaSource.sourceBuffers instanceof window.SourceBufferList", true);
     101
     102                afterSourceBufferAdded();
    95103            }
    96104
     
    115123                }
    116124                testExpected("mediaSource.sourceBuffers.length", 0);
     125
     126                afterSourceBufferRemoved();
    117127            }
    118128
  • trunk/LayoutTests/http/tests/media/media-source/video-media-source-seek-expected.txt

    r125059 r126946  
    55EVENT(playing)
    66EVENT(timeupdate) : seeking to 2.78
     7EVENT(seeking)
    78EVENT(webkitsourceopen)
    8 EVENT(seeking)
    99EVENT(webkitsourceended)
    1010EVENT(playing)
  • trunk/LayoutTests/http/tests/media/media-source/video-media-source-state-changes-expected.txt

    r125059 r126946  
    1717EVENT(seeked)
    1818onSecondSeeked
     19EVENT(emptied)
    1920EVENT(webkitsourceclose) : closed
    2021onFirstSourceClose
    21 EVENT(emptied)
    2222EVENT(webkitsourceopen) : open
    2323onSecondSourceOpen
     
    2626EVENT(playing)
    2727triggerSecondSourceClose
     28EVENT(emptied)
    2829EVENT(webkitsourceclose) : closed
    2930onSecondSourceClose
    30 EVENT(emptied)
    3131EVENT(webkitsourceopen) : open
    3232onThirdSourceOpen
  • trunk/Source/WebCore/ChangeLog

    r126945 r126946  
     12012-08-28  Aaron Colwell  <acolwell@chromium.org>
     2
     3        Make MediaSource event dispatch asynchronous.
     4        https://bugs.webkit.org/show_bug.cgi?id=95217
     5
     6        Reviewed by Eric Carlson.
     7
     8        Update MediaSource & SourceBufferList to use a GenericEventQueue to dispatch events
     9        instead of using synchronous dispatch.
     10
     11        Test: http/tests/media/media-source/video-media-source-async-events.html
     12
     13        * Modules/mediasource/MediaSource.cpp:
     14        (WebCore::MediaSource::MediaSource): Create GenericEventQueue & pass a pointer to SourceBufferList.
     15        (WebCore::MediaSource::addSourceBuffer):
     16        (WebCore::MediaSource::setReadyState): Updated to use new scheduleEvent() helper method.
     17        (WebCore::MediaSource::scheduleEvent): New method for creating events and adding them to the event queue.
     18        (WebCore):
     19        * Modules/mediasource/MediaSource.h: Added GenericEventQueue member and scheduleEvent() signature.
     20        (MediaSource):
     21        * Modules/mediasource/SourceBufferList.cpp:
     22        (WebCore::SourceBufferList::SourceBufferList):
     23        (WebCore::SourceBufferList::remove):
     24        (WebCore::SourceBufferList::createAndFireEvent): Updated to queue events instead of synchronously dispatch them.
     25        * Modules/mediasource/SourceBufferList.h:
     26        (WebCore):
     27        (WebCore::SourceBufferList::create):
     28        (SourceBufferList):
     29
    1302012-08-28  Leandro Gracia Gil  <leandrogracia@chromium.org>
    231
  • trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp

    r125682 r126946  
    5050    , m_readyState(closedKeyword())
    5151    , m_player(0)
    52 {
    53     m_sourceBuffers = SourceBufferList::create(scriptExecutionContext());
    54     m_activeSourceBuffers = SourceBufferList::create(scriptExecutionContext());
     52    , m_asyncEventQueue(GenericEventQueue::create(this))
     53{
     54    m_sourceBuffers = SourceBufferList::create(scriptExecutionContext(), m_asyncEventQueue.get());
     55    m_activeSourceBuffers = SourceBufferList::create(scriptExecutionContext(), m_asyncEventQueue.get());
    5556}
    5657
     
    8586        return 0;
    8687    }
    87    
     88
    8889    // 4. If the readyState attribute is not in the "open" state then throw an
    8990    // INVALID_STATE_ERR exception and abort these steps.
     
    183184        m_activeSourceBuffers->clear();
    184185        m_player = 0;
    185         dispatchEvent(Event::create(eventNames().webkitsourcecloseEvent, false, false));
    186         return;
    187     }
    188    
     186        scheduleEvent(eventNames().webkitsourcecloseEvent);
     187        return;
     188    }
     189
    189190    if (oldState == openKeyword() && m_readyState == endedKeyword()) {
    190         dispatchEvent(Event::create(eventNames().webkitsourceendedEvent, false, false));
     191        scheduleEvent(eventNames().webkitsourceendedEvent);
    191192        return;
    192193    }
    193194
    194195    if (m_readyState == openKeyword()) {
    195         dispatchEvent(Event::create(eventNames().webkitsourceopenEvent, false, false));
     196        scheduleEvent(eventNames().webkitsourceopenEvent);
    196197        return;
    197198    }
     
    302303}
    303304
     305void MediaSource::scheduleEvent(const AtomicString& eventName)
     306{
     307    ASSERT(m_asyncEventQueue);
     308
     309    RefPtr<Event> event = Event::create(eventName, false, false);
     310    event->setTarget(this);
     311
     312    m_asyncEventQueue->enqueueEvent(event.release());
     313}
     314
    304315} // namespace WebCore
    305316
  • trunk/Source/WebCore/Modules/mediasource/MediaSource.h

    r125682 r126946  
    3535
    3636#include "ContextDestructionObserver.h"
     37#include "GenericEventQueue.h"
    3738#include "MediaPlayer.h"
    3839#include "SourceBuffer.h"
     
    7778
    7879    void setMediaPlayer(MediaPlayer* player) { m_player = player; }
    79    
     80
    8081    PassRefPtr<TimeRanges> buffered(const String& id, ExceptionCode&) const;
    8182    void append(const String& id, PassRefPtr<Uint8Array> data, ExceptionCode&);
     
    99100    virtual void derefEventTarget() OVERRIDE { deref(); }
    100101
     102    void scheduleEvent(const AtomicString& eventName);
     103
    101104    EventTargetData m_eventTargetData;
    102105
     
    106109    RefPtr<SourceBufferList> m_sourceBuffers;
    107110    RefPtr<SourceBufferList> m_activeSourceBuffers;
     111    OwnPtr<GenericEventQueue> m_asyncEventQueue;
    108112};
    109113
  • trunk/Source/WebCore/Modules/mediasource/SourceBufferList.cpp

    r125424 r126946  
    3939namespace WebCore {
    4040
    41 SourceBufferList::SourceBufferList(ScriptExecutionContext* context)
     41SourceBufferList::SourceBufferList(ScriptExecutionContext* context,
     42                                   GenericEventQueue* asyncEventQueue)
    4243    : m_scriptExecutionContext(context)
     44    , m_asyncEventQueue(asyncEventQueue)
    4345    , m_lastSourceBufferId(0)
    4446{
     
    6466
    6567bool SourceBufferList::remove(SourceBuffer* buffer)
    66 {   
     68{
    6769    size_t index = m_list.find(buffer);
    6870    if (index == notFound)
     
    111113void SourceBufferList::createAndFireEvent(const AtomicString& eventName)
    112114{
     115    ASSERT(m_asyncEventQueue);
     116
    113117    RefPtr<Event> event = Event::create(eventName, false, false);
    114118    event->setTarget(this);
    115119
    116     EventTarget::dispatchEvent(event);
     120    m_asyncEventQueue->enqueueEvent(event.release());
    117121}
    118122
  • trunk/Source/WebCore/Modules/mediasource/SourceBufferList.h

    r125424 r126946  
    4141
    4242class SourceBuffer;
     43class GenericEventQueue;
    4344
    4445class SourceBufferList : public RefCounted<SourceBufferList>, public EventTarget {
    4546public:
    46     static PassRefPtr<SourceBufferList> create(ScriptExecutionContext* context)
     47    static PassRefPtr<SourceBufferList> create(ScriptExecutionContext* context, GenericEventQueue* asyncEventQueue)
    4748    {
    48         return adoptRef(new SourceBufferList(context));
     49        return adoptRef(new SourceBufferList(context, asyncEventQueue));
    4950    }
    5051    virtual ~SourceBufferList() { }
     
    7374
    7475private:
    75     explicit SourceBufferList(ScriptExecutionContext*);
     76    SourceBufferList(ScriptExecutionContext*, GenericEventQueue*);
    7677
    7778    bool contains(size_t id) const;
     
    8384    EventTargetData m_eventTargetData;
    8485    ScriptExecutionContext* m_scriptExecutionContext;
     86    GenericEventQueue* m_asyncEventQueue;
    8587
    8688    Vector<RefPtr<SourceBuffer> > m_list;
Note: See TracChangeset for help on using the changeset viewer.