blob: a03d4e28afc5539d87bf07dd510ac602c67145e6 [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 Kim4f74cca2020-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,
Arun Mirpuri2c26e122021-04-02 15:00:30 -070090 C2Config::PCM_FLOAT,
91 C2Config::PCM_24,
92 C2Config::PCM_32})
Pawin Vongmasa8be93112018-12-11 14:01:42 -080093 })
94 .withSetter((Setter<decltype(*mPcmEncodingInfo)>::StrictValueWithNoDeps))
95 .build());
96
Pawin Vongmasa36653902018-11-15 00:10:25 -080097 }
98
99private:
Pawin Vongmasa36653902018-11-15 00:10:25 -0800100 std::shared_ptr<C2StreamSampleRateInfo::output> mSampleRate;
101 std::shared_ptr<C2StreamChannelCountInfo::output> mChannelCount;
Lajos Molnar3bb81cd2019-02-20 15:10:30 -0800102 std::shared_ptr<C2StreamBitrateInfo::input> mBitrate;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800103 std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mInputMaxBufSize;
Pawin Vongmasa8be93112018-12-11 14:01:42 -0800104 std::shared_ptr<C2StreamPcmEncodingInfo::output> mPcmEncodingInfo;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800105};
106
107C2SoftRawDec::C2SoftRawDec(
108 const char *name,
109 c2_node_id_t id,
110 const std::shared_ptr<IntfImpl> &intfImpl)
111 : SimpleC2Component(std::make_shared<SimpleInterface<IntfImpl>>(name, id, intfImpl)),
112 mIntf(intfImpl) {
113}
114
115C2SoftRawDec::~C2SoftRawDec() {
116 onRelease();
117}
118
119c2_status_t C2SoftRawDec::onInit() {
120 mSignalledEos = false;
121 return C2_OK;
122}
123
124c2_status_t C2SoftRawDec::onStop() {
125 mSignalledEos = false;
126 return C2_OK;
127}
128
129void C2SoftRawDec::onReset() {
130 (void)onStop();
131}
132
133void C2SoftRawDec::onRelease() {
134}
135
136c2_status_t C2SoftRawDec::onFlush_sm() {
137 return onStop();
138}
139
140void C2SoftRawDec::process(
141 const std::unique_ptr<C2Work> &work,
142 const std::shared_ptr<C2BlockPool> &pool) {
143 (void)pool;
144 work->result = C2_OK;
145 work->workletsProcessed = 1u;
146
147 if (mSignalledEos) {
148 work->result = C2_BAD_VALUE;
149 return;
150 }
151
152 ALOGV("in buffer attr. timestamp %d frameindex %d",
153 (int)work->input.ordinal.timestamp.peeku(), (int)work->input.ordinal.frameIndex.peeku());
154
155 work->worklets.front()->output.flags = work->input.flags;
156 work->worklets.front()->output.buffers.clear();
157 work->worklets.front()->output.ordinal = work->input.ordinal;
158 if (!work->input.buffers.empty()) {
159 work->worklets.front()->output.buffers.push_back(work->input.buffers[0]);
160 }
161 if (work->input.flags & C2FrameData::FLAG_END_OF_STREAM) {
162 mSignalledEos = true;
163 ALOGV("signalled EOS");
164 }
165}
166
167c2_status_t C2SoftRawDec::drain(
168 uint32_t drainMode,
169 const std::shared_ptr<C2BlockPool> &pool) {
170 (void) pool;
171 if (drainMode == NO_DRAIN) {
172 ALOGW("drain with NO_DRAIN: no-op");
173 return C2_OK;
174 }
175 if (drainMode == DRAIN_CHAIN) {
176 ALOGW("DRAIN_CHAIN not supported");
177 return C2_OMITTED;
178 }
179
180 return C2_OK;
181}
182
183class C2SoftRawDecFactory : public C2ComponentFactory {
184public:
185 C2SoftRawDecFactory() : mHelper(std::static_pointer_cast<C2ReflectorHelper>(
186 GetCodec2PlatformComponentStore()->getParamReflector())) {
187 }
188
189 virtual c2_status_t createComponent(
190 c2_node_id_t id,
191 std::shared_ptr<C2Component>* const component,
192 std::function<void(C2Component*)> deleter) override {
193 *component = std::shared_ptr<C2Component>(
194 new C2SoftRawDec(COMPONENT_NAME,
195 id,
196 std::make_shared<C2SoftRawDec::IntfImpl>(mHelper)),
197 deleter);
198 return C2_OK;
199 }
200
201 virtual c2_status_t createInterface(
202 c2_node_id_t id,
203 std::shared_ptr<C2ComponentInterface>* const interface,
204 std::function<void(C2ComponentInterface*)> deleter) override {
205 *interface = std::shared_ptr<C2ComponentInterface>(
206 new SimpleInterface<C2SoftRawDec::IntfImpl>(
207 COMPONENT_NAME, id, std::make_shared<C2SoftRawDec::IntfImpl>(mHelper)),
208 deleter);
209 return C2_OK;
210 }
211
212 virtual ~C2SoftRawDecFactory() override = default;
213
214private:
215 std::shared_ptr<C2ReflectorHelper> mHelper;
216};
217
218} // namespace android
219
Cindy Zhouf6c0c3c2020-12-02 10:53:40 -0800220__attribute__((cfi_canonical_jump_table))
Pawin Vongmasa36653902018-11-15 00:10:25 -0800221extern "C" ::C2ComponentFactory* CreateCodec2Factory() {
222 ALOGV("in %s", __func__);
223 return new ::android::C2SoftRawDecFactory();
224}
225
Cindy Zhouf6c0c3c2020-12-02 10:53:40 -0800226__attribute__((cfi_canonical_jump_table))
Pawin Vongmasa36653902018-11-15 00:10:25 -0800227extern "C" void DestroyCodec2Factory(::C2ComponentFactory* factory) {
228 ALOGV("in %s", __func__);
229 delete factory;
230}