1 /* 2 * Copyright (C) 2011 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 AAC_WRITER_H_ 18 #define AAC_WRITER_H_ 19 20 #include "foundation/ABase.h" 21 #include <media/stagefright/MediaWriter.h> 22 #include <utils/threads.h> 23 24 namespace android { 25 26 struct MediaSource; 27 28 struct AACWriter : public MediaWriter { 29 AACWriter(int fd); 30 31 status_t initCheck() const; 32 33 virtual status_t addSource(const sp<MediaSource> &source); 34 virtual bool reachedEOS(); 35 virtual status_t start(MetaData *params = NULL); stopAACWriter36 virtual status_t stop() { return reset(); } 37 virtual status_t pause(); 38 39 protected: 40 virtual ~AACWriter(); 41 42 private: 43 enum { 44 kAdtsHeaderLength = 7, // # of bytes for the adts header 45 kSamplesPerFrame = 1024, // # of samples in a frame 46 }; 47 48 int mFd; 49 status_t mInitCheck; 50 sp<MediaSource> mSource; 51 bool mStarted; 52 volatile bool mPaused; 53 volatile bool mResumed; 54 volatile bool mDone; 55 volatile bool mReachedEOS; 56 pthread_t mThread; 57 int64_t mEstimatedSizeBytes; 58 int64_t mEstimatedDurationUs; 59 int32_t mChannelCount; 60 int32_t mSampleRate; 61 int32_t mAACProfile; 62 int32_t mFrameDurationUs; 63 64 static void *ThreadWrapper(void *); 65 status_t threadFunc(); 66 bool exceedsFileSizeLimit(); 67 bool exceedsFileDurationLimit(); 68 status_t writeAdtsHeader(uint32_t frameLength); 69 status_t reset(); 70 71 DISALLOW_EVIL_CONSTRUCTORS(AACWriter); 72 }; 73 74 } // namespace android 75 76 #endif // AAC_WRITER_H_ 77