1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef AUDIO_ENC_NATIVE_MOCK_H 17 #define AUDIO_ENC_NATIVE_MOCK_H 18 19 #include "avcodec_mock.h" 20 #include "avcodec_common.h" 21 #include "avcodec_audio_encoder.h" 22 23 namespace OHOS { 24 namespace Media { 25 class AudioEncNativeMock : public AudioEncMock { 26 public: AudioEncNativeMock(std::shared_ptr<AVCodecAudioEncoder> audioEnc)27 explicit AudioEncNativeMock(std::shared_ptr<AVCodecAudioEncoder> audioEnc) : audioEnc_(audioEnc) {} 28 ~AudioEncNativeMock() = default; 29 int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) override; 30 int32_t Configure(std::shared_ptr<FormatMock> format) override; 31 int32_t Prepare() override; 32 int32_t Start() override; 33 int32_t Stop() override; 34 int32_t Flush() override; 35 int32_t Reset() override; 36 int32_t Release() override; 37 int32_t PushInputData(uint32_t index, AVCodecBufferAttrMock &attr) override; 38 std::shared_ptr<FormatMock> GetOutputMediaDescription() override; 39 int32_t SetParameter(std::shared_ptr<FormatMock> format) override; 40 int32_t FreeOutputData(uint32_t index) override; 41 42 private: 43 std::shared_ptr<AVCodecAudioEncoder> audioEnc_ = nullptr; 44 }; 45 46 class AudioEncCallbackMock : public AVCodecCallback { 47 public: 48 AudioEncCallbackMock(std::shared_ptr<AVCodecCallbackMock> cb, std::weak_ptr<AVCodecAudioEncoder> ae); 49 ~AudioEncCallbackMock() = default; 50 void OnError(AVCodecErrorType errorType, int32_t errorCode) override; 51 void OnOutputFormatChanged(const Format &format) override; 52 void OnInputBufferAvailable(uint32_t index) override; 53 void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override; 54 55 private: 56 std::shared_ptr<AVCodecCallbackMock> mockCb_ = nullptr; 57 std::weak_ptr<AVCodecAudioEncoder> audioEnc_; 58 }; 59 } // namespace Media 60 } // namespace OHOS 61 #endif // AUDIO_ENC_NATIVE_MOCK_H