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
20dff843f2fae88c10fe18d2925a4e802a35d74433Bernhard Rosenkraenzer#include "foundation/ABase.h"
21760943b5e7a09b602aba04ec451e97662f48b0a4James Dong#include <media/stagefright/MediaWriter.h>
22760943b5e7a09b602aba04ec451e97662f48b0a4James Dong#include <utils/threads.h>
23760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
24760943b5e7a09b602aba04ec451e97662f48b0a4James Dongnamespace android {
25760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
26760943b5e7a09b602aba04ec451e97662f48b0a4James Dongstruct MediaSource;
27760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
28760943b5e7a09b602aba04ec451e97662f48b0a4James Dongstruct AACWriter : public MediaWriter {
29760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    AACWriter(int fd);
30760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
31760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    status_t initCheck() const;
32760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
33ba8128f9db82da66f28c6e6740d4721d80da954eDongwon Kang    virtual status_t addSource(const sp<MediaSource> &source);
34760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    virtual bool reachedEOS();
35760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    virtual status_t start(MetaData *params = NULL);
368bcc65c753085fe3328592cceda0cf0e8f8b0a45James Dong    virtual status_t stop() { return reset(); }
37760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    virtual status_t pause();
38760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
39760943b5e7a09b602aba04ec451e97662f48b0a4James Dongprotected:
40760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    virtual ~AACWriter();
41760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
42760943b5e7a09b602aba04ec451e97662f48b0a4James Dongprivate:
43760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    enum {
44760943b5e7a09b602aba04ec451e97662f48b0a4James Dong        kAdtsHeaderLength = 7,     // # of bytes for the adts header
45760943b5e7a09b602aba04ec451e97662f48b0a4James Dong        kSamplesPerFrame  = 1024,  // # of samples in a frame
46760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    };
47760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
48760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    int   mFd;
49760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    status_t mInitCheck;
50ba8128f9db82da66f28c6e6740d4721d80da954eDongwon Kang    sp<MediaSource> mSource;
51760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    bool mStarted;
52760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    volatile bool mPaused;
53760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    volatile bool mResumed;
54760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    volatile bool mDone;
55760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    volatile bool mReachedEOS;
56760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    pthread_t mThread;
57760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    int64_t mEstimatedSizeBytes;
58760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    int64_t mEstimatedDurationUs;
59760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    int32_t mChannelCount;
60760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    int32_t mSampleRate;
61aeb8fd460ed87d032b3fb8bb61e21eb542ce0f5bDave Burke    int32_t mAACProfile;
62760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    int32_t mFrameDurationUs;
63760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
64760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    static void *ThreadWrapper(void *);
65760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    status_t threadFunc();
66760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    bool exceedsFileSizeLimit();
67760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    bool exceedsFileDurationLimit();
68760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    status_t writeAdtsHeader(uint32_t frameLength);
698bcc65c753085fe3328592cceda0cf0e8f8b0a45James Dong    status_t reset();
70760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
71760943b5e7a09b602aba04ec451e97662f48b0a4James Dong    DISALLOW_EVIL_CONSTRUCTORS(AACWriter);
72760943b5e7a09b602aba04ec451e97662f48b0a4James Dong};
73760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
74760943b5e7a09b602aba04ec451e97662f48b0a4James Dong}  // namespace android
75760943b5e7a09b602aba04ec451e97662f48b0a4James Dong
76760943b5e7a09b602aba04ec451e97662f48b0a4James Dong#endif  // AAC_WRITER_H_
77