MPEG4Writer.h revision f60cafe0e6aad8f9ce54660fa88b651ae4e749e6
1/* 2 * Copyright (C) 2009 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 MPEG4_WRITER_H_ 18 19#define MPEG4_WRITER_H_ 20 21#include <stdio.h> 22 23#include <media/stagefright/MediaWriter.h> 24#include <utils/List.h> 25#include <utils/threads.h> 26 27namespace android { 28 29class MediaBuffer; 30class MediaSource; 31class MetaData; 32 33class MPEG4Writer : public MediaWriter { 34public: 35 MPEG4Writer(const char *filename); 36 MPEG4Writer(int fd); 37 38 virtual status_t addSource(const sp<MediaSource> &source); 39 virtual status_t start(); 40 virtual bool reachedEOS(); 41 virtual void stop(); 42 virtual void pause(); 43 44 void beginBox(const char *fourcc); 45 void writeInt8(int8_t x); 46 void writeInt16(int16_t x); 47 void writeInt32(int32_t x); 48 void writeInt64(int64_t x); 49 void writeCString(const char *s); 50 void writeFourcc(const char *fourcc); 51 void write(const void *data, size_t size); 52 void endBox(); 53 uint32_t interleaveDuration() const { return mInterleaveDurationUs; } 54 status_t setInterleaveDuration(uint32_t duration); 55 56protected: 57 virtual ~MPEG4Writer(); 58 59private: 60 class Track; 61 62 FILE *mFile; 63 bool mPaused; 64 bool mStarted; 65 off_t mOffset; 66 off_t mMdatOffset; 67 uint8_t *mMoovBoxBuffer; 68 off_t mMoovBoxBufferOffset; 69 bool mWriteMoovBoxToMemory; 70 off_t mFreeBoxOffset; 71 bool mStreamableFile; 72 off_t mEstimatedMoovBoxSize; 73 uint32_t mInterleaveDurationUs; 74 int64_t mStartTimestampUs; 75 Mutex mLock; 76 77 List<Track *> mTracks; 78 79 List<off_t> mBoxes; 80 81 void setStartTimestampUs(int64_t timeUs); 82 int64_t getStartTimestampUs(); // Not const 83 status_t startTracks(); 84 85 void lock(); 86 void unlock(); 87 88 // Acquire lock before calling these methods 89 off_t addSample_l(MediaBuffer *buffer); 90 off_t addLengthPrefixedSample_l(MediaBuffer *buffer); 91 92 inline size_t write(const void *ptr, size_t size, size_t nmemb, FILE* stream); 93 bool exceedsFileSizeLimit(); 94 bool exceedsFileDurationLimit(); 95 96 MPEG4Writer(const MPEG4Writer &); 97 MPEG4Writer &operator=(const MPEG4Writer &); 98}; 99 100} // namespace android 101 102#endif // MPEG4_WRITER_H_ 103