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, string componentName, 48 string statsFile); 49 50 void resetEncoder(); 51 52 private: 53 bool mIsAudioEncoder; 54 55 int32_t mWidth; 56 int32_t mHeight; 57 int32_t mFrameRate; 58 int32_t mSampleRate; 59 60 int32_t mNumInputFrame; 61 int32_t mInputMaxBufSize; 62 63 std::shared_ptr<android::Codec2Client::Listener> mListener; 64 std::shared_ptr<android::Codec2Client::Component> mComponent; 65 }; 66 67 #endif // __C2_ENCODER_H__ 68