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 VIDEO_DEC_NATIVE_MOCK_H 17 #define VIDEO_DEC_NATIVE_MOCK_H 18 19 #include "avcodec_mock.h" 20 #include "avcodec_common.h" 21 #include "avcodec_video_decoder.h" 22 23 namespace OHOS { 24 namespace Media { 25 class VideoDecNativeMock : public VideoDecMock { 26 public: VideoDecNativeMock(std::shared_ptr<AVCodecVideoDecoder> videoDec)27 explicit VideoDecNativeMock(std::shared_ptr<AVCodecVideoDecoder> videoDec) : videoDec_(videoDec) {} 28 ~VideoDecNativeMock() = default; 29 int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) override; 30 int32_t SetOutputSurface(std::shared_ptr<SurfaceMock> surface) override; 31 int32_t Configure(std::shared_ptr<FormatMock> format) override; 32 int32_t Prepare() override; 33 int32_t Start() override; 34 int32_t Stop() override; 35 int32_t Flush() override; 36 int32_t Reset() override; 37 int32_t Release() override; 38 std::shared_ptr<FormatMock> GetOutputMediaDescription() override; 39 int32_t SetParameter(std::shared_ptr<FormatMock> format) override; 40 int32_t PushInputData(uint32_t index, AVCodecBufferAttrMock &attr) override; 41 int32_t RenderOutputData(uint32_t index) override; 42 int32_t FreeOutputData(uint32_t index) override; 43 44 private: 45 std::shared_ptr<AVCodecVideoDecoder> videoDec_ = nullptr; 46 }; 47 48 class VideoDecCallbackMock : public AVCodecCallback { 49 public: 50 VideoDecCallbackMock(std::shared_ptr<AVCodecCallbackMock> cb, std::weak_ptr<AVCodecVideoDecoder> vd); 51 ~VideoDecCallbackMock() = default; 52 void OnError(AVCodecErrorType errorType, int32_t errorCode) override; 53 void OnOutputFormatChanged(const Format &format) override; 54 void OnInputBufferAvailable(uint32_t index) override; 55 void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override; 56 57 private: 58 std::shared_ptr<AVCodecCallbackMock> mockCb_ = nullptr; 59 std::weak_ptr<AVCodecVideoDecoder> videoDec_; 60 }; 61 } // namespace Media 62 } // namespace OHOS 63 #endif // VIDEO_DEC_NATIVE_MOCK_H