Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: Source/modules/mediasource/MediaSource.cpp

Issue 16625011: Add minimal implementation of unprefixed MediaSource API that has feature parity with prefixed API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix global-constructors-listing-expected.txt Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/mediasource/MediaSource.h ('k') | Source/modules/mediasource/MediaSource.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8145fcf9434890c2cbc5c846a4b5db66267b0dd8 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,33 @@
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()
{
- return m_sourceBuffers.get();
+ LOG(Media, "MediaSource::~MediaSource %p", this);
+ ASSERT(isClosed());
}
-WebKitSourceBufferList* WebKitMediaSource::activeSourceBuffers()
+SourceBuffer* MediaSource::addSourceBuffer(const String& type, ExceptionCode& ec)
{
- // FIXME(91649): support track selection
- return m_activeSourceBuffers.get();
-}
+ LOG(Media, "MediaSource::addSourceBuffer(%s) %p", type.ascii().data(), this);
-WebKitSourceBuffer* WebKitMediaSource::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
+ // 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 +94,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 +110,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 +123,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);
+
+ // 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 (unsigned long i = 0; i < m_sourceBuffers->length(); ++i)
+ 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 +204,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);
« no previous file with comments | « Source/modules/mediasource/MediaSource.h ('k') | Source/modules/mediasource/MediaSource.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698