1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef A_CODEC_H_
#define A_CODEC_H_
#include <stdint.h>
#include <android/native_window.h>
#include <media/IOMX.h>
#include <media/stagefright/foundation/AHierarchicalStateMachine.h>
namespace android {
struct ABuffer;
struct MemoryDealer;
struct ACodec : public AHierarchicalStateMachine {
enum {
kWhatFillThisBuffer = 'fill',
kWhatDrainThisBuffer = 'drai',
kWhatEOS = 'eos ',
kWhatShutdownCompleted = 'scom',
kWhatFlushCompleted = 'fcom',
kWhatOutputFormatChanged = 'outC',
kWhatError = 'erro',
};
ACodec();
void setNotificationMessage(const sp<AMessage> &msg);
void initiateSetup(const sp<AMessage> &msg);
void signalFlush();
void signalResume();
void initiateShutdown();
protected:
virtual ~ACodec();
private:
struct BaseState;
struct UninitializedState;
struct LoadedToIdleState;
struct IdleToExecutingState;
struct ExecutingState;
struct OutputPortSettingsChangedState;
struct ExecutingToIdleState;
struct IdleToLoadedState;
struct FlushingState;
enum {
kWhatSetup = 'setu',
kWhatOMXMessage = 'omx ',
kWhatInputBufferFilled = 'inpF',
kWhatOutputBufferDrained = 'outD',
kWhatShutdown = 'shut',
kWhatFlush = 'flus',
kWhatResume = 'resm',
kWhatDrainDeferredMessages = 'drai',
};
enum {
kPortIndexInput = 0,
kPortIndexOutput = 1
};
struct BufferInfo {
enum Status {
OWNED_BY_US,
OWNED_BY_COMPONENT,
OWNED_BY_UPSTREAM,
OWNED_BY_DOWNSTREAM,
OWNED_BY_NATIVE_WINDOW,
};
IOMX::buffer_id mBufferID;
Status mStatus;
sp<ABuffer> mData;
sp<GraphicBuffer> mGraphicBuffer;
};
sp<AMessage> mNotify;
sp<UninitializedState> mUninitializedState;
sp<LoadedToIdleState> mLoadedToIdleState;
sp<IdleToExecutingState> mIdleToExecutingState;
sp<ExecutingState> mExecutingState;
sp<OutputPortSettingsChangedState> mOutputPortSettingsChangedState;
sp<ExecutingToIdleState> mExecutingToIdleState;
sp<IdleToLoadedState> mIdleToLoadedState;
sp<FlushingState> mFlushingState;
AString mComponentName;
sp<IOMX> mOMX;
IOMX::node_id mNode;
sp<MemoryDealer> mDealer[2];
sp<ANativeWindow> mNativeWindow;
Vector<BufferInfo> mBuffers[2];
bool mPortEOS[2];
status_t mInputEOSResult;
List<sp<AMessage> > mDeferredQueue;
bool mSentFormat;
status_t allocateBuffersOnPort(OMX_U32 portIndex);
status_t freeBuffersOnPort(OMX_U32 portIndex);
status_t freeBuffer(OMX_U32 portIndex, size_t i);
status_t allocateOutputBuffersFromNativeWindow();
status_t cancelBufferToNativeWindow(BufferInfo *info);
status_t freeOutputBuffersNotOwnedByComponent();
BufferInfo *dequeueBufferFromNativeWindow();
BufferInfo *findBufferByID(
uint32_t portIndex, IOMX::buffer_id bufferID,
ssize_t *index = NULL);
void setComponentRole(bool isEncoder, const char *mime);
void configureCodec(const char *mime, const sp<AMessage> &msg);
status_t setVideoPortFormatType(
OMX_U32 portIndex,
OMX_VIDEO_CODINGTYPE compressionFormat,
OMX_COLOR_FORMATTYPE colorFormat);
status_t setSupportedOutputFormat();
status_t setupVideoDecoder(
const char *mime, int32_t width, int32_t height);
status_t setVideoFormatOnPort(
OMX_U32 portIndex,
int32_t width, int32_t height,
OMX_VIDEO_CODINGTYPE compressionFormat);
status_t setupAACDecoder(int32_t numChannels, int32_t sampleRate);
status_t setupAMRDecoder(bool isWAMR);
status_t setupG711Decoder(int32_t numChannels);
status_t setupRawAudioFormat(
OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels);
status_t setMinBufferSize(OMX_U32 portIndex, size_t size);
status_t initNativeWindow();
// Returns true iff all buffers on the given port have status OWNED_BY_US.
bool allYourBuffersAreBelongToUs(OMX_U32 portIndex);
bool allYourBuffersAreBelongToUs();
size_t countBuffersOwnedByComponent(OMX_U32 portIndex) const;
void deferMessage(const sp<AMessage> &msg);
void processDeferredMessages();
void sendFormatChange();
void signalError(OMX_ERRORTYPE error = OMX_ErrorUndefined);
DISALLOW_EVIL_CONSTRUCTORS(ACodec);
};
} // namespace android
#endif // A_CODEC_H_
|