diff --git a/bundle.json b/bundle.json index 69c5530d496ceb58dd1dd4b869b55c9ec2dd8927..7a920fa8805838d3e3a0e25e4cff5ad3fac4510f 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 bd3ec79dc0088338016d0905ab478bf3ddd85ee1..b76ed779184ca4781ede58e772db23274c35d295 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 877b64f0be85115d117393009d4027f597ad1f6a..0a1d7e9784b56cc0732751801b9250758bff01b5 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 12bb5a8d2f02b7f336d65642256074177a421230..1d4ab3d55243e4c656fb9f4fdc643e865dc55425 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 9b03bc42b055546c1078bd9a5118f510c2c68ee3..13f1fdd4e618e9cb51f3b1f989cd21c1d6de2b8e 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 e77609ba77397e973c1281e65d58a9a87b9cc277..b2b0a4f25f4ea3110045477e804221c423f0151c 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 63e5507a9e36026b10e20a99f02856dca4b8a36b..4d3cb4529854fc1c808c728c57b9f10c3f957895 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 6e9a450d1da4df1cd4cff06a2b421ab8c49e3f23..69f15b3b7130cd76b47e8e503b0f9891ff7df1c1 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 ec46cbbba4948355f656f0d5429760e7904b46bb..d01d526c5b82205aaf15d667fcfa163de6a59bc5 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 4af2aaa5c2c2bf019e5de3743f6af12559828039..812ebda93487f7be06a3f099a3cd1b3a54f3e9af 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 2f5dbfe4535c663edc49991d8e8cdc89ec4ac662..ab42beb0af19160e1f10befed70ee77712849ec5 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 5f1122a13862940963b3eec152638adac34cac56..ea80525a04f2139cb3e5466b8d9cf71ab2fc248a 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 24e84f7982bf2d67224ae26bd6fd3bae12a913ca..4736e41a5e2fc0add43b4ce14688ef3af5e4c803 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 68cf0ca56b876a8ef8f17a7a0b55f86c51598087..bb30baf229f80346040e3236d345c6622c4b9319 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 934b98a4064caed508855f007f45e3d33910bb51..7f36dd1c670a55547827a3a220e07515d828cb8b 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 b55963c52291d1a976cae8fae69b74dd211c8bd0..0eda2611d97ac224280eea66c6d934fc242f15f1 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 dfa9705ca48640ca40eaaabcd6fcdb71044df319..3d59207649244058ce6bc671c5bd22907d7267ec 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 095e959d56645a3f43e2d248afca6edbe363f7a1..e754f9b3c8c5d7040c772ce9748094009ad61b1c 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 4bcfa18d79ee12c59b83facfb9e409794349b323..7a9290ac4fcd6610cdabd3e0368e54b45882bad5 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 5a8844d596e3d79ffb099a27f07f64edccac10d1..143c8ec79a771717da6138ec832bca6a24a8e76c 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 fcedabda90b59f1e386a54d1db4211e0554305be..2bfa88ead1f2caaaa03c792c1524468aa56c6433 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 e0f647191d3598d47694e16f31ecef8bd596779d..007f0c0d7cfed18d27eb7903b63e94c107d866be 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 47e0e20603d629560d18d033faf2146e3f2c58e5..388f9eccfaed4e1111da84a5ec0147f045004f9a 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 f22b64d5ae3708a7bb5cc80d282d3866614c6a60..cbc9199925ba0de45eb559df96c72b9411594404 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 e9eb4333b5029dc7cd2b05bdc90c4c7942ba40db..180ec69921fbfef76d674cb36367c1eaf3696e11 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 0401884a2e5db276b23c11695f4611c6b2e46eae..6744e783fe237e156466d6f9f8d641b8d6215b2a 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 d36d7a965d6b7a5fd8206dacc788611f36b9ebfb..306e3cd25b01a4c35d64ec6684821f59f18575db 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 5534a2cd0e51e00516a98f4ff30eb7953c9fd6de..b83811eeacc4bc98a5a4f21b5cbb4d81059c7f14 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 a477035b445d53ef7a8a479f50eb7a0d19d06ea2..e0a64b94bb82b28e076caed775c4835906548565 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 2b29050e26e93961c62a5c88f09310e287d37ba2..61f164435b35cba291de38a2f6838954a20a6893 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 196aa16b225abdd9f8e1cad45d351ccf6da6624a..289556b15c0b01f2d30f8eda606272b26661f1d3 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 b19fb8708670905c20ec4fa4da4349283ef148c9..df4e68da94f389fadee2e3b116eea54ca8381111 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 e495674f0ce94509b755e027da4d60f6c8573694..adcef983bc08446eadd2095226be9ad826728fee 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 fa1bb0de1ab33c0918000e8a8f6e1e94f569ddbb..0f1c369756a4edb9cee9eabf8e06d9e93da01add 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 a100ce469242dd6cd4bc9944946eda3242ef1851..afc59997b8a2820bda7fd3991d26d798b84be35d 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 79a28cb344d9dcaa11d93abde7c6ce8f4007474b..78e29cbc12392c9a20f4f0ed251adec6cd5a8e62 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 2cfe9ff9215c7a6cb5dcd9e5ed6f088abd355713..ac7100f0052880f748252c7720586240a5c25cae 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 86529b2b0677dd44bf911fa0253e95c136b14a18..26e7ca79ebde67eb0ba9917816775ebbb2a1a720 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 49aa88c3c418b216bec3bf75cad0fdf7731f2e15..d81bbb572022015b8955f8df0712bb83a50687f6 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 9ef08e9abf2ee56b6ee1831ed9e85ef2d936d5f5..95cb9fd2e1fbfec6ef51c845772bd2afb497a727 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 b8a45c0477fa9ed986477534e3308522d55a9948..3599a089753d0413c61d11cb1336dfde8475d0d4 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 ee2777c4f04bfb351bc47a318f3b04281bcaa009..e5462741e2ae3a403a92b0152b1eba5438303158 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 4a7be9974f191170ca5f04504ec6d171a4e7a4a0..f6ef38acb6ac305f59faa9e4370f67d678fc429e 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 e0fce198e61ab974d27add61e020a82d15461d59..51b8dc810c782b9bdff10a28934908144edfb972 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 f55190dff1c0755099da28584a12b80ef11d63c4..baf1316effff0e023064fd28239ed6f76ba9b189 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 3bd7c3dd107df482aa501a7ca91d26b586acbf58..1ad38760d9d9e4080ebe78acdd1818453069fc75 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 169abcf7d4843d3ced4c7bc45f91ebcda4e6b61e..4a23f2f7d0c884f73d1ce31bf500104847de2c6c 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 ad7f052a2d4444088874df112372e33762996178..38c161a1d6573ebe524c7f4a4191b863b3eaea89 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 86822d7658ef051461ce4b774bb83b73a723692f..db73310304283fc878898bd16edf5a959131cd00 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 e74b8d33b83e11f27441ce7fa74f22ef3ea78e67..34bf3e66fd21005f7ae1dfc1e8d60b4effdc04aa 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 8c64475b54ad8b40db20fd09b9d972ddc5a90c92..9e1d32a7a7ba577bde3ba5b9c97c6a26608539a0 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 77a9bcc7c0d70ce0a3ecd83a242cd046d6c1d5d0..ed5b6ae9a460c66b9bdd6319dd4d550bea9763c8 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 a56bf79a6f63c722ac874b2034a9e03d7ec36f02..ac524c9570afdb69220dbea4a6d19b87c05a4783 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 e86261bcfda4cbce883f8d14f3400a92edace7b6..cab99cb92aff0dab2577433ec46a019da66663cf 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 30d0a6548dfd1a8ce671446bd799f347f366b4a0..8fdf16b84684827b0080f5b6b5bb480ccc409b2f 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 2951a93bea8a4c8be5f453ccd31a88702431b8b2..df3f48133a773dea375d93e0f88c6bfde36044f6 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 5a6a088ab9d18308bcd5bf9d4df657e5ccee5d75..3c351b7cea23b68f8d024cd17cd68d2a1e8c88cd 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 edc9a1b969a13fc10d2d95f3d21431a9153f156c..29bcc6504d77b055424430d76a6a2a101a9dbbb9 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 2ba35e1fabbb64b4ab1b4b2df14123f0d81593db..aab5014836b1232da97607b6f3a14ca80c7f3d3a 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 f5cc926bc6b478b0f71a2f0b2e73f96a10d65d00..38f3aa671319fc6e87bfbf57781b15c73cba3e2b 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 4816493bfecc7872f2645886d863069669c5f033..5bf696468955559e9fa72a7f2ac706cd77537789 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 b442d6b1cbd203f269702cb0f19f3d227a2170ef..e853b494dd9aea8c117311e1caf9199815fd2764 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 eec6b6b2147191bea3609b0064e9a6a806808960..237199d2aa1675e4917d1b84fee269bc83b5a9db 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 09cd1ce152beb86cdd6fab72a6f841dc8b7fe6ce..617fcde96899be1c4f5f50c7ac1034c48191b8b4 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 a399a62972005e468a8fadb0b19dfe56160f46c1..3618d8808b80ccbe59e13e7b405340a017550d88 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 e0e1efbe3896036a528813b535c4fddf2324151a..07fa8a6fa1bd4ee639da5c46ad9bd74efb249438 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));