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 25namespace android { 26 27class MetaData; 28 29struct 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 int chans, 54 double rate, 55 const sp<ABuffer> &buf, 56 int bps = 0, 57 uint64_t uid = 0, 58 bool lacing = false, 59 const char *lang = "und"); 60 61 static sp<WebmElement> VideoTrackEntry( 62 const char *codec, 63 uint64_t width, 64 uint64_t height, 65 const sp<MetaData> &md, 66 uint64_t uid = 0, 67 bool lacing = false, 68 const char *lang = "und"); 69 70 static sp<WebmElement> SeekEntry(uint64_t id, uint64_t off); 71 static sp<WebmElement> CuePointEntry(uint64_t time, int track, uint64_t off); 72 static sp<WebmElement> SimpleBlock( 73 int trackNum, 74 int16_t timecode, 75 bool key, 76 const uint8_t *data, 77 uint64_t dataSize); 78}; 79 80struct WebmUnsigned : public WebmElement { 81 WebmUnsigned(uint64_t id, uint64_t value); 82 const uint64_t mValue; 83 void serializePayload(uint8_t *buf); 84}; 85 86struct WebmFloat : public WebmElement { 87 const double mValue; 88 WebmFloat(uint64_t id, float value); 89 WebmFloat(uint64_t id, double value); 90 void serializePayload(uint8_t *buf); 91}; 92 93struct WebmBinary : public WebmElement { 94 const sp<ABuffer> mRef; 95 WebmBinary(uint64_t id, const sp<ABuffer> &ref); 96 void serializePayload(uint8_t *buf); 97}; 98 99struct WebmString : public WebmElement { 100 const char *const mStr; 101 WebmString(uint64_t id, const char *str); 102 void serializePayload(uint8_t *buf); 103}; 104 105struct WebmSimpleBlock : public WebmElement { 106 const int mTrackNum; 107 const int16_t mRelTimecode; 108 const bool mKey; 109 const sp<ABuffer> mRef; 110 111 WebmSimpleBlock(int trackNum, int16_t timecode, bool key, const sp<ABuffer>& orig); 112 void serializePayload(uint8_t *buf); 113}; 114 115struct EbmlVoid : public WebmElement { 116 const uint64_t mSizeWidth; 117 EbmlVoid(uint64_t totalSize); 118 int serializePayloadSize(uint8_t *buf); 119 void serializePayload(uint8_t *buf); 120}; 121 122struct WebmMaster : public WebmElement { 123 const List<sp<WebmElement> > mChildren; 124 WebmMaster(uint64_t id); 125 WebmMaster(uint64_t id, const List<sp<WebmElement> > &children); 126 int serializePayloadSize(uint8_t *buf); 127 void serializePayload(uint8_t *buf); 128}; 129 130} /* namespace android */ 131#endif /* WEBMELEMENT_H_ */ 132