OSDN Git Service

add support for wmv1
[android-x86/external-stagefright-plugins.git] / libstagefright / codecs / ffmpegdec / adec / SoftFFmpegAudio.h
1 /*
2  * Copyright 2012 Michael Chen <omxcodec@gmail.com>
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_FFMPEGAUDIO_H_
18
19 #define SOFT_FFMPEGAUDIO_H_
20
21 #include "SimpleSoftOMXComponent.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #include <inttypes.h>
28 #include <math.h>
29 #include <signal.h>
30 #include <limits.h> /* INT_MAX */
31
32 #include "config.h"
33 #include "libavutil/avstring.h"
34 #include "libavutil/colorspace.h"
35 #include "libavutil/mathematics.h"
36 #include "libavutil/pixdesc.h"
37 #include "libavutil/imgutils.h"
38 #include "libavutil/dict.h"
39 #include "libavutil/parseutils.h"
40 #include "libavutil/samplefmt.h"
41 #include "libavutil/avassert.h"
42 #include "libavutil/intreadwrite.h"
43 #include "libavformat/avformat.h"
44 #include "libavdevice/avdevice.h"
45 #include "libswscale/swscale.h"
46 #include "libavcodec/audioconvert.h"
47 #include "libavutil/opt.h"
48 #include "libavutil/internal.h"
49 #include "libavcodec/avfft.h"
50 #include "libswresample/swresample.h"
51
52 #include "cmdutils.h"
53
54 #include <SDL.h>
55 #include <SDL_thread.h>
56
57 #ifdef __cplusplus
58 }
59 #endif
60
61 namespace android {
62
63 struct SoftFFmpegAudio : public SimpleSoftOMXComponent {
64     SoftFFmpegAudio(const char *name,
65             const OMX_CALLBACKTYPE *callbacks,
66             OMX_PTR appData,
67             OMX_COMPONENTTYPE **component);
68
69 protected:
70     virtual ~SoftFFmpegAudio();
71
72     virtual OMX_ERRORTYPE internalGetParameter(
73             OMX_INDEXTYPE index, OMX_PTR params);
74
75     virtual OMX_ERRORTYPE internalSetParameter(
76             OMX_INDEXTYPE index, const OMX_PTR params);
77
78     virtual void onQueueFilled(OMX_U32 portIndex);
79     virtual void onPortFlushCompleted(OMX_U32 portIndex);
80     virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
81
82 private:
83     enum {
84         kNumBuffers = 4,
85         kOutputBufferSize = 4608 * 2
86     };
87
88     enum {
89         MODE_MPEG,
90         MODE_MPEGL1,
91         MODE_MPEGL2,
92         MODE_AAC,
93         MODE_AC3,
94         MODE_APE,
95         MODE_WMA,
96         MODE_DTS,
97         MODE_RA
98     } mMode;
99
100     enum {
101         kPortIndexInput  = 0,
102         kPortIndexOutput = 1,
103     };
104
105     AVCodecContext *mCtx;
106     struct SwrContext *mSwrCtx;
107
108     bool mCodecOpened;
109     bool mExtradataReady;
110     bool mIgnoreExtradata;
111     bool mFlushComplete;
112     bool mSignalledError;
113     bool mReceivedEOS;
114
115     AVFrame *mFrame;
116
117     int64_t mAnchorTimeUs;
118     int64_t mNumFramesOutput;
119     int32_t mInputBufferSize;
120
121     uint8_t mSilenceBuffer[kOutputBufferSize];
122     DECLARE_ALIGNED(16, uint8_t, mAudioBuf2)[AVCODEC_MAX_AUDIO_FRAME_SIZE * 4];
123     uint8_t *mPAudioBuffer;
124     int32_t mAudioBufferSize;
125
126     int32_t mNumChannels;
127     int32_t mSamplingRate;
128     AVSampleFormat mSamplingFmt;
129     bool mAudioConfigChanged;
130
131     enum AVSampleFormat mAudioSrcFmt;
132     enum AVSampleFormat mAudioTgtFmt;
133     int mAudioSrcChannels;
134     int mAudioTgtChannels;
135     int64_t mAudioSrcChannelLayout;
136     int64_t mAudioTgtChannelLayout;
137     int mAudioSrcFreq;
138     int mAudioTgtFreq;
139
140     enum {
141         NONE,
142         AWAITING_DISABLED,
143         AWAITING_ENABLED
144     } mOutputPortSettingsChange;
145
146     void setAVCtxToDefault(AVCodecContext *avctx, const AVCodec *codec);
147
148     void initPorts();
149     status_t initDecoder();
150     void deInitDecoder();
151
152     DISALLOW_EVIL_CONSTRUCTORS(SoftFFmpegAudio);
153 };
154
155 }  // namespace android
156
157 #endif  // SOFT_FFMPEGAUDIO_H_
158
159