From 2f578d828358a9f8f73f1ee505b43a986df9b269 Mon Sep 17 00:00:00 2001 From: sxzheng96 Date: Thu, 17 Mar 2022 11:37:30 +0800 Subject: [PATCH] modify distributed screen encoder format in RK3568 Signed-off-by: sxzheng96 --- common/include/dscreen_constants.h | 8 +- common/include/dscreen_errcode.h | 5 +- screenhandler/src/dscreen_handler.cpp | 7 +- .../include/screen_client_window_adapter.h | 2 +- services/screenservice/sourceservice/BUILD.gn | 119 +++++++++--------- .../dscreenmgr/include/dscreen.h | 1 + .../sourceservice/dscreenmgr/src/dscreen.cpp | 56 ++++++++- .../decoder/src/image_sink_decoder.cpp | 9 ++ .../include/screen_sink_trans.h | 4 +- .../screensinktrans/src/screen_sink_trans.cpp | 18 +-- .../encoder/src/image_source_encoder.cpp | 9 ++ .../include/screen_source_trans.h | 4 +- .../src/screen_source_trans.cpp | 18 +-- .../src/screen_sink_trans_test.cpp | 12 +- 14 files changed, 179 insertions(+), 93 deletions(-) diff --git a/common/include/dscreen_constants.h b/common/include/dscreen_constants.h index 50c0b15d..cce75aab 100644 --- a/common/include/dscreen_constants.h +++ b/common/include/dscreen_constants.h @@ -47,19 +47,21 @@ enum TaskType { enum CodecType : uint8_t { VIDEO_CODEC_TYPE_VIDEO_H264 = 0, VIDEO_CODEC_TYPE_VIDEO_H265 = 1, + VIDEO_CODEC_TYPE_VIDEO_MPEG4 = 2, }; enum VideoFormat : uint8_t { VIDEO_DATA_FORMAT_YUVI420 = 0, VIDEO_DATA_FORMAT_NV12 = 1, VIDEO_DATA_FORMAT_NV21 = 2, + VIDEO_DATA_FORMAT_RGBA8888 = 3, }; /* Screen package name */ -const std::string PKG_NAME = "DBinderBus_" + std::to_string(getpid()); +const std::string PKG_NAME = "ohos.dhardware"; /* Screen data session name */ -const std::string DATA_SESSION_NAME = "DBinder.ohos.dhardware.dscreen.data"; +const std::string DATA_SESSION_NAME = "ohos.dhardware.dscreen.data"; /* Screen session name max len */ constexpr uint32_t DSCREEN_MAX_SESSION_NAME_LEN = 50; @@ -112,6 +114,8 @@ const std::string KEY_ERR_CODE = "errCode"; const std::string KEY_ERR_CONTENT = "errContent"; const std::string KEY_VIDEO_PARAM = "videoParam"; const std::string KEY_MAPRELATION = "mapRelation"; +const std::string CODEC_NAME_H264 = "OMX_hisi_video_encoder_avc"; +const std::string CODEC_NAME_MPEG4 = "avenc_mpeg4"; constexpr float DEFAULT_DENSITY = 2.0; constexpr int32_t DEFAULT_SCREEN_FLAGS = 0; constexpr uint32_t DEFAULT_FPS = 30; diff --git a/common/include/dscreen_errcode.h b/common/include/dscreen_errcode.h index 7315a32b..a6101bbe 100644 --- a/common/include/dscreen_errcode.h +++ b/common/include/dscreen_errcode.h @@ -50,8 +50,9 @@ enum DScreenErrorCode { ERR_DH_SCREEN_SA_DSCREEN_TASK_NOT_VALID = -50026, ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED = -50027, ERR_DH_SCREEN_SA_INVALID_IPC_CALL = -50028, - ERR_DH_SCREEN_SA_REGISTER_SCREENLISTENER_FAIL = -520029, - ERR_DH_SCREEN_SA_UNREGISTER_SCREENLISTENER_FAIL = -520030, + ERR_DH_SCREEN_SA_REGISTER_SCREENLISTENER_FAIL = -500029, + ERR_DH_SCREEN_SA_UNREGISTER_SCREENLISTENER_FAIL = -500030, + ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL = -500031, // Transport component error code ERR_DH_SCREEN_TRANS_ERROR = -51000, ERR_DH_SCREEN_TRANS_TIMEOUT = -51001, diff --git a/screenhandler/src/dscreen_handler.cpp b/screenhandler/src/dscreen_handler.cpp index 1f632682..e6f4f589 100644 --- a/screenhandler/src/dscreen_handler.cpp +++ b/screenhandler/src/dscreen_handler.cpp @@ -156,11 +156,14 @@ std::string DScreenHandler::QueryCodecInfo() // query codec info std::shared_ptr codecList = Media::AVCodecListFactory::CreateAVCodecList(); std::vector> caps = codecList->GetVideoEncoderCaps(); + json codecTypeArray = json::array(); + for (const auto &cap : caps) { std::shared_ptr codecInfo = cap->GetCodecInfo(); - codecInfoStr_.append(codecInfo->GetName()); - codecInfoStr_.append(SEPERATOR); + codecTypeArray.push_back(codecInfo->GetName()); } + + codecInfoStr_ = codecTypeArray.dump(); return codecInfoStr_; } diff --git a/services/screenclient/include/screen_client_window_adapter.h b/services/screenclient/include/screen_client_window_adapter.h index 80347e60..9b68277e 100644 --- a/services/screenclient/include/screen_client_window_adapter.h +++ b/services/screenclient/include/screen_client_window_adapter.h @@ -47,7 +47,7 @@ private: std::mutex windowIdMapMutex_; }; -class ScreenClientInputEventListener : public RefBase, public MMI::IInputEventConsumer { +class ScreenClientInputEventListener : public MMI::IInputEventConsumer { public: ScreenClientInputEventListener() = default; void OnInputEvent(std::shared_ptr pointerEvent) const override; diff --git a/services/screenservice/sourceservice/BUILD.gn b/services/screenservice/sourceservice/BUILD.gn index 0fc5f388..708d3991 100644 --- a/services/screenservice/sourceservice/BUILD.gn +++ b/services/screenservice/sourceservice/BUILD.gn @@ -13,71 +13,74 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni") +import( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") ohos_shared_library("distributed_screen_source") { - include_dirs = [ - "//third_party/json/include", - "${windowmanager_path}/interfaces/innerkits/dm", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "//foundation/graphic/standard/interfaces/innerkits/surface", - "${fwk_common_path}/utils/include", - ] + include_dirs = [ + "//third_party/json/include", + "${windowmanager_path}/interfaces/innerkits/dm", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "//foundation/graphic/standard/interfaces/innerkits/surface", + "${fwk_common_path}/utils/include", + "${mediastandard_path}/interfaces/innerkits/native/media/include", + ] - include_dirs += [ - "./dscreenservice/include", - "./dscreenservice/include/callback", - "./dscreenmgr/include", - "${interfaces_path}/innerkits/native_cpp/screen_sink/include", - "${interfaces_path}/innerkits/native_cpp/screen_sink/include/callback", - "${interfaces_path}/innerkits/native_cpp/screen_source/include", - "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", - "${common_path}/include", - "${services_path}/common/utils/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/screentransport/screensourcetrans/include", - ] + include_dirs += [ + "./dscreenservice/include", + "./dscreenservice/include/callback", + "./dscreenmgr/include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include/callback", + "${interfaces_path}/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${common_path}/include", + "${services_path}/common/utils/include", + "${services_path}/common/databuffer/include", + "${services_path}/common/screen_channel/include", + "${services_path}/screentransport/screensourceprocessor/include", + "${services_path}/screentransport/screensourceprocessor/encoder/include", + "${services_path}/screentransport/screensourcetrans/include", + ] - sources = [ - "${services_path}/common/utils/src/dscreen_maprelation.cpp", - "${services_path}/common/utils/src/video_param.cpp", - "${interfaces_path}/innerkits/native_cpp/screen_sink/src/dscreen_sink_proxy.cpp", - "${interfaces_path}/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp", - "./dscreenservice/src/callback/dscreen_source_callback_proxy.cpp", - "./dscreenservice/src/dscreen_source_service.cpp", - "./dscreenservice/src/dscreen_source_stub.cpp", - "./dscreenmgr/src/dscreen.cpp", - "./dscreenmgr/src/dscreen_manager.cpp", - "./dscreenmgr/src/screen_manager_adapter.cpp", - ] + sources = [ + "${interfaces_path}/innerkits/native_cpp/screen_sink/src/dscreen_sink_proxy.cpp", + "${interfaces_path}/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp", + "${services_path}/common/utils/src/dscreen_maprelation.cpp", + "${services_path}/common/utils/src/video_param.cpp", + "./dscreenmgr/src/dscreen.cpp", + "./dscreenmgr/src/dscreen_manager.cpp", + "./dscreenmgr/src/screen_manager_adapter.cpp", + "./dscreenservice/src/callback/dscreen_source_callback_proxy.cpp", + "./dscreenservice/src/dscreen_source_service.cpp", + "./dscreenservice/src/dscreen_source_stub.cpp", + ] - deps = [ - "//utils/native/base:utils", - "${common_path}:distributed_screen_utils", - "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", - "//foundation/graphic/standard/frameworks/surface:surface", - "${windowmanager_path}/dm:libdm", - ] + deps = [ + "${common_path}:distributed_screen_utils", + "${mediastandard_path}/interfaces/innerkits/native/media:media_client", + "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans", + "${windowmanager_path}/dm:libdm", + "//foundation/graphic/standard/frameworks/surface:surface", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//utils/native/base:utils", + ] - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"dscreensource\"", - "LOG_DOMAIN=0xD004100", - ] + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"dscreensource\"", + "LOG_DOMAIN=0xD004100", + ] - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] - subsystem_name = "distributedhardware" + subsystem_name = "distributedhardware" - part_name = "distributed_screen" + part_name = "distributed_screen" } \ No newline at end of file diff --git a/services/screenservice/sourceservice/dscreenmgr/include/dscreen.h b/services/screenservice/sourceservice/dscreenmgr/include/dscreen.h index 961ef1e3..f00fdf05 100644 --- a/services/screenservice/sourceservice/dscreenmgr/include/dscreen.h +++ b/services/screenservice/sourceservice/dscreenmgr/include/dscreen.h @@ -97,6 +97,7 @@ private: void HandleDisable(const std::string &taskId); void HandleConnect(); void HandleDisconnect(); + int32_t NegotiateCodecType(const std::string &remoteCodecInfoStr); int32_t SetUp(); int32_t Start(); int32_t Stop(); diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp index 2986ad13..d6e73fdb 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp @@ -15,6 +15,9 @@ #include "dscreen.h" +#include "avcodec_info.h" +#include "avcodec_list.h" + #include "dscreen_constants.h" #include "dscreen_errcode.h" #include "dscreen_log.h" @@ -209,20 +212,69 @@ void DScreen::HandleEnable(const std::string ¶m, const std::string &taskId) videoParam_->SetScreenWidth(attrJson[KEY_SCREEN_WIDTH]); videoParam_->SetScreenHeight(attrJson[KEY_SCREEN_HEIGHT]); - videoParam_->SetVideoFormat(VIDEO_DATA_FORMAT_NV21); - videoParam_->SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264); + + // negotiate codecType + int32_t ret = NegotiateCodecType(attrJson[KEY_CODECTYPE]); + if (ret != DH_SUCCESS) { + DHLOGE("negotiate codec type failed."); + dscreenCallback_->OnRegResult(shared_from_this(), taskId, ERR_DH_SCREEN_SA_ENABLE_FAILED, + "negotiate codec type failed."); + return; + } uint64_t screenId = ScreenMgrAdapter::GetInstance().CreateVirtualScreen(devId_, dhId_, videoParam_); if (screenId == SCREEN_ID_INVALID) { DHLOGE("create virtual screen failed."); dscreenCallback_->OnRegResult(shared_from_this(), taskId, ERR_DH_SCREEN_SA_ENABLE_FAILED, "create virtual screen failed."); + return; } screenId_ = screenId; SetState(ENABLED); dscreenCallback_->OnRegResult(shared_from_this(), taskId, DH_SUCCESS, ""); } +int32_t DScreen::NegotiateCodecType(const std::string &remoteCodecInfoStr) +{ + json remoteCodecArray = json::parse(remoteCodecInfoStr, nullptr, false); + if (remoteCodecArray.is_discarded() || !remoteCodecArray.is_array()) { + DHLOGE("remoteCodecInfoStrjson is invalid."); + return ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL; + } + + std::vector localCodecArray; + // query local support encoder type + 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::vector codecTypeCandidates; + for (const auto &remoteCodecType : remoteCodecArray) { + if (std::find(localCodecArray.begin(), localCodecArray.end(), + remoteCodecType) != localCodecArray.end()) { + codecTypeCandidates.push_back(remoteCodecType); + } + } + + if (std::find(codecTypeCandidates.begin(), codecTypeCandidates.end(), + CODEC_NAME_H264) != codecTypeCandidates.end()) { + videoParam_->SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264); + videoParam_->SetVideoFormat(VIDEO_DATA_FORMAT_NV21); + } 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 { + DHLOGI("codec type not support."); + return ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL; + } + + return DH_SUCCESS; +} + void DScreen::HandleDisable(const std::string &taskId) { DHLOGI("HandleDisable, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); diff --git a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp index 93a52ab5..a210198f 100644 --- a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp +++ b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp @@ -119,6 +119,9 @@ int32_t ImageSinkDecoder::InitVideoDecoder(const VideoParam &configParam) 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"); + break; default: DHLOGE("%s: codecType is invalid!", LOG_TAG); videoDecoder_ = nullptr; @@ -154,6 +157,9 @@ int32_t ImageSinkDecoder::SetDecoderFormat(const VideoParam &configParam) 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"); + break; default: DHLOGE("The current codec type does not support decoding."); return ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION; @@ -168,6 +174,9 @@ int32_t ImageSinkDecoder::SetDecoderFormat(const VideoParam &configParam) 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; diff --git a/services/screentransport/screensinktrans/include/screen_sink_trans.h b/services/screentransport/screensinktrans/include/screen_sink_trans.h index abd9e75a..665c3dc0 100644 --- a/services/screentransport/screensinktrans/include/screen_sink_trans.h +++ b/services/screentransport/screensinktrans/include/screen_sink_trans.h @@ -50,8 +50,8 @@ private: int32_t CheckVideoParam(const VideoParam ¶m); int32_t CheckTransParam(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId); int32_t InitScreenTrans(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId); - int32_t RegisterChannelListner(); - int32_t RegisterProcessorListner(const VideoParam &localParam, const VideoParam &remoteParam, + int32_t RegisterChannelListener(); + int32_t RegisterProcessorListener(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId); private: diff --git a/services/screentransport/screensinktrans/src/screen_sink_trans.cpp b/services/screentransport/screensinktrans/src/screen_sink_trans.cpp index 83b10eee..6de90dc2 100644 --- a/services/screentransport/screensinktrans/src/screen_sink_trans.cpp +++ b/services/screentransport/screensinktrans/src/screen_sink_trans.cpp @@ -140,14 +140,16 @@ int32_t ScreenSinkTrans::SetImageSurface(const sptr &surface) int32_t ScreenSinkTrans::CheckVideoParam(const VideoParam ¶m) { if ((param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H264) && - (param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H265)) { + (param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H265) && + (param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_MPEG4)) { DHLOGE("%s: Invalid codec type.", LOG_TAG); return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM; } if ((param.GetVideoFormat() != VIDEO_DATA_FORMAT_YUVI420) && (param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV12) && - (param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV21)) { + (param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV21) && + (param.GetVideoFormat() != VIDEO_DATA_FORMAT_RGBA8888)) { DHLOGE("%s: Invalid video data format.", LOG_TAG); return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM; } @@ -204,7 +206,7 @@ int32_t ScreenSinkTrans::InitScreenTrans(const VideoParam &localParam, const Vid DHLOGE("%s: Create screen data channel failed.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } - int32_t ret = RegisterChannelListner(); + int32_t ret = RegisterChannelListener(); if (ret != DH_SUCCESS) { DHLOGE("%s: Register channel listener failed.", LOG_TAG); screenChannel_ = nullptr; @@ -217,7 +219,7 @@ int32_t ScreenSinkTrans::InitScreenTrans(const VideoParam &localParam, const Vid screenChannel_ = nullptr; return ERR_DH_SCREEN_TRANS_NULL_VALUE; } - ret = RegisterProcessorListner(localParam, remoteParam, peerDevId); + ret = RegisterProcessorListener(localParam, remoteParam, peerDevId); if (ret != DH_SUCCESS) { DHLOGE("%s: Register processor listener failed.", LOG_TAG); screenChannel_ = nullptr; @@ -228,9 +230,9 @@ int32_t ScreenSinkTrans::InitScreenTrans(const VideoParam &localParam, const Vid return DH_SUCCESS; } -int32_t ScreenSinkTrans::RegisterChannelListner() +int32_t ScreenSinkTrans::RegisterChannelListener() { - DHLOGI("%s: RegisterChannelListner.", LOG_TAG); + DHLOGI("%s: RegisterChannelListener.", LOG_TAG); std::shared_ptr listener = shared_from_this(); if (!listener) { DHLOGE("%s: Channel Listener is null.", LOG_TAG); @@ -246,10 +248,10 @@ int32_t ScreenSinkTrans::RegisterChannelListner() return DH_SUCCESS; } -int32_t ScreenSinkTrans::RegisterProcessorListner(const VideoParam &localParam, const VideoParam &remoteParam, +int32_t ScreenSinkTrans::RegisterProcessorListener(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId) { - DHLOGI("%s: RegisterProcessorListner.", LOG_TAG); + DHLOGI("%s: RegisterProcessorListener.", LOG_TAG); std::shared_ptr listener = shared_from_this(); if (!listener) { DHLOGE("%s: Channel listener to null.", LOG_TAG); diff --git a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp index 229344ff..6c03ad56 100644 --- a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp +++ b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp @@ -122,6 +122,9 @@ int32_t ImageSourceEncoder::InitVideoEncoder(const VideoParam &configParam) 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"); + break; default: DHLOGE("%s: codecType is invalid!", LOG_TAG); videoEncoder_ = nullptr; @@ -157,6 +160,9 @@ int32_t ImageSourceEncoder::SetEncoderFormat(const VideoParam &configParam) 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"); + break; default: DHLOGE("%s: Codec type is invalid.", LOG_TAG); return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM; @@ -171,6 +177,9 @@ int32_t ImageSourceEncoder::SetEncoderFormat(const VideoParam &configParam) 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; diff --git a/services/screentransport/screensourcetrans/include/screen_source_trans.h b/services/screentransport/screensourcetrans/include/screen_source_trans.h index b513c739..667212b3 100644 --- a/services/screentransport/screensourcetrans/include/screen_source_trans.h +++ b/services/screentransport/screensourcetrans/include/screen_source_trans.h @@ -55,8 +55,8 @@ private: int32_t CheckVideoParam(const VideoParam ¶m); int32_t CheckTransParam(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId); int32_t InitScreenTrans(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId); - int32_t RegisterChannelListner(); - int32_t RegisterProcessorListner(const VideoParam &localParam, const VideoParam &remoteParam); + int32_t RegisterChannelListener(); + int32_t RegisterProcessorListener(const VideoParam &localParam, const VideoParam &remoteParam); void FeedChannelData(); private: diff --git a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp index 13faed9b..6d2ef574 100644 --- a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp +++ b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp @@ -152,14 +152,16 @@ sptr &ScreenSourceTrans::GetImageSurface() int32_t ScreenSourceTrans::CheckVideoParam(const VideoParam ¶m) { if ((param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H264) && - (param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H265)) { + (param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_H265) && + (param.GetCodecType() != VIDEO_CODEC_TYPE_VIDEO_MPEG4)) { DHLOGE("%s: Invalid codec type.", LOG_TAG); return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM; } if ((param.GetVideoFormat() != VIDEO_DATA_FORMAT_YUVI420) && (param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV12) && - (param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV21)) { + (param.GetVideoFormat() != VIDEO_DATA_FORMAT_NV21) && + (param.GetVideoFormat() != VIDEO_DATA_FORMAT_RGBA8888)) { DHLOGE("%s: Invalid video data format.", LOG_TAG); return ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM; } @@ -216,7 +218,7 @@ int32_t ScreenSourceTrans::InitScreenTrans(const VideoParam &localParam, const V DHLOGE("%s: Create screen data channel failed.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } - int32_t ret = RegisterChannelListner(); + int32_t ret = RegisterChannelListener(); if (ret != DH_SUCCESS) { DHLOGE("%s: Register channel listener failed ret: %d.", LOG_TAG, ret); screenChannel_ = nullptr; @@ -229,7 +231,7 @@ int32_t ScreenSourceTrans::InitScreenTrans(const VideoParam &localParam, const V screenChannel_ = nullptr; return ERR_DH_SCREEN_TRANS_NULL_VALUE; } - ret = RegisterProcessorListner(localParam, remoteParam); + ret = RegisterProcessorListener(localParam, remoteParam); if (ret != DH_SUCCESS) { DHLOGE("%s: Register data processor listener failed ret: %d.", LOG_TAG, ret); screenChannel_ = nullptr; @@ -240,9 +242,9 @@ int32_t ScreenSourceTrans::InitScreenTrans(const VideoParam &localParam, const V return DH_SUCCESS; } -int32_t ScreenSourceTrans::RegisterChannelListner() +int32_t ScreenSourceTrans::RegisterChannelListener() { - DHLOGI("%s: RegisterChannelListner.", LOG_TAG); + DHLOGI("%s: RegisterChannelListener.", LOG_TAG); std::shared_ptr listener = shared_from_this(); if (!listener) { DHLOGE("%s: Channel listener is null", LOG_TAG); @@ -262,9 +264,9 @@ int32_t ScreenSourceTrans::RegisterChannelListner() return DH_SUCCESS; } -int32_t ScreenSourceTrans::RegisterProcessorListner(const VideoParam &localParam, const VideoParam &remoteParam) +int32_t ScreenSourceTrans::RegisterProcessorListener(const VideoParam &localParam, const VideoParam &remoteParam) { - DHLOGI("%s: RegisterProcessorListner.", LOG_TAG); + DHLOGI("%s: RegisterProcessorListener.", LOG_TAG); std::shared_ptr listener = shared_from_this(); if (!listener) { DHLOGE("%s: Processor listener is null", LOG_TAG); 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 3d88b9bf..ff655147 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 @@ -66,14 +66,14 @@ HWTEST_F(ScreenSinkTransTest, setup_test_001, TestSize.Level1) } /** - * @tc.name: register_processor_listner_001 - * @tc.desc: Verify the RegisterChannelListner function success. + * @tc.name: register_processor_listener_001 + * @tc.desc: Verify the RegisterChannelListener function success. * @tc.type: FUNC * @tc.require: Issue Number */ -HWTEST_F(ScreenSinkTransTest, register_processor_listner_001, TestSize.Level1) +HWTEST_F(ScreenSinkTransTest, register_processor_listener_001, TestSize.Level1) { - EXPECT_EQ(DH_SUCCESS, trans_->RegisterProcessorListner(param_, param_, peerDevId_)); + EXPECT_EQ(DH_SUCCESS, trans_->RegisterProcessorListener(param_, param_, peerDevId_)); } /** @@ -230,7 +230,7 @@ HWTEST_F(ScreenSinkTransTest, on_data_received_test_001, TestSize.Level1) /** * @tc.name: on_processor_state_notify_test_001 - * @tc.desc: Verify the RegisterChannelListner function. + * @tc.desc: Verify the RegisterChannelListener function. * @tc.type: FUNC * @tc.require: Issue Number */ @@ -243,7 +243,7 @@ HWTEST_F(ScreenSinkTransTest, on_processor_state_notify_test_001, TestSize.Level /** * @tc.name: on_processor_state_notify_test_002 - * @tc.desc: Verify the RegisterChannelListner function. + * @tc.desc: Verify the RegisterChannelListener function. * @tc.type: FUNC * @tc.require: Issue Number */ -- Gitee