Chromium Code Reviews| Index: Source/modules/mediasource/MediaSource.cpp |
| diff --git a/Source/modules/mediasource/WebKitMediaSource.cpp b/Source/modules/mediasource/MediaSource.cpp |
| similarity index 59% |
| copy from Source/modules/mediasource/WebKitMediaSource.cpp |
| copy to Source/modules/mediasource/MediaSource.cpp |
| index 8dd5f5640fb943338842987dbe2451cac2f30660..704bec123290db330281e55416f9c415d09a29f0 100644 |
| --- a/Source/modules/mediasource/WebKitMediaSource.cpp |
| +++ b/Source/modules/mediasource/MediaSource.cpp |
| @@ -1,5 +1,5 @@ |
| /* |
| - * Copyright (C) 2012 Google Inc. All rights reserved. |
| + * Copyright (C) 2013 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 |
| @@ -29,10 +29,12 @@ |
| */ |
| #include "config.h" |
| -#include "modules/mediasource/WebKitMediaSource.h" |
| +#include "modules/mediasource/MediaSource.h" |
| +#include "core/dom/GenericEventQueue.h" |
| #include "core/html/TimeRanges.h" |
| #include "core/platform/ContentType.h" |
| +#include "core/platform/Logging.h" |
| #include "core/platform/MIMETypeRegistry.h" |
| #include "core/platform/graphics/SourceBufferPrivate.h" |
| #include "modules/mediasource/MediaSourceRegistry.h" |
| @@ -40,35 +42,43 @@ |
| namespace WebCore { |
| -PassRefPtr<WebKitMediaSource> WebKitMediaSource::create(ScriptExecutionContext* context) |
| +PassRefPtr<MediaSource> MediaSource::create(ScriptExecutionContext* context) |
| { |
| - RefPtr<WebKitMediaSource> mediaSource(adoptRef(new WebKitMediaSource(context))); |
| + RefPtr<MediaSource> mediaSource(adoptRef(new MediaSource(context))); |
| mediaSource->suspendIfNeeded(); |
| return mediaSource.release(); |
| } |
| -WebKitMediaSource::WebKitMediaSource(ScriptExecutionContext* context) |
| +MediaSource::MediaSource(ScriptExecutionContext* context) |
| : MediaSourceBase(context) |
| { |
| + LOG(Media, "MediaSource::MediaSource %p", this); |
| ScriptWrappable::init(this); |
| - m_sourceBuffers = WebKitSourceBufferList::create(scriptExecutionContext(), asyncEventQueue()); |
| - m_activeSourceBuffers = WebKitSourceBufferList::create(scriptExecutionContext(), asyncEventQueue()); |
| + m_sourceBuffers = SourceBufferList::create(scriptExecutionContext(), asyncEventQueue()); |
| + m_activeSourceBuffers = SourceBufferList::create(scriptExecutionContext(), asyncEventQueue()); |
| } |
| -WebKitSourceBufferList* WebKitMediaSource::sourceBuffers() |
| +MediaSource::~MediaSource() |
| +{ |
| + LOG(Media, "MediaSource::~MediaSource %p", this); |
| + ASSERT(isClosed()); |
| +} |
| + |
| +SourceBufferList* MediaSource::sourceBuffers() |
|
adamk
2013/06/10 23:05:40
Not a big deal, but any reason not to inline this
acolwell GONE FROM CHROMIUM
2013/06/10 23:36:15
Done.
|
| { |
| return m_sourceBuffers.get(); |
| } |
| -WebKitSourceBufferList* WebKitMediaSource::activeSourceBuffers() |
| +SourceBufferList* MediaSource::activeSourceBuffers() |
| { |
| - // FIXME(91649): support track selection |
| return m_activeSourceBuffers.get(); |
| } |
| -WebKitSourceBuffer* WebKitMediaSource::addSourceBuffer(const String& type, ExceptionCode& ec) |
| +SourceBuffer* MediaSource::addSourceBuffer(const String& type, ExceptionCode& ec) |
| { |
| - // 3.1 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-addsourcebuffer |
| + LOG(Media, "MediaSource::addSourceBuffer(%s) %p", type.ascii().data(), this); |
| + |
| + // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type |
| // 1. If type is null or an empty then throw an INVALID_ACCESS_ERR exception and |
| // abort these steps. |
| if (type.isNull() || type.isEmpty()) { |
| @@ -94,10 +104,15 @@ WebKitSourceBuffer* WebKitMediaSource::addSourceBuffer(const String& type, Excep |
| ContentType contentType(type); |
| Vector<String> codecs = contentType.codecs(); |
| OwnPtr<SourceBufferPrivate> sourceBufferPrivate = createSourceBufferPrivate(contentType.type(), codecs, ec); |
| - if (!sourceBufferPrivate) |
| + |
| + if (!sourceBufferPrivate) { |
| + ASSERT(ec == NOT_SUPPORTED_ERR || ec == QUOTA_EXCEEDED_ERR); |
| + // 2. If type contains a MIME type that is not supported ..., then throw a NOT_SUPPORTED_ERR exception and abort these steps. |
| + // 3. If the user agent can't handle any more SourceBuffer objects then throw a QUOTA_EXCEEDED_ERR exception and abort these steps |
| return 0; |
| + } |
| - RefPtr<WebKitSourceBuffer> buffer = WebKitSourceBuffer::create(sourceBufferPrivate.release(), this); |
| + RefPtr<SourceBuffer> buffer = SourceBuffer::create(sourceBufferPrivate.release(), this, asyncEventQueue()); |
| // 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object. |
| m_sourceBuffers->add(buffer); |
| m_activeSourceBuffers->add(buffer); |
| @@ -105,9 +120,12 @@ WebKitSourceBuffer* WebKitMediaSource::addSourceBuffer(const String& type, Excep |
| return buffer.get(); |
| } |
| -void WebKitMediaSource::removeSourceBuffer(WebKitSourceBuffer* buffer, ExceptionCode& ec) |
| +void MediaSource::removeSourceBuffer(SourceBuffer* buffer, ExceptionCode& ec) |
| { |
| - // 3.1 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-removesourcebuffer |
| + LOG(Media, "MediaSource::removeSourceBuffer() %p", this); |
| + RefPtr<SourceBuffer> protect(buffer); |
| + |
| + // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-MediaSource-removeSourceBuffer-void-SourceBuffer-sourceBuffer |
| // 1. If sourceBuffer is null then throw an INVALID_ACCESS_ERR exception and |
| // abort these steps. |
| if (!buffer) { |
| @@ -115,64 +133,68 @@ void WebKitMediaSource::removeSourceBuffer(WebKitSourceBuffer* buffer, Exception |
| return; |
| } |
| - // 2. If sourceBuffers is empty then throw an INVALID_STATE_ERR exception and |
| - // abort these steps. |
| - if (isClosed() || !m_sourceBuffers->length()) { |
| - ec = INVALID_STATE_ERR; |
| - return; |
| - } |
| - |
| - // 3. If sourceBuffer specifies an object that is not in sourceBuffers then |
| + // 2. If sourceBuffer specifies an object that is not in sourceBuffers then |
| // throw a NOT_FOUND_ERR exception and abort these steps. |
| - // 6. Remove sourceBuffer from sourceBuffers and fire a removesourcebuffer event |
| - // on that object. |
| - if (!m_sourceBuffers->remove(buffer)) { |
| + if (!m_sourceBuffers->length() || !m_sourceBuffers->contains(buffer)) { |
| ec = NOT_FOUND_ERR; |
| return; |
| } |
| - // 7. Destroy all resources for sourceBuffer. |
| - m_activeSourceBuffers->remove(buffer); |
| + // 3. If the sourceBuffer.updating attribute equals true, then run the following steps: ... |
| + buffer->abortIfUpdating(); |
| - // 4. Remove track information from audioTracks, videoTracks, and textTracks for all tracks |
| - // associated with sourceBuffer and fire a simple event named change on the modified lists. |
| + // Steps 4-9 are related to updating audioTracks, videoTracks, and textTracks which aren't implmented yet. |
| // FIXME(91649): support track selection |
| - // 5. If sourceBuffer is in activeSourceBuffers, then remove it from that list and fire a |
| - // removesourcebuffer event on that object. |
| - // FIXME(91649): support track selection |
| + // 10. If sourceBuffer is in activeSourceBuffers, then remove sourceBuffer from activeSourceBuffers ... |
| + m_activeSourceBuffers->remove(buffer); |
| + |
| + // 11. Remove sourceBuffer from sourceBuffers and fire a removesourcebuffer event |
| + // on that object. |
| + m_sourceBuffers->remove(buffer); |
|
adamk
2013/06/10 23:05:40
Won't this fire two events?
acolwell GONE FROM CHROMIUM
2013/06/10 23:36:15
Yes. One for the m_activeSourceBuffers list and on
|
| + |
| + // 12. Destroy all resources for sourceBuffer. |
| + buffer->removedFromMediaSource(); |
| } |
| -void WebKitMediaSource::setReadyState(const AtomicString& state) |
| +void MediaSource::setReadyState(const AtomicString& state) |
| { |
| ASSERT(state == openKeyword() || state == closedKeyword() || state == endedKeyword()); |
| - String oldState = readyState(); |
| + AtomicString oldState = readyState(); |
| if (oldState == state) |
| return; |
| + LOG(Media, "MediaSource::setReadyState() %p : %s -> %s", this, oldState.string().ascii().data(), state.string().ascii().data()); |
| + |
| MediaSourceBase::setReadyState(state); |
| - if (isClosed()) { |
| - m_sourceBuffers->clear(); |
| - m_activeSourceBuffers->clear(); |
| - scheduleEvent(eventNames().webkitsourcecloseEvent); |
| + if (isOpen()) { |
| + scheduleEvent(eventNames().sourceopenEvent); |
| return; |
| } |
| if (oldState == openKeyword() && state == endedKeyword()) { |
| - scheduleEvent(eventNames().webkitsourceendedEvent); |
| + scheduleEvent(eventNames().sourceendedEvent); |
| return; |
| } |
| - if (isOpen()) { |
| - scheduleEvent(eventNames().webkitsourceopenEvent); |
| - return; |
| - } |
| + ASSERT(isClosed()); |
| + |
| + m_activeSourceBuffers->clear(); |
| + |
| + // Clear SourceBuffer references to this object. |
| + for (int i = 0; i < m_sourceBuffers->length(); ++i) |
|
adamk
2013/06/10 23:05:40
I expect you'll need to make this some sort of uns
acolwell GONE FROM CHROMIUM
2013/06/10 23:36:15
Done. {Shakes fist at clang for not detecting this
|
| + m_sourceBuffers->item(i)->removedFromMediaSource(); |
| + m_sourceBuffers->clear(); |
| + |
| + scheduleEvent(eventNames().sourcecloseEvent); |
| } |
| -bool WebKitMediaSource::isTypeSupported(const String& type) |
| +bool MediaSource::isTypeSupported(const String& type) |
| { |
| - // Section 2.1 isTypeSupported() method steps. |
| + LOG(Media, "MediaSource::isTypeSupported(%s)", type.ascii().data()); |
| + |
| + // Section 2.2 isTypeSupported() method steps. |
| // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#widl-MediaSource-isTypeSupported-boolean-DOMString-type |
| // 1. If type is an empty string, then return false. |
| if (type.isNull() || type.isEmpty()) |
| @@ -192,12 +214,12 @@ bool WebKitMediaSource::isTypeSupported(const String& type) |
| return MIMETypeRegistry::isSupportedMediaSourceMIMEType(contentType.type(), codecs); |
| } |
| -const AtomicString& WebKitMediaSource::interfaceName() const |
| +const AtomicString& MediaSource::interfaceName() const |
| { |
| - return eventNames().interfaceForWebKitMediaSource; |
| + return eventNames().interfaceForMediaSource; |
| } |
| -void WebKitMediaSource::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| +void MediaSource::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| { |
| MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); |
| ScriptWrappable::reportMemoryUsage(memoryObjectInfo); |