• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "C2SoftFlacEnc"
19 #include <log/log.h>
20 
21 #include <audio_utils/primitives.h>
22 #include <media/stagefright/foundation/MediaDefs.h>
23 
24 #include <C2Debug.h>
25 #include <C2PlatformSupport.h>
26 #include <SimpleC2Interface.h>
27 
28 #include "C2SoftFlacEnc.h"
29 
30 namespace android {
31 
32 namespace {
33 
34 constexpr char COMPONENT_NAME[] = "c2.android.flac.encoder";
35 
36 }  // namespace
37 
38 class C2SoftFlacEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
39 public:
IntfImpl(const std::shared_ptr<C2ReflectorHelper> & helper)40     explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
41         : SimpleInterface<void>::BaseParams(
42                 helper,
43                 COMPONENT_NAME,
44                 C2Component::KIND_ENCODER,
45                 C2Component::DOMAIN_AUDIO,
46                 MEDIA_MIMETYPE_AUDIO_FLAC) {
47         noPrivateBuffers();
48         noInputReferences();
49         noOutputReferences();
50         noInputLatency();
51         noTimeStretch();
52         setDerivedInstance(this);
53 
54         addParameter(
55                 DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES)
56                 .withConstValue(new C2ComponentAttributesSetting(
57                     C2Component::ATTRIB_IS_TEMPORAL))
58                 .build());
59         addParameter(
60                 DefineParam(mSampleRate, C2_PARAMKEY_SAMPLE_RATE)
61                 .withDefault(new C2StreamSampleRateInfo::input(0u, 44100))
62                 .withFields({C2F(mSampleRate, value).inRange(1, 655350)})
63                 .withSetter((Setter<decltype(*mSampleRate)>::StrictValueWithNoDeps))
64                 .build());
65         addParameter(
66                 DefineParam(mChannelCount, C2_PARAMKEY_CHANNEL_COUNT)
67                 .withDefault(new C2StreamChannelCountInfo::input(0u, 1))
68                 .withFields({C2F(mChannelCount, value).inRange(1, 2)})
69                 .withSetter(Setter<decltype(*mChannelCount)>::StrictValueWithNoDeps)
70                 .build());
71         addParameter(
72                 DefineParam(mBitrate, C2_PARAMKEY_BITRATE)
73                 .withDefault(new C2StreamBitrateInfo::output(0u, 768000))
74                 .withFields({C2F(mBitrate, value).inRange(1, 21000000)})
75                 .withSetter(Setter<decltype(*mBitrate)>::NonStrictValueWithNoDeps)
76                 .build());
77         addParameter(
78                 DefineParam(mComplexity, C2_PARAMKEY_COMPLEXITY)
79                 .withDefault(new C2StreamComplexityTuning::output(0u,
80                     FLAC_COMPRESSION_LEVEL_DEFAULT))
81                 .withFields({C2F(mComplexity, value).inRange(
82                     FLAC_COMPRESSION_LEVEL_MIN, FLAC_COMPRESSION_LEVEL_MAX)})
83                 .withSetter(Setter<decltype(*mComplexity)>::NonStrictValueWithNoDeps)
84                 .build());
85 
86         addParameter(
87                 DefineParam(mPcmEncodingInfo, C2_PARAMKEY_PCM_ENCODING)
88                 .withDefault(new C2StreamPcmEncodingInfo::input(0u, C2Config::PCM_16))
89                 .withFields({C2F(mPcmEncodingInfo, value).oneOf({
90                      C2Config::PCM_16,
91                      // C2Config::PCM_8,
92                      C2Config::PCM_FLOAT})
93                 })
94                 .withSetter((Setter<decltype(*mPcmEncodingInfo)>::StrictValueWithNoDeps))
95                 .build());
96 
97         addParameter(
98                 DefineParam(mInputMaxBufSize, C2_PARAMKEY_INPUT_MAX_BUFFER_SIZE)
99                 .withDefault(new C2StreamMaxBufferSizeInfo::input(0u, kMaxBlockSize))
100                 .withFields({
101                     C2F(mInputMaxBufSize, value).any(),
102                 })
103                 .withSetter(MaxInputSizeSetter, mChannelCount, mPcmEncodingInfo)
104                 .build());
105     }
106 
MaxInputSizeSetter(bool mayBlock,C2P<C2StreamMaxBufferSizeInfo::input> & me,const C2P<C2StreamChannelCountInfo::input> & channelCount,const C2P<C2StreamPcmEncodingInfo::input> & pcmEncoding)107     static C2R MaxInputSizeSetter(bool mayBlock,
108             C2P<C2StreamMaxBufferSizeInfo::input> &me,
109             const C2P<C2StreamChannelCountInfo::input> &channelCount,
110             const C2P<C2StreamPcmEncodingInfo::input> &pcmEncoding) {
111         (void)mayBlock;
112         C2R res = C2R::Ok();
113         int bytesPerSample = pcmEncoding.v.value == C2Config::PCM_FLOAT ? 4 : 2;
114         me.set().value = kMaxBlockSize * bytesPerSample * channelCount.v.value;
115         return res;
116     }
117 
getSampleRate() const118     uint32_t getSampleRate() const { return mSampleRate->value; }
getChannelCount() const119     uint32_t getChannelCount() const { return mChannelCount->value; }
getBitrate() const120     uint32_t getBitrate() const { return mBitrate->value; }
getComplexity() const121     uint32_t getComplexity() const { return mComplexity->value; }
getPcmEncodingInfo() const122     int32_t getPcmEncodingInfo() const { return mPcmEncodingInfo->value; }
123 
124 private:
125     std::shared_ptr<C2StreamSampleRateInfo::input> mSampleRate;
126     std::shared_ptr<C2StreamChannelCountInfo::input> mChannelCount;
127     std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
128     std::shared_ptr<C2StreamComplexityTuning::output> mComplexity;
129     std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mInputMaxBufSize;
130     std::shared_ptr<C2StreamPcmEncodingInfo::input> mPcmEncodingInfo;
131 };
132 
C2SoftFlacEnc(const char * name,c2_node_id_t id,const std::shared_ptr<IntfImpl> & intfImpl)133 C2SoftFlacEnc::C2SoftFlacEnc(
134         const char *name,
135         c2_node_id_t id,
136         const std::shared_ptr<IntfImpl> &intfImpl)
137     : SimpleC2Component(std::make_shared<SimpleInterface<IntfImpl>>(name, id, intfImpl)),
138       mIntf(intfImpl),
139       mFlacStreamEncoder(nullptr),
140       mInputBufferPcm32(nullptr) {
141 }
142 
C2SoftFlacEnc(const char * name,c2_node_id_t id,const std::shared_ptr<C2ReflectorHelper> & helper)143 C2SoftFlacEnc::C2SoftFlacEnc(
144         const char *name,
145         c2_node_id_t id,
146         const std::shared_ptr<C2ReflectorHelper> &helper)
147     : C2SoftFlacEnc(name, id, std::make_shared<IntfImpl>(helper)) {
148 }
149 
~C2SoftFlacEnc()150 C2SoftFlacEnc::~C2SoftFlacEnc() {
151     onRelease();
152 }
153 
onInit()154 c2_status_t C2SoftFlacEnc::onInit() {
155     mFlacStreamEncoder = FLAC__stream_encoder_new();
156     if (!mFlacStreamEncoder) return C2_CORRUPTED;
157 
158     mInputBufferPcm32 = (FLAC__int32*) malloc(
159             kInBlockSize * kMaxNumChannels * sizeof(FLAC__int32));
160     if (!mInputBufferPcm32) return C2_NO_MEMORY;
161 
162     mSignalledError = false;
163     mSignalledOutputEos = false;
164     mIsFirstFrame = true;
165     mAnchorTimeStamp = 0;
166     mProcessedSamples = 0u;
167     mEncoderWriteData = false;
168     mEncoderReturnedNbBytes = 0;
169     mHeaderOffset = 0;
170     mWroteHeader = false;
171 
172     status_t err = configureEncoder();
173     return err == OK ? C2_OK : C2_CORRUPTED;
174 }
175 
onRelease()176 void C2SoftFlacEnc::onRelease() {
177     if (mFlacStreamEncoder) {
178         FLAC__stream_encoder_delete(mFlacStreamEncoder);
179         mFlacStreamEncoder = nullptr;
180     }
181 
182     if (mInputBufferPcm32) {
183         free(mInputBufferPcm32);
184         mInputBufferPcm32 = nullptr;
185     }
186 }
187 
onReset()188 void C2SoftFlacEnc::onReset() {
189     (void) onStop();
190 }
191 
onStop()192 c2_status_t C2SoftFlacEnc::onStop() {
193     mSignalledError = false;
194     mSignalledOutputEos = false;
195     mIsFirstFrame = true;
196     mAnchorTimeStamp = 0;
197     mProcessedSamples = 0u;
198     mEncoderWriteData = false;
199     mEncoderReturnedNbBytes = 0;
200     mHeaderOffset = 0;
201     mWroteHeader = false;
202 
203     c2_status_t status = drain(DRAIN_COMPONENT_NO_EOS, nullptr);
204     if (C2_OK != status) return status;
205 
206     status_t err = configureEncoder();
207     if (err != OK) mSignalledError = true;
208     return C2_OK;
209 }
210 
onFlush_sm()211 c2_status_t C2SoftFlacEnc::onFlush_sm() {
212     return onStop();
213 }
214 
process(const std::unique_ptr<C2Work> & work,const std::shared_ptr<C2BlockPool> & pool)215 void C2SoftFlacEnc::process(
216         const std::unique_ptr<C2Work> &work,
217         const std::shared_ptr<C2BlockPool> &pool) {
218     // Initialize output work
219     work->result = C2_OK;
220     work->workletsProcessed = 1u;
221     work->worklets.front()->output.flags = work->input.flags;
222 
223     if (mSignalledError || mSignalledOutputEos) {
224         work->result = C2_BAD_VALUE;
225         return;
226     }
227 
228     bool eos = ((work->input.flags & C2FrameData::FLAG_END_OF_STREAM) != 0);
229     C2ReadView rView = mDummyReadView;
230     size_t inOffset = 0u;
231     size_t inSize = 0u;
232     if (!work->input.buffers.empty()) {
233         rView = work->input.buffers[0]->data().linearBlocks().front().map().get();
234         inSize = rView.capacity();
235         if (inSize && rView.error()) {
236             ALOGE("read view map failed %d", rView.error());
237             work->result = C2_CORRUPTED;
238             return;
239         }
240     }
241 
242     ALOGV("in buffer attr. size %zu timestamp %d frameindex %d, flags %x",
243               inSize, (int)work->input.ordinal.timestamp.peeku(),
244               (int)work->input.ordinal.frameIndex.peeku(), work->input.flags);
245     if (mIsFirstFrame && inSize) {
246         mAnchorTimeStamp = work->input.ordinal.timestamp.peekll();
247         mIsFirstFrame = false;
248     }
249 
250     if (!mWroteHeader) {
251         std::unique_ptr<C2StreamInitDataInfo::output> csd =
252             C2StreamInitDataInfo::output::AllocUnique(mHeaderOffset, 0u);
253         if (!csd) {
254             ALOGE("CSD allocation failed");
255             mSignalledError = true;
256             work->result = C2_NO_MEMORY;
257             return;
258         }
259         memcpy(csd->m.value, mHeader, mHeaderOffset);
260         ALOGV("put csd, %d bytes", mHeaderOffset);
261 
262         work->worklets.front()->output.configUpdate.push_back(std::move(csd));
263         mWroteHeader = true;
264     }
265 
266     const uint32_t channelCount = mIntf->getChannelCount();
267     const bool inputFloat = mIntf->getPcmEncodingInfo() == C2Config::PCM_FLOAT;
268     const unsigned sampleSize = inputFloat ? sizeof(float) : sizeof(int16_t);
269     const unsigned frameSize = channelCount * sampleSize;
270 
271     size_t outCapacity = inSize;
272     outCapacity += mBlockSize * frameSize;
273 
274     C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE };
275     c2_status_t err = pool->fetchLinearBlock(outCapacity, usage, &mOutputBlock);
276     if (err != C2_OK) {
277         ALOGE("fetchLinearBlock for Output failed with status %d", err);
278         work->result = C2_NO_MEMORY;
279         return;
280     }
281 
282     err = mOutputBlock->map().get().error();
283     if (err) {
284         ALOGE("write view map failed %d", err);
285         work->result = C2_CORRUPTED;
286         return;
287     }
288 
289     class FillWork {
290     public:
291         FillWork(uint32_t flags, C2WorkOrdinalStruct ordinal,
292                  const std::shared_ptr<C2Buffer> &buffer)
293             : mFlags(flags), mOrdinal(ordinal), mBuffer(buffer) {}
294         ~FillWork() = default;
295 
296         void operator()(const std::unique_ptr<C2Work> &work) {
297             work->worklets.front()->output.flags = (C2FrameData::flags_t)mFlags;
298             work->worklets.front()->output.buffers.clear();
299             work->worklets.front()->output.ordinal = mOrdinal;
300             work->workletsProcessed = 1u;
301             work->result = C2_OK;
302             if (mBuffer) {
303                 work->worklets.front()->output.buffers.push_back(mBuffer);
304             }
305             ALOGV("timestamp = %lld, index = %lld, w/%s buffer",
306                   mOrdinal.timestamp.peekll(), mOrdinal.frameIndex.peekll(),
307                   mBuffer ? "" : "o");
308         }
309 
310     private:
311         const uint32_t mFlags;
312         const C2WorkOrdinalStruct mOrdinal;
313         const std::shared_ptr<C2Buffer> mBuffer;
314     };
315 
316     mEncoderWriteData = true;
317     mEncoderReturnedNbBytes = 0;
318     size_t inPos = 0;
319     while (inPos < inSize) {
320         const uint8_t *inPtr = rView.data() + inOffset;
321         const size_t processSize = MIN(kInBlockSize * frameSize, (inSize - inPos));
322         const unsigned nbInputFrames = processSize / frameSize;
323         const unsigned nbInputSamples = processSize / sampleSize;
324 
325         ALOGV("about to encode %zu bytes", processSize);
326         if (inputFloat) {
327             const float * const pcmFloat = reinterpret_cast<const float *>(inPtr + inPos);
328             memcpy_to_q8_23_from_float_with_clamp(mInputBufferPcm32, pcmFloat, nbInputSamples);
329         } else {
330             const int16_t * const pcm16 = reinterpret_cast<const int16_t *>(inPtr + inPos);
331             for (unsigned i = 0; i < nbInputSamples; i++) {
332                 mInputBufferPcm32[i] = (FLAC__int32) pcm16[i];
333             }
334         }
335 
336         FLAC__bool ok = FLAC__stream_encoder_process_interleaved(
337                 mFlacStreamEncoder, mInputBufferPcm32, nbInputFrames);
338         if (!ok) {
339             ALOGE("error encountered during encoding");
340             mSignalledError = true;
341             work->result = C2_CORRUPTED;
342             mOutputBlock.reset();
343             return;
344         }
345         inPos += processSize;
346     }
347     if (eos && (C2_OK != drain(DRAIN_COMPONENT_WITH_EOS, pool))) {
348         ALOGE("error encountered during encoding");
349         mSignalledError = true;
350         work->result = C2_CORRUPTED;
351         mOutputBlock.reset();
352         return;
353     }
354 
355     // cloneAndSend will create clone of work when more than one encoded frame is produced
356     while (mOutputBuffers.size() > 1) {
357         const OutputBuffer& front = mOutputBuffers.front();
358         C2WorkOrdinalStruct ordinal = work->input.ordinal;
359         ordinal.frameIndex = front.frameIndex;
360         ordinal.timestamp = front.timestampUs;
361         cloneAndSend(work->input.ordinal.frameIndex.peeku(), work,
362                      FillWork(C2FrameData::FLAG_INCOMPLETE, ordinal, front.buffer));
363         mOutputBuffers.pop_front();
364     }
365 
366     std::shared_ptr<C2Buffer> buffer;
367     C2WorkOrdinalStruct ordinal = work->input.ordinal;
368     if (mOutputBuffers.size() == 1) {
369         const OutputBuffer& front = mOutputBuffers.front();
370         ordinal.frameIndex = front.frameIndex;
371         ordinal.timestamp = front.timestampUs;
372         buffer = front.buffer;
373         mOutputBuffers.pop_front();
374     }
375     // finish the response for the overall transaction.
376     // this includes any final frame that the encoder produced during this request
377     // this response is required even if no data was encoded.
378     FillWork((C2FrameData::flags_t)(eos ? C2FrameData::FLAG_END_OF_STREAM : 0),
379              ordinal, buffer)(work);
380 
381     mOutputBlock = nullptr;
382     if (eos) {
383         mSignalledOutputEos = true;
384         ALOGV("signalled EOS");
385     }
386     mEncoderWriteData = false;
387     mEncoderReturnedNbBytes = 0;
388 }
389 
onEncodedFlacAvailable(const FLAC__byte buffer[],size_t bytes,unsigned samples,unsigned current_frame)390 FLAC__StreamEncoderWriteStatus C2SoftFlacEnc::onEncodedFlacAvailable(
391         const FLAC__byte buffer[], size_t bytes, unsigned samples,
392         unsigned current_frame) {
393     (void) current_frame;
394     ALOGV("%s (bytes=%zu, samples=%u, curr_frame=%u)", __func__, bytes, samples,
395           current_frame);
396 
397     if (samples == 0) {
398         ALOGI("saving %zu bytes of header", bytes);
399         memcpy(mHeader + mHeaderOffset, buffer, bytes);
400         mHeaderOffset += bytes;// will contain header size when finished receiving header
401         return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
402     }
403 
404     if ((samples == 0) || !mEncoderWriteData) {
405         // called by the encoder because there's header data to save, but it's not the role
406         // of this component (unless WRITE_FLAC_HEADER_IN_FIRST_BUFFER is defined)
407         ALOGV("ignoring %zu bytes of header data (samples=%d)", bytes, samples);
408         return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
409     }
410 
411     // write encoded data
412     C2WriteView wView = mOutputBlock->map().get();
413     uint8_t* outData = wView.data();
414     const uint32_t sampleRate = mIntf->getSampleRate();
415     const int64_t outTimeStamp = mProcessedSamples * 1000000ll / sampleRate;
416     ALOGV("writing %zu bytes of encoded data on output", bytes);
417     // increment mProcessedSamples to maintain audio synchronization during
418     // play back
419     mProcessedSamples += samples;
420     if (bytes + mEncoderReturnedNbBytes > mOutputBlock->capacity()) {
421         ALOGE("not enough space left to write encoded data, dropping %zu bytes", bytes);
422         // a fatal error would stop the encoding
423         return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
424     }
425     memcpy(outData + mEncoderReturnedNbBytes, buffer, bytes);
426 
427     std::shared_ptr<C2Buffer> c2Buffer =
428         createLinearBuffer(mOutputBlock, mEncoderReturnedNbBytes, bytes);
429     mOutputBuffers.push_back({c2Buffer, mAnchorTimeStamp + outTimeStamp, current_frame});
430     mEncoderReturnedNbBytes += bytes;
431 
432     return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
433 }
434 
435 
configureEncoder()436 status_t C2SoftFlacEnc::configureEncoder() {
437     ALOGV("%s numChannel=%d, sampleRate=%d", __func__, mIntf->getChannelCount(), mIntf->getSampleRate());
438 
439     if (mSignalledError || !mFlacStreamEncoder) {
440         ALOGE("can't configure encoder: no encoder or invalid state");
441         return UNKNOWN_ERROR;
442     }
443 
444     const bool inputFloat = mIntf->getPcmEncodingInfo() == C2Config::PCM_FLOAT;
445     const int bitsPerSample = inputFloat ? 24 : 16;
446     FLAC__bool ok = true;
447     ok = ok && FLAC__stream_encoder_set_channels(mFlacStreamEncoder, mIntf->getChannelCount());
448     ok = ok && FLAC__stream_encoder_set_sample_rate(mFlacStreamEncoder, mIntf->getSampleRate());
449     ok = ok && FLAC__stream_encoder_set_bits_per_sample(mFlacStreamEncoder, bitsPerSample);
450     ok = ok && FLAC__stream_encoder_set_compression_level(mFlacStreamEncoder,
451                     mIntf->getComplexity());
452     ok = ok && FLAC__stream_encoder_set_verify(mFlacStreamEncoder, false);
453     if (!ok) {
454         ALOGE("unknown error when configuring encoder");
455         return UNKNOWN_ERROR;
456     }
457 
458     ok &= FLAC__STREAM_ENCODER_INIT_STATUS_OK ==
459             FLAC__stream_encoder_init_stream(mFlacStreamEncoder,
460                     flacEncoderWriteCallback    /*write_callback*/,
461                     nullptr /*seek_callback*/,
462                     nullptr /*tell_callback*/,
463                     nullptr /*metadata_callback*/,
464                     (void *) this /*client_data*/);
465 
466     if (!ok) {
467         ALOGE("unknown error when configuring encoder");
468         return UNKNOWN_ERROR;
469     }
470 
471     mBlockSize = FLAC__stream_encoder_get_blocksize(mFlacStreamEncoder);
472 
473     // Update kMaxBlockSize to match maximum size used by the encoder
474     CHECK(mBlockSize <= kMaxBlockSize);
475 
476     ALOGV("encoder successfully configured");
477     return OK;
478 }
479 
flacEncoderWriteCallback(const FLAC__StreamEncoder *,const FLAC__byte buffer[],size_t bytes,unsigned samples,unsigned current_frame,void * client_data)480 FLAC__StreamEncoderWriteStatus C2SoftFlacEnc::flacEncoderWriteCallback(
481             const FLAC__StreamEncoder *,
482             const FLAC__byte buffer[],
483             size_t bytes,
484             unsigned samples,
485             unsigned current_frame,
486             void *client_data) {
487     return ((C2SoftFlacEnc*) client_data)->onEncodedFlacAvailable(
488             buffer, bytes, samples, current_frame);
489 }
490 
drain(uint32_t drainMode,const std::shared_ptr<C2BlockPool> & pool)491 c2_status_t C2SoftFlacEnc::drain(
492         uint32_t drainMode,
493         const std::shared_ptr<C2BlockPool> &pool) {
494     (void) pool;
495     switch (drainMode) {
496         case NO_DRAIN:
497             ALOGW("drain with NO_DRAIN: no-op");
498             return C2_OK;
499         case DRAIN_CHAIN:
500             ALOGW("DRAIN_CHAIN not supported");
501             return C2_OMITTED;
502         case DRAIN_COMPONENT_WITH_EOS:
503             // TODO: This flag is not being sent back to the client
504             // because there are no items in PendingWork queue as all the
505             // inputs are being sent back with emptywork or valid encoded data
506             // mSignalledOutputEos = true;
507         case DRAIN_COMPONENT_NO_EOS:
508             break;
509         default:
510             return C2_BAD_VALUE;
511     }
512     FLAC__bool ok = FLAC__stream_encoder_finish(mFlacStreamEncoder);
513     if (!ok) return C2_CORRUPTED;
514 
515     return C2_OK;
516 }
517 
518 class C2SoftFlacEncFactory : public C2ComponentFactory {
519 public:
C2SoftFlacEncFactory()520     C2SoftFlacEncFactory() : mHelper(std::static_pointer_cast<C2ReflectorHelper>(
521             GetCodec2PlatformComponentStore()->getParamReflector())) {
522     }
523 
createComponent(c2_node_id_t id,std::shared_ptr<C2Component> * const component,std::function<void (C2Component *)> deleter)524     virtual c2_status_t createComponent(
525             c2_node_id_t id,
526             std::shared_ptr<C2Component>* const component,
527             std::function<void(C2Component*)> deleter) override {
528         *component = std::shared_ptr<C2Component>(
529                 new C2SoftFlacEnc(COMPONENT_NAME,
530                                   id,
531                                   std::make_shared<C2SoftFlacEnc::IntfImpl>(mHelper)),
532                 deleter);
533         return C2_OK;
534     }
535 
createInterface(c2_node_id_t id,std::shared_ptr<C2ComponentInterface> * const interface,std::function<void (C2ComponentInterface *)> deleter)536     virtual c2_status_t createInterface(
537             c2_node_id_t id,
538             std::shared_ptr<C2ComponentInterface>* const interface,
539             std::function<void(C2ComponentInterface*)> deleter) override {
540         *interface = std::shared_ptr<C2ComponentInterface>(
541                 new SimpleInterface<C2SoftFlacEnc::IntfImpl>(
542                         COMPONENT_NAME, id, std::make_shared<C2SoftFlacEnc::IntfImpl>(mHelper)),
543                 deleter);
544         return C2_OK;
545     }
546 
547     virtual ~C2SoftFlacEncFactory() override = default;
548 private:
549     std::shared_ptr<C2ReflectorHelper> mHelper;
550 };
551 
552 }  // namespace android
553 
554 __attribute__((cfi_canonical_jump_table))
CreateCodec2Factory()555 extern "C" ::C2ComponentFactory* CreateCodec2Factory() {
556     ALOGV("in %s", __func__);
557     return new ::android::C2SoftFlacEncFactory();
558 }
559 
560 __attribute__((cfi_canonical_jump_table))
DestroyCodec2Factory(::C2ComponentFactory * factory)561 extern "C" void DestroyCodec2Factory(::C2ComponentFactory* factory) {
562     ALOGV("in %s", __func__);
563     delete factory;
564 }
565