File: MockBox.h

package info (click to toggle)
webkit2gtk 2.6.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 115,572 kB
  • ctags: 216,388
  • sloc: cpp: 1,164,175; ansic: 18,422; perl: 16,884; python: 11,608; ruby: 9,409; xml: 8,376; asm: 4,765; yacc: 2,292; lex: 891; sh: 650; makefile: 79
file content (158 lines) | stat: -rw-r--r-- 4,825 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * Copyright (C) 2013 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    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 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 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. 
 */

#ifndef MockBox_h
#define MockBox_h

#if ENABLE(MEDIA_SOURCE)

#include <wtf/MediaTime.h>
#include <wtf/text/WTFString.h>

namespace JSC {
class ArrayBuffer;
}

namespace WebCore {

// A MockBox represents a ISO-BMFF like data structure. Data in the
// structure is little-endian. The layout of the data structure as follows:
//
// 4 bytes : 4CC : identifier
// 4 bytes : unsigned : length
// 
class MockBox {
public:
    static String peekType(JSC::ArrayBuffer*);
    static size_t peekLength(JSC::ArrayBuffer*);

    size_t length() const { return m_length; }
    const String& type() const { return m_type; }

protected:
    MockBox(JSC::ArrayBuffer*);

    size_t m_length;
    String m_type;
};

// A MockTrackBox extends MockBox and expects the following
// data structure:
//
// 4 bytes : 4CC : identifier = 'trak'
// 4 bytes : unsigned : length = 17
// 4 bytes : signed : track ID
// 4 bytes : 4CC : codec
// 1 byte  : unsigned : kind
// 
class MockTrackBox final : public MockBox {
public:
    static const String& type();
    MockTrackBox(JSC::ArrayBuffer*);

    int32_t trackID() const { return m_trackID; }

    const String& codec() const { return m_codec; }

    enum TrackKind { Audio, Video, Text };
    TrackKind kind() const { return m_kind; }

protected:
    uint8_t m_trackID;
    String m_codec;
    TrackKind m_kind;
};

// A MockInitializationBox extends MockBox and contains 0 or more
// MockTrackBoxes. It expects the following data structure:
//
// 4 bytes : 4CC : identifier = 'init'
// 4 bytes : unsigned : length = 16 + (13 * num tracks)
// 4 bytes : signed : duration time value
// 4 bytes : signed : duration time scale
// N bytes : MockTrackBoxes : tracks
//
class MockInitializationBox final : public MockBox {
public:
    static const String& type();
    MockInitializationBox(JSC::ArrayBuffer*);

    MediaTime duration() const { return m_duration; }
    const Vector<MockTrackBox>& tracks() const { return m_tracks; }

protected:
    MediaTime m_duration;
    Vector<MockTrackBox> m_tracks;
};

// A MockSampleBox extends MockBox and expects the following data structure:
//
// 4 bytes : 4CC : identifier = 'smpl'
// 4 bytes : unsigned : length = 29
// 4 bytes : signed : time scale
// 4 bytes : signed : presentation time value
// 4 bytes : signed : decode time value
// 4 bytes : signed : duration time value
// 4 bytes : signed : track ID
// 1 byte  : unsigned : flags
// 1 byte  : unsigned : generation
//
class MockSampleBox final : public MockBox {
public:
    static const String& type();
    MockSampleBox(JSC::ArrayBuffer*);

    MediaTime presentationTimestamp() const { return m_presentationTimestamp; }
    MediaTime decodeTimestamp() const { return m_decodeTimestamp; }
    MediaTime duration() const { return m_duration; }
    int32_t trackID() const { return m_trackID; }
    uint8_t flags() const { return m_flags; }
    uint8_t generation() const { return m_generation; }

    enum {
        IsSync = 1 << 0,
        IsCorrupted = 1 << 1,
        IsDropped = 1 << 2,
        IsDelayed = 1 << 3,
    };
    bool isSync() const { return m_flags & IsSync; }
    bool isCorrupted() const { return m_flags & IsCorrupted; }
    bool isDropped() const { return m_flags & IsDropped; }
    bool isDelayed() const { return m_flags & IsDelayed; }

protected:
    MediaTime m_presentationTimestamp;
    MediaTime m_decodeTimestamp;
    MediaTime m_duration;
    int32_t m_trackID;
    uint8_t m_flags;
    uint8_t m_generation;
};

}

#endif

#endif