blob: 392f968834377297830eccec7afc90fd49639906 [file] [log] [blame]
Andreas Huber07bf09d2010-01-25 14:27:12 -08001/*
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 AMR_WRITER_H_
18
19#define AMR_WRITER_H_
20
21#include <stdio.h>
22
Andreas Huber996dddf2010-01-25 15:30:31 -080023#include <media/stagefright/MediaWriter.h>
Andreas Huber07bf09d2010-01-25 14:27:12 -080024#include <utils/threads.h>
25
26namespace android {
27
28struct MediaSource;
James Dong6feaa462010-06-20 08:20:54 -070029struct MetaData;
Andreas Huber07bf09d2010-01-25 14:27:12 -080030
Andreas Huber996dddf2010-01-25 15:30:31 -080031struct AMRWriter : public MediaWriter {
Andreas Huber07bf09d2010-01-25 14:27:12 -080032 AMRWriter(const char *filename);
33 AMRWriter(int fd);
34
35 status_t initCheck() const;
36
Andreas Huber996dddf2010-01-25 15:30:31 -080037 virtual status_t addSource(const sp<MediaSource> &source);
38 virtual bool reachedEOS();
James Dong6feaa462010-06-20 08:20:54 -070039 virtual status_t start(MetaData *params = NULL);
James Dongc2240b12012-02-02 15:07:52 -080040 virtual status_t stop() { return reset(); }
James Dongd0366622010-08-18 19:10:39 -070041 virtual status_t pause();
Andreas Huber07bf09d2010-01-25 14:27:12 -080042
43protected:
44 virtual ~AMRWriter();
45
46private:
James Dongb1262a82010-11-16 14:04:54 -080047 int mFd;
Andreas Huber07bf09d2010-01-25 14:27:12 -080048 status_t mInitCheck;
49 sp<MediaSource> mSource;
50 bool mStarted;
James Dong08c74732010-06-10 12:28:15 -070051 volatile bool mPaused;
52 volatile bool mResumed;
Andreas Huber07bf09d2010-01-25 14:27:12 -080053 volatile bool mDone;
Andreas Hubere2018ca2010-03-23 14:33:02 -070054 volatile bool mReachedEOS;
Andreas Huber07bf09d2010-01-25 14:27:12 -080055 pthread_t mThread;
James Dong18244862010-05-11 14:57:02 -070056 int64_t mEstimatedSizeBytes;
57 int64_t mEstimatedDurationUs;
Andreas Huber07bf09d2010-01-25 14:27:12 -080058
59 static void *ThreadWrapper(void *);
James Dongd0366622010-08-18 19:10:39 -070060 status_t threadFunc();
James Dong18244862010-05-11 14:57:02 -070061 bool exceedsFileSizeLimit();
62 bool exceedsFileDurationLimit();
James Dongc2240b12012-02-02 15:07:52 -080063 status_t reset();
Andreas Huber07bf09d2010-01-25 14:27:12 -080064
65 AMRWriter(const AMRWriter &);
66 AMRWriter &operator=(const AMRWriter &);
67};
68
69} // namespace android
70
71#endif // AMR_WRITER_H_