1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef WEBMELEMENT_H_ 18 #define WEBMELEMENT_H_ 19 20 #include <media/stagefright/MediaBuffer.h> 21 #include <media/stagefright/foundation/ABase.h> 22 #include <media/stagefright/foundation/ABuffer.h> 23 #include <utils/List.h> 24 25 namespace android { 26 27 class MetaData; 28 29 struct WebmElement : public LightRefBase<WebmElement> { 30 const uint64_t mId, mSize; 31 32 WebmElement(uint64_t id, uint64_t size); 33 virtual ~WebmElement(); 34 35 virtual int serializePayloadSize(uint8_t *buf); 36 virtual void serializePayload(uint8_t *buf)=0; 37 uint64_t totalSize(); 38 uint64_t serializeInto(uint8_t *buf); 39 uint8_t *serialize(uint64_t& size); 40 int write(int fd, uint64_t& size); 41 42 static sp<WebmElement> EbmlHeader( 43 int ver = 1, 44 int readVer = 1, 45 int maxIdLen = 4, 46 int maxSizeLen = 8, 47 int docVer = 2, 48 int docReadVer = 2); 49 50 static sp<WebmElement> SegmentInfo(uint64_t scale = 1000000, double dur = 0); 51 52 static sp<WebmElement> AudioTrackEntry( 53 const char *codec, 54 int chans, 55 double rate, 56 const sp<ABuffer> &buf, 57 int bps = 0, 58 uint64_t uid = 0, 59 bool lacing = false, 60 const char *lang = "und"); 61 62 static sp<WebmElement> VideoTrackEntry( 63 const char *codec, 64 uint64_t width, 65 uint64_t height, 66 const sp<MetaData> &md, 67 uint64_t uid = 0, 68 bool lacing = false, 69 const char *lang = "und"); 70 71 static sp<WebmElement> SeekEntry(uint64_t id, uint64_t off); 72 static sp<WebmElement> CuePointEntry(uint64_t time, int track, uint64_t off); 73 static sp<WebmElement> SimpleBlock( 74 int trackNum, 75 int16_t timecode, 76 bool key, 77 const uint8_t *data, 78 uint64_t dataSize); 79 }; 80 81 struct WebmUnsigned : public WebmElement { 82 WebmUnsigned(uint64_t id, uint64_t value); 83 const uint64_t mValue; 84 void serializePayload(uint8_t *buf); 85 }; 86 87 struct WebmFloat : public WebmElement { 88 const double mValue; 89 WebmFloat(uint64_t id, float value); 90 WebmFloat(uint64_t id, double value); 91 void serializePayload(uint8_t *buf); 92 }; 93 94 struct WebmBinary : public WebmElement { 95 const sp<ABuffer> mRef; 96 WebmBinary(uint64_t id, const sp<ABuffer> &ref); 97 void serializePayload(uint8_t *buf); 98 }; 99 100 struct WebmString : public WebmElement { 101 const char *const mStr; 102 WebmString(uint64_t id, const char *str); 103 void serializePayload(uint8_t *buf); 104 }; 105 106 struct WebmSimpleBlock : public WebmElement { 107 const int mTrackNum; 108 const int16_t mRelTimecode; 109 const bool mKey; 110 const sp<ABuffer> mRef; 111 112 WebmSimpleBlock(int trackNum, int16_t timecode, bool key, const sp<ABuffer>& orig); 113 void serializePayload(uint8_t *buf); 114 }; 115 116 struct EbmlVoid : public WebmElement { 117 const uint64_t mSizeWidth; 118 explicit EbmlVoid(uint64_t totalSize); 119 int serializePayloadSize(uint8_t *buf); 120 void serializePayload(uint8_t *buf); 121 }; 122 123 struct WebmMaster : public WebmElement { 124 const List<sp<WebmElement> > mChildren; 125 explicit WebmMaster(uint64_t id); 126 WebmMaster(uint64_t id, const List<sp<WebmElement> > &children); 127 int serializePayloadSize(uint8_t *buf); 128 void serializePayload(uint8_t *buf); 129 }; 130 131 } /* namespace android */ 132 #endif /* WEBMELEMENT_H_ */ 133