summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/webm/WebmElement.h
blob: f19933e1f88b94118a254a916ccc6d7a934d6869 (plain)
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
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef WEBMELEMENT_H_
#define WEBMELEMENT_H_

#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/foundation/ABase.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <utils/List.h>

namespace android {

struct WebmElement : public LightRefBase<WebmElement> {
    const uint64_t mId, mSize;

    WebmElement(uint64_t id, uint64_t size);
    virtual ~WebmElement();

    virtual int serializePayloadSize(uint8_t *buf);
    virtual void serializePayload(uint8_t *buf)=0;
    uint64_t totalSize();
    uint64_t serializeInto(uint8_t *buf);
    uint8_t *serialize(uint64_t& size);
    int write(int fd, uint64_t& size);

    static sp<WebmElement> EbmlHeader(
            int ver = 1,
            int readVer = 1,
            int maxIdLen = 4,
            int maxSizeLen = 8,
            int docVer = 2,
            int docReadVer = 2);

    static sp<WebmElement> SegmentInfo(uint64_t scale = 1000000, double dur = 0);

    static sp<WebmElement> AudioTrackEntry(
            int chans,
            double rate,
            const sp<ABuffer> &buf,
            int bps = 0,
            uint64_t uid = 0,
            bool lacing = false,
            const char *lang = "und");

    static sp<WebmElement> VideoTrackEntry(
            uint64_t width,
            uint64_t height,
            uint64_t uid = 0,
            bool lacing = false,
            const char *lang = "und");

    static sp<WebmElement> SeekEntry(uint64_t id, uint64_t off);
    static sp<WebmElement> CuePointEntry(uint64_t time, int track, uint64_t off);
    static sp<WebmElement> SimpleBlock(
            int trackNum,
            int16_t timecode,
            bool key,
            const uint8_t *data,
            uint64_t dataSize);
};

struct WebmUnsigned : public WebmElement {
    WebmUnsigned(uint64_t id, uint64_t value);
    const uint64_t mValue;
    void serializePayload(uint8_t *buf);
};

struct WebmFloat : public WebmElement {
    const double mValue;
    WebmFloat(uint64_t id, float value);
    WebmFloat(uint64_t id, double value);
    void serializePayload(uint8_t *buf);
};

struct WebmBinary : public WebmElement {
    const sp<ABuffer> mRef;
    WebmBinary(uint64_t id, const sp<ABuffer> &ref);
    void serializePayload(uint8_t *buf);
};

struct WebmString : public WebmElement {
    const char *const mStr;
    WebmString(uint64_t id, const char *str);
    void serializePayload(uint8_t *buf);
};

struct WebmSimpleBlock : public WebmElement {
    const int mTrackNum;
    const int16_t mRelTimecode;
    const bool mKey;
    const sp<ABuffer> mRef;

    WebmSimpleBlock(int trackNum, int16_t timecode, bool key, const sp<ABuffer>& orig);
    void serializePayload(uint8_t *buf);
};

struct EbmlVoid : public WebmElement {
    const uint64_t mSizeWidth;
    EbmlVoid(uint64_t totalSize);
    int serializePayloadSize(uint8_t *buf);
    void serializePayload(uint8_t *buf);
};

struct WebmMaster : public WebmElement {
    const List<sp<WebmElement> > mChildren;
    WebmMaster(uint64_t id);
    WebmMaster(uint64_t id, const List<sp<WebmElement> > &children);
    int serializePayloadSize(uint8_t *buf);
    void serializePayload(uint8_t *buf);
};

} /* namespace android */
#endif /* WEBMELEMENT_H_ */