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
184
185
|
/*
* Copyright 2019 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.
*/
#ifdef __LP64__
#define OMX_ANDROID_COMPILE_AS_32BIT_ON_64BIT_PLATFORMS
#endif
//#define LOG_NDEBUG 0
#define LOG_TAG "Omx2IGraphicBufferSource"
#include <android-base/logging.h>
#include "Omx2IGraphicBufferSource.h"
#include <android/BnOMXBufferSource.h>
#include <media/OMXBuffer.h>
#include <media/stagefright/omx/OMXUtils.h>
#include <OMX_Component.h>
#include <OMX_Index.h>
#include <OMX_IndexExt.h>
namespace android {
namespace /* unnamed */ {
// OmxGraphicBufferSource -> IOMXBufferSource
struct OmxGbs2IOmxBs : public BnOMXBufferSource {
sp<OmxGraphicBufferSource> mBase;
OmxGbs2IOmxBs(sp<OmxGraphicBufferSource> const& base) : mBase{base} {}
BnStatus onOmxExecuting() override {
return mBase->onOmxExecuting();
}
BnStatus onOmxIdle() override {
return mBase->onOmxIdle();
}
BnStatus onOmxLoaded() override {
return mBase->onOmxLoaded();
}
BnStatus onInputBufferAdded(int32_t bufferId) override {
return mBase->onInputBufferAdded(bufferId);
}
BnStatus onInputBufferEmptied(
int32_t bufferId,
OMXFenceParcelable const& fenceParcel) override {
return mBase->onInputBufferEmptied(bufferId, fenceParcel.get());
}
};
struct OmxNodeWrapper : public IOmxNodeWrapper {
sp<IOMXNode> mBase;
OmxNodeWrapper(sp<IOMXNode> const& base) : mBase{base} {}
status_t emptyBuffer(
int32_t bufferId, uint32_t flags,
const sp<GraphicBuffer> &buffer,
int64_t timestamp, int fenceFd) override {
return mBase->emptyBuffer(bufferId, buffer, flags, timestamp, fenceFd);
}
void dispatchDataSpaceChanged(
int32_t dataSpace, int32_t aspects, int32_t pixelFormat) override {
omx_message msg{};
msg.type = omx_message::EVENT;
msg.fenceFd = -1;
msg.u.event_data.event = OMX_EventDataSpaceChanged;
msg.u.event_data.data1 = dataSpace;
msg.u.event_data.data2 = aspects;
msg.u.event_data.data3 = pixelFormat;
mBase->dispatchMessage(msg);
}
};
} // unnamed namespace
// Omx2IGraphicBufferSource
Omx2IGraphicBufferSource::Omx2IGraphicBufferSource(
sp<OmxGraphicBufferSource> const& base)
: mBase{base},
mOMXBufferSource{new OmxGbs2IOmxBs(base)} {
}
BnStatus Omx2IGraphicBufferSource::setSuspend(
bool suspend, int64_t timeUs) {
return BnStatus::fromStatusT(mBase->setSuspend(suspend, timeUs));
}
BnStatus Omx2IGraphicBufferSource::setRepeatPreviousFrameDelayUs(
int64_t repeatAfterUs) {
return BnStatus::fromStatusT(mBase->setRepeatPreviousFrameDelayUs(repeatAfterUs));
}
BnStatus Omx2IGraphicBufferSource::setMaxFps(float maxFps) {
return BnStatus::fromStatusT(mBase->setMaxFps(maxFps));
}
BnStatus Omx2IGraphicBufferSource::setTimeLapseConfig(
double fps, double captureFps) {
return BnStatus::fromStatusT(mBase->setTimeLapseConfig(fps, captureFps));
}
BnStatus Omx2IGraphicBufferSource::setStartTimeUs(
int64_t startTimeUs) {
return BnStatus::fromStatusT(mBase->setStartTimeUs(startTimeUs));
}
BnStatus Omx2IGraphicBufferSource::setStopTimeUs(
int64_t stopTimeUs) {
return BnStatus::fromStatusT(mBase->setStopTimeUs(stopTimeUs));
}
BnStatus Omx2IGraphicBufferSource::getStopTimeOffsetUs(
int64_t *stopTimeOffsetUs) {
return BnStatus::fromStatusT(mBase->getStopTimeOffsetUs(stopTimeOffsetUs));
}
BnStatus Omx2IGraphicBufferSource::setColorAspects(
int32_t aspects) {
return BnStatus::fromStatusT(mBase->setColorAspects(aspects));
}
BnStatus Omx2IGraphicBufferSource::setTimeOffsetUs(
int64_t timeOffsetsUs) {
return BnStatus::fromStatusT(mBase->setTimeOffsetUs(timeOffsetsUs));
}
BnStatus Omx2IGraphicBufferSource::signalEndOfInputStream() {
return BnStatus::fromStatusT(mBase->signalEndOfInputStream());
}
BnStatus Omx2IGraphicBufferSource::configure(
const sp<IOMXNode>& omxNode, int32_t dataSpace) {
if (omxNode == NULL) {
return BnStatus::fromServiceSpecificError(BAD_VALUE);
}
// Do setInputSurface() first, the node will try to enable metadata
// mode on input, and does necessary error checking. If this fails,
// we can't use this input surface on the node.
status_t err = omxNode->setInputSurface(mOMXBufferSource);
if (err != NO_ERROR) {
ALOGE("Unable to set input surface: %d", err);
return BnStatus::fromServiceSpecificError(err);
}
uint32_t consumerUsage;
if (omxNode->getParameter(
(OMX_INDEXTYPE)OMX_IndexParamConsumerUsageBits,
&consumerUsage, sizeof(consumerUsage)) != OK) {
consumerUsage = 0;
}
OMX_PARAM_PORTDEFINITIONTYPE def;
InitOMXParams(&def);
def.nPortIndex = 0; // kPortIndexInput
err = omxNode->getParameter(
OMX_IndexParamPortDefinition, &def, sizeof(def));
if (err != NO_ERROR) {
ALOGE("Failed to get port definition: %d", err);
return BnStatus::fromServiceSpecificError(UNKNOWN_ERROR);
}
return BnStatus::fromStatusT(mBase->configure(
new OmxNodeWrapper(omxNode),
dataSpace,
def.nBufferCountActual,
def.format.video.nFrameWidth,
def.format.video.nFrameHeight,
consumerUsage));
}
} // namespace android
|