MPEG4Writer.h revision 20111aa043c5f404472bc63b90bc5aad906b1101
120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber/*
220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * Copyright (C) 2009 The Android Open Source Project
320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber *
420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * you may not use this file except in compliance with the License.
620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * You may obtain a copy of the License at
720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber *
820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber *
1020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * Unless required by applicable law or agreed to in writing, software
1120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
1220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * See the License for the specific language governing permissions and
1420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * limitations under the License.
1520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber */
1620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
1720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#ifndef MPEG4_WRITER_H_
1820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
1920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#define MPEG4_WRITER_H_
2020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
2120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#include <stdio.h>
2220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
2320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#include <utils/List.h>
2420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#include <utils/RefBase.h>
2520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#include <utils/threads.h>
2620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
2720111aa043c5f404472bc63b90bc5aad906b1101Andreas Hubernamespace android {
2820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
2920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberclass MediaBuffer;
3020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberclass MediaSource;
3120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberclass MetaData;
3220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
3320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberclass MPEG4Writer {
3420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberpublic:
3520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    MPEG4Writer(const char *filename);
3620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    ~MPEG4Writer();
3720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
3820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    // Caller retains ownership of both meta and source.
3920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void addSource(const sp<MetaData> &meta, MediaSource *source);
4020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void start();
4120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void stop();
4220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
4320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void beginBox(const char *fourcc);
4420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void writeInt8(int8_t x);
4520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void writeInt16(int16_t x);
4620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void writeInt32(int32_t x);
4720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void writeInt64(int64_t x);
4820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void writeCString(const char *s);
4920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void writeFourcc(const char *fourcc);
5020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void write(const void *data, size_t size);
5120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    void endBox();
5220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
5320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberprivate:
5420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    class Track;
5520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
5620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    FILE *mFile;
5720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    off_t mOffset;
5820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    off_t mMdatOffset;
5920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    Mutex mLock;
6020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
6120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    List<Track *> mTracks;
6220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
6320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    List<off_t> mBoxes;
6420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
6520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    off_t addSample(MediaBuffer *buffer);
6620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
6720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    MPEG4Writer(const MPEG4Writer &);
6820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber    MPEG4Writer &operator=(const MPEG4Writer &);
6920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber};
7020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
7120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber}  // namespace android
7220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber
7320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#endif  // MPEG4_WRITER_H_
74