SoftAAC2.h revision d4838ed14a169f5981c0adc2edcb24559a913fe6
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    int64_t mAnchorTimeUs[kNumDelayBlocksMax];
62
63    CDrcPresModeWrapper mDrcWrap;
64
65    enum {
66        NONE,
67        AWAITING_DISABLED,
68        AWAITING_ENABLED
69    } mOutputPortSettingsChange;
70
71    void initPorts();
72    status_t initDecoder();
73    bool isConfigured() const;
74    void configureDownmix() const;
75    void drainDecoder();
76
77//      delay compensation
78    bool mEndOfInput;
79    bool mEndOfOutput;
80    int32_t mOutputDelayCompensated;
81    int32_t mOutputDelayRingBufferSize;
82    short *mOutputDelayRingBuffer;
83    int32_t mOutputDelayRingBufferWritePos;
84    int32_t mOutputDelayRingBufferReadPos;
85    bool outputDelayRingBufferPutSamples(INT_PCM *samples, int numSamples);
86    int32_t outputDelayRingBufferGetSamples(INT_PCM *samples, int numSamples);
87    int32_t outputDelayRingBufferSamplesAvailable();
88    int32_t outputDelayRingBufferSamplesLeft();
89
90    DISALLOW_EVIL_CONSTRUCTORS(SoftAAC2);
91};
92
93}  // namespace android
94
95#endif  // SOFT_AAC_2_H_
96