void MediaSource::setReadyState(const String& state) { ASSERT(state == openKeyword() || state == closedKeyword() || state == endedKeyword()); if (m_readyState == state) return; String oldState = m_readyState; m_readyState = state; if (m_readyState == closedKeyword()) { m_sourceBuffers->clear(); m_activeSourceBuffers->clear(); m_player = 0; scheduleEvent(eventNames().webkitsourcecloseEvent); return; } if (oldState == openKeyword() && m_readyState == endedKeyword()) { scheduleEvent(eventNames().webkitsourceendedEvent); return; } if (m_readyState == openKeyword()) { scheduleEvent(eventNames().webkitsourceopenEvent); return; } }
void MediaSource::setPrivateAndOpen(Ref<MediaSourcePrivate>&& mediaSourcePrivate) { ASSERT(!m_private); ASSERT(m_mediaElement); m_private = WTFMove(mediaSourcePrivate); setReadyState(openKeyword()); }
void MediaSource::endOfStream(const String& error, ExceptionCode& ec) { // 3.1 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-endofstream // 1. If the readyState attribute is not in the "open" state then throw an // INVALID_STATE_ERR exception and abort these steps. if (!m_player || m_readyState != openKeyword()) { ec = INVALID_STATE_ERR; return; } MediaPlayer::EndOfStreamStatus eosStatus = MediaPlayer::EosNoError; if (error.isNull() || error.isEmpty()) eosStatus = MediaPlayer::EosNoError; else if (error == "network") eosStatus = MediaPlayer::EosNetworkError; else if (error == "decode") eosStatus = MediaPlayer::EosDecodeError; else { ec = INVALID_ACCESS_ERR; return; } // 2. Change the readyState attribute value to "ended". setReadyState(endedKeyword()); m_player->sourceEndOfStream(eosStatus); }
void MediaSource::setPrivateAndOpen(PassOwnPtr<MediaSourcePrivate> mediaSourcePrivate) { ASSERT(mediaSourcePrivate); ASSERT(!m_private); m_private = mediaSourcePrivate; setReadyState(openKeyword()); }
void MediaSource::setPrivateAndOpen(PassRef<MediaSourcePrivate> mediaSourcePrivate) { ASSERT(!m_private); ASSERT(m_mediaElement); m_private = std::move(mediaSourcePrivate); setReadyState(openKeyword()); }
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 // 1. If type is null or an empty then throw an INVALID_ACCESS_ERR exception and // abort these steps. if (type.isNull() || type.isEmpty()) { ec = INVALID_ACCESS_ERR; return 0; } // 2. If type contains a MIME type that is not supported ..., then throw a // NOT_SUPPORTED_ERR exception and abort these steps. ContentType contentType(type); Vector<String> codecs = contentType.codecs(); if (!codecs.size()) { ec = NOT_SUPPORTED_ERR; return 0; } // 4. If the readyState attribute is not in the "open" state then throw an // INVALID_STATE_ERR exception and abort these steps. if (!m_player || m_readyState != openKeyword()) { ec = INVALID_STATE_ERR; return 0; } // 5. Create a new SourceBuffer object and associated resources. String id = m_sourceBuffers->generateUniqueId(); if (id == emptyString()) { ec = QUOTA_EXCEEDED_ERR; return 0; } RefPtr<SourceBuffer> buffer = SourceBuffer::create(id, this); switch (m_player->sourceAddId(buffer->id(), contentType.type(), codecs)) { case MediaPlayer::Ok: // 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object. m_sourceBuffers->add(buffer); m_activeSourceBuffers->add(buffer); // 7. Return the new object to the caller. return buffer.get(); case MediaPlayer::NotSupported: // 2 (cont). If type contains a MIME type ... that is not supported with the types // specified for the other SourceBuffer objects in sourceBuffers, then throw // a NOT_SUPPORTED_ERR exception and abort these steps. ec = NOT_SUPPORTED_ERR; return 0; case MediaPlayer::ReachedIdLimit: // 3 (cont). If the user agent can't handle any more SourceBuffer objects then throw // a QUOTA_EXCEEDED_ERR exception and abort these steps. ec = QUOTA_EXCEEDED_ERR; return 0; } ASSERT_NOT_REACHED(); return 0; }
void MediaSource::openIfInEndedState() { if (m_readyState != endedKeyword()) return; setReadyState(openKeyword()); m_private->unmarkEndOfStream(); }
void MediaSource::abort(const String& id, ExceptionCode& ec) { if (!m_player || m_readyState != openKeyword()) { ec = INVALID_STATE_ERR; return; } if (!m_player->sourceAbort(id)) ASSERT_NOT_REACHED(); }
void MediaSource::setDuration(double duration, ExceptionCode& ec) { if (duration < 0.0 || std::isnan(duration)) { ec = INVALID_ACCESS_ERR; return; } if (m_readyState != openKeyword()) { ec = INVALID_STATE_ERR; return; } m_player->sourceSetDuration(duration); }
void MediaSource::setReadyState(const AtomicString& state) { ASSERT(state == openKeyword() || state == closedKeyword() || state == endedKeyword()); AtomicString oldState = readyState(); LOG(Media, "MediaSource::setReadyState() %p : %s -> %s", this, oldState.string().ascii().data(), state.string().ascii().data()); if (state == closedKeyword()) { m_private.clear(); m_mediaElement = 0; } if (oldState == state) return; m_readyState = state; onReadyStateChange(oldState, state); }
void WebKitMediaSource::onReadyStateChange(const AtomicString& oldState, const AtomicString& newState) { if (isClosed()) { m_sourceBuffers->clear(); m_activeSourceBuffers->clear(); scheduleEvent(eventNames().webkitsourcecloseEvent); return; } if (oldState == openKeyword() && newState == endedKeyword()) { scheduleEvent(eventNames().webkitsourceendedEvent); return; } if (isOpen()) { scheduleEvent(eventNames().webkitsourceopenEvent); return; } }
void MediaSource::setReadyState(const AtomicString& state) { ASSERT(state == openKeyword() || state == closedKeyword() || state == endedKeyword()); AtomicString oldState = readyState(); LOG(MediaSource, "MediaSource::setReadyState(%p) : %s -> %s", this, oldState.string().ascii().data(), state.string().ascii().data()); if (state == closedKeyword()) { m_private = nullptr; m_mediaElement = nullptr; m_duration = MediaTime::invalidTime(); } if (oldState == state) return; m_readyState = state; onReadyStateChange(oldState, state); }
void MediaSource::append(const String& id, PassRefPtr<Uint8Array> data, ExceptionCode& ec) { if (!data.get()) { ec = INVALID_ACCESS_ERR; return; } if (!m_player || m_readyState == closedKeyword()) { ec = INVALID_STATE_ERR; return; } if (m_readyState == endedKeyword()) setReadyState(openKeyword()); if (!m_player->sourceAppend(id, data->data(), data->length())) { ec = SYNTAX_ERR; return; } }
void MediaSource::onReadyStateChange(const AtomicString& oldState, const AtomicString& newState) { if (isOpen()) { scheduleEvent(eventNames().sourceopenEvent); return; } if (oldState == openKeyword() && newState == endedKeyword()) { scheduleEvent(eventNames().sourceendedEvent); return; } ASSERT(isClosed()); m_activeSourceBuffers->clear(); // Clear SourceBuffer references to this object. for (auto& buffer : *m_sourceBuffers) buffer->removedFromMediaSource(); m_sourceBuffers->clear(); scheduleEvent(eventNames().sourcecloseEvent); }
void MediaSource::onReadyStateChange(const AtomicString& oldState, const AtomicString& newState) { if (isOpen()) { scheduleEvent(eventNames().sourceopenEvent); return; } if (oldState == openKeyword() && newState == endedKeyword()) { scheduleEvent(eventNames().sourceendedEvent); return; } ASSERT(isClosed()); m_activeSourceBuffers->clear(); // Clear SourceBuffer references to this object. for (unsigned long i = 0, length = m_sourceBuffers->length(); i < length; ++i) m_sourceBuffers->item(i)->removedFromMediaSource(); m_sourceBuffers->clear(); scheduleEvent(eventNames().sourcecloseEvent); }
bool MediaSource::isOpen() const { return readyState() == openKeyword(); }