1 /* 2 * Copyright (C) 2023 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 VIDEO_ENC_INNER_MOCK_H 17 #define VIDEO_ENC_INNER_MOCK_H 18 19 #include "vcodec_mock.h" 20 #include "avcodec_video_encoder.h" 21 22 namespace OHOS { 23 namespace MediaAVCodec { 24 class VideoEncInnerMock : public VideoEncMock { 25 public: VideoEncInnerMock(std::shared_ptr<AVCodecVideoEncoder> videoEnc)26 explicit VideoEncInnerMock(std::shared_ptr<AVCodecVideoEncoder> videoEnc) : videoEnc_(videoEnc) {} 27 int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) override; 28 int32_t Configure(std::shared_ptr<FormatMock> format) override; 29 int32_t Start() override; 30 int32_t Stop() override; 31 int32_t Flush() override; 32 int32_t Reset() override; 33 int32_t Release() override; 34 std::shared_ptr<FormatMock> GetOutputDescription() override; 35 int32_t SetParameter(std::shared_ptr<FormatMock> format) override; 36 int32_t FreeOutputData(uint32_t index) override; 37 int32_t NotifyEos() override; 38 int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr) override; 39 std::shared_ptr<SurfaceMock> CreateInputSurface() override; 40 bool IsValid() override; 41 42 private: 43 std::shared_ptr<AVCodecVideoEncoder> videoEnc_ = nullptr; 44 }; 45 46 class VideoEncCallbackMock : public AVCodecCallback { 47 public: 48 VideoEncCallbackMock(std::shared_ptr<AVCodecCallbackMock> cb, std::weak_ptr<AVCodecVideoEncoder> ve); 49 ~VideoEncCallbackMock() = default; 50 void OnError(AVCodecErrorType errorType, int32_t errorCode) override; 51 void OnOutputFormatChanged(const Format &format) override; 52 void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVSharedMemory> buffer) override; 53 void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag, 54 std::shared_ptr<AVSharedMemory> buffer) override; 55 56 private: 57 std::shared_ptr<AVCodecCallbackMock> mockCb_ = nullptr; 58 std::weak_ptr<AVCodecVideoEncoder> videoEnc_; 59 }; 60 } // namespace MediaAVCodec 61 } // namespace OHOS 62 #endif // VIDEO_ENC_INNER_MOCK_H