blob: 7b6f21aee4d5f4eb462888b547a7fcbe2483575d [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
2 * Copyright (C) 2018 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//#define LOG_NDEBUG 0
18#define LOG_TAG "C2SoftRawDec"
19#include <log/log.h>
20
21#include <media/stagefright/foundation/MediaDefs.h>
22
23#include <C2PlatformSupport.h>
24#include <SimpleC2Interface.h>
25
26#include "C2SoftRawDec.h"
27
28namespace android {
29
Rakesh Kumared134642019-03-12 14:18:42 +053030namespace {
31
Pawin Vongmasa36653902018-11-15 00:10:25 -080032constexpr char COMPONENT_NAME[] = "c2.android.raw.decoder";
33
Rakesh Kumared134642019-03-12 14:18:42 +053034} // namespace
35
36class C2SoftRawDec::IntfImpl : public SimpleInterface<void>::BaseParams {
Pawin Vongmasa36653902018-11-15 00:10:25 -080037public:
38 explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
Rakesh Kumared134642019-03-12 14:18:42 +053039 : SimpleInterface<void>::BaseParams(
40 helper,
41 COMPONENT_NAME,
42 C2Component::KIND_DECODER,
43 C2Component::DOMAIN_AUDIO,
44 MEDIA_MIMETYPE_AUDIO_RAW) {
45 noPrivateBuffers();
46 noInputReferences();
47 noOutputReferences();
48 noInputLatency();
49 noTimeStretch();
Pawin Vongmasa36653902018-11-15 00:10:25 -080050 setDerivedInstance(this);
51
52 addParameter(
Rakesh Kumared134642019-03-12 14:18:42 +053053 DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES)
54 .withConstValue(new C2ComponentAttributesSetting(
55 C2Component::ATTRIB_IS_TEMPORAL))
Pawin Vongmasa36653902018-11-15 00:10:25 -080056 .build());
57
58 addParameter(
Lajos Molnar3bb81cd2019-02-20 15:10:30 -080059 DefineParam(mSampleRate, C2_PARAMKEY_SAMPLE_RATE)
Pawin Vongmasa36653902018-11-15 00:10:25 -080060 .withDefault(new C2StreamSampleRateInfo::output(0u, 44100))
Wonsik Kim1a150012020-01-21 09:48:44 -080061 .withFields({C2F(mSampleRate, value).greaterThan(0)})
Pawin Vongmasa36653902018-11-15 00:10:25 -080062 .withSetter((Setter<decltype(*mSampleRate)>::StrictValueWithNoDeps))
63 .build());
64
65 addParameter(
Lajos Molnar3bb81cd2019-02-20 15:10:30 -080066 DefineParam(mChannelCount, C2_PARAMKEY_CHANNEL_COUNT)
Pawin Vongmasa36653902018-11-15 00:10:25 -080067 .withDefault(new C2StreamChannelCountInfo::output(0u, 2))
68 .withFields({C2F(mChannelCount, value).inRange(1, 8)})
69 .withSetter(Setter<decltype(*mChannelCount)>::StrictValueWithNoDeps)
70 .build());
71
72 addParameter(
Lajos Molnar3bb81cd2019-02-20 15:10:30 -080073 DefineParam(mBitrate, C2_PARAMKEY_BITRATE)
74 .withDefault(new C2StreamBitrateInfo::input(0u, 64000))
Marco Nelissen4054c972019-05-28 11:28:51 -070075 .withFields({C2F(mBitrate, value).inRange(1, 98304000)})
Pawin Vongmasa36653902018-11-15 00:10:25 -080076 .withSetter(Setter<decltype(*mBitrate)>::NonStrictValueWithNoDeps)
77 .build());
78
79 addParameter(
80 DefineParam(mInputMaxBufSize, C2_PARAMKEY_INPUT_MAX_BUFFER_SIZE)
81 .withConstValue(new C2StreamMaxBufferSizeInfo::input(0u, 64 * 1024))
82 .build());
Pawin Vongmasa8be93112018-12-11 14:01:42 -080083
84 addParameter(
85 DefineParam(mPcmEncodingInfo, C2_PARAMKEY_PCM_ENCODING)
86 .withDefault(new C2StreamPcmEncodingInfo::output(0u, C2Config::PCM_16))
87 .withFields({C2F(mPcmEncodingInfo, value).oneOf({
88 C2Config::PCM_16,
89 C2Config::PCM_8,
90 C2Config::PCM_FLOAT})
91 })
92 .withSetter((Setter<decltype(*mPcmEncodingInfo)>::StrictValueWithNoDeps))
93 .build());
94
Pawin Vongmasa36653902018-11-15 00:10:25 -080095 }
96
97private:
Pawin Vongmasa36653902018-11-15 00:10:25 -080098 std::shared_ptr<C2StreamSampleRateInfo::output> mSampleRate;
99 std::shared_ptr<C2StreamChannelCountInfo::output> mChannelCount;
Lajos Molnar3bb81cd2019-02-20 15:10:30 -0800100 std::shared_ptr<C2StreamBitrateInfo::input> mBitrate;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800101 std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mInputMaxBufSize;
Pawin Vongmasa8be93112018-12-11 14:01:42 -0800102 std::shared_ptr<C2StreamPcmEncodingInfo::output> mPcmEncodingInfo;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800103};
104
105C2SoftRawDec::C2SoftRawDec(
106 const char *name,
107 c2_node_id_t id,
108 const std::shared_ptr<IntfImpl> &intfImpl)
109 : SimpleC2Component(std::make_shared<SimpleInterface<IntfImpl>>(name, id, intfImpl)),
110 mIntf(intfImpl) {
111}
112
113C2SoftRawDec::~C2SoftRawDec() {
114 onRelease();
115}
116
117c2_status_t C2SoftRawDec::onInit() {
118 mSignalledEos = false;
119 return C2_OK;
120}
121
122c2_status_t C2SoftRawDec::onStop() {
123 mSignalledEos = false;
124 return C2_OK;
125}
126
127void C2SoftRawDec::onReset() {
128 (void)onStop();
129}
130
131void C2SoftRawDec::onRelease() {
132}
133
134c2_status_t C2SoftRawDec::onFlush_sm() {
135 return onStop();
136}
137
138void C2SoftRawDec::process(
139 const std::unique_ptr<C2Work> &work,
140 const std::shared_ptr<C2BlockPool> &pool) {
141 (void)pool;
142 work->result = C2_OK;
143 work->workletsProcessed = 1u;
144
145 if (mSignalledEos) {
146 work->result = C2_BAD_VALUE;
147 return;
148 }
149
150 ALOGV("in buffer attr. timestamp %d frameindex %d",
151 (int)work->input.ordinal.timestamp.peeku(), (int)work->input.ordinal.frameIndex.peeku());
152
153 work->worklets.front()->output.flags = work->input.flags;
154 work->worklets.front()->output.buffers.clear();
155 work->worklets.front()->output.ordinal = work->input.ordinal;
156 if (!work->input.buffers.empty()) {
157 work->worklets.front()->output.buffers.push_back(work->input.buffers[0]);
158 }
159 if (work->input.flags & C2FrameData::FLAG_END_OF_STREAM) {
160 mSignalledEos = true;
161 ALOGV("signalled EOS");
162 }
163}
164
165c2_status_t C2SoftRawDec::drain(
166 uint32_t drainMode,
167 const std::shared_ptr<C2BlockPool> &pool) {
168 (void) pool;
169 if (drainMode == NO_DRAIN) {
170 ALOGW("drain with NO_DRAIN: no-op");
171 return C2_OK;
172 }
173 if (drainMode == DRAIN_CHAIN) {
174 ALOGW("DRAIN_CHAIN not supported");
175 return C2_OMITTED;
176 }
177
178 return C2_OK;
179}
180
181class C2SoftRawDecFactory : public C2ComponentFactory {
182public:
183 C2SoftRawDecFactory() : mHelper(std::static_pointer_cast<C2ReflectorHelper>(
184 GetCodec2PlatformComponentStore()->getParamReflector())) {
185 }
186
187 virtual c2_status_t createComponent(
188 c2_node_id_t id,
189 std::shared_ptr<C2Component>* const component,
190 std::function<void(C2Component*)> deleter) override {
191 *component = std::shared_ptr<C2Component>(
192 new C2SoftRawDec(COMPONENT_NAME,
193 id,
194 std::make_shared<C2SoftRawDec::IntfImpl>(mHelper)),
195 deleter);
196 return C2_OK;
197 }
198
199 virtual c2_status_t createInterface(
200 c2_node_id_t id,
201 std::shared_ptr<C2ComponentInterface>* const interface,
202 std::function<void(C2ComponentInterface*)> deleter) override {
203 *interface = std::shared_ptr<C2ComponentInterface>(
204 new SimpleInterface<C2SoftRawDec::IntfImpl>(
205 COMPONENT_NAME, id, std::make_shared<C2SoftRawDec::IntfImpl>(mHelper)),
206 deleter);
207 return C2_OK;
208 }
209
210 virtual ~C2SoftRawDecFactory() override = default;
211
212private:
213 std::shared_ptr<C2ReflectorHelper> mHelper;
214};
215
216} // namespace android
217
218extern "C" ::C2ComponentFactory* CreateCodec2Factory() {
219 ALOGV("in %s", __func__);
220 return new ::android::C2SoftRawDecFactory();
221}
222
223extern "C" void DestroyCodec2Factory(::C2ComponentFactory* factory) {
224 ALOGV("in %s", __func__);
225 delete factory;
226}