diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp')
-rw-r--r-- | Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp | 121 |
1 files changed, 74 insertions, 47 deletions
diff --git a/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp b/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp index e0fc51c9f..4e40c8e73 100644 --- a/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp +++ b/Source/WebCore/platform/mock/mediasource/MockMediaPlayerMediaSource.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2013-2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -28,12 +28,11 @@ #if ENABLE(MEDIA_SOURCE) -#include "ExceptionCodePlaceholder.h" -#include "HTMLMediaSource.h" #include "MediaPlayer.h" +#include "MediaSourcePrivateClient.h" #include "MockMediaSourcePrivate.h" -#include <wtf/Functional.h> #include <wtf/MainThread.h> +#include <wtf/NeverDestroyed.h> #include <wtf/text/WTFString.h> namespace WebCore { @@ -41,28 +40,25 @@ namespace WebCore { // MediaPlayer Enigne Support void MockMediaPlayerMediaSource::registerMediaEngine(MediaEngineRegistrar registrar) { - registrar(create, getSupportedTypes, supportsType, 0, 0, 0); + registrar([](MediaPlayer* player) { return std::make_unique<MockMediaPlayerMediaSource>(player); }, getSupportedTypes, + supportsType, 0, 0, 0, 0); } -PassOwnPtr<MediaPlayerPrivateInterface> MockMediaPlayerMediaSource::create(MediaPlayer* player) +static const HashSet<String, ASCIICaseInsensitiveHash>& mimeTypeCache() { - return adoptPtr(new MockMediaPlayerMediaSource(player)); -} - -static HashSet<String> mimeTypeCache() -{ - DEFINE_STATIC_LOCAL(HashSet<String>, cache, ()); + static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> cache; static bool isInitialized = false; if (!isInitialized) { isInitialized = true; - cache.add(ASCIILiteral("video/mock")); + cache.get().add(ASCIILiteral("video/mock")); + cache.get().add(ASCIILiteral("audio/mock")); } return cache; } -void MockMediaPlayerMediaSource::getSupportedTypes(HashSet<String>& supportedTypes) +void MockMediaPlayerMediaSource::getSupportedTypes(HashSet<String, ASCIICaseInsensitiveHash>& supportedTypes) { supportedTypes = mimeTypeCache(); } @@ -72,7 +68,7 @@ MediaPlayer::SupportsType MockMediaPlayerMediaSource::supportsType(const MediaEn if (!parameters.isMediaSource) return MediaPlayer::IsNotSupported; - if (!mimeTypeCache().contains(parameters.type)) + if (parameters.type.isEmpty() || !mimeTypeCache().contains(parameters.type)) return MediaPlayer::IsNotSupported; if (parameters.codecs.isEmpty()) @@ -84,10 +80,10 @@ MediaPlayer::SupportsType MockMediaPlayerMediaSource::supportsType(const MediaEn MockMediaPlayerMediaSource::MockMediaPlayerMediaSource(MediaPlayer* player) : m_player(player) , m_currentTime(MediaTime::zeroTime()) - , m_duration(0) , m_readyState(MediaPlayer::HaveNothing) , m_networkState(MediaPlayer::Empty) , m_playing(false) + , m_seekCompleted(true) { } @@ -100,11 +96,9 @@ void MockMediaPlayerMediaSource::load(const String&) ASSERT_NOT_REACHED(); } -void MockMediaPlayerMediaSource::load(const String&, PassRefPtr<HTMLMediaSource> source) +void MockMediaPlayerMediaSource::load(const String&, MediaSourcePrivateClient* source) { - m_mediaSource = source; - m_mediaSourcePrivate = MockMediaSourcePrivate::create(this); - m_mediaSource->setPrivateAndOpen(*m_mediaSourcePrivate); + m_mediaSourcePrivate = MockMediaSourcePrivate::create(this, source); } void MockMediaPlayerMediaSource::cancelLoad() @@ -114,7 +108,9 @@ void MockMediaPlayerMediaSource::cancelLoad() void MockMediaPlayerMediaSource::play() { m_playing = 1; - callOnMainThread(bind(&MockMediaPlayerMediaSource::advanceCurrentTime, this)); + callOnMainThread([this] { + advanceCurrentTime(); + }); } void MockMediaPlayerMediaSource::pause() @@ -122,9 +118,9 @@ void MockMediaPlayerMediaSource::pause() m_playing = 0; } -IntSize MockMediaPlayerMediaSource::naturalSize() const +FloatSize MockMediaPlayerMediaSource::naturalSize() const { - return IntSize(); + return FloatSize(); } bool MockMediaPlayerMediaSource::hasVideo() const @@ -143,7 +139,7 @@ void MockMediaPlayerMediaSource::setVisible(bool) bool MockMediaPlayerMediaSource::seeking() const { - return false; + return !m_seekCompleted; } bool MockMediaPlayerMediaSource::paused() const @@ -161,14 +157,17 @@ MediaPlayer::ReadyState MockMediaPlayerMediaSource::readyState() const return m_readyState; } -double MockMediaPlayerMediaSource::maxTimeSeekableDouble() const +MediaTime MockMediaPlayerMediaSource::maxMediaTimeSeekable() const { return m_duration; } -PassRefPtr<TimeRanges> MockMediaPlayerMediaSource::buffered() const +std::unique_ptr<PlatformTimeRanges> MockMediaPlayerMediaSource::buffered() const { - return m_mediaSource ? m_mediaSource->buffered() : TimeRanges::create(); + if (m_mediaSourcePrivate) + return m_mediaSourcePrivate->buffered(); + + return std::make_unique<PlatformTimeRanges>(); } bool MockMediaPlayerMediaSource::didLoadingProgress() const @@ -180,45 +179,54 @@ void MockMediaPlayerMediaSource::setSize(const IntSize&) { } -void MockMediaPlayerMediaSource::paint(GraphicsContext*, const IntRect&) +void MockMediaPlayerMediaSource::paint(GraphicsContext&, const FloatRect&) { } -double MockMediaPlayerMediaSource::currentTimeDouble() const +MediaTime MockMediaPlayerMediaSource::currentMediaTime() const { - return m_currentTime.toDouble(); + return m_currentTime; } -double MockMediaPlayerMediaSource::durationDouble() const +MediaTime MockMediaPlayerMediaSource::durationMediaTime() const { - return m_duration; + return m_mediaSourcePrivate ? m_mediaSourcePrivate->duration() : MediaTime::zeroTime(); } -void MockMediaPlayerMediaSource::seekWithTolerance(double time, double negativeTolerance, double positiveTolerance) +void MockMediaPlayerMediaSource::seekWithTolerance(const MediaTime& time, const MediaTime& negativeTolerance, const MediaTime& positiveTolerance) { if (!negativeTolerance && !positiveTolerance) { - m_currentTime = MediaTime::createWithDouble(time); - m_mediaSourcePrivate->seekToTime(MediaTime::createWithDouble(time)); + m_currentTime = time; + m_mediaSourcePrivate->seekToTime(time); } else - m_currentTime = m_mediaSourcePrivate->seekToTime(MediaTime::createWithDouble(time), MediaTime::createWithDouble(negativeTolerance), MediaTime::createWithDouble(positiveTolerance)); - m_player->timeChanged(); + m_currentTime = m_mediaSourcePrivate->seekToTime(time, negativeTolerance, positiveTolerance); - if (m_playing) - callOnMainThread(bind(&MockMediaPlayerMediaSource::advanceCurrentTime, this)); + if (m_seekCompleted) { + m_player->timeChanged(); + + if (m_playing) + callOnMainThread([this] { + advanceCurrentTime(); + }); + } } void MockMediaPlayerMediaSource::advanceCurrentTime() { - RefPtr<TimeRanges> buffered = this->buffered(); - size_t pos = buffered->find(m_currentTime.toDouble()); + if (!m_mediaSourcePrivate) + return; + + auto buffered = m_mediaSourcePrivate->buffered(); + size_t pos = buffered->find(m_currentTime); if (pos == notFound) return; - m_currentTime = MediaTime::createWithDouble(std::min(m_duration, buffered->end(pos, IGNORE_EXCEPTION))); + bool ignoreError; + m_currentTime = std::min(m_duration, buffered->end(pos, ignoreError)); m_player->timeChanged(); } -void MockMediaPlayerMediaSource::updateDuration(double duration) +void MockMediaPlayerMediaSource::updateDuration(const MediaTime& duration) { if (m_duration == duration) return; @@ -245,6 +253,25 @@ void MockMediaPlayerMediaSource::setNetworkState(MediaPlayer::NetworkState netwo m_player->networkStateChanged(); } +void MockMediaPlayerMediaSource::waitForSeekCompleted() +{ + m_seekCompleted = false; +} + +void MockMediaPlayerMediaSource::seekCompleted() +{ + if (m_seekCompleted) + return; + m_seekCompleted = true; + + m_player->timeChanged(); + + if (m_playing) + callOnMainThread([this] { + advanceCurrentTime(); + }); +} + unsigned long MockMediaPlayerMediaSource::totalVideoFrames() { return m_mediaSourcePrivate ? m_mediaSourcePrivate->totalVideoFrames() : 0; @@ -260,9 +287,9 @@ unsigned long MockMediaPlayerMediaSource::corruptedVideoFrames() return m_mediaSourcePrivate ? m_mediaSourcePrivate->corruptedVideoFrames() : 0; } -double MockMediaPlayerMediaSource::totalFrameDelay() +MediaTime MockMediaPlayerMediaSource::totalFrameDelay() { - return m_mediaSourcePrivate ? m_mediaSourcePrivate->totalFrameDelay() : 0; + return m_mediaSourcePrivate ? m_mediaSourcePrivate->totalFrameDelay() : MediaTime::zeroTime(); } } |