1 | /* |
2 | * Copyright (C) 2013 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 | #ifndef MediaSample_h |
27 | #define MediaSample_h |
28 | |
29 | #include "FloatSize.h" |
30 | #include <JavaScriptCore/TypedArrays.h> |
31 | #include <wtf/EnumTraits.h> |
32 | #include <wtf/MediaTime.h> |
33 | #include <wtf/RefCounted.h> |
34 | #include <wtf/text/AtomicString.h> |
35 | |
36 | typedef struct opaqueCMSampleBuffer *CMSampleBufferRef; |
37 | typedef struct _GstSample GstSample; |
38 | |
39 | namespace WebCore { |
40 | |
41 | class MockSampleBox; |
42 | |
43 | struct PlatformSample { |
44 | enum { |
45 | None, |
46 | MockSampleBoxType, |
47 | CMSampleBufferType, |
48 | GStreamerSampleType, |
49 | } type; |
50 | union { |
51 | MockSampleBox* mockSampleBox; |
52 | CMSampleBufferRef cmSampleBuffer; |
53 | GstSample* gstSample; |
54 | } sample; |
55 | }; |
56 | |
57 | class MediaSample : public RefCounted<MediaSample> { |
58 | public: |
59 | virtual ~MediaSample() = default; |
60 | |
61 | virtual MediaTime presentationTime() const = 0; |
62 | virtual MediaTime outputPresentationTime() const { return presentationTime(); } |
63 | virtual MediaTime decodeTime() const = 0; |
64 | virtual MediaTime duration() const = 0; |
65 | virtual MediaTime outputDuration() const { return duration(); } |
66 | virtual AtomicString trackID() const = 0; |
67 | virtual void setTrackID(const String&) = 0; |
68 | virtual size_t sizeInBytes() const = 0; |
69 | virtual FloatSize presentationSize() const = 0; |
70 | virtual void offsetTimestampsBy(const MediaTime&) = 0; |
71 | virtual void setTimestamps(const MediaTime&, const MediaTime&) = 0; |
72 | virtual bool isDivisable() const = 0; |
73 | enum DivideFlags { BeforePresentationTime, AfterPresentationTime }; |
74 | virtual std::pair<RefPtr<MediaSample>, RefPtr<MediaSample>> divide(const MediaTime& presentationTime) = 0; |
75 | virtual Ref<MediaSample> createNonDisplayingCopy() const = 0; |
76 | |
77 | virtual RefPtr<JSC::Uint8ClampedArray> getRGBAImageData() const { return nullptr; } |
78 | |
79 | enum SampleFlags { |
80 | None = 0, |
81 | IsSync = 1 << 0, |
82 | IsNonDisplaying = 1 << 1, |
83 | HasAlpha = 1 << 2, |
84 | }; |
85 | virtual SampleFlags flags() const = 0; |
86 | virtual PlatformSample platformSample() = 0; |
87 | |
88 | enum class VideoRotation { |
89 | None = 0, |
90 | UpsideDown = 180, |
91 | Right = 90, |
92 | Left = 270, |
93 | }; |
94 | virtual VideoRotation videoRotation() const { return VideoRotation::None; } |
95 | virtual bool videoMirrored() const { return false; } |
96 | virtual uint32_t videoPixelFormat() const { return 0; } |
97 | |
98 | bool isSync() const { return flags() & IsSync; } |
99 | bool isNonDisplaying() const { return flags() & IsNonDisplaying; } |
100 | bool hasAlpha() const { return flags() & HasAlpha; } |
101 | |
102 | virtual void dump(PrintStream&) const = 0; |
103 | virtual String toJSONString() const { return { }; } |
104 | }; |
105 | |
106 | } // namespace WebCore |
107 | |
108 | namespace WTF { |
109 | |
110 | template<> struct EnumTraits<WebCore::MediaSample::VideoRotation> { |
111 | using values = EnumValues< |
112 | WebCore::MediaSample::VideoRotation, |
113 | WebCore::MediaSample::VideoRotation::None, |
114 | WebCore::MediaSample::VideoRotation::UpsideDown, |
115 | WebCore::MediaSample::VideoRotation::Right, |
116 | WebCore::MediaSample::VideoRotation::Left |
117 | >; |
118 | }; |
119 | |
120 | template<typename Type> struct LogArgument; |
121 | template <> |
122 | struct LogArgument<WebCore::MediaSample> { |
123 | static String toString(const WebCore::MediaSample& sample) |
124 | { |
125 | return sample.toJSONString(); |
126 | } |
127 | }; |
128 | |
129 | } // namespace WTF |
130 | |
131 | #endif |
132 | |