Home | History | Annotate | Download | only in stagefright
      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);
     37     virtual status_t stop() { return reset(); }
     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 mAACProfile;
     63     int32_t mFrameDurationUs;
     64 
     65     static void *ThreadWrapper(void *);
     66     status_t threadFunc();
     67     bool exceedsFileSizeLimit();
     68     bool exceedsFileDurationLimit();
     69     status_t writeAdtsHeader(uint32_t frameLength);
     70     status_t reset();
     71 
     72     DISALLOW_EVIL_CONSTRUCTORS(AACWriter);
     73 };
     74 
     75 }  // namespace android
     76 
     77 #endif  // AAC_WRITER_H_
     78