diff --git a/common/include/dscreen_constants.h b/common/include/dscreen_constants.h index d071b381b1b8901d051860e76c7b9fa1dbd74073..962c21d2f81ec0316f37a92ce6179ba3104b9d79 100644 --- a/common/include/dscreen_constants.h +++ b/common/include/dscreen_constants.h @@ -72,7 +72,7 @@ const std::string JPEG_SESSION_NAME = "ohos.dhardware.dscreen.jpeg"; constexpr int32_t YR_PARAM = 66; constexpr int32_t YG_PARAM = 129; constexpr int32_t YB_PARAM = 25; -constexpr int32_t UR_PARAM = -38; +constexpr int32_t UR_PARAM = 38; constexpr int32_t UG_PARAM = 74; constexpr int32_t UB_PARAM = 112; constexpr int32_t VG_PARAM = 94; diff --git a/common/include/dscreen_errcode.h b/common/include/dscreen_errcode.h index 53a1ae0f290da21c18079edfcd0bde563f7c920f..438a54da10f00aacbd81d9e204b301c6907e605e 100644 --- a/common/include/dscreen_errcode.h +++ b/common/include/dscreen_errcode.h @@ -92,6 +92,7 @@ enum DScreenErrorCode { ERR_DH_SCREEN_CODEC_SET_CALLBACK_FAILED = -53005, ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED = -53006, ERR_DH_SCREEN_CODEC_SURFACE_ERROR = -53007, + ERR_DH_SCREEN_CODEC_PARTAIL_DATA_ERROR = -53008, // ScreenClient error code ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR = -54000, ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR = -54001, diff --git a/services/common/decision_center/src/screen_decision_center.cpp b/services/common/decision_center/src/screen_decision_center.cpp index fb9de49131e00d538f2785623ce0b80d3a26e83a..72b5341f475eca2d5f06c6cc1f6540a4e38a5464 100644 --- a/services/common/decision_center/src/screen_decision_center.cpp +++ b/services/common/decision_center/src/screen_decision_center.cpp @@ -28,8 +28,8 @@ bool ScreenDecisionCenter::IsDirtyRectValid(const std::vector &damag DHLOGE("%s: damages size is empty.", LOG_TAG); return false; } - int32_t screenWidth = configParam_.GetScreenWidth(); - int32_t screenHeight = configParam_.GetScreenHeight(); + int32_t screenWidth = static_cast(configParam_.GetScreenWidth()); + int32_t screenHeight = static_cast(configParam_.GetScreenHeight()); for (const auto &damage : damages) { if (damage.x < 0 || damage.x > screenWidth || damage.y < 0 || damage.y > screenHeight || damage.x % TWO == 1 || damage.w % TWO == 1) { diff --git a/services/common/imageJpeg/include/jpeg_image_processor.h b/services/common/imageJpeg/include/jpeg_image_processor.h index f814fd8d9dd596e5e92b45528bb43ece1ac6a38c..00f218759cd9549795498d3c2a90633d3ff173b7 100644 --- a/services/common/imageJpeg/include/jpeg_image_processor.h +++ b/services/common/imageJpeg/include/jpeg_image_processor.h @@ -41,7 +41,8 @@ public: int32_t DecodeDamageData(const std::shared_ptr &data, uint8_t *lastFrame); int32_t ReplaceDamage2LastFrame(uint8_t *lastFrame, uint8_t *dirtyImageData, const DirtyRect rect); private: - uint32_t CompressRgbaToJpeg(const OHOS::Rect &damage, uint8_t *inputData, std::shared_ptr &data); + uint32_t CompressRgbaToJpeg(const OHOS::Rect &damage, uint8_t *inputData, + uint32_t inputDataSize, std::shared_ptr &data); void DecompressJpegToNV12(size_t jpegSize, uint8_t *inputData, uint8_t *outputData); static const constexpr char *LOG_TAG = "JpegImageProcessor"; diff --git a/services/common/imageJpeg/src/jpeg_image_processor.cpp b/services/common/imageJpeg/src/jpeg_image_processor.cpp index 40a6d0f894609cd1e19641d86b239362a0c20a2b..04cd939904853660a16c1db2239f75be4130ce0d 100644 --- a/services/common/imageJpeg/src/jpeg_image_processor.cpp +++ b/services/common/imageJpeg/src/jpeg_image_processor.cpp @@ -49,7 +49,7 @@ int32_t JpegImageProcessor::FillDirtyImages2Surface(const std::shared_ptrCancelBuffer(windowSurfaceBuffer); return surfaceErr; } - int32_t surfaceBuffeSize = windowSurfaceBuffer->GetSize(); + uint32_t surfaceBuffeSize = windowSurfaceBuffer->GetSize(); auto windowSurfaceAddr = static_cast(windowSurfaceBuffer->GetVirAddr()); ret = memcpy_s(windowSurfaceAddr, surfaceBuffeSize, lastFrame, lastFrameSize); if (ret != DH_SUCCESS) { @@ -121,7 +121,7 @@ void JpegImageProcessor::EncodeDamageData(sptr &surfaceBuffer, const OHOS::Rect &damage, std::shared_ptr &data) { DHLOGI("%s: EncodeDamageData.", LOG_TAG); - int32_t partialSize = damage.w * damage.h *RGBA_CHROMA; + uint32_t partialSize = damage.w * damage.h * RGBA_CHROMA; unsigned char *partialBuffer = new unsigned char[partialSize]; unsigned char *partialBufferIdx = partialBuffer; auto surfaceAddrIdx = static_cast(surfaceBuffer->GetVirAddr()); @@ -137,7 +137,7 @@ void JpegImageProcessor::EncodeDamageData(sptr &surfaceBuffer, partialBufferIdx += damage.w * RGBA_CHROMA; surfaceAddrIdx += configParam_.GetScreenWidth() * RGBA_CHROMA; } - uint32_t jpegSize = CompressRgbaToJpeg(damage, partialBuffer, data); + uint32_t jpegSize = CompressRgbaToJpeg(damage, partialBuffer, partialSize, data); DHLOGI("CompressRgbaToJpeg end, jpegSize %." PRId32, jpegSize); delete [] partialBuffer; } @@ -147,8 +147,8 @@ int32_t JpegImageProcessor::DecodeDamageData(const std::shared_ptr & DHLOGI("%s: DecodeDamageData.", LOG_TAG); std::vector dirtyRectVec = data->GetDirtyRectVec(); int32_t offset = 0; - int32_t screenWidth = configParam_.GetScreenWidth(); - int32_t screenHeight = configParam_.GetScreenHeight(); + int32_t screenWidth = static_cast(configParam_.GetScreenWidth()); + int32_t screenHeight = static_cast(configParam_.GetScreenHeight()); for (auto item : dirtyRectVec) { if (item.xPos > screenWidth || item.yPos > screenHeight || item.width > screenWidth - item.xPos || item.height > screenHeight - item.yPos) { @@ -184,29 +184,29 @@ int32_t JpegImageProcessor::ReplaceDamage2LastFrame(uint8_t *lastFrame, uint8_t { DHLOGI("%s: ReplaceDamage2LastFrame.", LOG_TAG); uint8_t *lastFrameIdx = lastFrame; - uint8_t *yData = lastFrameIdx + configParam_.GetScreenWidth() * rect.yPos + rect.xPos; + uint8_t *yData = lastFrameIdx + static_cast(configParam_.GetScreenWidth() * rect.yPos + rect.xPos); uint8_t *uData = lastFrameIdx + configParam_.GetScreenWidth() * configParam_.GetScreenHeight() + - configParam_.GetScreenWidth() * (rect.yPos / TWO) + rect.xPos; + static_cast(configParam_.GetScreenWidth() * (rect.yPos / TWO) + rect.xPos); uint8_t *yDirtyData = dirtyImageData; uint8_t *uDirtyData = dirtyImageData + rect.width * rect.height; uint8_t *yTempData = nullptr; uint8_t *uTempData = nullptr; for (int32_t i = 0 ; i < rect.height ; i++) { - yTempData = yData + i * configParam_.GetScreenWidth(); + yTempData = yData + static_cast(i * configParam_.GetScreenWidth()); int32_t ret = memcpy_s(yTempData, rect.width, yDirtyData, rect.width); if (ret != EOK) { DHLOGE("%s: memcpy yData failed.", LOG_TAG); return ret; } - yDirtyData += rect.width; + yDirtyData += static_cast(rect.width); if (i % TWO) { - uTempData = uData + configParam_.GetScreenWidth() * (i / TWO); + uTempData = uData + static_cast(configParam_.GetScreenWidth() * (i / TWO)); ret = memcpy_s(uTempData, rect.width, uDirtyData, rect.width); if (ret != EOK) { DHLOGE("%s: memcpy uData failed.", LOG_TAG); return ret; } - uDirtyData += rect.width; + uDirtyData += static_cast(rect.width); } } DHLOGI("%s: ReplaceDamage2LastFrame success.", LOG_TAG); @@ -214,9 +214,12 @@ int32_t JpegImageProcessor::ReplaceDamage2LastFrame(uint8_t *lastFrame, uint8_t } uint32_t JpegImageProcessor::CompressRgbaToJpeg(const OHOS::Rect &damage, - uint8_t *inputData, std::shared_ptr &data) + uint8_t *inputData, uint32_t inputDataSize, std::shared_ptr &data) { DHLOGI("%s: CompressRgbaToJpeg.", LOG_TAG); + if (inputDataSize != damage.w * damage.h * RGBA_CHROMA) { + return ERR_DH_SCREEN_CODEC_PARTAIL_DATA_ERROR; + } jpeg_compress_struct cinfo; jpeg_error_mgr jerr; JSAMPROW row_pointer[1]; @@ -270,9 +273,9 @@ void JpegImageProcessor::DecompressJpegToNV12(size_t jpegSize, uint8_t *inputDat jpeg_mem_src(&cinfo, inputData, jpegSize); (void)jpeg_read_header(&cinfo, TRUE); (void)jpeg_start_decompress(&cinfo); - int32_t row_stride = cinfo.output_width * cinfo.output_components; + int32_t row_stride = static_cast(cinfo.output_width * cinfo.output_components); JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr)&cinfo, JPOOL_IMAGE, row_stride, 1); - int32_t uvIndex = cinfo.output_width * cinfo.output_height; + uint32_t uvIndex = cinfo.output_width * cinfo.output_height; int32_t i = 0; #ifdef LIBYUV uint8_t *rgb = new uint8_t[cinfo.output_width * cinfo.output_height * RGBA_CHROMA]; @@ -291,8 +294,8 @@ void JpegImageProcessor::DecompressJpegToNV12(size_t jpegSize, uint8_t *inputDat #else int32_t y = ((YR_PARAM * buffer[0][j * RGB_CHROMA] + YG_PARAM * buffer[0][j * RGB_CHROMA + 1] + YB_PARAM * buffer[0][j * RGB_CHROMA + TWO] + UA_PARAM) >> MOVEBITS) + YA_PARAM; - int32_t u = ((UR_PARAM * buffer[0][j * RGB_CHROMA] - UG_PARAM * buffer[0][j * RGB_CHROMA + 1] + - UB_PARAM * buffer[0][j * RGB_CHROMA + TWO] + UA_PARAM) >> MOVEBITS) + UA_PARAM; + int32_t u = ((UB_PARAM * buffer[0][j * RGB_CHROMA + TWO] - UR_PARAM * buffer[0][j * RGB_CHROMA] - + UG_PARAM * buffer[0][j * RGB_CHROMA + 1] + UA_PARAM) >> MOVEBITS) + UA_PARAM; int32_t v = ((UB_PARAM * buffer[0][j * RGB_CHROMA] - VG_PARAM * buffer[0][j * RGB_CHROMA + 1] - VB_PARAM * buffer[0][j * RGB_CHROMA + TWO] + UA_PARAM) >> MOVEBITS) + UA_PARAM; outputData[yIndex++] = static_cast((y < 0) ? 0 : (y > YUV_PARAM) ? YUV_PARAM : y); diff --git a/services/screendemo/decoder_demo.cpp b/services/screendemo/decoder_demo.cpp index 23c597f336a32677551b6430fdc5c89b30f9a620..c90351a2a105f6f0bf56f2495af3ad0724231a8f 100644 --- a/services/screendemo/decoder_demo.cpp +++ b/services/screendemo/decoder_demo.cpp @@ -310,11 +310,6 @@ void VDecDemo::OutputFunc() } } -VDecDemoCallback::VDecDemoCallback(shared_ptr signal) - : signal_(signal) -{ -} - void VDecDemoCallback::OnError(AVCodecErrorType errorType, int32_t errorCode) { cout << "Error received, errorType:" << errorType << " errorCode:" << errorCode << endl; diff --git a/services/screendemo/decoder_demo.h b/services/screendemo/decoder_demo.h index 01f83f5ca537ea4dc6146fb3044ddd6b200fdd2a..b55963c52291d1a976cae8fae69b74dd211c8bd0 100644 --- a/services/screendemo/decoder_demo.h +++ b/services/screendemo/decoder_demo.h @@ -39,7 +39,7 @@ public: class VDecDemoCallback : public AVCodecCallback, public NoCopyable { public: - explicit VDecDemoCallback(std::shared_ptr signal); + explicit VDecDemoCallback(std::shared_ptr signal) : signal_(signal) {}; virtual ~VDecDemoCallback() = default; void OnError(AVCodecErrorType errorType, int32_t errorCode) override; diff --git a/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp b/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp index 15802569fa2793a1ce22b332b4457fb9416ed545..bfc0368dd61025d779efe7a5594336bb83176ba0 100644 --- a/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp @@ -131,13 +131,8 @@ void ScreenRegionManager::HandleNotifySetUp(const std::string &remoteDevId, cons { DHLOGI("HandleNotifySetUp, remoteDevId: %s", GetAnonyString(remoteDevId).c_str()); json eventContentJson = json::parse(eventContent, nullptr, false); - if (eventContentJson.is_discarded()) { - NotifyRemoteSourceSetUpResult(remoteDevId, "", ERR_DH_SCREEN_SA_SCREENREGION_SETUP_FAIL, ""); - return; - } - - if (!CheckContentJson(eventContentJson) || !eventContentJson.contains(KEY_VIDEO_PARAM) || - !eventContentJson.contains(KEY_MAPRELATION)) { + if (eventContentJson.is_discarded()||!CheckContentJson(eventContentJson) || + !eventContentJson.contains(KEY_VIDEO_PARAM) || !eventContentJson.contains(KEY_MAPRELATION)) { NotifyRemoteSourceSetUpResult(remoteDevId, "", ERR_DH_SCREEN_SA_SCREENREGION_SETUP_FAIL, ""); return; } @@ -175,14 +170,12 @@ void ScreenRegionManager::HandleNotifySetUp(const std::string &remoteDevId, cons screenRegion->SetScreenVersion(version_); ret = screenRegion->SetUp(); if (ret != DH_SUCCESS) { - DHLOGE("screen region setup failed"); NotifyRemoteSourceSetUpResult(remoteDevId, dhId, ERR_DH_SCREEN_SA_SCREENREGION_SETUP_FAIL, ""); return; } ret = screenRegion->Start(); if (ret != DH_SUCCESS) { - DHLOGE("screen region start failed"); NotifyRemoteSourceSetUpResult(remoteDevId, dhId, ERR_DH_SCREEN_SA_SCREENREGION_START_FAIL, ""); return; } diff --git a/services/screentransport/screensinkprocessor/decoder/include/image_sink_decoder.h b/services/screentransport/screensinkprocessor/decoder/include/image_sink_decoder.h index 2d9b181ff316b577dcee64cd1d75460b4edab51e..196aa16b225abdd9f8e1cad45d351ccf6da6624a 100644 --- a/services/screentransport/screensinkprocessor/decoder/include/image_sink_decoder.h +++ b/services/screentransport/screensinkprocessor/decoder/include/image_sink_decoder.h @@ -92,7 +92,7 @@ private: Media::AVCodecBufferInfo decoderBufferInfo_; bool isDecoderReady_ = false; - int32_t alignedHeight_ = 0; + uint32_t alignedHeight_ = 0; sptr consumerSurface_; sptr producerSurface_; sptr windowSurface_; diff --git a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp index 4a8691266755104b3044c26ad13eb91d784dfbec..13503ed9ed1694632c863a345e3c1cc8b5c9a456 100644 --- a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp +++ b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp @@ -81,7 +81,8 @@ int32_t ImageSinkDecoder::AddSurface() consumerBufferListener_ = new ConsumBufferListener(shared_from_this()); } consumerSurface_->RegisterConsumerListener(consumerBufferListener_); - lastFrameSize_ = configParam_.GetVideoWidth() * configParam_.GetVideoHeight() * RGB_CHROMA / TWO; + lastFrameSize_ = static_cast(configParam_.GetVideoWidth() * + configParam_.GetVideoHeight() * RGB_CHROMA / TWO); lastFrame_ = new uint8_t[lastFrameSize_]; return DH_SUCCESS; } @@ -117,7 +118,7 @@ void ImageSinkDecoder::NormalProcess(sptr surfaceBuffer, sptr(surfaceBuffer->GetVirAddr()); auto windowSurfaceAddr = static_cast(windowSurfaceBuffer->GetVirAddr()); int32_t sizeData = lastFrameSize_; - int32_t size = windowSurfaceBuffer->GetSize(); + uint32_t size = windowSurfaceBuffer->GetSize(); int32_t ret = memcpy_s(windowSurfaceAddr, size, surfaceAddr, sizeData); if (ret != EOK) { DHLOGE("%s: surfaceBuffer memcpy run failed.", LOG_TAG); @@ -130,11 +131,11 @@ void ImageSinkDecoder::OffsetProcess(sptr surfaceBuffer, sptr(surfaceBuffer->GetVirAddr()); auto windowSurfaceAddr = static_cast(windowSurfaceBuffer->GetVirAddr()); - int32_t size = windowSurfaceBuffer->GetSize(); - int32_t srcDataOffset = 0; - int32_t dstDataOffset = 0; - int32_t alignedWidth = surfaceBuffer->GetStride(); - int32_t chromaOffset = configParam_.GetVideoWidth() * configParam_.GetVideoHeight(); + uint32_t size = windowSurfaceBuffer->GetSize(); + uint32_t srcDataOffset = 0; + uint32_t dstDataOffset = 0; + uint32_t alignedWidth = surfaceBuffer->GetStride(); + uint32_t chromaOffset = configParam_.GetVideoWidth() * configParam_.GetVideoHeight(); for (unsigned int yh = 0 ; yh < configParam_.GetVideoHeight() ; yh++) { int32_t ret = memcpy_s(windowSurfaceAddr + dstDataOffset, chromaOffset - dstDataOffset, surfaceAddr + srcDataOffset, configParam_.GetVideoWidth()); diff --git a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp index ffb8ff6f4c3b0e6d484d9467a9bdd59906530946..e743964da7f88ce12bf58251a34424823aea74ef 100644 --- a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp +++ b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp @@ -31,9 +31,9 @@ #include "dscreen_log.h" #include "jpeglib.h" #ifdef __LP64__ -const std::string LIB_LOAD_PATH = "/system/lib64/libdistributed_screen_dbg_itf.z.so"; +static const std::string LIB_LOAD_PATH = "/system/lib64/libdistributed_screen_dbg_itf.z.so"; #else -const std::string LIB_LOAD_PATH = "/system/lib/libdistributed_screen_dbg_itf.z.so"; +static const std::string LIB_LOAD_PATH = "/system/lib/libdistributed_screen_dbg_itf.z.so"; #endif using GetDscreenDBGItfFunc = OHOS::DistributedHardware::IDScreenDBGItf* (*)(); using GetImageDirtyFunc = OHOS::DistributedHardware::IImageSetDirty* (*)(); @@ -194,8 +194,8 @@ sptr ImageSourceEncoder::GetEncoderInputSurfaceBuffer() { DHLOGI("%s: GetEncoderInputSurfaceBuffer.", LOG_TAG); OHOS::BufferRequestConfig requestConfig; - requestConfig.width = configParam_.GetVideoWidth(); - requestConfig.height = configParam_.GetVideoHeight(); + requestConfig.width = static_cast(configParam_.GetVideoWidth()); + requestConfig.height = static_cast(configParam_.GetVideoHeight()); requestConfig.usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA; requestConfig.strideAlignment = STRIDE_ALIGNMENT; requestConfig.format = PixelFormat::PIXEL_FMT_RGBA_8888; @@ -217,7 +217,7 @@ int32_t ImageSourceEncoder::FeedEncoderData(sptr &surfaceBuffer) DHLOGE("Get encoder input producer surface buffer failed."); return ERR_DH_SCREEN_CODEC_SURFACE_ERROR; } - int32_t screenDataSize = configParam_.GetVideoWidth() * configParam_.GetVideoHeight() * RGBA_CHROMA; + uint32_t screenDataSize = configParam_.GetVideoWidth() * configParam_.GetVideoHeight() * RGBA_CHROMA; auto encoderSurfaceAddr = static_cast(encoderSurfaceBuffer->GetVirAddr()); auto surfaceAddr = static_cast(surfaceBuffer->GetVirAddr()); int32_t ret = memcpy_s(encoderSurfaceAddr, screenDataSize, surfaceAddr, screenDataSize);