1 /*
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 __C2_ENCODER_H__
18 #define __C2_ENCODER_H__
19 
20 #include <stdio.h>
21 #include <algorithm>
22 #include <fstream>
23 
24 #include "BenchmarkC2Common.h"
25 
26 #define DEFAULT_AUDIO_FRAME_SIZE 4096
27 
28 constexpr int32_t KDefaultFrameRate = 25;
29 
30 class C2Encoder : public BenchmarkC2Common {
31   public:
C2Encoder()32     C2Encoder()
33         : mIsAudioEncoder(false),
34           mWidth(0),
35           mHeight(0),
36           mNumInputFrame(0),
37           mComponent(nullptr) {}
38 
39     int32_t createCodec2Component(string codecName, AMediaFormat *format);
40 
41     int32_t encodeFrames(ifstream &eleStream, size_t inputBufferSize);
42 
43     int32_t getInputMaxBufSize();
44 
45     void deInitCodec();
46 
47     void dumpStatistics(string inputReference, int64_t durationUs);
48 
49     void resetEncoder();
50 
51   private:
52     bool mIsAudioEncoder;
53 
54     int32_t mWidth;
55     int32_t mHeight;
56     int32_t mFrameRate;
57     int32_t mSampleRate;
58 
59     int32_t mNumInputFrame;
60     int32_t mInputMaxBufSize;
61 
62     std::shared_ptr<android::Codec2Client::Listener> mListener;
63     std::shared_ptr<android::Codec2Client::Component> mComponent;
64 };
65 
66 #endif  // __C2_ENCODER_H__
67