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 VIDEOENC_CAPI_MOCK_H 17 #define VIDEOENC_CAPI_MOCK_H 18 19 #include <mutex> 20 #include <map> 21 #include "vcodec_mock.h" 22 #include "native_avcodec_videoencoder.h" 23 24 25 namespace OHOS { 26 namespace MediaAVCodec { 27 class VideoEncCapiMock : public VideoEncMock { 28 public: VideoEncCapiMock(OH_AVCodec * codec)29 explicit VideoEncCapiMock(OH_AVCodec *codec) : codec_(codec) {} 30 int32_t SetCallback(std::shared_ptr<AVCodecCallbackMock> cb) override; 31 int32_t Configure(std::shared_ptr<FormatMock> format) 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 std::shared_ptr<FormatMock> GetOutputDescription() override; 38 int32_t SetParameter(std::shared_ptr<FormatMock> format) override; 39 int32_t FreeOutputData(uint32_t index) override; 40 int32_t NotifyEos() override; 41 int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr) override; 42 std::shared_ptr<SurfaceMock> CreateInputSurface() override; 43 bool IsValid() override; 44 45 private: 46 static void OnError(OH_AVCodec *codec, int32_t errorCode, void *userData); 47 static void OnStreamChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData); 48 static void OnNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData); 49 static void OnNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, 50 OH_AVCodecBufferAttr *attr, void *userData); 51 static void SetCallback(OH_AVCodec *codec, std::shared_ptr<AVCodecCallbackMock> cb); 52 static void DelCallback(OH_AVCodec *codec); 53 static std::shared_ptr<AVCodecCallbackMock> GetCallback(OH_AVCodec *codec); 54 55 static std::mutex mutex_; 56 static std::map<OH_AVCodec *, std::shared_ptr<AVCodecCallbackMock>> mockCbMap_; 57 OH_AVCodec *codec_ = nullptr; 58 }; 59 } // namespace MediaAVCodec 60 } // namespace OHOS 61 #endif // VIDEOENC_CAPI_MOCK_H