1 2 /* 3 * Copyright (C) 2023 Huawei Device Co., Ltd. 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 VIDEODEC_CAPI_MOCK_H 18 #define VIDEODEC_CAPI_MOCK_H 19 20 #include <map> 21 #include <mutex> 22 #include "native_avcodec_videodecoder.h" 23 #include "vcodec_mock.h" 24 25 26 namespace OHOS { 27 namespace MediaAVCodec { 28 class VideoDecCapiMock : public VideoDecMock { 29 public: VideoDecCapiMock(OH_AVCodec * codec)30 explicit VideoDecCapiMock(OH_AVCodec *codec) : codec_(codec) {} 31 ~VideoDecCapiMock() = default; 32 int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) override; 33 int32_t SetOutputSurface(std::shared_ptr<SurfaceMock> surface) override; 34 int32_t Configure(std::shared_ptr<FormatMock> format) override; 35 int32_t Start() override; 36 int32_t Stop() override; 37 int32_t Flush() override; 38 int32_t Reset() override; 39 int32_t Release() override; 40 std::shared_ptr<FormatMock> GetOutputDescription() override; 41 int32_t SetParameter(std::shared_ptr<FormatMock> format) override; 42 int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr) override; 43 int32_t RenderOutputData(uint32_t index) override; 44 int32_t FreeOutputData(uint32_t index) override; 45 bool IsValid() override; 46 47 private: 48 static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData); 49 static void OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData); 50 static void OnNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData); 51 static void OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr, 52 void *userData); 53 54 static void SetCallback(OH_AVCodec *codec, std::shared_ptr<AVCodecCallbackMock> cb); 55 static void DelCallback(OH_AVCodec *codec); 56 static std::shared_ptr<AVCodecCallbackMock> GetCallback(OH_AVCodec *codec); 57 58 static std::mutex mutex_; 59 static std::map<OH_AVCodec *, std::shared_ptr<AVCodecCallbackMock>> mockCbMap_; 60 OH_AVCodec *codec_ = nullptr; 61 }; 62 } // namespace MediaAVCodec 63 } // namespace OHOS 64 #endif // VIDEODEC_CAPI_MOCK_H