/* * 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 VIDEODEC_API11_SAMPLE_H #define VIDEODEC_API11_SAMPLE_H #include #include #include #include #include #include #include #include #include #include #include "securec.h" #include "native_avcodec_videodecoder.h" #include "nocopyable.h" #include "native_avmemory.h" #include "native_avformat.h" #include "native_averrors.h" #include "surface/window.h" #include "iconsumer_surface.h" namespace OHOS { namespace Media { class VDecAPI11Signal { public: std::mutex inMutex_; std::mutex outMutex_; std::condition_variable inCond_; std::condition_variable outCond_; std::queue inIdxQueue_; std::queue outIdxQueue_; std::queue attrQueue_; std::queue inBufferQueue_; std::queue outBufferQueue_; }; class VDecAPI11Sample : public NoCopyable { public: VDecAPI11Sample() = default; ~VDecAPI11Sample(); int32_t RunVideoDec_Surface(std::string codeName = ""); int32_t RunVideoDec(std::string codeName = ""); const char *INP_DIR = "/data/test/media/1920_1080_10_30Mb.h264"; const char *OUT_DIR = "/data/test/media/VDecTest.yuv"; const char *OUT_DIR2 = "/data/test/media/VDecTest2.yuv"; bool SF_OUTPUT = false; bool TRANSFER_FLAG = false; bool NV21_FLAG = false; bool PREPARE_FLAG = true; bool IS_FIRST_FRAME = true; uint32_t DEFAULT_WIDTH = 1920; uint32_t DEFAULT_HEIGHT = 1080; uint32_t originalWidth = 0; uint32_t originalHeight = 0; uint32_t defualtPixelFormat = AV_PIXEL_FORMAT_NV12; uint32_t REPEAT_CALL_TIME = 10; uint32_t MAX_SURF_NUM = 2; double DEFAULT_FRAME_RATE = 30.0; uint32_t DEFAULT_RANGE_FLAG = 0; bool BEFORE_EOS_INPUT = false; // 0800 测试用例 bool BEFORE_EOS_INPUT_INPUT = false; // 0900 测试用例 bool AFTER_EOS_DESTORY_CODEC = true; // 1000 测试用例 结束不销毁codec uint32_t REPEAT_START_STOP_BEFORE_EOS = 0; // 1200 测试用例 uint32_t REPEAT_START_FLUSH_BEFORE_EOS = 0; // 1300 测试用例 uint32_t frameCount_ = 0; uint32_t repeat_time = 0; uint32_t outFrameCount = 0; bool outputYuvFlag = false; // 解码输出数据预期 bool needCheckOutputDesc = false; bool isResChangeStream = false; uint32_t expectCropTop = 0; uint32_t expectCropBottom = 0; uint32_t expectCropLeft = 0; uint32_t expectCropRight = 0; int32_t stride_ = 0; int32_t sliceHeight_ = 0; int32_t picWidth_ = 0; int32_t picHeight_ = 0; int32_t Start(); int32_t Stop(); int32_t Flush(); int32_t Reset(); int32_t Prepare(); int32_t state_EOS(); void SetEOS(uint32_t index, OH_AVBuffer *buffer); void WaitForEOS(); int32_t ConfigureVideoDecoder(); int32_t StartDecoder(); int32_t StartVideoDecoder(); int64_t GetSystemTimeUs(); int32_t CreateVideoDecoder(std::string codeName); int32_t SetVideoDecoderCallback(); void testAPI(); int32_t SwitchSurface(); int32_t RepeatCallSetSurface(); int32_t Release(); int32_t SetParameter(OH_AVFormat *format); void CheckOutputDescription(); void AutoSwitchSurface(); void InputFunc(); int32_t PushData(uint32_t index, OH_AVBuffer *buffer); int32_t CheckAndReturnBufferSize(OH_AVBuffer *buffer); uint32_t SendData(uint32_t bufferSize, uint32_t index, OH_AVBuffer *buffer); void ProcessOutputData(OH_AVBuffer *buffer, uint32_t index); int32_t CheckAttrFlag(OH_AVCodecBufferAttr attr); void GetStride(); void InputFuncTest(); void InFuncTest(); void OutputFuncTest(); void ReleaseSignal(); void CreateSurface(); void ReleaseInFile(); void StopInloop(); void Flush_buffer(); void StopOutloop(); bool IsRender(); void RenderOutAtTime(uint32_t index); bool MdCompare(uint8_t source[]); std::vector LoadHashFile(); VDecAPI11Signal *signal_; uint32_t errCount = 0; uint32_t outCount = 0; int64_t renderTimestampNs = 0; bool rsAtTime = false; int64_t outTimeArray[2000] = {}; bool sleepOnFPS = false; bool repeatRun = false; int64_t decode_count = 0; int64_t start_time = 0; int32_t maxInputSize = 0; int64_t end_time = 0; bool autoSwitchSurface = false; std::atomic isFlushing_ { false }; int32_t switchSurfaceFlag = 0; std::atomic isRunning_ { false }; bool inputCallbackFlush = false; bool inputCallbackStop = false; bool outputCallbackFlush = false; bool outputCallbackStop = false; bool useHDRSource = false; bool isAPI = false; int32_t DEFAULT_PROFILE = HEVC_PROFILE_MAIN_10; int32_t DecodeSetSurface(); private: std::unique_ptr inFile_; std::unique_ptr inputLoop_; std::unique_ptr outputLoop_; std::unordered_map inBufferMap_; std::unordered_map outBufferMap_; OH_AVCodec *vdec_; OH_AVCodecCallback cb_; int64_t timeStamp_ { 0}; int64_t lastRenderedTimeUs_ { 0 }; bool isFirstFrame_ = true; OHNativeWindow *nativeWindow[2] = {}; sptr cs[2] = {}; sptr ps[2] = {}; }; } // namespace Media } // namespace OHOS void VdecAPI11Error(OH_AVCodec *codec, int32_t errorCode, void *userData); void VdecAPI11FormatChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData); void VdecAPI11InputDataReady(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData); void VdecAPI11OutputDataReady(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *data, void *userData); #endif // VIDEODEC_SAMPLE_H