/* * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef VENC_SAMPLE_H #define VENC_SAMPLE_H #include #include #include #include #include #include #include #include "securec.h" #include "vcodec_mock.h" namespace OHOS { namespace MediaAVCodec { struct VEncSignal { public: std::mutex mutex_; std::mutex inMutex_; std::mutex outMutex_; std::condition_variable cond_; std::condition_variable inCond_; std::condition_variable outCond_; std::queue inIndexQueue_; std::queue outIndexQueue_; std::queue outAttrQueue_; std::queue> inBufferQueue_; std::queue> outBufferQueue_; int32_t errorNum_ = 0; std::atomic isRunning_ = false; }; class VEncCallbackTest : public AVCodecCallbackMock { public: explicit VEncCallbackTest(std::shared_ptr signal); virtual ~VEncCallbackTest(); void OnError(int32_t errorCode) override; void OnStreamChanged(std::shared_ptr format) override; void OnNeedInputData(uint32_t index, std::shared_ptr data) override; void OnNewOutputData(uint32_t index, std::shared_ptr data, OH_AVCodecBufferAttr attr) override; private: std::shared_ptr signal_ = nullptr; }; class VideoEncSample : public NoCopyable { public: explicit VideoEncSample(std::shared_ptr signal); virtual ~VideoEncSample(); bool CreateVideoEncMockByMime(const std::string &mime); bool CreateVideoEncMockByName(const std::string &name); int32_t Release(); int32_t SetCallback(std::shared_ptr cb); int32_t Configure(std::shared_ptr format); int32_t Start(); int32_t Stop(); int32_t Flush(); int32_t Reset(); std::shared_ptr GetOutputDescription(); int32_t SetParameter(std::shared_ptr format); int32_t FreeOutputData(uint32_t index); int32_t NotifyEos(); int32_t PushInputData(uint32_t index, OH_AVCodecBufferAttr &attr); std::shared_ptr CreateInputSurface(); bool IsValid(); private: std::shared_ptr videoEnc_ = nullptr; std::shared_ptr signal_ = nullptr; }; } // namespace MediaAVCodec } // namespace OHOS #endif // VENC_SAMPLE_H