From d4150dd9d1c5836c3d3675c85ab5b575909f0bf9 Mon Sep 17 00:00:00 2001 From: West Date: Thu, 7 Dec 2023 12:09:02 +0800 Subject: [PATCH 01/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91add=20perf=20test=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I02444787c5ab528f26fef182c024346acfbc6aaa --- config.gni | 1 + 1 file changed, 1 insertion(+) diff --git a/config.gni b/config.gni index 5d7cfd3b6..8539f650b 100644 --- a/config.gni +++ b/config.gni @@ -23,6 +23,7 @@ declare_args() { av_codec_support_test = true av_codec_support_xcollie = true av_codec_support_bitstream_dump = true + av_codec_support_codec_perf_test = false } av_codec_sanitize = { cfi = true -- Gitee From 0b6f82c33bb67ceb967f07ee175dffe30604cd32 Mon Sep 17 00:00:00 2001 From: West Date: Sun, 10 Dec 2023 23:17:39 +0800 Subject: [PATCH 02/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Add=20perf=20test=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I1cbd9ff04c3a26894aaab16d6f6f934715b32518 --- test/BUILD.gn | 5 + test/unittest/video_perf_test/BUILD.gn | 71 +++++ .../common/include/av_codec_sample_error.h | 24 ++ .../common/include/av_codec_sample_log.h | 24 ++ .../common/include/sample_callback.h | 29 ++ .../common/include/sample_info.h | 91 ++++++ .../common/sample_callback.cpp | 74 +++++ .../sample/decoder/include/video_decoder.h | 41 +++ .../include/video_decoder_perf_test_sample.h | 46 +++ .../sample/decoder/video_decoder.cpp | 161 +++++++++++ .../video_decoder_perf_test_sample.cpp | 269 ++++++++++++++++++ .../sample/encoder/include/video_encoder.h | 42 +++ .../include/video_encoder_perf_test_sample.h | 43 +++ .../sample/encoder/video_encoder.cpp | 181 ++++++++++++ .../video_encoder_perf_test_sample.cpp | 240 ++++++++++++++++ .../video_decoder_perf_test_suilt.cpp | 214 ++++++++++++++ .../video_encoder_perf_test_suilt.cpp | 9 + 17 files changed, 1564 insertions(+) create mode 100644 test/unittest/video_perf_test/BUILD.gn create mode 100644 test/unittest/video_perf_test/common/include/av_codec_sample_error.h create mode 100644 test/unittest/video_perf_test/common/include/av_codec_sample_log.h create mode 100644 test/unittest/video_perf_test/common/include/sample_callback.h create mode 100644 test/unittest/video_perf_test/common/include/sample_info.h create mode 100644 test/unittest/video_perf_test/common/sample_callback.cpp create mode 100644 test/unittest/video_perf_test/sample/decoder/include/video_decoder.h create mode 100644 test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h create mode 100644 test/unittest/video_perf_test/sample/decoder/video_decoder.cpp create mode 100644 test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp create mode 100644 test/unittest/video_perf_test/sample/encoder/include/video_encoder.h create mode 100644 test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h create mode 100644 test/unittest/video_perf_test/sample/encoder/video_encoder.cpp create mode 100644 test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp create mode 100644 test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp create mode 100644 test/unittest/video_perf_test/test_suilt/video_encoder_perf_test_suilt.cpp diff --git a/test/BUILD.gn b/test/BUILD.gn index 9aeaf540a..9f99b8c0b 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -53,6 +53,11 @@ group("av_codec_unit_test") { "unittest/video_test/vcodec_framework_test:videoenc_inner_unit_test", ] } + if (av_codec_support_codec_perf_test) { + deps += [ + "unittest/video_perf_test:video_perf_test" + ] + } } } diff --git a/test/unittest/video_perf_test/BUILD.gn b/test/unittest/video_perf_test/BUILD.gn new file mode 100644 index 000000000..994a5f826 --- /dev/null +++ b/test/unittest/video_perf_test/BUILD.gn @@ -0,0 +1,71 @@ +# 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. + +import("//build/test.gni") +import("//foundation/multimedia/av_codec/config.gni") + +ohos_unittest("video_perf_test") { + module_out_path = "av_codec/unittest/perf_test" + + include_dirs = [ + "./common/include", + "./sample/decoder/include", + "./sample/encoder/include", + "./test_suilt/include", + "$av_codec_root_dir/interfaces/kits/c", + "$av_codec_root_dir/services/dfx/include" + ] + + cflags = [ + "-std=c++17", + "-fno-rtti", + "-fno-exceptions", + "-Wall", + "-fno-common", + "-fstack-protector-strong", + "-Wshadow", + "-FPIC", + "-FS", + "-O2", + "-D_FORTIFY_SOURCE=2", + "-fvisibility=hidden", + "-Wformat=2", + "-Wdate-time", + "-Werror", + "-Wextra", + "-Wimplicit-fallthrough", + "-Wsign-compare", + "-Wunused-parameter", + ] + + sources = [ + "./common/sample_callback.cpp", + "./sample/decoder/video_decoder_perf_test_sample.cpp", + "./sample/decoder/video_decoder.cpp", + "./sample/encoder/video_encoder_perf_test_sample.cpp", + "./sample/encoder/video_encoder.cpp", + "./test_suilt/video_decoder_perf_test_suilt.cpp", + "./test_suilt/video_encoder_perf_test_suilt.cpp", + ] + + deps = [ "$av_codec_root_dir/interfaces/kits/c:capi_packages" ] + + public_deps = [] + + external_deps = [ + "c_utils:utils", + "graphic_2d:surface", + "hilog:libhilog", + "histreamer:media_foundation", + ] +} \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/include/av_codec_sample_error.h b/test/unittest/video_perf_test/common/include/av_codec_sample_error.h new file mode 100644 index 000000000..c9136caa3 --- /dev/null +++ b/test/unittest/video_perf_test/common/include/av_codec_sample_error.h @@ -0,0 +1,24 @@ +/* + * 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 AVCODEC_SAMPLE_ERROE_H +#define AVCODEC_SAMPLE_ERROE_H + +enum AVCodecSampleError : int { + AVCODEC_SAMPLE_ERR_OK = 0, + AVCODEC_SAMPLE_ERR_ERROR = -1, +}; + +#endif // AVCODEC_SAMPLE_ERROE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/include/av_codec_sample_log.h b/test/unittest/video_perf_test/common/include/av_codec_sample_log.h new file mode 100644 index 000000000..fbf6a69b9 --- /dev/null +++ b/test/unittest/video_perf_test/common/include/av_codec_sample_log.h @@ -0,0 +1,24 @@ +/* + * 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 AVCODEC_TEST_LOG_H +#define AVCODEC_TEST_LOG_H + +#include "avcodec_log.h" + +#undef LOG_DOMAIN +#define LOG_DOMAIN 0xD002B66 + +#endif // AVCODEC_SAMPLE_LOG_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/include/sample_callback.h b/test/unittest/video_perf_test/common/include/sample_callback.h new file mode 100644 index 000000000..ed9ae8f6c --- /dev/null +++ b/test/unittest/video_perf_test/common/include/sample_callback.h @@ -0,0 +1,29 @@ +/* + * 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 AVCODEC_SAMPLE_SAMPLE_CALLBACK_H +#define AVCODEC_SAMPLE_SAMPLE_CALLBACK_H + +#include "sample_info.h" + +void OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *userData); +void OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, void *userData); +void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData); +void OnOutputBufferAvailable(OH_AVCodec * codec, uint32_t index, OH_AVMemory *data, + OH_AVCodecBufferAttr *attr, void *userData); +void onNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData); +void onNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData); + +#endif // AVCODEC_SAMPLE_SAMPLE_CALLBACK_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h new file mode 100644 index 000000000..86cbc3008 --- /dev/null +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -0,0 +1,91 @@ +/* + * 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 AVCODEC_SAMPLE_SAMPLE_INFO_H +#define AVCODEC_SAMPLE_SAMPLE_INFO_H +#include +#include +#include +#include +#include "native_avcodec_base.h" +#include "native_avbuffer.h" + +constexpr std::string_view MIME_VIDEO_AVC = "video/avc"; +constexpr std::string_view MIME_VIDEO_HEVC = "video/hevc"; + +constexpr int32_t BITRATE_10M = 10 * 1024 * 1024; // 10Mbps +constexpr int32_t BITRATE_20M = 20 * 1024 * 1024; // 20Mbps +constexpr int32_t BITRATE_30M = 30 * 1024 * 1024; // 30Mbps + +enum TestMode { + FRAME_DELAY, + FRAME_RATE, +}; + +/* CodecRunMode description + * +-----+------------+--------------+ + * | Bit | 01 | 00 | + * +-----+------------+--------------+ + * |Field| IsAVBuffer | IsBufferMode | + * +-----+------------+--------------+ + */ +enum CodecRunMode { + SURFACE_ORIGIN = (0 << 1) | 0, + BUFFER_SHARED_MEMORY = (0 << 1) | 1, + SURFACE_AVBUFFER = (1 << 1) | 0, + BUFFER_AVBUFFER = (1 << 1) | 1, +}; + +struct SampleInfo { + std::string_view inputFilePath; + std::string_view codecMime; + int32_t videoWidth = 0; + int32_t videoHeight = 0; + double frameRate = 0.0; + int64_t bitrate = 10 * 1024 * 1024; // 10Mbps; + + CodecRunMode codecRunMode; + TestMode testMode; + int32_t frameInterval = 0; + NativeWindow* window = nullptr; +}; + +struct CodecBufferInfo { + uint32_t bufferIndex = 0; + uintptr_t *buffer = nullptr; + OH_AVCodecBufferAttr attr = {0, 0, 0, AVCODEC_BUFFER_FLAGS_NONE}; + + CodecBufferInfo(uint32_t argBufferIndex, OH_AVMemory *argBuffer, OH_AVCodecBufferAttr argAttr): + bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)), attr(argAttr) {}; + CodecBufferInfo(uint32_t argBufferIndex, OH_AVMemory *argBuffer): + bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) {}; + CodecBufferInfo(uint32_t argBufferIndex, OH_AVBuffer *argBuffer): + bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) {}; +}; + +class CodecUserData { +public: + int32_t inputFrameCount_ = 0; + std::mutex inputMutex_; + std::condition_variable inputCond_; + std::queue inputBufferInfoQueue_; + + int32_t outputFrameCount_ = 0; + std::mutex outputMutex_; + std::condition_variable outputCond_; + std::queue outputBufferInfoQueue_; +}; + +#endif // AVCODEC_SAMPLE_SAMPLE_INFO_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp new file mode 100644 index 000000000..b3a40c1f3 --- /dev/null +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -0,0 +1,74 @@ +#include "sample_callback.h" +#include "av_codec_sample_log.h" + +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SampleCallback"}; +constexpr int LIMIT_LOGD_FREQUENCY = 50; +} + +void OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *userData) +{ + AVCODEC_LOGE("On decoder error, error code: %{public}d", errorCode); +} + +void OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, void *userData) +{ + AVCODEC_LOGW("On decoder format change"); +} + +void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData) +{ + if (userData == nullptr) { + return; + } + CodecUserData *codecUserData = static_cast(userData); + codecUserData->inputFrameCount_++; + AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "On input buffer available, frameCount: %{public}d", + codecUserData->inputFrameCount_); + std::unique_lock lock(codecUserData->inputMutex_); + codecUserData->inputBufferInfoQueue_.emplace(index, data); + codecUserData->inputCond_.notify_all(); +} + +void OnOutputBufferAvailable(OH_AVCodec * codec, uint32_t index, OH_AVMemory *data, + OH_AVCodecBufferAttr *attr, void *userData) +{ + if (userData == nullptr) { + return; + } + CodecUserData *codecUserData = static_cast(userData); + codecUserData->outputFrameCount_++; + AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "On output buffer available, frameCount: %{public}d", + codecUserData->outputFrameCount_); + std::unique_lock lock(codecUserData->outputMutex_); + codecUserData->outputBufferInfoQueue_.emplace(index, data, *attr); + codecUserData->outputCond_.notify_all(); +} + +void onNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) +{ + if (userData == nullptr) { + return; + } + CodecUserData *codecUserData = static_cast(userData); + codecUserData->inputFrameCount_++; + AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "On need input buffer, frameCount: %{public}d", + codecUserData->inputFrameCount_); + std::unique_lock lock(codecUserData->inputMutex_); + codecUserData->inputBufferInfoQueue_.emplace(index, buffer); + codecUserData->inputCond_.notify_all(); +} + +void onNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) +{ + if (userData == nullptr) { + return; + } + CodecUserData *codecUserData = static_cast(userData); + codecUserData->outputFrameCount_++; + AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "On need input buffer, frameCount: %{public}d", + codecUserData->outputFrameCount_); + std::unique_lock lock(codecUserData->outputMutex_); + codecUserData->outputBufferInfoQueue_.emplace(index, buffer); + codecUserData->outputCond_.notify_all(); +} \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h new file mode 100644 index 000000000..7c3c0fdf4 --- /dev/null +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h @@ -0,0 +1,41 @@ +/* + * 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 VIDEODECODER_H +#define VIDEODECODER_H + +#include "native_avcodec_videodecoder.h" +#include "sample_info.h" + +class VideoDecoder { +public: + VideoDecoder() = default; + ~VideoDecoder(); + + int32_t Create(const std::string_view &codecMime); + int32_t Config(const SampleInfo &sampleInfo, CodecUserData *codecUserData); + int32_t Start(); + int32_t PushInputData(CodecBufferInfo &info); + int32_t FreeOutputData(uint32_t bufferIndex); + int32_t Stop(); + int32_t Release(); + +private: + int32_t SetCallback(CodecUserData *codecUserData); + + OH_AVCodec *decoder_; + bool isAVBufferMode_; +}; +#endif //VIDEODECODER_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h new file mode 100644 index 000000000..484966f85 --- /dev/null +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -0,0 +1,46 @@ +#ifndef AVCODEC_TEST_VIDEO_PERF_TEST_DECODER_SAMPLE_H +#define AVCODEC_TEST_VIDEO_PERF_TEST_DECODER_SAMPLE_H + +#include +#include +#include +#include +#include +#include +#include "video_decoder.h" +#include "sample_info.h" +#include "surface.h" + +class VideoDecoderPerfTestSample { +public: + VideoDecoderPerfTestSample() {}; + ~VideoDecoderPerfTestSample(); + + int32_t Create(SampleInfo sampleInfo); + int32_t Start(); + int32_t WaitForDone(); + +private: + void StartRelease(); + void Release(); + void decInputThread(); + void decOutputThread(); + bool IsCodecData(const uint8_t *const bufferAddr); + int32_t ReadOneFrame(CodecBufferInfo &info); + int32_t CreateWindow(OHNativeWindow *&window); + + std::unique_ptr videoDecoder_ = nullptr; + std::unique_ptr decInputThread_ = nullptr; + std::unique_ptr decOutputThread_ = nullptr; + std::unique_ptr releaseThread_ = nullptr; + std::unique_ptr inputFile_ = nullptr; + + std::mutex mutex_; + std::atomic isStarted_ { false }; + std::condition_variable doneCond_; + SampleInfo sampleInfo_; + CodecUserData *decContext_ = nullptr; + OHOS::sptr surface_; +}; + +#endif // AVCODEC_TEST_VIDEO_PERF_TEST_DECODER_SAMPLE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp new file mode 100644 index 000000000..1e6418643 --- /dev/null +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp @@ -0,0 +1,161 @@ +/* + * 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. + */ + +#include "video_decoder.h" +#include "av_codec_sample_error.h" +#include "av_codec_sample_log.h" +#include "sample_callback.h" + +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoDecoder"}; +} // namespace + +VideoDecoder::~VideoDecoder() +{ + Release(); +} + +int32_t VideoDecoder::Create(const std::string_view &codecMime) +{ + decoder_ = OH_VideoDecoder_CreateByMime(codecMime.data()); + CHECK_AND_RETURN_RET_LOG(decoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Create failed"); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoDecoder::Config(const SampleInfo &sampleInfo, CodecUserData *codecUserData) +{ + CHECK_AND_RETURN_RET_LOG(decoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Decoder is null"); + CHECK_AND_RETURN_RET_LOG(codecUserData != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Invalid param: codecUserData"); + isAVBufferMode_ = (static_cast(sampleInfo.codecRunMode) & 0b10); // ob10: AVBuffer mode mask + + // Configure video decoder + { + OH_AVFormat *format = OH_AVFormat_Create(); + CHECK_AND_RETURN_RET_LOG(format != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "AVFormat create failed"); + + OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); + OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); + + AVCODEC_LOGI("====== VideoDecoder config ======"); + AVCODEC_LOGI("%{public}d*%{public}d, %{public}.1ffps", + sampleInfo.videoWidth, sampleInfo.videoHeight, sampleInfo.frameRate); + AVCODEC_LOGI("====== VideoDecoder config ======"); + + int ret = OH_VideoDecoder_Configure(decoder_, format); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Config failed, ret: %{public}d", ret); + OH_AVFormat_Destroy(format); + format = nullptr; + } + + // SetSurface from video decoder + if (sampleInfo.window != nullptr) + { + int ret = OH_VideoDecoder_SetSurface(decoder_, sampleInfo.window); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK && sampleInfo.window, AVCODEC_SAMPLE_ERR_ERROR, + "Set surface failed, ret: %{public}d", ret); + } + + // SetCallback for video decoder + { + int32_t ret = SetCallback(codecUserData); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, + "Set callback failed, ret: %{public}d", ret); + } + + // Prepare video decoder + { + int ret = OH_VideoDecoder_Prepare(decoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Prepare failed, ret: %{public}d", ret); + } + + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoDecoder::Start() +{ + CHECK_AND_RETURN_RET_LOG(decoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Decoder is null"); + + int ret = OH_VideoDecoder_Start(decoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Start failed, ret: %{public}d", ret); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoDecoder::PushInputData(CodecBufferInfo &info) +{ + CHECK_AND_RETURN_RET_LOG(decoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Decoder is null"); + + int32_t ret = AV_ERR_OK; + if (isAVBufferMode_) { + ret = OH_AVBuffer_SetBufferAttr( + reinterpret_cast(info.buffer), reinterpret_cast(&info.attr)); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Set avbuffer attr failed"); + ret = OH_VideoDecoder_PushInputBuffer(decoder_, info.bufferIndex); + } else { + ret = OH_VideoDecoder_PushInputData(decoder_, info.bufferIndex, info.attr); + } + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Push input data failed"); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoDecoder::FreeOutputData(uint32_t bufferIndex) +{ + CHECK_AND_RETURN_RET_LOG(decoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Decoder is null"); + + int32_t ret = AVCODEC_SAMPLE_ERR_OK; + if (isAVBufferMode_) { + ret = OH_VideoDecoder_FreeOutputBuffer(decoder_, bufferIndex); + } else { + ret = OH_VideoDecoder_FreeOutputData(decoder_, bufferIndex); + } + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Free output data failed"); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoDecoder::Stop() +{ + CHECK_AND_RETURN_RET_LOG(decoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Decoder is null"); + + int ret = OH_VideoDecoder_Flush(decoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Flush failed, ret: %{public}d", ret); + + ret = OH_VideoDecoder_Stop(decoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Stop failed, ret: %{public}d", ret); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoDecoder::Release() +{ + if (decoder_ != nullptr) { + OH_VideoDecoder_Destroy(decoder_); + decoder_ = nullptr; + } + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoDecoder::SetCallback(CodecUserData *codecUserData) +{ + int32_t ret = AV_ERR_OK; + if (isAVBufferMode_) { + ret = OH_VideoDecoder_RegisterCallback(decoder_, + {OnCodecError, OnCodecFormatChange, onNeedInputBuffer, onNewOutputBuffer}, codecUserData); + } else { + ret = OH_VideoDecoder_SetCallback(decoder_, + {OnCodecError, OnCodecFormatChange, OnInputBufferAvailable, OnOutputBufferAvailable}, codecUserData); + } + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Set callback failed, ret: %{public}d", ret); + + return AVCODEC_SAMPLE_ERR_OK; +} diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp new file mode 100644 index 000000000..5400b834c --- /dev/null +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -0,0 +1,269 @@ +/* + * 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. + */ + +#include "video_decoder_perf_test_sample.h" +#include +#include "av_codec_sample_log.h" +#include "av_codec_sample_error.h" +#include "iconsumer_surface.h" +#include "window.h" +#include "refbase.h" + +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoDecoderSample"}; +constexpr uint8_t AVCC_FRAME_HEAD_LEN = 4; +} + +class SurfaceConsumer : public OHOS::IBufferConsumerListener { +public: + SurfaceConsumer(OHOS::sptr cs, std::string_view name) : cs(cs) {}; + ~SurfaceConsumer() {} + void OnBufferAvailable() override + { + OHOS::sptr buffer; + int32_t flushFence; + cs->AcquireBuffer(buffer, flushFence, timestamp, damage); + + cs->ReleaseBuffer(buffer, -1); + } + +private: + int64_t timestamp = 0; + OHOS::Rect damage = {}; + OHOS::sptr cs {nullptr}; +}; + +VideoDecoderPerfTestSample::~VideoDecoderPerfTestSample() +{ + StartRelease(); + if (releaseThread_ && releaseThread_->joinable()) { + releaseThread_->join(); + } +} + +int32_t VideoDecoderPerfTestSample::Create(SampleInfo sampleInfo) +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(!isStarted_, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + CHECK_AND_RETURN_RET_LOG(videoDecoder_ == nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + + sampleInfo_ = sampleInfo; + + videoDecoder_ = std::make_unique(); + CHECK_AND_RETURN_RET_LOG(videoDecoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, + "Create video decoder failed, no memory"); + + int32_t ret = videoDecoder_->Create(sampleInfo_.codecMime); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create video decoder failed"); + + decContext_ = new CodecUserData; + ret = CreateWindow(sampleInfo_.window); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create window failed"); + ret = videoDecoder_->Config(sampleInfo_, decContext_); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Decoder config failed"); + + releaseThread_ = nullptr; + AVCODEC_LOGI("Succeed"); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoDecoderPerfTestSample::Start() +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(!isStarted_, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + CHECK_AND_RETURN_RET_LOG(decContext_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + CHECK_AND_RETURN_RET_LOG(videoDecoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + + int32_t ret = videoDecoder_->Start(); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Decoder start failed"); + + isStarted_ = true; + inputFile_ = std::make_unique(sampleInfo_.inputFilePath.data(), std::ios::binary | std::ios::in); + decInputThread_ = std::make_unique(&VideoDecoderPerfTestSample::decInputThread, this); + decOutputThread_ = std::make_unique(&VideoDecoderPerfTestSample::decOutputThread, this); + if (decInputThread_ == nullptr || decOutputThread_ == nullptr || !inputFile_->is_open()) { + AVCODEC_LOGE("Create thread or open file failed"); + StartRelease(); + return AVCODEC_SAMPLE_ERR_ERROR; + } + + AVCODEC_LOGI("Succeed"); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoDecoderPerfTestSample::WaitForDone() +{ + AVCODEC_LOGI("In"); + std::unique_lock lock(mutex_); + doneCond_.wait(lock); + AVCODEC_LOGI("Done"); + return AVCODEC_SAMPLE_ERR_OK; +} + +void VideoDecoderPerfTestSample::StartRelease() +{ + if (releaseThread_ == nullptr) { + AVCODEC_LOGI("Start to release"); + releaseThread_ = std::make_unique(&VideoDecoderPerfTestSample::Release, this); + } +} + +void VideoDecoderPerfTestSample::Release() +{ + std::lock_guard lock(mutex_); + isStarted_ = false; + if (decInputThread_ && decInputThread_->joinable()) { + decInputThread_->join(); + } + if (decOutputThread_ && decOutputThread_->joinable()) { + decOutputThread_->join(); + } + if (videoDecoder_ != nullptr) { + videoDecoder_->Release(); + } + decInputThread_.reset(); + decOutputThread_.reset(); + videoDecoder_.reset(); + + if (sampleInfo_.window != nullptr) { + OH_NativeWindow_DestroyNativeWindow(sampleInfo_.window); + sampleInfo_.window = nullptr; + } + if (decContext_ != nullptr) { + delete decContext_; + decContext_ = nullptr; + } + if (inputFile_ != nullptr) { + inputFile_.reset(); + } + + AVCODEC_LOGI("Succeed"); + doneCond_.notify_all(); +} + +void VideoDecoderPerfTestSample::decInputThread() +{ + using namespace std::chrono_literals; + auto lastPushTime = std::chrono::system_clock::now(); + while (true) { + CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); + std::unique_lock lock(decContext_->inputMutex_); + bool condRet = decContext_->inputCond_.wait_for(lock, 5s, + [this]() { return !isStarted_ || !decContext_->inputBufferInfoQueue_.empty(); }); + CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); + CHECK_AND_CONTINUE_LOG(!decContext_->inputBufferInfoQueue_.empty(), + "Buffer queue is empty, continue, cond ret: %{public}d", condRet); + + CodecBufferInfo bufferInfo = decContext_->inputBufferInfoQueue_.front(); + decContext_->inputBufferInfoQueue_.pop(); + lock.unlock(); + + int32_t ret = ReadOneFrame(bufferInfo); + CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); + + if (sampleInfo_.testMode == TestMode::FRAME_DELAY) { + std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); + lastPushTime = std::chrono::system_clock::now(); + } + + ret = videoDecoder_->PushInputData(bufferInfo); + CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); + CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); + } + StartRelease(); +} + +void VideoDecoderPerfTestSample::decOutputThread() +{ + using namespace std::chrono_literals; + while (true) { + CHECK_AND_BREAK_LOG(isStarted_, "Decoder output thread out"); + std::unique_lock lock(decContext_->outputMutex_); + bool condRet = decContext_->outputCond_.wait_for(lock, 5s, + [this]() { return !isStarted_ || !decContext_->outputBufferInfoQueue_.empty(); }); + CHECK_AND_BREAK_LOG(isStarted_, "Decoder output thread out"); + CHECK_AND_CONTINUE_LOG(!decContext_->outputBufferInfoQueue_.empty(), + "Buffer queue is empty, continue, cond ret: %{public}d", condRet); + + CodecBufferInfo bufferInfo = decContext_->outputBufferInfoQueue_.front(); + decContext_->outputBufferInfoQueue_.pop(); + lock.unlock(); + + CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); + int32_t ret = videoDecoder_->FreeOutputData(bufferInfo.bufferIndex); + CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Decoder output thread out"); + } + AVCODEC_LOGI("On decoder output thread exit, output frame count: %{public}d", decContext_->outputFrameCount_); + StartRelease(); +} + +bool VideoDecoderPerfTestSample::IsCodecData(const uint8_t *const bufferAddr) +{ + bool isH264Stream = sampleInfo_.codecMime == MIME_VIDEO_AVC; + + // 0x1F: avc nulu type mask; 0x7E: hevc nalu type mask + uint8_t NaluType = isH264Stream ? + (bufferAddr[AVCC_FRAME_HEAD_LEN] & 0x1F) : ((bufferAddr[AVCC_FRAME_HEAD_LEN] & 0x7E) >> 1); + + // 7: avc nalu sps; 8: avc nalue pps; 32: hevc nalu vps; 33: hevc nalu sps; 34: hevc nalu pps + if ((isH264Stream && ((NaluType == 7) || (NaluType == 8))) || + (!isH264Stream && ((NaluType == 32) || (NaluType == 33) || (NaluType == 34)))) { + return true; + } + return false; +} + +int32_t VideoDecoderPerfTestSample::ReadOneFrame(CodecBufferInfo &info) +{ + CHECK_AND_RETURN_RET_LOG(inputFile_ != nullptr && inputFile_->is_open(), + AVCODEC_SAMPLE_ERR_ERROR, "Input file is not open!"); + + char ch[AVCC_FRAME_HEAD_LEN] = {}; + (void)inputFile_->read(ch, AVCC_FRAME_HEAD_LEN); + // 0 1 2 3: avcc frame head byte offset; 8 16 24: avcc frame head bit offset + uint32_t bufferSize = static_cast(((ch[3] & 0xFF)) | ((ch[2] & 0xFF) << 8) | + ((ch[1] & 0xFF) << 16) | ((ch[0] & 0xFF) << 24)); + + auto bufferAddr = static_cast(sampleInfo_.codecRunMode) & 0b10 ? // 0b10: AVBuffer mode mask + OH_AVBuffer_GetAddr(reinterpret_cast(info.buffer)) : + OH_AVMemory_GetAddr(reinterpret_cast(info.buffer)); + (void)inputFile_->read(reinterpret_cast(bufferAddr + AVCC_FRAME_HEAD_LEN), bufferSize); + bufferAddr[0] = 0; + bufferAddr[1] = 0; + bufferAddr[2] = 0; // 2: annexB frame head offset 2 + bufferAddr[3] = 1; // 3: annexB frame head offset 3 + + info.attr.flags = IsCodecData(bufferAddr) ? AVCODEC_BUFFER_FLAGS_CODEC_DATA : AVCODEC_BUFFER_FLAGS_NONE; + if (inputFile_->eof()) { + info.attr.flags = AVCODEC_BUFFER_FLAGS_EOS; + } + info.attr.size = bufferSize + AVCC_FRAME_HEAD_LEN; + info.attr.pts = decContext_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us + + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoDecoderPerfTestSample::CreateWindow(OHNativeWindow *&window) +{ + auto consumer_ = OHOS::Surface::CreateSurfaceAsConsumer(); + OHOS::sptr listener = new SurfaceConsumer(consumer_, ""); + consumer_->RegisterConsumerListener(listener); + auto producer = consumer_->GetProducer(); + surface_ = OHOS::Surface::CreateSurfaceAsProducer(producer); + window = CreateNativeWindowFromSurface(&surface_); + CHECK_AND_RETURN_RET_LOG(window != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Create window failed!"); + + return AVCODEC_SAMPLE_ERR_OK; +} diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h new file mode 100644 index 000000000..47d6c8f5c --- /dev/null +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h @@ -0,0 +1,42 @@ +/* + * 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 AV_CODEC_DEMO_VIDEOENCODER_H +#define AV_CODEC_DEMO_VIDEOENCODER_H + +#include "native_avcodec_videoencoder.h" +#include "sample_info.h" + +class VideoEncoder { +public: + VideoEncoder() = default; + ~VideoEncoder(); + + int32_t Create(const std::string_view &codecMime); + int32_t Config(SampleInfo &sampleInfo, CodecUserData *codecUserData); + int32_t Start(); + int32_t PushInputData(CodecBufferInfo &info); + int32_t NotifyEndOfStream(); + int32_t FreeOutputData(uint32_t bufferIndex); + int32_t Stop(); + int32_t Release(); + +private: + int32_t SetCallback(CodecUserData *codecUserData); + + OH_AVCodec *encoder_ = nullptr; + bool isAVBufferMode_; +}; +#endif // AV_CODEC_DEMO_VIDEOENCODER_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h new file mode 100644 index 000000000..6bde4ec3a --- /dev/null +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h @@ -0,0 +1,43 @@ +#ifndef AVCODEC_TEST_VIDEO_PERF_TEST_ENCODER_SAMPLE_H +#define AVCODEC_TEST_VIDEO_PERF_TEST_ENCODER_SAMPLE_H + +#include +#include +#include +#include +#include +#include "video_encoder.h" +#include "sample_info.h" + +class VideoEncoderPerfTestSample { +public: + VideoEncoderPerfTestSample() {}; + ~VideoEncoderPerfTestSample(); + + int32_t Create(SampleInfo sampleInfo); + int32_t Start(); + int32_t WaitForDone(); + +private: + void StartRelease(); + void Release(); + void encBufferInputThread(); + void encSurfaceInputThread(); + void encOutputThread(); + int32_t ReadOneFrame(CodecBufferInfo &info); + int32_t ReadOneFrame(uint8_t *bufferAddr, uint32_t &flags); + + std::unique_ptr videoEncoder_ = nullptr; + std::unique_ptr encInputThread_ = nullptr; + std::unique_ptr encOutputThread_ = nullptr; + std::unique_ptr releaseThread_ = nullptr; + std::unique_ptr inputFile_ = nullptr; + + std::mutex mutex_; + std::atomic isStarted_ { false }; + std::condition_variable doneCond_; + SampleInfo sampleInfo_; + CodecUserData *encContext_ = nullptr; +}; + +#endif // AVCODEC_TEST_VIDEO_PERF_TEST_ENCODER_SAMPLE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp new file mode 100644 index 000000000..e44b58002 --- /dev/null +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp @@ -0,0 +1,181 @@ +/* + * 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. + */ + +#include "video_encoder.h" +#include "surface_type.h" +#include "external_window.h" +#include "av_codec_sample_error.h" +#include "av_codec_sample_log.h" +#include "sample_callback.h" + +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoEncoder"}; +} // namespace + +VideoEncoder::~VideoEncoder() +{ + Release(); +} + +int32_t VideoEncoder::Create(const std::string_view &codecMime) +{ + encoder_ = OH_VideoEncoder_CreateByMime(codecMime.data()); + CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Create failed"); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoder::Config(SampleInfo &sampleInfo, CodecUserData *codecUserData) +{ + CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Encoder is null"); + CHECK_AND_RETURN_RET_LOG(codecUserData != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Invalid param: codecUserData"); + isAVBufferMode_ = (static_cast(sampleInfo.codecRunMode) & 0b10); // ob10: AVBuffer mode mask + + // Configure video encoder + { + OH_AVFormat *format = OH_AVFormat_Create(); + CHECK_AND_RETURN_RET_LOG(format != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "AVFormat create failed"); + + OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); + OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CBR); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, sampleInfo.bitrate); + + AVCODEC_LOGI("====== VideoEncoder config ======"); + AVCODEC_LOGI("%{public}d*%{public}d, %{public}.1ffps", + sampleInfo.videoWidth, sampleInfo.videoHeight, sampleInfo.frameRate); + AVCODEC_LOGI("BitRate Mode: %{public}d, BitRate: %{public}" PRId64, CBR, sampleInfo.bitrate / 1024); + AVCODEC_LOGI("====== VideoEncoder config ======"); + + int ret = OH_VideoEncoder_Configure(encoder_, format); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, + "Config failed, ret: %{public}d", ret); + OH_AVFormat_Destroy(format); + format = nullptr; + } + + // GetSurface from video encoder + if (!(static_cast(sampleInfo.codecRunMode) & 0b01)) // 0b01: Buffer mode mask + { + int ret = OH_VideoEncoder_GetSurface(encoder_, &sampleInfo.window); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK && sampleInfo.window, AVCODEC_SAMPLE_ERR_ERROR, + "Get surface failed, ret: %{public}d", ret); + ret = OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_FORMAT, OHOS::GRAPHIC_PIXEL_FMT_RGBA_8888); + ret = OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_BUFFER_GEOMETRY, + sampleInfo.videoWidth, sampleInfo.videoHeight); + } + + // SetCallback for video encoder + { + int32_t ret = SetCallback(codecUserData); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, + "Set callback failed, ret: %{public}d", ret); + } + + // Prepare video encoder + { + int ret = OH_VideoEncoder_Prepare(encoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Prepare failed, ret: %{public}d", ret); + } + + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoder::Start() +{ + CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Encoder is null"); + + int ret = OH_VideoEncoder_Start(encoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Start failed, ret: %{public}d", ret); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoder::PushInputData(CodecBufferInfo &info) +{ + CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Decoder is null"); + + int32_t ret = AV_ERR_OK; + if (isAVBufferMode_) { + ret = OH_AVBuffer_SetBufferAttr( + reinterpret_cast(info.buffer), reinterpret_cast(&info.attr)); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Set avbuffer attr failed"); + ret = OH_VideoEncoder_PushInputBuffer(encoder_, info.bufferIndex); + } else { + ret = OH_VideoEncoder_PushInputData(encoder_, info.bufferIndex, info.attr); + } + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Push input data failed"); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoder::FreeOutputData(uint32_t bufferIndex) +{ + CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Encoder is null"); + + int32_t ret = AV_ERR_OK; + if (isAVBufferMode_) { + ret = OH_VideoEncoder_FreeOutputBuffer(encoder_, bufferIndex); + } else { + ret = OH_VideoEncoder_FreeOutputData(encoder_, bufferIndex); + } + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, + "Free output data failed, ret: %{public}d", ret); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoder::Stop() +{ + CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Encoder is null"); + + int ret = OH_VideoEncoder_Flush(encoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Flush failed, ret: %{public}d", ret); + + ret = OH_VideoEncoder_Stop(encoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Stop failed, ret: %{public}d", ret); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoder::Release() +{ + if (encoder_ != nullptr) { + OH_VideoEncoder_Destroy(encoder_); + encoder_ = nullptr; + } + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoder::SetCallback(CodecUserData *codecUserData) +{ + int32_t ret = AV_ERR_OK; + if (isAVBufferMode_) { + ret = OH_VideoEncoder_RegisterCallback(encoder_, + {OnCodecError, OnCodecFormatChange, onNeedInputBuffer, onNewOutputBuffer}, codecUserData); + } else { + ret = OH_VideoEncoder_SetCallback(encoder_, + {OnCodecError, OnCodecFormatChange, OnInputBufferAvailable, OnOutputBufferAvailable}, codecUserData); + } + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Set callback failed, ret: %{public}d", ret); + + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoder::NotifyEndOfStream() +{ + CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Encoder is null"); + + int32_t ret = OH_VideoEncoder_NotifyEndOfStream(encoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, + "Notify end of stream failed, ret: %{public}d", ret); + return AVCODEC_SAMPLE_ERR_OK; +} diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp new file mode 100644 index 000000000..94699eda0 --- /dev/null +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -0,0 +1,240 @@ +#include "video_encoder_perf_test_sample.h" +#include +#include +#include +#include "external_window.h" +#include "native_buffer_inner.h" +#include "av_codec_sample_log.h" +#include "av_codec_sample_error.h" + +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoEncoderSample"}; +} + +VideoEncoderPerfTestSample::~VideoEncoderPerfTestSample() +{ + StartRelease(); +} + +int32_t VideoEncoderPerfTestSample::Create(SampleInfo sampleInfo) +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(!isStarted_, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + CHECK_AND_RETURN_RET_LOG(videoEncoder_ == nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + + sampleInfo_ = sampleInfo; + + videoEncoder_ = std::make_unique(); + CHECK_AND_RETURN_RET_LOG(videoEncoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, + "Create video encoder failed, no memory"); + + int32_t ret = videoEncoder_->Create(sampleInfo_.codecMime); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create video encoder failed"); + + encContext_ = new CodecUserData; + ret = videoEncoder_->Config(sampleInfo_, encContext_); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Encoder config failed"); + + releaseThread_ = nullptr; + AVCODEC_LOGI("Succeed"); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoderPerfTestSample::Start() +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(!isStarted_, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + CHECK_AND_RETURN_RET_LOG(encContext_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + CHECK_AND_RETURN_RET_LOG(videoEncoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + + int32_t ret = videoEncoder_->Start(); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Encoder start failed"); + + isStarted_ = true; + inputFile_ = std::make_unique(sampleInfo_.inputFilePath.data(), std::ios::binary | std::ios::in); + encInputThread_ = (static_cast(sampleInfo_.codecRunMode) & 0b01) ? // 0b01: Buffer mode mask + std::make_unique(&VideoEncoderPerfTestSample::encBufferInputThread, this) : + std::make_unique(&VideoEncoderPerfTestSample::encSurfaceInputThread, this); + encOutputThread_ = std::make_unique(&VideoEncoderPerfTestSample::encOutputThread, this); + if (encInputThread_ == nullptr || encOutputThread_ == nullptr || !inputFile_->is_open()) { + AVCODEC_LOGE("Create thread failed"); + StartRelease(); + return AVCODEC_SAMPLE_ERR_ERROR; + } + + AVCODEC_LOGI("Succeed"); + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoderPerfTestSample::WaitForDone() +{ + AVCODEC_LOGI("In"); + std::unique_lock lock(mutex_); + doneCond_.wait(lock); + AVCODEC_LOGI("Done"); + return AVCODEC_SAMPLE_ERR_OK; +} + +void VideoEncoderPerfTestSample::StartRelease() +{ + if (releaseThread_ == nullptr) { + AVCODEC_LOGI("Start release VideoEncoderPerfTestSample"); + releaseThread_ = std::make_unique(&VideoEncoderPerfTestSample::Release, this); + } +} + +void VideoEncoderPerfTestSample::Release() +{ + std::lock_guard lock(mutex_); + isStarted_ = false; + + if (encInputThread_ && encInputThread_->joinable()) { + encInputThread_->join(); + } + if (encOutputThread_ && encOutputThread_->joinable()) { + encOutputThread_->join(); + } + if (videoEncoder_ != nullptr) { + videoEncoder_->Release(); + } + encInputThread_.reset(); + encOutputThread_.reset(); + videoEncoder_.reset(); + + if (sampleInfo_.window != nullptr) { + OH_NativeWindow_DestroyNativeWindow(sampleInfo_.window); + sampleInfo_.window = nullptr; + } + if (encContext_ != nullptr) { + delete encContext_; + encContext_ = nullptr; + } + if (inputFile_ != nullptr) { + inputFile_.reset(); + } + + AVCODEC_LOGI("Succeed"); + doneCond_.notify_all(); +} + +void VideoEncoderPerfTestSample::encBufferInputThread() +{ + using namespace std::chrono_literals; + auto lastPushTime = std::chrono::system_clock::now(); + while (true) { + CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); + std::unique_lock lock(encContext_->inputMutex_); + bool condRet = encContext_->inputCond_.wait_for(lock, 2s, + [this]() { return !isStarted_ || !encContext_->inputBufferInfoQueue_.empty(); }); + CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); + CHECK_AND_CONTINUE_LOG(!encContext_->inputBufferInfoQueue_.empty(), + "Buffer queue is empty, continue, cond ret: %{public}d", condRet); + + CodecBufferInfo bufferInfo = encContext_->inputBufferInfoQueue_.front(); + encContext_->inputBufferInfoQueue_.pop(); + lock.unlock(); + + bufferInfo.attr.pts = encContext_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us + + int32_t ret = ReadOneFrame(bufferInfo); + CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); + + if (sampleInfo_.testMode == TestMode::FRAME_DELAY) { + std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); + lastPushTime = std::chrono::system_clock::now(); + } + + ret = videoEncoder_->PushInputData(bufferInfo); + CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); + CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); + } + StartRelease(); +} + +void VideoEncoderPerfTestSample::encSurfaceInputThread() +{ + using namespace std::chrono_literals; + auto lastPushTime = std::chrono::system_clock::now(); + while (true) { + CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); + + OHNativeWindowBuffer *buffer; + int fenceFd = -1; + int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(sampleInfo_.window, &buffer, &fenceFd); + CHECK_AND_CONTINUE_LOG(ret == 0, "RequestBuffer failed, ret: %{public}d", ret); + std::shared_ptr bufferUP(buffer, OH_NativeWindow_DestroyNativeWindowBuffer); + + OH_NativeBuffer *nativeBuffer = OH_NativeBufferFromNativeWindowBuffer(buffer); + uint8_t *bufferAddr = nullptr; + ret = OH_NativeBuffer_Map(nativeBuffer, reinterpret_cast(&bufferAddr)); + CHECK_AND_BREAK_LOG(ret == 0, "Map native buffer failed, thread out"); + + uint32_t flags = AVCODEC_BUFFER_FLAGS_NONE; + ret = ReadOneFrame(bufferAddr, flags); + CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); + CHECK_AND_BREAK_LOG(flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); + + if (sampleInfo_.testMode == TestMode::FRAME_DELAY) { + std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); + lastPushTime = std::chrono::system_clock::now(); + } + + encContext_->inputFrameCount_++; + uint64_t pts = encContext_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us + (void)NativeWindowHandleOpt(sampleInfo_.window, SET_UI_TIMESTAMP, pts); + ret = OH_NativeBuffer_Unmap(nativeBuffer); + CHECK_AND_BREAK_LOG(ret == 0, "Read frame failed, thread out"); + + ret = OH_NativeWindow_NativeWindowFlushBuffer(sampleInfo_.window, buffer, fenceFd, {nullptr, 0}); + CHECK_AND_BREAK_LOG(ret == 0, "Read frame failed, thread out"); + } + videoEncoder_->NotifyEndOfStream(); + StartRelease(); +} + +void VideoEncoderPerfTestSample::encOutputThread() +{ + while (true) { + CHECK_AND_BREAK_LOG(isStarted_, "Encoder output thread out"); + std::unique_lock lock(encContext_->outputMutex_); + encContext_->outputCond_.wait( + lock, [this]() { return (!encContext_->outputBufferInfoQueue_.empty() || !isStarted_); } + ); + CHECK_AND_BREAK_LOG(isStarted_, "Encoder output thread out"); + + CodecBufferInfo bufferInfo = encContext_->outputBufferInfoQueue_.front(); + encContext_->outputBufferInfoQueue_.pop(); + lock.unlock(); + + CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Encoder output thread out"); + + int32_t ret = videoEncoder_->FreeOutputData(bufferInfo.bufferIndex); + CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Encoder output thread out"); + } + StartRelease(); +} + +int32_t VideoEncoderPerfTestSample::ReadOneFrame(CodecBufferInfo &info) +{ + auto bufferAddr = static_cast(sampleInfo_.codecRunMode) & 0b10 ? // 0b10: AVBuffer mode mask + OH_AVBuffer_GetAddr(reinterpret_cast(info.buffer)) : + OH_AVMemory_GetAddr(reinterpret_cast(info.buffer)); + int32_t ret = ReadOneFrame(bufferAddr, info.attr.flags); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Read frame failed"); + + return AVCODEC_SAMPLE_ERR_OK; +} + +int32_t VideoEncoderPerfTestSample::ReadOneFrame(uint8_t *bufferAddr, uint32_t &flags) +{ + CHECK_AND_RETURN_RET_LOG(inputFile_ != nullptr && inputFile_->is_open(), + AVCODEC_SAMPLE_ERR_ERROR, "Input file is not open!"); + CHECK_AND_RETURN_RET_LOG(bufferAddr != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Invalid buffer address"); + + uint64_t bufferSize = sampleInfo_.videoWidth * sampleInfo_.videoHeight * 3 / 2; // YUV buffer size + inputFile_->read(reinterpret_cast(bufferAddr), bufferSize); + + flags = inputFile_->eof() ? AVCODEC_BUFFER_FLAGS_EOS : AVCODEC_BUFFER_FLAGS_NONE; + + return AVCODEC_SAMPLE_ERR_OK; +} \ No newline at end of file diff --git a/test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp new file mode 100644 index 000000000..955180000 --- /dev/null +++ b/test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp @@ -0,0 +1,214 @@ +#include +#include +#include "gtest/gtest.h" +#include "video_decoder_perf_test_sample.h" +#include "av_codec_sample_error.h" +#include "av_codec_sample_log.h" + +namespace { +using namespace testing::ext; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoDecoderPerfTestSuilt"}; + +constexpr int32_t FRAME_INTERVAL_33MS = 33; // 33ms + +constexpr std::string_view FILE_AVC_1280_720_30_10M = "/data/test/media/1280_720_10M_30.h264"; +constexpr std::string_view FILE_AVC_1280_720_60_10M = "/data/test/media/1280_720_10M_60.h264"; +constexpr std::string_view FILE_AVC_1920_1080_30_20M = "/data/test/media/1920_1080_20M_30.h264"; +constexpr std::string_view FILE_AVC_1920_1080_60_20M = "/data/test/media/1920_1080_20M_60.h264"; +constexpr std::string_view FILE_AVC_3840_2160_30_30M = "/data/test/media/3840_2160_30M_30.h264"; +constexpr std::string_view FILE_AVC_3840_2160_60_30M = "/data/test/media/3840_2160_30M_60.h264"; + +constexpr std::string_view FILE_HEVC_1280_720_30_10M = "/data/test/media/1280_720_10M_30.h265"; +constexpr std::string_view FILE_HEVC_1280_720_60_10M = "/data/test/media/1280_720_10M_60.h265"; +constexpr std::string_view FILE_HEVC_1920_1080_30_20M = "/data/test/media/1920_1080_20M_30.h265"; +constexpr std::string_view FILE_HEVC_1920_1080_60_20M = "/data/test/media/1920_1080_20M_60.h265"; +constexpr std::string_view FILE_HEVC_3840_2160_30_30M = "/data/test/media/3840_2160_30M_30.h265"; +constexpr std::string_view FILE_HEVC_3840_2160_60_30M = "/data/test/media/3840_2160_30M_60.h265"; +} // namespace + +class VideoDecoderPerfTestSuilt : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp(void) {}; + void TearDown(void) {}; + + int32_t RunTest(const SampleInfo &sampleInfo); +}; + +/* Generate case name + * + * Example: + * GENERATE_CASE_NAME(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10) + * + * To be: + * CASE_FRAME_DELAY_BUFFER_SHARED_MEMORY_AVC_1280_720_30_10M + */ +#define GENERATE_CASE_NAME(testMode, codecRunMode, mime, width, height, fps, bitrate) \ + CASE_##testMode##_##codecRunMode##_##mime##_##width##_##height##_##fps##_##bitrate##M + +/* Template of perf test case + * + * Example: + * ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) + * + * To be: + * HWTEST_F(VideoDecoderPerfTestSuilt, FRAME_DELAY_BUFFER_SHARED_MEMORY_AVC_1280_720_30_10M, TestSize.Level1) + * { + * SampleInfo sampleInfo = { + * FILE_AVC_1280_720_30_10M, MIME_VIDEO_AVC, 1280, 720, 30, BITRATE_10M, + * CodecRunMode::BUFFER_SHARED_MEMORY, TestMode::FRAME_DELAY, FRAME_INTERVAL_33MS + * }; + * ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunTest(sampleInfo)); + * } + */ +#define ADD_CASE(testMode, codecRunMode, mime, width, height, fps, bitrate, inteval) \ +HWTEST_F(VideoDecoderPerfTestSuilt, \ +GENERATE_CASE_NAME(testMode, codecRunMode, mime, width, height, fps, bitrate), TestSize.Level1) \ +{ \ + SampleInfo sampleInfo = { \ + FILE_##mime##_##width##_##height##_##fps##_##bitrate##M, \ + MIME_VIDEO_##mime, (width), (height), (fps), BITRATE_##bitrate##M, (codecRunMode), (testMode), (inteval) \ + }; \ + ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunTest(sampleInfo)); \ +} + +int32_t VideoDecoderPerfTestSuilt::RunTest(const SampleInfo &sampleInfo) +{ + AVCODEC_LOGI("====== Video perf test config ======"); + AVCODEC_LOGI("test mode: %{public}d, codec run mode: %{public}d", sampleInfo.testMode, sampleInfo.codecRunMode); + AVCODEC_LOGI("input file: %{public}s", sampleInfo.inputFilePath.data()); + AVCODEC_LOGI("mime: %{public}s, %{public}d*%{public}d, %{public}.1ffps, %{public}.2fMbps, interval: %{public}dms", + sampleInfo.codecMime.data(), sampleInfo.videoWidth, sampleInfo.videoHeight, sampleInfo.frameRate, + static_cast(sampleInfo.bitrate) / 1024 / 1024, FRAME_INTERVAL_33MS); // 1024: precision + AVCODEC_LOGI("====== Video perf test config ======"); + + std::unique_ptr sample = std::make_unique(); + int32_t ret = sample->Create(sampleInfo); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Create failed"); + ret = sample->Start(); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Start failed"); + ret = sample->WaitForDone(); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Wait for done failed"); + return AVCODEC_SAMPLE_ERR_OK; +} + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 1280, 720, 30, 10, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 1280, 720, 30, 10, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 60, 10, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 1280, 720, 60, 10, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 1280, 720, 60, 10, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 1280, 720, 60, 10, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 30, 20, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 1920, 1080, 30, 20, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 1920, 1080, 30, 20, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 1920, 1080, 30, 20, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 60, 20, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 1920, 1080, 60, 20, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 1920, 1080, 60, 20, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 1920, 1080, 60, 20, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 30, 30, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 3840, 2160, 30, 30, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 3840, 2160, 30, 30, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 3840, 2160, 30, 30, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 60, 30, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 3840, 2160, 60, 30, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 3840, 2160, 60, 30, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 3840, 2160, 60, 30, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 30, 10, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1280, 720, 30, 10, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 1280, 720, 30, 10, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1280, 720, 30, 10, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 60, 10, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1280, 720, 60, 10, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 1280, 720, 60, 10, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1280, 720, 60, 10, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 30, 20, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1920, 1080, 30, 20, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 1920, 1080, 30, 20, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1920, 1080, 30, 20, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 60, 20, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1920, 1080, 60, 20, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 1920, 1080, 60, 20, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1920, 1080, 60, 20, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 30, 30, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, 30, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 30, 30, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 3840, 2160, 30, 30, 0) + +ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, 0) +ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) +ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, 0) +ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) \ No newline at end of file diff --git a/test/unittest/video_perf_test/test_suilt/video_encoder_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_encoder_perf_test_suilt.cpp new file mode 100644 index 000000000..59f1f4c79 --- /dev/null +++ b/test/unittest/video_perf_test/test_suilt/video_encoder_perf_test_suilt.cpp @@ -0,0 +1,9 @@ +#include "gtest/gtest.h" + +class VideoEncoderPerfTestSuilt : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp(void) {}; + void TearDown(void) {}; +}; \ No newline at end of file -- Gitee From eba1b767a95c629f64ca482e19d9895b9310ab44 Mon Sep 17 00:00:00 2001 From: West Date: Mon, 11 Dec 2023 17:23:27 +0800 Subject: [PATCH 03/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Add=20perf=20test=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I4504459d499167c2985fee2e72c26f308383a6ef --- test/unittest/video_perf_test/BUILD.gn | 1 + .../common/include/sample_info.h | 6 + .../common/sample_callback.cpp | 8 +- .../sample/base/video_perf_test_sample_base.h | 14 + .../include/video_decoder_perf_test_sample.h | 12 +- .../include/video_encoder_perf_test_sample.h | 12 +- .../video_decoder_perf_test_suilt.cpp | 365 +++++++++++------- .../video_encoder_perf_test_suilt.cpp | 9 - 8 files changed, 273 insertions(+), 154 deletions(-) create mode 100644 test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h delete mode 100644 test/unittest/video_perf_test/test_suilt/video_encoder_perf_test_suilt.cpp diff --git a/test/unittest/video_perf_test/BUILD.gn b/test/unittest/video_perf_test/BUILD.gn index 994a5f826..0bcdf1b14 100644 --- a/test/unittest/video_perf_test/BUILD.gn +++ b/test/unittest/video_perf_test/BUILD.gn @@ -19,6 +19,7 @@ ohos_unittest("video_perf_test") { include_dirs = [ "./common/include", + "./sample/base", "./sample/decoder/include", "./sample/encoder/include", "./test_suilt/include", diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h index 86cbc3008..a9e08fb08 100644 --- a/test/unittest/video_perf_test/common/include/sample_info.h +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -29,6 +29,11 @@ constexpr int32_t BITRATE_10M = 10 * 1024 * 1024; // 10Mbps constexpr int32_t BITRATE_20M = 20 * 1024 * 1024; // 20Mbps constexpr int32_t BITRATE_30M = 30 * 1024 * 1024; // 30Mbps +enum CodecType { + VIDEO_DECODER, + VIDEO_ENCODER +}; + enum TestMode { FRAME_DELAY, FRAME_RATE, @@ -49,6 +54,7 @@ enum CodecRunMode { }; struct SampleInfo { + CodecType codecType; std::string_view inputFilePath; std::string_view codecMime; int32_t videoWidth = 0; diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index b3a40c1f3..29478338e 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -23,7 +23,7 @@ void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data } CodecUserData *codecUserData = static_cast(userData); codecUserData->inputFrameCount_++; - AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "On input buffer available, frameCount: %{public}d", + AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->inputFrameCount_); std::unique_lock lock(codecUserData->inputMutex_); codecUserData->inputBufferInfoQueue_.emplace(index, data); @@ -38,7 +38,7 @@ void OnOutputBufferAvailable(OH_AVCodec * codec, uint32_t index, OH_AVMemory *da } CodecUserData *codecUserData = static_cast(userData); codecUserData->outputFrameCount_++; - AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "On output buffer available, frameCount: %{public}d", + AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->outputFrameCount_); std::unique_lock lock(codecUserData->outputMutex_); codecUserData->outputBufferInfoQueue_.emplace(index, data, *attr); @@ -52,7 +52,7 @@ void onNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, v } CodecUserData *codecUserData = static_cast(userData); codecUserData->inputFrameCount_++; - AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "On need input buffer, frameCount: %{public}d", + AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->inputFrameCount_); std::unique_lock lock(codecUserData->inputMutex_); codecUserData->inputBufferInfoQueue_.emplace(index, buffer); @@ -66,7 +66,7 @@ void onNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, v } CodecUserData *codecUserData = static_cast(userData); codecUserData->outputFrameCount_++; - AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "On need input buffer, frameCount: %{public}d", + AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->outputFrameCount_); std::unique_lock lock(codecUserData->outputMutex_); codecUserData->outputBufferInfoQueue_.emplace(index, buffer); diff --git a/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h b/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h new file mode 100644 index 000000000..dc2c40a21 --- /dev/null +++ b/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h @@ -0,0 +1,14 @@ +#ifndef AVCODEC_TEST_VIDEO_PERF_TEST_SAMPLE_BASE_H +#define AVCODEC_TEST_VIDEO_PERF_TEST_SAMPLE_BASE_H + +#include "sample_info.h" + +class VideoPerfTestSampleBase { +public: + virtual ~VideoPerfTestSampleBase() {}; + + virtual int32_t Create(SampleInfo sampleInfo) = 0; + virtual int32_t Start() = 0; + virtual int32_t WaitForDone() = 0; +}; +#endif // AVCODEC_TEST_VIDEO_PERF_TEST_SAMPLE_BASE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index 484966f85..82da85374 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -7,18 +7,18 @@ #include #include #include +#include "video_perf_test_sample_base.h" #include "video_decoder.h" -#include "sample_info.h" #include "surface.h" -class VideoDecoderPerfTestSample { +class VideoDecoderPerfTestSample : public VideoPerfTestSampleBase { public: VideoDecoderPerfTestSample() {}; - ~VideoDecoderPerfTestSample(); + ~VideoDecoderPerfTestSample() override; - int32_t Create(SampleInfo sampleInfo); - int32_t Start(); - int32_t WaitForDone(); + int32_t Create(SampleInfo sampleInfo) override; + int32_t Start() override; + int32_t WaitForDone() override; private: void StartRelease(); diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h index 6bde4ec3a..5c364fe0e 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h @@ -6,17 +6,17 @@ #include #include #include +#include "video_perf_test_sample_base.h" #include "video_encoder.h" -#include "sample_info.h" -class VideoEncoderPerfTestSample { +class VideoEncoderPerfTestSample : public VideoPerfTestSampleBase { public: VideoEncoderPerfTestSample() {}; - ~VideoEncoderPerfTestSample(); + ~VideoEncoderPerfTestSample() override; - int32_t Create(SampleInfo sampleInfo); - int32_t Start(); - int32_t WaitForDone(); + int32_t Create(SampleInfo sampleInfo) override; + int32_t Start() override; + int32_t WaitForDone() override; private: void StartRelease(); diff --git a/test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp index 955180000..2d5fbfa98 100644 --- a/test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp +++ b/test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp @@ -1,13 +1,15 @@ #include #include #include "gtest/gtest.h" +#include "video_perf_test_sample_base.h" #include "video_decoder_perf_test_sample.h" +#include "video_encoder_perf_test_sample.h" #include "av_codec_sample_error.h" #include "av_codec_sample_log.h" namespace { using namespace testing::ext; -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoDecoderPerfTestSuilt"}; +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoPerfTestSuilt"}; constexpr int32_t FRAME_INTERVAL_33MS = 33; // 33ms @@ -24,9 +26,13 @@ constexpr std::string_view FILE_HEVC_1920_1080_30_20M = "/data/test/media/1920_1 constexpr std::string_view FILE_HEVC_1920_1080_60_20M = "/data/test/media/1920_1080_20M_60.h265"; constexpr std::string_view FILE_HEVC_3840_2160_30_30M = "/data/test/media/3840_2160_30M_30.h265"; constexpr std::string_view FILE_HEVC_3840_2160_60_30M = "/data/test/media/3840_2160_30M_60.h265"; + +constexpr std::string_view FILE_1280_720 = "/data/test/media/1280_720_nv.yuv"; +constexpr std::string_view FILE_1920_1080 = "/data/test/media/1920_1080_nv.yuv"; +constexpr std::string_view FILE_3840_2160 = "/data/test/media/3840_2160_nv.yuv"; } // namespace -class VideoDecoderPerfTestSuilt : public testing::Test { +class VideoPerfTestSuilt : public testing::Test { public: static void SetUpTestCase(void) {}; static void TearDownTestCase(void) {}; @@ -44,8 +50,8 @@ public: * To be: * CASE_FRAME_DELAY_BUFFER_SHARED_MEMORY_AVC_1280_720_30_10M */ -#define GENERATE_CASE_NAME(testMode, codecRunMode, mime, width, height, fps, bitrate) \ - CASE_##testMode##_##codecRunMode##_##mime##_##width##_##height##_##fps##_##bitrate##M +#define GENERATE_CASE_NAME(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate) \ + CASE_##codecType##_##testMode##_##codecRunMode##_##mime##_##width##_##height##_##fps##_##bitrate##M /* Template of perf test case * @@ -62,18 +68,20 @@ public: * ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunTest(sampleInfo)); * } */ -#define ADD_CASE(testMode, codecRunMode, mime, width, height, fps, bitrate, inteval) \ -HWTEST_F(VideoDecoderPerfTestSuilt, \ -GENERATE_CASE_NAME(testMode, codecRunMode, mime, width, height, fps, bitrate), TestSize.Level1) \ +#define ADD_CASE(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate, inteval) \ +HWTEST_F(VideoPerfTestSuilt, \ +GENERATE_CASE_NAME(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate), TestSize.Level1) \ { \ + std::string_view inputFileName = codecType == CodecType::VIDEO_DECODER ? \ + "FILE_" #mime "_" #width "_" #height "_" #fps "_" #bitrate "M" : "FILE_" #width "_" #height; \ SampleInfo sampleInfo = { \ - FILE_##mime##_##width##_##height##_##fps##_##bitrate##M, \ + codecType, inputFileName, \ MIME_VIDEO_##mime, (width), (height), (fps), BITRATE_##bitrate##M, (codecRunMode), (testMode), (inteval) \ }; \ ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunTest(sampleInfo)); \ } -int32_t VideoDecoderPerfTestSuilt::RunTest(const SampleInfo &sampleInfo) +int32_t VideoPerfTestSuilt::RunTest(const SampleInfo &sampleInfo) { AVCODEC_LOGI("====== Video perf test config ======"); AVCODEC_LOGI("test mode: %{public}d, codec run mode: %{public}d", sampleInfo.testMode, sampleInfo.codecRunMode); @@ -83,7 +91,10 @@ int32_t VideoDecoderPerfTestSuilt::RunTest(const SampleInfo &sampleInfo) static_cast(sampleInfo.bitrate) / 1024 / 1024, FRAME_INTERVAL_33MS); // 1024: precision AVCODEC_LOGI("====== Video perf test config ======"); - std::unique_ptr sample = std::make_unique(); + std::unique_ptr sample = sampleInfo.codecType == CodecType::VIDEO_DECODER ? + static_cast>(std::make_unique()) : + static_cast>(std::make_unique()); + int32_t ret = sample->Create(sampleInfo); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Create failed"); ret = sample->Start(); @@ -93,122 +104,218 @@ int32_t VideoDecoderPerfTestSuilt::RunTest(const SampleInfo &sampleInfo) return AVCODEC_SAMPLE_ERR_OK; } -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) -ADD_CASE(FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 1280, 720, 30, 10, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 1280, 720, 30, 10, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 60, 10, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 1280, 720, 60, 10, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 1280, 720, 60, 10, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 1280, 720, 60, 10, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 30, 20, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 1920, 1080, 30, 20, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 1920, 1080, 30, 20, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 1920, 1080, 30, 20, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 60, 20, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 1920, 1080, 60, 20, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 1920, 1080, 60, 20, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 1920, 1080, 60, 20, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 30, 30, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 3840, 2160, 30, 30, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 3840, 2160, 30, 30, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 3840, 2160, 30, 30, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 60, 30, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, AVC, 3840, 2160, 60, 30, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, AVC, 3840, 2160, 60, 30, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, AVC, 3840, 2160, 60, 30, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 30, 10, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1280, 720, 30, 10, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 1280, 720, 30, 10, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1280, 720, 30, 10, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 60, 10, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1280, 720, 60, 10, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 1280, 720, 60, 10, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1280, 720, 60, 10, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 30, 20, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1920, 1080, 30, 20, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 1920, 1080, 30, 20, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1920, 1080, 30, 20, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 60, 20, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1920, 1080, 60, 20, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 1920, 1080, 60, 20, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1920, 1080, 60, 20, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 30, 30, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, 30, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 30, 30, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 3840, 2160, 30, 30, 0) - -ADD_CASE(FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, 0) -ADD_CASE(FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) -ADD_CASE(FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, 0) -ADD_CASE(FRAME_RATE, SURFACE_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) \ No newline at end of file +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_AVBUFFER, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_DECODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, AVC, 1280, 720, 30, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 1280, 720, 30, 10, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 1280, 720, 60, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 60, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, AVC, 1280, 720, 60, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 1280, 720, 60, 10, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 1920, 1080, 30, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 30, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, AVC, 1920, 1080, 30, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 1920, 1080, 30, 20, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 1920, 1080, 60, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 60, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, AVC, 1920, 1080, 60, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 1920, 1080, 60, 20, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 3840, 2160, 30, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 30, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, AVC, 3840, 2160, 30, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 3840, 2160, 30, 30, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 3840, 2160, 60, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 60, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, AVC, 3840, 2160, 60, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 3840, 2160, 60, 30, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 1280, 720, 30, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 30, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1280, 720, 30, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1280, 720, 30, 10, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 1280, 720, 60, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 60, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1280, 720, 60, 10, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1280, 720, 60, 10, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 1920, 1080, 30, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 30, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1920, 1080, 30, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1920, 1080, 30, 20, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 1920, 1080, 60, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 60, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, HEVC, 1920, 1080, 60, 20, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1920, 1080, 60, 20, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 30, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 30, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, HEVC, 3840, 2160, 30, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, 30, 0) + +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) +ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 1280, 720, 30, 10, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 1280, 720, 60, 10, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 60, 10, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 1280, 720, 60, 10, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 1920, 1080, 30, 20, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 30, 20, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 1920, 1080, 30, 20, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 1920, 1080, 60, 20, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 60, 20, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 1920, 1080, 60, 20, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 3840, 2160, 30, 30, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 30, 30, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 3840, 2160, 30, 30, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 3840, 2160, 60, 30, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 60, 30, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, AVC, 3840, 2160, 60, 30, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 1280, 720, 30, 10, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 30, 10, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1280, 720, 30, 10, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 1280, 720, 60, 10, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 60, 10, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1280, 720, 60, 10, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 1920, 1080, 30, 20, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 30, 20, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1920, 1080, 30, 20, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 1920, 1080, 60, 20, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 60, 20, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 1920, 1080, 60, 20, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 30, 30, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 30, 30, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, 30, 0) + +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, 0) +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) \ No newline at end of file diff --git a/test/unittest/video_perf_test/test_suilt/video_encoder_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_encoder_perf_test_suilt.cpp deleted file mode 100644 index 59f1f4c79..000000000 --- a/test/unittest/video_perf_test/test_suilt/video_encoder_perf_test_suilt.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "gtest/gtest.h" - -class VideoEncoderPerfTestSuilt : public testing::Test { -public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase(void) {}; - void SetUp(void) {}; - void TearDown(void) {}; -}; \ No newline at end of file -- Gitee From 5fb057cdb9e3d5969be928f10e15d719d6c89c3a Mon Sep 17 00:00:00 2001 From: West Date: Mon, 11 Dec 2023 19:08:28 +0800 Subject: [PATCH 04/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Add=20perf=20test=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Idd415af5454652df8f5e1deec4ee5a35b5fe752b --- test/unittest/video_perf_test/BUILD.gn | 3 +-- ...ecoder_perf_test_suilt.cpp => video_perf_test_suilt.cpp} | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) rename test/unittest/video_perf_test/test_suilt/{video_decoder_perf_test_suilt.cpp => video_perf_test_suilt.cpp} (98%) diff --git a/test/unittest/video_perf_test/BUILD.gn b/test/unittest/video_perf_test/BUILD.gn index 0bcdf1b14..a791b7796 100644 --- a/test/unittest/video_perf_test/BUILD.gn +++ b/test/unittest/video_perf_test/BUILD.gn @@ -55,8 +55,7 @@ ohos_unittest("video_perf_test") { "./sample/decoder/video_decoder.cpp", "./sample/encoder/video_encoder_perf_test_sample.cpp", "./sample/encoder/video_encoder.cpp", - "./test_suilt/video_decoder_perf_test_suilt.cpp", - "./test_suilt/video_encoder_perf_test_suilt.cpp", + "./test_suilt/video_perf_test_suilt.cpp", ] deps = [ "$av_codec_root_dir/interfaces/kits/c:capi_packages" ] diff --git a/test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp similarity index 98% rename from test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp rename to test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp index 2d5fbfa98..0ede8967a 100644 --- a/test/unittest/video_perf_test/test_suilt/video_decoder_perf_test_suilt.cpp +++ b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp @@ -50,7 +50,7 @@ public: * To be: * CASE_FRAME_DELAY_BUFFER_SHARED_MEMORY_AVC_1280_720_30_10M */ -#define GENERATE_CASE_NAME(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate) \ +#define GENERATE_CASE_NAME(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate) \ CASE_##codecType##_##testMode##_##codecRunMode##_##mime##_##width##_##height##_##fps##_##bitrate##M /* Template of perf test case @@ -72,8 +72,8 @@ public: HWTEST_F(VideoPerfTestSuilt, \ GENERATE_CASE_NAME(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate), TestSize.Level1) \ { \ - std::string_view inputFileName = codecType == CodecType::VIDEO_DECODER ? \ - "FILE_" #mime "_" #width "_" #height "_" #fps "_" #bitrate "M" : "FILE_" #width "_" #height; \ + std::string_view inputFileName = (codecType) == CodecType::VIDEO_DECODER ? \ + FILE_##mime##_##width##_##height##_##fps##_##bitrate##M : FILE_##width##_##height; \ SampleInfo sampleInfo = { \ codecType, inputFileName, \ MIME_VIDEO_##mime, (width), (height), (fps), BITRATE_##bitrate##M, (codecRunMode), (testMode), (inteval) \ -- Gitee From c61b54edc04a1de11c096c4a87c3d67d17ac006d Mon Sep 17 00:00:00 2001 From: West Date: Mon, 11 Dec 2023 20:21:24 +0800 Subject: [PATCH 05/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Add=20perf=20test=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I670b0f1d4aaf448788d837c889bcee114c496a1a --- .../video_encoder_perf_test_sample.cpp | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 94699eda0..8b7afeae4 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -14,6 +14,9 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoEncod VideoEncoderPerfTestSample::~VideoEncoderPerfTestSample() { StartRelease(); + if (releaseThread_ && releaseThread_->joinable()) { + releaseThread_->join(); + } } int32_t VideoEncoderPerfTestSample::Create(SampleInfo sampleInfo) @@ -124,7 +127,7 @@ void VideoEncoderPerfTestSample::encBufferInputThread() while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); std::unique_lock lock(encContext_->inputMutex_); - bool condRet = encContext_->inputCond_.wait_for(lock, 2s, + bool condRet = encContext_->inputCond_.wait_for(lock, 5s, [this]() { return !isStarted_ || !encContext_->inputBufferInfoQueue_.empty(); }); CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); CHECK_AND_CONTINUE_LOG(!encContext_->inputBufferInfoQueue_.empty(), @@ -155,14 +158,13 @@ void VideoEncoderPerfTestSample::encSurfaceInputThread() { using namespace std::chrono_literals; auto lastPushTime = std::chrono::system_clock::now(); + OHNativeWindowBuffer *buffer = nullptr; while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); - OHNativeWindowBuffer *buffer; int fenceFd = -1; int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(sampleInfo_.window, &buffer, &fenceFd); CHECK_AND_CONTINUE_LOG(ret == 0, "RequestBuffer failed, ret: %{public}d", ret); - std::shared_ptr bufferUP(buffer, OH_NativeWindow_DestroyNativeWindowBuffer); OH_NativeBuffer *nativeBuffer = OH_NativeBufferFromNativeWindowBuffer(buffer); uint8_t *bufferAddr = nullptr; @@ -187,6 +189,11 @@ void VideoEncoderPerfTestSample::encSurfaceInputThread() ret = OH_NativeWindow_NativeWindowFlushBuffer(sampleInfo_.window, buffer, fenceFd, {nullptr, 0}); CHECK_AND_BREAK_LOG(ret == 0, "Read frame failed, thread out"); + + buffer = nullptr; + } + if (buffer != nullptr) { + OH_NativeWindow_DestroyNativeWindowBuffer(buffer); } videoEncoder_->NotifyEndOfStream(); StartRelease(); @@ -194,13 +201,15 @@ void VideoEncoderPerfTestSample::encSurfaceInputThread() void VideoEncoderPerfTestSample::encOutputThread() { + using namespace std::chrono_literals; while (true) { - CHECK_AND_BREAK_LOG(isStarted_, "Encoder output thread out"); + CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); std::unique_lock lock(encContext_->outputMutex_); - encContext_->outputCond_.wait( - lock, [this]() { return (!encContext_->outputBufferInfoQueue_.empty() || !isStarted_); } - ); - CHECK_AND_BREAK_LOG(isStarted_, "Encoder output thread out"); + bool condRet = encContext_->outputCond_.wait_for(lock, 5s, + [this]() { return !isStarted_ || !encContext_->outputBufferInfoQueue_.empty(); }); + CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); + CHECK_AND_CONTINUE_LOG(!encContext_->outputBufferInfoQueue_.empty(), + "Buffer queue is empty, continue, cond ret: %{public}d", condRet); CodecBufferInfo bufferInfo = encContext_->outputBufferInfoQueue_.front(); encContext_->outputBufferInfoQueue_.pop(); -- Gitee From 0cfe171fd29ab73f6251ee8aa3be5a0bfe0f6fa4 Mon Sep 17 00:00:00 2001 From: West Date: Mon, 11 Dec 2023 20:24:42 +0800 Subject: [PATCH 06/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Add=20perf=20test=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I34ba4c3f59c2326e5e3a88da36f3db68688bf67e --- .../sample/encoder/video_encoder_perf_test_sample.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 8b7afeae4..21b677d56 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -220,6 +220,7 @@ void VideoEncoderPerfTestSample::encOutputThread() int32_t ret = videoEncoder_->FreeOutputData(bufferInfo.bufferIndex); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Encoder output thread out"); } + AVCODEC_LOGI("On encoder output thread exit, output frame count: %{public}d", encContext_->outputFrameCount_); StartRelease(); } -- Gitee From e3d935c81adf8029104cd8449d019d0966f3e348 Mon Sep 17 00:00:00 2001 From: West Date: Mon, 11 Dec 2023 21:39:22 +0800 Subject: [PATCH 07/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Add=20perf=20test=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Ib36c5c61d89d9ac2e9d87ebd58987a4abe0de7f2 --- test/unittest/video_perf_test/BUILD.gn | 2 ++ .../common/av_codec_sample_log.cpp | 19 +++++++++++++++++++ .../common/include/av_codec_sample_log.h | 7 +++++++ .../video_decoder_perf_test_sample.cpp | 3 +++ .../video_encoder_perf_test_sample.cpp | 6 ++++++ 5 files changed, 37 insertions(+) create mode 100644 test/unittest/video_perf_test/common/av_codec_sample_log.cpp diff --git a/test/unittest/video_perf_test/BUILD.gn b/test/unittest/video_perf_test/BUILD.gn index a791b7796..c51504e8b 100644 --- a/test/unittest/video_perf_test/BUILD.gn +++ b/test/unittest/video_perf_test/BUILD.gn @@ -51,6 +51,7 @@ ohos_unittest("video_perf_test") { sources = [ "./common/sample_callback.cpp", + "./common/av_codec_sample_log.cpp", "./sample/decoder/video_decoder_perf_test_sample.cpp", "./sample/decoder/video_decoder.cpp", "./sample/encoder/video_encoder_perf_test_sample.cpp", @@ -67,5 +68,6 @@ ohos_unittest("video_perf_test") { "graphic_2d:surface", "hilog:libhilog", "histreamer:media_foundation", + "init:libbegetutil", ] } \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/av_codec_sample_log.cpp b/test/unittest/video_perf_test/common/av_codec_sample_log.cpp new file mode 100644 index 000000000..9f7fa46f9 --- /dev/null +++ b/test/unittest/video_perf_test/common/av_codec_sample_log.cpp @@ -0,0 +1,19 @@ +/* + * 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. + */ + +#include "av_codec_sample_log.h" +#include "syspara/parameters.h" + +const bool VERBOSE_LOG = OHOS::system::GetBoolParameter("OHOS.Media.AVCodecSample.VerboseLog", false); diff --git a/test/unittest/video_perf_test/common/include/av_codec_sample_log.h b/test/unittest/video_perf_test/common/include/av_codec_sample_log.h index fbf6a69b9..d15f637bf 100644 --- a/test/unittest/video_perf_test/common/include/av_codec_sample_log.h +++ b/test/unittest/video_perf_test/common/include/av_codec_sample_log.h @@ -21,4 +21,11 @@ #undef LOG_DOMAIN #define LOG_DOMAIN 0xD002B66 +extern const bool VERBOSE_LOG; + +#define AVCODEC_LOGV(fmt, ...) \ + if (VERBOSE_LOG) { \ + AVCODEC_LOGI(fmt, ##__VA_ARGS__); \ + } + #endif // AVCODEC_SAMPLE_LOG_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 5400b834c..4a46d55e0 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -174,8 +174,11 @@ void VideoDecoderPerfTestSample::decInputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); if (sampleInfo_.testMode == TestMode::FRAME_DELAY) { + auto beforeSleepTime = std::chrono::system_clock::now(); std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); lastPushTime = std::chrono::system_clock::now(); + AVCODEC_LOGV("Sleep time: %{public}2.2fms", + static_cast>(lastPushTime - beforeSleepTime).count()); } ret = videoDecoder_->PushInputData(bufferInfo); diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 21b677d56..0a3e99c85 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -143,8 +143,11 @@ void VideoEncoderPerfTestSample::encBufferInputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); if (sampleInfo_.testMode == TestMode::FRAME_DELAY) { + auto beforeSleepTime = std::chrono::system_clock::now(); std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); lastPushTime = std::chrono::system_clock::now(); + AVCODEC_LOGV("Sleep time: %{public}2.2fms", + static_cast>(lastPushTime - beforeSleepTime).count()); } ret = videoEncoder_->PushInputData(bufferInfo); @@ -177,8 +180,11 @@ void VideoEncoderPerfTestSample::encSurfaceInputThread() CHECK_AND_BREAK_LOG(flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); if (sampleInfo_.testMode == TestMode::FRAME_DELAY) { + auto beforeSleepTime = std::chrono::system_clock::now(); std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); lastPushTime = std::chrono::system_clock::now(); + AVCODEC_LOGV("Sleep time: %{public}2.2fms", + static_cast>(lastPushTime - beforeSleepTime).count()); } encContext_->inputFrameCount_++; -- Gitee From a38cf5a8f7fe1461b75214a8a2ad5d38ea6835dd Mon Sep 17 00:00:00 2001 From: West Date: Tue, 12 Dec 2023 12:11:54 +0800 Subject: [PATCH 08/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Separate=20dfx=20trace=20and=20sysevent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Ibdd9d7e3c4a153519679e66cab9bf7abf0393d31 --- .../avcodec/avcodec_audio_decoder_impl.cpp | 2 +- .../avcodec/avcodec_audio_encoder_impl.cpp | 2 +- .../avcodec/avcodec_video_decoder_impl.cpp | 2 +- .../avcodec/avcodec_video_encoder_impl.cpp | 2 +- .../native/avdemuxer/avdemuxer_impl.cpp | 2 +- frameworks/native/avmuxer/avmuxer_impl.cpp | 2 +- frameworks/native/avsource/avsource_impl.cpp | 2 +- .../capi/avcodec/native_video_decoder.cpp | 2 +- .../capi/avcodec/native_video_encoder.cpp | 2 +- services/dfx/BUILD.gn | 3 +- .../{avcodec_dfx.cpp => avcodec_sysevent.cpp} | 31 +----------- services/dfx/avcodec_trace.cpp | 49 +++++++++++++++++++ services/dfx/avcodec_xcollie.cpp | 2 +- .../{avcodec_dfx.h => avcodec_sysevent.h} | 21 ++------ services/dfx/include/avcodec_trace.h | 39 +++++++++++++++ .../codec/audio/audio_codec_adapter.cpp | 2 +- .../engine/codec/audio/audio_codec_worker.cpp | 2 +- .../audio_ffmpeg_aac_decoder_plugin.cpp | 2 +- .../decoder/audio_ffmpeg_decoder_plugin.cpp | 2 +- .../audio_ffmpeg_flac_decoder_plugin.cpp | 2 +- .../audio_ffmpeg_vorbis_decoder_plugin.cpp | 2 +- .../decoder/audio_g711mu_decoder_plugin.cpp | 2 +- .../decoder/audio_opus_decoder_plugin.cpp | 2 +- .../audio_ffmpeg_aac_encoder_plugin.cpp | 2 +- .../encoder/audio_ffmpeg_encoder_plugin.cpp | 2 +- .../audio_ffmpeg_flac_encoder_plugin.cpp | 2 +- .../encoder/audio_g711mu_encoder_plugin.cpp | 2 +- .../encoder/audio_opus_encoder_plugin.cpp | 2 +- services/engine/codec/video/fcodec.cpp | 2 +- .../engine/demuxer/demuxer_engine_impl.cpp | 2 +- services/engine/muxer/muxer_buffer_pool.cpp | 2 +- services/engine/muxer/muxer_engine_impl.cpp | 3 +- .../engine/plugin/core/demuxer_factory.cpp | 2 +- .../ffmpeg_demuxer/block_queue_pool.cpp | 2 +- .../ffmpeg_demuxer/ffmpeg_demuxer_plugin.cpp | 2 +- .../engine/source/ffmpeg_format_helper.cpp | 2 +- services/engine/source/source.cpp | 3 +- services/engine/source/source_engine_impl.cpp | 2 +- .../services/codec/ipc/codec_service_stub.cpp | 2 +- .../services/codec/server/codec_server.cpp | 2 + services/services/codec/server/codec_server.h | 2 +- .../sa_avcodec/client/avcodec_client.cpp | 3 +- .../sa_avcodec/server/avcodec_server.cpp | 3 +- .../server/avcodec_server_manager.cpp | 2 +- 44 files changed, 138 insertions(+), 87 deletions(-) rename services/dfx/{avcodec_dfx.cpp => avcodec_sysevent.cpp} (86%) create mode 100644 services/dfx/avcodec_trace.cpp rename services/dfx/include/{avcodec_dfx.h => avcodec_sysevent.h} (81%) create mode 100644 services/dfx/include/avcodec_trace.h diff --git a/frameworks/native/avcodec/avcodec_audio_decoder_impl.cpp b/frameworks/native/avcodec/avcodec_audio_decoder_impl.cpp index f83650956..8ae051b8b 100644 --- a/frameworks/native/avcodec/avcodec_audio_decoder_impl.cpp +++ b/frameworks/native/avcodec/avcodec_audio_decoder_impl.cpp @@ -17,7 +17,7 @@ #include "i_avcodec_service.h" #include "avcodec_log.h" #include "avcodec_errors.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "codec_server.h" namespace { diff --git a/frameworks/native/avcodec/avcodec_audio_encoder_impl.cpp b/frameworks/native/avcodec/avcodec_audio_encoder_impl.cpp index 85f78de42..bce86fdbc 100644 --- a/frameworks/native/avcodec/avcodec_audio_encoder_impl.cpp +++ b/frameworks/native/avcodec/avcodec_audio_encoder_impl.cpp @@ -17,7 +17,7 @@ #include "i_avcodec_service.h" #include "avcodec_log.h" #include "avcodec_errors.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "codec_server.h" namespace { diff --git a/frameworks/native/avcodec/avcodec_video_decoder_impl.cpp b/frameworks/native/avcodec/avcodec_video_decoder_impl.cpp index 469195ddb..85874e2bc 100644 --- a/frameworks/native/avcodec/avcodec_video_decoder_impl.cpp +++ b/frameworks/native/avcodec/avcodec_video_decoder_impl.cpp @@ -14,7 +14,7 @@ */ #include "avcodec_video_decoder_impl.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "i_avcodec_service.h" diff --git a/frameworks/native/avcodec/avcodec_video_encoder_impl.cpp b/frameworks/native/avcodec/avcodec_video_encoder_impl.cpp index 9719e32d8..03c6f6d3c 100644 --- a/frameworks/native/avcodec/avcodec_video_encoder_impl.cpp +++ b/frameworks/native/avcodec/avcodec_video_encoder_impl.cpp @@ -14,7 +14,7 @@ */ #include "avcodec_video_encoder_impl.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "i_avcodec_service.h" diff --git a/frameworks/native/avdemuxer/avdemuxer_impl.cpp b/frameworks/native/avdemuxer/avdemuxer_impl.cpp index b14c49e75..f4eb1d58d 100644 --- a/frameworks/native/avdemuxer/avdemuxer_impl.cpp +++ b/frameworks/native/avdemuxer/avdemuxer_impl.cpp @@ -21,7 +21,7 @@ #include "securec.h" #include "avcodec_log.h" #include "avsharedmemorybase.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "i_avcodec_service.h" #include "avcodec_errors.h" diff --git a/frameworks/native/avmuxer/avmuxer_impl.cpp b/frameworks/native/avmuxer/avmuxer_impl.cpp index 5fd00ff34..22f69fa45 100644 --- a/frameworks/native/avmuxer/avmuxer_impl.cpp +++ b/frameworks/native/avmuxer/avmuxer_impl.cpp @@ -20,7 +20,7 @@ #include "i_avcodec_service.h" #include "avcodec_log.h" #include "avsharedmemorybase.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" namespace { diff --git a/frameworks/native/avsource/avsource_impl.cpp b/frameworks/native/avsource/avsource_impl.cpp index 00a4514b1..6c5660e59 100644 --- a/frameworks/native/avsource/avsource_impl.cpp +++ b/frameworks/native/avsource/avsource_impl.cpp @@ -19,7 +19,7 @@ #include "i_avcodec_service.h" #include "avcodec_errors.h" #include "avcodec_log.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avsource_impl.h" namespace { diff --git a/frameworks/native/capi/avcodec/native_video_decoder.cpp b/frameworks/native/capi/avcodec/native_video_decoder.cpp index 47f3ce431..f299b9cad 100644 --- a/frameworks/native/capi/avcodec/native_video_decoder.cpp +++ b/frameworks/native/capi/avcodec/native_video_decoder.cpp @@ -17,7 +17,7 @@ #include #include #include -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "avcodec_video_decoder.h" diff --git a/frameworks/native/capi/avcodec/native_video_encoder.cpp b/frameworks/native/capi/avcodec/native_video_encoder.cpp index 40a9e54e5..782959d9f 100644 --- a/frameworks/native/capi/avcodec/native_video_encoder.cpp +++ b/frameworks/native/capi/avcodec/native_video_encoder.cpp @@ -16,7 +16,7 @@ #include #include #include -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "avcodec_video_encoder.h" diff --git a/services/dfx/BUILD.gn b/services/dfx/BUILD.gn index 48b88a640..695168b2e 100644 --- a/services/dfx/BUILD.gn +++ b/services/dfx/BUILD.gn @@ -26,7 +26,8 @@ ohos_shared_library("av_codec_service_dfx") { sources = [ "avcodec_bitstream_dump.cpp", - "avcodec_dfx.cpp", + "avcodec_trace.cpp", + "avcodec_sysevent.cpp", "avcodec_dump_utils.cpp", "avcodec_xcollie.cpp", ] diff --git a/services/dfx/avcodec_dfx.cpp b/services/dfx/avcodec_sysevent.cpp similarity index 86% rename from services/dfx/avcodec_dfx.cpp rename to services/dfx/avcodec_sysevent.cpp index 1953bfcbd..4aee8b780 100644 --- a/services/dfx/avcodec_dfx.cpp +++ b/services/dfx/avcodec_sysevent.cpp @@ -13,12 +13,11 @@ * limitations under the License. */ -#include +#include #include #include "securec.h" #include "avcodec_log.h" #include "avcodec_errors.h" -#include "hitrace_meter.h" #include "dump_usage.h" namespace { @@ -110,33 +109,5 @@ void CodecStopEventWrite(uint32_t clientPid, uint32_t clientUid, uint32_t codecI OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "CLIENT_PID", clientPid, "CLIENT_UID", clientUid, "CODEC_INSTANCE_ID", codecInstanceId); } - -AVCodecTrace::AVCodecTrace(const std::string& funcName) -{ - StartTrace(HITRACE_TAG_ZMEDIA, funcName); - isSync_ = true; -} - -void AVCodecTrace::TraceBegin(const std::string& funcName, int32_t taskId) -{ - StartAsyncTrace(HITRACE_TAG_ZMEDIA, funcName, taskId); -} - -void AVCodecTrace::TraceEnd(const std::string& funcName, int32_t taskId) -{ - FinishAsyncTrace(HITRACE_TAG_ZMEDIA, funcName, taskId); -} - -void AVCodecTrace::CounterTrace(const std::string& varName, int32_t val) -{ - CountTrace(HITRACE_TAG_ZMEDIA, varName, val); -} - -AVCodecTrace::~AVCodecTrace() -{ - if (isSync_) { - FinishTrace(HITRACE_TAG_ZMEDIA); - } -} } // namespace MediaAVCodec } // namespace OHOS diff --git a/services/dfx/avcodec_trace.cpp b/services/dfx/avcodec_trace.cpp new file mode 100644 index 000000000..96a979076 --- /dev/null +++ b/services/dfx/avcodec_trace.cpp @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#include +#include "hitrace_meter.h" + +namespace OHOS { +namespace MediaAVCodec { +AVCodecTrace::AVCodecTrace(const std::string& funcName) +{ + StartTrace(HITRACE_TAG_ZMEDIA, funcName); + isSync_ = true; +} + +void AVCodecTrace::TraceBegin(const std::string& funcName, int32_t taskId) +{ + StartAsyncTrace(HITRACE_TAG_ZMEDIA, funcName, taskId); +} + +void AVCodecTrace::TraceEnd(const std::string& funcName, int32_t taskId) +{ + FinishAsyncTrace(HITRACE_TAG_ZMEDIA, funcName, taskId); +} + +void AVCodecTrace::CounterTrace(const std::string& varName, int32_t val) +{ + CountTrace(HITRACE_TAG_ZMEDIA, varName, val); +} + +AVCodecTrace::~AVCodecTrace() +{ + if (isSync_) { + FinishTrace(HITRACE_TAG_ZMEDIA); + } +} +} // namespace MediaAVCodec +} // namespace OHOS diff --git a/services/dfx/avcodec_xcollie.cpp b/services/dfx/avcodec_xcollie.cpp index 43719fcc1..a93492702 100644 --- a/services/dfx/avcodec_xcollie.cpp +++ b/services/dfx/avcodec_xcollie.cpp @@ -19,7 +19,7 @@ #include "param_wrapper.h" #include "avcodec_dump_utils.h" #include "avcodec_log.h" -#include "avcodec_dfx.h" +#include "avcodec_sysevent.h" #ifdef HICOLLIE_ENABLE #include "xcollie/xcollie.h" #include "xcollie/xcollie_define.h" diff --git a/services/dfx/include/avcodec_dfx.h b/services/dfx/include/avcodec_sysevent.h similarity index 81% rename from services/dfx/include/avcodec_dfx.h rename to services/dfx/include/avcodec_sysevent.h index 0bc2c9786..8532eb58c 100644 --- a/services/dfx/include/avcodec_dfx.h +++ b/services/dfx/include/avcodec_sysevent.h @@ -13,11 +13,10 @@ * limitations under the License. */ -#ifndef AVCODEC_DFX_H -#define AVCODEC_DFX_H +#ifndef AVCODEC_SYSEVENT_H +#define AVCODEC_SYSEVENT_H #include -#include #include "nocopyable.h" #include "hisysevent.h" @@ -74,20 +73,6 @@ __attribute__((visibility("default"))) void ServiceStartEventWrite(uint32_t useT __attribute__((visibility("default"))) void CodecStartEventWrite(CodecDfxInfo& codecDfxInfo); __attribute__((visibility("default"))) void CodecStopEventWrite(uint32_t clientPid, uint32_t clientUid, uint32_t codecInstanceId); - -#define AVCODEC_SYNC_TRACE AVCodecTrace trace(std::string(__FUNCTION__)) - -class __attribute__((visibility("default"))) AVCodecTrace : public NoCopyable { -public: - explicit AVCodecTrace(const std::string& funcName); - static void TraceBegin(const std::string& funcName, int32_t taskId); - static void TraceEnd(const std::string& funcName, int32_t taskId); - static void CounterTrace(const std::string& varName, int32_t val); - ~AVCodecTrace(); - -private: - bool isSync_ = false; -}; } // namespace MediaAVCodec } // namespace OHOS -#endif // AVCODEC_DFX_H \ No newline at end of file +#endif // AVCODEC_SYSEVENT_H \ No newline at end of file diff --git a/services/dfx/include/avcodec_trace.h b/services/dfx/include/avcodec_trace.h new file mode 100644 index 000000000..cf8daf213 --- /dev/null +++ b/services/dfx/include/avcodec_trace.h @@ -0,0 +1,39 @@ +/* + * 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 AVCODEC_TRACE_H +#define AVCODEC_TRACE_H + +#include +#include "nocopyable.h" + +namespace OHOS { +namespace MediaAVCodec { +#define AVCODEC_SYNC_TRACE AVCodecTrace trace(std::string(__FUNCTION__)) + +class __attribute__((visibility("default"))) AVCodecTrace : public NoCopyable { +public: + explicit AVCodecTrace(const std::string& funcName); + static void TraceBegin(const std::string& funcName, int32_t taskId); + static void TraceEnd(const std::string& funcName, int32_t taskId); + static void CounterTrace(const std::string& varName, int32_t val); + ~AVCodecTrace(); + +private: + bool isSync_ = false; +}; +} // namespace MediaAVCodec +} // namespace OHOS +#endif // AVCODEC_TRACE_H \ No newline at end of file diff --git a/services/engine/codec/audio/audio_codec_adapter.cpp b/services/engine/codec/audio/audio_codec_adapter.cpp index e709669db..93e5a42f2 100644 --- a/services/engine/codec/audio/audio_codec_adapter.cpp +++ b/services/engine/codec/audio/audio_codec_adapter.cpp @@ -15,7 +15,7 @@ #include "audio_codec_adapter.h" #include -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "media_description.h" diff --git a/services/engine/codec/audio/audio_codec_worker.cpp b/services/engine/codec/audio/audio_codec_worker.cpp index 657c8aa28..61f846181 100644 --- a/services/engine/codec/audio/audio_codec_worker.cpp +++ b/services/engine/codec/audio/audio_codec_worker.cpp @@ -14,7 +14,7 @@ */ #include "audio_codec_worker.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "utils.h" diff --git a/services/engine/codec/audio/decoder/audio_ffmpeg_aac_decoder_plugin.cpp b/services/engine/codec/audio/decoder/audio_ffmpeg_aac_decoder_plugin.cpp index bca9b1165..00538c32f 100644 --- a/services/engine/codec/audio/decoder/audio_ffmpeg_aac_decoder_plugin.cpp +++ b/services/engine/codec/audio/decoder/audio_ffmpeg_aac_decoder_plugin.cpp @@ -15,7 +15,7 @@ #include "audio_ffmpeg_aac_decoder_plugin.h" #include -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "media_description.h" diff --git a/services/engine/codec/audio/decoder/audio_ffmpeg_decoder_plugin.cpp b/services/engine/codec/audio/decoder/audio_ffmpeg_decoder_plugin.cpp index b1392d12f..33d48ac75 100644 --- a/services/engine/codec/audio/decoder/audio_ffmpeg_decoder_plugin.cpp +++ b/services/engine/codec/audio/decoder/audio_ffmpeg_decoder_plugin.cpp @@ -14,7 +14,7 @@ */ #include "audio_ffmpeg_decoder_plugin.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "media_description.h" diff --git a/services/engine/codec/audio/decoder/audio_ffmpeg_flac_decoder_plugin.cpp b/services/engine/codec/audio/decoder/audio_ffmpeg_flac_decoder_plugin.cpp index a8c1813db..869719969 100644 --- a/services/engine/codec/audio/decoder/audio_ffmpeg_flac_decoder_plugin.cpp +++ b/services/engine/codec/audio/decoder/audio_ffmpeg_flac_decoder_plugin.cpp @@ -16,7 +16,7 @@ #include "audio_ffmpeg_flac_decoder_plugin.h" #include "avcodec_errors.h" #include "media_description.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "avcodec_mime_type.h" diff --git a/services/engine/codec/audio/decoder/audio_ffmpeg_vorbis_decoder_plugin.cpp b/services/engine/codec/audio/decoder/audio_ffmpeg_vorbis_decoder_plugin.cpp index f8ab2edc0..6c82d6290 100644 --- a/services/engine/codec/audio/decoder/audio_ffmpeg_vorbis_decoder_plugin.cpp +++ b/services/engine/codec/audio/decoder/audio_ffmpeg_vorbis_decoder_plugin.cpp @@ -15,7 +15,7 @@ #include "audio_ffmpeg_vorbis_decoder_plugin.h" #include -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "avcodec_errors.h" #include "media_description.h" diff --git a/services/engine/codec/audio/decoder/audio_g711mu_decoder_plugin.cpp b/services/engine/codec/audio/decoder/audio_g711mu_decoder_plugin.cpp index 15d5fd124..82e081538 100644 --- a/services/engine/codec/audio/decoder/audio_g711mu_decoder_plugin.cpp +++ b/services/engine/codec/audio/decoder/audio_g711mu_decoder_plugin.cpp @@ -16,7 +16,7 @@ #include "audio_g711mu_decoder_plugin.h" #include "avcodec_errors.h" #include "media_description.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "avcodec_mime_type.h" diff --git a/services/engine/codec/audio/decoder/audio_opus_decoder_plugin.cpp b/services/engine/codec/audio/decoder/audio_opus_decoder_plugin.cpp index baa0beb0b..e2acb3da0 100644 --- a/services/engine/codec/audio/decoder/audio_opus_decoder_plugin.cpp +++ b/services/engine/codec/audio/decoder/audio_opus_decoder_plugin.cpp @@ -16,7 +16,7 @@ #include #include #include "avcodec_errors.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "media_description.h" #include "avcodec_mime_type.h" diff --git a/services/engine/codec/audio/encoder/audio_ffmpeg_aac_encoder_plugin.cpp b/services/engine/codec/audio/encoder/audio_ffmpeg_aac_encoder_plugin.cpp index 6055c9e8b..4741411be 100644 --- a/services/engine/codec/audio/encoder/audio_ffmpeg_aac_encoder_plugin.cpp +++ b/services/engine/codec/audio/encoder/audio_ffmpeg_aac_encoder_plugin.cpp @@ -16,7 +16,7 @@ #include "audio_ffmpeg_aac_encoder_plugin.h" #include #include "avcodec_errors.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "media_description.h" #include "avcodec_mime_type.h" diff --git a/services/engine/codec/audio/encoder/audio_ffmpeg_encoder_plugin.cpp b/services/engine/codec/audio/encoder/audio_ffmpeg_encoder_plugin.cpp index cb3f0e8e6..b6e7a5609 100644 --- a/services/engine/codec/audio/encoder/audio_ffmpeg_encoder_plugin.cpp +++ b/services/engine/codec/audio/encoder/audio_ffmpeg_encoder_plugin.cpp @@ -16,7 +16,7 @@ #include "audio_ffmpeg_encoder_plugin.h" #include "avcodec_errors.h" #include "media_description.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "securec.h" #include "ffmpeg_converter.h" diff --git a/services/engine/codec/audio/encoder/audio_ffmpeg_flac_encoder_plugin.cpp b/services/engine/codec/audio/encoder/audio_ffmpeg_flac_encoder_plugin.cpp index fd675195a..53efec0fe 100644 --- a/services/engine/codec/audio/encoder/audio_ffmpeg_flac_encoder_plugin.cpp +++ b/services/engine/codec/audio/encoder/audio_ffmpeg_flac_encoder_plugin.cpp @@ -17,7 +17,7 @@ #include #include "media_description.h" #include "avcodec_errors.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "avcodec_mime_type.h" #include "avcodec_audio_common.h" diff --git a/services/engine/codec/audio/encoder/audio_g711mu_encoder_plugin.cpp b/services/engine/codec/audio/encoder/audio_g711mu_encoder_plugin.cpp index d2bf3cbef..a091a84ac 100644 --- a/services/engine/codec/audio/encoder/audio_g711mu_encoder_plugin.cpp +++ b/services/engine/codec/audio/encoder/audio_g711mu_encoder_plugin.cpp @@ -16,7 +16,7 @@ #include "audio_g711mu_encoder_plugin.h" #include "media_description.h" #include "avcodec_errors.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "avcodec_mime_type.h" #include "avcodec_audio_common.h" diff --git a/services/engine/codec/audio/encoder/audio_opus_encoder_plugin.cpp b/services/engine/codec/audio/encoder/audio_opus_encoder_plugin.cpp index 8c615b201..ba025752a 100644 --- a/services/engine/codec/audio/encoder/audio_opus_encoder_plugin.cpp +++ b/services/engine/codec/audio/encoder/audio_opus_encoder_plugin.cpp @@ -16,7 +16,7 @@ #include #include #include "avcodec_errors.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "media_description.h" #include "avcodec_mime_type.h" diff --git a/services/engine/codec/video/fcodec.cpp b/services/engine/codec/video/fcodec.cpp index 82ac8d071..3d24e58ab 100644 --- a/services/engine/codec/video/fcodec.cpp +++ b/services/engine/codec/video/fcodec.cpp @@ -18,7 +18,7 @@ #include #include #include "securec.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "utils.h" #include "avcodec_codec_name.h" diff --git a/services/engine/demuxer/demuxer_engine_impl.cpp b/services/engine/demuxer/demuxer_engine_impl.cpp index f952d6b4e..122db627d 100644 --- a/services/engine/demuxer/demuxer_engine_impl.cpp +++ b/services/engine/demuxer/demuxer_engine_impl.cpp @@ -19,7 +19,7 @@ #include "demuxer_factory.h" #include "avcodec_errors.h" #include "iostream" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "DemuxerEngineImpl"}; diff --git a/services/engine/muxer/muxer_buffer_pool.cpp b/services/engine/muxer/muxer_buffer_pool.cpp index ce3aecd2f..e9e105ede 100644 --- a/services/engine/muxer/muxer_buffer_pool.cpp +++ b/services/engine/muxer/muxer_buffer_pool.cpp @@ -16,7 +16,7 @@ #include "muxer_buffer_pool.h" #include #include "avcodec_log.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "MuxerBufferPool"}; diff --git a/services/engine/muxer/muxer_engine_impl.cpp b/services/engine/muxer/muxer_engine_impl.cpp index affb37be8..726cf0440 100644 --- a/services/engine/muxer/muxer_engine_impl.cpp +++ b/services/engine/muxer/muxer_engine_impl.cpp @@ -23,7 +23,8 @@ #include "securec.h" #include "avcodec_log.h" #include "muxer_factory.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" +#include "avcodec_sysevent.h" #include "avcodec_info.h" #include "avcodec_errors.h" #include "avcodec_dump_utils.h" diff --git a/services/engine/plugin/core/demuxer_factory.cpp b/services/engine/plugin/core/demuxer_factory.cpp index a0ccfe64f..48836cd3e 100644 --- a/services/engine/plugin/core/demuxer_factory.cpp +++ b/services/engine/plugin/core/demuxer_factory.cpp @@ -18,7 +18,7 @@ #include #include "type_cast_ext.h" #include "avcodec_log.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "demuxer_factory.h" diff --git a/services/engine/plugin/plugins/demuxer/ffmpeg_demuxer/block_queue_pool.cpp b/services/engine/plugin/plugins/demuxer/ffmpeg_demuxer/block_queue_pool.cpp index ca17d975d..162d864ee 100644 --- a/services/engine/plugin/plugins/demuxer/ffmpeg_demuxer/block_queue_pool.cpp +++ b/services/engine/plugin/plugins/demuxer/ffmpeg_demuxer/block_queue_pool.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "block_queue_pool.h" diff --git a/services/engine/plugin/plugins/demuxer/ffmpeg_demuxer/ffmpeg_demuxer_plugin.cpp b/services/engine/plugin/plugins/demuxer/ffmpeg_demuxer/ffmpeg_demuxer_plugin.cpp index d992181e3..dbb4b4f48 100644 --- a/services/engine/plugin/plugins/demuxer/ffmpeg_demuxer/ffmpeg_demuxer_plugin.cpp +++ b/services/engine/plugin/plugins/demuxer/ffmpeg_demuxer/ffmpeg_demuxer_plugin.cpp @@ -24,7 +24,7 @@ #include "native_avcodec_base.h" #include "plugin_definition.h" #include "avcodec_log.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "ffmpeg_demuxer_plugin.h" #if defined(LIBAVFORMAT_VERSION_INT) && defined(LIBAVFORMAT_VERSION_INT) diff --git a/services/engine/source/ffmpeg_format_helper.cpp b/services/engine/source/ffmpeg_format_helper.cpp index fb9d47445..edfd53f0a 100644 --- a/services/engine/source/ffmpeg_format_helper.cpp +++ b/services/engine/source/ffmpeg_format_helper.cpp @@ -18,7 +18,7 @@ #include "av_common.h" #include "avcodec_common.h" #include "avcodec_errors.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_log.h" #include "avcodec_info.h" #include "ffmpeg_converter.h" diff --git a/services/engine/source/source.cpp b/services/engine/source/source.cpp index ff87500b8..9118e7b59 100644 --- a/services/engine/source/source.cpp +++ b/services/engine/source/source.cpp @@ -20,7 +20,8 @@ #include #include #include "avcodec_errors.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" +#include "avcodec_sysevent.h" #include "media_description.h" #include "avcodec_log.h" #include "avcodec_info.h" diff --git a/services/engine/source/source_engine_impl.cpp b/services/engine/source/source_engine_impl.cpp index baf1f909b..20e8bba5e 100644 --- a/services/engine/source/source_engine_impl.cpp +++ b/services/engine/source/source_engine_impl.cpp @@ -20,7 +20,7 @@ #include "securec.h" #include "source.h" #include "avcodec_log.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" namespace { diff --git a/services/services/codec/ipc/codec_service_stub.cpp b/services/services/codec/ipc/codec_service_stub.cpp index a8071c2b8..58efd3c10 100644 --- a/services/services/codec/ipc/codec_service_stub.cpp +++ b/services/services/codec/ipc/codec_service_stub.cpp @@ -15,7 +15,7 @@ #include "codec_service_stub.h" #include -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "avcodec_parcel.h" diff --git a/services/services/codec/server/codec_server.cpp b/services/services/codec/server/codec_server.cpp index 2c8606e4f..1fac1ab6b 100644 --- a/services/services/codec/server/codec_server.cpp +++ b/services/services/codec/server/codec_server.cpp @@ -26,6 +26,8 @@ #include "codec_factory.h" #include "media_description.h" #include "surface_type.h" +#include "avcodec_trace.h" +#include "avcodec_sysevent.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "CodecServer"}; diff --git a/services/services/codec/server/codec_server.h b/services/services/codec/server/codec_server.h index 56c54c067..38b10a1ff 100644 --- a/services/services/codec/server/codec_server.h +++ b/services/services/codec/server/codec_server.h @@ -17,7 +17,7 @@ #define CODEC_SERVER_H #include -#include "avcodec_dfx.h" +#include "avcodec_sysevent.h" #include "codecbase.h" #include "i_codec_service.h" #include "nocopyable.h" diff --git a/services/services/sa_avcodec/client/avcodec_client.cpp b/services/services/sa_avcodec/client/avcodec_client.cpp index 44438f576..8ea6c3a1d 100644 --- a/services/services/sa_avcodec/client/avcodec_client.cpp +++ b/services/services/sa_avcodec/client/avcodec_client.cpp @@ -17,7 +17,8 @@ #include "ipc_skeleton.h" #include "iservice_registry.h" #include "system_ability_definition.h" -#include "avcodec_dfx.h" +#include "avcodec_trace.h" +#include "avcodec_sysevent.h" #ifdef SUPPORT_CODEC #include "i_standard_codec_service.h" diff --git a/services/services/sa_avcodec/server/avcodec_server.cpp b/services/services/sa_avcodec/server/avcodec_server.cpp index 13f62bfbb..58e2829a6 100644 --- a/services/services/sa_avcodec/server/avcodec_server.cpp +++ b/services/services/sa_avcodec/server/avcodec_server.cpp @@ -15,7 +15,8 @@ #include "avcodec_server.h" #include -#include "avcodec_dfx.h" +#include "avcodec_trace.h" +#include "avcodec_sysevent.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "iservice_registry.h" diff --git a/services/services/sa_avcodec/server/avcodec_server_manager.cpp b/services/services/sa_avcodec/server/avcodec_server_manager.cpp index 5adfbb7ce..074c973a6 100644 --- a/services/services/sa_avcodec/server/avcodec_server_manager.cpp +++ b/services/services/sa_avcodec/server/avcodec_server_manager.cpp @@ -18,7 +18,7 @@ #include #include #include -#include "avcodec_dfx.h" +#include "avcodec_trace.h" #include "avcodec_errors.h" #include "avcodec_log.h" #include "avcodec_xcollie.h" -- Gitee From b2d2fa65110e3df999019ecc83b39a6ccc0ead91 Mon Sep 17 00:00:00 2001 From: West Date: Tue, 12 Dec 2023 17:27:11 +0800 Subject: [PATCH 09/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Add=20avbuffer=20interface=20trace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Iabab0f620923672b38184121394f2411146f0590 --- .../capi/avcodec/native_video_decoder.cpp | 55 +++++++++---------- .../capi/avcodec/native_video_encoder.cpp | 55 +++++++++---------- 2 files changed, 52 insertions(+), 58 deletions(-) diff --git a/frameworks/native/capi/avcodec/native_video_decoder.cpp b/frameworks/native/capi/avcodec/native_video_decoder.cpp index f299b9cad..5a9942305 100644 --- a/frameworks/native/capi/avcodec/native_video_decoder.cpp +++ b/frameworks/native/capi/avcodec/native_video_decoder.cpp @@ -47,7 +47,7 @@ struct VideoDecoderObject : public OH_AVCodec { const std::shared_ptr videoDecoder_; std::list> memoryObjList_; - std::list> bufferObjList_; + std::unordered_map> bufferObjMap_; std::shared_ptr memoryCallback_ = nullptr; std::shared_ptr bufferCallback_ = nullptr; std::atomic isFlushing_ = false; @@ -232,10 +232,6 @@ public: } OH_AVBuffer *data = GetTransData(codec_, index, buffer); - { - std::unique_lock mapLock(mapMutex_); - bufferInputMap_[index] = buffer; - } callback_.onNeedInputBuffer(codec_, index, data, userData_); } @@ -271,18 +267,6 @@ public: callback_.onNewOutputBuffer(codec_, index, data, userData_); } - AVCodecBufferFlag GetFlagByIndex(uint32_t index) - { - std::shared_lock lock(mapMutex_); - return static_cast(bufferInputMap_[index]->flag_); - } - - void ClearBufferMap() - { - std::unique_lock mapLock(mapMutex_); - bufferInputMap_.clear(); - } - void StopCallback() { std::unique_lock lock(mutex_); @@ -301,9 +285,9 @@ private: { std::shared_lock lock(videoDecObj->objListMutex_); - for (auto &bufferObj : videoDecObj->bufferObjList_) { - if (bufferObj->IsEqualBuffer(buffer)) { - return reinterpret_cast(bufferObj.GetRefPtr()); + for (auto &bufferObj : videoDecObj->bufferObjMap_) { + if (bufferObj.second->IsEqualBuffer(buffer)) { + return reinterpret_cast(bufferObj.second.GetRefPtr()); } } } @@ -312,16 +296,14 @@ private: CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "failed to new OH_AVBuffer"); std::lock_guard lock(videoDecObj->objListMutex_); - videoDecObj->bufferObjList_.push_back(object); + videoDecObj->bufferObjMap_.emplace(index, object); return reinterpret_cast(object.GetRefPtr()); } struct OH_AVCodec *codec_; struct OH_AVCodecCallback callback_; - std::unordered_map> bufferInputMap_; void *userData_; std::shared_mutex mutex_; - std::shared_mutex mapMutex_; }; namespace OHOS { @@ -333,8 +315,7 @@ void ClearBufferList(struct VideoDecoderObject **videoDecObj) (*videoDecObj)->memoryObjList_.clear(); } if ((*videoDecObj)->bufferCallback_ != nullptr) { - (*videoDecObj)->bufferObjList_.clear(); - (*videoDecObj)->bufferCallback_->ClearBufferMap(); + (*videoDecObj)->bufferObjMap_.clear(); } } @@ -575,15 +556,31 @@ OH_AVErrCode OH_VideoDecoder_PushInputBuffer(struct OH_AVCodec *codec, uint32_t struct VideoDecoderObject *videoDecObj = reinterpret_cast(codec); CHECK_AND_RETURN_RET_LOG(videoDecObj->videoDecoder_ != nullptr, AV_ERR_INVALID_VAL, "video decoder is nullptr!"); + { + std::shared_lock lock(videoDecObj->objListMutex_); + auto bufferIter = videoDecObj->bufferObjMap_.find(index); + CHECK_AND_RETURN_RET_LOG(bufferIter != videoDecObj->bufferObjMap_.end(), AV_ERR_INVALID_VAL, + "Invalid buffer index"); + auto buffer = bufferIter->second->buffer_; + if (buffer->flag_ == AVCODEC_BUFFER_FLAG_EOS) { + videoDecObj->isEOS_.store(true); + AVCODEC_LOGD("Set eos status to true"); + } + if (buffer->flag_ != AVCODEC_BUFFER_FLAGS_CODEC_DATA) { + if (videoDecObj->isFirstFrameIn_) { + AVCodecTrace::TraceBegin("OH::FirstFrame", buffer->pts_); + videoDecObj->isFirstFrameIn_ = false; + } else { + AVCodecTrace::TraceBegin("OH::Frame", buffer->pts_); + } + } + } + int32_t ret = videoDecObj->videoDecoder_->QueueInputBuffer(index); CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCSErrorToOHAVErrCode(static_cast(ret)), "videoDecoder QueueInputBuffer failed!"); CHECK_AND_RETURN_RET_LOG(videoDecObj->bufferCallback_ != nullptr, AV_ERR_INVALID_STATE, "The callback of OH_AVBuffer is nullptr!"); - if (videoDecObj->bufferCallback_->GetFlagByIndex(index) == AVCODEC_BUFFER_FLAG_EOS) { - videoDecObj->isEOS_.store(true); - AVCODEC_LOGD("Set eos status to true"); - } return AV_ERR_OK; } diff --git a/frameworks/native/capi/avcodec/native_video_encoder.cpp b/frameworks/native/capi/avcodec/native_video_encoder.cpp index 782959d9f..4c04312a1 100644 --- a/frameworks/native/capi/avcodec/native_video_encoder.cpp +++ b/frameworks/native/capi/avcodec/native_video_encoder.cpp @@ -47,7 +47,7 @@ struct VideoEncoderObject : public OH_AVCodec { const std::shared_ptr videoEncoder_; std::list> memoryObjList_; - std::list> bufferObjList_; + std::unordered_map> bufferObjMap_; std::shared_ptr memoryCallback_ = nullptr; std::shared_ptr bufferCallback_ = nullptr; std::atomic isFlushing_ = false; @@ -234,10 +234,6 @@ public: OH_AVBuffer *data = nullptr; if (!videoEncObj->isInputSurfaceMode_) { data = GetTransData(codec_, index, buffer); - { - std::unique_lock mapLock(mapMutex_); - bufferInputMap_[index] = buffer; - } } callback_.onNeedInputBuffer(codec_, index, data, userData_); } @@ -279,18 +275,6 @@ public: codec_ = nullptr; } - AVCodecBufferFlag GetFlagByIndex(uint32_t index) - { - std::shared_lock lock(mapMutex_); - return static_cast(bufferInputMap_[index]->flag_); - } - - void ClearBufferMap() - { - std::unique_lock mapLock(mapMutex_); - bufferInputMap_.clear(); - } - private: OH_AVBuffer *GetTransData(struct OH_AVCodec *codec, uint32_t index, std::shared_ptr buffer) { @@ -303,9 +287,9 @@ private: { std::shared_lock lock(videoEncObj->objListMutex_); - for (auto &bufferObj : videoEncObj->bufferObjList_) { - if (bufferObj->IsEqualBuffer(buffer)) { - return reinterpret_cast(bufferObj.GetRefPtr()); + for (auto &bufferObj : videoEncObj->bufferObjMap_) { + if (bufferObj.second->IsEqualBuffer(buffer)) { + return reinterpret_cast(bufferObj.second.GetRefPtr()); } } } @@ -314,16 +298,14 @@ private: CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "failed to new OH_AVBuffer"); std::lock_guard lock(videoEncObj->objListMutex_); - videoEncObj->bufferObjList_.push_back(object); + videoEncObj->bufferObjMap_.emplace(index, object); return reinterpret_cast(object.GetRefPtr()); } struct OH_AVCodec *codec_; struct OH_AVCodecCallback callback_; - std::unordered_map> bufferInputMap_; void *userData_; std::shared_mutex mutex_; - std::shared_mutex mapMutex_; }; namespace OHOS { @@ -335,8 +317,7 @@ void ClearBufferList(struct VideoEncoderObject **videoEncObj) (*videoEncObj)->memoryObjList_.clear(); } if ((*videoEncObj)->bufferCallback_ != nullptr) { - (*videoEncObj)->bufferObjList_.clear(); - (*videoEncObj)->bufferCallback_->ClearBufferMap(); + (*videoEncObj)->bufferObjMap_.clear(); } } @@ -716,13 +697,29 @@ OH_AVErrCode OH_VideoEncoder_PushInputBuffer(struct OH_AVCodec *codec, uint32_t CHECK_AND_RETURN_RET_LOG(videoEncObj->bufferCallback_ != nullptr, AV_ERR_INVALID_STATE, "The callback of OH_AVBuffer is nullptr!"); + { + std::shared_lock lock(videoEncObj->objListMutex_); + auto bufferIter = videoEncObj->bufferObjMap_.find(index); + CHECK_AND_RETURN_RET_LOG(bufferIter != videoEncObj->bufferObjMap_.end(), AV_ERR_INVALID_VAL, + "Invalid buffer index"); + auto buffer = bufferIter->second->buffer_; + if (buffer->flag_ == AVCODEC_BUFFER_FLAG_EOS) { + videoEncObj->isEOS_.store(true); + AVCODEC_LOGD("Set eos status to true"); + } + if (buffer->flag_ != AVCODEC_BUFFER_FLAGS_CODEC_DATA) { + if (videoEncObj->isFirstFrameIn_) { + AVCodecTrace::TraceBegin("OH::FirstFrame", buffer->pts_); + videoEncObj->isFirstFrameIn_ = false; + } else { + AVCodecTrace::TraceBegin("OH::Frame", buffer->pts_); + } + } + } + int32_t ret = videoEncObj->videoEncoder_->QueueInputBuffer(index); CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCSErrorToOHAVErrCode(static_cast(ret)), "videoEncoder QueueInputBuffer failed!"); - if (videoEncObj->bufferCallback_->GetFlagByIndex(index) == AVCODEC_BUFFER_FLAG_EOS) { - videoEncObj->isEOS_.store(true); - AVCODEC_LOGD("Set eos status to true"); - } return AV_ERR_OK; } -- Gitee From 51de3ef69bb762c51ff75a1d4744b104547ac137 Mon Sep 17 00:00:00 2001 From: West Date: Tue, 12 Dec 2023 19:20:05 +0800 Subject: [PATCH 10/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Add=20perf=20test=20surface=20input=20=20trac?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Id2c43237262fa1611e60480568c1a879814ef4c7 --- services/avcodec_dfx.cpp | 142 ++++++++++++++++++ test/unittest/video_perf_test/BUILD.gn | 2 + .../include/video_decoder_perf_test_sample.h | 10 +- .../video_decoder_perf_test_sample.cpp | 62 ++++---- .../include/video_encoder_perf_test_sample.h | 14 +- .../video_encoder_perf_test_sample.cpp | 88 ++++++----- 6 files changed, 239 insertions(+), 79 deletions(-) create mode 100644 services/avcodec_dfx.cpp diff --git a/services/avcodec_dfx.cpp b/services/avcodec_dfx.cpp new file mode 100644 index 000000000..1953bfcbd --- /dev/null +++ b/services/avcodec_dfx.cpp @@ -0,0 +1,142 @@ +/* + * 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. + */ + +#include +#include +#include "securec.h" +#include "avcodec_log.h" +#include "avcodec_errors.h" +#include "hitrace_meter.h" +#include "dump_usage.h" + +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVCodecDFX"}; +constexpr uint32_t MAX_STRING_SIZE = 256; +constexpr char HISYSEVENT_DOMAIN_AVCODEC[] = "AV_CODEC"; +} // namespace + +namespace OHOS { +namespace MediaAVCodec { +bool AVCodecEvent::CreateMsg(const char* format, ...) +{ + va_list args; + va_start(args, format); + char msg[MAX_STRING_SIZE] = {0}; + if (vsnprintf_s(msg, sizeof(msg), sizeof(msg) - 1, format, args) < 0) { + AVCODEC_LOGE("failed to call vsnprintf_s"); + va_end(args); + return false; + } + va_end(args); + msg_ = msg; + return true; +} + +void AVCodecEvent::FaultEventWrite(const std::string& eventName, + OHOS::HiviewDFX::HiSysEvent::EventType type, + FaultType faultType, + const std::string& module) +{ + std::string faultName; + switch (faultType) { + case FaultType::FAULT_TYPE_FREEZE: + faultName = "Freeze"; + break; + case FaultType::FAULT_TYPE_CRASH: + faultName = "Crash"; + break; + case FaultType::FAULT_TYPE_INNER_ERROR: + faultName = "Inner error"; + break; + default: + AVCODEC_LOGE("Invalid fault type:%{public}d", faultType); + } + HiSysEventWrite(HISYSEVENT_DOMAIN_AVCODEC, eventName, type, "MODULE", module, "FAULTTYPE", faultName, "MSG", msg_); +} + +void FaultEventWrite(FaultType faultType, const std::string& msg, const std::string& module) +{ + AVCodecEvent event; + if (event.CreateMsg("%s", msg.c_str())) { + event.FaultEventWrite("FAULT", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, faultType, module); + } else { + AVCODEC_LOGW("Failed to call CreateMsg"); + } +} + +void ServiceStartEventWrite(uint32_t useTime, const std::string& module) +{ + OHOS::HiviewDFX::DumpUsage dumpUse; + uint64_t useMemory = dumpUse.GetPss(getpid()); + HiSysEventWrite(HISYSEVENT_DOMAIN_AVCODEC, "SERVICE_START_INFO", + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "MODULE", module.c_str(), "TIME", useTime, + "MEMORY", useMemory); +} + +void CodecStartEventWrite(CodecDfxInfo& codecDfxInfo) +{ + HiSysEventWrite(HISYSEVENT_DOMAIN_AVCODEC, "CODEC_START_INFO", + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "CLIENT_PID", codecDfxInfo.clientPid, + "CLIENT_UID", codecDfxInfo.clientUid, + "CODEC_INSTANCE_ID", codecDfxInfo.codecInstanceId, + "CODEC_NAME", codecDfxInfo.codecName, + "CODEC_IS_VENDOR", codecDfxInfo.codecIsVendor, + "CODEC_MODE", codecDfxInfo.codecMode, + "ENCODER_BITRATE", codecDfxInfo.encoderBitRate, + "VIDEO_WIDTH", codecDfxInfo.videoWidth, + "VIDEO_HEIGHT", codecDfxInfo.videoHeight, + "VIDEO_FRAMERATE", codecDfxInfo.videoFrameRate, + "VIDEO_PIXEL_FORMAT", codecDfxInfo.videoPixelFormat, + "AUDIO_CHANNEL_COUNT", codecDfxInfo.audioChannelCount, + "AUDIO_SAMPLE_RATE", codecDfxInfo.audioSampleRate); +} + +void CodecStopEventWrite(uint32_t clientPid, uint32_t clientUid, uint32_t codecInstanceId) +{ + HiSysEventWrite(HISYSEVENT_DOMAIN_AVCODEC, "CODEC_STOP_INFO", + OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + "CLIENT_PID", clientPid, "CLIENT_UID", clientUid, "CODEC_INSTANCE_ID", codecInstanceId); +} + +AVCodecTrace::AVCodecTrace(const std::string& funcName) +{ + StartTrace(HITRACE_TAG_ZMEDIA, funcName); + isSync_ = true; +} + +void AVCodecTrace::TraceBegin(const std::string& funcName, int32_t taskId) +{ + StartAsyncTrace(HITRACE_TAG_ZMEDIA, funcName, taskId); +} + +void AVCodecTrace::TraceEnd(const std::string& funcName, int32_t taskId) +{ + FinishAsyncTrace(HITRACE_TAG_ZMEDIA, funcName, taskId); +} + +void AVCodecTrace::CounterTrace(const std::string& varName, int32_t val) +{ + CountTrace(HITRACE_TAG_ZMEDIA, varName, val); +} + +AVCodecTrace::~AVCodecTrace() +{ + if (isSync_) { + FinishTrace(HITRACE_TAG_ZMEDIA); + } +} +} // namespace MediaAVCodec +} // namespace OHOS diff --git a/test/unittest/video_perf_test/BUILD.gn b/test/unittest/video_perf_test/BUILD.gn index c51504e8b..dfe696aaf 100644 --- a/test/unittest/video_perf_test/BUILD.gn +++ b/test/unittest/video_perf_test/BUILD.gn @@ -50,6 +50,7 @@ ohos_unittest("video_perf_test") { ] sources = [ + "../../../services/dfx/avcodec_trace.cpp", "./common/sample_callback.cpp", "./common/av_codec_sample_log.cpp", "./sample/decoder/video_decoder_perf_test_sample.cpp", @@ -69,5 +70,6 @@ ohos_unittest("video_perf_test") { "hilog:libhilog", "histreamer:media_foundation", "init:libbegetutil", + "hitrace:hitrace_meter", ] } \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index 82da85374..194c17df3 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -23,15 +23,15 @@ public: private: void StartRelease(); void Release(); - void decInputThread(); - void decOutputThread(); + void InputThread(); + void OutputThread(); bool IsCodecData(const uint8_t *const bufferAddr); int32_t ReadOneFrame(CodecBufferInfo &info); int32_t CreateWindow(OHNativeWindow *&window); std::unique_ptr videoDecoder_ = nullptr; - std::unique_ptr decInputThread_ = nullptr; - std::unique_ptr decOutputThread_ = nullptr; + std::unique_ptr inputThread_ = nullptr; + std::unique_ptr outputThread_ = nullptr; std::unique_ptr releaseThread_ = nullptr; std::unique_ptr inputFile_ = nullptr; @@ -39,7 +39,7 @@ private: std::atomic isStarted_ { false }; std::condition_variable doneCond_; SampleInfo sampleInfo_; - CodecUserData *decContext_ = nullptr; + CodecUserData *context_ = nullptr; OHOS::sptr surface_; }; diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 4a46d55e0..a86939544 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -68,10 +68,10 @@ int32_t VideoDecoderPerfTestSample::Create(SampleInfo sampleInfo) int32_t ret = videoDecoder_->Create(sampleInfo_.codecMime); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create video decoder failed"); - decContext_ = new CodecUserData; + context_ = new CodecUserData; ret = CreateWindow(sampleInfo_.window); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create window failed"); - ret = videoDecoder_->Config(sampleInfo_, decContext_); + ret = videoDecoder_->Config(sampleInfo_, context_); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Decoder config failed"); releaseThread_ = nullptr; @@ -83,7 +83,7 @@ int32_t VideoDecoderPerfTestSample::Start() { std::lock_guard lock(mutex_); CHECK_AND_RETURN_RET_LOG(!isStarted_, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); - CHECK_AND_RETURN_RET_LOG(decContext_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + CHECK_AND_RETURN_RET_LOG(context_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); CHECK_AND_RETURN_RET_LOG(videoDecoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); int32_t ret = videoDecoder_->Start(); @@ -91,9 +91,9 @@ int32_t VideoDecoderPerfTestSample::Start() isStarted_ = true; inputFile_ = std::make_unique(sampleInfo_.inputFilePath.data(), std::ios::binary | std::ios::in); - decInputThread_ = std::make_unique(&VideoDecoderPerfTestSample::decInputThread, this); - decOutputThread_ = std::make_unique(&VideoDecoderPerfTestSample::decOutputThread, this); - if (decInputThread_ == nullptr || decOutputThread_ == nullptr || !inputFile_->is_open()) { + inputThread_ = std::make_unique(&VideoDecoderPerfTestSample::InputThread, this); + outputThread_ = std::make_unique(&VideoDecoderPerfTestSample::OutputThread, this); + if (inputThread_ == nullptr || outputThread_ == nullptr || !inputFile_->is_open()) { AVCODEC_LOGE("Create thread or open file failed"); StartRelease(); return AVCODEC_SAMPLE_ERR_ERROR; @@ -124,26 +124,26 @@ void VideoDecoderPerfTestSample::Release() { std::lock_guard lock(mutex_); isStarted_ = false; - if (decInputThread_ && decInputThread_->joinable()) { - decInputThread_->join(); + if (inputThread_ && inputThread_->joinable()) { + inputThread_->join(); } - if (decOutputThread_ && decOutputThread_->joinable()) { - decOutputThread_->join(); + if (outputThread_ && outputThread_->joinable()) { + outputThread_->join(); } if (videoDecoder_ != nullptr) { videoDecoder_->Release(); } - decInputThread_.reset(); - decOutputThread_.reset(); + inputThread_.reset(); + outputThread_.reset(); videoDecoder_.reset(); if (sampleInfo_.window != nullptr) { OH_NativeWindow_DestroyNativeWindow(sampleInfo_.window); sampleInfo_.window = nullptr; } - if (decContext_ != nullptr) { - delete decContext_; - decContext_ = nullptr; + if (context_ != nullptr) { + delete context_; + context_ = nullptr; } if (inputFile_ != nullptr) { inputFile_.reset(); @@ -153,21 +153,21 @@ void VideoDecoderPerfTestSample::Release() doneCond_.notify_all(); } -void VideoDecoderPerfTestSample::decInputThread() +void VideoDecoderPerfTestSample::InputThread() { using namespace std::chrono_literals; auto lastPushTime = std::chrono::system_clock::now(); while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); - std::unique_lock lock(decContext_->inputMutex_); - bool condRet = decContext_->inputCond_.wait_for(lock, 5s, - [this]() { return !isStarted_ || !decContext_->inputBufferInfoQueue_.empty(); }); + std::unique_lock lock(context_->inputMutex_); + bool condRet = context_->inputCond_.wait_for(lock, 5s, + [this]() { return !isStarted_ || !context_->inputBufferInfoQueue_.empty(); }); CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); - CHECK_AND_CONTINUE_LOG(!decContext_->inputBufferInfoQueue_.empty(), + CHECK_AND_CONTINUE_LOG(!context_->inputBufferInfoQueue_.empty(), "Buffer queue is empty, continue, cond ret: %{public}d", condRet); - CodecBufferInfo bufferInfo = decContext_->inputBufferInfoQueue_.front(); - decContext_->inputBufferInfoQueue_.pop(); + CodecBufferInfo bufferInfo = context_->inputBufferInfoQueue_.front(); + context_->inputBufferInfoQueue_.pop(); lock.unlock(); int32_t ret = ReadOneFrame(bufferInfo); @@ -188,27 +188,27 @@ void VideoDecoderPerfTestSample::decInputThread() StartRelease(); } -void VideoDecoderPerfTestSample::decOutputThread() +void VideoDecoderPerfTestSample::OutputThread() { using namespace std::chrono_literals; while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Decoder output thread out"); - std::unique_lock lock(decContext_->outputMutex_); - bool condRet = decContext_->outputCond_.wait_for(lock, 5s, - [this]() { return !isStarted_ || !decContext_->outputBufferInfoQueue_.empty(); }); + std::unique_lock lock(context_->outputMutex_); + bool condRet = context_->outputCond_.wait_for(lock, 5s, + [this]() { return !isStarted_ || !context_->outputBufferInfoQueue_.empty(); }); CHECK_AND_BREAK_LOG(isStarted_, "Decoder output thread out"); - CHECK_AND_CONTINUE_LOG(!decContext_->outputBufferInfoQueue_.empty(), + CHECK_AND_CONTINUE_LOG(!context_->outputBufferInfoQueue_.empty(), "Buffer queue is empty, continue, cond ret: %{public}d", condRet); - CodecBufferInfo bufferInfo = decContext_->outputBufferInfoQueue_.front(); - decContext_->outputBufferInfoQueue_.pop(); + CodecBufferInfo bufferInfo = context_->outputBufferInfoQueue_.front(); + context_->outputBufferInfoQueue_.pop(); lock.unlock(); CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); int32_t ret = videoDecoder_->FreeOutputData(bufferInfo.bufferIndex); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Decoder output thread out"); } - AVCODEC_LOGI("On decoder output thread exit, output frame count: %{public}d", decContext_->outputFrameCount_); + AVCODEC_LOGI("On decoder output thread exit, output frame count: %{public}d", context_->outputFrameCount_); StartRelease(); } @@ -253,7 +253,7 @@ int32_t VideoDecoderPerfTestSample::ReadOneFrame(CodecBufferInfo &info) info.attr.flags = AVCODEC_BUFFER_FLAGS_EOS; } info.attr.size = bufferSize + AVCC_FRAME_HEAD_LEN; - info.attr.pts = decContext_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us + info.attr.pts = context_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us return AVCODEC_SAMPLE_ERR_OK; } diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h index 5c364fe0e..efb9a6bc4 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h @@ -21,15 +21,16 @@ public: private: void StartRelease(); void Release(); - void encBufferInputThread(); - void encSurfaceInputThread(); - void encOutputThread(); + void BufferInputThread(); + void SurfaceInputThread(); + void OutputThread(); int32_t ReadOneFrame(CodecBufferInfo &info); int32_t ReadOneFrame(uint8_t *bufferAddr, uint32_t &flags); + void AddSurfaceInputTrace(uint32_t flag, uint64_t pts); std::unique_ptr videoEncoder_ = nullptr; - std::unique_ptr encInputThread_ = nullptr; - std::unique_ptr encOutputThread_ = nullptr; + std::unique_ptr inputThread_ = nullptr; + std::unique_ptr outputThread_ = nullptr; std::unique_ptr releaseThread_ = nullptr; std::unique_ptr inputFile_ = nullptr; @@ -37,7 +38,8 @@ private: std::atomic isStarted_ { false }; std::condition_variable doneCond_; SampleInfo sampleInfo_; - CodecUserData *encContext_ = nullptr; + CodecUserData *context_ = nullptr; + bool isFirstFrameIn_ = true; }; #endif // AVCODEC_TEST_VIDEO_PERF_TEST_ENCODER_SAMPLE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 0a3e99c85..0da3d7ca3 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -6,6 +6,7 @@ #include "native_buffer_inner.h" #include "av_codec_sample_log.h" #include "av_codec_sample_error.h" +#include "avcodec_trace.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoEncoderSample"}; @@ -34,8 +35,8 @@ int32_t VideoEncoderPerfTestSample::Create(SampleInfo sampleInfo) int32_t ret = videoEncoder_->Create(sampleInfo_.codecMime); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create video encoder failed"); - encContext_ = new CodecUserData; - ret = videoEncoder_->Config(sampleInfo_, encContext_); + context_ = new CodecUserData; + ret = videoEncoder_->Config(sampleInfo_, context_); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Encoder config failed"); releaseThread_ = nullptr; @@ -47,7 +48,7 @@ int32_t VideoEncoderPerfTestSample::Start() { std::lock_guard lock(mutex_); CHECK_AND_RETURN_RET_LOG(!isStarted_, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); - CHECK_AND_RETURN_RET_LOG(encContext_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); + CHECK_AND_RETURN_RET_LOG(context_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); CHECK_AND_RETURN_RET_LOG(videoEncoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); int32_t ret = videoEncoder_->Start(); @@ -55,11 +56,11 @@ int32_t VideoEncoderPerfTestSample::Start() isStarted_ = true; inputFile_ = std::make_unique(sampleInfo_.inputFilePath.data(), std::ios::binary | std::ios::in); - encInputThread_ = (static_cast(sampleInfo_.codecRunMode) & 0b01) ? // 0b01: Buffer mode mask - std::make_unique(&VideoEncoderPerfTestSample::encBufferInputThread, this) : - std::make_unique(&VideoEncoderPerfTestSample::encSurfaceInputThread, this); - encOutputThread_ = std::make_unique(&VideoEncoderPerfTestSample::encOutputThread, this); - if (encInputThread_ == nullptr || encOutputThread_ == nullptr || !inputFile_->is_open()) { + inputThread_ = (static_cast(sampleInfo_.codecRunMode) & 0b01) ? // 0b01: Buffer mode mask + std::make_unique(&VideoEncoderPerfTestSample::BufferInputThread, this) : + std::make_unique(&VideoEncoderPerfTestSample::SurfaceInputThread, this); + outputThread_ = std::make_unique(&VideoEncoderPerfTestSample::OutputThread, this); + if (inputThread_ == nullptr || outputThread_ == nullptr || !inputFile_->is_open()) { AVCODEC_LOGE("Create thread failed"); StartRelease(); return AVCODEC_SAMPLE_ERR_ERROR; @@ -91,26 +92,26 @@ void VideoEncoderPerfTestSample::Release() std::lock_guard lock(mutex_); isStarted_ = false; - if (encInputThread_ && encInputThread_->joinable()) { - encInputThread_->join(); + if (inputThread_ && inputThread_->joinable()) { + inputThread_->join(); } - if (encOutputThread_ && encOutputThread_->joinable()) { - encOutputThread_->join(); + if (outputThread_ && outputThread_->joinable()) { + outputThread_->join(); } if (videoEncoder_ != nullptr) { videoEncoder_->Release(); } - encInputThread_.reset(); - encOutputThread_.reset(); + inputThread_.reset(); + outputThread_.reset(); videoEncoder_.reset(); if (sampleInfo_.window != nullptr) { OH_NativeWindow_DestroyNativeWindow(sampleInfo_.window); sampleInfo_.window = nullptr; } - if (encContext_ != nullptr) { - delete encContext_; - encContext_ = nullptr; + if (context_ != nullptr) { + delete context_; + context_ = nullptr; } if (inputFile_ != nullptr) { inputFile_.reset(); @@ -120,24 +121,24 @@ void VideoEncoderPerfTestSample::Release() doneCond_.notify_all(); } -void VideoEncoderPerfTestSample::encBufferInputThread() +void VideoEncoderPerfTestSample::BufferInputThread() { using namespace std::chrono_literals; auto lastPushTime = std::chrono::system_clock::now(); while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); - std::unique_lock lock(encContext_->inputMutex_); - bool condRet = encContext_->inputCond_.wait_for(lock, 5s, - [this]() { return !isStarted_ || !encContext_->inputBufferInfoQueue_.empty(); }); + std::unique_lock lock(context_->inputMutex_); + bool condRet = context_->inputCond_.wait_for(lock, 5s, + [this]() { return !isStarted_ || !context_->inputBufferInfoQueue_.empty(); }); CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); - CHECK_AND_CONTINUE_LOG(!encContext_->inputBufferInfoQueue_.empty(), + CHECK_AND_CONTINUE_LOG(!context_->inputBufferInfoQueue_.empty(), "Buffer queue is empty, continue, cond ret: %{public}d", condRet); - CodecBufferInfo bufferInfo = encContext_->inputBufferInfoQueue_.front(); - encContext_->inputBufferInfoQueue_.pop(); + CodecBufferInfo bufferInfo = context_->inputBufferInfoQueue_.front(); + context_->inputBufferInfoQueue_.pop(); lock.unlock(); - bufferInfo.attr.pts = encContext_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us + bufferInfo.attr.pts = context_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us int32_t ret = ReadOneFrame(bufferInfo); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); @@ -157,7 +158,7 @@ void VideoEncoderPerfTestSample::encBufferInputThread() StartRelease(); } -void VideoEncoderPerfTestSample::encSurfaceInputThread() +void VideoEncoderPerfTestSample::SurfaceInputThread() { using namespace std::chrono_literals; auto lastPushTime = std::chrono::system_clock::now(); @@ -187,11 +188,12 @@ void VideoEncoderPerfTestSample::encSurfaceInputThread() static_cast>(lastPushTime - beforeSleepTime).count()); } - encContext_->inputFrameCount_++; - uint64_t pts = encContext_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us + context_->inputFrameCount_++; + uint64_t pts = context_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us (void)NativeWindowHandleOpt(sampleInfo_.window, SET_UI_TIMESTAMP, pts); ret = OH_NativeBuffer_Unmap(nativeBuffer); CHECK_AND_BREAK_LOG(ret == 0, "Read frame failed, thread out"); + AddSurfaceInputTrace(flags, pts); ret = OH_NativeWindow_NativeWindowFlushBuffer(sampleInfo_.window, buffer, fenceFd, {nullptr, 0}); CHECK_AND_BREAK_LOG(ret == 0, "Read frame failed, thread out"); @@ -205,20 +207,20 @@ void VideoEncoderPerfTestSample::encSurfaceInputThread() StartRelease(); } -void VideoEncoderPerfTestSample::encOutputThread() +void VideoEncoderPerfTestSample::OutputThread() { using namespace std::chrono_literals; while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); - std::unique_lock lock(encContext_->outputMutex_); - bool condRet = encContext_->outputCond_.wait_for(lock, 5s, - [this]() { return !isStarted_ || !encContext_->outputBufferInfoQueue_.empty(); }); + std::unique_lock lock(context_->outputMutex_); + bool condRet = context_->outputCond_.wait_for(lock, 5s, + [this]() { return !isStarted_ || !context_->outputBufferInfoQueue_.empty(); }); CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); - CHECK_AND_CONTINUE_LOG(!encContext_->outputBufferInfoQueue_.empty(), + CHECK_AND_CONTINUE_LOG(!context_->outputBufferInfoQueue_.empty(), "Buffer queue is empty, continue, cond ret: %{public}d", condRet); - CodecBufferInfo bufferInfo = encContext_->outputBufferInfoQueue_.front(); - encContext_->outputBufferInfoQueue_.pop(); + CodecBufferInfo bufferInfo = context_->outputBufferInfoQueue_.front(); + context_->outputBufferInfoQueue_.pop(); lock.unlock(); CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Encoder output thread out"); @@ -226,7 +228,7 @@ void VideoEncoderPerfTestSample::encOutputThread() int32_t ret = videoEncoder_->FreeOutputData(bufferInfo.bufferIndex); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Encoder output thread out"); } - AVCODEC_LOGI("On encoder output thread exit, output frame count: %{public}d", encContext_->outputFrameCount_); + AVCODEC_LOGI("On encoder output thread exit, output frame count: %{public}d", context_->outputFrameCount_); StartRelease(); } @@ -253,4 +255,16 @@ int32_t VideoEncoderPerfTestSample::ReadOneFrame(uint8_t *bufferAddr, uint32_t & flags = inputFile_->eof() ? AVCODEC_BUFFER_FLAGS_EOS : AVCODEC_BUFFER_FLAGS_NONE; return AVCODEC_SAMPLE_ERR_OK; -} \ No newline at end of file +} + +void VideoEncoderPerfTestSample::AddSurfaceInputTrace(uint32_t flag, uint64_t pts) +{ + if (flag != AVCODEC_BUFFER_FLAGS_CODEC_DATA) { + if (isFirstFrameIn_) { + OHOS::MediaAVCodec::AVCodecTrace::TraceBegin("OH::FirstFrame", pts); + isFirstFrameIn_ = false; + } else { + OHOS::MediaAVCodec::AVCodecTrace::TraceBegin("OH::Frame", pts); + } + } +} -- Gitee From 4a7830ceb593b33e86f52f7be685ef69c2216f5b Mon Sep 17 00:00:00 2001 From: West Date: Tue, 12 Dec 2023 20:11:14 +0800 Subject: [PATCH 11/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Add=20perf=20test=20sample=20trace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I357ce3d695e04f2a17356c923d3338b4e6273362 --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 3 +++ .../sample/encoder/video_encoder_perf_test_sample.cpp | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index a86939544..7ea925c2f 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -20,6 +20,7 @@ #include "iconsumer_surface.h" #include "window.h" #include "refbase.h" +#include "avcodec_trace.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoDecoderSample"}; @@ -157,6 +158,7 @@ void VideoDecoderPerfTestSample::InputThread() { using namespace std::chrono_literals; auto lastPushTime = std::chrono::system_clock::now(); + OHOS::MediaAVCodec::AVCodecTrace::TraceBegin("SampleWorkTime", FAKE_POINTER(this)); while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); std::unique_lock lock(context_->inputMutex_); @@ -208,6 +210,7 @@ void VideoDecoderPerfTestSample::OutputThread() int32_t ret = videoDecoder_->FreeOutputData(bufferInfo.bufferIndex); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Decoder output thread out"); } + OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); AVCODEC_LOGI("On decoder output thread exit, output frame count: %{public}d", context_->outputFrameCount_); StartRelease(); } diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 0da3d7ca3..7862eef65 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -125,6 +125,7 @@ void VideoEncoderPerfTestSample::BufferInputThread() { using namespace std::chrono_literals; auto lastPushTime = std::chrono::system_clock::now(); + OHOS::MediaAVCodec::AVCodecTrace::TraceBegin("SampleWorkTime", FAKE_POINTER(this)); while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); std::unique_lock lock(context_->inputMutex_); @@ -163,9 +164,9 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() using namespace std::chrono_literals; auto lastPushTime = std::chrono::system_clock::now(); OHNativeWindowBuffer *buffer = nullptr; + OHOS::MediaAVCodec::AVCodecTrace::TraceBegin("SampleWorkTime", FAKE_POINTER(this)); while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); - int fenceFd = -1; int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(sampleInfo_.window, &buffer, &fenceFd); CHECK_AND_CONTINUE_LOG(ret == 0, "RequestBuffer failed, ret: %{public}d", ret); @@ -228,6 +229,7 @@ void VideoEncoderPerfTestSample::OutputThread() int32_t ret = videoEncoder_->FreeOutputData(bufferInfo.bufferIndex); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Encoder output thread out"); } + OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); AVCODEC_LOGI("On encoder output thread exit, output frame count: %{public}d", context_->outputFrameCount_); StartRelease(); } -- Gitee From 1c154780f88d661430e93acd53bfd11b931cced7 Mon Sep 17 00:00:00 2001 From: West Date: Tue, 12 Dec 2023 21:38:09 +0800 Subject: [PATCH 12/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E5=A4=8D=20buffer=20=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=20surface=20=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Ife71e155f6be87e2c1ed76ff98e1faf885f7dd7f --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 7ea925c2f..dcc2a0c25 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -70,8 +70,10 @@ int32_t VideoDecoderPerfTestSample::Create(SampleInfo sampleInfo) CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create video decoder failed"); context_ = new CodecUserData; - ret = CreateWindow(sampleInfo_.window); - CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create window failed"); + if (!(sampleInfo_.codecRunMode & 0b00)) { // 0b00: Buffer mode mask + ret = CreateWindow(sampleInfo_.window); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create window failed"); + } ret = videoDecoder_->Config(sampleInfo_, context_); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Decoder config failed"); -- Gitee From 5253e0a20bf3fde5b939395a9e604b425bfbfd33 Mon Sep 17 00:00:00 2001 From: West Date: Tue, 12 Dec 2023 21:53:42 +0800 Subject: [PATCH 13/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E5=A4=8D=20buffer=20=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=20surface=20=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I9835841732c0883328d9100826126030af3280ba --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index dcc2a0c25..7a769c52c 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -70,7 +70,7 @@ int32_t VideoDecoderPerfTestSample::Create(SampleInfo sampleInfo) CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create video decoder failed"); context_ = new CodecUserData; - if (!(sampleInfo_.codecRunMode & 0b00)) { // 0b00: Buffer mode mask + if (!(sampleInfo_.codecRunMode & 0b01)) { // 0b01: Buffer mode mask ret = CreateWindow(sampleInfo_.window); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create window failed"); } -- Gitee From ab85eaba0522fe7263041a77851d04af137193d4 Mon Sep 17 00:00:00 2001 From: West Date: Thu, 14 Dec 2023 15:15:59 +0800 Subject: [PATCH 14/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E5=A4=8D=20perf=20test=20pts=20?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I1f76255cb4c5bb6887d05e09466bd5c4a8e2fed9 --- test/unittest/video_perf_test/common/sample_callback.cpp | 4 ---- .../sample/decoder/video_decoder_perf_test_sample.cpp | 5 ++++- .../sample/encoder/video_encoder_perf_test_sample.cpp | 8 ++++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index 29478338e..aff9cc961 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -22,7 +22,6 @@ void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data return; } CodecUserData *codecUserData = static_cast(userData); - codecUserData->inputFrameCount_++; AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->inputFrameCount_); std::unique_lock lock(codecUserData->inputMutex_); @@ -37,7 +36,6 @@ void OnOutputBufferAvailable(OH_AVCodec * codec, uint32_t index, OH_AVMemory *da return; } CodecUserData *codecUserData = static_cast(userData); - codecUserData->outputFrameCount_++; AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->outputFrameCount_); std::unique_lock lock(codecUserData->outputMutex_); @@ -51,7 +49,6 @@ void onNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, v return; } CodecUserData *codecUserData = static_cast(userData); - codecUserData->inputFrameCount_++; AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->inputFrameCount_); std::unique_lock lock(codecUserData->inputMutex_); @@ -65,7 +62,6 @@ void onNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, v return; } CodecUserData *codecUserData = static_cast(userData); - codecUserData->outputFrameCount_++; AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->outputFrameCount_); std::unique_lock lock(codecUserData->outputMutex_); diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 7a769c52c..8a57a093c 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -172,6 +172,7 @@ void VideoDecoderPerfTestSample::InputThread() CodecBufferInfo bufferInfo = context_->inputBufferInfoQueue_.front(); context_->inputBufferInfoQueue_.pop(); + context_->inputFrameCount_++; lock.unlock(); int32_t ret = ReadOneFrame(bufferInfo); @@ -206,6 +207,7 @@ void VideoDecoderPerfTestSample::OutputThread() CodecBufferInfo bufferInfo = context_->outputBufferInfoQueue_.front(); context_->outputBufferInfoQueue_.pop(); + context_->outputFrameCount_++; lock.unlock(); CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); @@ -258,7 +260,8 @@ int32_t VideoDecoderPerfTestSample::ReadOneFrame(CodecBufferInfo &info) info.attr.flags = AVCODEC_BUFFER_FLAGS_EOS; } info.attr.size = bufferSize + AVCC_FRAME_HEAD_LEN; - info.attr.pts = context_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us + info.attr.pts = context_->inputFrameCount_ * + ((sampleInfo_.frameInterval == 0) ? 1 : sampleInfo_.frameInterval) * 1000; // 1000: 1ms to us return AVCODEC_SAMPLE_ERR_OK; } diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 7862eef65..8ddd11ae2 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -137,9 +137,11 @@ void VideoEncoderPerfTestSample::BufferInputThread() CodecBufferInfo bufferInfo = context_->inputBufferInfoQueue_.front(); context_->inputBufferInfoQueue_.pop(); + context_->inputFrameCount_++; lock.unlock(); - bufferInfo.attr.pts = context_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us + bufferInfo.attr.pts = context_->inputFrameCount_ * + ((sampleInfo_.frameInterval == 0) ? 1 : sampleInfo_.frameInterval) * 1000; // 1000: 1ms to us int32_t ret = ReadOneFrame(bufferInfo); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); @@ -190,7 +192,8 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() } context_->inputFrameCount_++; - uint64_t pts = context_->inputFrameCount_ * sampleInfo_.frameInterval * 1000; // 1000: 1ms to us + uint64_t pts = context_->inputFrameCount_ * + ((sampleInfo_.frameInterval == 0) ? 1 : sampleInfo_.frameInterval) * 1000; // 1000: 1ms to us (void)NativeWindowHandleOpt(sampleInfo_.window, SET_UI_TIMESTAMP, pts); ret = OH_NativeBuffer_Unmap(nativeBuffer); CHECK_AND_BREAK_LOG(ret == 0, "Read frame failed, thread out"); @@ -222,6 +225,7 @@ void VideoEncoderPerfTestSample::OutputThread() CodecBufferInfo bufferInfo = context_->outputBufferInfoQueue_.front(); context_->outputBufferInfoQueue_.pop(); + context_->outputFrameCount_++; lock.unlock(); CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Encoder output thread out"); -- Gitee From 6625d839616525d6ca65b50690e8bae7c892b70f Mon Sep 17 00:00:00 2001 From: West Date: Fri, 15 Dec 2023 09:40:32 +0800 Subject: [PATCH 15/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91add=20perf=20test=20trace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Iab3eab327fc02f63bc6312ed05077be4be849dbe --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 1 + .../sample/encoder/video_encoder_perf_test_sample.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 8a57a093c..7532194b9 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -215,6 +215,7 @@ void VideoDecoderPerfTestSample::OutputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Decoder output thread out"); } OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); + OHOS::MediaAVCodec::AVCodecTrace::CounterTrace("SampleFrameCount", context_->outputFrameCount_); AVCODEC_LOGI("On decoder output thread exit, output frame count: %{public}d", context_->outputFrameCount_); StartRelease(); } diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 8ddd11ae2..9234caaa9 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -234,6 +234,7 @@ void VideoEncoderPerfTestSample::OutputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Encoder output thread out"); } OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); + OHOS::MediaAVCodec::AVCodecTrace::CounterTrace("SampleFrameCount", context_->outputFrameCount_); AVCODEC_LOGI("On encoder output thread exit, output frame count: %{public}d", context_->outputFrameCount_); StartRelease(); } -- Gitee From e6562f30ad4392c105d07c9f6d68f32ea7011de1 Mon Sep 17 00:00:00 2001 From: West Date: Sat, 16 Dec 2023 10:52:53 +0800 Subject: [PATCH 16/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=20perf=20test=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BA=BF=E7=A8=8B=E9=80=80=E5=87=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I57575379bb7bab908349f57d3e9f0d414a5b17b2 --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 2 +- .../sample/encoder/video_encoder_perf_test_sample.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 7532194b9..95a25a88a 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -126,13 +126,13 @@ void VideoDecoderPerfTestSample::StartRelease() void VideoDecoderPerfTestSample::Release() { std::lock_guard lock(mutex_); - isStarted_ = false; if (inputThread_ && inputThread_->joinable()) { inputThread_->join(); } if (outputThread_ && outputThread_->joinable()) { outputThread_->join(); } + isStarted_ = false; if (videoDecoder_ != nullptr) { videoDecoder_->Release(); } diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 9234caaa9..681abba72 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -90,14 +90,13 @@ void VideoEncoderPerfTestSample::StartRelease() void VideoEncoderPerfTestSample::Release() { std::lock_guard lock(mutex_); - isStarted_ = false; - if (inputThread_ && inputThread_->joinable()) { inputThread_->join(); } if (outputThread_ && outputThread_->joinable()) { outputThread_->join(); } + isStarted_ = false; if (videoEncoder_ != nullptr) { videoEncoder_->Release(); } -- Gitee From fd28aa97acde41e585ef85aecc076db00ab1fbb1 Mon Sep 17 00:00:00 2001 From: West Date: Sat, 16 Dec 2023 16:24:37 +0800 Subject: [PATCH 17/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=20perf=20test=20AVBuffer?= =?UTF-8?q?=20mode=20=E6=8E=A5=E6=94=B6=E4=B8=8D=E5=88=B0=20EOS=20?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I6983591a52f5fb148aaaf84c0d02a511f943fbc9 --- .../common/include/sample_info.h | 6 +- .../common/sample_callback.cpp | 15 ++++ .../sample/base/video_perf_test_sample_base.h | 15 ++++ .../include/video_decoder_perf_test_sample.h | 15 ++++ .../video_decoder_perf_test_sample.cpp | 4 +- .../include/video_encoder_perf_test_sample.h | 15 ++++ .../video_encoder_perf_test_sample.cpp | 21 ++++- .../test_suilt/video_perf_test_suilt.cpp | 88 +++++++++++-------- 8 files changed, 137 insertions(+), 42 deletions(-) diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h index a9e08fb08..0a5723dee 100644 --- a/test/unittest/video_perf_test/common/include/sample_info.h +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -78,7 +78,11 @@ struct CodecBufferInfo { CodecBufferInfo(uint32_t argBufferIndex, OH_AVMemory *argBuffer): bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) {}; CodecBufferInfo(uint32_t argBufferIndex, OH_AVBuffer *argBuffer): - bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) {}; + bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) + { + auto bufferAttr = OH_AVBuffer_GetBufferAttr(argBuffer); + attr = {bufferAttr.pts, bufferAttr.size, bufferAttr.offset, bufferAttr.flags}; + }; }; class CodecUserData { diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index aff9cc961..9ac5d8712 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -1,3 +1,18 @@ +/* + * 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. + */ + #include "sample_callback.h" #include "av_codec_sample_log.h" diff --git a/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h b/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h index dc2c40a21..ca8b02856 100644 --- a/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h +++ b/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h @@ -1,3 +1,18 @@ +/* + * 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 AVCODEC_TEST_VIDEO_PERF_TEST_SAMPLE_BASE_H #define AVCODEC_TEST_VIDEO_PERF_TEST_SAMPLE_BASE_H diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index 194c17df3..063ee9a88 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -1,3 +1,18 @@ +/* + * 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 AVCODEC_TEST_VIDEO_PERF_TEST_DECODER_SAMPLE_H #define AVCODEC_TEST_VIDEO_PERF_TEST_DECODER_SAMPLE_H diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 95a25a88a..bf0dfc8d1 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -188,7 +188,7 @@ void VideoDecoderPerfTestSample::InputThread() ret = videoDecoder_->PushInputData(bufferInfo); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); - CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); + CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); } StartRelease(); } @@ -210,7 +210,7 @@ void VideoDecoderPerfTestSample::OutputThread() context_->outputFrameCount_++; lock.unlock(); - CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); + CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); int32_t ret = videoDecoder_->FreeOutputData(bufferInfo.bufferIndex); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Decoder output thread out"); } diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h index efb9a6bc4..26ef58bb9 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h @@ -1,3 +1,18 @@ +/* + * 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 AVCODEC_TEST_VIDEO_PERF_TEST_ENCODER_SAMPLE_H #define AVCODEC_TEST_VIDEO_PERF_TEST_ENCODER_SAMPLE_H diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 681abba72..f0ed6f049 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -1,3 +1,18 @@ +/* + * 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. + */ + #include "video_encoder_perf_test_sample.h" #include #include @@ -155,7 +170,7 @@ void VideoEncoderPerfTestSample::BufferInputThread() ret = videoEncoder_->PushInputData(bufferInfo); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); - CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); + CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); } StartRelease(); } @@ -180,7 +195,7 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() uint32_t flags = AVCODEC_BUFFER_FLAGS_NONE; ret = ReadOneFrame(bufferAddr, flags); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); - CHECK_AND_BREAK_LOG(flags != AVCODEC_BUFFER_FLAGS_EOS, "Catch EOS, thread out"); + CHECK_AND_BREAK_LOG(!(flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); if (sampleInfo_.testMode == TestMode::FRAME_DELAY) { auto beforeSleepTime = std::chrono::system_clock::now(); @@ -227,7 +242,7 @@ void VideoEncoderPerfTestSample::OutputThread() context_->outputFrameCount_++; lock.unlock(); - CHECK_AND_BREAK_LOG(bufferInfo.attr.flags != AVCODEC_BUFFER_FLAGS_EOS, "Encoder output thread out"); + CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); int32_t ret = videoEncoder_->FreeOutputData(bufferInfo.bufferIndex); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Encoder output thread out"); diff --git a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp index 0ede8967a..5188c0c99 100644 --- a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp +++ b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp @@ -1,3 +1,18 @@ +/* + * 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. + */ + #include #include #include "gtest/gtest.h" @@ -12,6 +27,7 @@ using namespace testing::ext; constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoPerfTestSuilt"}; constexpr int32_t FRAME_INTERVAL_33MS = 33; // 33ms +constexpr int32_t FRAME_INTERVAL_50MS = 50; // 50ms constexpr std::string_view FILE_AVC_1280_720_30_10M = "/data/test/media/1280_720_10M_30.h264"; constexpr std::string_view FILE_AVC_1280_720_60_10M = "/data/test/media/1280_720_10M_60.h264"; @@ -224,53 +240,53 @@ ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, ADD_CASE(VIDEO_DECODER, FRAME_RATE, SURFACE_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) ADD_CASE(VIDEO_DECODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1280, 720, 60, 10, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 30, 20, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 1920, 1080, 60, 20, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 30, 30, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, AVC, 3840, 2160, 60, 30, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 30, 10, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1280, 720, 60, 10, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 30, 20, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 1920, 1080, 60, 20, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, 30, FRAME_INTERVAL_50MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) -ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_33MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_50MS) +ADD_CASE(VIDEO_ENCODER, FRAME_DELAY, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, FRAME_INTERVAL_50MS) ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, 0) ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, 0) -- Gitee From f4d1499f9cab6e9cdb41cadae2b593b2fd1f3783 Mon Sep 17 00:00:00 2001 From: West Date: Tue, 19 Dec 2023 16:58:57 +0800 Subject: [PATCH 18/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E7=BC=96=E7=A0=81=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=20pts=E3=80=81=E6=A1=86=E6=9E=B6=20trace=20=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I3b121ae45f5a0213651b00f8be2106ddb33acd9b --- .../native/capi/avcodec/native_video_decoder.cpp | 4 ++-- .../native/capi/avcodec/native_video_encoder.cpp | 4 ++-- .../sample/encoder/video_encoder_perf_test_sample.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frameworks/native/capi/avcodec/native_video_decoder.cpp b/frameworks/native/capi/avcodec/native_video_decoder.cpp index 5a9942305..bef8cca1a 100644 --- a/frameworks/native/capi/avcodec/native_video_decoder.cpp +++ b/frameworks/native/capi/avcodec/native_video_decoder.cpp @@ -133,7 +133,7 @@ public: data = GetTransData(codec_, index, buffer); } - if (flag != AVCODEC_BUFFER_FLAG_CODEC_DATA) { + if (!((flag & AVCODEC_BUFFER_FLAG_CODEC_DATA) || (flag & AVCODEC_BUFFER_FLAG_EOS))) { if (videoDecObj->isFirstFrameOut_) { AVCodecTrace::TraceEnd("OH::FirstFrame", info.presentationTimeUs); videoDecObj->isFirstFrameOut_ = false; @@ -252,7 +252,7 @@ public: OH_AVBuffer *data = nullptr; data = GetTransData(codec_, index, buffer); - if (buffer->flag_ != AVCODEC_BUFFER_FLAG_CODEC_DATA) { + if (!((buffer->flag_ & AVCODEC_BUFFER_FLAG_CODEC_DATA) || (buffer->flag_ & AVCODEC_BUFFER_FLAG_EOS))) { if (videoDecObj->isFirstFrameOut_) { AVCodecTrace::TraceEnd("OH::FirstFrame", buffer->pts_); videoDecObj->isFirstFrameOut_ = false; diff --git a/frameworks/native/capi/avcodec/native_video_encoder.cpp b/frameworks/native/capi/avcodec/native_video_encoder.cpp index 97a075988..f10a517a9 100644 --- a/frameworks/native/capi/avcodec/native_video_encoder.cpp +++ b/frameworks/native/capi/avcodec/native_video_encoder.cpp @@ -134,7 +134,7 @@ public: // The bufferInfo lifecycle is controlled by the current function stack OH_AVMemory *data = GetTransData(codec_, index, buffer); - if (flag != AVCODEC_BUFFER_FLAG_CODEC_DATA) { + if (!((flag & AVCODEC_BUFFER_FLAG_CODEC_DATA) || (flag & AVCODEC_BUFFER_FLAG_EOS))) { if (videoEncObj->isFirstFrameOut_) { AVCodecTrace::TraceEnd("OH::FirstFrame", info.presentationTimeUs); videoEncObj->isFirstFrameOut_ = false; @@ -254,7 +254,7 @@ public: OH_AVBuffer *data = nullptr; data = GetTransData(codec_, index, buffer); - if (buffer->flag_ != AVCODEC_BUFFER_FLAG_CODEC_DATA) { + if (!((buffer->flag_ & AVCODEC_BUFFER_FLAG_CODEC_DATA) || (buffer->flag_ & AVCODEC_BUFFER_FLAG_EOS))) { if (videoEncObj->isFirstFrameOut_) { AVCodecTrace::TraceEnd("OH::FirstFrame", buffer->pts_); videoEncObj->isFirstFrameOut_ = false; diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index f0ed6f049..38d8d267b 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -180,9 +180,14 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() using namespace std::chrono_literals; auto lastPushTime = std::chrono::system_clock::now(); OHNativeWindowBuffer *buffer = nullptr; + (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo_.window, SET_USAGE, 16425); // 16425: Window usage OHOS::MediaAVCodec::AVCodecTrace::TraceBegin("SampleWorkTime", FAKE_POINTER(this)); while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); + context_->inputFrameCount_++; + uint64_t pts = context_->inputFrameCount_ * + ((sampleInfo_.frameInterval == 0) ? 1 : sampleInfo_.frameInterval) * 1000; // 1000: 1ms to us + (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo_.window, SET_UI_TIMESTAMP, pts); int fenceFd = -1; int32_t ret = OH_NativeWindow_NativeWindowRequestBuffer(sampleInfo_.window, &buffer, &fenceFd); CHECK_AND_CONTINUE_LOG(ret == 0, "RequestBuffer failed, ret: %{public}d", ret); @@ -204,11 +209,6 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() AVCODEC_LOGV("Sleep time: %{public}2.2fms", static_cast>(lastPushTime - beforeSleepTime).count()); } - - context_->inputFrameCount_++; - uint64_t pts = context_->inputFrameCount_ * - ((sampleInfo_.frameInterval == 0) ? 1 : sampleInfo_.frameInterval) * 1000; // 1000: 1ms to us - (void)NativeWindowHandleOpt(sampleInfo_.window, SET_UI_TIMESTAMP, pts); ret = OH_NativeBuffer_Unmap(nativeBuffer); CHECK_AND_BREAK_LOG(ret == 0, "Read frame failed, thread out"); AddSurfaceInputTrace(flags, pts); -- Gitee From 0e0ddc563f922c587cea124945dd0a47d373923a Mon Sep 17 00:00:00 2001 From: West Date: Wed, 20 Dec 2023 11:34:18 +0800 Subject: [PATCH 19/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West --- .../common/include/sample_callback.h | 2 +- .../video_perf_test/common/include/sample_info.h | 12 ++++++------ .../video_perf_test/common/sample_callback.cpp | 2 +- .../sample/decoder/video_decoder.cpp | 3 +-- .../decoder/video_decoder_perf_test_sample.cpp | 16 ++++++++++------ .../sample/encoder/video_encoder.cpp | 3 +-- .../encoder/video_encoder_perf_test_sample.cpp | 4 ++-- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/test/unittest/video_perf_test/common/include/sample_callback.h b/test/unittest/video_perf_test/common/include/sample_callback.h index ed9ae8f6c..47c49dbba 100644 --- a/test/unittest/video_perf_test/common/include/sample_callback.h +++ b/test/unittest/video_perf_test/common/include/sample_callback.h @@ -21,7 +21,7 @@ void OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *userData); void OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, void *userData); void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData); -void OnOutputBufferAvailable(OH_AVCodec * codec, uint32_t index, OH_AVMemory *data, +void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr, void *userData); void onNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData); void onNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData); diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h index 0a5723dee..4e31f279f 100644 --- a/test/unittest/video_perf_test/common/include/sample_info.h +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -73,12 +73,12 @@ struct CodecBufferInfo { uintptr_t *buffer = nullptr; OH_AVCodecBufferAttr attr = {0, 0, 0, AVCODEC_BUFFER_FLAGS_NONE}; - CodecBufferInfo(uint32_t argBufferIndex, OH_AVMemory *argBuffer, OH_AVCodecBufferAttr argAttr): - bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)), attr(argAttr) {}; - CodecBufferInfo(uint32_t argBufferIndex, OH_AVMemory *argBuffer): - bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) {}; - CodecBufferInfo(uint32_t argBufferIndex, OH_AVBuffer *argBuffer): - bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) + CodecBufferInfo(uint32_t argBufferIndex, OH_AVMemory *argBuffer, OH_AVCodecBufferAttr argAttr) + : bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)), attr(argAttr) {}; + CodecBufferInfo(uint32_t argBufferIndex, OH_AVMemory *argBuffer) + : bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) {}; + CodecBufferInfo(uint32_t argBufferIndex, OH_AVBuffer *argBuffer) + : bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) { auto bufferAttr = OH_AVBuffer_GetBufferAttr(argBuffer); attr = {bufferAttr.pts, bufferAttr.size, bufferAttr.offset, bufferAttr.flags}; diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index 9ac5d8712..c177732f5 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -44,7 +44,7 @@ void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data codecUserData->inputCond_.notify_all(); } -void OnOutputBufferAvailable(OH_AVCodec * codec, uint32_t index, OH_AVMemory *data, +void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr, void *userData) { if (userData == nullptr) { diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp index 1e6418643..b5bcc1892 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp @@ -61,8 +61,7 @@ int32_t VideoDecoder::Config(const SampleInfo &sampleInfo, CodecUserData *codecU } // SetSurface from video decoder - if (sampleInfo.window != nullptr) - { + if (sampleInfo.window != nullptr) { int ret = OH_VideoDecoder_SetSurface(decoder_, sampleInfo.window); CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK && sampleInfo.window, AVCODEC_SAMPLE_ERR_ERROR, "Set surface failed, ret: %{public}d", ret); diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index bf0dfc8d1..0d8245bcf 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -46,7 +46,7 @@ private: OHOS::sptr cs {nullptr}; }; -VideoDecoderPerfTestSample::~VideoDecoderPerfTestSample() +VideoDecoderPerfTestSample::~VideoDecoderPerfTestSample() { StartRelease(); if (releaseThread_ && releaseThread_->joinable()) { @@ -54,7 +54,7 @@ VideoDecoderPerfTestSample::~VideoDecoderPerfTestSample() } } -int32_t VideoDecoderPerfTestSample::Create(SampleInfo sampleInfo) +int32_t VideoDecoderPerfTestSample::Create(SampleInfo sampleInfo) { std::lock_guard lock(mutex_); CHECK_AND_RETURN_RET_LOG(!isStarted_, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); @@ -225,12 +225,16 @@ bool VideoDecoderPerfTestSample::IsCodecData(const uint8_t *const bufferAddr) bool isH264Stream = sampleInfo_.codecMime == MIME_VIDEO_AVC; // 0x1F: avc nulu type mask; 0x7E: hevc nalu type mask - uint8_t NaluType = isH264Stream ? + uint8_t naluType = isH264Stream ? (bufferAddr[AVCC_FRAME_HEAD_LEN] & 0x1F) : ((bufferAddr[AVCC_FRAME_HEAD_LEN] & 0x7E) >> 1); - // 7: avc nalu sps; 8: avc nalue pps; 32: hevc nalu vps; 33: hevc nalu sps; 34: hevc nalu pps - if ((isH264Stream && ((NaluType == 7) || (NaluType == 8))) || - (!isH264Stream && ((NaluType == 32) || (NaluType == 33) || (NaluType == 34)))) { + constexpr uint8_t AVC_SPS = 7; + constexpr uint8_t AVC_PPS = 8; + constexpr uint8_t HEVC_VPS = 32; + constexpr uint8_t HEVC_SPS = 33; + constexpr uint8_t HEVC_PPS = 34; + if ((isH264Stream && ((naluType == AVC_SPS) || (naluType == AVC_PPS))) || + (!isH264Stream && ((naluType == HEVC_VPS) || (naluType == HEVC_SPS) || (naluType == HEVC_PPS)))) { return true; } return false; diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp index e44b58002..455a2f8dc 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp @@ -67,8 +67,7 @@ int32_t VideoEncoder::Config(SampleInfo &sampleInfo, CodecUserData *codecUserDat } // GetSurface from video encoder - if (!(static_cast(sampleInfo.codecRunMode) & 0b01)) // 0b01: Buffer mode mask - { + if (!(static_cast(sampleInfo.codecRunMode) & 0b01)) { // 0b01: Buffer mode mask int ret = OH_VideoEncoder_GetSurface(encoder_, &sampleInfo.window); CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK && sampleInfo.window, AVCODEC_SAMPLE_ERR_ERROR, "Get surface failed, ret: %{public}d", ret); diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 38d8d267b..0c03ccac1 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -27,7 +27,7 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoEncoderSample"}; } -VideoEncoderPerfTestSample::~VideoEncoderPerfTestSample() +VideoEncoderPerfTestSample::~VideoEncoderPerfTestSample() { StartRelease(); if (releaseThread_ && releaseThread_->joinable()) { @@ -35,7 +35,7 @@ VideoEncoderPerfTestSample::~VideoEncoderPerfTestSample() } } -int32_t VideoEncoderPerfTestSample::Create(SampleInfo sampleInfo) +int32_t VideoEncoderPerfTestSample::Create(SampleInfo sampleInfo) { std::lock_guard lock(mutex_); CHECK_AND_RETURN_RET_LOG(!isStarted_, AVCODEC_SAMPLE_ERR_ERROR, "Already started."); -- Gitee From 5e728cd2057208df1084635ee7615b075be55b09 Mon Sep 17 00:00:00 2001 From: West Date: Wed, 20 Dec 2023 11:51:05 +0800 Subject: [PATCH 20/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West --- .../sample/base/video_perf_test_sample_base.h | 6 +++--- .../video_perf_test/sample/decoder/include/video_decoder.h | 6 +++--- .../sample/decoder/include/video_decoder_perf_test_sample.h | 6 +++--- .../video_perf_test/sample/encoder/include/video_encoder.h | 6 +++--- .../sample/encoder/include/video_encoder_perf_test_sample.h | 6 +++--- .../video_perf_test/test_suilt/video_perf_test_suilt.cpp | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h b/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h index ca8b02856..b920df051 100644 --- a/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h +++ b/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef AVCODEC_TEST_VIDEO_PERF_TEST_SAMPLE_BASE_H -#define AVCODEC_TEST_VIDEO_PERF_TEST_SAMPLE_BASE_H +#ifndef AVCODEC_SAMPLE_VIDEO_PERF_TEST_SAMPLE_BASE_H +#define AVCODEC_SAMPLE_VIDEO_PERF_TEST_SAMPLE_BASE_H #include "sample_info.h" @@ -26,4 +26,4 @@ public: virtual int32_t Start() = 0; virtual int32_t WaitForDone() = 0; }; -#endif // AVCODEC_TEST_VIDEO_PERF_TEST_SAMPLE_BASE_H \ No newline at end of file +#endif // AVCODEC_SAMPLE_VIDEO_PERF_TEST_SAMPLE_BASE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h index 7c3c0fdf4..46b61f7da 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef VIDEODECODER_H -#define VIDEODECODER_H +#ifndef AVCODEC_SAMPLE_VIDEO_DECODER_H +#define AVCODEC_SAMPLE_VIDEO_DECODER_H #include "native_avcodec_videodecoder.h" #include "sample_info.h" @@ -38,4 +38,4 @@ private: OH_AVCodec *decoder_; bool isAVBufferMode_; }; -#endif //VIDEODECODER_H \ No newline at end of file +#endif // AVCODEC_SAMPLE_VIDEO_DECODER_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index 063ee9a88..024121a95 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef AVCODEC_TEST_VIDEO_PERF_TEST_DECODER_SAMPLE_H -#define AVCODEC_TEST_VIDEO_PERF_TEST_DECODER_SAMPLE_H +#ifndef AVCODEC_SAMPLE_VIDEO_PERF_TEST_DECODER_SAMPLE_H +#define AVCODEC_SAMPLE_VIDEO_PERF_TEST_DECODER_SAMPLE_H #include #include @@ -58,4 +58,4 @@ private: OHOS::sptr surface_; }; -#endif // AVCODEC_TEST_VIDEO_PERF_TEST_DECODER_SAMPLE_H \ No newline at end of file +#endif // AVCODEC_SAMPLE_VIDEO_PERF_TEST_DECODER_SAMPLE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h index 47d6c8f5c..121a2c996 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef AV_CODEC_DEMO_VIDEOENCODER_H -#define AV_CODEC_DEMO_VIDEOENCODER_H +#ifndef AVCODEC_SAMPLE_VIDEO_ENCODER_H +#define AVCODEC_SAMPLE_VIDEO_ENCODER_H #include "native_avcodec_videoencoder.h" #include "sample_info.h" @@ -39,4 +39,4 @@ private: OH_AVCodec *encoder_ = nullptr; bool isAVBufferMode_; }; -#endif // AV_CODEC_DEMO_VIDEOENCODER_H \ No newline at end of file +#endif // AVCODEC_SAMPLE_VIDEO_ENCODER_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h index 26ef58bb9..151d762d9 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef AVCODEC_TEST_VIDEO_PERF_TEST_ENCODER_SAMPLE_H -#define AVCODEC_TEST_VIDEO_PERF_TEST_ENCODER_SAMPLE_H +#ifndef AVCODEC_SAMPLE_VIDEO_PERF_TEST_ENCODER_SAMPLE_H +#define AVCODEC_SAMPLE_VIDEO_PERF_TEST_ENCODER_SAMPLE_H #include #include @@ -57,4 +57,4 @@ private: bool isFirstFrameIn_ = true; }; -#endif // AVCODEC_TEST_VIDEO_PERF_TEST_ENCODER_SAMPLE_H \ No newline at end of file +#endif // AVCODEC_SAMPLE_VIDEO_PERF_TEST_ENCODER_SAMPLE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp index 5188c0c99..5cf8debc1 100644 --- a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp +++ b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp @@ -46,7 +46,6 @@ constexpr std::string_view FILE_HEVC_3840_2160_60_30M = "/data/test/media/3840_2 constexpr std::string_view FILE_1280_720 = "/data/test/media/1280_720_nv.yuv"; constexpr std::string_view FILE_1920_1080 = "/data/test/media/1920_1080_nv.yuv"; constexpr std::string_view FILE_3840_2160 = "/data/test/media/3840_2160_nv.yuv"; -} // namespace class VideoPerfTestSuilt : public testing::Test { public: @@ -334,4 +333,5 @@ ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, 0) ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, 0) -ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) \ No newline at end of file +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) +} // namespace \ No newline at end of file -- Gitee From 61693ba04fcf805d271cf1a5249573adc9c0199a Mon Sep 17 00:00:00 2001 From: West Date: Wed, 20 Dec 2023 11:55:13 +0800 Subject: [PATCH 21/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West --- test/unittest/video_perf_test/common/sample_callback.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index c177732f5..6b07f2998 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -19,7 +19,6 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SampleCallback"}; constexpr int LIMIT_LOGD_FREQUENCY = 50; -} void OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *userData) { @@ -82,4 +81,5 @@ void onNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, v std::unique_lock lock(codecUserData->outputMutex_); codecUserData->outputBufferInfoQueue_.emplace(index, buffer); codecUserData->outputCond_.notify_all(); +} } \ No newline at end of file -- Gitee From 62bd162ed475127b477c8c878ca3c2dff3783539 Mon Sep 17 00:00:00 2001 From: West Date: Wed, 20 Dec 2023 11:59:22 +0800 Subject: [PATCH 22/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West --- test/unittest/video_perf_test/common/av_codec_sample_log.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unittest/video_perf_test/common/av_codec_sample_log.cpp b/test/unittest/video_perf_test/common/av_codec_sample_log.cpp index 9f7fa46f9..b2d49836e 100644 --- a/test/unittest/video_perf_test/common/av_codec_sample_log.cpp +++ b/test/unittest/video_perf_test/common/av_codec_sample_log.cpp @@ -16,4 +16,6 @@ #include "av_codec_sample_log.h" #include "syspara/parameters.h" +namespace { const bool VERBOSE_LOG = OHOS::system::GetBoolParameter("OHOS.Media.AVCodecSample.VerboseLog", false); +} -- Gitee From db2f8f3c34b88763b7eafec3c176bdae29e5a593 Mon Sep 17 00:00:00 2001 From: West Date: Fri, 22 Dec 2023 01:33:26 +0000 Subject: [PATCH 23/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Iee6f21495458b7008b19cb38e75193dbbbb9425a --- .../common/av_codec_sample_log.cpp | 8 +++-- .../common/include/av_codec_sample_error.h | 8 +++-- .../common/include/av_codec_sample_log.h | 11 +++++-- .../common/include/sample_callback.h | 25 +++++++++------ .../common/include/sample_info.h | 15 ++++++--- .../common/sample_callback.cpp | 20 +++++++----- .../sample/base/video_perf_test_sample_base.h | 6 ++++ .../sample/decoder/include/video_decoder.h | 8 ++++- .../include/video_decoder_perf_test_sample.h | 7 ++++- .../sample/decoder/video_decoder.cpp | 19 ++++++++---- .../video_decoder_perf_test_sample.cpp | 6 ++++ .../sample/encoder/include/video_encoder.h | 8 ++++- .../include/video_encoder_perf_test_sample.h | 7 ++++- .../sample/encoder/video_encoder.cpp | 17 +++++++--- .../video_encoder_perf_test_sample.cpp | 6 ++++ .../test_suilt/video_perf_test_suilt.cpp | 31 ++++++++++--------- 16 files changed, 144 insertions(+), 58 deletions(-) diff --git a/test/unittest/video_perf_test/common/av_codec_sample_log.cpp b/test/unittest/video_perf_test/common/av_codec_sample_log.cpp index b2d49836e..aeff6c7ec 100644 --- a/test/unittest/video_perf_test/common/av_codec_sample_log.cpp +++ b/test/unittest/video_perf_test/common/av_codec_sample_log.cpp @@ -16,6 +16,10 @@ #include "av_codec_sample_log.h" #include "syspara/parameters.h" -namespace { +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { const bool VERBOSE_LOG = OHOS::system::GetBoolParameter("OHOS.Media.AVCodecSample.VerboseLog", false); -} +} // Sample +} // MediaAVCodec +} // OHOS diff --git a/test/unittest/video_perf_test/common/include/av_codec_sample_error.h b/test/unittest/video_perf_test/common/include/av_codec_sample_error.h index c9136caa3..1a5ffbde6 100644 --- a/test/unittest/video_perf_test/common/include/av_codec_sample_error.h +++ b/test/unittest/video_perf_test/common/include/av_codec_sample_error.h @@ -15,10 +15,14 @@ #ifndef AVCODEC_SAMPLE_ERROE_H #define AVCODEC_SAMPLE_ERROE_H - +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { enum AVCodecSampleError : int { AVCODEC_SAMPLE_ERR_OK = 0, AVCODEC_SAMPLE_ERR_ERROR = -1, }; - +} // Sample +} // MediaAVCodec +} // OHOS #endif // AVCODEC_SAMPLE_ERROE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/include/av_codec_sample_log.h b/test/unittest/video_perf_test/common/include/av_codec_sample_log.h index d15f637bf..dca40e522 100644 --- a/test/unittest/video_perf_test/common/include/av_codec_sample_log.h +++ b/test/unittest/video_perf_test/common/include/av_codec_sample_log.h @@ -13,11 +13,14 @@ * limitations under the License. */ -#ifndef AVCODEC_TEST_LOG_H -#define AVCODEC_TEST_LOG_H +#ifndef AVCODEC_SAMPLE_LOG_H +#define AVCODEC_SAMPLE_LOG_H #include "avcodec_log.h" +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { #undef LOG_DOMAIN #define LOG_DOMAIN 0xD002B66 @@ -27,5 +30,7 @@ extern const bool VERBOSE_LOG; if (VERBOSE_LOG) { \ AVCODEC_LOGI(fmt, ##__VA_ARGS__); \ } - +} // Sample +} // MediaAVCodec +} // OHOS #endif // AVCODEC_SAMPLE_LOG_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/include/sample_callback.h b/test/unittest/video_perf_test/common/include/sample_callback.h index 47c49dbba..3c31d0075 100644 --- a/test/unittest/video_perf_test/common/include/sample_callback.h +++ b/test/unittest/video_perf_test/common/include/sample_callback.h @@ -17,13 +17,20 @@ #define AVCODEC_SAMPLE_SAMPLE_CALLBACK_H #include "sample_info.h" - -void OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *userData); -void OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, void *userData); -void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData); -void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, - OH_AVCodecBufferAttr *attr, void *userData); -void onNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData); -void onNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData); - +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { +class SampleCallback { +public: + static void OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *userData); + static void OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, void *userData); + static void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData); + static void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, + OH_AVCodecBufferAttr *attr, void *userData); + static void OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData); + static void OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData); +}; +} // Sample +} // MediaAVCodec +} // OHOS #endif // AVCODEC_SAMPLE_SAMPLE_CALLBACK_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h index 4e31f279f..39e21793a 100644 --- a/test/unittest/video_perf_test/common/include/sample_info.h +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -22,6 +22,9 @@ #include "native_avcodec_base.h" #include "native_avbuffer.h" +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { constexpr std::string_view MIME_VIDEO_AVC = "video/avc"; constexpr std::string_view MIME_VIDEO_HEVC = "video/hevc"; @@ -55,8 +58,8 @@ enum CodecRunMode { struct SampleInfo { CodecType codecType; - std::string_view inputFilePath; - std::string_view codecMime; + std::string inputFilePath; + std::string codecMime; int32_t videoWidth = 0; int32_t videoHeight = 0; double frameRate = 0.0; @@ -66,6 +69,7 @@ struct SampleInfo { TestMode testMode; int32_t frameInterval = 0; NativeWindow* window = nullptr; + uint32_t repeatTime = 0; }; struct CodecBufferInfo { @@ -80,8 +84,7 @@ struct CodecBufferInfo { CodecBufferInfo(uint32_t argBufferIndex, OH_AVBuffer *argBuffer) : bufferIndex(argBufferIndex), buffer(reinterpret_cast(argBuffer)) { - auto bufferAttr = OH_AVBuffer_GetBufferAttr(argBuffer); - attr = {bufferAttr.pts, bufferAttr.size, bufferAttr.offset, bufferAttr.flags}; + OH_AVBuffer_GetBufferAttr(argBuffer, &attr); }; }; @@ -97,5 +100,7 @@ public: std::condition_variable outputCond_; std::queue outputBufferInfoQueue_; }; - +} // Sample +} // MediaAVCodec +} // OHOS #endif // AVCODEC_SAMPLE_SAMPLE_INFO_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index 6b07f2998..3e70d2a8e 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -19,18 +19,22 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SampleCallback"}; constexpr int LIMIT_LOGD_FREQUENCY = 50; +} -void OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *userData) +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { +void SampleCallback::OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *userData) { AVCODEC_LOGE("On decoder error, error code: %{public}d", errorCode); } -void OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, void *userData) +void SampleCallback::OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, void *userData) { AVCODEC_LOGW("On decoder format change"); } -void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData) +void SampleCallback::OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData) { if (userData == nullptr) { return; @@ -43,7 +47,7 @@ void OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data codecUserData->inputCond_.notify_all(); } -void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, +void SampleCallback::OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr, void *userData) { if (userData == nullptr) { @@ -57,7 +61,7 @@ void OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *dat codecUserData->outputCond_.notify_all(); } -void onNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) +void SampleCallback::OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) { if (userData == nullptr) { return; @@ -70,7 +74,7 @@ void onNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, v codecUserData->inputCond_.notify_all(); } -void onNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) +void SampleCallback::OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData) { if (userData == nullptr) { return; @@ -82,4 +86,6 @@ void onNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, v codecUserData->outputBufferInfoQueue_.emplace(index, buffer); codecUserData->outputCond_.notify_all(); } -} \ No newline at end of file +} // Sample +} // MediaAVCodec +} // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h b/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h index b920df051..3319e8677 100644 --- a/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h +++ b/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h @@ -18,6 +18,9 @@ #include "sample_info.h" +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { class VideoPerfTestSampleBase { public: virtual ~VideoPerfTestSampleBase() {}; @@ -26,4 +29,7 @@ public: virtual int32_t Start() = 0; virtual int32_t WaitForDone() = 0; }; +} // Sample +} // MediaAVCodec +} // OHOS #endif // AVCODEC_SAMPLE_VIDEO_PERF_TEST_SAMPLE_BASE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h index 46b61f7da..ea170933f 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h @@ -19,12 +19,15 @@ #include "native_avcodec_videodecoder.h" #include "sample_info.h" +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { class VideoDecoder { public: VideoDecoder() = default; ~VideoDecoder(); - int32_t Create(const std::string_view &codecMime); + int32_t Create(const std::string &codecMime); int32_t Config(const SampleInfo &sampleInfo, CodecUserData *codecUserData); int32_t Start(); int32_t PushInputData(CodecBufferInfo &info); @@ -38,4 +41,7 @@ private: OH_AVCodec *decoder_; bool isAVBufferMode_; }; +} // Sample +} // MediaAVCodec +} // OHOS #endif // AVCODEC_SAMPLE_VIDEO_DECODER_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index 024121a95..29f893dac 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -26,6 +26,9 @@ #include "video_decoder.h" #include "surface.h" +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { class VideoDecoderPerfTestSample : public VideoPerfTestSampleBase { public: VideoDecoderPerfTestSample() {}; @@ -57,5 +60,7 @@ private: CodecUserData *context_ = nullptr; OHOS::sptr surface_; }; - +} // Sample +} // MediaAVCodec +} // OHOS #endif // AVCODEC_SAMPLE_VIDEO_PERF_TEST_DECODER_SAMPLE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp index b5bcc1892..0773aa409 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp @@ -22,14 +22,17 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoDecoder"}; } // namespace +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { VideoDecoder::~VideoDecoder() { Release(); } -int32_t VideoDecoder::Create(const std::string_view &codecMime) +int32_t VideoDecoder::Create(const std::string &codecMime) { - decoder_ = OH_VideoDecoder_CreateByMime(codecMime.data()); + decoder_ = OH_VideoDecoder_CreateByMime(codecMime.c_str()); CHECK_AND_RETURN_RET_LOG(decoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Create failed"); return AVCODEC_SAMPLE_ERR_OK; } @@ -98,8 +101,7 @@ int32_t VideoDecoder::PushInputData(CodecBufferInfo &info) int32_t ret = AV_ERR_OK; if (isAVBufferMode_) { - ret = OH_AVBuffer_SetBufferAttr( - reinterpret_cast(info.buffer), reinterpret_cast(&info.attr)); + ret = OH_AVBuffer_SetBufferAttr(reinterpret_cast(info.buffer),&info.attr); CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Set avbuffer attr failed"); ret = OH_VideoDecoder_PushInputBuffer(decoder_, info.bufferIndex); } else { @@ -149,12 +151,17 @@ int32_t VideoDecoder::SetCallback(CodecUserData *codecUserData) int32_t ret = AV_ERR_OK; if (isAVBufferMode_) { ret = OH_VideoDecoder_RegisterCallback(decoder_, - {OnCodecError, OnCodecFormatChange, onNeedInputBuffer, onNewOutputBuffer}, codecUserData); + {SampleCallback::OnCodecError, SampleCallback::OnCodecFormatChange, + SampleCallback::OnNeedInputBuffer, SampleCallback::OnNewOutputBuffer}, codecUserData); } else { ret = OH_VideoDecoder_SetCallback(decoder_, - {OnCodecError, OnCodecFormatChange, OnInputBufferAvailable, OnOutputBufferAvailable}, codecUserData); + {SampleCallback::OnCodecError, SampleCallback::OnCodecFormatChange, + SampleCallback::OnInputBufferAvailable, SampleCallback::OnOutputBufferAvailable}, codecUserData); } CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Set callback failed, ret: %{public}d", ret); return AVCODEC_SAMPLE_ERR_OK; } +} // Sample +} // MediaAVCodec +} // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 0d8245bcf..f79809285 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -27,6 +27,9 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoDecod constexpr uint8_t AVCC_FRAME_HEAD_LEN = 4; } +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { class SurfaceConsumer : public OHOS::IBufferConsumerListener { public: SurfaceConsumer(OHOS::sptr cs, std::string_view name) : cs(cs) {}; @@ -283,3 +286,6 @@ int32_t VideoDecoderPerfTestSample::CreateWindow(OHNativeWindow *&window) return AVCODEC_SAMPLE_ERR_OK; } +} // Sample +} // MediaAVCodec +} // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h index 121a2c996..6c3c98a51 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h @@ -19,12 +19,15 @@ #include "native_avcodec_videoencoder.h" #include "sample_info.h" +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { class VideoEncoder { public: VideoEncoder() = default; ~VideoEncoder(); - int32_t Create(const std::string_view &codecMime); + int32_t Create(const std::string &codecMime); int32_t Config(SampleInfo &sampleInfo, CodecUserData *codecUserData); int32_t Start(); int32_t PushInputData(CodecBufferInfo &info); @@ -39,4 +42,7 @@ private: OH_AVCodec *encoder_ = nullptr; bool isAVBufferMode_; }; +} // Sample +} // MediaAVCodec +} // OHOS #endif // AVCODEC_SAMPLE_VIDEO_ENCODER_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h index 151d762d9..72879d20c 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h @@ -24,6 +24,9 @@ #include "video_perf_test_sample_base.h" #include "video_encoder.h" +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { class VideoEncoderPerfTestSample : public VideoPerfTestSampleBase { public: VideoEncoderPerfTestSample() {}; @@ -56,5 +59,7 @@ private: CodecUserData *context_ = nullptr; bool isFirstFrameIn_ = true; }; - +} // Sample +} // MediaAVCodec +} // OHOS #endif // AVCODEC_SAMPLE_VIDEO_PERF_TEST_ENCODER_SAMPLE_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp index 455a2f8dc..0765b8e1e 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp @@ -24,12 +24,15 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoEncoder"}; } // namespace +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { VideoEncoder::~VideoEncoder() { Release(); } -int32_t VideoEncoder::Create(const std::string_view &codecMime) +int32_t VideoEncoder::Create(const std::string &codecMime) { encoder_ = OH_VideoEncoder_CreateByMime(codecMime.data()); CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Create failed"); @@ -107,8 +110,7 @@ int32_t VideoEncoder::PushInputData(CodecBufferInfo &info) int32_t ret = AV_ERR_OK; if (isAVBufferMode_) { - ret = OH_AVBuffer_SetBufferAttr( - reinterpret_cast(info.buffer), reinterpret_cast(&info.attr)); + ret = OH_AVBuffer_SetBufferAttr(reinterpret_cast(info.buffer), &info.attr); CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Set avbuffer attr failed"); ret = OH_VideoEncoder_PushInputBuffer(encoder_, info.bufferIndex); } else { @@ -159,10 +161,12 @@ int32_t VideoEncoder::SetCallback(CodecUserData *codecUserData) int32_t ret = AV_ERR_OK; if (isAVBufferMode_) { ret = OH_VideoEncoder_RegisterCallback(encoder_, - {OnCodecError, OnCodecFormatChange, onNeedInputBuffer, onNewOutputBuffer}, codecUserData); + {SampleCallback::OnCodecError, SampleCallback::OnCodecFormatChange, + SampleCallback::OnNeedInputBuffer, SampleCallback::OnNewOutputBuffer}, codecUserData); } else { ret = OH_VideoEncoder_SetCallback(encoder_, - {OnCodecError, OnCodecFormatChange, OnInputBufferAvailable, OnOutputBufferAvailable}, codecUserData); + {SampleCallback::OnCodecError, SampleCallback::OnCodecFormatChange, + SampleCallback::OnInputBufferAvailable, SampleCallback::OnOutputBufferAvailable}, codecUserData); } CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Set callback failed, ret: %{public}d", ret); @@ -178,3 +182,6 @@ int32_t VideoEncoder::NotifyEndOfStream() "Notify end of stream failed, ret: %{public}d", ret); return AVCODEC_SAMPLE_ERR_OK; } +} // Sample +} // MediaAVCodec +} // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 0c03ccac1..4ea8c9b28 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -27,6 +27,9 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoEncoderSample"}; } +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { VideoEncoderPerfTestSample::~VideoEncoderPerfTestSample() { StartRelease(); @@ -289,3 +292,6 @@ void VideoEncoderPerfTestSample::AddSurfaceInputTrace(uint32_t flag, uint64_t pt } } } +} // Sample +} // MediaAVCodec +} // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp index 5cf8debc1..701007598 100644 --- a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp +++ b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp @@ -46,6 +46,8 @@ constexpr std::string_view FILE_HEVC_3840_2160_60_30M = "/data/test/media/3840_2 constexpr std::string_view FILE_1280_720 = "/data/test/media/1280_720_nv.yuv"; constexpr std::string_view FILE_1920_1080 = "/data/test/media/1920_1080_nv.yuv"; constexpr std::string_view FILE_3840_2160 = "/data/test/media/3840_2160_nv.yuv"; +} // namespace +using namespace OHOS::MediaAVCodec::Sample; class VideoPerfTestSuilt : public testing::Test { public: @@ -83,26 +85,26 @@ public: * ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunTest(sampleInfo)); * } */ -#define ADD_CASE(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate, inteval) \ -HWTEST_F(VideoPerfTestSuilt, \ -GENERATE_CASE_NAME(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate), TestSize.Level1) \ -{ \ - std::string_view inputFileName = (codecType) == CodecType::VIDEO_DECODER ? \ - FILE_##mime##_##width##_##height##_##fps##_##bitrate##M : FILE_##width##_##height; \ - SampleInfo sampleInfo = { \ - codecType, inputFileName, \ - MIME_VIDEO_##mime, (width), (height), (fps), BITRATE_##bitrate##M, (codecRunMode), (testMode), (inteval) \ - }; \ - ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunTest(sampleInfo)); \ +#define ADD_CASE(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate, inteval) \ +HWTEST_F(VideoPerfTestSuilt, \ +GENERATE_CASE_NAME(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate), TestSize.Level1) \ +{ \ + std::string inputFileName = (codecType) == CodecType::VIDEO_DECODER ? \ + FILE_##mime##_##width##_##height##_##fps##_##bitrate##M.data() : FILE_##width##_##height.data(); \ + SampleInfo sampleInfo = { \ + codecType, inputFileName, \ + MIME_VIDEO_##mime.data(), (width), (height), (fps), BITRATE_##bitrate##M, (codecRunMode), (testMode), (inteval)\ + }; \ + ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunTest(sampleInfo)); \ } int32_t VideoPerfTestSuilt::RunTest(const SampleInfo &sampleInfo) { AVCODEC_LOGI("====== Video perf test config ======"); AVCODEC_LOGI("test mode: %{public}d, codec run mode: %{public}d", sampleInfo.testMode, sampleInfo.codecRunMode); - AVCODEC_LOGI("input file: %{public}s", sampleInfo.inputFilePath.data()); + AVCODEC_LOGI("input file: %{public}s", sampleInfo.inputFilePath.c_str()); AVCODEC_LOGI("mime: %{public}s, %{public}d*%{public}d, %{public}.1ffps, %{public}.2fMbps, interval: %{public}dms", - sampleInfo.codecMime.data(), sampleInfo.videoWidth, sampleInfo.videoHeight, sampleInfo.frameRate, + sampleInfo.codecMime.c_str(), sampleInfo.videoWidth, sampleInfo.videoHeight, sampleInfo.frameRate, static_cast(sampleInfo.bitrate) / 1024 / 1024, FRAME_INTERVAL_33MS); // 1024: precision AVCODEC_LOGI("====== Video perf test config ======"); @@ -333,5 +335,4 @@ ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, 0) ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, 0) -ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) -} // namespace \ No newline at end of file +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) \ No newline at end of file -- Gitee From 10dc0ffe626a9341f695457d86765ceb2a204f8f Mon Sep 17 00:00:00 2001 From: West Date: Fri, 22 Dec 2023 01:40:28 +0000 Subject: [PATCH 24/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=20perf=20test=20=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Ie9c8c0c41ab27d8fbc1b0ad57e039ab6fa61cc0b --- .../video_perf_test/test_suilt/video_perf_test_suilt.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp index 701007598..c357f08d0 100644 --- a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp +++ b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp @@ -76,10 +76,12 @@ public: * ADD_CASE(FRAME_DELAY, BUFFER_SHARED_MEMORY, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) * * To be: - * HWTEST_F(VideoDecoderPerfTestSuilt, FRAME_DELAY_BUFFER_SHARED_MEMORY_AVC_1280_720_30_10M, TestSize.Level1) + * HWTEST_F(VideoDecoderPerfTestSuilt, CASE_FRAME_DELAY_BUFFER_SHARED_MEMORY_AVC_1280_720_30_10M, TestSize.Level1) * { + * std::string inputFileName = (codecType) == CodecType::VIDEO_DECODER ? + * FILE_AVC_1280_720_30_10M.data() : FILE_1280_720.data(); * SampleInfo sampleInfo = { - * FILE_AVC_1280_720_30_10M, MIME_VIDEO_AVC, 1280, 720, 30, BITRATE_10M, + * inputFileName, MIME_VIDEO_AVC, 1280, 720, 30, BITRATE_10M, * CodecRunMode::BUFFER_SHARED_MEMORY, TestMode::FRAME_DELAY, FRAME_INTERVAL_33MS * }; * ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunTest(sampleInfo)); -- Gitee From ec11bc24665da02a592ef52d9d486e65fce1e67b Mon Sep 17 00:00:00 2001 From: West Date: Fri, 22 Dec 2023 07:08:08 +0000 Subject: [PATCH 25/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E6=B7=BB=E5=8A=A0=20video=5Fcodec=5Fdemo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Ia7fbb578f0f53784029eee23bf6d72f090d5a45f --- test/BUILD.gn | 1 + test/unittest/video_perf_test/BUILD.gn | 70 +++++++++++++++---- .../common/sample_callback.cpp | 10 +++ .../video_perf_test/demo/video_codec_demo.cpp | 27 +++++++ .../include/video_decoder_perf_test_sample.h | 2 - .../video_decoder_perf_test_sample.cpp | 9 +-- .../sample/helper/arg_parser.cpp | 28 ++++++++ .../sample/helper/include/arg_parser.h | 27 +++++++ .../sample/helper/include/sample_helper.h | 28 ++++++++ .../sample/helper/sample_helper.cpp | 62 ++++++++++++++++ .../test_suilt/video_perf_test_suilt.cpp | 41 ++--------- 11 files changed, 249 insertions(+), 56 deletions(-) create mode 100644 test/unittest/video_perf_test/demo/video_codec_demo.cpp create mode 100644 test/unittest/video_perf_test/sample/helper/arg_parser.cpp create mode 100644 test/unittest/video_perf_test/sample/helper/include/arg_parser.h create mode 100644 test/unittest/video_perf_test/sample/helper/include/sample_helper.h create mode 100644 test/unittest/video_perf_test/sample/helper/sample_helper.cpp diff --git a/test/BUILD.gn b/test/BUILD.gn index 655c838ab..b4ea5762b 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -19,6 +19,7 @@ group("av_codec_demo_test") { deps = [] if (av_codec_support_test) { deps += [ "nativedemo:av_codec_demo" ] + deps += [ "unittest/video_perf_test:video_codec_demo" ] } } diff --git a/test/unittest/video_perf_test/BUILD.gn b/test/unittest/video_perf_test/BUILD.gn index dfe696aaf..2df31b506 100644 --- a/test/unittest/video_perf_test/BUILD.gn +++ b/test/unittest/video_perf_test/BUILD.gn @@ -14,19 +14,7 @@ import("//build/test.gni") import("//foundation/multimedia/av_codec/config.gni") -ohos_unittest("video_perf_test") { - module_out_path = "av_codec/unittest/perf_test" - - include_dirs = [ - "./common/include", - "./sample/base", - "./sample/decoder/include", - "./sample/encoder/include", - "./test_suilt/include", - "$av_codec_root_dir/interfaces/kits/c", - "$av_codec_root_dir/services/dfx/include" - ] - +config("video_sample_config") { cflags = [ "-std=c++17", "-fno-rtti", @@ -49,6 +37,18 @@ ohos_unittest("video_perf_test") { "-Wunused-parameter", ] + include_dirs = [ + "./common/include", + "./sample/base", + "./sample/decoder/include", + "./sample/encoder/include", + "./sample/helper/include", + "$av_codec_root_dir/interfaces/kits/c", + "$av_codec_root_dir/services/dfx/include" + ] +} + +ohos_source_set("video_sample") { sources = [ "../../../services/dfx/avcodec_trace.cpp", "./common/sample_callback.cpp", @@ -57,12 +57,13 @@ ohos_unittest("video_perf_test") { "./sample/decoder/video_decoder.cpp", "./sample/encoder/video_encoder_perf_test_sample.cpp", "./sample/encoder/video_encoder.cpp", - "./test_suilt/video_perf_test_suilt.cpp", + "./sample/helper/arg_parser.cpp", + "./sample/helper/sample_helper.cpp", ] deps = [ "$av_codec_root_dir/interfaces/kits/c:capi_packages" ] - public_deps = [] + public_configs = [":video_sample_config"] external_deps = [ "c_utils:utils", @@ -72,4 +73,43 @@ ohos_unittest("video_perf_test") { "init:libbegetutil", "hitrace:hitrace_meter", ] + + subsystem_name = "multimedia" + part_name = "av_codec" +} + +ohos_unittest("video_perf_test") { + module_out_path = "av_codec/unittest/perf_test" + + sources = [ + "./test_suilt/video_perf_test_suilt.cpp", + ] + + deps = [ ":video_sample" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "histreamer:media_foundation", + ] + + subsystem_name = "multimedia" + part_name = "av_codec" +} + +ohos_executable("video_codec_demo") { + sources = [ + "./demo/video_codec_demo.cpp", + ] + + deps = [ ":video_sample" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "histreamer:media_foundation", + ] + + subsystem_name = "multimedia" + part_name = "av_codec" } \ No newline at end of file diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index 3e70d2a8e..7626fa3b2 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -26,11 +26,17 @@ namespace MediaAVCodec { namespace Sample { void SampleCallback::OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *userData) { + (void)codec; + (void)errorCode; + (void)userData; AVCODEC_LOGE("On decoder error, error code: %{public}d", errorCode); } void SampleCallback::OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, void *userData) { + (void)codec; + (void)format; + (void)userData; AVCODEC_LOGW("On decoder format change"); } @@ -39,6 +45,7 @@ void SampleCallback::OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, O if (userData == nullptr) { return; } + (void)codec; CodecUserData *codecUserData = static_cast(userData); AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->inputFrameCount_); @@ -53,6 +60,7 @@ void SampleCallback::OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, if (userData == nullptr) { return; } + (void)codec; CodecUserData *codecUserData = static_cast(userData); AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->outputFrameCount_); @@ -66,6 +74,7 @@ void SampleCallback::OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVB if (userData == nullptr) { return; } + (void)codec; CodecUserData *codecUserData = static_cast(userData); AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->inputFrameCount_); @@ -79,6 +88,7 @@ void SampleCallback::OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVB if (userData == nullptr) { return; } + (void)codec; CodecUserData *codecUserData = static_cast(userData); AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", codecUserData->outputFrameCount_); diff --git a/test/unittest/video_perf_test/demo/video_codec_demo.cpp b/test/unittest/video_perf_test/demo/video_codec_demo.cpp new file mode 100644 index 000000000..797eb9f7b --- /dev/null +++ b/test/unittest/video_perf_test/demo/video_codec_demo.cpp @@ -0,0 +1,27 @@ +/* + * 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. + */ + +#include "video_perf_test_sample_base.h" +#include "video_decoder_perf_test_sample.h" +#include "video_encoder_perf_test_sample.h" +#include "av_codec_sample_error.h" +#include "av_codec_sample_log.h" +#include "arg_parser.h" + +int main() +{ + + return 0; +} \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index 29f893dac..8722e3834 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -24,7 +24,6 @@ #include #include "video_perf_test_sample_base.h" #include "video_decoder.h" -#include "surface.h" namespace OHOS { namespace MediaAVCodec { @@ -58,7 +57,6 @@ private: std::condition_variable doneCond_; SampleInfo sampleInfo_; CodecUserData *context_ = nullptr; - OHOS::sptr surface_; }; } // Sample } // MediaAVCodec diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index f79809285..78da292b5 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -21,6 +21,7 @@ #include "window.h" #include "refbase.h" #include "avcodec_trace.h" +#include "surface.h" namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoDecoderSample"}; @@ -32,7 +33,7 @@ namespace MediaAVCodec { namespace Sample { class SurfaceConsumer : public OHOS::IBufferConsumerListener { public: - SurfaceConsumer(OHOS::sptr cs, std::string_view name) : cs(cs) {}; + SurfaceConsumer(OHOS::sptr cs) : cs(cs) {}; ~SurfaceConsumer() {} void OnBufferAvailable() override { @@ -277,11 +278,11 @@ int32_t VideoDecoderPerfTestSample::ReadOneFrame(CodecBufferInfo &info) int32_t VideoDecoderPerfTestSample::CreateWindow(OHNativeWindow *&window) { auto consumer_ = OHOS::Surface::CreateSurfaceAsConsumer(); - OHOS::sptr listener = new SurfaceConsumer(consumer_, ""); + OHOS::sptr listener = new SurfaceConsumer(consumer_); consumer_->RegisterConsumerListener(listener); auto producer = consumer_->GetProducer(); - surface_ = OHOS::Surface::CreateSurfaceAsProducer(producer); - window = CreateNativeWindowFromSurface(&surface_); + auto surface = OHOS::Surface::CreateSurfaceAsProducer(producer); + window = CreateNativeWindowFromSurface(&surface); CHECK_AND_RETURN_RET_LOG(window != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Create window failed!"); return AVCODEC_SAMPLE_ERR_OK; diff --git a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp new file mode 100644 index 000000000..2bacc436d --- /dev/null +++ b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp @@ -0,0 +1,28 @@ +/* + * 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. + */ + +#include "arg_parser.h" +#include "sample_info.h" + +namespace { + +} // namespace + +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { +} // Sample +} // MediaAVCodec +} // OHOS diff --git a/test/unittest/video_perf_test/sample/helper/include/arg_parser.h b/test/unittest/video_perf_test/sample/helper/include/arg_parser.h new file mode 100644 index 000000000..a78419149 --- /dev/null +++ b/test/unittest/video_perf_test/sample/helper/include/arg_parser.h @@ -0,0 +1,27 @@ +/* + * 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 AVCODEC_SAMPLE_ARG_PARSER_H +#define AVCODEC_SAMPLE_ARG_PARSER_H + +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { + +} // Sample +} // MediaAVCodec +} // OHOS + +#endif // AVCODEC_SAMPLE_ARG_PARSER_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/helper/include/sample_helper.h b/test/unittest/video_perf_test/sample/helper/include/sample_helper.h new file mode 100644 index 000000000..0a0b7a2f1 --- /dev/null +++ b/test/unittest/video_perf_test/sample/helper/include/sample_helper.h @@ -0,0 +1,28 @@ +/* + * 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 AVCODEC_SAMPLE_SAMPLE_HELPER_H +#define AVCODEC_SAMPLE_SAMPLE_HELPER_H + +#include "sample_info.h" + +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { +int32_t RunSample(const SampleInfo &sampleInfo); +} // Sample +} // MediaAVCodec +} // OHOS +#endif // AVCODEC_SAMPLE_SAMPLE_HELPER_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp new file mode 100644 index 000000000..54b740a5a --- /dev/null +++ b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp @@ -0,0 +1,62 @@ +/* + * 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. + */ + +#include "sample_helper.h" +#include +#include "video_perf_test_sample_base.h" +#include "video_decoder_perf_test_sample.h" +#include "video_encoder_perf_test_sample.h" +#include "av_codec_sample_log.h" +#include "av_codec_sample_error.h" + +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SampleHelper"}; + +const std::unordered_map RUN_MODE_TO_STRING = { + {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_AVBUFFER, "Buffer AVBuffer"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_SHARED_MEMORY, "Buffer SharedMemory"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::SURFACE_ORIGIN, "Surface Origin"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::SURFACE_AVBUFFER, "Surface AVBuffer"}, +}; +} + +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { +int32_t RunSample(const SampleInfo &sampleInfo) +{ + AVCODEC_LOGI("====== Video sample config ======"); + AVCODEC_LOGI("codec run mode: %{public}s", RUN_MODE_TO_STRING.at(sampleInfo.codecRunMode).c_str()); + AVCODEC_LOGI("input file: %{public}s", sampleInfo.inputFilePath.c_str()); + AVCODEC_LOGI("mime: %{public}s, %{public}d*%{public}d, %{public}.1ffps, %{public}.2fMbps, interval: %{public}dms", + sampleInfo.codecMime.c_str(), sampleInfo.videoWidth, sampleInfo.videoHeight, sampleInfo.frameRate, + static_cast(sampleInfo.bitrate) / 1024 / 1024, sampleInfo.frameInterval); // 1024: precision + AVCODEC_LOGI("====== Video sample config ======"); + + std::unique_ptr sample = sampleInfo.codecType == CodecType::VIDEO_DECODER ? + static_cast>(std::make_unique()) : + static_cast>(std::make_unique()); + + int32_t ret = sample->Create(sampleInfo); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Create failed"); + ret = sample->Start(); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Start failed"); + ret = sample->WaitForDone(); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Wait for done failed"); + return AVCODEC_SAMPLE_ERR_OK; +} +} // Sample +} // MediaAVCodec +} // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp index c357f08d0..22ebde167 100644 --- a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp +++ b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp @@ -14,17 +14,12 @@ */ #include -#include #include "gtest/gtest.h" -#include "video_perf_test_sample_base.h" -#include "video_decoder_perf_test_sample.h" -#include "video_encoder_perf_test_sample.h" #include "av_codec_sample_error.h" -#include "av_codec_sample_log.h" +#include "sample_helper.h" namespace { using namespace testing::ext; -constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoPerfTestSuilt"}; constexpr int32_t FRAME_INTERVAL_33MS = 33; // 33ms constexpr int32_t FRAME_INTERVAL_50MS = 50; // 50ms @@ -47,16 +42,14 @@ constexpr std::string_view FILE_1280_720 = "/data/test/media/1280_720_nv.yuv"; constexpr std::string_view FILE_1920_1080 = "/data/test/media/1920_1080_nv.yuv"; constexpr std::string_view FILE_3840_2160 = "/data/test/media/3840_2160_nv.yuv"; } // namespace -using namespace OHOS::MediaAVCodec::Sample; +namespace OHOS::MediaAVCodec::Sample { class VideoPerfTestSuilt : public testing::Test { public: static void SetUpTestCase(void) {}; static void TearDownTestCase(void) {}; void SetUp(void) {}; void TearDown(void) {}; - - int32_t RunTest(const SampleInfo &sampleInfo); }; /* Generate case name @@ -84,7 +77,7 @@ public: * inputFileName, MIME_VIDEO_AVC, 1280, 720, 30, BITRATE_10M, * CodecRunMode::BUFFER_SHARED_MEMORY, TestMode::FRAME_DELAY, FRAME_INTERVAL_33MS * }; - * ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunTest(sampleInfo)); + * ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunSample(sampleInfo)); * } */ #define ADD_CASE(codecType, testMode, codecRunMode, mime, width, height, fps, bitrate, inteval) \ @@ -97,30 +90,7 @@ GENERATE_CASE_NAME(codecType, testMode, codecRunMode, mime, width, height, fps, codecType, inputFileName, \ MIME_VIDEO_##mime.data(), (width), (height), (fps), BITRATE_##bitrate##M, (codecRunMode), (testMode), (inteval)\ }; \ - ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunTest(sampleInfo)); \ -} - -int32_t VideoPerfTestSuilt::RunTest(const SampleInfo &sampleInfo) -{ - AVCODEC_LOGI("====== Video perf test config ======"); - AVCODEC_LOGI("test mode: %{public}d, codec run mode: %{public}d", sampleInfo.testMode, sampleInfo.codecRunMode); - AVCODEC_LOGI("input file: %{public}s", sampleInfo.inputFilePath.c_str()); - AVCODEC_LOGI("mime: %{public}s, %{public}d*%{public}d, %{public}.1ffps, %{public}.2fMbps, interval: %{public}dms", - sampleInfo.codecMime.c_str(), sampleInfo.videoWidth, sampleInfo.videoHeight, sampleInfo.frameRate, - static_cast(sampleInfo.bitrate) / 1024 / 1024, FRAME_INTERVAL_33MS); // 1024: precision - AVCODEC_LOGI("====== Video perf test config ======"); - - std::unique_ptr sample = sampleInfo.codecType == CodecType::VIDEO_DECODER ? - static_cast>(std::make_unique()) : - static_cast>(std::make_unique()); - - int32_t ret = sample->Create(sampleInfo); - CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Create failed"); - ret = sample->Start(); - CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Start failed"); - ret = sample->WaitForDone(); - CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Wait for done failed"); - return AVCODEC_SAMPLE_ERR_OK; + ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunSample(sampleInfo)); \ } ADD_CASE(VIDEO_DECODER, FRAME_DELAY, SURFACE_ORIGIN, AVC, 1280, 720, 30, 10, FRAME_INTERVAL_33MS) @@ -337,4 +307,5 @@ ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 30, ADD_CASE(VIDEO_ENCODER, FRAME_RATE, SURFACE_ORIGIN, HEVC, 3840, 2160, 60, 30, 0) ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_SHARED_MEMORY, HEVC, 3840, 2160, 60, 30, 0) -ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) \ No newline at end of file +ADD_CASE(VIDEO_ENCODER, FRAME_RATE, BUFFER_AVBUFFER, HEVC, 3840, 2160, 60, 30, 0) +} // namespace OHOS::MediaAVCodec::Sample \ No newline at end of file -- Gitee From f821b2ffa18c90ac3fbafe22db8de3a59b9d0787 Mon Sep 17 00:00:00 2001 From: West Date: Sat, 23 Dec 2023 04:20:06 +0000 Subject: [PATCH 26/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E6=B7=BB=E5=8A=A0=20video=5Fcodec=5Fdemo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I2a52da86eef35165a48fb03ee992ee924caf9f32 --- .../common/include/sample_info.h | 12 +- .../video_perf_test/demo/video_codec_demo.cpp | 22 +++- .../sample/helper/arg_parser.cpp | 122 +++++++++++++++++- .../sample/helper/include/arg_parser.h | 4 +- .../sample/helper/include/sample_helper.h | 1 + .../sample/helper/sample_helper.cpp | 5 + 6 files changed, 153 insertions(+), 13 deletions(-) diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h index 39e21793a..2598ac6a8 100644 --- a/test/unittest/video_perf_test/common/include/sample_info.h +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -57,19 +57,21 @@ enum CodecRunMode { }; struct SampleInfo { - CodecType codecType; + CodecType codecType = VIDEO_DECODER; std::string inputFilePath; - std::string codecMime; + std::string codecMime = MIME_VIDEO_AVC.data(); int32_t videoWidth = 0; int32_t videoHeight = 0; double frameRate = 0.0; int64_t bitrate = 10 * 1024 * 1024; // 10Mbps; - CodecRunMode codecRunMode; - TestMode testMode; + CodecRunMode codecRunMode = SURFACE_ORIGIN; + TestMode testMode = FRAME_DELAY; int32_t frameInterval = 0; NativeWindow* window = nullptr; - uint32_t repeatTime = 0; + uint32_t repeatTimes = 0; + uint32_t pixelFormat = 2; + bool isHDRVivid = false; }; struct CodecBufferInfo { diff --git a/test/unittest/video_perf_test/demo/video_codec_demo.cpp b/test/unittest/video_perf_test/demo/video_codec_demo.cpp index 797eb9f7b..09e27527e 100644 --- a/test/unittest/video_perf_test/demo/video_codec_demo.cpp +++ b/test/unittest/video_perf_test/demo/video_codec_demo.cpp @@ -13,15 +13,25 @@ * limitations under the License. */ -#include "video_perf_test_sample_base.h" -#include "video_decoder_perf_test_sample.h" -#include "video_encoder_perf_test_sample.h" -#include "av_codec_sample_error.h" -#include "av_codec_sample_log.h" +#include #include "arg_parser.h" +#include "sample_helper.h" +#include "av_codec_sample_error.h" + +using namespace OHOS::MediaAVCodec::Sample; -int main() +int main(int argc, char *argv[]) { + auto info = ParseDemoArg(argc, argv); + if (!SampleInfoChecker()) { + std::cout << "Demo arg check failed, exit" << std::endl; + return 1; + } + int ret = RunSample(info); + if (ret != AVCODEC_SAMPLE_ERR_OK) { + std::cout << "Demo run failed!" << std::endl; + return 1; + } return 0; } \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp index 2bacc436d..cd99a657a 100644 --- a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp +++ b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp @@ -14,15 +14,135 @@ */ #include "arg_parser.h" -#include "sample_info.h" +#include +#include namespace { +enum DemoShortArgument : int { + DEMO_ARG_UNKNOW = 0, + DEMO_ARG_HELP, + DEMO_ARG_CODEC_TYPE, + DEMO_ARG_INPUT_FILE, + DEMO_ARG_CODEC_MIME, + DEMO_ARG_WIDTH, + DEMO_ARG_HEIGHT, + DEMO_ARG_FRAMERATE, + DEMO_ARG_PIXEL_FORMAT, + DEMO_ARG_BITRATE, + DEMO_ARG_BITRATE_MODE, + DEMO_ARG_CODEC_RUN_MODE, + DEMO_ARG_FRAME_INTERVAL, + DEMO_ARG_REPEAT_TIMES, + DEMO_ARG_HDR_VIVID_VIDEO, +}; + +constexpr struct option DEMO_LONG_ARGUMENT[] = { + {"help", no_argument, nullptr, DEMO_ARG_HELP}, + {"codec_type", required_argument, nullptr, DEMO_ARG_CODEC_TYPE}, + {"file", required_argument, nullptr, DEMO_ARG_INPUT_FILE}, + {"mime", required_argument, nullptr, DEMO_ARG_CODEC_MIME}, + {"width", required_argument, nullptr, DEMO_ARG_WIDTH}, + {"height", required_argument, nullptr, DEMO_ARG_HEIGHT}, + {"framerate", required_argument, nullptr, DEMO_ARG_FRAMERATE}, + {"pixel_format", required_argument, nullptr, DEMO_ARG_PIXEL_FORMAT}, + {"bitrate", required_argument, nullptr, DEMO_ARG_BITRATE}, + {"bitrate_mode", required_argument, nullptr, DEMO_ARG_BITRATE_MODE}, + {"codec_run_mode", required_argument, nullptr, DEMO_ARG_CODEC_RUN_MODE}, + {"frame_interval", required_argument, nullptr, DEMO_ARG_FRAME_INTERVAL}, + {"repeat_times", required_argument, nullptr, DEMO_ARG_REPEAT_TIMES}, + {"hdr_vivid_video", required_argument, nullptr, DEMO_ARG_HDR_VIVID_VIDEO}, +}; + +const std::string HELP_TEXT = +R"HELP_TEXT(Video codec demo help: + --help print this help info + + --codec_type codec type (0: decoder; 1: encoder) + --file input file path + --mime codec mime (H264: video/avc; H265: video/hevc) + --width video width + --height video height + --framerate video framerate + --pixel_format 0: YUV420P 1: YUVI420 2: NV12 + 3: NV21 4: SURFACE_FORMAT 5: RGBA + --bitrate encoder bitrate (bps) + --bitrate_mode encoder bitrate mode (0: CBR; 1: VBR; 2: CQ) + --codec_run_mode 0: Surface origin 1: Buffer SharedMemory + 2: Surface AVBuffer 3: Buffer AVBuffer + + --frame_interval frame push interval (ms) + --repeat_times demo repeat times + --hdr_vivid_video input file is hdr vivid video? (0: false; 1: true) +Example: + --codec_type 0 --file input.h264 -mime video/avc --width 1280 --height 720 --framerate 30 --pixel_format 1 + --codec_run_mode 0 --frame_interval 0 --repeat_times 1 --hdr_vivid_video 0 +)HELP_TEXT"; + +void ShowHelp() +{ + std::cout << HELP_TEXT << std::endl; +} } // namespace namespace OHOS { namespace MediaAVCodec { namespace Sample { +SampleInfo ParseDemoArg(int argc, char *argv[]) +{ + SampleInfo info; + int32_t argType = DEMO_ARG_UNKNOW; + while ((argType = getopt_long(argc, argv, "", DEMO_LONG_ARGUMENT, nullptr)) != -1) { + switch (argType) { + case DEMO_ARG_HELP: + ShowHelp(); + break; + case DEMO_ARG_CODEC_TYPE: + info.codecType = static_cast(std::stol(optarg)); + break; + case DEMO_ARG_INPUT_FILE: + info.inputFilePath = optarg; + break; + case DEMO_ARG_CODEC_MIME: + info.codecMime = optarg; + break; + case DEMO_ARG_WIDTH: + info.videoWidth = std::stol(optarg); + break; + case DEMO_ARG_HEIGHT: + info.videoHeight = std::stol(optarg); + break; + case DEMO_ARG_FRAMERATE: + info.frameRate = std::stof(optarg); + break; + case DEMO_ARG_PIXEL_FORMAT: + info.pixelFormat = std::stol(optarg); + break; + case DEMO_ARG_BITRATE: + info.bitrate = std::stoll(optarg); + break; + case DEMO_ARG_BITRATE_MODE: + info.bitrate = std::stol(optarg); + break; + case DEMO_ARG_CODEC_RUN_MODE: + info.codecRunMode = static_cast(std::stol(optarg)); + break; + case DEMO_ARG_FRAME_INTERVAL: + info.frameInterval = std::stol(optarg); + break; + case DEMO_ARG_REPEAT_TIMES: + info.repeatTimes = std::stol(optarg); + break; + case DEMO_ARG_HDR_VIVID_VIDEO: + info.isHDRVivid = std::stol(optarg); + break; + default: + std::cout << "Unknow arg type: " << argType << ", value: " << optarg << std::endl; + break; + } + } + return info; +} } // Sample } // MediaAVCodec } // OHOS diff --git a/test/unittest/video_perf_test/sample/helper/include/arg_parser.h b/test/unittest/video_perf_test/sample/helper/include/arg_parser.h index a78419149..12cd6633d 100644 --- a/test/unittest/video_perf_test/sample/helper/include/arg_parser.h +++ b/test/unittest/video_perf_test/sample/helper/include/arg_parser.h @@ -16,10 +16,12 @@ #ifndef AVCODEC_SAMPLE_ARG_PARSER_H #define AVCODEC_SAMPLE_ARG_PARSER_H +#include "sample_info.h" + namespace OHOS { namespace MediaAVCodec { namespace Sample { - +SampleInfo ParseDemoArg(int argc, char *argv[]); } // Sample } // MediaAVCodec } // OHOS diff --git a/test/unittest/video_perf_test/sample/helper/include/sample_helper.h b/test/unittest/video_perf_test/sample/helper/include/sample_helper.h index 0a0b7a2f1..ce5724c3d 100644 --- a/test/unittest/video_perf_test/sample/helper/include/sample_helper.h +++ b/test/unittest/video_perf_test/sample/helper/include/sample_helper.h @@ -21,6 +21,7 @@ namespace OHOS { namespace MediaAVCodec { namespace Sample { +bool SampleInfoChecker(); int32_t RunSample(const SampleInfo &sampleInfo); } // Sample } // MediaAVCodec diff --git a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp index 54b740a5a..d0df1bd2b 100644 --- a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp +++ b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp @@ -35,6 +35,11 @@ const std::unordered_map namespace OHOS { namespace MediaAVCodec { namespace Sample { +bool SampleInfoChecker() +{ + return true; +} + int32_t RunSample(const SampleInfo &sampleInfo) { AVCODEC_LOGI("====== Video sample config ======"); -- Gitee From 9c585bf6aceda8d5f6c27410f4171bed44aa060c Mon Sep 17 00:00:00 2001 From: West Date: Sat, 23 Dec 2023 09:43:50 +0000 Subject: [PATCH 27/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E6=B7=BB=E5=8A=A0=20video=5Fcodec=5Fdemo=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=8F=8A=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I5cfa5f79bd39e71af399e5ec7b380c0511832038 --- .../common/include/sample_info.h | 1 + .../include/video_decoder_perf_test_sample.h | 4 + .../sample/decoder/video_decoder.cpp | 6 +- .../video_decoder_perf_test_sample.cpp | 54 ++++++++-- .../sample/encoder/include/video_encoder.h | 1 + .../include/video_encoder_perf_test_sample.h | 3 + .../sample/encoder/video_encoder.cpp | 101 +++++++++++------- .../video_encoder_perf_test_sample.cpp | 71 ++++++++---- .../sample/helper/arg_parser.cpp | 42 ++++---- .../sample/helper/sample_helper.cpp | 49 ++++++--- 10 files changed, 222 insertions(+), 110 deletions(-) diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h index 2598ac6a8..1caba86b5 100644 --- a/test/unittest/video_perf_test/common/include/sample_info.h +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -72,6 +72,7 @@ struct SampleInfo { uint32_t repeatTimes = 0; uint32_t pixelFormat = 2; bool isHDRVivid = false; + bool needDumpOutput = false; }; struct CodecBufferInfo { diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index 8722e3834..b8c88e886 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -45,12 +45,16 @@ private: bool IsCodecData(const uint8_t *const bufferAddr); int32_t ReadOneFrame(CodecBufferInfo &info); int32_t CreateWindow(OHNativeWindow *&window); + void ThreadSleep(); + void DumpOutput(const CodecBufferInfo &bufferInfo); + std::unique_ptr videoDecoder_ = nullptr; std::unique_ptr inputThread_ = nullptr; std::unique_ptr outputThread_ = nullptr; std::unique_ptr releaseThread_ = nullptr; std::unique_ptr inputFile_ = nullptr; + std::unique_ptr outputFile_ = nullptr; std::mutex mutex_; std::atomic isStarted_ { false }; diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp index 0773aa409..0819d3bb3 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp @@ -51,12 +51,8 @@ int32_t VideoDecoder::Config(const SampleInfo &sampleInfo, CodecUserData *codecU OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, sampleInfo.pixelFormat); - AVCODEC_LOGI("====== VideoDecoder config ======"); - AVCODEC_LOGI("%{public}d*%{public}d, %{public}.1ffps", - sampleInfo.videoWidth, sampleInfo.videoHeight, sampleInfo.frameRate); - AVCODEC_LOGI("====== VideoDecoder config ======"); - int ret = OH_VideoDecoder_Configure(decoder_, format); CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Config failed, ret: %{public}d", ret); OH_AVFormat_Destroy(format); diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 78da292b5..8d35650f2 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -24,6 +24,8 @@ #include "surface.h" namespace { +using namespace std::chrono_literals; + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoDecoderSample"}; constexpr uint8_t AVCC_FRAME_HEAD_LEN = 4; } @@ -162,8 +164,6 @@ void VideoDecoderPerfTestSample::Release() void VideoDecoderPerfTestSample::InputThread() { - using namespace std::chrono_literals; - auto lastPushTime = std::chrono::system_clock::now(); OHOS::MediaAVCodec::AVCodecTrace::TraceBegin("SampleWorkTime", FAKE_POINTER(this)); while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); @@ -182,13 +182,7 @@ void VideoDecoderPerfTestSample::InputThread() int32_t ret = ReadOneFrame(bufferInfo); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); - if (sampleInfo_.testMode == TestMode::FRAME_DELAY) { - auto beforeSleepTime = std::chrono::system_clock::now(); - std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); - lastPushTime = std::chrono::system_clock::now(); - AVCODEC_LOGV("Sleep time: %{public}2.2fms", - static_cast>(lastPushTime - beforeSleepTime).count()); - } + ThreadSleep(); ret = videoDecoder_->PushInputData(bufferInfo); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); @@ -199,7 +193,6 @@ void VideoDecoderPerfTestSample::InputThread() void VideoDecoderPerfTestSample::OutputThread() { - using namespace std::chrono_literals; while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Decoder output thread out"); std::unique_lock lock(context_->outputMutex_); @@ -212,9 +205,11 @@ void VideoDecoderPerfTestSample::OutputThread() CodecBufferInfo bufferInfo = context_->outputBufferInfoQueue_.front(); context_->outputBufferInfoQueue_.pop(); context_->outputFrameCount_++; + CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); lock.unlock(); - CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); + DumpOutput(bufferInfo); + int32_t ret = videoDecoder_->FreeOutputData(bufferInfo.bufferIndex); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Decoder output thread out"); } @@ -287,6 +282,43 @@ int32_t VideoDecoderPerfTestSample::CreateWindow(OHNativeWindow *&window) return AVCODEC_SAMPLE_ERR_OK; } + +void VideoDecoderPerfTestSample::ThreadSleep() +{ + if (sampleInfo_.frameInterval <= 0) { + return; + } + + using namespace std::chrono_literals; + thread_local auto lastPushTime = std::chrono::system_clock::now(); + + auto beforeSleepTime = std::chrono::system_clock::now(); + std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); + lastPushTime = std::chrono::system_clock::now(); + AVCODEC_LOGV("Sleep time: %{public}2.2fms", + static_cast>(lastPushTime - beforeSleepTime).count()); +} + +inline void VideoDecoderPerfTestSample::DumpOutput(const CodecBufferInfo &bufferInfo) +{ + if (!sampleInfo_.needDumpOutput) { + return; + } + + using namespace std::string_literals; + if (outputFile_ == nullptr) { + auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + outputFile_ = std::make_unique("VideoDecoderOut_"s + std::to_string(time) + ".yuv", + std::ios::out | std::ios::trunc); + if (!outputFile_->is_open()) { + outputFile_ = nullptr; + } + } + auto bufferAddr = static_cast(sampleInfo_.codecRunMode) & 0b10 ? // 0b10: AVBuffer mode mask + OH_AVBuffer_GetAddr(reinterpret_cast(bufferInfo.buffer)) : + OH_AVMemory_GetAddr(reinterpret_cast(bufferInfo.buffer)); + outputFile_->write(reinterpret_cast(bufferAddr), bufferInfo.attr.size); +} } // Sample } // MediaAVCodec } // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h index 6c3c98a51..ffd182c24 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h @@ -38,6 +38,7 @@ public: private: int32_t SetCallback(CodecUserData *codecUserData); + int32_t Configure(const SampleInfo &sampleInfo); OH_AVCodec *encoder_ = nullptr; bool isAVBufferMode_; diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h index 72879d20c..01fb118c7 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h @@ -45,12 +45,15 @@ private: int32_t ReadOneFrame(CodecBufferInfo &info); int32_t ReadOneFrame(uint8_t *bufferAddr, uint32_t &flags); void AddSurfaceInputTrace(uint32_t flag, uint64_t pts); + void ThreadSleep(); + void DumpOutput(const CodecBufferInfo &bufferInfo); std::unique_ptr videoEncoder_ = nullptr; std::unique_ptr inputThread_ = nullptr; std::unique_ptr outputThread_ = nullptr; std::unique_ptr releaseThread_ = nullptr; std::unique_ptr inputFile_ = nullptr; + std::unique_ptr outputFile_ = nullptr; std::mutex mutex_; std::atomic isStarted_ { false }; diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp index 0765b8e1e..a531d61ab 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp @@ -14,6 +14,7 @@ */ #include "video_encoder.h" +#include #include "surface_type.h" #include "external_window.h" #include "av_codec_sample_error.h" @@ -22,11 +23,32 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoEncoder"}; + +const std::unordered_map AV_PIXEL_FORMAT_TO_GRAPHIC_PIXEL_FMT = { + {}, +}; } // namespace namespace OHOS { namespace MediaAVCodec { namespace Sample { +int32_t ToGraphicPixelFormat(int32_t avPixelFormat, bool isHDRVivid) +{ + if (isHDRVivid) { + return GRAPHIC_PIXEL_FMT_YCBCR_P010; + } + switch(avPixelFormat) { + case AV_PIXEL_FORMAT_RGBA: + return GRAPHIC_PIXEL_FMT_RGBA_8888; + case AV_PIXEL_FORMAT_YUVI420: + return GRAPHIC_PIXEL_FMT_RGBA_8888; + case AV_PIXEL_FORMAT_NV21: + return GRAPHIC_PIXEL_FMT_RGBA_8888; + default: // NV12 and others + return GRAPHIC_PIXEL_FMT_RGBA_8888; + } +} + VideoEncoder::~VideoEncoder() { Release(); @@ -46,51 +68,29 @@ int32_t VideoEncoder::Config(SampleInfo &sampleInfo, CodecUserData *codecUserDat isAVBufferMode_ = (static_cast(sampleInfo.codecRunMode) & 0b10); // ob10: AVBuffer mode mask // Configure video encoder - { - OH_AVFormat *format = OH_AVFormat_Create(); - CHECK_AND_RETURN_RET_LOG(format != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "AVFormat create failed"); - - OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); - OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); - OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); - OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CBR); - OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, sampleInfo.bitrate); - - AVCODEC_LOGI("====== VideoEncoder config ======"); - AVCODEC_LOGI("%{public}d*%{public}d, %{public}.1ffps", - sampleInfo.videoWidth, sampleInfo.videoHeight, sampleInfo.frameRate); - AVCODEC_LOGI("BitRate Mode: %{public}d, BitRate: %{public}" PRId64, CBR, sampleInfo.bitrate / 1024); - AVCODEC_LOGI("====== VideoEncoder config ======"); - - int ret = OH_VideoEncoder_Configure(encoder_, format); - CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, - "Config failed, ret: %{public}d", ret); - OH_AVFormat_Destroy(format); - format = nullptr; - } + int32_t ret = Configure(sampleInfo); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Configure failed"); // GetSurface from video encoder if (!(static_cast(sampleInfo.codecRunMode) & 0b01)) { // 0b01: Buffer mode mask - int ret = OH_VideoEncoder_GetSurface(encoder_, &sampleInfo.window); + ret = OH_VideoEncoder_GetSurface(encoder_, &sampleInfo.window); CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK && sampleInfo.window, AVCODEC_SAMPLE_ERR_ERROR, "Get surface failed, ret: %{public}d", ret); - ret = OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_FORMAT, OHOS::GRAPHIC_PIXEL_FMT_RGBA_8888); - ret = OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_BUFFER_GEOMETRY, + (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_BUFFER_GEOMETRY, sampleInfo.videoWidth, sampleInfo.videoHeight); + (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_USAGE, 16425); // 16425: Window usage + (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_FORMAT, + ToGraphicPixelFormat(sampleInfo.pixelFormat, sampleInfo.isHDRVivid)); } // SetCallback for video encoder - { - int32_t ret = SetCallback(codecUserData); - CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, - "Set callback failed, ret: %{public}d", ret); - } + ret = SetCallback(codecUserData); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, + "Set callback failed, ret: %{public}d", ret); // Prepare video encoder - { - int ret = OH_VideoEncoder_Prepare(encoder_); - CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Prepare failed, ret: %{public}d", ret); - } + ret = OH_VideoEncoder_Prepare(encoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Prepare failed, ret: %{public}d", ret); return AVCODEC_SAMPLE_ERR_OK; } @@ -120,6 +120,16 @@ int32_t VideoEncoder::PushInputData(CodecBufferInfo &info) return AVCODEC_SAMPLE_ERR_OK; } +int32_t VideoEncoder::NotifyEndOfStream() +{ + CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Encoder is null"); + + int32_t ret = OH_VideoEncoder_NotifyEndOfStream(encoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, + "Notify end of stream failed, ret: %{public}d", ret); + return AVCODEC_SAMPLE_ERR_OK; +} + int32_t VideoEncoder::FreeOutputData(uint32_t bufferIndex) { CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Encoder is null"); @@ -173,13 +183,26 @@ int32_t VideoEncoder::SetCallback(CodecUserData *codecUserData) return AVCODEC_SAMPLE_ERR_OK; } -int32_t VideoEncoder::NotifyEndOfStream() +int32_t VideoEncoder::Configure(const SampleInfo &sampleInfo) { - CHECK_AND_RETURN_RET_LOG(encoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Encoder is null"); + OH_AVFormat *format = OH_AVFormat_Create(); + CHECK_AND_RETURN_RET_LOG(format != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "AVFormat create failed"); + + OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); + OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CBR); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, sampleInfo.bitrate); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, sampleInfo.pixelFormat); + if (sampleInfo.isHDRVivid) { + OH_AVFormat_SetIntValue(format, OH_MD_KEY_PROFILE, HEVC_PROFILE_MAIN_10); + } + + int ret = OH_VideoEncoder_Configure(encoder_, format); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Config failed, ret: %{public}d", ret); - int32_t ret = OH_VideoEncoder_NotifyEndOfStream(encoder_); - CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, - "Notify end of stream failed, ret: %{public}d", ret); + OH_AVFormat_Destroy(format); + format = nullptr; return AVCODEC_SAMPLE_ERR_OK; } } // Sample diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 4ea8c9b28..f334bbc96 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -24,6 +24,9 @@ #include "avcodec_trace.h" namespace { +using namespace std::string_literals; +using namespace std::chrono_literals; + constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "VideoEncoderSample"}; } @@ -133,6 +136,9 @@ void VideoEncoderPerfTestSample::Release() if (inputFile_ != nullptr) { inputFile_.reset(); } + if (outputFile_ != nullptr) { + outputFile_.reset(); + } AVCODEC_LOGI("Succeed"); doneCond_.notify_all(); @@ -140,8 +146,6 @@ void VideoEncoderPerfTestSample::Release() void VideoEncoderPerfTestSample::BufferInputThread() { - using namespace std::chrono_literals; - auto lastPushTime = std::chrono::system_clock::now(); OHOS::MediaAVCodec::AVCodecTrace::TraceBegin("SampleWorkTime", FAKE_POINTER(this)); while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); @@ -163,13 +167,7 @@ void VideoEncoderPerfTestSample::BufferInputThread() int32_t ret = ReadOneFrame(bufferInfo); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); - if (sampleInfo_.testMode == TestMode::FRAME_DELAY) { - auto beforeSleepTime = std::chrono::system_clock::now(); - std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); - lastPushTime = std::chrono::system_clock::now(); - AVCODEC_LOGV("Sleep time: %{public}2.2fms", - static_cast>(lastPushTime - beforeSleepTime).count()); - } + ThreadSleep(); ret = videoEncoder_->PushInputData(bufferInfo); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); @@ -180,10 +178,7 @@ void VideoEncoderPerfTestSample::BufferInputThread() void VideoEncoderPerfTestSample::SurfaceInputThread() { - using namespace std::chrono_literals; - auto lastPushTime = std::chrono::system_clock::now(); OHNativeWindowBuffer *buffer = nullptr; - (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo_.window, SET_USAGE, 16425); // 16425: Window usage OHOS::MediaAVCodec::AVCodecTrace::TraceBegin("SampleWorkTime", FAKE_POINTER(this)); while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); @@ -204,18 +199,12 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() ret = ReadOneFrame(bufferAddr, flags); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); CHECK_AND_BREAK_LOG(!(flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); - - if (sampleInfo_.testMode == TestMode::FRAME_DELAY) { - auto beforeSleepTime = std::chrono::system_clock::now(); - std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); - lastPushTime = std::chrono::system_clock::now(); - AVCODEC_LOGV("Sleep time: %{public}2.2fms", - static_cast>(lastPushTime - beforeSleepTime).count()); - } ret = OH_NativeBuffer_Unmap(nativeBuffer); CHECK_AND_BREAK_LOG(ret == 0, "Read frame failed, thread out"); - AddSurfaceInputTrace(flags, pts); + ThreadSleep(); + + AddSurfaceInputTrace(flags, pts); ret = OH_NativeWindow_NativeWindowFlushBuffer(sampleInfo_.window, buffer, fenceFd, {nullptr, 0}); CHECK_AND_BREAK_LOG(ret == 0, "Read frame failed, thread out"); @@ -230,7 +219,6 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() void VideoEncoderPerfTestSample::OutputThread() { - using namespace std::chrono_literals; while (true) { CHECK_AND_BREAK_LOG(isStarted_, "Work done, thread out"); std::unique_lock lock(context_->outputMutex_); @@ -243,9 +231,10 @@ void VideoEncoderPerfTestSample::OutputThread() CodecBufferInfo bufferInfo = context_->outputBufferInfoQueue_.front(); context_->outputBufferInfoQueue_.pop(); context_->outputFrameCount_++; + CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); lock.unlock(); - CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); + DumpOutput(bufferInfo); int32_t ret = videoEncoder_->FreeOutputData(bufferInfo.bufferIndex); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Encoder output thread out"); @@ -292,6 +281,42 @@ void VideoEncoderPerfTestSample::AddSurfaceInputTrace(uint32_t flag, uint64_t pt } } } + +void VideoEncoderPerfTestSample::ThreadSleep() +{ + if (sampleInfo_.frameInterval <= 0) { + return; + } + + using namespace std::chrono_literals; + thread_local auto lastPushTime = std::chrono::system_clock::now(); + + auto beforeSleepTime = std::chrono::system_clock::now(); + std::this_thread::sleep_until(lastPushTime + std::chrono::milliseconds(sampleInfo_.frameInterval)); + lastPushTime = std::chrono::system_clock::now(); + AVCODEC_LOGV("Sleep time: %{public}2.2fms", + static_cast>(lastPushTime - beforeSleepTime).count()); +} + +inline void VideoEncoderPerfTestSample::DumpOutput(const CodecBufferInfo &bufferInfo) +{ + if (!sampleInfo_.needDumpOutput) { + return; + } + + if (outputFile_ == nullptr) { + auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + outputFile_ = std::make_unique("VideoEncoderOut_"s + std::to_string(time) + ".bin", + std::ios::out | std::ios::trunc); + if (!outputFile_->is_open()) { + outputFile_ = nullptr; + } + } + auto bufferAddr = static_cast(sampleInfo_.codecRunMode) & 0b10 ? // 0b10: AVBuffer mode mask + OH_AVBuffer_GetAddr(reinterpret_cast(bufferInfo.buffer)) : + OH_AVMemory_GetAddr(reinterpret_cast(bufferInfo.buffer)); + outputFile_->write(reinterpret_cast(bufferAddr), bufferInfo.attr.size); +} } // Sample } // MediaAVCodec } // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp index cd99a657a..3ef16fa93 100644 --- a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp +++ b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp @@ -34,23 +34,25 @@ enum DemoShortArgument : int { DEMO_ARG_FRAME_INTERVAL, DEMO_ARG_REPEAT_TIMES, DEMO_ARG_HDR_VIVID_VIDEO, + DEMO_ARG_NEED_DUMP_OUTPUT, }; constexpr struct option DEMO_LONG_ARGUMENT[] = { - {"help", no_argument, nullptr, DEMO_ARG_HELP}, - {"codec_type", required_argument, nullptr, DEMO_ARG_CODEC_TYPE}, - {"file", required_argument, nullptr, DEMO_ARG_INPUT_FILE}, - {"mime", required_argument, nullptr, DEMO_ARG_CODEC_MIME}, - {"width", required_argument, nullptr, DEMO_ARG_WIDTH}, - {"height", required_argument, nullptr, DEMO_ARG_HEIGHT}, - {"framerate", required_argument, nullptr, DEMO_ARG_FRAMERATE}, - {"pixel_format", required_argument, nullptr, DEMO_ARG_PIXEL_FORMAT}, - {"bitrate", required_argument, nullptr, DEMO_ARG_BITRATE}, - {"bitrate_mode", required_argument, nullptr, DEMO_ARG_BITRATE_MODE}, - {"codec_run_mode", required_argument, nullptr, DEMO_ARG_CODEC_RUN_MODE}, - {"frame_interval", required_argument, nullptr, DEMO_ARG_FRAME_INTERVAL}, - {"repeat_times", required_argument, nullptr, DEMO_ARG_REPEAT_TIMES}, - {"hdr_vivid_video", required_argument, nullptr, DEMO_ARG_HDR_VIVID_VIDEO}, + {"help", no_argument, nullptr, DEMO_ARG_HELP}, + {"codec_type", required_argument, nullptr, DEMO_ARG_CODEC_TYPE}, + {"file", required_argument, nullptr, DEMO_ARG_INPUT_FILE}, + {"mime", required_argument, nullptr, DEMO_ARG_CODEC_MIME}, + {"width", required_argument, nullptr, DEMO_ARG_WIDTH}, + {"height", required_argument, nullptr, DEMO_ARG_HEIGHT}, + {"framerate", required_argument, nullptr, DEMO_ARG_FRAMERATE}, + {"pixel_format", required_argument, nullptr, DEMO_ARG_PIXEL_FORMAT}, + {"bitrate", required_argument, nullptr, DEMO_ARG_BITRATE}, + {"bitrate_mode", required_argument, nullptr, DEMO_ARG_BITRATE_MODE}, + {"codec_run_mode", required_argument, nullptr, DEMO_ARG_CODEC_RUN_MODE}, + {"frame_interval", required_argument, nullptr, DEMO_ARG_FRAME_INTERVAL}, + {"repeat_times", required_argument, nullptr, DEMO_ARG_REPEAT_TIMES}, + {"hdr_vivid_video", required_argument, nullptr, DEMO_ARG_HDR_VIVID_VIDEO}, + {"need_dump_output", required_argument, nullptr, DEMO_ARG_NEED_DUMP_OUTPUT}, }; const std::string HELP_TEXT = @@ -63,8 +65,8 @@ R"HELP_TEXT(Video codec demo help: --width video width --height video height --framerate video framerate - --pixel_format 0: YUV420P 1: YUVI420 2: NV12 - 3: NV21 4: SURFACE_FORMAT 5: RGBA + --pixel_format 1: YUVI420 2: NV12 3: NV21 + 4: SURFACE_FORMAT 5: RGBA --bitrate encoder bitrate (bps) --bitrate_mode encoder bitrate mode (0: CBR; 1: VBR; 2: CQ) --codec_run_mode 0: Surface origin 1: Buffer SharedMemory @@ -73,10 +75,11 @@ R"HELP_TEXT(Video codec demo help: --frame_interval frame push interval (ms) --repeat_times demo repeat times --hdr_vivid_video input file is hdr vivid video? (0: false; 1: true) + --need_dump_output need to dump output stream? (0: false; 1: true) Example: - --codec_type 0 --file input.h264 -mime video/avc --width 1280 --height 720 --framerate 30 --pixel_format 1 - --codec_run_mode 0 --frame_interval 0 --repeat_times 1 --hdr_vivid_video 0 + --codec_type 0 --file input.h264 --mime video/avc --width 1280 --height 720 --framerate 30 --pixel_format 1 + --codec_run_mode 0 --frame_interval 0 --repeat_times 1 --hdr_vivid_video 0 --need_dump_output 0 )HELP_TEXT"; void ShowHelp() @@ -136,6 +139,9 @@ SampleInfo ParseDemoArg(int argc, char *argv[]) case DEMO_ARG_HDR_VIVID_VIDEO: info.isHDRVivid = std::stol(optarg); break; + case DEMO_ARG_NEED_DUMP_OUTPUT: + info.needDumpOutput = std::stol(optarg); + break; default: std::cout << "Unknow arg type: " << argType << ", value: " << optarg << std::endl; break; diff --git a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp index d0df1bd2b..9b7c4c9a6 100644 --- a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp +++ b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp @@ -25,11 +25,38 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SampleHelper"}; const std::unordered_map RUN_MODE_TO_STRING = { - {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_AVBUFFER, "Buffer AVBuffer"}, - {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_SHARED_MEMORY, "Buffer SharedMemory"}, - {OHOS::MediaAVCodec::Sample::CodecRunMode::SURFACE_ORIGIN, "Surface Origin"}, - {OHOS::MediaAVCodec::Sample::CodecRunMode::SURFACE_AVBUFFER, "Surface AVBuffer"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_AVBUFFER, "Buffer AVBuffer"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_SHARED_MEMORY, "Buffer SharedMemory"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::SURFACE_ORIGIN, "Surface Origin"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::SURFACE_AVBUFFER, "Surface AVBuffer"}, }; + +const std::unordered_map BOOL_TO_STRING = { + {false, "false"}, + {true, "true"} +}; + +const std::unordered_map PIXEL_FORMAT_TO_STRING = { + {AV_PIXEL_FORMAT_YUVI420, "YUVI420"}, + {AV_PIXEL_FORMAT_NV12, "NV12"}, + {AV_PIXEL_FORMAT_NV21, "NV21"}, + {AV_PIXEL_FORMAT_SURFACE_FORMAT, "SURFACE_FORMAT"}, + {AV_PIXEL_FORMAT_RGBA, "RGBA"}, +}; + +void PrintSampleInfo(const OHOS::MediaAVCodec::Sample::SampleInfo &info) +{ + AVCODEC_LOGI("====== Video sample config ======"); + AVCODEC_LOGI("codec run mode: %{public}s", RUN_MODE_TO_STRING.at(info.codecRunMode).c_str()); + AVCODEC_LOGI("input file: %{public}s", info.inputFilePath.c_str()); + AVCODEC_LOGI("mime: %{public}s, %{public}d*%{public}d, %{public}.1ffps, %{public}.2fMbps, pixel format: %{public}s", + info.codecMime.c_str(), info.videoWidth, info.videoHeight, info.frameRate, + static_cast(info.bitrate) / 1024 / 1024, // 1024: precision + PIXEL_FORMAT_TO_STRING.at(info.pixelFormat).c_str()); + AVCODEC_LOGI("interval: %{public}dms, HDR vivid: %{public}s, dump output: %{public}s", + info.frameInterval, BOOL_TO_STRING.at(info.isHDRVivid).c_str(), BOOL_TO_STRING.at(info.needDumpOutput).c_str()); + AVCODEC_LOGI("====== Video sample config ======"); +} } namespace OHOS { @@ -40,21 +67,15 @@ bool SampleInfoChecker() return true; } -int32_t RunSample(const SampleInfo &sampleInfo) +int32_t RunSample(const SampleInfo &info) { - AVCODEC_LOGI("====== Video sample config ======"); - AVCODEC_LOGI("codec run mode: %{public}s", RUN_MODE_TO_STRING.at(sampleInfo.codecRunMode).c_str()); - AVCODEC_LOGI("input file: %{public}s", sampleInfo.inputFilePath.c_str()); - AVCODEC_LOGI("mime: %{public}s, %{public}d*%{public}d, %{public}.1ffps, %{public}.2fMbps, interval: %{public}dms", - sampleInfo.codecMime.c_str(), sampleInfo.videoWidth, sampleInfo.videoHeight, sampleInfo.frameRate, - static_cast(sampleInfo.bitrate) / 1024 / 1024, sampleInfo.frameInterval); // 1024: precision - AVCODEC_LOGI("====== Video sample config ======"); + PrintSampleInfo(info); - std::unique_ptr sample = sampleInfo.codecType == CodecType::VIDEO_DECODER ? + std::unique_ptr sample = info.codecType == CodecType::VIDEO_DECODER ? static_cast>(std::make_unique()) : static_cast>(std::make_unique()); - int32_t ret = sample->Create(sampleInfo); + int32_t ret = sample->Create(info); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Create failed"); ret = sample->Start(); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Start failed"); -- Gitee From 35b2957eb6c297bbf70ad87e00e99ede4bab75cb Mon Sep 17 00:00:00 2001 From: West Date: Sat, 23 Dec 2023 09:55:06 +0000 Subject: [PATCH 28/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=20sample=20=E5=B8=A7?= =?UTF-8?q?=E6=95=B0=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Iaabe3e0be1275da05439b64796914c9006852e98 --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 2 +- .../sample/encoder/video_encoder_perf_test_sample.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 8d35650f2..96677117e 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -204,8 +204,8 @@ void VideoDecoderPerfTestSample::OutputThread() CodecBufferInfo bufferInfo = context_->outputBufferInfoQueue_.front(); context_->outputBufferInfoQueue_.pop(); - context_->outputFrameCount_++; CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); + context_->outputFrameCount_++; lock.unlock(); DumpOutput(bufferInfo); diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index f334bbc96..ef24f3e07 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -230,8 +230,8 @@ void VideoEncoderPerfTestSample::OutputThread() CodecBufferInfo bufferInfo = context_->outputBufferInfoQueue_.front(); context_->outputBufferInfoQueue_.pop(); - context_->outputFrameCount_++; CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); + context_->outputFrameCount_++; lock.unlock(); DumpOutput(bufferInfo); -- Gitee From d0cde90e67b5adcd5a605bfdb315116b53da0349 Mon Sep 17 00:00:00 2001 From: West Date: Sat, 23 Dec 2023 10:27:03 +0000 Subject: [PATCH 29/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=20sample=20=E5=B8=A7?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I69f722580e860b07bed3b31138ced48a1dfe7c35 --- test/unittest/video_perf_test/common/sample_callback.cpp | 9 --------- .../sample/decoder/video_decoder_perf_test_sample.cpp | 2 ++ .../sample/encoder/video_encoder_perf_test_sample.cpp | 2 ++ 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index 7626fa3b2..9ab5cc1ae 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -18,7 +18,6 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SampleCallback"}; -constexpr int LIMIT_LOGD_FREQUENCY = 50; } namespace OHOS { @@ -47,8 +46,6 @@ void SampleCallback::OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, O } (void)codec; CodecUserData *codecUserData = static_cast(userData); - AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", - codecUserData->inputFrameCount_); std::unique_lock lock(codecUserData->inputMutex_); codecUserData->inputBufferInfoQueue_.emplace(index, data); codecUserData->inputCond_.notify_all(); @@ -62,8 +59,6 @@ void SampleCallback::OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, } (void)codec; CodecUserData *codecUserData = static_cast(userData); - AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", - codecUserData->outputFrameCount_); std::unique_lock lock(codecUserData->outputMutex_); codecUserData->outputBufferInfoQueue_.emplace(index, data, *attr); codecUserData->outputCond_.notify_all(); @@ -76,8 +71,6 @@ void SampleCallback::OnNeedInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVB } (void)codec; CodecUserData *codecUserData = static_cast(userData); - AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", - codecUserData->inputFrameCount_); std::unique_lock lock(codecUserData->inputMutex_); codecUserData->inputBufferInfoQueue_.emplace(index, buffer); codecUserData->inputCond_.notify_all(); @@ -90,8 +83,6 @@ void SampleCallback::OnNewOutputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVB } (void)codec; CodecUserData *codecUserData = static_cast(userData); - AVCODEC_LOGD_LIMIT(LIMIT_LOGD_FREQUENCY, "FrameCount: %{public}d", - codecUserData->outputFrameCount_); std::unique_lock lock(codecUserData->outputMutex_); codecUserData->outputBufferInfoQueue_.emplace(index, buffer); codecUserData->outputCond_.notify_all(); diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 96677117e..912336fc3 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -206,6 +206,8 @@ void VideoDecoderPerfTestSample::OutputThread() context_->outputBufferInfoQueue_.pop(); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); context_->outputFrameCount_++; + AVCODEC_LOGV("Out buffer count: %{public}d, size: %{public}d, flag: %{public}, pts: %{public}" PRId64, + context_->outputFrameCount_, bufferInfo.attr.size, bufferInfo.attr.flags, bufferInfo.attr.pts); lock.unlock(); DumpOutput(bufferInfo); diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index ef24f3e07..d10de94f1 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -232,6 +232,8 @@ void VideoEncoderPerfTestSample::OutputThread() context_->outputBufferInfoQueue_.pop(); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); context_->outputFrameCount_++; + AVCODEC_LOGV("Out buffer count: %{public}d, size: %{public}d, flag: %{public}, pts: %{public}" PRId64, + context_->outputFrameCount_, bufferInfo.attr.size, bufferInfo.attr.flags, bufferInfo.attr.pts); lock.unlock(); DumpOutput(bufferInfo); -- Gitee From bbf457020e8a14e22f087bbb36d34e8385bab3ca Mon Sep 17 00:00:00 2001 From: West Date: Sat, 23 Dec 2023 10:29:26 +0000 Subject: [PATCH 30/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=20sample=20=E5=B8=A7?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I1f3af0f21bb0ffbb6a74f07b47e234f80640106c --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 2 +- .../sample/encoder/video_encoder_perf_test_sample.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 912336fc3..a84bdda15 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -206,7 +206,7 @@ void VideoDecoderPerfTestSample::OutputThread() context_->outputBufferInfoQueue_.pop(); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); context_->outputFrameCount_++; - AVCODEC_LOGV("Out buffer count: %{public}d, size: %{public}d, flag: %{public}, pts: %{public}" PRId64, + AVCODEC_LOGV("Out buffer count: %{public}d, size: %{public}d, flag: %{public}d, pts: %{public}" PRId64, context_->outputFrameCount_, bufferInfo.attr.size, bufferInfo.attr.flags, bufferInfo.attr.pts); lock.unlock(); diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index d10de94f1..be9b5c404 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -232,7 +232,7 @@ void VideoEncoderPerfTestSample::OutputThread() context_->outputBufferInfoQueue_.pop(); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); context_->outputFrameCount_++; - AVCODEC_LOGV("Out buffer count: %{public}d, size: %{public}d, flag: %{public}, pts: %{public}" PRId64, + AVCODEC_LOGV("Out buffer count: %{public}d, size: %{public}d, flag: %{public}d, pts: %{public}" PRId64, context_->outputFrameCount_, bufferInfo.attr.size, bufferInfo.attr.flags, bufferInfo.attr.pts); lock.unlock(); -- Gitee From 8d29eb9e90046a573d589bfeba3cec9f1e214092 Mon Sep 17 00:00:00 2001 From: West Date: Sat, 23 Dec 2023 14:15:02 +0000 Subject: [PATCH 31/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E5=A4=8D=20sample=20=E6=9C=AA?= =?UTF-8?q?=E4=BC=A0=20buffer=20size=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I49dc1bc28ebd8c17e391bee7c9f7059e51d0ef54 --- .../encoder/include/video_encoder_perf_test_sample.h | 2 +- .../video_perf_test/sample/encoder/video_encoder.cpp | 6 +++--- .../sample/encoder/video_encoder_perf_test_sample.cpp | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h index 01fb118c7..126bb4a55 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h @@ -43,7 +43,7 @@ private: void SurfaceInputThread(); void OutputThread(); int32_t ReadOneFrame(CodecBufferInfo &info); - int32_t ReadOneFrame(uint8_t *bufferAddr, uint32_t &flags); + int32_t ReadOneFrame(uint8_t *bufferAddr, int32_t &bufferSize, uint32_t &flags); void AddSurfaceInputTrace(uint32_t flag, uint64_t pts); void ThreadSleep(); void DumpOutput(const CodecBufferInfo &bufferInfo); diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp index a531d61ab..f80090f0e 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp @@ -41,11 +41,11 @@ int32_t ToGraphicPixelFormat(int32_t avPixelFormat, bool isHDRVivid) case AV_PIXEL_FORMAT_RGBA: return GRAPHIC_PIXEL_FMT_RGBA_8888; case AV_PIXEL_FORMAT_YUVI420: - return GRAPHIC_PIXEL_FMT_RGBA_8888; + return GRAPHIC_PIXEL_FMT_YCBCR_420_P; case AV_PIXEL_FORMAT_NV21: - return GRAPHIC_PIXEL_FMT_RGBA_8888; + return GRAPHIC_PIXEL_FMT_YCBCR_420_SP; default: // NV12 and others - return GRAPHIC_PIXEL_FMT_RGBA_8888; + return GRAPHIC_PIXEL_FMT_YCBCR_420_SP; } } diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index be9b5c404..3ca553c5d 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -196,7 +196,8 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() CHECK_AND_BREAK_LOG(ret == 0, "Map native buffer failed, thread out"); uint32_t flags = AVCODEC_BUFFER_FLAGS_NONE; - ret = ReadOneFrame(bufferAddr, flags); + int32_t bufferSize = 0; + ret = ReadOneFrame(bufferAddr, bufferSize, flags); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); CHECK_AND_BREAK_LOG(!(flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); ret = OH_NativeBuffer_Unmap(nativeBuffer); @@ -252,19 +253,19 @@ int32_t VideoEncoderPerfTestSample::ReadOneFrame(CodecBufferInfo &info) auto bufferAddr = static_cast(sampleInfo_.codecRunMode) & 0b10 ? // 0b10: AVBuffer mode mask OH_AVBuffer_GetAddr(reinterpret_cast(info.buffer)) : OH_AVMemory_GetAddr(reinterpret_cast(info.buffer)); - int32_t ret = ReadOneFrame(bufferAddr, info.attr.flags); + int32_t ret = ReadOneFrame(bufferAddr, info.attr.size, info.attr.flags); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Read frame failed"); return AVCODEC_SAMPLE_ERR_OK; } -int32_t VideoEncoderPerfTestSample::ReadOneFrame(uint8_t *bufferAddr, uint32_t &flags) +int32_t VideoEncoderPerfTestSample::ReadOneFrame(uint8_t *bufferAddr, int32_t &bufferSize, uint32_t &flags) { CHECK_AND_RETURN_RET_LOG(inputFile_ != nullptr && inputFile_->is_open(), AVCODEC_SAMPLE_ERR_ERROR, "Input file is not open!"); CHECK_AND_RETURN_RET_LOG(bufferAddr != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Invalid buffer address"); - uint64_t bufferSize = sampleInfo_.videoWidth * sampleInfo_.videoHeight * 3 / 2; // YUV buffer size + bufferSize = sampleInfo_.videoWidth * sampleInfo_.videoHeight * 3 / 2; // YUV buffer size inputFile_->read(reinterpret_cast(bufferAddr), bufferSize); flags = inputFile_->eof() ? AVCODEC_BUFFER_FLAGS_EOS : AVCODEC_BUFFER_FLAGS_NONE; -- Gitee From 407927b489c686a0c68a521d4ec399056b8cf3f4 Mon Sep 17 00:00:00 2001 From: West Date: Sun, 24 Dec 2023 10:08:48 +0800 Subject: [PATCH 32/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E5=A4=8D=20dfx=20=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I5b3788518a20c628e034309ddca3f0a34cd3af09 --- .../audio_decoder/aac/ffmpeg_aac_decoder_plugin.cpp | 1 - .../audio_decoder/amrnb/ffmpeg_amrnb_decoder_plugin.cpp | 1 - .../audio_decoder/amrwb/ffmpeg_amrwb_decoder_plugin.cpp | 1 - .../audio_decoder/flac/ffmpeg_flac_decoder_plugin.cpp | 1 - .../audio_decoder/mp3/ffmpeg_mp3_decoder_plugin.cpp | 1 - .../audio_decoder/vorbis/ffmpeg_vorbis_decoder_plugin.cpp | 1 - 6 files changed, 6 deletions(-) diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/aac/ffmpeg_aac_decoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/aac/ffmpeg_aac_decoder_plugin.cpp index 51af7e050..861914685 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/aac/ffmpeg_aac_decoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/aac/ffmpeg_aac_decoder_plugin.cpp @@ -15,7 +15,6 @@ #include "ffmpeg_aac_decoder_plugin.h" #include #include "avcodec_codec_name.h" -#include "avcodec_dfx.h" #include "avcodec_log.h" #include "plugin/codec_plugin.h" #include "plugin/plugin_definition.h" diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/amrnb/ffmpeg_amrnb_decoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/amrnb/ffmpeg_amrnb_decoder_plugin.cpp index 3237074ba..527466984 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/amrnb/ffmpeg_amrnb_decoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/amrnb/ffmpeg_amrnb_decoder_plugin.cpp @@ -14,7 +14,6 @@ */ #include "ffmpeg_amrnb_decoder_plugin.h" #include "avcodec_codec_name.h" -#include "avcodec_dfx.h" #include "avcodec_log.h" #include "plugin/codec_plugin.h" #include "plugin/plugin_definition.h" diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/amrwb/ffmpeg_amrwb_decoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/amrwb/ffmpeg_amrwb_decoder_plugin.cpp index 4c8b17b45..26968365e 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/amrwb/ffmpeg_amrwb_decoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/amrwb/ffmpeg_amrwb_decoder_plugin.cpp @@ -14,7 +14,6 @@ */ #include "ffmpeg_amrwb_decoder_plugin.h" #include "avcodec_codec_name.h" -#include "avcodec_dfx.h" #include "avcodec_log.h" #include "plugin/codec_plugin.h" #include "plugin/plugin_definition.h" diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/flac/ffmpeg_flac_decoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/flac/ffmpeg_flac_decoder_plugin.cpp index e53e52433..18e653fad 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/flac/ffmpeg_flac_decoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/flac/ffmpeg_flac_decoder_plugin.cpp @@ -14,7 +14,6 @@ */ #include "ffmpeg_flac_decoder_plugin.h" #include "avcodec_codec_name.h" -#include "avcodec_dfx.h" #include "avcodec_log.h" #include "plugin/codec_plugin.h" #include "plugin/plugin_definition.h" diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/mp3/ffmpeg_mp3_decoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/mp3/ffmpeg_mp3_decoder_plugin.cpp index 2af1dd073..fb3959d8b 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/mp3/ffmpeg_mp3_decoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/mp3/ffmpeg_mp3_decoder_plugin.cpp @@ -14,7 +14,6 @@ */ #include "ffmpeg_mp3_decoder_plugin.h" #include "avcodec_codec_name.h" -#include "avcodec_dfx.h" #include "avcodec_log.h" #include "plugin/codec_plugin.h" #include "plugin/plugin_definition.h" diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/vorbis/ffmpeg_vorbis_decoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/vorbis/ffmpeg_vorbis_decoder_plugin.cpp index e48fa7284..6474c958d 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/vorbis/ffmpeg_vorbis_decoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/vorbis/ffmpeg_vorbis_decoder_plugin.cpp @@ -15,7 +15,6 @@ #include "ffmpeg_vorbis_decoder_plugin.h" #include #include "avcodec_codec_name.h" -#include "avcodec_dfx.h" #include "avcodec_log.h" #include "plugin/codec_plugin.h" #include "plugin/plugin_definition.h" -- Gitee From 1a05f2976757728278ba8469a6a850547a194440 Mon Sep 17 00:00:00 2001 From: West Date: Sun, 24 Dec 2023 23:56:49 +0800 Subject: [PATCH 33/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91Add=20video=20codec=20demo=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I790ad1e8b8a02b447b4e04799cf8d421a8e6aea6 --- test/unittest/video_perf_test/BUILD.gn | 1 + .../common/include/sample_info.h | 8 +-- .../common/sample_callback.cpp | 13 +++-- .../video_perf_test/demo/video_codec_demo.cpp | 3 +- .../sample/decoder/include/video_decoder.h | 1 + .../include/video_decoder_perf_test_sample.h | 1 - .../sample/decoder/video_decoder.cpp | 50 ++++++++++--------- .../video_decoder_perf_test_sample.cpp | 23 ++++++--- .../sample/encoder/include/video_encoder.h | 3 +- .../sample/encoder/video_encoder.cpp | 32 +++++++----- .../video_encoder_perf_test_sample.cpp | 3 +- .../sample/helper/arg_checker.cpp | 41 +++++++++++++++ .../sample/helper/include/arg_checker.h | 28 +++++++++++ .../sample/helper/include/sample_helper.h | 2 +- .../sample/helper/sample_helper.cpp | 21 ++++++-- .../test_suilt/video_perf_test_suilt.cpp | 2 +- 16 files changed, 167 insertions(+), 65 deletions(-) create mode 100644 test/unittest/video_perf_test/sample/helper/arg_checker.cpp create mode 100644 test/unittest/video_perf_test/sample/helper/include/arg_checker.h diff --git a/test/unittest/video_perf_test/BUILD.gn b/test/unittest/video_perf_test/BUILD.gn index 2df31b506..edede7a6d 100644 --- a/test/unittest/video_perf_test/BUILD.gn +++ b/test/unittest/video_perf_test/BUILD.gn @@ -58,6 +58,7 @@ ohos_source_set("video_sample") { "./sample/encoder/video_encoder_perf_test_sample.cpp", "./sample/encoder/video_encoder.cpp", "./sample/helper/arg_parser.cpp", + "./sample/helper/arg_checker.cpp", "./sample/helper/sample_helper.cpp", ] diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h index 1caba86b5..8eb0e1bf7 100644 --- a/test/unittest/video_perf_test/common/include/sample_info.h +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -37,11 +37,6 @@ enum CodecType { VIDEO_ENCODER }; -enum TestMode { - FRAME_DELAY, - FRAME_RATE, -}; - /* CodecRunMode description * +-----+------------+--------------+ * | Bit | 01 | 00 | @@ -66,7 +61,6 @@ struct SampleInfo { int64_t bitrate = 10 * 1024 * 1024; // 10Mbps; CodecRunMode codecRunMode = SURFACE_ORIGIN; - TestMode testMode = FRAME_DELAY; int32_t frameInterval = 0; NativeWindow* window = nullptr; uint32_t repeatTimes = 0; @@ -93,6 +87,8 @@ struct CodecBufferInfo { class CodecUserData { public: + SampleInfo *sampleInfo = nullptr; + int32_t inputFrameCount_ = 0; std::mutex inputMutex_; std::condition_variable inputCond_; diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index 9ab5cc1ae..42303df3a 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -33,10 +33,17 @@ void SampleCallback::OnCodecError(OH_AVCodec *codec, int32_t errorCode, void *us void SampleCallback::OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, void *userData) { + if (userData == nullptr) { + return; + } (void)codec; - (void)format; - (void)userData; - AVCODEC_LOGW("On decoder format change"); + CodecUserData *codecUserData = static_cast(userData); + std::unique_lock lock(codecUserData->outputMutex_); + OH_AVFormat_GetIntValue(format, OH_MD_KEY_WIDTH, &codecUserData->sampleInfo->videoWidth); + OH_AVFormat_GetIntValue(format, OH_MD_KEY_HEIGHT, &codecUserData->sampleInfo->videoHeight); + + AVCODEC_LOGW("On decoder format change, resolution: %{public}d*%{piblic}d", + codecUserData->sampleInfo->videoWidth, codecUserData->sampleInfo->videoHeight); } void SampleCallback::OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData) diff --git a/test/unittest/video_perf_test/demo/video_codec_demo.cpp b/test/unittest/video_perf_test/demo/video_codec_demo.cpp index 09e27527e..1bc27e397 100644 --- a/test/unittest/video_perf_test/demo/video_codec_demo.cpp +++ b/test/unittest/video_perf_test/demo/video_codec_demo.cpp @@ -15,6 +15,7 @@ #include #include "arg_parser.h" +#include "arg_checker.h" #include "sample_helper.h" #include "av_codec_sample_error.h" @@ -23,7 +24,7 @@ using namespace OHOS::MediaAVCodec::Sample; int main(int argc, char *argv[]) { auto info = ParseDemoArg(argc, argv); - if (!SampleInfoChecker()) { + if (!SampleInfoChecker(info)) { std::cout << "Demo arg check failed, exit" << std::endl; return 1; } diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h index ea170933f..8cf2a17af 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h @@ -37,6 +37,7 @@ public: private: int32_t SetCallback(CodecUserData *codecUserData); + int32_t Configure(const SampleInfo &sampleInfo); OH_AVCodec *decoder_; bool isAVBufferMode_; diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index b8c88e886..a9e4da388 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -48,7 +48,6 @@ private: void ThreadSleep(); void DumpOutput(const CodecBufferInfo &bufferInfo); - std::unique_ptr videoDecoder_ = nullptr; std::unique_ptr inputThread_ = nullptr; std::unique_ptr outputThread_ = nullptr; diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp index 0819d3bb3..eb95cf662 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp @@ -44,40 +44,24 @@ int32_t VideoDecoder::Config(const SampleInfo &sampleInfo, CodecUserData *codecU isAVBufferMode_ = (static_cast(sampleInfo.codecRunMode) & 0b10); // ob10: AVBuffer mode mask // Configure video decoder - { - OH_AVFormat *format = OH_AVFormat_Create(); - CHECK_AND_RETURN_RET_LOG(format != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "AVFormat create failed"); - - OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); - OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); - OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); - OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, sampleInfo.pixelFormat); - - int ret = OH_VideoDecoder_Configure(decoder_, format); - CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Config failed, ret: %{public}d", ret); - OH_AVFormat_Destroy(format); - format = nullptr; - } + int32_t ret = Configure(sampleInfo); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Configure failed"); // SetSurface from video decoder if (sampleInfo.window != nullptr) { - int ret = OH_VideoDecoder_SetSurface(decoder_, sampleInfo.window); + ret = OH_VideoDecoder_SetSurface(decoder_, sampleInfo.window); CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK && sampleInfo.window, AVCODEC_SAMPLE_ERR_ERROR, "Set surface failed, ret: %{public}d", ret); } // SetCallback for video decoder - { - int32_t ret = SetCallback(codecUserData); - CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, - "Set callback failed, ret: %{public}d", ret); - } + ret = SetCallback(codecUserData); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, + "Set callback failed, ret: %{public}d", ret); // Prepare video decoder - { - int ret = OH_VideoDecoder_Prepare(decoder_); - CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Prepare failed, ret: %{public}d", ret); - } + ret = OH_VideoDecoder_Prepare(decoder_); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Prepare failed, ret: %{public}d", ret); return AVCODEC_SAMPLE_ERR_OK; } @@ -158,6 +142,24 @@ int32_t VideoDecoder::SetCallback(CodecUserData *codecUserData) return AVCODEC_SAMPLE_ERR_OK; } + +int32_t VideoDecoder::Configure(const SampleInfo &sampleInfo) +{ + OH_AVFormat *format = OH_AVFormat_Create(); + CHECK_AND_RETURN_RET_LOG(format != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "AVFormat create failed"); + + OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, sampleInfo.videoWidth); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, sampleInfo.videoHeight); + OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_FRAME_RATE, sampleInfo.frameRate); + OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, sampleInfo.pixelFormat); + + int ret = OH_VideoDecoder_Configure(decoder_, format); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Config failed, ret: %{public}d", ret); + OH_AVFormat_Destroy(format); + format = nullptr; + + return AVCODEC_SAMPLE_ERR_OK; +} } // Sample } // MediaAVCodec } // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index a84bdda15..27d9a6f7f 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -15,14 +15,16 @@ #include "video_decoder_perf_test_sample.h" #include -#include "av_codec_sample_log.h" -#include "av_codec_sample_error.h" +#include "refbase.h" #include "iconsumer_surface.h" #include "window.h" -#include "refbase.h" -#include "avcodec_trace.h" #include "surface.h" +#include "avcodec_trace.h" +#include "av_codec_sample_log.h" +#include "av_codec_sample_error.h" +#include "sample_helper.h" + namespace { using namespace std::chrono_literals; @@ -76,6 +78,7 @@ int32_t VideoDecoderPerfTestSample::Create(SampleInfo sampleInfo) CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create video decoder failed"); context_ = new CodecUserData; + context_->sampleInfo = &sampleInfo_; if (!(sampleInfo_.codecRunMode & 0b01)) { // 0b01: Buffer mode mask ret = CreateWindow(sampleInfo_.window); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create window failed"); @@ -303,15 +306,19 @@ void VideoDecoderPerfTestSample::ThreadSleep() inline void VideoDecoderPerfTestSample::DumpOutput(const CodecBufferInfo &bufferInfo) { - if (!sampleInfo_.needDumpOutput) { + if (!(sampleInfo_.needDumpOutput) || !(sampleInfo_.codecRunMode & 0b01)) { // 0b01: Buffer mode mask return; } - using namespace std::string_literals; if (outputFile_ == nullptr) { + using namespace std::string_literals; auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - outputFile_ = std::make_unique("VideoDecoderOut_"s + std::to_string(time) + ".yuv", - std::ios::out | std::ios::trunc); + std::string outputName = "VideoDecoderOut_"s + "_" + + ToString(static_cast(sampleInfo_.pixelFormat)) + "_" + + std::to_string(sampleInfo_.videoWidth) + "*" + std::to_string(sampleInfo_.videoHeight) + "_" + + std::to_string(time) + ".yuv"; + + outputFile_ = std::make_unique(outputName, std::ios::out | std::ios::trunc); if (!outputFile_->is_open()) { outputFile_ = nullptr; } diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h index ffd182c24..ac91a8e70 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h @@ -39,7 +39,8 @@ public: private: int32_t SetCallback(CodecUserData *codecUserData); int32_t Configure(const SampleInfo &sampleInfo); - + int32_t GetSurface(SampleInfo &sampleInfo); + OH_AVCodec *encoder_ = nullptr; bool isAVBufferMode_; }; diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp index f80090f0e..14f764fd8 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp @@ -43,7 +43,7 @@ int32_t ToGraphicPixelFormat(int32_t avPixelFormat, bool isHDRVivid) case AV_PIXEL_FORMAT_YUVI420: return GRAPHIC_PIXEL_FMT_YCBCR_420_P; case AV_PIXEL_FORMAT_NV21: - return GRAPHIC_PIXEL_FMT_YCBCR_420_SP; + return GRAPHIC_PIXEL_FMT_YCRCB_420_SP; default: // NV12 and others return GRAPHIC_PIXEL_FMT_YCBCR_420_SP; } @@ -72,21 +72,12 @@ int32_t VideoEncoder::Config(SampleInfo &sampleInfo, CodecUserData *codecUserDat CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Configure failed"); // GetSurface from video encoder - if (!(static_cast(sampleInfo.codecRunMode) & 0b01)) { // 0b01: Buffer mode mask - ret = OH_VideoEncoder_GetSurface(encoder_, &sampleInfo.window); - CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK && sampleInfo.window, AVCODEC_SAMPLE_ERR_ERROR, - "Get surface failed, ret: %{public}d", ret); - (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_BUFFER_GEOMETRY, - sampleInfo.videoWidth, sampleInfo.videoHeight); - (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_USAGE, 16425); // 16425: Window usage - (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_FORMAT, - ToGraphicPixelFormat(sampleInfo.pixelFormat, sampleInfo.isHDRVivid)); - } + ret = GetSurface(sampleInfo); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Get surface failed"); // SetCallback for video encoder ret = SetCallback(codecUserData); - CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, - "Set callback failed, ret: %{public}d", ret); + CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Set callback failed"); // Prepare video encoder ret = OH_VideoEncoder_Prepare(encoder_); @@ -205,6 +196,21 @@ int32_t VideoEncoder::Configure(const SampleInfo &sampleInfo) format = nullptr; return AVCODEC_SAMPLE_ERR_OK; } + +int32_t VideoEncoder::GetSurface(SampleInfo &sampleInfo) +{ + if (!(static_cast(sampleInfo.codecRunMode) & 0b01)) { // 0b01: Buffer mode mask + int32_t ret = OH_VideoEncoder_GetSurface(encoder_, &sampleInfo.window); + CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK && sampleInfo.window, AVCODEC_SAMPLE_ERR_ERROR, + "Get surface failed, ret: %{public}d", ret); + (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_BUFFER_GEOMETRY, + sampleInfo.videoWidth, sampleInfo.videoHeight); + (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_USAGE, 16425); // 16425: Window usage + (void)OH_NativeWindow_NativeWindowHandleOpt(sampleInfo.window, SET_FORMAT, + ToGraphicPixelFormat(sampleInfo.pixelFormat, sampleInfo.isHDRVivid)); + } + return AVCODEC_SAMPLE_ERR_OK; +} } // Sample } // MediaAVCodec } // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 3ca553c5d..6bdaeb367 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -57,6 +57,7 @@ int32_t VideoEncoderPerfTestSample::Create(SampleInfo sampleInfo) CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Create video encoder failed"); context_ = new CodecUserData; + context_->sampleInfo = &sampleInfo_; ret = videoEncoder_->Config(sampleInfo_, context_); CHECK_AND_RETURN_RET_LOG(ret == AVCODEC_SAMPLE_ERR_OK, ret, "Encoder config failed"); @@ -201,7 +202,7 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Read frame failed, thread out"); CHECK_AND_BREAK_LOG(!(flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); ret = OH_NativeBuffer_Unmap(nativeBuffer); - CHECK_AND_BREAK_LOG(ret == 0, "Read frame failed, thread out"); + CHECK_AND_BREAK_LOG(ret == 0, "Unmap buffer failed, thread out"); ThreadSleep(); diff --git a/test/unittest/video_perf_test/sample/helper/arg_checker.cpp b/test/unittest/video_perf_test/sample/helper/arg_checker.cpp new file mode 100644 index 000000000..713a5a2ee --- /dev/null +++ b/test/unittest/video_perf_test/sample/helper/arg_checker.cpp @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#include "arg_checker.h" +#include "av_codec_sample_log.h" + +namespace { +template +bool ArgumentChecker(T value, T lowerLimit, T upperLimit) +{ + (void)value; + (void)lowerLimit; + (void)upperLimit; + + return true; +} +} + +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { +bool SampleInfoChecker(const SampleInfo &sampleInfo) +{ + (void)sampleInfo; + return true; +} +} // Sample +} // MediaAVCodec +} // OHOS \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/helper/include/arg_checker.h b/test/unittest/video_perf_test/sample/helper/include/arg_checker.h new file mode 100644 index 000000000..0868015f7 --- /dev/null +++ b/test/unittest/video_perf_test/sample/helper/include/arg_checker.h @@ -0,0 +1,28 @@ +/* + * 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 AVCODEC_SAMPLE_ARG_CHECKER_H +#define AVCODEC_SAMPLE_ARG_CHECKER_H + +#include "sample_info.h" + +namespace OHOS { +namespace MediaAVCodec { +namespace Sample { +bool SampleInfoChecker(const SampleInfo &sampleInfo); +} // Sample +} // MediaAVCodec +} // OHOS +#endif // AVCODEC_SAMPLE_ARG_CHECKER_H \ No newline at end of file diff --git a/test/unittest/video_perf_test/sample/helper/include/sample_helper.h b/test/unittest/video_perf_test/sample/helper/include/sample_helper.h index ce5724c3d..8fac347d3 100644 --- a/test/unittest/video_perf_test/sample/helper/include/sample_helper.h +++ b/test/unittest/video_perf_test/sample/helper/include/sample_helper.h @@ -21,7 +21,7 @@ namespace OHOS { namespace MediaAVCodec { namespace Sample { -bool SampleInfoChecker(); +std::string ToString(OH_AVPixelFormat pixelFormat); int32_t RunSample(const SampleInfo &sampleInfo); } // Sample } // MediaAVCodec diff --git a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp index 9b7c4c9a6..14ee2f65f 100644 --- a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp +++ b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp @@ -24,6 +24,11 @@ namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SampleHelper"}; +const std::unordered_map CODEC_TYPE_TO_STRING = { + {OHOS::MediaAVCodec::Sample::CodecType::VIDEO_DECODER, "Decoder"}, + {OHOS::MediaAVCodec::Sample::CodecType::VIDEO_ENCODER, "Encoder"}, +}; + const std::unordered_map RUN_MODE_TO_STRING = { {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_AVBUFFER, "Buffer AVBuffer"}, {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_SHARED_MEMORY, "Buffer SharedMemory"}, @@ -36,7 +41,7 @@ const std::unordered_map BOOL_TO_STRING = { {true, "true"} }; -const std::unordered_map PIXEL_FORMAT_TO_STRING = { +const std::unordered_map PIXEL_FORMAT_TO_STRING = { {AV_PIXEL_FORMAT_YUVI420, "YUVI420"}, {AV_PIXEL_FORMAT_NV12, "NV12"}, {AV_PIXEL_FORMAT_NV21, "NV21"}, @@ -47,12 +52,13 @@ const std::unordered_map PIXEL_FORMAT_TO_STRING = { void PrintSampleInfo(const OHOS::MediaAVCodec::Sample::SampleInfo &info) { AVCODEC_LOGI("====== Video sample config ======"); - AVCODEC_LOGI("codec run mode: %{public}s", RUN_MODE_TO_STRING.at(info.codecRunMode).c_str()); + AVCODEC_LOGI("codec type: %{public}s, codec run mode: %{public}s", + CODEC_TYPE_TO_STRING.at(info.codecType).c_str(), RUN_MODE_TO_STRING.at(info.codecRunMode).c_str()); AVCODEC_LOGI("input file: %{public}s", info.inputFilePath.c_str()); AVCODEC_LOGI("mime: %{public}s, %{public}d*%{public}d, %{public}.1ffps, %{public}.2fMbps, pixel format: %{public}s", info.codecMime.c_str(), info.videoWidth, info.videoHeight, info.frameRate, static_cast(info.bitrate) / 1024 / 1024, // 1024: precision - PIXEL_FORMAT_TO_STRING.at(info.pixelFormat).c_str()); + OHOS::MediaAVCodec::Sample::ToString(static_cast(info.pixelFormat)).c_str()); AVCODEC_LOGI("interval: %{public}dms, HDR vivid: %{public}s, dump output: %{public}s", info.frameInterval, BOOL_TO_STRING.at(info.isHDRVivid).c_str(), BOOL_TO_STRING.at(info.needDumpOutput).c_str()); AVCODEC_LOGI("====== Video sample config ======"); @@ -62,9 +68,14 @@ void PrintSampleInfo(const OHOS::MediaAVCodec::Sample::SampleInfo &info) namespace OHOS { namespace MediaAVCodec { namespace Sample { -bool SampleInfoChecker() +std::string ToString(OH_AVPixelFormat pixelFormat) { - return true; + std::string ret; + auto iter = PIXEL_FORMAT_TO_STRING.find(pixelFormat); + if (iter != PIXEL_FORMAT_TO_STRING.end()) { + ret = PIXEL_FORMAT_TO_STRING.at(pixelFormat); + } + return ret; } int32_t RunSample(const SampleInfo &info) diff --git a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp index 22ebde167..92f567efa 100644 --- a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp +++ b/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp @@ -88,7 +88,7 @@ GENERATE_CASE_NAME(codecType, testMode, codecRunMode, mime, width, height, fps, FILE_##mime##_##width##_##height##_##fps##_##bitrate##M.data() : FILE_##width##_##height.data(); \ SampleInfo sampleInfo = { \ codecType, inputFileName, \ - MIME_VIDEO_##mime.data(), (width), (height), (fps), BITRATE_##bitrate##M, (codecRunMode), (testMode), (inteval)\ + MIME_VIDEO_##mime.data(), (width), (height), (fps), BITRATE_##bitrate##M, (codecRunMode), (inteval) \ }; \ ASSERT_EQ(AVCODEC_SAMPLE_ERR_OK, RunSample(sampleInfo)); \ } -- Gitee From 250548fdde00ea89bdd59c88f7452c6e089dae90 Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 03:24:15 +0000 Subject: [PATCH 34/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91sample=20=E6=B7=BB=E5=8A=A0=20input=20?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E9=80=80=E5=87=BA=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I31db17b34e2ffa1473cbd732fccca952740c4502 --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 1 + .../sample/encoder/video_encoder_perf_test_sample.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 27d9a6f7f..343c4ec71 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -191,6 +191,7 @@ void VideoDecoderPerfTestSample::InputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); } + AVCODEC_LOGI("On buffer input thread exit, frame count: %{public}d", context_->inputFrameCount_); StartRelease(); } diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 6bdaeb367..624dd103f 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -174,6 +174,7 @@ void VideoEncoderPerfTestSample::BufferInputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); } + AVCODEC_LOGI("On buffer input thread exit, frame count: %{public}d", context_->inputFrameCount_); StartRelease(); } @@ -216,6 +217,7 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() OH_NativeWindow_DestroyNativeWindowBuffer(buffer); } videoEncoder_->NotifyEndOfStream(); + AVCODEC_LOGI("On surface input thread exit, frame count: %{public}d", context_->inputFrameCount_); StartRelease(); } @@ -245,7 +247,7 @@ void VideoEncoderPerfTestSample::OutputThread() } OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); OHOS::MediaAVCodec::AVCodecTrace::CounterTrace("SampleFrameCount", context_->outputFrameCount_); - AVCODEC_LOGI("On encoder output thread exit, output frame count: %{public}d", context_->outputFrameCount_); + AVCODEC_LOGI("On output thread exit, frame count: %{public}d", context_->outputFrameCount_); StartRelease(); } -- Gitee From a540e01d941c4620d9647b863d02651e377bf0ff Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 03:27:08 +0000 Subject: [PATCH 35/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91sample=20=E6=B7=BB=E5=8A=A0=20input=20?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E9=80=80=E5=87=BA=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: If2e2832ab5e1b3f841cd49634fe7dc1e82835879 --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 4 ++-- .../sample/encoder/video_encoder_perf_test_sample.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 343c4ec71..52d065605 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -191,7 +191,7 @@ void VideoDecoderPerfTestSample::InputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); } - AVCODEC_LOGI("On buffer input thread exit, frame count: %{public}d", context_->inputFrameCount_); + AVCODEC_LOGI("Exit, frame count: %{public}d", context_->inputFrameCount_); StartRelease(); } @@ -221,7 +221,7 @@ void VideoDecoderPerfTestSample::OutputThread() } OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); OHOS::MediaAVCodec::AVCodecTrace::CounterTrace("SampleFrameCount", context_->outputFrameCount_); - AVCODEC_LOGI("On decoder output thread exit, output frame count: %{public}d", context_->outputFrameCount_); + AVCODEC_LOGI("Exit, output frame count: %{public}d", context_->outputFrameCount_); StartRelease(); } diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 624dd103f..15b5528c7 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -174,7 +174,7 @@ void VideoEncoderPerfTestSample::BufferInputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); } - AVCODEC_LOGI("On buffer input thread exit, frame count: %{public}d", context_->inputFrameCount_); + AVCODEC_LOGI("Exit, frame count: %{public}d", context_->inputFrameCount_); StartRelease(); } @@ -217,7 +217,7 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() OH_NativeWindow_DestroyNativeWindowBuffer(buffer); } videoEncoder_->NotifyEndOfStream(); - AVCODEC_LOGI("On surface input thread exit, frame count: %{public}d", context_->inputFrameCount_); + AVCODEC_LOGI("Exit, frame count: %{public}d", context_->inputFrameCount_); StartRelease(); } @@ -247,7 +247,7 @@ void VideoEncoderPerfTestSample::OutputThread() } OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); OHOS::MediaAVCodec::AVCodecTrace::CounterTrace("SampleFrameCount", context_->outputFrameCount_); - AVCODEC_LOGI("On output thread exit, frame count: %{public}d", context_->outputFrameCount_); + AVCODEC_LOGI("Exit, frame count: %{public}d", context_->outputFrameCount_); StartRelease(); } -- Gitee From d5b19625b0e9f7ac13fdca08547f67549b10e8ee Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 03:29:14 +0000 Subject: [PATCH 36/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91sample=20=E6=B7=BB=E5=8A=A0=20input=20?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E9=80=80=E5=87=BA=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I6fcc47d9ff7cb4343015f8b38c15fe3216b1095b --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 52d065605..fb1ec3c29 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -221,7 +221,7 @@ void VideoDecoderPerfTestSample::OutputThread() } OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); OHOS::MediaAVCodec::AVCodecTrace::CounterTrace("SampleFrameCount", context_->outputFrameCount_); - AVCODEC_LOGI("Exit, output frame count: %{public}d", context_->outputFrameCount_); + AVCODEC_LOGI("Exit, frame count: %{public}d", context_->outputFrameCount_); StartRelease(); } -- Gitee From db18e8f7b6d85499cd432e6aa6b1e9af8c952866 Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 03:54:47 +0000 Subject: [PATCH 37/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=20encoder=20sample=20buffe?= =?UTF-8?q?r=20size=20=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I30a35ec3a1566206b3ff065ba8ef133818bae877 --- .../video_perf_test/common/include/sample_info.h | 2 +- .../encoder/include/video_encoder_perf_test_sample.h | 1 + .../sample/encoder/video_encoder_perf_test_sample.cpp | 10 +++++++++- .../video_perf_test/sample/helper/arg_parser.cpp | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h index 8eb0e1bf7..38471a5bc 100644 --- a/test/unittest/video_perf_test/common/include/sample_info.h +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -64,7 +64,7 @@ struct SampleInfo { int32_t frameInterval = 0; NativeWindow* window = nullptr; uint32_t repeatTimes = 0; - uint32_t pixelFormat = 2; + OH_AVPixelFormat pixelFormat = AV_PIXEL_FORMAT_NV12; bool isHDRVivid = false; bool needDumpOutput = false; }; diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h index 126bb4a55..dbadf86ad 100644 --- a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h @@ -42,6 +42,7 @@ private: void BufferInputThread(); void SurfaceInputThread(); void OutputThread(); + int32_t GetBufferSize(); int32_t ReadOneFrame(CodecBufferInfo &info); int32_t ReadOneFrame(uint8_t *bufferAddr, int32_t &bufferSize, uint32_t &flags); void AddSurfaceInputTrace(uint32_t flag, uint64_t pts); diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 15b5528c7..ffdbde802 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -251,6 +251,14 @@ void VideoEncoderPerfTestSample::OutputThread() StartRelease(); } +inline int32_t VideoEncoderPerfTestSample::GetBufferSize() +{ + int32_t size = sampleInfo_.pixelFormat == AV_PIXEL_FORMAT_RGBA ? + sampleInfo_.videoWidth * sampleInfo_.videoHeight * 3 : // RGBA buffer size + sampleInfo_.videoWidth * sampleInfo_.videoHeight * 3 / 2; // YUV420 buffer size + return sampleInfo_.isHDRVivid ? size * 2 : size;; +} + int32_t VideoEncoderPerfTestSample::ReadOneFrame(CodecBufferInfo &info) { auto bufferAddr = static_cast(sampleInfo_.codecRunMode) & 0b10 ? // 0b10: AVBuffer mode mask @@ -268,7 +276,7 @@ int32_t VideoEncoderPerfTestSample::ReadOneFrame(uint8_t *bufferAddr, int32_t &b AVCODEC_SAMPLE_ERR_ERROR, "Input file is not open!"); CHECK_AND_RETURN_RET_LOG(bufferAddr != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Invalid buffer address"); - bufferSize = sampleInfo_.videoWidth * sampleInfo_.videoHeight * 3 / 2; // YUV buffer size + bufferSize = GetBufferSize(); inputFile_->read(reinterpret_cast(bufferAddr), bufferSize); flags = inputFile_->eof() ? AVCODEC_BUFFER_FLAGS_EOS : AVCODEC_BUFFER_FLAGS_NONE; diff --git a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp index 3ef16fa93..a33a870da 100644 --- a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp +++ b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp @@ -119,7 +119,7 @@ SampleInfo ParseDemoArg(int argc, char *argv[]) info.frameRate = std::stof(optarg); break; case DEMO_ARG_PIXEL_FORMAT: - info.pixelFormat = std::stol(optarg); + info.pixelFormat = static_cast(std::stol(optarg)); break; case DEMO_ARG_BITRATE: info.bitrate = std::stoll(optarg); -- Gitee From 79f1d8b5b3b395f97e33e9c7e58038bf94c65f33 Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 04:07:05 +0000 Subject: [PATCH 38/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=20sample=20callback=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I7a04eaceb241ba3294f544c9c4a31af56a18746b --- test/unittest/video_perf_test/common/sample_callback.cpp | 2 +- .../sample/decoder/video_decoder_perf_test_sample.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index 42303df3a..00987213d 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -42,7 +42,7 @@ void SampleCallback::OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, OH_AVFormat_GetIntValue(format, OH_MD_KEY_WIDTH, &codecUserData->sampleInfo->videoWidth); OH_AVFormat_GetIntValue(format, OH_MD_KEY_HEIGHT, &codecUserData->sampleInfo->videoHeight); - AVCODEC_LOGW("On decoder format change, resolution: %{public}d*%{piblic}d", + AVCODEC_LOGW("On decoder format change, resolution: %{public}d*%{public}d", codecUserData->sampleInfo->videoWidth, codecUserData->sampleInfo->videoHeight); } diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index fb1ec3c29..6d2b7d8ef 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -314,7 +314,7 @@ inline void VideoDecoderPerfTestSample::DumpOutput(const CodecBufferInfo &buffer if (outputFile_ == nullptr) { using namespace std::string_literals; auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - std::string outputName = "VideoDecoderOut_"s + "_" + + std::string outputName = "VideoDecoderOut_"s + ToString(static_cast(sampleInfo_.pixelFormat)) + "_" + std::to_string(sampleInfo_.videoWidth) + "*" + std::to_string(sampleInfo_.videoHeight) + "_" + std::to_string(time) + ".yuv"; -- Gitee From 69b61776bdb1d05515cb1bc9f485fb43b7eeef7f Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 18:40:58 +0800 Subject: [PATCH 39/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91support=20decoder=20sample=20dump=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I37034bba9a42704972ecd444d40c49598d67b6b2 --- test/unittest/video_perf_test/BUILD.gn | 2 + .../common/include/sample_info.h | 2 +- .../sample/decoder/include/video_decoder.h | 2 +- .../include/video_decoder_perf_test_sample.h | 14 +++++ .../sample/decoder/video_decoder.cpp | 8 ++- .../video_decoder_perf_test_sample.cpp | 55 +++++++++---------- 6 files changed, 50 insertions(+), 33 deletions(-) diff --git a/test/unittest/video_perf_test/BUILD.gn b/test/unittest/video_perf_test/BUILD.gn index edede7a6d..bb092ca56 100644 --- a/test/unittest/video_perf_test/BUILD.gn +++ b/test/unittest/video_perf_test/BUILD.gn @@ -92,6 +92,7 @@ ohos_unittest("video_perf_test") { "c_utils:utils", "hilog:libhilog", "histreamer:media_foundation", + "graphic_2d:surface", ] subsystem_name = "multimedia" @@ -109,6 +110,7 @@ ohos_executable("video_codec_demo") { "c_utils:utils", "hilog:libhilog", "histreamer:media_foundation", + "graphic_2d:surface", ] subsystem_name = "multimedia" diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h index 38471a5bc..6500a746e 100644 --- a/test/unittest/video_perf_test/common/include/sample_info.h +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -39,7 +39,7 @@ enum CodecType { /* CodecRunMode description * +-----+------------+--------------+ - * | Bit | 01 | 00 | + * | Bit | 2 | 1 | * +-----+------------+--------------+ * |Field| IsAVBuffer | IsBufferMode | * +-----+------------+--------------+ diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h index 8cf2a17af..536198032 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h @@ -31,7 +31,7 @@ public: int32_t Config(const SampleInfo &sampleInfo, CodecUserData *codecUserData); int32_t Start(); int32_t PushInputData(CodecBufferInfo &info); - int32_t FreeOutputData(uint32_t bufferIndex); + int32_t FreeOutputData(uint32_t bufferIndex, bool renderOutput); int32_t Stop(); int32_t Release(); diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index a9e4da388..fe96dd513 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -24,6 +24,7 @@ #include #include "video_perf_test_sample_base.h" #include "video_decoder.h" +#include "iconsumer_surface.h" namespace OHOS { namespace MediaAVCodec { @@ -46,8 +47,21 @@ private: int32_t ReadOneFrame(CodecBufferInfo &info); int32_t CreateWindow(OHNativeWindow *&window); void ThreadSleep(); + void DumpOutput(uint8_t *bufferAddr, uint32_t bufferSize); void DumpOutput(const CodecBufferInfo &bufferInfo); + class SurfaceConsumer : public OHOS::IBufferConsumerListener { + public: + SurfaceConsumer(OHOS::sptr surface, VideoDecoderPerfTestSample *sample) : surface_(surface) {}; + void OnBufferAvailable() override; + + private: + VideoDecoderPerfTestSample *sample_; + int64_t timestamp_ = 0; + OHOS::Rect damage_ = {}; + OHOS::sptr surface_ {nullptr}; + }; + std::unique_ptr videoDecoder_ = nullptr; std::unique_ptr inputThread_ = nullptr; std::unique_ptr outputThread_ = nullptr; diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp index eb95cf662..d411ac942 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp @@ -91,15 +91,17 @@ int32_t VideoDecoder::PushInputData(CodecBufferInfo &info) return AVCODEC_SAMPLE_ERR_OK; } -int32_t VideoDecoder::FreeOutputData(uint32_t bufferIndex) +int32_t VideoDecoder::FreeOutputData(uint32_t bufferIndex, bool renderOutput) { CHECK_AND_RETURN_RET_LOG(decoder_ != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Decoder is null"); int32_t ret = AVCODEC_SAMPLE_ERR_OK; if (isAVBufferMode_) { - ret = OH_VideoDecoder_FreeOutputBuffer(decoder_, bufferIndex); + ret = renderOutput ? OH_VideoDecoder_RenderOutputBuffer(decoder_, bufferIndex) : + OH_VideoDecoder_FreeOutputBuffer(decoder_, bufferIndex); } else { - ret = OH_VideoDecoder_FreeOutputData(decoder_, bufferIndex); + ret = renderOutput ? OH_VideoDecoder_RenderOutputData(decoder_, bufferIndex) : + OH_VideoDecoder_FreeOutputData(decoder_, bufferIndex); } CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Free output data failed"); return AVCODEC_SAMPLE_ERR_OK; diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 6d2b7d8ef..252e78d8b 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -16,7 +16,6 @@ #include "video_decoder_perf_test_sample.h" #include #include "refbase.h" -#include "iconsumer_surface.h" #include "window.h" #include "surface.h" @@ -35,25 +34,6 @@ constexpr uint8_t AVCC_FRAME_HEAD_LEN = 4; namespace OHOS { namespace MediaAVCodec { namespace Sample { -class SurfaceConsumer : public OHOS::IBufferConsumerListener { -public: - SurfaceConsumer(OHOS::sptr cs) : cs(cs) {}; - ~SurfaceConsumer() {} - void OnBufferAvailable() override - { - OHOS::sptr buffer; - int32_t flushFence; - cs->AcquireBuffer(buffer, flushFence, timestamp, damage); - - cs->ReleaseBuffer(buffer, -1); - } - -private: - int64_t timestamp = 0; - OHOS::Rect damage = {}; - OHOS::sptr cs {nullptr}; -}; - VideoDecoderPerfTestSample::~VideoDecoderPerfTestSample() { StartRelease(); @@ -216,7 +196,7 @@ void VideoDecoderPerfTestSample::OutputThread() DumpOutput(bufferInfo); - int32_t ret = videoDecoder_->FreeOutputData(bufferInfo.bufferIndex); + int32_t ret = videoDecoder_->FreeOutputData(bufferInfo.bufferIndex, !(sampleInfo_.codecRunMode & 0b01)); CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Decoder output thread out"); } OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); @@ -279,7 +259,7 @@ int32_t VideoDecoderPerfTestSample::ReadOneFrame(CodecBufferInfo &info) int32_t VideoDecoderPerfTestSample::CreateWindow(OHNativeWindow *&window) { auto consumer_ = OHOS::Surface::CreateSurfaceAsConsumer(); - OHOS::sptr listener = new SurfaceConsumer(consumer_); + OHOS::sptr listener = new SurfaceConsumer(consumer_, this); consumer_->RegisterConsumerListener(listener); auto producer = consumer_->GetProducer(); auto surface = OHOS::Surface::CreateSurfaceAsProducer(producer); @@ -305,12 +285,8 @@ void VideoDecoderPerfTestSample::ThreadSleep() static_cast>(lastPushTime - beforeSleepTime).count()); } -inline void VideoDecoderPerfTestSample::DumpOutput(const CodecBufferInfo &bufferInfo) +inline void VideoDecoderPerfTestSample::DumpOutput(uint8_t *bufferAddr, uint32_t bufferSize) { - if (!(sampleInfo_.needDumpOutput) || !(sampleInfo_.codecRunMode & 0b01)) { // 0b01: Buffer mode mask - return; - } - if (outputFile_ == nullptr) { using namespace std::string_literals; auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); @@ -324,10 +300,33 @@ inline void VideoDecoderPerfTestSample::DumpOutput(const CodecBufferInfo &buffer outputFile_ = nullptr; } } + outputFile_->write(reinterpret_cast(bufferAddr), bufferSize); +} + +inline void VideoDecoderPerfTestSample::DumpOutput(const CodecBufferInfo &bufferInfo) +{ + if (!(sampleInfo_.needDumpOutput) || !(sampleInfo_.codecRunMode & 0b01)) { // 0b01: Buffer mode mask + return; + } + auto bufferAddr = static_cast(sampleInfo_.codecRunMode) & 0b10 ? // 0b10: AVBuffer mode mask OH_AVBuffer_GetAddr(reinterpret_cast(bufferInfo.buffer)) : OH_AVMemory_GetAddr(reinterpret_cast(bufferInfo.buffer)); - outputFile_->write(reinterpret_cast(bufferAddr), bufferInfo.attr.size); + + DumpOutput(bufferAddr, bufferInfo.attr.size); +} + +void VideoDecoderPerfTestSample::SurfaceConsumer::OnBufferAvailable() +{ + if (sample_ == nullptr) { + return; + } + OHOS::sptr buffer; + int32_t flushFence; + surface_->AcquireBuffer(buffer, flushFence, timestamp_, damage_); + + sample_->DumpOutput(reinterpret_cast(buffer->GetVirAddr()), buffer->GetSize()); + surface_->ReleaseBuffer(buffer, -1); } } // Sample } // MediaAVCodec -- Gitee From 6c537287a7726c73bf6ff5a2450160117d34ee84 Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 19:12:33 +0800 Subject: [PATCH 40/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91support=20decoder=20sample=20dump=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Iaf1d99ffdeb5c130da8a3e4d62ad306d422615f9 --- .../sample/decoder/include/video_decoder_perf_test_sample.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index fe96dd513..569dfcb20 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -52,7 +52,8 @@ private: class SurfaceConsumer : public OHOS::IBufferConsumerListener { public: - SurfaceConsumer(OHOS::sptr surface, VideoDecoderPerfTestSample *sample) : surface_(surface) {}; + SurfaceConsumer(OHOS::sptr surface, VideoDecoderPerfTestSample *sample) + : surface_(surface), sample_(sample) {}; void OnBufferAvailable() override; private: -- Gitee From ee15e4fa814d51fc7c1140beb6c8484f10845280 Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 19:15:16 +0800 Subject: [PATCH 41/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91support=20decoder=20sample=20dump=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I017ff88df8e648e12b470ae3f093a1553275dfda --- .../sample/decoder/include/video_decoder_perf_test_sample.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h index 569dfcb20..263cc5aa7 100644 --- a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h +++ b/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h @@ -57,10 +57,10 @@ private: void OnBufferAvailable() override; private: - VideoDecoderPerfTestSample *sample_; int64_t timestamp_ = 0; OHOS::Rect damage_ = {}; OHOS::sptr surface_ {nullptr}; + VideoDecoderPerfTestSample *sample_; }; std::unique_ptr videoDecoder_ = nullptr; -- Gitee From 35529c2839016448a9c6938321ed4e842f91f492 Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 22:10:20 +0800 Subject: [PATCH 42/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91support=20sample=20limit=20=20numbers=20of=20?= =?UTF-8?q?processed=20frames?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Id6ff5deb01105a395d6745ca7dabbe4e3d23598d --- .../video_perf_test/common/include/sample_info.h | 5 +++-- .../decoder/video_decoder_perf_test_sample.cpp | 11 ++++++++--- .../encoder/video_encoder_perf_test_sample.cpp | 13 +++++++++---- .../video_perf_test/sample/helper/arg_parser.cpp | 12 +++++++++--- .../video_perf_test/sample/helper/sample_helper.cpp | 5 +++-- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_perf_test/common/include/sample_info.h index 6500a746e..abbdbeaeb 100644 --- a/test/unittest/video_perf_test/common/include/sample_info.h +++ b/test/unittest/video_perf_test/common/include/sample_info.h @@ -67,6 +67,7 @@ struct SampleInfo { OH_AVPixelFormat pixelFormat = AV_PIXEL_FORMAT_NV12; bool isHDRVivid = false; bool needDumpOutput = false; + uint32_t maxFrames = UINT32_MAX; }; struct CodecBufferInfo { @@ -89,12 +90,12 @@ class CodecUserData { public: SampleInfo *sampleInfo = nullptr; - int32_t inputFrameCount_ = 0; + uint32_t inputFrameCount_ = 0; std::mutex inputMutex_; std::condition_variable inputCond_; std::queue inputBufferInfoQueue_; - int32_t outputFrameCount_ = 0; + uint32_t outputFrameCount_ = 0; std::mutex outputMutex_; std::condition_variable outputCond_; std::queue outputBufferInfoQueue_; diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 252e78d8b..3b07b6d4b 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -171,7 +171,7 @@ void VideoDecoderPerfTestSample::InputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); } - AVCODEC_LOGI("Exit, frame count: %{public}d", context_->inputFrameCount_); + AVCODEC_LOGI("Exit, frame count: %{public}u", context_->inputFrameCount_); StartRelease(); } @@ -190,7 +190,7 @@ void VideoDecoderPerfTestSample::OutputThread() context_->outputBufferInfoQueue_.pop(); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); context_->outputFrameCount_++; - AVCODEC_LOGV("Out buffer count: %{public}d, size: %{public}d, flag: %{public}d, pts: %{public}" PRId64, + AVCODEC_LOGV("Out buffer count: %{public}u, size: %{public}d, flag: %{public}u, pts: %{public}" PRId64, context_->outputFrameCount_, bufferInfo.attr.size, bufferInfo.attr.flags, bufferInfo.attr.pts); lock.unlock(); @@ -201,7 +201,7 @@ void VideoDecoderPerfTestSample::OutputThread() } OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); OHOS::MediaAVCodec::AVCodecTrace::CounterTrace("SampleFrameCount", context_->outputFrameCount_); - AVCODEC_LOGI("Exit, frame count: %{public}d", context_->outputFrameCount_); + AVCODEC_LOGI("Exit, frame count: %{public}u", context_->outputFrameCount_); StartRelease(); } @@ -230,6 +230,11 @@ int32_t VideoDecoderPerfTestSample::ReadOneFrame(CodecBufferInfo &info) CHECK_AND_RETURN_RET_LOG(inputFile_ != nullptr && inputFile_->is_open(), AVCODEC_SAMPLE_ERR_ERROR, "Input file is not open!"); + if (context_->inputFrameCount_ > sampleInfo_.maxFrames) { + info.attr.flags = AVCODEC_BUFFER_FLAGS_EOS; + return AVCODEC_SAMPLE_ERR_OK; + } + char ch[AVCC_FRAME_HEAD_LEN] = {}; (void)inputFile_->read(ch, AVCC_FRAME_HEAD_LEN); // 0 1 2 3: avcc frame head byte offset; 8 16 24: avcc frame head bit offset diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index ffdbde802..1b700ffea 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -174,7 +174,7 @@ void VideoEncoderPerfTestSample::BufferInputThread() CHECK_AND_BREAK_LOG(ret == AVCODEC_SAMPLE_ERR_OK, "Push data failed, thread out"); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); } - AVCODEC_LOGI("Exit, frame count: %{public}d", context_->inputFrameCount_); + AVCODEC_LOGI("Exit, frame count: %{public}u", context_->inputFrameCount_); StartRelease(); } @@ -217,7 +217,7 @@ void VideoEncoderPerfTestSample::SurfaceInputThread() OH_NativeWindow_DestroyNativeWindowBuffer(buffer); } videoEncoder_->NotifyEndOfStream(); - AVCODEC_LOGI("Exit, frame count: %{public}d", context_->inputFrameCount_); + AVCODEC_LOGI("Exit, frame count: %{public}u", context_->inputFrameCount_); StartRelease(); } @@ -236,7 +236,7 @@ void VideoEncoderPerfTestSample::OutputThread() context_->outputBufferInfoQueue_.pop(); CHECK_AND_BREAK_LOG(!(bufferInfo.attr.flags & AVCODEC_BUFFER_FLAGS_EOS), "Catch EOS, thread out"); context_->outputFrameCount_++; - AVCODEC_LOGV("Out buffer count: %{public}d, size: %{public}d, flag: %{public}d, pts: %{public}" PRId64, + AVCODEC_LOGV("Out buffer count: %{public}u, size: %{public}d, flag: %{public}u, pts: %{public}" PRId64, context_->outputFrameCount_, bufferInfo.attr.size, bufferInfo.attr.flags, bufferInfo.attr.pts); lock.unlock(); @@ -247,7 +247,7 @@ void VideoEncoderPerfTestSample::OutputThread() } OHOS::MediaAVCodec::AVCodecTrace::TraceEnd("SampleWorkTime", FAKE_POINTER(this)); OHOS::MediaAVCodec::AVCodecTrace::CounterTrace("SampleFrameCount", context_->outputFrameCount_); - AVCODEC_LOGI("Exit, frame count: %{public}d", context_->outputFrameCount_); + AVCODEC_LOGI("Exit, frame count: %{public}u", context_->outputFrameCount_); StartRelease(); } @@ -276,6 +276,11 @@ int32_t VideoEncoderPerfTestSample::ReadOneFrame(uint8_t *bufferAddr, int32_t &b AVCODEC_SAMPLE_ERR_ERROR, "Input file is not open!"); CHECK_AND_RETURN_RET_LOG(bufferAddr != nullptr, AVCODEC_SAMPLE_ERR_ERROR, "Invalid buffer address"); + if (context_->inputFrameCount_ > sampleInfo_.maxFrames) { + flags = AVCODEC_BUFFER_FLAGS_EOS; + return AVCODEC_SAMPLE_ERR_OK; + } + bufferSize = GetBufferSize(); inputFile_->read(reinterpret_cast(bufferAddr), bufferSize); diff --git a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp index a33a870da..93b6f6bf6 100644 --- a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp +++ b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp @@ -35,6 +35,7 @@ enum DemoShortArgument : int { DEMO_ARG_REPEAT_TIMES, DEMO_ARG_HDR_VIVID_VIDEO, DEMO_ARG_NEED_DUMP_OUTPUT, + DEMO_ARG_MAX_FRAMES, }; constexpr struct option DEMO_LONG_ARGUMENT[] = { @@ -53,6 +54,7 @@ constexpr struct option DEMO_LONG_ARGUMENT[] = { {"repeat_times", required_argument, nullptr, DEMO_ARG_REPEAT_TIMES}, {"hdr_vivid_video", required_argument, nullptr, DEMO_ARG_HDR_VIVID_VIDEO}, {"need_dump_output", required_argument, nullptr, DEMO_ARG_NEED_DUMP_OUTPUT}, + {"max_frames", required_argument, nullptr, DEMO_ARG_MAX_FRAMES}, }; const std::string HELP_TEXT = @@ -76,10 +78,11 @@ R"HELP_TEXT(Video codec demo help: --repeat_times demo repeat times --hdr_vivid_video input file is hdr vivid video? (0: false; 1: true) --need_dump_output need to dump output stream? (0: false; 1: true) - + --max_frames number of frames to be processed + Example: --codec_type 0 --file input.h264 --mime video/avc --width 1280 --height 720 --framerate 30 --pixel_format 1 - --codec_run_mode 0 --frame_interval 0 --repeat_times 1 --hdr_vivid_video 0 --need_dump_output 0 + --codec_run_mode 0 --frame_interval 0 --repeat_times 1 --hdr_vivid_video 0 --need_dump_output 0 --max_frames 100 )HELP_TEXT"; void ShowHelp() @@ -134,7 +137,7 @@ SampleInfo ParseDemoArg(int argc, char *argv[]) info.frameInterval = std::stol(optarg); break; case DEMO_ARG_REPEAT_TIMES: - info.repeatTimes = std::stol(optarg); + info.repeatTimes = std::stoul(optarg); break; case DEMO_ARG_HDR_VIVID_VIDEO: info.isHDRVivid = std::stol(optarg); @@ -142,6 +145,9 @@ SampleInfo ParseDemoArg(int argc, char *argv[]) case DEMO_ARG_NEED_DUMP_OUTPUT: info.needDumpOutput = std::stol(optarg); break; + case DEMO_ARG_MAX_FRAMES: + info.maxFrames = std::stoul(optarg); + break; default: std::cout << "Unknow arg type: " << argType << ", value: " << optarg << std::endl; break; diff --git a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp index 14ee2f65f..7c9dca9a2 100644 --- a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp +++ b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp @@ -52,8 +52,9 @@ const std::unordered_map PIXEL_FORMAT_TO_STRING = void PrintSampleInfo(const OHOS::MediaAVCodec::Sample::SampleInfo &info) { AVCODEC_LOGI("====== Video sample config ======"); - AVCODEC_LOGI("codec type: %{public}s, codec run mode: %{public}s", - CODEC_TYPE_TO_STRING.at(info.codecType).c_str(), RUN_MODE_TO_STRING.at(info.codecRunMode).c_str()); + AVCODEC_LOGI("codec type: %{public}s, codec run mode: %{public}s, max frames: %{public}u", + CODEC_TYPE_TO_STRING.at(info.codecType).c_str(), RUN_MODE_TO_STRING.at(info.codecRunMode).c_str(), + info.maxFrames); AVCODEC_LOGI("input file: %{public}s", info.inputFilePath.c_str()); AVCODEC_LOGI("mime: %{public}s, %{public}d*%{public}d, %{public}.1ffps, %{public}.2fMbps, pixel format: %{public}s", info.codecMime.c_str(), info.videoWidth, info.videoHeight, info.frameRate, -- Gitee From d99ac8204010f250a34202267c4573e0aff56b80 Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 23:33:10 +0800 Subject: [PATCH 43/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I622959a9f22e16b948c9efbd6b11a4545d3151be --- services/dfx/BUILD.gn | 4 ++-- test/unittest/video_perf_test/common/sample_callback.cpp | 4 ++-- .../video_perf_test/sample/decoder/video_decoder.cpp | 2 +- .../sample/decoder/video_decoder_perf_test_sample.cpp | 4 ++-- .../video_perf_test/sample/encoder/video_encoder.cpp | 2 +- .../sample/encoder/video_encoder_perf_test_sample.cpp | 4 ++-- .../unittest/video_perf_test/sample/helper/arg_parser.cpp | 2 +- .../video_perf_test/sample/helper/sample_helper.cpp | 8 ++++---- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/services/dfx/BUILD.gn b/services/dfx/BUILD.gn index ac7f611dd..bc3f29f49 100644 --- a/services/dfx/BUILD.gn +++ b/services/dfx/BUILD.gn @@ -26,9 +26,9 @@ ohos_shared_library("av_codec_service_dfx") { sources = [ "avcodec_bitstream_dump.cpp", - "avcodec_trace.cpp", - "avcodec_sysevent.cpp", "avcodec_dump_utils.cpp", + "avcodec_sysevent.cpp", + "avcodec_trace.cpp", "avcodec_xcollie.cpp", ] diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_perf_test/common/sample_callback.cpp index 00987213d..a5b318771 100644 --- a/test/unittest/video_perf_test/common/sample_callback.cpp +++ b/test/unittest/video_perf_test/common/sample_callback.cpp @@ -42,7 +42,7 @@ void SampleCallback::OnCodecFormatChange(OH_AVCodec *codec, OH_AVFormat *format, OH_AVFormat_GetIntValue(format, OH_MD_KEY_WIDTH, &codecUserData->sampleInfo->videoWidth); OH_AVFormat_GetIntValue(format, OH_MD_KEY_HEIGHT, &codecUserData->sampleInfo->videoHeight); - AVCODEC_LOGW("On decoder format change, resolution: %{public}d*%{public}d", + AVCODEC_LOGW("On decoder format change, resolution: %{public}d*%{public}d", codecUserData->sampleInfo->videoWidth, codecUserData->sampleInfo->videoHeight); } @@ -59,7 +59,7 @@ void SampleCallback::OnInputBufferAvailable(OH_AVCodec *codec, uint32_t index, O } void SampleCallback::OnOutputBufferAvailable(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, - OH_AVCodecBufferAttr *attr, void *userData) + OH_AVCodecBufferAttr *attr, void *userData) { if (userData == nullptr) { return; diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp index d411ac942..dc32d6798 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp @@ -81,7 +81,7 @@ int32_t VideoDecoder::PushInputData(CodecBufferInfo &info) int32_t ret = AV_ERR_OK; if (isAVBufferMode_) { - ret = OH_AVBuffer_SetBufferAttr(reinterpret_cast(info.buffer),&info.attr); + ret = OH_AVBuffer_SetBufferAttr(reinterpret_cast(info.buffer), &info.attr); CHECK_AND_RETURN_RET_LOG(ret == AV_ERR_OK, AVCODEC_SAMPLE_ERR_ERROR, "Set avbuffer attr failed"); ret = OH_VideoDecoder_PushInputBuffer(decoder_, info.bufferIndex); } else { diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 3b07b6d4b..6ef898735 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -290,7 +290,7 @@ void VideoDecoderPerfTestSample::ThreadSleep() static_cast>(lastPushTime - beforeSleepTime).count()); } -inline void VideoDecoderPerfTestSample::DumpOutput(uint8_t *bufferAddr, uint32_t bufferSize) +void VideoDecoderPerfTestSample::DumpOutput(uint8_t *bufferAddr, uint32_t bufferSize) { if (outputFile_ == nullptr) { using namespace std::string_literals; @@ -308,7 +308,7 @@ inline void VideoDecoderPerfTestSample::DumpOutput(uint8_t *bufferAddr, uint32_t outputFile_->write(reinterpret_cast(bufferAddr), bufferSize); } -inline void VideoDecoderPerfTestSample::DumpOutput(const CodecBufferInfo &bufferInfo) +void VideoDecoderPerfTestSample::DumpOutput(const CodecBufferInfo &bufferInfo) { if (!(sampleInfo_.needDumpOutput) || !(sampleInfo_.codecRunMode & 0b01)) { // 0b01: Buffer mode mask return; diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp index 14f764fd8..70a01e38b 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp @@ -37,7 +37,7 @@ int32_t ToGraphicPixelFormat(int32_t avPixelFormat, bool isHDRVivid) if (isHDRVivid) { return GRAPHIC_PIXEL_FMT_YCBCR_P010; } - switch(avPixelFormat) { + switch (avPixelFormat) { case AV_PIXEL_FORMAT_RGBA: return GRAPHIC_PIXEL_FMT_RGBA_8888; case AV_PIXEL_FORMAT_YUVI420: diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp index 1b700ffea..1b36af10e 100644 --- a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp @@ -256,7 +256,7 @@ inline int32_t VideoEncoderPerfTestSample::GetBufferSize() int32_t size = sampleInfo_.pixelFormat == AV_PIXEL_FORMAT_RGBA ? sampleInfo_.videoWidth * sampleInfo_.videoHeight * 3 : // RGBA buffer size sampleInfo_.videoWidth * sampleInfo_.videoHeight * 3 / 2; // YUV420 buffer size - return sampleInfo_.isHDRVivid ? size * 2 : size;; + return sampleInfo_.isHDRVivid ? size * 2 : size; } int32_t VideoEncoderPerfTestSample::ReadOneFrame(CodecBufferInfo &info) @@ -317,7 +317,7 @@ void VideoEncoderPerfTestSample::ThreadSleep() static_cast>(lastPushTime - beforeSleepTime).count()); } -inline void VideoEncoderPerfTestSample::DumpOutput(const CodecBufferInfo &bufferInfo) +void VideoEncoderPerfTestSample::DumpOutput(const CodecBufferInfo &bufferInfo) { if (!sampleInfo_.needDumpOutput) { return; diff --git a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp index 93b6f6bf6..08bdf8a6c 100644 --- a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp +++ b/test/unittest/video_perf_test/sample/helper/arg_parser.cpp @@ -67,7 +67,7 @@ R"HELP_TEXT(Video codec demo help: --width video width --height video height --framerate video framerate - --pixel_format 1: YUVI420 2: NV12 3: NV21 + --pixel_format 1: YUVI420 2: NV12 3: NV21 4: SURFACE_FORMAT 5: RGBA --bitrate encoder bitrate (bps) --bitrate_mode encoder bitrate mode (0: CBR; 1: VBR; 2: CQ) diff --git a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp index 7c9dca9a2..a8fb5b042 100644 --- a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp +++ b/test/unittest/video_perf_test/sample/helper/sample_helper.cpp @@ -30,10 +30,10 @@ const std::unordered_map COD }; const std::unordered_map RUN_MODE_TO_STRING = { - {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_AVBUFFER, "Buffer AVBuffer"}, - {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_SHARED_MEMORY, "Buffer SharedMemory"}, - {OHOS::MediaAVCodec::Sample::CodecRunMode::SURFACE_ORIGIN, "Surface Origin"}, - {OHOS::MediaAVCodec::Sample::CodecRunMode::SURFACE_AVBUFFER, "Surface AVBuffer"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_AVBUFFER, "Buffer AVBuffer"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::BUFFER_SHARED_MEMORY, "Buffer SharedMemory"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::SURFACE_ORIGIN, "Surface Origin"}, + {OHOS::MediaAVCodec::Sample::CodecRunMode::SURFACE_AVBUFFER, "Surface AVBuffer"}, }; const std::unordered_map BOOL_TO_STRING = { -- Gitee From 8f6ca4da726bbdd5139dbc820b104328528e1b1d Mon Sep 17 00:00:00 2001 From: West Date: Mon, 25 Dec 2023 23:50:31 +0800 Subject: [PATCH 44/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91support=20video=20codec=20demo=20repeat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Ibb445037923b2db2190364044fa6040ca19bb9ec --- .../video_perf_test/demo/video_codec_demo.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/unittest/video_perf_test/demo/video_codec_demo.cpp b/test/unittest/video_perf_test/demo/video_codec_demo.cpp index 1bc27e397..056d12a92 100644 --- a/test/unittest/video_perf_test/demo/video_codec_demo.cpp +++ b/test/unittest/video_perf_test/demo/video_codec_demo.cpp @@ -29,10 +29,14 @@ int main(int argc, char *argv[]) return 1; } - int ret = RunSample(info); - if (ret != AVCODEC_SAMPLE_ERR_OK) { - std::cout << "Demo run failed!" << std::endl; - return 1; + for (uint32_t times = 1; times <= info.repeatTimes; times++) { + std::cout << "\rRepeat times: (" << times << "/" << info.repeatTimes << ")" << std::flush; + + int ret = RunSample(info); + if (ret != AVCODEC_SAMPLE_ERR_OK) { + std::cout << "Demo run failed!" << std::endl; + return 1; + } } return 0; } \ No newline at end of file -- Gitee From 27170880261f26e5f96426dc7f0b90b14bf4e5b3 Mon Sep 17 00:00:00 2001 From: West Date: Tue, 26 Dec 2023 00:24:11 +0800 Subject: [PATCH 45/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Iffd7a647aed425f80f6f4e9fe11bbece0e97c3c2 --- test/BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/BUILD.gn b/test/BUILD.gn index 1c326a58d..3f358102f 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -55,9 +55,7 @@ group("av_codec_unit_test") { ] } if (av_codec_support_codec_perf_test) { - deps += [ - "unittest/video_perf_test:video_perf_test" - ] + deps += [ "unittest/video_perf_test:video_perf_test" ] } } } -- Gitee From 704eaffb8bb04f999a85da84ebcec3607abee555 Mon Sep 17 00:00:00 2001 From: West Date: Tue, 26 Dec 2023 09:06:17 +0800 Subject: [PATCH 46/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91support=20decoder=20sample=20dump=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I545fe58700d8791f087556214f96c9abd89b8bf7 --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 6ef898735..430a0a88e 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -330,7 +330,9 @@ void VideoDecoderPerfTestSample::SurfaceConsumer::OnBufferAvailable() int32_t flushFence; surface_->AcquireBuffer(buffer, flushFence, timestamp_, damage_); - sample_->DumpOutput(reinterpret_cast(buffer->GetVirAddr()), buffer->GetSize()); + if (sample_->sampleInfo_.needDumpOutput) { + sample_->DumpOutput(reinterpret_cast(buffer->GetVirAddr()), buffer->GetSize()); + } surface_->ReleaseBuffer(buffer, -1); } } // Sample -- Gitee From a9ce79564b95c41affe13ae0283d4d9e245a18ef Mon Sep 17 00:00:00 2001 From: West Date: Tue, 26 Dec 2023 10:05:15 +0800 Subject: [PATCH 47/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91support=20decoder=20sample=20dump=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I9c8e7ea5f35cab53e37d9101b987dedd0e0a35fd --- .../sample/decoder/video_decoder_perf_test_sample.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp index 430a0a88e..91b6026ea 100644 --- a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp +++ b/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp @@ -297,7 +297,7 @@ void VideoDecoderPerfTestSample::DumpOutput(uint8_t *bufferAddr, uint32_t buffer auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::string outputName = "VideoDecoderOut_"s + ToString(static_cast(sampleInfo_.pixelFormat)) + "_" + - std::to_string(sampleInfo_.videoWidth) + "*" + std::to_string(sampleInfo_.videoHeight) + "_" + + std::to_string(sampleInfo_.videoWidth) + "_" + std::to_string(sampleInfo_.videoHeight) + "_" + std::to_string(time) + ".yuv"; outputFile_ = std::make_unique(outputName, std::ios::out | std::ios::trunc); -- Gitee From 54976a5236c04797d03d262902aefa3fdff5ada1 Mon Sep 17 00:00:00 2001 From: West Date: Tue, 26 Dec 2023 19:52:13 +0800 Subject: [PATCH 48/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I83c5215f8d68a6bf6e0c86af0ca3c8d178cfd510 --- test/unittest/video_perf_test/BUILD.gn | 28 +++++++++++--------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/test/unittest/video_perf_test/BUILD.gn b/test/unittest/video_perf_test/BUILD.gn index bb092ca56..8cf803a9d 100644 --- a/test/unittest/video_perf_test/BUILD.gn +++ b/test/unittest/video_perf_test/BUILD.gn @@ -44,35 +44,35 @@ config("video_sample_config") { "./sample/encoder/include", "./sample/helper/include", "$av_codec_root_dir/interfaces/kits/c", - "$av_codec_root_dir/services/dfx/include" + "$av_codec_root_dir/services/dfx/include", ] } ohos_source_set("video_sample") { sources = [ "../../../services/dfx/avcodec_trace.cpp", - "./common/sample_callback.cpp", "./common/av_codec_sample_log.cpp", - "./sample/decoder/video_decoder_perf_test_sample.cpp", + "./common/sample_callback.cpp", "./sample/decoder/video_decoder.cpp", - "./sample/encoder/video_encoder_perf_test_sample.cpp", + "./sample/decoder/video_decoder_perf_test_sample.cpp", "./sample/encoder/video_encoder.cpp", - "./sample/helper/arg_parser.cpp", + "./sample/encoder/video_encoder_perf_test_sample.cpp", "./sample/helper/arg_checker.cpp", + "./sample/helper/arg_parser.cpp", "./sample/helper/sample_helper.cpp", ] deps = [ "$av_codec_root_dir/interfaces/kits/c:capi_packages" ] - public_configs = [":video_sample_config"] + public_configs = [ ":video_sample_config" ] external_deps = [ "c_utils:utils", "graphic_2d:surface", "hilog:libhilog", "histreamer:media_foundation", - "init:libbegetutil", "hitrace:hitrace_meter", + "init:libbegetutil", ] subsystem_name = "multimedia" @@ -82,17 +82,15 @@ ohos_source_set("video_sample") { ohos_unittest("video_perf_test") { module_out_path = "av_codec/unittest/perf_test" - sources = [ - "./test_suilt/video_perf_test_suilt.cpp", - ] + sources = [ "./test_suilt/video_perf_test_suilt.cpp" ] deps = [ ":video_sample" ] external_deps = [ "c_utils:utils", + "graphic_2d:surface", "hilog:libhilog", "histreamer:media_foundation", - "graphic_2d:surface", ] subsystem_name = "multimedia" @@ -100,19 +98,17 @@ ohos_unittest("video_perf_test") { } ohos_executable("video_codec_demo") { - sources = [ - "./demo/video_codec_demo.cpp", - ] + sources = [ "./demo/video_codec_demo.cpp" ] deps = [ ":video_sample" ] external_deps = [ "c_utils:utils", + "graphic_2d:surface", "hilog:libhilog", "histreamer:media_foundation", - "graphic_2d:surface", ] subsystem_name = "multimedia" part_name = "av_codec" -} \ No newline at end of file +} -- Gitee From 4ff55663ab088ae70edb925a78e94c5c8ea1ce2c Mon Sep 17 00:00:00 2001 From: West Date: Tue, 26 Dec 2023 20:36:41 +0800 Subject: [PATCH 49/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: Idba2a2faa11f5c9204fb282f2fa32dde9488d181 --- test/BUILD.gn | 4 ++-- test/unittest/{ => video_test}/video_perf_test/BUILD.gn | 2 +- .../video_perf_test/common/av_codec_sample_log.cpp | 0 .../video_perf_test/common/include/av_codec_sample_error.h | 0 .../video_perf_test/common/include/av_codec_sample_log.h | 0 .../video_perf_test/common/include/sample_callback.h | 0 .../video_perf_test/common/include/sample_info.h | 0 .../video_perf_test/common/sample_callback.cpp | 0 .../video_perf_test/demo/video_codec_demo.cpp | 0 .../video_perf_test/sample/base/video_perf_test_sample_base.h | 0 .../video_perf_test/sample/decoder/include/video_decoder.h | 0 .../sample/decoder/include/video_decoder_perf_test_sample.h | 0 .../video_perf_test/sample/decoder/video_decoder.cpp | 0 .../sample/decoder/video_decoder_perf_test_sample.cpp | 0 .../video_perf_test/sample/encoder/include/video_encoder.h | 0 .../sample/encoder/include/video_encoder_perf_test_sample.h | 0 .../video_perf_test/sample/encoder/video_encoder.cpp | 0 .../sample/encoder/video_encoder_perf_test_sample.cpp | 0 .../video_perf_test/sample/helper/arg_checker.cpp | 0 .../video_perf_test/sample/helper/arg_parser.cpp | 0 .../video_perf_test/sample/helper/include/arg_checker.h | 0 .../video_perf_test/sample/helper/include/arg_parser.h | 0 .../video_perf_test/sample/helper/include/sample_helper.h | 0 .../video_perf_test/sample/helper/sample_helper.cpp | 0 .../video_perf_test/test_suilt/video_perf_test_suilt.cpp | 0 25 files changed, 3 insertions(+), 3 deletions(-) rename test/unittest/{ => video_test}/video_perf_test/BUILD.gn (98%) rename test/unittest/{ => video_test}/video_perf_test/common/av_codec_sample_log.cpp (100%) rename test/unittest/{ => video_test}/video_perf_test/common/include/av_codec_sample_error.h (100%) rename test/unittest/{ => video_test}/video_perf_test/common/include/av_codec_sample_log.h (100%) rename test/unittest/{ => video_test}/video_perf_test/common/include/sample_callback.h (100%) rename test/unittest/{ => video_test}/video_perf_test/common/include/sample_info.h (100%) rename test/unittest/{ => video_test}/video_perf_test/common/sample_callback.cpp (100%) rename test/unittest/{ => video_test}/video_perf_test/demo/video_codec_demo.cpp (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/base/video_perf_test_sample_base.h (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/decoder/include/video_decoder.h (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/decoder/video_decoder.cpp (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/encoder/include/video_encoder.h (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/encoder/video_encoder.cpp (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/helper/arg_checker.cpp (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/helper/arg_parser.cpp (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/helper/include/arg_checker.h (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/helper/include/arg_parser.h (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/helper/include/sample_helper.h (100%) rename test/unittest/{ => video_test}/video_perf_test/sample/helper/sample_helper.cpp (100%) rename test/unittest/{ => video_test}/video_perf_test/test_suilt/video_perf_test_suilt.cpp (100%) diff --git a/test/BUILD.gn b/test/BUILD.gn index 3f358102f..b8c013327 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -19,7 +19,7 @@ group("av_codec_demo_test") { deps = [] if (av_codec_support_test) { deps += [ "nativedemo:av_codec_demo" ] - deps += [ "unittest/video_perf_test:video_codec_demo" ] + deps += [ "unittest/video_test/video_perf_test:video_codec_demo" ] } } @@ -55,7 +55,7 @@ group("av_codec_unit_test") { ] } if (av_codec_support_codec_perf_test) { - deps += [ "unittest/video_perf_test:video_perf_test" ] + deps += [ "unittest/video_test/video_perf_test:video_perf_test" ] } } } diff --git a/test/unittest/video_perf_test/BUILD.gn b/test/unittest/video_test/video_perf_test/BUILD.gn similarity index 98% rename from test/unittest/video_perf_test/BUILD.gn rename to test/unittest/video_test/video_perf_test/BUILD.gn index 8cf803a9d..1ab522edd 100644 --- a/test/unittest/video_perf_test/BUILD.gn +++ b/test/unittest/video_test/video_perf_test/BUILD.gn @@ -50,7 +50,7 @@ config("video_sample_config") { ohos_source_set("video_sample") { sources = [ - "../../../services/dfx/avcodec_trace.cpp", + "../../../../services/dfx/avcodec_trace.cpp", "./common/av_codec_sample_log.cpp", "./common/sample_callback.cpp", "./sample/decoder/video_decoder.cpp", diff --git a/test/unittest/video_perf_test/common/av_codec_sample_log.cpp b/test/unittest/video_test/video_perf_test/common/av_codec_sample_log.cpp similarity index 100% rename from test/unittest/video_perf_test/common/av_codec_sample_log.cpp rename to test/unittest/video_test/video_perf_test/common/av_codec_sample_log.cpp diff --git a/test/unittest/video_perf_test/common/include/av_codec_sample_error.h b/test/unittest/video_test/video_perf_test/common/include/av_codec_sample_error.h similarity index 100% rename from test/unittest/video_perf_test/common/include/av_codec_sample_error.h rename to test/unittest/video_test/video_perf_test/common/include/av_codec_sample_error.h diff --git a/test/unittest/video_perf_test/common/include/av_codec_sample_log.h b/test/unittest/video_test/video_perf_test/common/include/av_codec_sample_log.h similarity index 100% rename from test/unittest/video_perf_test/common/include/av_codec_sample_log.h rename to test/unittest/video_test/video_perf_test/common/include/av_codec_sample_log.h diff --git a/test/unittest/video_perf_test/common/include/sample_callback.h b/test/unittest/video_test/video_perf_test/common/include/sample_callback.h similarity index 100% rename from test/unittest/video_perf_test/common/include/sample_callback.h rename to test/unittest/video_test/video_perf_test/common/include/sample_callback.h diff --git a/test/unittest/video_perf_test/common/include/sample_info.h b/test/unittest/video_test/video_perf_test/common/include/sample_info.h similarity index 100% rename from test/unittest/video_perf_test/common/include/sample_info.h rename to test/unittest/video_test/video_perf_test/common/include/sample_info.h diff --git a/test/unittest/video_perf_test/common/sample_callback.cpp b/test/unittest/video_test/video_perf_test/common/sample_callback.cpp similarity index 100% rename from test/unittest/video_perf_test/common/sample_callback.cpp rename to test/unittest/video_test/video_perf_test/common/sample_callback.cpp diff --git a/test/unittest/video_perf_test/demo/video_codec_demo.cpp b/test/unittest/video_test/video_perf_test/demo/video_codec_demo.cpp similarity index 100% rename from test/unittest/video_perf_test/demo/video_codec_demo.cpp rename to test/unittest/video_test/video_perf_test/demo/video_codec_demo.cpp diff --git a/test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h b/test/unittest/video_test/video_perf_test/sample/base/video_perf_test_sample_base.h similarity index 100% rename from test/unittest/video_perf_test/sample/base/video_perf_test_sample_base.h rename to test/unittest/video_test/video_perf_test/sample/base/video_perf_test_sample_base.h diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder.h b/test/unittest/video_test/video_perf_test/sample/decoder/include/video_decoder.h similarity index 100% rename from test/unittest/video_perf_test/sample/decoder/include/video_decoder.h rename to test/unittest/video_test/video_perf_test/sample/decoder/include/video_decoder.h diff --git a/test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h b/test/unittest/video_test/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h similarity index 100% rename from test/unittest/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h rename to test/unittest/video_test/video_perf_test/sample/decoder/include/video_decoder_perf_test_sample.h diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder.cpp b/test/unittest/video_test/video_perf_test/sample/decoder/video_decoder.cpp similarity index 100% rename from test/unittest/video_perf_test/sample/decoder/video_decoder.cpp rename to test/unittest/video_test/video_perf_test/sample/decoder/video_decoder.cpp diff --git a/test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp b/test/unittest/video_test/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp similarity index 100% rename from test/unittest/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp rename to test/unittest/video_test/video_perf_test/sample/decoder/video_decoder_perf_test_sample.cpp diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder.h b/test/unittest/video_test/video_perf_test/sample/encoder/include/video_encoder.h similarity index 100% rename from test/unittest/video_perf_test/sample/encoder/include/video_encoder.h rename to test/unittest/video_test/video_perf_test/sample/encoder/include/video_encoder.h diff --git a/test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h b/test/unittest/video_test/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h similarity index 100% rename from test/unittest/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h rename to test/unittest/video_test/video_perf_test/sample/encoder/include/video_encoder_perf_test_sample.h diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder.cpp b/test/unittest/video_test/video_perf_test/sample/encoder/video_encoder.cpp similarity index 100% rename from test/unittest/video_perf_test/sample/encoder/video_encoder.cpp rename to test/unittest/video_test/video_perf_test/sample/encoder/video_encoder.cpp diff --git a/test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp b/test/unittest/video_test/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp similarity index 100% rename from test/unittest/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp rename to test/unittest/video_test/video_perf_test/sample/encoder/video_encoder_perf_test_sample.cpp diff --git a/test/unittest/video_perf_test/sample/helper/arg_checker.cpp b/test/unittest/video_test/video_perf_test/sample/helper/arg_checker.cpp similarity index 100% rename from test/unittest/video_perf_test/sample/helper/arg_checker.cpp rename to test/unittest/video_test/video_perf_test/sample/helper/arg_checker.cpp diff --git a/test/unittest/video_perf_test/sample/helper/arg_parser.cpp b/test/unittest/video_test/video_perf_test/sample/helper/arg_parser.cpp similarity index 100% rename from test/unittest/video_perf_test/sample/helper/arg_parser.cpp rename to test/unittest/video_test/video_perf_test/sample/helper/arg_parser.cpp diff --git a/test/unittest/video_perf_test/sample/helper/include/arg_checker.h b/test/unittest/video_test/video_perf_test/sample/helper/include/arg_checker.h similarity index 100% rename from test/unittest/video_perf_test/sample/helper/include/arg_checker.h rename to test/unittest/video_test/video_perf_test/sample/helper/include/arg_checker.h diff --git a/test/unittest/video_perf_test/sample/helper/include/arg_parser.h b/test/unittest/video_test/video_perf_test/sample/helper/include/arg_parser.h similarity index 100% rename from test/unittest/video_perf_test/sample/helper/include/arg_parser.h rename to test/unittest/video_test/video_perf_test/sample/helper/include/arg_parser.h diff --git a/test/unittest/video_perf_test/sample/helper/include/sample_helper.h b/test/unittest/video_test/video_perf_test/sample/helper/include/sample_helper.h similarity index 100% rename from test/unittest/video_perf_test/sample/helper/include/sample_helper.h rename to test/unittest/video_test/video_perf_test/sample/helper/include/sample_helper.h diff --git a/test/unittest/video_perf_test/sample/helper/sample_helper.cpp b/test/unittest/video_test/video_perf_test/sample/helper/sample_helper.cpp similarity index 100% rename from test/unittest/video_perf_test/sample/helper/sample_helper.cpp rename to test/unittest/video_test/video_perf_test/sample/helper/sample_helper.cpp diff --git a/test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp b/test/unittest/video_test/video_perf_test/test_suilt/video_perf_test_suilt.cpp similarity index 100% rename from test/unittest/video_perf_test/test_suilt/video_perf_test_suilt.cpp rename to test/unittest/video_test/video_perf_test/test_suilt/video_perf_test_suilt.cpp -- Gitee From 960da73d41e9e97bab57e3ebee636e2ddf373b88 Mon Sep 17 00:00:00 2001 From: West Date: Tue, 26 Dec 2023 20:53:17 +0800 Subject: [PATCH 50/50] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BF=AE=E6=94=B9=E7=BC=96=E8=AF=91=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: West Change-Id: I164a6ae1dd8299c5ed4ef11aa8516c349ae3b980 --- .../audio_decoder/g711mu/audio_g711mu_decoder_plugin.cpp | 1 - .../audio_encoder/g711mu/audio_g711mu_encoder_plugin.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/g711mu/audio_g711mu_decoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/g711mu/audio_g711mu_decoder_plugin.cpp index 2d622ecef..ef3f3fed7 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/g711mu/audio_g711mu_decoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_decoder/g711mu/audio_g711mu_decoder_plugin.cpp @@ -16,7 +16,6 @@ #include "audio_g711mu_decoder_plugin.h" #include "avcodec_audio_common.h" #include "avcodec_codec_name.h" -#include "avcodec_dfx.h" #include "avcodec_log.h" #include "avcodec_mime_type.h" #include "plugin/codec_plugin.h" diff --git a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/g711mu/audio_g711mu_encoder_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/g711mu/audio_g711mu_encoder_plugin.cpp index 7dfd6d86e..d327876c2 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/g711mu/audio_g711mu_encoder_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/audio_encoder/g711mu/audio_g711mu_encoder_plugin.cpp @@ -16,7 +16,6 @@ #include "audio_g711mu_encoder_plugin.h" #include "avcodec_audio_common.h" #include "avcodec_codec_name.h" -#include "avcodec_dfx.h" #include "avcodec_log.h" #include "avcodec_mime_type.h" #include "plugin/codec_plugin.h" -- Gitee