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/MockSourceBufferPrivate.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/MockSourceBufferPrivate.cpp')
-rw-r--r-- | Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp | 122 |
1 files changed, 71 insertions, 51 deletions
diff --git a/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp b/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp index 643ae76cd..e031a9b5d 100644 --- a/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp +++ b/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Apple Inc. All rights reserved. + * Copyright (C) 2013-2017 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,17 +10,17 @@ * 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 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" @@ -38,29 +38,40 @@ #include "SourceBufferPrivateClient.h" #include <map> #include <runtime/ArrayBuffer.h> +#include <wtf/StringPrintStream.h> namespace WebCore { class MockMediaSample final : public MediaSample { public: - static RefPtr<MockMediaSample> create(const MockSampleBox& box) { return adoptRef(new MockMediaSample(box)); } + static Ref<MockMediaSample> create(const MockSampleBox& box) { return adoptRef(*new MockMediaSample(box)); } virtual ~MockMediaSample() { } - virtual MediaTime presentationTime() const override { return m_box.presentationTimestamp(); } - virtual MediaTime decodeTime() const override { return m_box.decodeTimestamp(); } - virtual MediaTime duration() const override { return m_box.duration(); } - virtual AtomicString trackID() const override { return m_id; } - - virtual SampleFlags flags() const override; - virtual PlatformSample platformSample() override; - -protected: +private: MockMediaSample(const MockSampleBox& box) : m_box(box) , m_id(String::format("%d", box.trackID())) { } + MediaTime presentationTime() const override { return m_box.presentationTimestamp(); } + MediaTime decodeTime() const override { return m_box.decodeTimestamp(); } + MediaTime duration() const override { return m_box.duration(); } + AtomicString trackID() const override { return m_id; } + void setTrackID(const String& id) override { m_id = id; } + size_t sizeInBytes() const override { return sizeof(m_box); } + SampleFlags flags() const override; + PlatformSample platformSample() override; + FloatSize presentationSize() const override { return FloatSize(); } + void dump(PrintStream&) const override; + void offsetTimestampsBy(const MediaTime& offset) override { m_box.offsetTimestampsBy(offset); } + void setTimestamps(const MediaTime& presentationTimestamp, const MediaTime& decodeTimestamp) override { m_box.setTimestamps(presentationTimestamp, decodeTimestamp); } + bool isDivisable() const override { return false; } + std::pair<RefPtr<MediaSample>, RefPtr<MediaSample>> divide(const MediaTime&) override { return {nullptr, nullptr}; } + Ref<MediaSample> createNonDisplayingCopy() const override; + + unsigned generation() const { return m_box.generation(); } + MockSampleBox m_box; AtomicString m_id; }; @@ -68,8 +79,10 @@ protected: MediaSample::SampleFlags MockMediaSample::flags() const { unsigned flags = None; - if (m_box.flags() & MockSampleBox::IsSync) + if (m_box.isSync()) flags |= IsSync; + if (m_box.isNonDisplaying()) + flags |= IsNonDisplaying; return SampleFlags(flags); } @@ -79,15 +92,27 @@ PlatformSample MockMediaSample::platformSample() return sample; } +void MockMediaSample::dump(PrintStream& out) const +{ + out.print("{PTS(", presentationTime(), "), DTS(", decodeTime(), "), duration(", duration(), "), flags(", (int)flags(), "), generation(", generation(), ")}"); +} + +Ref<MediaSample> MockMediaSample::createNonDisplayingCopy() const +{ + auto copy = MockMediaSample::create(m_box); + copy->m_box.setFlag(MockSampleBox::IsNonDisplaying); + return WTFMove(copy); +} + class MockMediaDescription final : public MediaDescription { public: static RefPtr<MockMediaDescription> create(const MockTrackBox& box) { return adoptRef(new MockMediaDescription(box)); } virtual ~MockMediaDescription() { } - virtual AtomicString codec() const override { return m_box.codec(); } - virtual bool isVideo() const override { return m_box.kind() == MockTrackBox::Video; } - virtual bool isAudio() const override { return m_box.kind() == MockTrackBox::Audio; } - virtual bool isText() const override { return m_box.kind() == MockTrackBox::Text; } + AtomicString codec() const override { return m_box.codec(); } + bool isVideo() const override { return m_box.kind() == MockTrackBox::Video; } + bool isAudio() const override { return m_box.kind() == MockTrackBox::Audio; } + bool isText() const override { return m_box.kind() == MockTrackBox::Text; } protected: MockMediaDescription(const MockTrackBox& box) : m_box(box) { } @@ -114,12 +139,12 @@ void MockSourceBufferPrivate::setClient(SourceBufferPrivateClient* client) m_client = client; } -SourceBufferPrivate::AppendResult MockSourceBufferPrivate::append(const unsigned char* data, unsigned length) +void MockSourceBufferPrivate::append(const unsigned char* data, unsigned length) { m_inputBuffer.append(data, length); - AppendResult result = AppendSucceeded; + SourceBufferPrivateClient::AppendResult result = SourceBufferPrivateClient::AppendSucceeded; - while (m_inputBuffer.size() && result == AppendSucceeded) { + while (m_inputBuffer.size() && result == SourceBufferPrivateClient::AppendSucceeded) { RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(m_inputBuffer.data(), m_inputBuffer.size()); size_t boxLength = MockBox::peekLength(buffer.get()); if (boxLength > buffer->byteLength()) @@ -133,12 +158,13 @@ SourceBufferPrivate::AppendResult MockSourceBufferPrivate::append(const unsigned MockSampleBox sampleBox = MockSampleBox(buffer.get()); didReceiveSample(sampleBox); } else - result = ParsingFailed; + result = SourceBufferPrivateClient::ParsingFailed; m_inputBuffer.remove(0, boxLength); } - return result; + if (m_client) + m_client->sourceBufferPrivateAppendComplete(result); } void MockSourceBufferPrivate::didReceiveInitializationSegment(const MockInitializationBox& initBox) @@ -169,7 +195,7 @@ void MockSourceBufferPrivate::didReceiveInitializationSegment(const MockInitiali } } - m_client->sourceBufferPrivateDidReceiveInitializationSegment(this, segment); + m_client->sourceBufferPrivateDidReceiveInitializationSegment(segment); } @@ -178,13 +204,17 @@ void MockSourceBufferPrivate::didReceiveSample(const MockSampleBox& sampleBox) if (!m_client) return; - m_client->sourceBufferPrivateDidReceiveSample(this, MockMediaSample::create(sampleBox)); + m_client->sourceBufferPrivateDidReceiveSample(MockMediaSample::create(sampleBox)); } void MockSourceBufferPrivate::abort() { } +void MockSourceBufferPrivate::resetParserState() +{ +} + void MockSourceBufferPrivate::removedFromMediaSource() { if (m_mediaSource) @@ -202,32 +232,27 @@ void MockSourceBufferPrivate::setReadyState(MediaPlayer::ReadyState readyState) m_mediaSource->player()->setReadyState(readyState); } -void MockSourceBufferPrivate::evictCodedFrames() -{ - // No-op. -} - -bool MockSourceBufferPrivate::isFull() -{ - return false; -} - void MockSourceBufferPrivate::setActive(bool isActive) { if (m_mediaSource) m_mediaSource->sourceBufferPrivateDidChangeActiveState(this, isActive); } -void MockSourceBufferPrivate::enqueueSample(PassRefPtr<MediaSample> sample, AtomicString) +Vector<String> MockSourceBufferPrivate::enqueuedSamplesForTrackID(const AtomicString&) +{ + return m_enqueuedSamples; +} + +void MockSourceBufferPrivate::enqueueSample(Ref<MediaSample>&& sample, const AtomicString&) { - if (!m_mediaSource || !sample) + if (!m_mediaSource) return; PlatformSample platformSample = sample->platformSample(); if (platformSample.type != PlatformSample::MockSampleBoxType) return; - MockSampleBox* box = platformSample.sample.mockSampleBox; + auto* box = platformSample.sample.mockSampleBox; if (!box) return; @@ -237,37 +262,32 @@ void MockSourceBufferPrivate::enqueueSample(PassRefPtr<MediaSample> sample, Atom if (box->isDropped()) m_mediaSource->incrementDroppedFrames(); if (box->isDelayed()) - m_mediaSource->incrementTotalFrameDelayBy(1); + m_mediaSource->incrementTotalFrameDelayBy(MediaTime(1, 1)); + + m_enqueuedSamples.append(toString(sample.get())); } bool MockSourceBufferPrivate::hasVideo() const { - if (!m_client) - return false; - - return m_client->sourceBufferPrivateHasVideo(this); + return m_client && m_client->sourceBufferPrivateHasVideo(); } bool MockSourceBufferPrivate::hasAudio() const { - if (!m_client) - return false; - - return m_client->sourceBufferPrivateHasAudio(this); + return m_client && m_client->sourceBufferPrivateHasAudio(); } - MediaTime MockSourceBufferPrivate::fastSeekTimeForMediaTime(const MediaTime& time, const MediaTime& negativeThreshold, const MediaTime& positiveThreshold) { if (m_client) - return m_client->sourceBufferPrivateFastSeekTimeForMediaTime(this, time, negativeThreshold, positiveThreshold); + return m_client->sourceBufferPrivateFastSeekTimeForMediaTime(time, negativeThreshold, positiveThreshold); return time; } void MockSourceBufferPrivate::seekToTime(const MediaTime& time) { if (m_client) - m_client->sourceBufferPrivateSeekToTime(this, time); + m_client->sourceBufferPrivateSeekToTime(time); } } |