blob: a7c9ecf7c504412a02f0c621a4de81af4e447a01 [file] [log] [blame]
Andreas Huberc751ecc2010-09-27 12:04:43 -07001/*
2 * Copyright (C) 2010 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 MPEG2TS_WRITER_H_
18
19#define MPEG2TS_WRITER_H_
20
21#include <media/stagefright/foundation/ABase.h>
22#include <media/stagefright/foundation/AHandlerReflector.h>
23#include <media/stagefright/foundation/ALooper.h>
24#include <media/stagefright/MediaWriter.h>
25
26namespace android {
27
Andreas Huber9adf4662010-10-12 14:17:45 -070028struct ABuffer;
29
Andreas Huberc751ecc2010-09-27 12:04:43 -070030struct MPEG2TSWriter : public MediaWriter {
Andreas Huber9adf4662010-10-12 14:17:45 -070031 MPEG2TSWriter(int fd);
Andreas Huberc751ecc2010-09-27 12:04:43 -070032 MPEG2TSWriter(const char *filename);
33
Andreas Huber068dbbf2011-06-27 15:47:56 -070034 MPEG2TSWriter(
35 void *cookie,
36 ssize_t (*write)(void *cookie, const void *data, size_t size));
37
Andreas Huberc751ecc2010-09-27 12:04:43 -070038 virtual status_t addSource(const sp<MediaSource> &source);
39 virtual status_t start(MetaData *param = NULL);
James Dongc2240b12012-02-02 15:07:52 -080040 virtual status_t stop() { return reset(); }
Andreas Huberc751ecc2010-09-27 12:04:43 -070041 virtual status_t pause();
42 virtual bool reachedEOS();
43 virtual status_t dump(int fd, const Vector<String16>& args);
44
45 void onMessageReceived(const sp<AMessage> &msg);
46
47protected:
48 virtual ~MPEG2TSWriter();
49
50private:
51 enum {
52 kWhatSourceNotify = 'noti'
53 };
54
55 struct SourceInfo;
56
57 FILE *mFile;
Andreas Huber068dbbf2011-06-27 15:47:56 -070058
59 void *mWriteCookie;
60 ssize_t (*mWriteFunc)(void *cookie, const void *data, size_t size);
61
Andreas Huberc751ecc2010-09-27 12:04:43 -070062 sp<ALooper> mLooper;
63 sp<AHandlerReflector<MPEG2TSWriter> > mReflector;
64
65 bool mStarted;
66
67 Vector<sp<SourceInfo> > mSources;
68 size_t mNumSourcesDone;
69
70 int64_t mNumTSPacketsWritten;
71 int64_t mNumTSPacketsBeforeMeta;
72
Andreas Huber9adf4662010-10-12 14:17:45 -070073 void init();
74
Andreas Huberc751ecc2010-09-27 12:04:43 -070075 void writeTS();
76 void writeProgramAssociationTable();
77 void writeProgramMap();
78 void writeAccessUnit(int32_t sourceIndex, const sp<ABuffer> &buffer);
79
Andreas Huber068dbbf2011-06-27 15:47:56 -070080 ssize_t internalWrite(const void *data, size_t size);
James Dongc2240b12012-02-02 15:07:52 -080081 status_t reset();
Andreas Huber068dbbf2011-06-27 15:47:56 -070082
Andreas Huberc751ecc2010-09-27 12:04:43 -070083 DISALLOW_EVIL_CONSTRUCTORS(MPEG2TSWriter);
84};
85
86} // namespace android
87
88#endif // MPEG2TS_WRITER_H_