SoftAAC2.h revision 8484830a6b488b41da0e32acacf2e6b68060d9d0
1/*
2 * Copyright (C) 2012 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 SOFT_AAC_2_H_
18#define SOFT_AAC_2_H_
19
20#include "SimpleSoftOMXComponent.h"
21
22#include "aacdecoder_lib.h"
23#include "DrcPresModeWrap.h"
24
25namespace android {
26
27struct SoftAAC2 : public SimpleSoftOMXComponent {
28    SoftAAC2(const char *name,
29            const OMX_CALLBACKTYPE *callbacks,
30            OMX_PTR appData,
31            OMX_COMPONENTTYPE **component);
32
33protected:
34    virtual ~SoftAAC2();
35
36    virtual OMX_ERRORTYPE internalGetParameter(
37            OMX_INDEXTYPE index, OMX_PTR params);
38
39    virtual OMX_ERRORTYPE internalSetParameter(
40            OMX_INDEXTYPE index, const OMX_PTR params);
41
42    virtual void onQueueFilled(OMX_U32 portIndex);
43    virtual void onPortFlushCompleted(OMX_U32 portIndex);
44    virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
45    virtual void onReset();
46
47private:
48    enum {
49        kNumInputBuffers        = 4,
50        kNumOutputBuffers       = 4,
51        kNumDelayBlocksMax      = 8,
52    };
53
54    HANDLE_AACDECODER mAACDecoder;
55    CStreamInfo *mStreamInfo;
56    bool mIsADTS;
57    bool mIsFirst;
58    size_t mInputBufferCount;
59    size_t mOutputBufferCount;
60    bool mSignalledError;
61    OMX_BUFFERHEADERTYPE *mLastInHeader;
62    int64_t mCurrentInputTime;
63    Vector<int64_t> mAnchorTimes;
64
65    CDrcPresModeWrapper mDrcWrap;
66
67    enum {
68        NONE,
69        AWAITING_DISABLED,
70        AWAITING_ENABLED
71    } mOutputPortSettingsChange;
72
73    void initPorts();
74    status_t initDecoder();
75    bool isConfigured() const;
76    void configureDownmix() const;
77    void drainDecoder();
78
79//      delay compensation
80    bool mEndOfInput;
81    bool mEndOfOutput;
82    int32_t mOutputDelayCompensated;
83    int32_t mOutputDelayRingBufferSize;
84    short *mOutputDelayRingBuffer;
85    int32_t mOutputDelayRingBufferWritePos;
86    int32_t mOutputDelayRingBufferReadPos;
87    bool outputDelayRingBufferPutSamples(INT_PCM *samples, int numSamples);
88    int32_t outputDelayRingBufferGetSamples(INT_PCM *samples, int numSamples);
89    int32_t outputDelayRingBufferSamplesAvailable();
90    int32_t outputDelayRingBufferSamplesLeft();
91
92    DISALLOW_EVIL_CONSTRUCTORS(SoftAAC2);
93};
94
95}  // namespace android
96
97#endif  // SOFT_AAC_2_H_
98