• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     int64_t mCodecDelay;
74     int64_t mSeekPreRoll;
75     int64_t mSamplesToDiscard;
76     int64_t mAnchorTimeUs;
77     int64_t mNumFramesOutput;
78     bool mHaveEOS;
79 
80     enum {
81         NONE,
82         AWAITING_DISABLED,
83         AWAITING_ENABLED
84     } mOutputPortSettingsChange;
85 
86     void initPorts();
87     status_t initDecoder();
88     bool isConfigured() const;
89     void handleEOS();
90 
91     DISALLOW_EVIL_CONSTRUCTORS(SoftOpus);
92 };
93 
94 }  // namespace android
95 
96 #endif  // SOFT_OPUS_H_
97