xref: /aosp_15_r20/frameworks/av/media/libstagefright/codecs/opus/dec/SoftOpus.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
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 <media/stagefright/omx/SimpleSoftOMXComponent.h>
27 
28 struct OpusMSDecoder;
29 
30 namespace android {
31 
32 struct 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 
42 struct SoftOpus : public SimpleSoftOMXComponent {
43     SoftOpus(const char *name,
44              const OMX_CALLBACKTYPE *callbacks,
45              OMX_PTR appData,
46              OMX_COMPONENTTYPE **component);
47 
48 protected:
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 
62 private:
63     enum {
64         kNumBuffers = 4,
65         kMaxNumSamplesPerBuffer = 960 * 6
66     };
67 
68     size_t mInputBufferCount;
69 
70     OpusMSDecoder *mDecoder;
71     OpusHeader *mHeader;
72 
73     int32_t mNumChannels;
74     int32_t mSamplingRate;
75     int64_t mCodecDelay;
76     int64_t mSeekPreRoll;
77     int64_t mSamplesToDiscard;
78     int64_t mAnchorTimeUs;
79     int64_t mNumFramesOutput;
80     bool mHaveEOS;
81 
82     enum {
83         NONE,
84         AWAITING_DISABLED,
85         AWAITING_ENABLED
86     } mOutputPortSettingsChange;
87 
88     void initPorts();
89     status_t initDecoder();
90     bool isConfigured() const;
91     void handleEOS();
92 
93     DISALLOW_EVIL_CONSTRUCTORS(SoftOpus);
94 };
95 
96 }  // namespace android
97 
98 #endif  // SOFT_OPUS_H_
99