blob: 69e5240062a6df6a038816bc8a90e93979436d03 [file] [log] [blame]
Manisha Jajooc237cbc2018-11-16 18:56:20 +05301/*
2 * Copyright (C) 2019 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#ifndef ANDROID_C2_SOFT_OPUS_ENC_H_
18#define ANDROID_C2_SOFT_OPUS_ENC_H_
19
20#include <atomic>
21#include <SimpleC2Component.h>
22#define MIN(a, b) (((a) < (b)) ? (a) : (b))
23
24struct OpusMSEncoder;
25
26namespace android {
27
28struct C2SoftOpusEnc : public SimpleC2Component {
29 class IntfImpl;
30
31 C2SoftOpusEnc(const char *name, c2_node_id_t id,
32 const std::shared_ptr<IntfImpl> &intfImpl);
33 virtual ~C2SoftOpusEnc();
34
35 // From SimpleC2Component
36 c2_status_t onInit() override;
37 c2_status_t onStop() override;
38 void onReset() override;
39 void onRelease() override;
40 c2_status_t onFlush_sm() override;
41 void process(
42 const std::unique_ptr<C2Work> &work,
43 const std::shared_ptr<C2BlockPool> &pool) override;
44 c2_status_t drain(
45 uint32_t drainMode,
46 const std::shared_ptr<C2BlockPool> &pool) override;
47private:
48 /* OPUS_FRAMESIZE_20_MS */
49 const int kFrameSize = 960;
50 const int kMaxPayload = 4000;
51 const int kMaxNumChannels = 8;
52
53 std::shared_ptr<IntfImpl> mIntf;
54 std::shared_ptr<C2LinearBlock> mOutputBlock;
55
56 OpusMSEncoder* mEncoder;
57 int16_t* mInputBufferPcm16;
58
59 bool mHeaderGenerated;
60 bool mIsFirstFrame;
61 bool mEncoderFlushed;
62 bool mBufferAvailable;
63 bool mSignalledEos;
64 bool mSignalledError;
65 uint32_t mSampleRate;
66 uint32_t mChannelCount;
67 uint32_t mFrameDurationMs;
68 uint64_t mAnchorTimeStamp;
69 uint64_t mProcessedSamples;
70 // Codec delay in ns
71 uint64_t mCodecDelay;
72 // Seek pre-roll in ns
73 uint64_t mSeekPreRoll;
74 int mNumSamplesPerFrame;
75 int mBytesEncoded;
76 int32_t mFilledLen;
77 size_t mNumPcmBytesPerInputFrame;
78 std::atomic_uint64_t mOutIndex;
79 c2_status_t initEncoder();
80 c2_status_t configureEncoder();
81 int drainEncoder(uint8_t* outPtr);
82 c2_status_t drainInternal(const std::shared_ptr<C2BlockPool>& pool,
83 const std::unique_ptr<C2Work>& work);
84
85 C2_DO_NOT_COPY(C2SoftOpusEnc);
86};
87
88} // namespace android
89
90#endif // ANDROID_C2_SOFT_OPUS_ENC_H_