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_AMRNB_ENCODER_H_
18
19#define SOFT_AMRNB_ENCODER_H_
20
21#include "SimpleSoftOMXComponent.h"
22
23namespace android {
24
25struct SoftAMRNBEncoder : public SimpleSoftOMXComponent {
26    SoftAMRNBEncoder(
27            const char *name,
28            const OMX_CALLBACKTYPE *callbacks,
29            OMX_PTR appData,
30            OMX_COMPONENTTYPE **component);
31
32protected:
33    virtual ~SoftAMRNBEncoder();
34
35    virtual OMX_ERRORTYPE internalGetParameter(
36            OMX_INDEXTYPE index, OMX_PTR params);
37
38    virtual OMX_ERRORTYPE internalSetParameter(
39            OMX_INDEXTYPE index, const OMX_PTR params);
40
41    virtual void onQueueFilled(OMX_U32 portIndex);
42
43private:
44    enum {
45        kNumBuffers             = 4,
46        kNumSamplesPerFrame     = 160,
47    };
48
49    void *mEncState;
50    void *mSidState;
51
52    OMX_U32 mBitRate;
53    int mMode;
54
55    size_t mInputSize;
56    int16_t mInputFrame[kNumSamplesPerFrame];
57    int64_t mInputTimeUs;
58
59    bool mSawInputEOS;
60    bool mSignalledError;
61
62    void initPorts();
63    status_t initEncoder();
64
65    status_t setAudioParams();
66
67    DISALLOW_EVIL_CONSTRUCTORS(SoftAMRNBEncoder);
68};
69
70}  // namespace android
71
72#endif  // SOFT_AMRNB_ENCODER_H_
73