1/*
2 * Copyright (C) 2014 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/*
18 * The Opus specification is part of IETF RFC 6716:
19 * http://tools.ietf.org/html/rfc6716
20 */
21
22#ifndef SOFT_OPUS_H_
23
24#define SOFT_OPUS_H_
25
26#include "SimpleSoftOMXComponent.h"
27
28struct OpusMSDecoder;
29
30namespace android {
31
32struct OpusHeader {
33  int channels;
34  int skip_samples;
35  int channel_mapping;
36  int num_streams;
37  int num_coupled;
38  int16_t gain_db;
39  uint8_t stream_map[8];
40};
41
42struct SoftOpus : public SimpleSoftOMXComponent {
43    SoftOpus(const char *name,
44             const OMX_CALLBACKTYPE *callbacks,
45             OMX_PTR appData,
46             OMX_COMPONENTTYPE **component);
47
48protected:
49    virtual ~SoftOpus();
50
51    virtual OMX_ERRORTYPE internalGetParameter(
52            OMX_INDEXTYPE index, OMX_PTR params);
53
54    virtual OMX_ERRORTYPE internalSetParameter(
55            OMX_INDEXTYPE index, const OMX_PTR params);
56
57    virtual void onQueueFilled(OMX_U32 portIndex);
58    virtual void onPortFlushCompleted(OMX_U32 portIndex);
59    virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
60    virtual void onReset();
61
62private:
63    enum {
64        kNumBuffers = 4,
65        kMaxNumSamplesPerBuffer = 960 * 6
66    };
67
68    size_t mInputBufferCount;
69
70    OpusMSDecoder *mDecoder;
71    OpusHeader *mHeader;
72
73    int64_t mCodecDelay;
74    int64_t mSeekPreRoll;
75    int64_t mSamplesToDiscard;
76    int64_t mAnchorTimeUs;
77    int64_t mNumFramesOutput;
78
79    enum {
80        NONE,
81        AWAITING_DISABLED,
82        AWAITING_ENABLED
83    } mOutputPortSettingsChange;
84
85    void initPorts();
86    status_t initDecoder();
87    bool isConfigured() const;
88
89    DISALLOW_EVIL_CONSTRUCTORS(SoftOpus);
90};
91
92}  // namespace android
93
94#endif  // SOFT_OPUS_H_
95