James Dong | f84bfab | 2011-03-21 14:29:38 -0700 | [diff] [blame] | 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 <media/stagefright/MediaWriter.h> |
| 21 | #include <utils/threads.h> |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | struct MediaSource; |
| 26 | struct MetaData; |
| 27 | |
| 28 | struct AACWriter : public MediaWriter { |
| 29 | AACWriter(const char *filename); |
| 30 | AACWriter(int fd); |
| 31 | |
| 32 | status_t initCheck() const; |
| 33 | |
| 34 | virtual status_t addSource(const sp<MediaSource> &source); |
| 35 | virtual bool reachedEOS(); |
| 36 | virtual status_t start(MetaData *params = NULL); |
James Dong | c2240b1 | 2012-02-02 15:07:52 -0800 | [diff] [blame] | 37 | virtual status_t stop() { return reset(); } |
James Dong | f84bfab | 2011-03-21 14:29:38 -0700 | [diff] [blame] | 38 | virtual status_t pause(); |
| 39 | |
| 40 | protected: |
| 41 | virtual ~AACWriter(); |
| 42 | |
| 43 | private: |
| 44 | enum { |
| 45 | kAdtsHeaderLength = 7, // # of bytes for the adts header |
| 46 | kSamplesPerFrame = 1024, // # of samples in a frame |
| 47 | }; |
| 48 | |
| 49 | int mFd; |
| 50 | status_t mInitCheck; |
| 51 | sp<MediaSource> mSource; |
| 52 | bool mStarted; |
| 53 | volatile bool mPaused; |
| 54 | volatile bool mResumed; |
| 55 | volatile bool mDone; |
| 56 | volatile bool mReachedEOS; |
| 57 | pthread_t mThread; |
| 58 | int64_t mEstimatedSizeBytes; |
| 59 | int64_t mEstimatedDurationUs; |
| 60 | int32_t mChannelCount; |
| 61 | int32_t mSampleRate; |
| 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); |
James Dong | c2240b1 | 2012-02-02 15:07:52 -0800 | [diff] [blame] | 69 | status_t reset(); |
James Dong | f84bfab | 2011-03-21 14:29:38 -0700 | [diff] [blame] | 70 | |
| 71 | DISALLOW_EVIL_CONSTRUCTORS(AACWriter); |
| 72 | }; |
| 73 | |
| 74 | } // namespace android |
| 75 | |
| 76 | #endif // AAC_WRITER_H_ |