1/*
2 * Copyright (C) 2013-2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#if ENABLE(MEDIA_SOURCE)
29
30#include "MediaSourcePrivate.h"
31#include <wtf/MediaTime.h>
32
33namespace WebCore {
34
35class MockMediaPlayerMediaSource;
36class MockSourceBufferPrivate;
37
38class MockMediaSourcePrivate final : public MediaSourcePrivate {
39public:
40 static Ref<MockMediaSourcePrivate> create(MockMediaPlayerMediaSource&, MediaSourcePrivateClient&);
41 virtual ~MockMediaSourcePrivate();
42
43 const Vector<MockSourceBufferPrivate*>& activeSourceBuffers() const { return m_activeSourceBuffers; }
44
45 bool hasAudio() const;
46 bool hasVideo() const;
47
48 MediaTime duration();
49 std::unique_ptr<PlatformTimeRanges> buffered();
50
51 MockMediaPlayerMediaSource& player() const { return m_player; }
52
53 void seekToTime(const MediaTime&);
54 MediaTime seekToTime(const MediaTime&, const MediaTime& negativeThreshold, const MediaTime& positiveThreshold);
55
56 Optional<VideoPlaybackQualityMetrics> videoPlaybackQualityMetrics();
57
58 void incrementTotalVideoFrames() { ++m_totalVideoFrames; }
59 void incrementDroppedFrames() { ++m_droppedVideoFrames; }
60 void incrementCorruptedFrames() { ++m_corruptedVideoFrames; }
61 void incrementTotalFrameDelayBy(const MediaTime& delay) { m_totalFrameDelay += delay; }
62
63#if !RELEASE_LOG_DISABLED
64 const Logger& mediaSourceLogger() const;
65 const void* mediaSourceLogIdentifier();
66#endif
67
68private:
69 MockMediaSourcePrivate(MockMediaPlayerMediaSource&, MediaSourcePrivateClient&);
70
71 // MediaSourcePrivate Overrides
72 AddStatus addSourceBuffer(const ContentType&, RefPtr<SourceBufferPrivate>&) override;
73 void durationChanged() override;
74 void markEndOfStream(EndOfStreamStatus) override;
75 void unmarkEndOfStream() override;
76 MediaPlayer::ReadyState readyState() const override;
77 void setReadyState(MediaPlayer::ReadyState) override;
78 void waitForSeekCompleted() override;
79 void seekCompleted() override;
80
81 void sourceBufferPrivateDidChangeActiveState(MockSourceBufferPrivate*, bool active);
82 void removeSourceBuffer(SourceBufferPrivate*);
83
84 friend class MockSourceBufferPrivate;
85
86 MockMediaPlayerMediaSource& m_player;
87 Ref<MediaSourcePrivateClient> m_client;
88 Vector<RefPtr<MockSourceBufferPrivate>> m_sourceBuffers;
89 Vector<MockSourceBufferPrivate*> m_activeSourceBuffers;
90 bool m_isEnded { false };
91
92 unsigned m_totalVideoFrames { 0 };
93 unsigned m_droppedVideoFrames { 0 };
94 unsigned m_corruptedVideoFrames { 0 };
95 MediaTime m_totalFrameDelay;
96};
97
98}
99
100#endif // ENABLE(MEDIA_SOURCE)
101