SoftAAC2.h revision fa20a1db4be377a004efd756887f8b212e31d670
12aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim/*
22aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim * Copyright (C) 2012 The Android Open Source Project
32aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim *
42aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim * Licensed under the Apache License, Version 2.0 (the "License");
52aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim * you may not use this file except in compliance with the License.
62aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim * You may obtain a copy of the License at
72aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim *
82aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim *      http://www.apache.org/licenses/LICENSE-2.0
92aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim *
102aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim * Unless required by applicable law or agreed to in writing, software
112aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim * distributed under the License is distributed on an "AS IS" BASIS,
122aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim * See the License for the specific language governing permissions and
142aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim * limitations under the License.
152aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim */
162aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
172aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim#ifndef SOFT_AAC_2_H_
182aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim#define SOFT_AAC_2_H_
192aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
202aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim#include "SimpleSoftOMXComponent.h"
212aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
222aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim#include "aacdecoder_lib.h"
232aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim#include "DrcPresModeWrap.h"
242aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
252aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kimnamespace android {
262aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
272aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kimstruct SoftAAC2 : public SimpleSoftOMXComponent {
282aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    SoftAAC2(const char *name,
292aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim            const OMX_CALLBACKTYPE *callbacks,
302aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim            OMX_PTR appData,
312aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim            OMX_COMPONENTTYPE **component);
322aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
332aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kimprotected:
342aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    virtual ~SoftAAC2();
352aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
362aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    virtual OMX_ERRORTYPE internalGetParameter(
372aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim            OMX_INDEXTYPE index, OMX_PTR params);
382aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
392aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    virtual OMX_ERRORTYPE internalSetParameter(
402aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim            OMX_INDEXTYPE index, const OMX_PTR params);
412aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
422aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    virtual void onQueueFilled(OMX_U32 portIndex);
432aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    virtual void onPortFlushCompleted(OMX_U32 portIndex);
442aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
452aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    virtual void onReset();
462aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
472aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kimprivate:
482aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    enum {
492aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim        kNumInputBuffers        = 4,
502aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim        kNumOutputBuffers       = 4,
512aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim        kNumDelayBlocksMax      = 8,
522aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    };
532aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
542aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    HANDLE_AACDECODER mAACDecoder;
552aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    CStreamInfo *mStreamInfo;
562aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    bool mIsADTS;
572aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    bool mIsFirst;
582aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    size_t mInputBufferCount;
592aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    size_t mOutputBufferCount;
602aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    bool mSignalledError;
612aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    OMX_BUFFERHEADERTYPE *mLastInHeader;
622aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    Vector<int32_t> mBufferSizes;
632aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    Vector<int32_t> mDecodedSizes;
642aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    Vector<int64_t> mBufferTimestamps;
652aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
662aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    CDrcPresModeWrapper mDrcWrap;
672aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
682aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    enum {
692aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim        NONE,
702aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim        AWAITING_DISABLED,
712aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim        AWAITING_ENABLED
722aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    } mOutputPortSettingsChange;
732aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
742aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    void initPorts();
752aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    status_t initDecoder();
762aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    bool isConfigured() const;
772aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    void configureDownmix() const;
782aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    void drainDecoder();
792aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
802aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim//      delay compensation
812aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    bool mEndOfInput;
822aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    bool mEndOfOutput;
832aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    int32_t mOutputDelayCompensated;
842aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    int32_t mOutputDelayRingBufferSize;
852aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    short *mOutputDelayRingBuffer;
862aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    int32_t mOutputDelayRingBufferWritePos;
872aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    int32_t mOutputDelayRingBufferReadPos;
882aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    bool outputDelayRingBufferPutSamples(INT_PCM *samples, int numSamples);
892aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    int32_t outputDelayRingBufferGetSamples(INT_PCM *samples, int numSamples);
902aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    int32_t outputDelayRingBufferSamplesAvailable();
912aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    int32_t outputDelayRingBufferSamplesLeft();
922aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
932aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim    DISALLOW_EVIL_CONSTRUCTORS(SoftAAC2);
942aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim};
952aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
962aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim}  // namespace android
972aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim
982aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim#endif  // SOFT_AAC_2_H_
992aca5ff9f1e2b779fb71eb7af45b2fc8e65a5ba2Hyojun Kim