From 4316acbbf10b15858a3a89fd15fbea194a68d5df Mon Sep 17 00:00:00 2001 From: pwx1285814 Date: Wed, 19 Jun 2024 21:31:55 +0800 Subject: [PATCH] =?UTF-8?q?avcodec=E6=8E=A5=E5=8F=A3=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: pwx1285814 Change-Id: I8eff91daad8b20cf0005f2bc4576492ad6d2518a Signed-off-by: pwx1285814 --- bundle.json | 3 +- common/include/dscreen_constants.h | 4 +- common/include/dscreen_json_util.h | 3 +- common/src/dscreen_json_util.cpp | 11 +- distributedscreen.gni | 3 +- screenhandler/BUILD.gn | 5 +- screenhandler/src/dscreen_handler.cpp | 25 ++-- .../test/unittest/screenhandler/BUILD.gn | 5 +- .../test/unittest/decision_center/BUILD.gn | 5 +- .../common/test/unittest/imageJpeg/BUILD.gn | 5 +- .../test/unittest/utils/video_param_test.cpp | 12 +- services/common/utils/include/video_param.h | 8 +- services/common/utils/src/video_param.cpp | 10 +- services/screendemo/BUILD.gn | 3 +- services/screendemo/decoder_demo.cpp | 44 +++--- services/screendemo/decoder_demo.h | 16 ++- services/screendemo/test.cpp | 4 +- services/screenservice/sinkservice/BUILD.gn | 4 +- .../screenregionmgr/1.0/src/screenregion.cpp | 4 +- .../screenregionmgr/2.0/src/screenregion.cpp | 5 +- services/screenservice/sourceservice/BUILD.gn | 5 +- .../dscreenmgr/1.0/src/dscreen.cpp | 43 +++--- .../dscreenmgr/2.0/src/dscreen_manager.cpp | 3 +- .../1.0/src/screenregion_test.cpp | 4 +- .../sinkservice/screenregionmgr/BUILD.gn | 4 +- .../dscreenmgr/1.0/src/dscreen_test.cpp | 4 +- .../1.0/src/screen_manager_adapter_test.cpp | 4 +- .../dscreenmgr/2.0/src/dscreen_test.cpp | 6 +- .../sourceservice/dscreenmgr/BUILD.gn | 6 +- .../decoder/include/image_decoder_callback.h | 15 +- .../decoder/include/image_sink_decoder.h | 26 ++-- .../decoder/src/image_decoder_callback.cpp | 14 +- .../decoder/src/image_sink_decoder.cpp | 134 +++++++++--------- .../screentransport/screensinktrans/BUILD.gn | 5 +- .../encoder/include/image_encoder_callback.h | 15 +- .../encoder/include/image_source_encoder.h | 21 +-- .../encoder/src/image_encoder_callback.cpp | 14 +- .../encoder/src/image_source_encoder.cpp | 72 ++++------ .../screensourcetrans/BUILD.gn | 5 +- .../onbufferavailable_fuzzer/BUILD.gn | 5 +- .../onbufferavailable_fuzzer.cpp | 4 +- .../onbufferavailable_fuzzer/BUILD.gn | 5 +- .../onerror_fuzzer/BUILD.gn | 5 +- .../onerror_fuzzer/onerror_fuzzer.cpp | 8 +- .../oninputbufferavailable_fuzzer/BUILD.gn | 5 +- .../oninputbufferavailable_fuzzer.cpp | 7 +- .../onoutputbufferavailable_fuzzer/BUILD.gn | 5 +- .../onoutputbufferavailable_fuzzer.cpp | 11 +- .../onoutputformatchanged_fuzzer/BUILD.gn | 5 +- .../onoutputformatchanged_fuzzer.cpp | 6 +- .../unittest/screensinkprocessor/BUILD.gn | 5 +- .../include/image_sink_decoder_test.h | 3 +- .../include/image_sink_processor_test.h | 3 +- .../src/image_sink_decoder_test.cpp | 82 +++++------ .../src/image_sink_processor_test.cpp | 18 ++- .../test/unittest/screensinktrans/BUILD.gn | 5 +- .../src/screen_sink_trans_test.cpp | 10 +- .../unittest/screensourceprocessor/BUILD.gn | 5 +- .../src/image_source_encoder_test.cpp | 96 +++++-------- .../src/image_source_processor_test.cpp | 12 +- .../test/unittest/screensourcetrans/BUILD.gn | 5 +- .../src/screen_source_trans_test.cpp | 4 +- .../unittest/screentranstestutils/BUILD.gn | 5 +- .../include/screentrans_test_utils.h | 4 +- .../src/screen_callback_test.cpp | 28 ++-- .../softbusadapter/src/softbus_adapter.cpp | 6 +- 66 files changed, 468 insertions(+), 468 deletions(-) diff --git a/bundle.json b/bundle.json index 69c5530d..7a920fa8 100644 --- a/bundle.json +++ b/bundle.json @@ -28,6 +28,7 @@ "components": [ "access_token", "accessibility", + "av_codec", "dsoftbus", "hisysevent", "init", @@ -36,12 +37,12 @@ "input", "graphic_2d", "graphic_surface", + "media_foundation", "samgr", "safwk", "hicollie", "hitrace", "c_utils", - "player_framework", "window_manager", "distributed_hardware_fwk", "libyuv" diff --git a/common/include/dscreen_constants.h b/common/include/dscreen_constants.h index bd3ec79d..b76ed779 100644 --- a/common/include/dscreen_constants.h +++ b/common/include/dscreen_constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -208,7 +208,7 @@ constexpr int32_t PARTIAL_REFRESH_ENABLED_VALUE = 1; constexpr uint32_t MAX_MESSAGES_LEN = 40 * 1024 * 1024; constexpr float DEFAULT_DENSITY = 2.0; constexpr int32_t DEFAULT_SCREEN_FLAGS = 0; -constexpr uint32_t DEFAULT_FPS = 60; +constexpr double DEFAULT_FPS = 60.0; constexpr int32_t DIRTY_MAX_SIZE = 10; constexpr uint8_t DEFAULT_CODECTYPE = VIDEO_CODEC_TYPE_VIDEO_H264; constexpr uint8_t DEFAULT_VIDEO_FORMAT = VIDEO_DATA_FORMAT_NV12; diff --git a/common/include/dscreen_json_util.h b/common/include/dscreen_json_util.h index 877b64f0..0a1d7e97 100644 --- a/common/include/dscreen_json_util.h +++ b/common/include/dscreen_json_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -24,6 +24,7 @@ bool IsString(const nlohmann::json &jsonObj, const std::string &key); bool IsUInt8(const nlohmann::json &jsonObj, const std::string &key); bool IsInt32(const nlohmann::json &jsonObj, const std::string &key); bool IsUInt32(const nlohmann::json &jsonObj, const std::string &key); +bool IsFloat(const nlohmann::json &jsonObj, const std::string &key); bool IsInt64(const nlohmann::json &jsonObj, const std::string &key); bool IsUInt64(const nlohmann::json &jsonObj, const std::string &key); bool IsArray(const nlohmann::json &jsonObj, const std::string &key); diff --git a/common/src/dscreen_json_util.cpp b/common/src/dscreen_json_util.cpp index 12bb5a8d..1d4ab3d5 100644 --- a/common/src/dscreen_json_util.cpp +++ b/common/src/dscreen_json_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -76,6 +76,15 @@ bool IsUInt64(const nlohmann::json &jsonObj, const std::string &key) return res; } +bool IsFloat(const nlohmann::json &jsonObj, const std::string &key) +{ + bool res = jsonObj.contains(key) && jsonObj[key].is_number_float(); + if (!res) { + DHLOGE("the key %s in jsonObj is invalid.", key.c_str()); + } + return res; +} + bool IsArray(const nlohmann::json &jsonObj, const std::string &key) { bool res = jsonObj.contains(key) && jsonObj[key].is_array(); diff --git a/distributedscreen.gni b/distributedscreen.gni index 9b03bc42..13f1fdd4 100644 --- a/distributedscreen.gni +++ b/distributedscreen.gni @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -16,7 +16,6 @@ distributedhardwarefwk_path = "//foundation/distributedhardware/distributed_hardware_fwk" fuzz_test_path = "distributed_screen/distributed_screen" windowmanager_path = "//foundation/window/window_manager" -mediastandard_path = "//foundation/multimedia/player_framework" driver_path = "//drivers/peripheral/display" ipc_path = "//foundation/communication/ipc" common_path = "${distributedscreen_path}/common" diff --git a/screenhandler/BUILD.gn b/screenhandler/BUILD.gn index e77609ba..b2b0a4f2 100644 --- a/screenhandler/BUILD.gn +++ b/screenhandler/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -47,11 +47,12 @@ ohos_shared_library("distributed_screen_handler") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", "graphic_surface:surface", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", "window_manager:libdm", ] diff --git a/screenhandler/src/dscreen_handler.cpp b/screenhandler/src/dscreen_handler.cpp index 63e5507a..4d3cb452 100644 --- a/screenhandler/src/dscreen_handler.cpp +++ b/screenhandler/src/dscreen_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -213,22 +213,23 @@ std::string DScreenHandler::QueryCodecInfo() } // query codec info - std::shared_ptr codecList = Media::AVCodecListFactory::CreateAVCodecList(); + std::shared_ptr codecList = MediaAVCodec::AVCodecListFactory::CreateAVCodecList(); if (codecList == nullptr) { + DHLOGE("Create avCodecList failed."); return codecInfoStr_; } - std::vector> caps = codecList->GetVideoEncoderCaps(); + const std::vector encoderName = {std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC), + std::string(MediaAVCodec::CodecMimeType::VIDEO_HEVC)}; json codecTypeArray = json::array(); - for (const auto &cap : caps) { - if (cap == nullptr) { - continue; - } - std::shared_ptr codecInfo = cap->GetCodecInfo(); - if (codecInfo == nullptr) { - continue; - } - codecTypeArray.push_back(codecInfo->GetName()); + for (const auto &coder : encoderName) { + MediaAVCodec::CapabilityData *capData = codecList->GetCapability(coder, true, + MediaAVCodec::AVCodecCategory::AVCODEC_HARDWARE); + if (capData == nullptr) { + continue; + } + std::string mimeType = capData->mimeType; + codecTypeArray.push_back(mimeType); } codecInfoStr_ = codecTypeArray.dump(); diff --git a/screenhandler/test/unittest/screenhandler/BUILD.gn b/screenhandler/test/unittest/screenhandler/BUILD.gn index 6e9a450d..69f15b3b 100644 --- a/screenhandler/test/unittest/screenhandler/BUILD.gn +++ b/screenhandler/test/unittest/screenhandler/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -48,11 +48,12 @@ ohos_unittest("DscreenHandlerTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "graphic_2d:libgraphic_utils", "graphic_surface:surface", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", "window_manager:libdm", ] diff --git a/services/common/test/unittest/decision_center/BUILD.gn b/services/common/test/unittest/decision_center/BUILD.gn index ec46cbbb..d01d526c 100644 --- a/services/common/test/unittest/decision_center/BUILD.gn +++ b/services/common/test/unittest/decision_center/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 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 @@ -48,10 +48,11 @@ ohos_unittest("ScreenDecisionCenterTest") { deps = [ "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans" ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "graphic_surface:surface", "graphic_surface:sync_fence", - "player_framework:media_client", + "media_foundation:media_foundation", ] } diff --git a/services/common/test/unittest/imageJpeg/BUILD.gn b/services/common/test/unittest/imageJpeg/BUILD.gn index 4af2aaa5..812ebda9 100644 --- a/services/common/test/unittest/imageJpeg/BUILD.gn +++ b/services/common/test/unittest/imageJpeg/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 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 @@ -47,9 +47,10 @@ ohos_unittest("JpegImageProcessorTest") { deps = [ "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans" ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "graphic_surface:surface", - "player_framework:media_client", + "media_foundation:media_foundation", ] } diff --git a/services/common/test/unittest/utils/video_param_test.cpp b/services/common/test/unittest/utils/video_param_test.cpp index 2f5dbfe4..ab42beb0 100644 --- a/services/common/test/unittest/utils/video_param_test.cpp +++ b/services/common/test/unittest/utils/video_param_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -98,9 +98,9 @@ HWTEST_F(VideoParamTest, GetVideoHeight_001, TestSize.Level1) */ HWTEST_F(VideoParamTest, GetFps_001, TestSize.Level1) { - uint32_t fps = 1; + double fps = 1.0; videoParam_->SetFps(fps); - uint32_t actual = videoParam_->GetFps(); + double actual = videoParam_->GetFps(); EXPECT_EQ(fps, actual); } @@ -145,7 +145,7 @@ HWTEST_F(VideoParamTest, to_json_001, TestSize.Level1) uint32_t screenHeight = 100; uint32_t videoWidth = 100; uint32_t videoHeight = 100; - uint32_t fps = 30; + double fps = 30.0; uint8_t videoFormat = DEFAULT_VIDEO_FORMAT; uint8_t codecType = DEFAULT_CODECTYPE; @@ -177,7 +177,7 @@ HWTEST_F(VideoParamTest, from_json_001, TestSize.Level1) uint32_t screenHeight = 100; uint32_t videoWidth = 100; uint32_t videoHeight = 100; - uint32_t fps = 30; + double fps = 30.0; uint8_t codecType = DEFAULT_CODECTYPE; uint8_t videoFormat = DEFAULT_VIDEO_FORMAT; @@ -208,7 +208,7 @@ HWTEST_F(VideoParamTest, from_json_002, TestSize.Level1) uint32_t screenHeight = 200; uint32_t videoWidth = 200; uint32_t videoHeight = 200; - uint32_t fps = 30; + double fps = 30.0; uint8_t codecType = DEFAULT_CODECTYPE; uint8_t videoFormat = DEFAULT_VIDEO_FORMAT; VideoParam jsonVideoParam; diff --git a/services/common/utils/include/video_param.h b/services/common/utils/include/video_param.h index 5f1122a1..ea80525a 100644 --- a/services/common/utils/include/video_param.h +++ b/services/common/utils/include/video_param.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -34,8 +34,8 @@ public: uint32_t GetVideoWidth() const; void SetVideoHeight(uint32_t videoHeight); uint32_t GetVideoHeight() const; - void SetFps(uint32_t fps); - uint32_t GetFps() const; + void SetFps(double fps); + double GetFps() const; void SetCodecType(uint8_t codecType); uint8_t GetCodecType() const; void SetVideoFormat(uint8_t videoFormat); @@ -50,7 +50,7 @@ private: uint32_t screenHeight_; uint32_t videoWidth_; uint32_t videoHeight_; - uint32_t fps_ = DEFAULT_FPS; + double fps_ = DEFAULT_FPS; uint8_t codecType_ = DEFAULT_CODECTYPE; uint8_t videoFormat_ = DEFAULT_VIDEO_FORMAT; bool isPartialRefresh_ = false; diff --git a/services/common/utils/src/video_param.cpp b/services/common/utils/src/video_param.cpp index 24e84f79..4736e41a 100644 --- a/services/common/utils/src/video_param.cpp +++ b/services/common/utils/src/video_param.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -71,12 +71,12 @@ uint32_t VideoParam::GetVideoHeight() const return videoHeight_; } -void VideoParam::SetFps(uint32_t fps) +void VideoParam::SetFps(double fps) { fps_ = fps; } -uint32_t VideoParam::GetFps() const +double VideoParam::GetFps() const { return fps_; } @@ -119,7 +119,7 @@ void from_json(const json &j, DistributedHardware::VideoParam &videoParam) { if (!IsUInt32(j, KEY_SCREEN_WIDTH) || !IsUInt32(j, KEY_SCREEN_HEIGHT) || !IsUInt32(j, KEY_VIDEO_WIDTH) || !IsUInt32(j, KEY_VIDEO_HEIGHT) || - !IsUInt32(j, KEY_FPS) || !IsUInt8(j, KEY_CODECTYPE) || + !IsFloat(j, KEY_FPS) || !IsUInt8(j, KEY_CODECTYPE) || !IsUInt8(j, KEY_COLOR_FORMAT)) { return; } @@ -128,7 +128,7 @@ void from_json(const json &j, DistributedHardware::VideoParam &videoParam) videoParam.screenHeight_ = j[KEY_SCREEN_HEIGHT].get(); videoParam.videoWidth_ = j[KEY_VIDEO_WIDTH].get(); videoParam.videoHeight_ = j[KEY_VIDEO_HEIGHT].get(); - videoParam.fps_ = j[KEY_FPS].get(); + videoParam.fps_ = j[KEY_FPS].get(); videoParam.codecType_ = j[KEY_CODECTYPE].get(); videoParam.videoFormat_ = j[KEY_COLOR_FORMAT].get(); videoParam.isPartialRefresh_ = false; diff --git a/services/screendemo/BUILD.gn b/services/screendemo/BUILD.gn index 68cf0ca5..bb30baf2 100644 --- a/services/screendemo/BUILD.gn +++ b/services/screendemo/BUILD.gn @@ -55,12 +55,13 @@ ohos_executable("distributedScreenTest") { "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", + "av_codec:av_codec_client", "c_utils:utils", "dsoftbus:softbus_client", "graphic_2d:librender_service_client", "graphic_surface:surface", "hilog:libhilog", - "player_framework:media_client", + "media_foundation:media_foundation", "samgr:samgr_proxy", "window_manager:libdm", "window_manager:libwm", diff --git a/services/screendemo/decoder_demo.cpp b/services/screendemo/decoder_demo.cpp index 934b98a4..7f36dd1c 100644 --- a/services/screendemo/decoder_demo.cpp +++ b/services/screendemo/decoder_demo.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 @@ -57,7 +57,7 @@ static const int32_t ES_W[183] = { }; using namespace OHOS; -using namespace OHOS::Media; +using namespace OHOS::MediaAVCodec; using namespace std; namespace { constexpr uint32_t DEFAULT_FRAME_RATE = 30; @@ -75,7 +75,7 @@ void VDecDemo::RunCase() { CheckCodecType(); CreateVdec(); - Format format; + Media::Format format; format.PutIntValue("width", width_); format.PutIntValue("height", height_); if (isW) { @@ -108,7 +108,7 @@ int32_t VDecDemo::CreateVdec() return 0; } -int32_t VDecDemo::Configure(const Format &format) +int32_t VDecDemo::Configure(const Media::Format &format) { return vdec_->Configure(format); } @@ -191,12 +191,16 @@ int32_t VDecDemo::SetSurface() void VDecDemo::CheckCodecType() { std::vector localCodecArray; - std::shared_ptr codecList = Media::AVCodecListFactory::CreateAVCodecList(); - std::vector> caps = codecList->GetVideoEncoderCaps(); - for (const auto &cap : caps) { - std::shared_ptr codecInfo = cap->GetCodecInfo(); - localCodecArray.push_back(codecInfo->GetName()); - } + std::shared_ptr codecList = MediaAVCodec::AVCodecListFactory::CreateAVCodecList(); + const std::vector encoderName = {std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC), + std::string(MediaAVCodec::CodecMimeType::VIDEO_HEVC)}; + + for (const auto &coder : encoderName) { + MediaAVCodec::CapabilityData *capData = codecList->GetCapability(coder, true, + MediaAVCodec::AVCodecCategory::AVCODEC_HARDWARE); + std::string mimeType = capData->mimeType; + localCodecArray.push_back(mimeType); +} if (std::find(localCodecArray.begin(), localCodecArray.end(), CODEC_NAME_H264) != localCodecArray.end()) { @@ -226,20 +230,17 @@ void VDecDemo::InputFunc() { const int32_t *frameLen = GetFrameLen(); - while (true) { - if (!isRunning_.load()) { - break; - } - + while (isRunning_.load()) { unique_lock lock(signal_->inMutex_); - signal_->inCond_.wait(lock, [this]() { return signal_->inQueue_.size() > 0; }); + signal_->inCond_.wait(lock, [this]() { return signal_->inQueue_.size() > 0 + && signal_->availableInputBufferQueue_.size() > 0; }); if (!isRunning_.load()) { break; } uint32_t index = signal_->inQueue_.front(); - auto buffer = vdec_->GetInputBuffer(index); + std::shared_ptr buffer = signal_->availableInputBufferQueue_.front(); char *fileBuffer = static_cast(malloc(sizeof(char) * (*frameLen) + 1)); if (fileBuffer == nullptr) { @@ -270,6 +271,7 @@ void VDecDemo::InputFunc() frameLen++; timeStamp_ += FRAME_DURATION_US; signal_->inQueue_.pop(); + signal_->availableInputBufferQueue_.pop(); frameCount_++; if (frameCount_ == defaultFrameCount_) { @@ -309,20 +311,22 @@ void VDecDemoCallback::OnError(AVCodecErrorType errorType, int32_t errorCode) cout << "Error received, errorType:" << errorType << " errorCode:" << errorCode << endl; } -void VDecDemoCallback::OnOutputFormatChanged(const Format &format) +void VDecDemoCallback::OnOutputFormatChanged(const Media::Format &format) { cout << "OnOutputFormatChanged received" << endl; } -void VDecDemoCallback::OnInputBufferAvailable(uint32_t index) +void VDecDemoCallback::OnInputBufferAvailable(uint32_t index, std::shared_ptr buffer) { cout << "OnInputBufferAvailable received, index:" << index << endl; unique_lock lock(signal_->inMutex_); signal_->inQueue_.push(index); + signal_->availableInputBufferQueue_.push(buffer); signal_->inCond_.notify_all(); } -void VDecDemoCallback::OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) +void VDecDemoCallback::OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, + AVCodecBufferFlag flag, std::shared_ptr buffer) { cout << "OnOutputBufferAvailable received, index:" << index << endl; unique_lock lock(signal_->outMutex_); diff --git a/services/screendemo/decoder_demo.h b/services/screendemo/decoder_demo.h index b55963c5..0eda2611 100644 --- a/services/screendemo/decoder_demo.h +++ b/services/screendemo/decoder_demo.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2022-2024 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 @@ -26,7 +26,7 @@ #include "nocopyable.h" namespace OHOS { -namespace Media { +namespace MediaAVCodec { class VDecSignal { public: std::mutex inMutex_; @@ -35,6 +35,7 @@ public: std::condition_variable outCond_; std::queue inQueue_; std::queue outQueue_; + std::queue> availableInputBufferQueue_; }; class VDecDemoCallback : public AVCodecCallback, public NoCopyable { @@ -43,9 +44,10 @@ public: virtual ~VDecDemoCallback() = default; void OnError(AVCodecErrorType errorType, int32_t errorCode) override; - void OnOutputFormatChanged(const Format &format) override; - void OnInputBufferAvailable(uint32_t index) override; - void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override; + void OnOutputFormatChanged(const Media::Format &format) override; + void OnInputBufferAvailable(uint32_t index, std::shared_ptr buffer) override; + void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag, + std::shared_ptr buffer) override; private: std::shared_ptr signal_; @@ -61,7 +63,7 @@ public: private: int32_t CreateVdec(); - int32_t Configure(const Format &format); + int32_t Configure(const Media::Format &format); int32_t Prepare(); int32_t Start(); int32_t Stop(); @@ -81,7 +83,7 @@ private: std::unique_ptr testFile_; std::unique_ptr inputLoop_; std::unique_ptr outputLoop_; - std::shared_ptr vdec_; + std::shared_ptr vdec_; std::shared_ptr signal_; std::shared_ptr cb_; bool isFirstFrame_ = true; diff --git a/services/screendemo/test.cpp b/services/screendemo/test.cpp index dfa9705c..3d592076 100644 --- a/services/screendemo/test.cpp +++ b/services/screendemo/test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -41,7 +41,7 @@ using namespace std; using namespace OHOS; using namespace OHOS::DistributedHardware; using namespace OHOS::Rosen; -using namespace OHOS::Media; +using namespace OHOS::MediaAVCodec; using namespace OHOS::Security::AccessToken; namespace { diff --git a/services/screenservice/sinkservice/BUILD.gn b/services/screenservice/sinkservice/BUILD.gn index 095e959d..e754f9b3 100644 --- a/services/screenservice/sinkservice/BUILD.gn +++ b/services/screenservice/sinkservice/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -83,6 +83,7 @@ ohos_shared_library("distributed_screen_sink") { external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:libdhfwk_sdk", @@ -92,6 +93,7 @@ ohos_shared_library("distributed_screen_sink") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", + "media_foundation:media_foundation", "safwk:system_ability_fwk", "samgr:samgr_proxy", "window_manager:libdm", diff --git a/services/screenservice/sinkservice/screenregionmgr/1.0/src/screenregion.cpp b/services/screenservice/sinkservice/screenregionmgr/1.0/src/screenregion.cpp index 4bcfa18d..7a9290ac 100644 --- a/services/screenservice/sinkservice/screenregionmgr/1.0/src/screenregion.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/1.0/src/screenregion.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -46,7 +46,7 @@ ScreenRegion::~ScreenRegion() void ScreenRegion::OnTransError(int32_t err, const std::string &content) { - DHLOGE("OnTransError, err: %" PRId32, err); + DHLOGW("OnTransError, err: %" PRId32, err); Stop(); } diff --git a/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp b/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp index 5a8844d5..143c8ec7 100644 --- a/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/2.0/src/screenregion.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -107,7 +107,8 @@ int32_t ScreenRegion::StartReceiverEngine(const std::string &content) } ret = receiverAdapter_->Start(); if (ret != DH_SUCCESS) { - DHLOGE("start av receiver engine failed."); + DHLOGE("start av receiver engine failed, remove window."); + (void)ScreenClient::GetInstance().RemoveWindow(windowId_); return ERR_DH_AV_TRANS_START_FAILED; } isRunning = true; diff --git a/services/screenservice/sourceservice/BUILD.gn b/services/screenservice/sourceservice/BUILD.gn index fcedabda..2bfa88ea 100644 --- a/services/screenservice/sourceservice/BUILD.gn +++ b/services/screenservice/sourceservice/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -89,6 +89,7 @@ ohos_shared_library("distributed_screen_source") { external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributed_av_sender", "distributed_hardware_fwk:distributedhardwareutils", @@ -100,7 +101,7 @@ ohos_shared_library("distributed_screen_source") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", "safwk:system_ability_fwk", "samgr:samgr_proxy", "window_manager:libdm", diff --git a/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp b/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp index e0f64719..007f0c0d 100644 --- a/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/1.0/src/dscreen.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -76,7 +76,7 @@ DScreen::~DScreen() void DScreen::OnTransError(int32_t err, const std::string &content) { - DHLOGD("OnTransError, err: %" PRId32, err); + DHLOGW("OnTransError, err: %" PRId32, err); AddTask(std::make_shared(TaskType::TASK_DISCONNECT, "")); ScreenMgrAdapter::GetInstance().RemoveScreenFromGroup(screenId_); } @@ -280,22 +280,23 @@ int32_t DScreen::NegotiateCodecType(const std::string &remoteCodecInfoStr) std::vector localCodecArray; // query local support encoder type - std::shared_ptr codecList = Media::AVCodecListFactory::CreateAVCodecList(); + std::shared_ptr codecList = MediaAVCodec::AVCodecListFactory::CreateAVCodecList(); if (codecList == nullptr) { - DHLOGE("codecList is nullptr."); + DHLOGE("Create avCodecList failed."); return ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL; } - std::vector> caps = codecList->GetVideoEncoderCaps(); - for (const auto &cap : caps) { - if (cap == nullptr) { - continue; - } - std::shared_ptr codecInfo = cap->GetCodecInfo(); - if (codecInfo == nullptr) { - continue; - } - localCodecArray.push_back(codecInfo->GetName()); + const std::vector encoderName = {std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC), + std::string(MediaAVCodec::CodecMimeType::VIDEO_HEVC)}; + for (const auto &coder : encoderName) { + MediaAVCodec::CapabilityData *capData = codecList->GetCapability(coder, true, + MediaAVCodec::AVCodecCategory::AVCODEC_HARDWARE); + if (capData == nullptr) { + continue; + } + std::string mimeType = capData->mimeType; + localCodecArray.push_back(mimeType); } + std::vector codecTypeCandidates; for (const auto &remoteCodecType : remoteCodecArray) { if (std::find(localCodecArray.begin(), localCodecArray.end(), @@ -305,23 +306,17 @@ int32_t DScreen::NegotiateCodecType(const std::string &remoteCodecInfoStr) } if (std::find(codecTypeCandidates.begin(), codecTypeCandidates.end(), - CODEC_NAME_H264) != codecTypeCandidates.end()) { + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)) != codecTypeCandidates.end()) { videoParam_->SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264); - videoParam_->SetVideoFormat(VIDEO_DATA_FORMAT_NV12); - videoParam_->SetPartialRefreshFlag(true); - } else if (std::find(codecTypeCandidates.begin(), codecTypeCandidates.end(), - CODEC_NAME_MPEG4) != codecTypeCandidates.end()) { - videoParam_->SetCodecType(VIDEO_CODEC_TYPE_VIDEO_MPEG4); - videoParam_->SetVideoFormat(VIDEO_DATA_FORMAT_RGBA8888); } else if (std::find(codecTypeCandidates.begin(), codecTypeCandidates.end(), - CODEC_NAME_H265) != codecTypeCandidates.end()) { + std::string(MediaAVCodec::CodecMimeType::VIDEO_HEVC)) != codecTypeCandidates.end()) { videoParam_->SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H265); - videoParam_->SetVideoFormat(VIDEO_DATA_FORMAT_NV12); - videoParam_->SetPartialRefreshFlag(true); } else { DHLOGI("codec type not support."); return ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL; } + videoParam_->SetVideoFormat(VIDEO_DATA_FORMAT_RGBA8888); + videoParam_->SetPartialRefreshFlag(true); return DH_SUCCESS; } diff --git a/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp b/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp index 47e0e206..388f9ecc 100644 --- a/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/2.0/src/dscreen_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -239,7 +239,6 @@ int32_t DScreenManager::EnableDistributedScreen(const std::string &devId, const int32_t ret = ScreenMgrAdapter::GetInstance().RegisterScreenGroupListener(dScreenGroupListener_); if (ret != DH_SUCCESS) { DHLOGE("DScreenManager2.0 EnableDistributedScreen failed, err: %" PRId32, ret); - delete dScreenGroupListener_; dScreenGroupListener_ = nullptr; return ERR_DH_SCREEN_SA_ENABLE_FAILED; } diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp index f22b64d5..cbc91999 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -176,7 +176,7 @@ HWTEST_F(ScreenRegionTestV1, SetUp_001, TestSize.Level1) videoParam->videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; videoParam->codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; videoParam->videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; - videoParam->fps_ = 30; + videoParam->fps_ = 30.0; screenRegion_->SetVideoParam(videoParam); std::string version = "1.0"; int32_t ret = screenRegion_->SetUp(version); diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn b/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn index e9eb4333..180ec699 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -75,6 +75,7 @@ ohos_unittest("DscreenRegionMgrTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributedhardwareutils", @@ -83,6 +84,7 @@ ohos_unittest("DscreenRegionMgrTest") { "graphic_2d:librender_service_client", "graphic_surface:surface", "hisysevent:libhisysevent", + "media_foundation:media_foundation", "window_manager:libdm", ] } diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp index 0401884a..6744e783 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/dscreen_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -52,7 +52,7 @@ void DScreenTestV1::SetUp(void) dScreen_->videoParam_->SetVideoWidth(videoDataNum); dScreen_->videoParam_->SetScreenHeight(videoDataNum); dScreen_->videoParam_->SetScreenWidth(videoDataNum); - dScreen_->videoParam_->SetFps(videoDataNum); + dScreen_->videoParam_->SetFps(DEFAULT_FPS); dScreen_->devId_ = "peerDevId"; } diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/screen_manager_adapter_test.cpp b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/screen_manager_adapter_test.cpp index d36d7a96..306e3cd2 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/screen_manager_adapter_test.cpp +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/1.0/src/screen_manager_adapter_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -234,7 +234,7 @@ HWTEST_F(DScreenManagerAdapterTest, SetImageSurface_001, TestSize.Level1) */ HWTEST_F(DScreenManagerAdapterTest, GetMapRelation_001, TestSize.Level1) { - std::shared_ptr ret = ScreenMgrAdapter::GetInstance().GetMapRelation(1000); + std::shared_ptr ret = ScreenMgrAdapter::GetInstance().GetMapRelation(100000); EXPECT_EQ(nullptr, ret); } diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/dscreen_test.cpp b/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/dscreen_test.cpp index 5534a2cd..b83811ee 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/dscreen_test.cpp +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/2.0/src/dscreen_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -50,7 +50,7 @@ void DScreenTestV2::SetUp(void) dScreen_->videoParam_->SetVideoWidth(videoDataNum); dScreen_->videoParam_->SetScreenHeight(videoDataNum); dScreen_->videoParam_->SetScreenWidth(videoDataNum); - dScreen_->videoParam_->SetFps(videoDataNum); + dScreen_->videoParam_->SetFps(DEFAULT_FPS); dScreen_->devId_ = "peerDevId"; } @@ -310,7 +310,7 @@ HWTEST_F(DScreenTestV2, SetUp_002, TestSize.Level1) HWTEST_F(DScreenTestV2, SetUp_003, TestSize.Level1) { dScreen_->senderAdapter_ = std::make_shared(); - dScreen_->screenId_ = 2; + dScreen_->screenId_ = 200000; int32_t ret = dScreen_->SetUp(); EXPECT_EQ(ERR_DH_AV_TRANS_SETUP_FAILED, ret); } diff --git a/services/screenservice/test/unittest/sourceservice/dscreenmgr/BUILD.gn b/services/screenservice/test/unittest/sourceservice/dscreenmgr/BUILD.gn index a477035b..e0a64b94 100644 --- a/services/screenservice/test/unittest/sourceservice/dscreenmgr/BUILD.gn +++ b/services/screenservice/test/unittest/sourceservice/dscreenmgr/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -25,7 +25,6 @@ config("module_private_config") { "${distributedhardwarefwk_path}/common/utils/include", "${distributedhardwarefwk_path}/utils/include", "${fwk_common_path}/utils/include", - "${mediastandard_path}/interfaces/inner_api/native", ] include_dirs += [ @@ -82,6 +81,7 @@ ohos_unittest("DscreenMgrTest") { "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributed_av_sender", "distributed_hardware_fwk:distributedhardwareutils", @@ -93,7 +93,7 @@ ohos_unittest("DscreenMgrTest") { "graphic_surface:sync_fence", "hdf_core:libhdi", "hicollie:libhicollie", - "player_framework:media_client", + "media_foundation:media_foundation", "window_manager:libdm", ] } diff --git a/services/screentransport/screensinkprocessor/decoder/include/image_decoder_callback.h b/services/screentransport/screensinkprocessor/decoder/include/image_decoder_callback.h index 2b29050e..61f16443 100644 --- a/services/screentransport/screensinkprocessor/decoder/include/image_decoder_callback.h +++ b/services/screentransport/screensinkprocessor/decoder/include/image_decoder_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -18,22 +18,23 @@ #include -#include "media_errors.h" +#include "avcodec_errors.h" #include "avcodec_common.h" -#include "format.h" +#include "meta/format.h" namespace OHOS { namespace DistributedHardware { class ImageSinkDecoder; -class ImageDecoderCallback : public Media::AVCodecCallback { +class ImageDecoderCallback : public MediaAVCodec::AVCodecCallback { public: explicit ImageDecoderCallback(const std::shared_ptr &decoder) : videoDecoder_(decoder) {}; ~ImageDecoderCallback() override = default; - void OnError(Media::AVCodecErrorType errorType, int32_t errorCode) override; - void OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, Media::AVCodecBufferFlag flag) override; - void OnInputBufferAvailable(uint32_t index) override; + void OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode) override; + void OnOutputBufferAvailable(uint32_t index, MediaAVCodec::AVCodecBufferInfo info, + MediaAVCodec::AVCodecBufferFlag flag, std::shared_ptr buffer) override; + void OnInputBufferAvailable(uint32_t index, std::shared_ptr buffer) override; void OnOutputFormatChanged(const Media::Format &format) override; private: diff --git a/services/screentransport/screensinkprocessor/decoder/include/image_sink_decoder.h b/services/screentransport/screensinkprocessor/decoder/include/image_sink_decoder.h index 196aa16b..289556b1 100644 --- a/services/screentransport/screensinkprocessor/decoder/include/image_sink_decoder.h +++ b/services/screentransport/screensinkprocessor/decoder/include/image_sink_decoder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -22,11 +22,11 @@ #include #include -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "avcodec_common.h" #include "avcodec_video_decoder.h" -#include "media_errors.h" -#include "format.h" +#include "avcodec_errors.h" +#include "meta/format.h" #include "surface.h" #include "iconsumer_surface.h" @@ -64,10 +64,10 @@ public: sptr GetWinSurfaceBuffer(); void NormalProcess(sptr surfaceBuffer, sptr windowSurfaceBuffer); void OffsetProcess(sptr surfaceBuffer, sptr windowSurfaceBuffer); - - void OnError(Media::AVCodecErrorType errorType, int32_t errorCode); - void OnInputBufferAvailable(uint32_t index); - void OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, Media::AVCodecBufferFlag flag); + void OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode); + void OnInputBufferAvailable(uint32_t index, std::shared_ptr buffer); + void OnOutputBufferAvailable(uint32_t index, MediaAVCodec::AVCodecBufferInfo info, + MediaAVCodec::AVCodecBufferFlag flag, std::shared_ptr buffer); void OnOutputFormatChanged(const Media::Format &format); private: @@ -89,7 +89,8 @@ private: uint8_t *lastFrame_ = nullptr; int32_t lastFrameSize_ = 0; Media::Format imageFormat_; - Media::AVCodecBufferInfo decoderBufferInfo_; + Media::Format decodeOutputFormat_; + MediaAVCodec::AVCodecBufferInfo decoderBufferInfo_; bool isDecoderReady_ = false; uint32_t alignedHeight_ = 0; @@ -98,9 +99,10 @@ private: sptr windowSurface_; sptr consumerBufferListener_; std::queue> videoDataQueue_; - std::queue bufferIndexQueue_; - std::shared_ptr videoDecoder_; - std::shared_ptr decodeVideoCallback_; + std::queue availableInputIndexsQueue_; + std::queue> availableInputBufferQueue_; + std::shared_ptr videoDecoder_; + std::shared_ptr decodeVideoCallback_; std::weak_ptr imageProcessorListener_; }; } // namespace DistributedHardware diff --git a/services/screentransport/screensinkprocessor/decoder/src/image_decoder_callback.cpp b/services/screentransport/screensinkprocessor/decoder/src/image_decoder_callback.cpp index b19fb870..df4e68da 100644 --- a/services/screentransport/screensinkprocessor/decoder/src/image_decoder_callback.cpp +++ b/services/screentransport/screensinkprocessor/decoder/src/image_decoder_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -20,7 +20,7 @@ namespace OHOS { namespace DistributedHardware { -void ImageDecoderCallback::OnError(Media::AVCodecErrorType errorType, int32_t errorCode) +void ImageDecoderCallback::OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode) { DHLOGD("%s: OnError.", LOG_TAG); std::shared_ptr decoder = videoDecoder_.lock(); @@ -31,8 +31,8 @@ void ImageDecoderCallback::OnError(Media::AVCodecErrorType errorType, int32_t er decoder->OnError(errorType, errorCode); } -void ImageDecoderCallback::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, - Media::AVCodecBufferFlag flag) +void ImageDecoderCallback::OnOutputBufferAvailable(uint32_t index, MediaAVCodec::AVCodecBufferInfo info, + MediaAVCodec::AVCodecBufferFlag flag, std::shared_ptr buffer) { DHLOGD("%s: OnOutputBufferAvailable.", LOG_TAG); std::shared_ptr decoder = videoDecoder_.lock(); @@ -40,10 +40,10 @@ void ImageDecoderCallback::OnOutputBufferAvailable(uint32_t index, Media::AVCode DHLOGE("decoder is nullptr."); return; } - decoder->OnOutputBufferAvailable(index, info, flag); + decoder->OnOutputBufferAvailable(index, info, flag, buffer); } -void ImageDecoderCallback::OnInputBufferAvailable(uint32_t index) +void ImageDecoderCallback::OnInputBufferAvailable(uint32_t index, std::shared_ptr buffer) { DHLOGD("%s: OnInputBufferAvailable.", LOG_TAG); std::shared_ptr decoder = videoDecoder_.lock(); @@ -51,7 +51,7 @@ void ImageDecoderCallback::OnInputBufferAvailable(uint32_t index) DHLOGE("decoder is nullptr."); return; } - decoder->OnInputBufferAvailable(index); + decoder->OnInputBufferAvailable(index, buffer); } void ImageDecoderCallback::OnOutputFormatChanged(const Media::Format &format) diff --git a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp index e495674f..adcef983 100644 --- a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp +++ b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -65,6 +65,8 @@ int32_t ImageSinkDecoder::AddSurface() return ERR_DH_SCREEN_CODEC_SURFACE_ERROR; } + consumerSurface_->SetDefaultUsage(BUFFER_USAGE_CPU_READ); + sptr producer = consumerSurface_->GetProducer(); if (producer == nullptr) { DHLOGE("%s: Get preducer surface failed.", LOG_TAG); @@ -135,29 +137,29 @@ void ImageSinkDecoder::OffsetProcess(sptr surfaceBuffer, sptr(surfaceBuffer->GetStride()); - uint32_t chromaOffset = configParam_.GetVideoWidth() * configParam_.GetVideoHeight(); + uint32_t chromaOffset = alignedWidth * configParam_.GetVideoHeight(); for (unsigned int yh = 0 ; yh < configParam_.GetVideoHeight() ; yh++) { int32_t ret = memcpy_s(windowSurfaceAddr + dstDataOffset, chromaOffset - dstDataOffset, - surfaceAddr + srcDataOffset, configParam_.GetVideoWidth()); + surfaceAddr + srcDataOffset, alignedWidth); if (ret != EOK) { DHLOGE("%s: surfaceBuffer memcpy_s run failed.", LOG_TAG); windowSurface_->CancelBuffer(windowSurfaceBuffer); return; } - dstDataOffset += configParam_.GetVideoWidth(); + dstDataOffset += alignedWidth; srcDataOffset += alignedWidth; } dstDataOffset = chromaOffset; srcDataOffset = alignedWidth * alignedHeight_; for (unsigned int uvh = 0 ; uvh < configParam_.GetVideoHeight() / TWO; uvh++) { int32_t ret = memcpy_s(windowSurfaceAddr + dstDataOffset, size - dstDataOffset, - surfaceAddr + srcDataOffset, configParam_.GetVideoWidth()); + surfaceAddr + srcDataOffset, alignedWidth); if (ret != EOK) { DHLOGE("%s: surfaceBuffer memcpy_s run failed.", LOG_TAG); windowSurface_->CancelBuffer(windowSurfaceBuffer); return; } - dstDataOffset += configParam_.GetVideoWidth(); + dstDataOffset += alignedWidth; srcDataOffset += alignedWidth; } } @@ -183,9 +185,16 @@ void ImageSinkDecoder::ConsumeSurface() consumerSurface_->ReleaseBuffer(surfaceBuffer, -1); return; } - int32_t alignedWidth = surfaceBuffer->GetStride(); - if (static_cast(alignedWidth) == configParam_.GetVideoWidth() && - static_cast(alignedHeight_) == configParam_.GetVideoHeight()) { + + if (lastFrameSize_ != surfaceBuffer->GetStride() * surfaceBuffer->GetHeight() * THREE / TWO) { + if (lastFrame_ != nullptr) { + delete [] lastFrame_; + } + lastFrameSize_ = surfaceBuffer->GetStride() * surfaceBuffer->GetHeight() * THREE / TWO; + lastFrame_ = new uint8_t[lastFrameSize_]; + } + + if (static_cast(alignedHeight_) == configParam_.GetVideoHeight()) { NormalProcess(surfaceBuffer, windowSurfaceBuffer); } else { OffsetProcess(surfaceBuffer, windowSurfaceBuffer); @@ -199,7 +208,7 @@ void ImageSinkDecoder::ConsumeSurface() windowSurface_->CancelBuffer(windowSurfaceBuffer); return; } - DHLOGI("%s: ConsumeSurface sucess, send NV12 to window.", LOG_TAG); + DHLOGI("%s: ConsumeSurface success, send NV12 to window.", LOG_TAG); surfaceErr = windowSurface_->FlushBuffer(windowSurfaceBuffer, -1, flushConfig); if (surfaceErr != SURFACE_ERROR_OK) { DHLOGE("%s: windowSurface_ flush buffer failed.", LOG_TAG); @@ -227,7 +236,7 @@ int32_t ImageSinkDecoder::ReleaseDecoder() delete [] lastFrame_; } int32_t ret = videoDecoder_->Release(); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: ReleaseDecoder failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_RELEASE_FAILED; } @@ -246,13 +255,13 @@ int32_t ImageSinkDecoder::StartDecoder() } int32_t ret = videoDecoder_->Prepare(); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Prepare decoder failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_PREPARE_FAILED; } ret = videoDecoder_->Start(); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Start decoder failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_START_FAILED; } @@ -270,13 +279,13 @@ int32_t ImageSinkDecoder::StopDecoder() } int32_t ret = videoDecoder_->Flush(); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Flush decoder failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_FLUSH_FAILED; } ret = videoDecoder_->Stop(); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Stop decoder failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_STOP_FAILED; } @@ -290,13 +299,12 @@ int32_t ImageSinkDecoder::InitVideoDecoder(const VideoParam &configParam) DHLOGI("%s: InitVideoDecoder.", LOG_TAG); switch (configParam.GetCodecType()) { case VIDEO_CODEC_TYPE_VIDEO_H264: - videoDecoder_ = Media::VideoDecoderFactory::CreateByMime("video/avc"); + videoDecoder_ = MediaAVCodec::VideoDecoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); break; case VIDEO_CODEC_TYPE_VIDEO_H265: - videoDecoder_ = Media::VideoDecoderFactory::CreateByMime("video/hevc"); - break; - case VIDEO_CODEC_TYPE_VIDEO_MPEG4: - videoDecoder_ = Media::VideoDecoderFactory::CreateByMime("video/mp4v-es"); + videoDecoder_ = MediaAVCodec::VideoDecoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_HEVC)); break; default: DHLOGE("%s: codecType is invalid!", LOG_TAG); @@ -304,13 +312,13 @@ int32_t ImageSinkDecoder::InitVideoDecoder(const VideoParam &configParam) } if (videoDecoder_ == nullptr) { - DHLOGE("%s: Create videoEncode failed.", LOG_TAG); + DHLOGE("%s: Create videoEncoder failed.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } decodeVideoCallback_ = std::make_shared(shared_from_this()); int32_t ret = videoDecoder_->SetCallback(decodeVideoCallback_); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Set decoder callback failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_SET_CALLBACK_FAILED; } @@ -328,43 +336,24 @@ int32_t ImageSinkDecoder::SetDecoderFormat(const VideoParam &configParam) switch (configParam.GetCodecType()) { case VIDEO_CODEC_TYPE_VIDEO_H264: - imageFormat_.PutStringValue("codec_mime", "video/avc"); + imageFormat_.PutStringValue("codec_mime", MediaAVCodec::CodecMimeType::VIDEO_AVC); break; case VIDEO_CODEC_TYPE_VIDEO_H265: - imageFormat_.PutStringValue("codec_mime", "video/hevc"); - break; - case VIDEO_CODEC_TYPE_VIDEO_MPEG4: - imageFormat_.PutStringValue("codec_mime", "video/mp4v-es"); + imageFormat_.PutStringValue("codec_mime", MediaAVCodec::CodecMimeType::VIDEO_HEVC); break; default: DHLOGE("The current codec type does not support decoding."); return ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION; } - switch (configParam.GetVideoFormat()) { - case VIDEO_DATA_FORMAT_YUVI420: - imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::YUVI420); - break; - case VIDEO_DATA_FORMAT_NV12: - imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV12); - break; - case VIDEO_DATA_FORMAT_NV21: - imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV21); - break; - case VIDEO_DATA_FORMAT_RGBA8888: - imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::RGBA); - break; - default: - DHLOGE("The current pixel format does not support decoding."); - return ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION; - } + imageFormat_.PutIntValue("pixel_format", static_cast(MediaAVCodec::VideoPixelFormat::NV12)); imageFormat_.PutLongValue("max_input_size", MAX_YUV420_BUFFER_SIZE); imageFormat_.PutIntValue("width", configParam.GetVideoWidth()); imageFormat_.PutIntValue("height", configParam.GetVideoHeight()); - imageFormat_.PutIntValue("frame_rate", configParam.GetFps()); + imageFormat_.PutDoubleValue("frame_rate", configParam.GetFps()); int32_t ret = videoDecoder_->Configure(imageFormat_); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: configure decoder format param failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED; } @@ -382,13 +371,13 @@ int32_t ImageSinkDecoder::SetOutputSurface(sptr &surface) windowSurface_ = surface; if (consumerSurface_ == nullptr || producerSurface_ == nullptr || !configParam_.GetPartialRefreshFlag()) { int32_t ret = videoDecoder_->SetOutputSurface(surface); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: SetOutputSurface failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_SURFACE_ERROR; } } else { int32_t ret = videoDecoder_->SetOutputSurface(producerSurface_); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: SetOutputSurface failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_SURFACE_ERROR; } @@ -414,7 +403,7 @@ int32_t ImageSinkDecoder::InputScreenData(const std::shared_ptr &dat return DH_SUCCESS; } -void ImageSinkDecoder::OnError(Media::AVCodecErrorType errorType, int32_t errorCode) +void ImageSinkDecoder::OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode) { DHLOGI("%s: OnImageDecodeError, errorType:%" PRId32", errorCode:%" PRId32, LOG_TAG, errorType, errorCode); std::shared_ptr listener = imageProcessorListener_.lock(); @@ -425,15 +414,16 @@ void ImageSinkDecoder::OnError(Media::AVCodecErrorType errorType, int32_t errorC listener->OnProcessorStateNotify(errorCode); } -void ImageSinkDecoder::OnInputBufferAvailable(uint32_t index) +void ImageSinkDecoder::OnInputBufferAvailable(uint32_t index, std::shared_ptr buffer) { DHLOGI("%s: OnDecodeInputBufferAvailable: %u.", LOG_TAG, index); std::lock_guard dataLock(dataMutex_); - bufferIndexQueue_.push(index); + availableInputIndexsQueue_.push(index); + availableInputBufferQueue_.push(buffer); } -void ImageSinkDecoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, - Media::AVCodecBufferFlag flag) +void ImageSinkDecoder::OnOutputBufferAvailable(uint32_t index, MediaAVCodec::AVCodecBufferInfo info, + MediaAVCodec::AVCodecBufferFlag flag, std::shared_ptr buffer) { DHLOGI("%s: OnDecodeOutputBufferAvailable.", LOG_TAG); if (videoDecoder_ == nullptr) { @@ -443,7 +433,7 @@ void ImageSinkDecoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBuf decoderBufferInfo_ = info; int32_t ret = videoDecoder_->ReleaseOutputBuffer(index, true); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGD("%s: ReleaseOutputBuffer failed.", LOG_TAG); } } @@ -469,12 +459,9 @@ int32_t ImageSinkDecoder::StopInputThread() decodeThread_.join(); } std::lock_guard dataLock(dataMutex_); - while (!bufferIndexQueue_.empty()) { - bufferIndexQueue_.pop(); - } - while (!videoDataQueue_.empty()) { - videoDataQueue_.pop(); - } + std::queue>().swap(videoDataQueue_); + std::queue().swap(availableInputIndexsQueue_); + std::queue>().swap(availableInputBufferQueue_); return DH_SUCCESS; } @@ -492,14 +479,15 @@ void ImageSinkDecoder::DecodeScreenData() { std::unique_lock lock(dataMutex_); decodeCond_.wait_for(lock, std::chrono::milliseconds(DECODE_WAIT_MILLISECONDS), - [this]() { return (!videoDataQueue_.empty() && !bufferIndexQueue_.empty()); }); + [this]() { return (!videoDataQueue_.empty() && !availableInputIndexsQueue_.empty() + && !availableInputBufferQueue_.empty()); }); - if (videoDataQueue_.empty() || bufferIndexQueue_.empty()) { - DHLOGD("%s: Index queue or data queue is empty.", LOG_TAG); + if (videoDataQueue_.empty() || availableInputIndexsQueue_.empty() || availableInputBufferQueue_.empty()) { + DHLOGD("%s: Index queue or data queue or buffer queue is empty.", LOG_TAG); continue; } - bufferIndex = bufferIndexQueue_.front(); - bufferIndexQueue_.pop(); + bufferIndex = availableInputIndexsQueue_.front(); + availableInputIndexsQueue_.pop(); screenData = videoDataQueue_.front(); videoDataQueue_.pop(); } @@ -521,9 +509,14 @@ int32_t ImageSinkDecoder::ProcessData(const std::shared_ptr &screenD return ERR_DH_SCREEN_TRANS_NULL_VALUE; } - auto inputBuffer = videoDecoder_->GetInputBuffer(bufferIndex); + if (availableInputBufferQueue_.empty()) { + DHLOGD("%s: input buffer queue is empty.", LOG_TAG); + return ERR_DH_SCREEN_CODEC_SURFACE_ERROR; + } + + std::shared_ptr inputBuffer = availableInputBufferQueue_.front(); if (inputBuffer == nullptr) { - DHLOGE("%s: GetInputBuffer failed.", LOG_TAG); + DHLOGE("%s: Failed to obtain the input shared memory corresponding to the [%d] index.", LOG_TAG, bufferIndex); return ERR_DH_SCREEN_CODEC_SURFACE_ERROR; } @@ -534,15 +527,16 @@ int32_t ImageSinkDecoder::ProcessData(const std::shared_ptr &screenD } DHLOGD("%s: Decode screen data. send data to H264 decoder", LOG_TAG); - Media::AVCodecBufferInfo bufferInfo; + MediaAVCodec::AVCodecBufferInfo bufferInfo; bufferInfo.presentationTimeUs = 0; bufferInfo.size = static_cast(screenData->Capacity()); bufferInfo.offset = 0; - ret = videoDecoder_->QueueInputBuffer(bufferIndex, bufferInfo, Media::AVCODEC_BUFFER_FLAG_NONE); - if (ret != Media::MSERR_OK) { + ret = videoDecoder_->QueueInputBuffer(bufferIndex, bufferInfo, MediaAVCodec::AVCODEC_BUFFER_FLAG_NONE); + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: QueueInputBuffer failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_SURFACE_ERROR; } + availableInputBufferQueue_.pop(); return DH_SUCCESS; } } // namespace DistributedHardware diff --git a/services/screentransport/screensinktrans/BUILD.gn b/services/screentransport/screensinktrans/BUILD.gn index fa1bb0de..0f1c3697 100644 --- a/services/screentransport/screensinktrans/BUILD.gn +++ b/services/screentransport/screensinktrans/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -74,6 +74,7 @@ ohos_shared_library("distributed_screen_sinktrans") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:libdhfwk_sdk", @@ -82,7 +83,7 @@ ohos_shared_library("distributed_screen_sinktrans") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - "player_framework:media_client", + "media_foundation:media_foundation", ] if (!distributed_screen_common) { diff --git a/services/screentransport/screensourceprocessor/encoder/include/image_encoder_callback.h b/services/screentransport/screensourceprocessor/encoder/include/image_encoder_callback.h index a100ce46..afc59997 100644 --- a/services/screentransport/screensourceprocessor/encoder/include/image_encoder_callback.h +++ b/services/screentransport/screensourceprocessor/encoder/include/image_encoder_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -18,22 +18,23 @@ #include -#include "media_errors.h" +#include "avcodec_errors.h" #include "avcodec_common.h" -#include "format.h" +#include "meta/format.h" namespace OHOS { namespace DistributedHardware { class ImageSourceEncoder; -class ImageEncoderCallback : public Media::AVCodecCallback { +class ImageEncoderCallback : public MediaAVCodec::AVCodecCallback { public: explicit ImageEncoderCallback(const std::shared_ptr &encoder) : videoEncoder_(encoder) {}; ~ImageEncoderCallback() override = default; - void OnError(Media::AVCodecErrorType errorType, int32_t errorCode) override; - void OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, Media::AVCodecBufferFlag flag) override; - void OnInputBufferAvailable(uint32_t index) override; + void OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode) override; + void OnOutputBufferAvailable(uint32_t index, MediaAVCodec::AVCodecBufferInfo info, + MediaAVCodec::AVCodecBufferFlag flag, std::shared_ptr buffer) override; + void OnInputBufferAvailable(uint32_t index, std::shared_ptr buffer) override; void OnOutputFormatChanged(const Media::Format &format) override; private: diff --git a/services/screentransport/screensourceprocessor/encoder/include/image_source_encoder.h b/services/screentransport/screensourceprocessor/encoder/include/image_source_encoder.h index 79a28cb3..78e29cbc 100644 --- a/services/screentransport/screensourceprocessor/encoder/include/image_source_encoder.h +++ b/services/screentransport/screensourceprocessor/encoder/include/image_source_encoder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -19,12 +19,12 @@ #include #include -#include "avsharedmemory.h" +#include "buffer/avsharedmemory.h" #include "avcodec_video_encoder.h" #include "avcodec_common.h" -#include "format.h" +#include "meta/format.h" #include "iconsumer_surface.h" -#include "media_errors.h" +#include "avcodec_errors.h" #include "surface.h" #include "sync_fence.h" @@ -56,9 +56,10 @@ public: int32_t StopEncoder(); int32_t AddSurface(); sptr &GetInputSurface(); - void OnError(Media::AVCodecErrorType errorType, int32_t errorCode); - void OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, Media::AVCodecBufferFlag flag); - void OnInputBufferAvailable(uint32_t index); + void OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode); + void OnOutputBufferAvailable(uint32_t index, MediaAVCodec::AVCodecBufferInfo info, + MediaAVCodec::AVCodecBufferFlag flag, std::shared_ptr buffer); + void OnInputBufferAvailable(uint32_t index, std::shared_ptr buffer); void OnOutputFormatChanged(const Media::Format &format); void ConsumeSurface(); int32_t FeedEncoderData(sptr &surfaceBuffer); @@ -74,7 +75,7 @@ private: static const constexpr char *LOG_TAG = "ImageSourceEncoder"; Media::Format imageFormat_; - Media::AVCodecBufferInfo encoderBufferInfo_; + MediaAVCodec::AVCodecBufferInfo encoderBufferInfo_; VideoParam configParam_; sptr encoderSurface_; @@ -82,9 +83,9 @@ private: sptr producerSurface_; sptr consumerBufferListener_; std::mutex bufferMtx_; - std::shared_ptr videoEncoder_; + std::shared_ptr videoEncoder_; std::shared_ptr videoSharedMemory_; - std::shared_ptr encodeVideoCallback_; + std::shared_ptr encodeVideoCallback_; std::weak_ptr imageProcessorListener_; std::vector> eventContent_; OHOS::sptr syncFence_ = SyncFence::INVALID_FENCE; diff --git a/services/screentransport/screensourceprocessor/encoder/src/image_encoder_callback.cpp b/services/screentransport/screensourceprocessor/encoder/src/image_encoder_callback.cpp index 2cfe9ff9..ac7100f0 100644 --- a/services/screentransport/screensourceprocessor/encoder/src/image_encoder_callback.cpp +++ b/services/screentransport/screensourceprocessor/encoder/src/image_encoder_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -20,7 +20,7 @@ namespace OHOS { namespace DistributedHardware { -void ImageEncoderCallback::OnError(Media::AVCodecErrorType errorType, int32_t errorCode) +void ImageEncoderCallback::OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode) { DHLOGD("%s: OnError.", LOG_TAG); std::shared_ptr encoder = videoEncoder_.lock(); @@ -31,8 +31,8 @@ void ImageEncoderCallback::OnError(Media::AVCodecErrorType errorType, int32_t er encoder->OnError(errorType, errorCode); } -void ImageEncoderCallback::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, - Media::AVCodecBufferFlag flag) +void ImageEncoderCallback::OnOutputBufferAvailable(uint32_t index, MediaAVCodec::AVCodecBufferInfo info, + MediaAVCodec::AVCodecBufferFlag flag, std::shared_ptr buffer) { DHLOGD("%s: OnOutputBufferAvailable.", LOG_TAG); std::shared_ptr encoder = videoEncoder_.lock(); @@ -40,10 +40,10 @@ void ImageEncoderCallback::OnOutputBufferAvailable(uint32_t index, Media::AVCode DHLOGE("encoder is nullptr."); return; } - encoder->OnOutputBufferAvailable(index, info, flag); + encoder->OnOutputBufferAvailable(index, info, flag, buffer); } -void ImageEncoderCallback::OnInputBufferAvailable(uint32_t index) +void ImageEncoderCallback::OnInputBufferAvailable(uint32_t index, std::shared_ptr buffer) { DHLOGD("%s: OnInputBufferAvailable.", LOG_TAG); std::shared_ptr encoder = videoEncoder_.lock(); @@ -51,7 +51,7 @@ void ImageEncoderCallback::OnInputBufferAvailable(uint32_t index) DHLOGE("encoder is nullptr."); return; } - encoder->OnInputBufferAvailable(index); + encoder->OnInputBufferAvailable(index, buffer); } void ImageEncoderCallback::OnOutputFormatChanged(const Media::Format &format) diff --git a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp index 86529b2b..26e7ca79 100644 --- a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp +++ b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -232,7 +232,7 @@ int32_t ImageSourceEncoder::FeedEncoderData(sptr &surfaceBuffer) return ret; } BufferFlushConfig flushConfig = { {0, 0, encoderSurfaceBuffer->GetWidth(), encoderSurfaceBuffer->GetHeight()}, 0}; - DHLOGI("%s: FeedEncoderData to H264 encoder.", LOG_TAG); + DHLOGI("%s: FeedEncoderData to encoder.", LOG_TAG); SurfaceError surfaceErr = encoderSurface_->FlushBuffer(encoderSurfaceBuffer, -1, flushConfig); if (surfaceErr != SURFACE_ERROR_OK) { DHLOGE("%s: encoderSurface_ flush buffer failed.", LOG_TAG); @@ -253,7 +253,7 @@ int32_t ImageSourceEncoder::ReleaseEncoder() } int32_t ret = videoEncoder_->Release(); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Release encoder failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_RELEASE_FAILED; } @@ -276,13 +276,13 @@ int32_t ImageSourceEncoder::StartEncoder() } int32_t ret = videoEncoder_->Prepare(); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Prepare encoder failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_PREPARE_FAILED; } ret = videoEncoder_->Start(); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Start encoder failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_START_FAILED; } @@ -299,12 +299,12 @@ int32_t ImageSourceEncoder::StopEncoder() } int32_t ret = videoEncoder_->Flush(); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Flush encoder failed.", LOG_TAG); } ret = videoEncoder_->Stop(); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Stop encoder failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_STOP_FAILED; } @@ -322,13 +322,12 @@ int32_t ImageSourceEncoder::InitVideoEncoder(const VideoParam &configParam) DHLOGI("%s: InitVideoEncoder.", LOG_TAG); switch (configParam.GetCodecType()) { case VIDEO_CODEC_TYPE_VIDEO_H264: - videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/avc"); + videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); break; case VIDEO_CODEC_TYPE_VIDEO_H265: - videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/hevc"); - break; - case VIDEO_CODEC_TYPE_VIDEO_MPEG4: - videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/mp4v-es"); + videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_HEVC)); break; default: DHLOGE("%s: codecType is invalid!", LOG_TAG); @@ -342,7 +341,7 @@ int32_t ImageSourceEncoder::InitVideoEncoder(const VideoParam &configParam) encodeVideoCallback_ = std::make_shared(shared_from_this()); int32_t ret = videoEncoder_->SetCallback(encodeVideoCallback_); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Set codec callback failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_SET_CALLBACK_FAILED; } @@ -360,49 +359,31 @@ int32_t ImageSourceEncoder::SetEncoderFormat(const VideoParam &configParam) switch (configParam.GetCodecType()) { case VIDEO_CODEC_TYPE_VIDEO_H264: - imageFormat_.PutStringValue("codec_mime", "video/avc"); + imageFormat_.PutStringValue("codec_mime", MediaAVCodec::CodecMimeType::VIDEO_AVC); break; case VIDEO_CODEC_TYPE_VIDEO_H265: - imageFormat_.PutStringValue("codec_mime", "video/hevc"); - break; - case VIDEO_CODEC_TYPE_VIDEO_MPEG4: - imageFormat_.PutStringValue("codec_mime", "video/mp4v-es"); + imageFormat_.PutStringValue("codec_mime", MediaAVCodec::CodecMimeType::VIDEO_HEVC); break; default: DHLOGE("%s: Codec type is invalid.", LOG_TAG); return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM; } - switch (configParam.GetVideoFormat()) { - case VIDEO_DATA_FORMAT_YUVI420: - imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::YUVI420); - break; - case VIDEO_DATA_FORMAT_NV12: - imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV12); - break; - case VIDEO_DATA_FORMAT_NV21: - imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV21); - break; - case VIDEO_DATA_FORMAT_RGBA8888: - imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::RGBA); - break; - default: - DHLOGE("%s: Video format is invalid.", LOG_TAG); - return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM; - } + + imageFormat_.PutIntValue("pixel_format", static_cast(MediaAVCodec::VideoPixelFormat::RGBA)); imageFormat_.PutLongValue("max_input_size", MAX_YUV420_BUFFER_SIZE); imageFormat_.PutIntValue("width", configParam.GetVideoWidth()); imageFormat_.PutIntValue("height", configParam.GetVideoHeight()); - imageFormat_.PutIntValue("frame_rate", configParam.GetFps()); + imageFormat_.PutDoubleValue("frame_rate", configParam.GetFps()); int32_t ret = videoEncoder_->Configure(imageFormat_); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: Configure encoder failed.", LOG_TAG); return ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED; } return DH_SUCCESS; } -void ImageSourceEncoder::OnError(Media::AVCodecErrorType errorType, int32_t errorCode) +void ImageSourceEncoder::OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode) { DHLOGI("%s: Encoder error, errorType:%" PRId32", errorCode:%" PRId32, LOG_TAG, errorType, errorCode); std::shared_ptr listener = imageProcessorListener_.lock(); @@ -413,8 +394,8 @@ void ImageSourceEncoder::OnError(Media::AVCodecErrorType errorType, int32_t erro listener->OnProcessorStateNotify(errorCode); } -void ImageSourceEncoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, - Media::AVCodecBufferFlag flag) +void ImageSourceEncoder::OnOutputBufferAvailable(uint32_t index, MediaAVCodec::AVCodecBufferInfo info, + MediaAVCodec::AVCodecBufferFlag flag, std::shared_ptr buffer) { DHLOGD("%s: OnOutputBufferAvailable, receiv H264 data from encoder.", LOG_TAG); std::shared_ptr listener = imageProcessorListener_.lock(); @@ -428,9 +409,8 @@ void ImageSourceEncoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecB } encoderBufferInfo_ = info; - videoSharedMemory_ = videoEncoder_->GetOutputBuffer(index); - if (videoSharedMemory_ == nullptr) { - DHLOGE("%s: GetOutputBuffer failed.", LOG_TAG); + if (buffer == nullptr) { + DHLOGE("%s: Buffer is null, index = %d", LOG_TAG, index); return; } @@ -440,7 +420,7 @@ void ImageSourceEncoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecB return; } auto dataBuf = std::make_shared(dataSize); - int32_t ret = memcpy_s(dataBuf->Data(), dataBuf->Capacity(), videoSharedMemory_->GetBase(), dataSize); + int32_t ret = memcpy_s(dataBuf->Data(), dataBuf->Capacity(), buffer->GetBase(), dataSize); if (ret != EOK) { DHLOGE("%s: Copy data failed.", LOG_TAG); return; @@ -449,12 +429,12 @@ void ImageSourceEncoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecB dataBuf->SetSize(dataSize); listener->OnImageProcessDone(dataBuf); ret = videoEncoder_->ReleaseOutputBuffer(index); - if (ret != Media::MSERR_OK) { + if (ret != MediaAVCodec::AVCS_ERR_OK) { DHLOGE("%s: videoEncoder ReleaseOutputBuffer failed.", LOG_TAG); } } -void ImageSourceEncoder::OnInputBufferAvailable(uint32_t index) +void ImageSourceEncoder::OnInputBufferAvailable(uint32_t index, std::shared_ptr buffer) { (void) index; } diff --git a/services/screentransport/screensourcetrans/BUILD.gn b/services/screentransport/screensourcetrans/BUILD.gn index 49aa88c3..d81bbb57 100644 --- a/services/screentransport/screensourcetrans/BUILD.gn +++ b/services/screentransport/screensourcetrans/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -73,6 +73,7 @@ ohos_shared_library("distributed_screen_sourcetrans") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:distributed_av_sender", "distributed_hardware_fwk:libdhfwk_sdk", @@ -82,7 +83,7 @@ ohos_shared_library("distributed_screen_sourcetrans") { "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", - "player_framework:media_client", + "media_foundation:media_foundation", ] if (!distributed_screen_common) { diff --git a/services/screentransport/test/fuzztest/screensinkprocessor/onbufferavailable_fuzzer/BUILD.gn b/services/screentransport/test/fuzztest/screensinkprocessor/onbufferavailable_fuzzer/BUILD.gn index 9ef08e9a..95cb9fd2 100644 --- a/services/screentransport/test/fuzztest/screensinkprocessor/onbufferavailable_fuzzer/BUILD.gn +++ b/services/screentransport/test/fuzztest/screensinkprocessor/onbufferavailable_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 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 @@ -61,12 +61,13 @@ ohos_fuzztest("OnBufferAvailableFuzzTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:libdhfwk_sdk", "graphic_surface:surface", "graphic_surface:sync_fence", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", ] } diff --git a/services/screentransport/test/fuzztest/screensinkprocessor/onbufferavailable_fuzzer/onbufferavailable_fuzzer.cpp b/services/screentransport/test/fuzztest/screensinkprocessor/onbufferavailable_fuzzer/onbufferavailable_fuzzer.cpp index b8a45c04..3599a089 100644 --- a/services/screentransport/test/fuzztest/screensinkprocessor/onbufferavailable_fuzzer/onbufferavailable_fuzzer.cpp +++ b/services/screentransport/test/fuzztest/screensinkprocessor/onbufferavailable_fuzzer/onbufferavailable_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -21,7 +21,7 @@ #include "avcodec_common.h" #include "dscreen_constants.h" #include "dscreen_errcode.h" -#include "format.h" +#include "meta/format.h" #include "iimage_source_processor_listener.h" #include "screen_sink_trans.h" #include "image_sink_decoder.h" diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onbufferavailable_fuzzer/BUILD.gn b/services/screentransport/test/fuzztest/screensourceprocessor/onbufferavailable_fuzzer/BUILD.gn index ee2777c4..e5462741 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onbufferavailable_fuzzer/BUILD.gn +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onbufferavailable_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 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 @@ -61,12 +61,13 @@ ohos_fuzztest("OnBufferAvailableFuzzTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:libdhfwk_sdk", "graphic_surface:surface", "graphic_surface:sync_fence", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", ] } diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/BUILD.gn b/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/BUILD.gn index 4a7be997..f6ef38ac 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/BUILD.gn +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 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 @@ -53,12 +53,13 @@ ohos_fuzztest("OnErrorFuzzTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:libdhfwk_sdk", "graphic_surface:surface", "graphic_surface:sync_fence", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", ] defines = [ diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/onerror_fuzzer.cpp b/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/onerror_fuzzer.cpp index e0fce198..51b8dc81 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/onerror_fuzzer.cpp +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onerror_fuzzer/onerror_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -19,12 +19,12 @@ #include "avcodec_common.h" #include "dscreen_constants.h" -#include "format.h" +#include "meta/format.h" #include "iimage_source_processor_listener.h" #include "image_source_encoder.h" #include "image_encoder_callback.h" #include "iscreen_channel_listener.h" -#include "media_errors.h" +#include "avcodec_errors.h" #include "screen_source_trans.h" namespace OHOS { @@ -38,7 +38,7 @@ void OnErrorFuzzTest(const uint8_t* data, size_t size) std::shared_ptr encoder = std::make_shared(listener); std::shared_ptr encoderCallback = std::make_shared(encoder); int32_t errorCode = *(reinterpret_cast(data)); - Media::AVCodecErrorType errorType = Media::AVCODEC_ERROR_INTERNAL; + MediaAVCodec::AVCodecErrorType errorType = MediaAVCodec::AVCODEC_ERROR_INTERNAL; encoderCallback->OnError(errorType, errorCode); } } diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/BUILD.gn b/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/BUILD.gn index f55190df..baf1316e 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/BUILD.gn +++ b/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 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 @@ -53,12 +53,13 @@ ohos_fuzztest("OnInputBufferAvailableFuzzTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:libdhfwk_sdk", "graphic_surface:surface", "graphic_surface:sync_fence", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", ] defines = [ diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/oninputbufferavailable_fuzzer.cpp b/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/oninputbufferavailable_fuzzer.cpp index 3bd7c3dd..1ad38760 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/oninputbufferavailable_fuzzer.cpp +++ b/services/screentransport/test/fuzztest/screensourceprocessor/oninputbufferavailable_fuzzer/oninputbufferavailable_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -18,7 +18,7 @@ #include #include "avcodec_common.h" -#include "format.h" +#include "meta/format.h" #include "image_encoder_callback.h" #include "screen_source_trans.h" @@ -33,7 +33,8 @@ void OnInputBufferAvailableFuzzTest(const uint8_t* data, size_t size) std::shared_ptr encoder = std::make_shared(listener); std::shared_ptr encoderCallback = std::make_shared(encoder); uint32_t index = *(reinterpret_cast(data)); - encoderCallback->OnInputBufferAvailable(index); + std::shared_ptr buffer = nullptr; + encoderCallback->OnInputBufferAvailable(index, buffer); } } } diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/BUILD.gn b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/BUILD.gn index 169abcf7..4a23f2f7 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/BUILD.gn +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 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 @@ -54,12 +54,13 @@ ohos_fuzztest("OnOutputBufferAvailableFuzzTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:libdhfwk_sdk", "graphic_surface:surface", "graphic_surface:sync_fence", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", ] defines = [ diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/onoutputbufferavailable_fuzzer.cpp b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/onoutputbufferavailable_fuzzer.cpp index ad7f052a..38c161a1 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/onoutputbufferavailable_fuzzer.cpp +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputbufferavailable_fuzzer/onoutputbufferavailable_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -18,7 +18,7 @@ #include #include "avcodec_common.h" -#include "format.h" +#include "meta/format.h" #include "image_encoder_callback.h" #include "screen_source_trans.h" @@ -33,9 +33,10 @@ void OnOutputBufferAvailableFuzzTest(const uint8_t* data, size_t size) std::shared_ptr encoder = std::make_shared(listener); std::shared_ptr encoderCallback = std::make_shared(encoder); uint32_t index = *(reinterpret_cast(data)); - Media::AVCodecBufferInfo info; - Media::AVCodecBufferFlag flag = Media::AVCODEC_BUFFER_FLAG_NONE; - encoderCallback->OnOutputBufferAvailable(index, info, flag); + MediaAVCodec::AVCodecBufferInfo info; + MediaAVCodec::AVCodecBufferFlag flag = MediaAVCodec::AVCODEC_BUFFER_FLAG_NONE; + std::shared_ptr buffer = nullptr; + encoderCallback->OnOutputBufferAvailable(index, info, flag, buffer); } } } diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputformatchanged_fuzzer/BUILD.gn b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputformatchanged_fuzzer/BUILD.gn index 86822d76..db733103 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputformatchanged_fuzzer/BUILD.gn +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputformatchanged_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2024 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 @@ -53,12 +53,13 @@ ohos_fuzztest("OnOutputFormatChangedFuzzTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "distributed_hardware_fwk:libdhfwk_sdk", "graphic_surface:surface", "graphic_surface:sync_fence", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", ] defines = [ diff --git a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputformatchanged_fuzzer/onoutputformatchanged_fuzzer.cpp b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputformatchanged_fuzzer/onoutputformatchanged_fuzzer.cpp index e74b8d33..34bf3e66 100644 --- a/services/screentransport/test/fuzztest/screensourceprocessor/onoutputformatchanged_fuzzer/onoutputformatchanged_fuzzer.cpp +++ b/services/screentransport/test/fuzztest/screensourceprocessor/onoutputformatchanged_fuzzer/onoutputformatchanged_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -20,12 +20,12 @@ #include "avcodec_common.h" #include "dscreen_constants.h" #include "dscreen_errcode.h" -#include "format.h" +#include "meta/format.h" #include "iimage_source_processor_listener.h" #include "image_source_encoder.h" #include "image_encoder_callback.h" #include "iscreen_channel_listener.h" -#include "media_errors.h" +#include "avcodec_errors.h" #include "screen_source_trans.h" namespace OHOS { diff --git a/services/screentransport/test/unittest/screensinkprocessor/BUILD.gn b/services/screentransport/test/unittest/screensinkprocessor/BUILD.gn index 8c64475b..9e1d32a7 100644 --- a/services/screentransport/test/unittest/screensinkprocessor/BUILD.gn +++ b/services/screentransport/test/unittest/screensinkprocessor/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -64,9 +64,10 @@ ohos_unittest("SinkProcessorTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "graphic_surface:surface", - "player_framework:media_client", + "media_foundation:media_foundation", ] defines = [ diff --git a/services/screentransport/test/unittest/screensinkprocessor/include/image_sink_decoder_test.h b/services/screentransport/test/unittest/screensinkprocessor/include/image_sink_decoder_test.h index 77a9bcc7..ed5b6ae9 100644 --- a/services/screentransport/test/unittest/screensinkprocessor/include/image_sink_decoder_test.h +++ b/services/screentransport/test/unittest/screensinkprocessor/include/image_sink_decoder_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -35,6 +35,7 @@ public: VideoParam param_; std::shared_ptr imageDecoder_ = nullptr; + std::shared_ptr videoDecoder_ = nullptr; std::shared_ptr imageListener_ = nullptr; }; } // namespace DistributedHardware diff --git a/services/screentransport/test/unittest/screensinkprocessor/include/image_sink_processor_test.h b/services/screentransport/test/unittest/screensinkprocessor/include/image_sink_processor_test.h index a56bf79a..ac524c95 100644 --- a/services/screentransport/test/unittest/screensinkprocessor/include/image_sink_processor_test.h +++ b/services/screentransport/test/unittest/screensinkprocessor/include/image_sink_processor_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -36,6 +36,7 @@ public: VideoParam param_; std::shared_ptr processor_; std::shared_ptr imageListener_; + std::shared_ptr videoDecoder_ = nullptr; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp b/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp index e86261bc..cab99cb9 100644 --- a/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp +++ b/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_decoder_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -43,10 +43,19 @@ void ImageSinkDecoderTest::SetUp(void) imageListener_ = std::make_shared(); imageDecoder_ = std::make_shared(imageListener_); - imageDecoder_->videoDecoder_ = Media::VideoDecoderFactory::CreateByMime("video/avc"); + videoDecoder_ = MediaAVCodec::VideoDecoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); + imageDecoder_->videoDecoder_ = videoDecoder_; } -void ImageSinkDecoderTest::TearDown(void) {} +void ImageSinkDecoderTest::TearDown(void) +{ + if (videoDecoder_ != nullptr) { + videoDecoder_->Stop(); + videoDecoder_->Release(); + videoDecoder_ = nullptr; + } +} /** * @tc.name: configure_decoder_test_001 @@ -79,8 +88,8 @@ HWTEST_F(ImageSinkDecoderTest, configure_decoder_test_002, TestSize.Level1) */ HWTEST_F(ImageSinkDecoderTest, configure_decoder_test_003, TestSize.Level1) { - param_.videoFormat_ = VIDEO_CODEC_TYPE_INVALID; - EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION, imageDecoder_->ConfigureDecoder(param_)); + param_.SetVideoWidth(0); + EXPECT_EQ(ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED, imageDecoder_->ConfigureDecoder(param_)); } /** @@ -114,7 +123,7 @@ HWTEST_F(ImageSinkDecoderTest, release_decoder_test_002, TestSize.Level1) */ HWTEST_F(ImageSinkDecoderTest, start_decoder_test_001, TestSize.Level1) { - EXPECT_EQ(ERR_DH_SCREEN_CODEC_PREPARE_FAILED, imageDecoder_->StartDecoder()); + EXPECT_EQ(ERR_DH_SCREEN_CODEC_START_FAILED, imageDecoder_->StartDecoder()); } /** @@ -176,18 +185,6 @@ HWTEST_F(ImageSinkDecoderTest, init_video_decoder_test_003, TestSize.Level1) EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, imageDecoder_->InitVideoDecoder(param_)); } -/** - * @tc.name: init_video_decoder_test_004 - * @tc.desc: Verify the InitVideoDecoder function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ -HWTEST_F(ImageSinkDecoderTest, init_video_decoder_test_004, TestSize.Level1) -{ - param_.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4; - EXPECT_EQ(DH_SUCCESS, imageDecoder_->InitVideoDecoder(param_)); -} - /** * @tc.name: set_decoder_format_test_001 * @tc.desc: Verify the SetDecoderFormat function. @@ -208,7 +205,6 @@ HWTEST_F(ImageSinkDecoderTest, set_decoder_format_test_001, TestSize.Level1) HWTEST_F(ImageSinkDecoderTest, set_decoder_format_test_002, TestSize.Level1) { param_.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H265; - param_.videoFormat_ = VIDEO_DATA_FORMAT_NV12; EXPECT_EQ(DH_SUCCESS, imageDecoder_->SetDecoderFormat(param_)); } @@ -244,9 +240,8 @@ HWTEST_F(ImageSinkDecoderTest, set_decoder_format_test_004, TestSize.Level1) */ HWTEST_F(ImageSinkDecoderTest, set_decoder_format_test_005, TestSize.Level1) { - param_.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H265; - param_.videoFormat_ = VIDEO_CODEC_TYPE_INVALID; - EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION, imageDecoder_->SetDecoderFormat(param_)); + param_.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264); + EXPECT_EQ(DH_SUCCESS, imageDecoder_->SetDecoderFormat(param_)); } /** @@ -257,22 +252,8 @@ HWTEST_F(ImageSinkDecoderTest, set_decoder_format_test_005, TestSize.Level1) */ HWTEST_F(ImageSinkDecoderTest, set_decoder_format_test_006, TestSize.Level1) { - param_.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4; - param_.videoFormat_ = VIDEO_DATA_FORMAT_NV21; - EXPECT_EQ(DH_SUCCESS, imageDecoder_->SetDecoderFormat(param_)); -} - -/** - * @tc.name: set_decoder_format_test_007 - * @tc.desc: Verify the SetDecoderFormat function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ -HWTEST_F(ImageSinkDecoderTest, set_decoder_format_test_007, TestSize.Level1) -{ - param_.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4; - param_.videoFormat_ = VIDEO_DATA_FORMAT_RGBA8888; - EXPECT_EQ(DH_SUCCESS, imageDecoder_->SetDecoderFormat(param_)); + param_.SetVideoWidth(0); + EXPECT_EQ(ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED, imageDecoder_->SetDecoderFormat(param_)); } /** @@ -283,7 +264,7 @@ HWTEST_F(ImageSinkDecoderTest, set_decoder_format_test_007, TestSize.Level1) */ HWTEST_F(ImageSinkDecoderTest, set_output_surface_test_001, TestSize.Level1) { - Media::AVCodecErrorType errorType = Media::AVCODEC_ERROR_EXTEND_START; + MediaAVCodec::AVCodecErrorType errorType = MediaAVCodec::AVCODEC_ERROR_EXTEND_START; imageDecoder_->OnError(errorType, DH_SUCCESS); sptr surface = IConsumerSurface::Create("test"); sptr bp = surface->GetProducer(); @@ -300,14 +281,15 @@ HWTEST_F(ImageSinkDecoderTest, set_output_surface_test_001, TestSize.Level1) */ HWTEST_F(ImageSinkDecoderTest, on_input_buffer_available_test_001, TestSize.Level1) { - Media::AVCodecErrorType errorType = Media::AVCODEC_ERROR_EXTEND_START; + MediaAVCodec::AVCodecErrorType errorType = MediaAVCodec::AVCODEC_ERROR_EXTEND_START; int32_t errorCode = DH_SUCCESS; std::shared_ptr listener= nullptr; imageDecoder_->imageProcessorListener_ = listener; imageDecoder_->OnError(errorType, errorCode); unsigned int len = 1; - imageDecoder_->OnInputBufferAvailable(0); - EXPECT_EQ(len, imageDecoder_->bufferIndexQueue_.size()); + std::shared_ptr buffer = nullptr; + imageDecoder_->OnInputBufferAvailable(0, buffer); + EXPECT_EQ(len, imageDecoder_->availableInputIndexsQueue_.size()); } /** @@ -319,10 +301,11 @@ HWTEST_F(ImageSinkDecoderTest, on_input_buffer_available_test_001, TestSize.Leve HWTEST_F(ImageSinkDecoderTest, on_output_buffer_available_test_001, TestSize.Level1) { uint32_t index = 0; - Media::AVCodecBufferFlag flag = Media::AVCODEC_BUFFER_FLAG_CODEC_DATA; - Media::AVCodecBufferInfo info; + MediaAVCodec::AVCodecBufferFlag flag = MediaAVCodec::AVCODEC_BUFFER_FLAG_CODEC_DATA; + MediaAVCodec::AVCodecBufferInfo info; info.presentationTimeUs = 1; - imageDecoder_->OnOutputBufferAvailable(index, info, flag); + std::shared_ptr buffer = nullptr; + imageDecoder_->OnOutputBufferAvailable(index, info, flag, buffer); EXPECT_EQ(info.presentationTimeUs, imageDecoder_->decoderBufferInfo_.presentationTimeUs); } @@ -335,12 +318,13 @@ HWTEST_F(ImageSinkDecoderTest, on_output_buffer_available_test_001, TestSize.Lev HWTEST_F(ImageSinkDecoderTest, on_output_buffer_available_test_002, TestSize.Level1) { uint32_t index = 0; - Media::AVCodecBufferFlag flag = Media::AVCODEC_BUFFER_FLAG_CODEC_DATA; - Media::AVCodecBufferInfo info; + MediaAVCodec::AVCodecBufferFlag flag = MediaAVCodec::AVCODEC_BUFFER_FLAG_CODEC_DATA; + MediaAVCodec::AVCodecBufferInfo info; info.presentationTimeUs = 1; imageDecoder_->decoderBufferInfo_.presentationTimeUs = 0; imageDecoder_->videoDecoder_ = nullptr; - imageDecoder_->OnOutputBufferAvailable(index, info, flag); + std::shared_ptr buffer = nullptr; + imageDecoder_->OnOutputBufferAvailable(index, info, flag, buffer); EXPECT_NE(info.presentationTimeUs, imageDecoder_->decoderBufferInfo_.presentationTimeUs); } @@ -397,7 +381,7 @@ HWTEST_F(ImageSinkDecoderTest, process_data_test_001, TestSize.Level1) imageDecoder_->videoDataQueue_.push(data); uint32_t index = 0; - imageDecoder_->bufferIndexQueue_.push(index); + imageDecoder_->availableInputIndexsQueue_.push(index); imageDecoder_->StartInputThread(); EXPECT_EQ(true, imageDecoder_->isDecoderReady_); diff --git a/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_processor_test.cpp b/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_processor_test.cpp index 30d0a654..8fdf16b8 100644 --- a/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_processor_test.cpp +++ b/services/screentransport/test/unittest/screensinkprocessor/src/image_sink_processor_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -43,10 +43,19 @@ void ImageSinkProcessorTest::SetUp(void) processor_ = std::make_shared(); imageListener_ = std::make_shared(); processor_->imageDecoder_ = std::make_shared(imageListener_); - processor_->imageDecoder_->videoDecoder_ = Media::VideoDecoderFactory::CreateByMime("video/avc"); + videoDecoder_ = MediaAVCodec::VideoDecoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); + processor_->imageDecoder_->videoDecoder_ = videoDecoder_; } -void ImageSinkProcessorTest::TearDown(void) {} +void ImageSinkProcessorTest::TearDown(void) +{ + if (videoDecoder_ != nullptr) { + videoDecoder_->Stop(); + videoDecoder_->Release(); + videoDecoder_ = nullptr; + } +} /** * @tc.name: configure_image_processor_test_001 @@ -103,7 +112,8 @@ HWTEST_F(ImageSinkProcessorTest, release_image_processor_test_002, TestSize.Leve */ HWTEST_F(ImageSinkProcessorTest, start_image_processor_test_001, TestSize.Level1) { - EXPECT_EQ(ERR_DH_SCREEN_CODEC_PREPARE_FAILED, processor_->StartImageProcessor()); + processor_->imageDecoder_->videoDecoder_ = nullptr; + EXPECT_NE(DH_SUCCESS, processor_->StartImageProcessor()); } /** diff --git a/services/screentransport/test/unittest/screensinktrans/BUILD.gn b/services/screentransport/test/unittest/screensinktrans/BUILD.gn index 2951a93b..df3f4813 100644 --- a/services/screentransport/test/unittest/screensinktrans/BUILD.gn +++ b/services/screentransport/test/unittest/screensinktrans/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -61,10 +61,11 @@ ohos_unittest("SinkTransTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "dsoftbus:softbus_client", "graphic_surface:surface", - "player_framework:media_client", + "media_foundation:media_foundation", ] defines = [ diff --git a/services/screentransport/test/unittest/screensinktrans/src/screen_sink_trans_test.cpp b/services/screentransport/test/unittest/screensinktrans/src/screen_sink_trans_test.cpp index 5a6a088a..3c351b7c 100644 --- a/services/screentransport/test/unittest/screensinktrans/src/screen_sink_trans_test.cpp +++ b/services/screentransport/test/unittest/screensinktrans/src/screen_sink_trans_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -51,7 +51,13 @@ void ScreenSinkTransTest::SetUp(void) param_.fps_ = FPS; } -void ScreenSinkTransTest::TearDown(void) {} +void ScreenSinkTransTest::TearDown(void) +{ + if (trans_ != nullptr) { + trans_->Stop(); + trans_->Release(); + } +} /** * @tc.name: setup_test_001 diff --git a/services/screentransport/test/unittest/screensourceprocessor/BUILD.gn b/services/screentransport/test/unittest/screensourceprocessor/BUILD.gn index edc9a1b9..29bcc650 100644 --- a/services/screentransport/test/unittest/screensourceprocessor/BUILD.gn +++ b/services/screentransport/test/unittest/screensourceprocessor/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -64,11 +64,12 @@ ohos_unittest("SourceProcessorTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "graphic_surface:surface", "graphic_surface:sync_fence", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", ] } diff --git a/services/screentransport/test/unittest/screensourceprocessor/src/image_source_encoder_test.cpp b/services/screentransport/test/unittest/screensourceprocessor/src/image_source_encoder_test.cpp index 2ba35e1f..aab50148 100644 --- a/services/screentransport/test/unittest/screensourceprocessor/src/image_source_encoder_test.cpp +++ b/services/screentransport/test/unittest/screensourceprocessor/src/image_source_encoder_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -29,7 +29,13 @@ void ImageSourceEncoderTest::SetUp(void) encoder = std::make_shared(imageListener); } -void ImageSourceEncoderTest::TearDown(void) {} +void ImageSourceEncoderTest::TearDown(void) +{ + if (encoder != nullptr) { + encoder->StopEncoder(); + encoder->ReleaseEncoder(); + } +} /** * @tc.name: ConfigureEncoder_001 @@ -40,11 +46,9 @@ void ImageSourceEncoderTest::TearDown(void) {} HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_001, TestSize.Level1) { VideoParam configParam; - configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; - configParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; - + configParam.SetCodecType(2); int32_t actual = encoder->ConfigureEncoder(configParam); - EXPECT_EQ(ERR_DH_SCREEN_CODEC_SURFACE_ERROR, actual); + EXPECT_EQ(ERR_DH_SCREEN_TRANS_CREATE_CODEC_FAILED, actual); } /** @@ -56,10 +60,9 @@ HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_001, TestSize.Level1) HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_002, TestSize.Level1) { VideoParam configParam; - configParam.codecType_ = -1; - + configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264); int32_t actual = encoder->ConfigureEncoder(configParam); - EXPECT_EQ(ERR_DH_SCREEN_TRANS_CREATE_CODEC_FAILED, actual); + EXPECT_EQ(ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED, actual); } /** @@ -68,14 +71,16 @@ HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_002, TestSize.Level1) * @tc.type: FUNC * @tc.require: Issue Number */ -HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_003, TestSize.Level1) + +HWTEST_F(ImageSourceEncoderTest, ConfigureEncoder_004, TestSize.Level1) { VideoParam configParam; - configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; - configParam.videoFormat_ = -1; + configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264); + configParam.SetVideoWidth(DSCREEN_MAX_VIDEO_DATA_WIDTH); + configParam.SetVideoHeight(DSCREEN_MAX_VIDEO_DATA_HEIGHT); int32_t actual = encoder->ConfigureEncoder(configParam); - EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual); + EXPECT_EQ(DH_SUCCESS, actual); } /** @@ -98,7 +103,8 @@ HWTEST_F(ImageSourceEncoderTest, ReleaseEncoder_001, TestSize.Level1) */ HWTEST_F(ImageSourceEncoderTest, ReleaseEncoder_002, TestSize.Level1) { - encoder->videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/avc"); + encoder->videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); int32_t actual = encoder->ReleaseEncoder(); EXPECT_EQ(DH_SUCCESS, actual); @@ -124,10 +130,10 @@ HWTEST_F(ImageSourceEncoderTest, StartEncoder_001, TestSize.Level1) */ HWTEST_F(ImageSourceEncoderTest, StartEncoder_002, TestSize.Level1) { - encoder->videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/avc"); - + encoder->videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); int32_t actual = encoder->StartEncoder(); - EXPECT_EQ(ERR_DH_SCREEN_CODEC_PREPARE_FAILED, actual); + EXPECT_EQ(ERR_DH_SCREEN_CODEC_START_FAILED, actual); } /** @@ -150,7 +156,8 @@ HWTEST_F(ImageSourceEncoderTest, StopEncoder_001, TestSize.Level1) */ HWTEST_F(ImageSourceEncoderTest, StopEncoder_002, TestSize.Level1) { - encoder->videoEncoder_ = Media::VideoEncoderFactory::CreateByMime("video/avc"); + encoder->videoEncoder_ = MediaAVCodec::VideoEncoderFactory::CreateByMime( + std::string(MediaAVCodec::CodecMimeType::VIDEO_AVC)); int32_t actual = encoder->StopEncoder(); EXPECT_EQ(ERR_DH_SCREEN_CODEC_STOP_FAILED, actual); @@ -180,7 +187,7 @@ HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_001, TestSize.Level1) HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_002, TestSize.Level1) { VideoParam configParam; - configParam.codecType_ = -1; + configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4; int32_t actual = encoder->InitVideoEncoder(configParam); EXPECT_EQ(ERR_DH_SCREEN_TRANS_CREATE_CODEC_FAILED, actual); @@ -210,7 +217,7 @@ HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_003, TestSize.Level1) HWTEST_F(ImageSourceEncoderTest, InitVideoEncoder_004, TestSize.Level1) { VideoParam configParam; - configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4; + configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; int32_t actual = encoder->InitVideoEncoder(configParam); EXPECT_EQ(DH_SUCCESS, actual); @@ -254,8 +261,9 @@ HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_002, TestSize.Level1) HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_003, TestSize.Level1) { VideoParam configParam; - configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; - configParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264); + configParam.SetVideoWidth(DSCREEN_MAX_VIDEO_DATA_WIDTH); + configParam.SetVideoHeight(DSCREEN_MAX_VIDEO_DATA_HEIGHT); int32_t actual = encoder->InitVideoEncoder(configParam); actual = encoder->SetEncoderFormat(configParam); @@ -271,47 +279,15 @@ HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_003, TestSize.Level1) HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_004, TestSize.Level1) { VideoParam configParam; - configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H265; - configParam.videoFormat_ = VIDEO_DATA_FORMAT_NV12; + configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H265); + configParam.SetVideoWidth(DSCREEN_MAX_VIDEO_DATA_WIDTH); + configParam.SetVideoHeight(DSCREEN_MAX_VIDEO_DATA_HEIGHT); int32_t actual = encoder->InitVideoEncoder(configParam); actual = encoder->SetEncoderFormat(configParam); EXPECT_EQ(DH_SUCCESS, actual); } -/** - * @tc.name: SetEncoderFormat_005 - * @tc.desc: Verify the SetEncoderFormat function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ -HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_005, TestSize.Level1) -{ - VideoParam configParam; - configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4; - configParam.videoFormat_ = VIDEO_DATA_FORMAT_NV21; - int32_t actual = encoder->InitVideoEncoder(configParam); - actual = encoder->SetEncoderFormat(configParam); - - EXPECT_EQ(DH_SUCCESS, actual); -} - -/** - * @tc.name: SetEncoderFormat_006 - * @tc.desc: Verify the SetEncoderFormat function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ -HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_006, TestSize.Level1) -{ - VideoParam configParam; - configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4; - configParam.videoFormat_ = VIDEO_DATA_FORMAT_RGBA8888; - int32_t actual = encoder->InitVideoEncoder(configParam); - actual = encoder->SetEncoderFormat(configParam); - - EXPECT_EQ(DH_SUCCESS, actual); -} /** * @tc.name: SetEncoderFormat_007 @@ -322,9 +298,11 @@ HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_006, TestSize.Level1) HWTEST_F(ImageSourceEncoderTest, SetEncoderFormat_007, TestSize.Level1) { VideoParam configParam; - configParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4; - configParam.videoFormat_ = -1; + configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H265); + configParam.SetVideoWidth(DSCREEN_MAX_VIDEO_DATA_WIDTH); + configParam.SetVideoHeight(DSCREEN_MAX_VIDEO_DATA_HEIGHT); int32_t actual = encoder->InitVideoEncoder(configParam); + configParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_MPEG4); actual = encoder->SetEncoderFormat(configParam); EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual); } diff --git a/services/screentransport/test/unittest/screensourceprocessor/src/image_source_processor_test.cpp b/services/screentransport/test/unittest/screensourceprocessor/src/image_source_processor_test.cpp index f5cc926b..38f3aa67 100644 --- a/services/screentransport/test/unittest/screensourceprocessor/src/image_source_processor_test.cpp +++ b/services/screentransport/test/unittest/screensourceprocessor/src/image_source_processor_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -41,7 +41,7 @@ HWTEST_F(ImageSourceProcessorTest, ConfigureImageProcessor_001, TestSize.Level1) int32_t actual = processor.ConfigureImageProcessor(localParam, remoteParam, listener); - EXPECT_EQ(ERR_DH_SCREEN_CODEC_SURFACE_ERROR, actual); + EXPECT_EQ(ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED, actual); } /** @@ -53,13 +53,15 @@ HWTEST_F(ImageSourceProcessorTest, ConfigureImageProcessor_001, TestSize.Level1) HWTEST_F(ImageSourceProcessorTest, ConfigureImageProcessor_002, TestSize.Level1) { VideoParam localParam; - localParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; VideoParam remoteParam; - std::shared_ptr listener = nullptr; + localParam.SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264); + localParam.SetVideoWidth(DSCREEN_MAX_VIDEO_DATA_WIDTH); + localParam.SetVideoHeight(DSCREEN_MAX_VIDEO_DATA_HEIGHT); + std::shared_ptr listener = nullptr; int32_t actual = processor.ConfigureImageProcessor(localParam, remoteParam, listener); - EXPECT_EQ(ERR_DH_SCREEN_CODEC_SURFACE_ERROR, actual); + EXPECT_EQ(DH_SUCCESS, actual); } /** diff --git a/services/screentransport/test/unittest/screensourcetrans/BUILD.gn b/services/screentransport/test/unittest/screensourcetrans/BUILD.gn index 4816493b..5bf69646 100644 --- a/services/screentransport/test/unittest/screensourcetrans/BUILD.gn +++ b/services/screentransport/test/unittest/screensourcetrans/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -69,13 +69,14 @@ ohos_unittest("SourceTransTest") { "access_token:libaccesstoken_sdk", "access_token:libnativetoken", "access_token:libtoken_setproc", + "av_codec:av_codec_client", "c_utils:utils", "dsoftbus:softbus_client", "graphic_2d:libgraphic_utils", "graphic_surface:surface", "graphic_surface:sync_fence", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", ] } diff --git a/services/screentransport/test/unittest/screensourcetrans/src/screen_source_trans_test.cpp b/services/screentransport/test/unittest/screensourcetrans/src/screen_source_trans_test.cpp index b442d6b1..e853b494 100644 --- a/services/screentransport/test/unittest/screensourcetrans/src/screen_source_trans_test.cpp +++ b/services/screentransport/test/unittest/screensourcetrans/src/screen_source_trans_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -156,7 +156,7 @@ HWTEST_F(ScreenSourceTransTest, InitScreenTrans_001, TestSize.Level1) int32_t actual = trans->InitScreenTrans(localParam, remoteParam, peerDevId); DisablePermissionAccess(tokenId_); - EXPECT_EQ(ERR_DH_SCREEN_CODEC_SURFACE_ERROR, actual); + EXPECT_EQ(ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED, actual); } /** diff --git a/services/screentransport/test/unittest/screentranstestutils/BUILD.gn b/services/screentransport/test/unittest/screentranstestutils/BUILD.gn index eec6b6b2..237199d2 100644 --- a/services/screentransport/test/unittest/screentranstestutils/BUILD.gn +++ b/services/screentransport/test/unittest/screentranstestutils/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. +# Copyright (c) 2022-2024 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 @@ -68,12 +68,13 @@ ohos_unittest("ScreenCallbackTest") { ] external_deps = [ + "av_codec:av_codec_client", "c_utils:utils", "graphic_2d:libgraphic_utils", "graphic_surface:surface", "graphic_surface:sync_fence", "ipc:ipc_core", - "player_framework:media_client", + "media_foundation:media_foundation", ] } diff --git a/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h b/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h index 09cd1ce1..617fcde9 100644 --- a/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h +++ b/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -32,7 +32,7 @@ constexpr int32_t VIDEO_CODEC_TYPE_INVALID = -1; constexpr int32_t VIDEO_DATA_FORMAT_INVALID = -1; constexpr int32_t WIDTH_INVALID = 9999; constexpr int32_t HEIGHT_INVALID = 9999; -constexpr int32_t FPS = 30; +constexpr double FPS = 30.0; constexpr size_t DATA_LEN = 128; class MockIScreenSinkTransCallback : public IScreenSinkTransCallback { diff --git a/services/screentransport/test/unittest/screentranstestutils/src/screen_callback_test.cpp b/services/screentransport/test/unittest/screentranstestutils/src/screen_callback_test.cpp index a399a629..3618d880 100644 --- a/services/screentransport/test/unittest/screentranstestutils/src/screen_callback_test.cpp +++ b/services/screentransport/test/unittest/screentranstestutils/src/screen_callback_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -14,9 +14,9 @@ */ #include -#include "media_errors.h" +#include "avcodec_errors.h" #include "avcodec_common.h" -#include "format.h" +#include "meta/format.h" #define private public #include "dscreen_constants.h" @@ -90,17 +90,18 @@ HWTEST_F(ScreenCallbackTest, RegisterStateCallback_004, TestSize.Level1) std::shared_ptr listener = std::make_shared(); std::shared_ptr encoder = std::make_shared(listener); std::shared_ptr encoderCallback = std::make_shared(encoder); - Media::AVCodecErrorType errorType = Media::AVCODEC_ERROR_INTERNAL; + MediaAVCodec::AVCodecErrorType errorType = MediaAVCodec::AVCODEC_ERROR_INTERNAL; int32_t errorCode = 0; encoderCallback->OnError(errorType, errorCode); uint32_t index = 0; - Media::AVCodecBufferInfo info; + MediaAVCodec::AVCodecBufferInfo info; info.presentationTimeUs = 0; info.size = 0; info.offset = 0; - Media::AVCodecBufferFlag flag = Media::AVCODEC_BUFFER_FLAG_NONE; - encoderCallback->OnOutputBufferAvailable(index, info, flag); - encoderCallback->OnInputBufferAvailable(index); + MediaAVCodec::AVCodecBufferFlag flag = MediaAVCodec::AVCODEC_BUFFER_FLAG_NONE; + std::shared_ptr buffer = nullptr; + encoderCallback->OnOutputBufferAvailable(index, info, flag, buffer); + encoderCallback->OnInputBufferAvailable(index, buffer); Media::Format format; encoderCallback->OnOutputFormatChanged(format); @@ -122,17 +123,18 @@ HWTEST_F(ScreenCallbackTest, RegisterStateCallback_005, TestSize.Level1) std::shared_ptr decoder = std::make_shared(listener); std::shared_ptr decoderCallback = std::make_shared(decoder); - Media::AVCodecErrorType errorType = Media::AVCODEC_ERROR_INTERNAL; + MediaAVCodec::AVCodecErrorType errorType = MediaAVCodec::AVCODEC_ERROR_INTERNAL; int32_t errorCode = 0; decoderCallback->OnError(errorType, errorCode); uint32_t index = 0; - Media::AVCodecBufferInfo info; + MediaAVCodec::AVCodecBufferInfo info; info.presentationTimeUs = 0; info.size = 0; info.offset = 0; - Media::AVCodecBufferFlag flag = Media::AVCODEC_BUFFER_FLAG_NONE; - decoderCallback->OnOutputBufferAvailable(index, info, flag); - decoderCallback->OnInputBufferAvailable(index); + MediaAVCodec::AVCodecBufferFlag flag = MediaAVCodec::AVCODEC_BUFFER_FLAG_NONE; + std::shared_ptr buffer = nullptr; + decoderCallback->OnOutputBufferAvailable(index, info, flag, buffer); + decoderCallback->OnInputBufferAvailable(index, buffer); Media::Format format; decoderCallback->OnOutputFormatChanged(format); diff --git a/services/softbusadapter/src/softbus_adapter.cpp b/services/softbusadapter/src/softbus_adapter.cpp index e0e1efbe..07fa8a6f 100644 --- a/services/softbusadapter/src/softbus_adapter.cpp +++ b/services/softbusadapter/src/softbus_adapter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -226,9 +226,9 @@ std::shared_ptr &SoftbusAdapter::GetSoftbusListenerByName(int3 { char sessionName[DSCREEN_MAX_SESSION_NAME_LEN] = ""; char peerDevId[DSCREEN_MAX_DEVICE_ID_LEN] = ""; - int32_t ret = GetPeerSessionName(sessionId, sessionName, sizeof(sessionName)); + int32_t ret = GetMySessionName(sessionId, sessionName, sizeof(sessionName)); if (ret != DH_SUCCESS) { - DHLOGE("%s: GetPeerSessionName failed ret:%" PRId32, LOG_TAG, ret); + DHLOGE("%s: GetMySessionName failed ret:%" PRId32, LOG_TAG, ret); return nullListener_; } ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId)); -- Gitee