This source file includes following definitions.
- create
- sourceBuffers
- activeSourceBuffers
- addSourceBuffer
- removeSourceBuffer
- onReadyStateChange
- activeRanges
- isUpdating
- isTypeSupported
- interfaceName
- trace
#include "config.h"
#include "modules/mediasource/WebKitMediaSource.h"
#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/dom/ExceptionCode.h"
#include "core/frame/UseCounter.h"
#include "core/html/TimeRanges.h"
#include "modules/mediasource/MediaSourceRegistry.h"
#include "platform/ContentType.h"
#include "platform/MIMETypeRegistry.h"
#include "public/platform/WebSourceBuffer.h"
#include "wtf/Uint8Array.h"
using blink::WebSourceBuffer;
namespace WebCore {
PassRefPtrWillBeRawPtr<WebKitMediaSource> WebKitMediaSource::create(ExecutionContext* context)
{
RefPtrWillBeRawPtr<WebKitMediaSource> mediaSource(adoptRefWillBeRefCountedGarbageCollected(new WebKitMediaSource(context)));
mediaSource->suspendIfNeeded();
return mediaSource.release();
}
WebKitMediaSource::WebKitMediaSource(ExecutionContext* context)
: MediaSourceBase(context)
{
ScriptWrappable::init(this);
m_sourceBuffers = WebKitSourceBufferList::create(executionContext(), asyncEventQueue());
m_activeSourceBuffers = WebKitSourceBufferList::create(executionContext(), asyncEventQueue());
}
WebKitSourceBufferList* WebKitMediaSource::sourceBuffers()
{
return m_sourceBuffers.get();
}
WebKitSourceBufferList* WebKitMediaSource::activeSourceBuffers()
{
return m_activeSourceBuffers.get();
}
WebKitSourceBuffer* WebKitMediaSource::addSourceBuffer(const String& type, ExceptionState& exceptionState)
{
if (type.isNull() || type.isEmpty()) {
exceptionState.throwDOMException(InvalidAccessError, "The type provided is empty.");
return 0;
}
if (!isTypeSupported(type)) {
exceptionState.throwDOMException(NotSupportedError, "The type provided ('" + type + "') is not supported.");
return 0;
}
if (!isOpen()) {
exceptionState.throwDOMException(InvalidStateError, "This MediaSource's readyState is not 'open'.");
return 0;
}
ContentType contentType(type);
Vector<String> codecs = contentType.codecs();
OwnPtr<WebSourceBuffer> webSourceBuffer = createWebSourceBuffer(contentType.type(), codecs, exceptionState);
if (!webSourceBuffer)
return 0;
RefPtrWillBeRawPtr<WebKitSourceBuffer> buffer = WebKitSourceBuffer::create(webSourceBuffer.release(), this);
m_sourceBuffers->add(buffer);
m_activeSourceBuffers->add(buffer);
return buffer.get();
}
void WebKitMediaSource::removeSourceBuffer(WebKitSourceBuffer* buffer, ExceptionState& exceptionState)
{
if (!buffer) {
exceptionState.throwDOMException(InvalidAccessError, "The SourceBuffer provided is invalid.");
return;
}
if (isClosed()) {
exceptionState.throwDOMException(InvalidStateError, "This MediaSource's readyState is 'closed'.");
return;
}
if (!m_sourceBuffers->length()) {
exceptionState.throwDOMException(InvalidStateError, "This MediaSource does not contain any SourceBuffers.");
return;
}
if (!m_sourceBuffers->remove(buffer)) {
exceptionState.throwDOMException(NotFoundError, "The SourceBuffer provided was not contained in this MediaSource.");
return;
}
m_activeSourceBuffers->remove(buffer);
}
void WebKitMediaSource::onReadyStateChange(const AtomicString& oldState, const AtomicString& newState)
{
if (oldState == closedKeyword() && newState == openKeyword())
UseCounter::countDeprecation(executionContext(), UseCounter::PrefixedMediaSourceOpen);
if (isClosed()) {
m_sourceBuffers->clear();
m_activeSourceBuffers->clear();
scheduleEvent(EventTypeNames::webkitsourceclose);
return;
}
if (oldState == openKeyword() && newState == endedKeyword()) {
scheduleEvent(EventTypeNames::webkitsourceended);
return;
}
if (isOpen()) {
scheduleEvent(EventTypeNames::webkitsourceopen);
return;
}
}
Vector<RefPtr<TimeRanges> > WebKitMediaSource::activeRanges() const
{
Vector<RefPtr<TimeRanges> > activeRanges(m_activeSourceBuffers->length());
for (size_t i = 0; i < m_activeSourceBuffers->length(); ++i)
activeRanges[i] = m_activeSourceBuffers->item(i)->buffered(ASSERT_NO_EXCEPTION);
return activeRanges;
}
bool WebKitMediaSource::isUpdating() const
{
return false;
}
bool WebKitMediaSource::isTypeSupported(const String& type)
{
if (type.isNull() || type.isEmpty())
return false;
ContentType contentType(type);
String codecs = contentType.parameter("codecs");
if (contentType.type().isEmpty())
return false;
return MIMETypeRegistry::isSupportedMediaSourceMIMEType(contentType.type(), codecs);
}
const AtomicString& WebKitMediaSource::interfaceName() const
{
return EventTargetNames::WebKitMediaSource;
}
void WebKitMediaSource::trace(Visitor* visitor)
{
visitor->trace(m_sourceBuffers);
visitor->trace(m_activeSourceBuffers);
MediaSourceBase::trace(visitor);
}
}