1760943b5e7a09b602aba04ec451e97662f48b0a4James Dong/* 2760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * Copyright (C) 2011 The Android Open Source Project 3760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * 4760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * Licensed under the Apache License, Version 2.0 (the "License"); 5760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * you may not use this file except in compliance with the License. 6760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * You may obtain a copy of the License at 7760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * 8760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * http://www.apache.org/licenses/LICENSE-2.0 9760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * 10760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * Unless required by applicable law or agreed to in writing, software 11760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * distributed under the License is distributed on an "AS IS" BASIS, 12760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * See the License for the specific language governing permissions and 14760943b5e7a09b602aba04ec451e97662f48b0a4James Dong * limitations under the License. 15760943b5e7a09b602aba04ec451e97662f48b0a4James Dong */ 16760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 17760943b5e7a09b602aba04ec451e97662f48b0a4James Dong#ifndef AAC_WRITER_H_ 18760943b5e7a09b602aba04ec451e97662f48b0a4James Dong#define AAC_WRITER_H_ 19760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 20760943b5e7a09b602aba04ec451e97662f48b0a4James Dong#include <media/stagefright/MediaWriter.h> 21760943b5e7a09b602aba04ec451e97662f48b0a4James Dong#include <utils/threads.h> 22760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 23760943b5e7a09b602aba04ec451e97662f48b0a4James Dongnamespace android { 24760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 25760943b5e7a09b602aba04ec451e97662f48b0a4James Dongstruct MediaSource; 26760943b5e7a09b602aba04ec451e97662f48b0a4James Dongstruct MetaData; 27760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 28760943b5e7a09b602aba04ec451e97662f48b0a4James Dongstruct AACWriter : public MediaWriter { 29760943b5e7a09b602aba04ec451e97662f48b0a4James Dong AACWriter(const char *filename); 30760943b5e7a09b602aba04ec451e97662f48b0a4James Dong AACWriter(int fd); 31760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 32760943b5e7a09b602aba04ec451e97662f48b0a4James Dong status_t initCheck() const; 33760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 34760943b5e7a09b602aba04ec451e97662f48b0a4James Dong virtual status_t addSource(const sp<MediaSource> &source); 35760943b5e7a09b602aba04ec451e97662f48b0a4James Dong virtual bool reachedEOS(); 36760943b5e7a09b602aba04ec451e97662f48b0a4James Dong virtual status_t start(MetaData *params = NULL); 378bcc65c753085fe3328592cceda0cf0e8f8b0a45James Dong virtual status_t stop() { return reset(); } 38760943b5e7a09b602aba04ec451e97662f48b0a4James Dong virtual status_t pause(); 39760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 40760943b5e7a09b602aba04ec451e97662f48b0a4James Dongprotected: 41760943b5e7a09b602aba04ec451e97662f48b0a4James Dong virtual ~AACWriter(); 42760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 43760943b5e7a09b602aba04ec451e97662f48b0a4James Dongprivate: 44760943b5e7a09b602aba04ec451e97662f48b0a4James Dong enum { 45760943b5e7a09b602aba04ec451e97662f48b0a4James Dong kAdtsHeaderLength = 7, // # of bytes for the adts header 46760943b5e7a09b602aba04ec451e97662f48b0a4James Dong kSamplesPerFrame = 1024, // # of samples in a frame 47760943b5e7a09b602aba04ec451e97662f48b0a4James Dong }; 48760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 49760943b5e7a09b602aba04ec451e97662f48b0a4James Dong int mFd; 50760943b5e7a09b602aba04ec451e97662f48b0a4James Dong status_t mInitCheck; 51760943b5e7a09b602aba04ec451e97662f48b0a4James Dong sp<MediaSource> mSource; 52760943b5e7a09b602aba04ec451e97662f48b0a4James Dong bool mStarted; 53760943b5e7a09b602aba04ec451e97662f48b0a4James Dong volatile bool mPaused; 54760943b5e7a09b602aba04ec451e97662f48b0a4James Dong volatile bool mResumed; 55760943b5e7a09b602aba04ec451e97662f48b0a4James Dong volatile bool mDone; 56760943b5e7a09b602aba04ec451e97662f48b0a4James Dong volatile bool mReachedEOS; 57760943b5e7a09b602aba04ec451e97662f48b0a4James Dong pthread_t mThread; 58760943b5e7a09b602aba04ec451e97662f48b0a4James Dong int64_t mEstimatedSizeBytes; 59760943b5e7a09b602aba04ec451e97662f48b0a4James Dong int64_t mEstimatedDurationUs; 60760943b5e7a09b602aba04ec451e97662f48b0a4James Dong int32_t mChannelCount; 61760943b5e7a09b602aba04ec451e97662f48b0a4James Dong int32_t mSampleRate; 62aeb8fd460ed87d032b3fb8bb61e21eb542ce0f5bDave Burke int32_t mAACProfile; 63760943b5e7a09b602aba04ec451e97662f48b0a4James Dong int32_t mFrameDurationUs; 64760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 65760943b5e7a09b602aba04ec451e97662f48b0a4James Dong static void *ThreadWrapper(void *); 66760943b5e7a09b602aba04ec451e97662f48b0a4James Dong status_t threadFunc(); 67760943b5e7a09b602aba04ec451e97662f48b0a4James Dong bool exceedsFileSizeLimit(); 68760943b5e7a09b602aba04ec451e97662f48b0a4James Dong bool exceedsFileDurationLimit(); 69760943b5e7a09b602aba04ec451e97662f48b0a4James Dong status_t writeAdtsHeader(uint32_t frameLength); 708bcc65c753085fe3328592cceda0cf0e8f8b0a45James Dong status_t reset(); 71760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 72760943b5e7a09b602aba04ec451e97662f48b0a4James Dong DISALLOW_EVIL_CONSTRUCTORS(AACWriter); 73760943b5e7a09b602aba04ec451e97662f48b0a4James Dong}; 74760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 75760943b5e7a09b602aba04ec451e97662f48b0a4James Dong} // namespace android 76760943b5e7a09b602aba04ec451e97662f48b0a4James Dong 77760943b5e7a09b602aba04ec451e97662f48b0a4James Dong#endif // AAC_WRITER_H_ 78