From 11e4944c2e4ff0e6585b9cd8d5867f0924adeee0 Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Mon, 30 May 2022 11:31:11 +0800 Subject: [PATCH 1/8] add screen demo Signed-off-by: qinlong0101 --- bundle.json | 3 +- services/screendemo/BUILD.gn | 69 ++++ services/screendemo/common.h | 57 +++ services/screendemo/decoder_demo.cpp | 328 +++++++++++++++++ services/screendemo/decoder_demo.h | 93 +++++ services/screendemo/test.cpp | 340 ++++++++++++++++++ .../dscreenmgr/src/dscreen_manager.cpp | 10 +- 7 files changed, 897 insertions(+), 3 deletions(-) create mode 100644 services/screendemo/BUILD.gn create mode 100644 services/screendemo/common.h create mode 100644 services/screendemo/decoder_demo.cpp create mode 100644 services/screendemo/decoder_demo.h create mode 100644 services/screendemo/test.cpp diff --git a/bundle.json b/bundle.json index e5afdc47..11151efc 100644 --- a/bundle.json +++ b/bundle.json @@ -56,7 +56,8 @@ "//foundation/distributedhardware/distributedscreen/services/screenservice/sinkservice:distributed_screen_sink", "//foundation/distributedhardware/distributedscreen/services/screenservice/sourceservice:distributed_screen_source", "//foundation/distributedhardware/distributedscreen/sa_profile:dscreen_sa_profile", - "//foundation/distributedhardware/distributedscreen/sa_profile:dscreen.cfg" + "//foundation/distributedhardware/distributedscreen/sa_profile:dscreen.cfg", + "//foundation/distributedhardware/distributedscreen/services/screendemo:distributedScreenTest" ], "inner_kits":[ { diff --git a/services/screendemo/BUILD.gn b/services/screendemo/BUILD.gn new file mode 100644 index 00000000..a464d4f2 --- /dev/null +++ b/services/screendemo/BUILD.gn @@ -0,0 +1,69 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni") + +ohos_executable("distributedScreenTest") { + install_enable = false + include_dirs = [ + "${services_path}/common/utils/include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${fwk_common_path}/utils/include", + "${windowmanager_path}/interfaces/innerkits/dm", + "${services_path}/screenclient/include", + "${windowmanager_path}/interfaces/innerkits/wm", + "${common_path}/include", + ] + + include_dirs += [ + "foundation/multimedia/media_standard/interfaces/inner_api/native", + ] + + sources = [ + "./test.cpp", + "./decoder_demo.cpp", + ] + + deps = [ + "${services_path}/screenclient:distributed_screen_client", + "${common_path}:distributed_screen_utils", + "${interfaces_path}/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk", + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + "${windowmanager_path}/dm:libdm", + "${windowmanager_path}/wm:libwm", + "//foundation/communication/dsoftbus/adapter:softbus_adapter", + "//foundation/communication/dsoftbus/sdk:softbus_client", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"distributedScreenTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "multimedia_media_standard:media_client", + ] + + cflags = ["-Wall"] + cflags_cc = cflags + + part_name = "distributed_screen" + subsystem_name = "distributedhardware" +} diff --git a/services/screendemo/common.h b/services/screendemo/common.h new file mode 100644 index 00000000..4ba467b6 --- /dev/null +++ b/services/screendemo/common.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DISTRIBUTED_SCREEN_TEST_SA_H +#define DISTRIBUTED_SCREEN_TEST_SA_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "idistributed_hardware_source.h" + +namespace OHOS { +namespace DistributedHardware { +class DScreenMockRegisterCallback : public RegisterCallback { +public: + virtual ~DScreenMockRegisterCallback() = default; + int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, const std::string &data) + { + std::cout << "Register devId: " << devId << " dhId: " << dhId << ", status: " << status << std::endl; + return 0; + } +}; + +class DScreenMockUnRegisterCallback : public UnregisterCallback { +public: + virtual ~DScreenMockUnRegisterCallback() = default; + int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, const std::string &data) + { + std::cout << "Unregister devId: " << devId << " dhId: " << dhId << ", status: " << status << std::endl; + return 0; + } +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // DISTRIBUTED_SCREEN_TEST_SA_H \ No newline at end of file diff --git a/services/screendemo/decoder_demo.cpp b/services/screendemo/decoder_demo.cpp new file mode 100644 index 00000000..f320b1bf --- /dev/null +++ b/services/screendemo/decoder_demo.cpp @@ -0,0 +1,328 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "decoder_demo.h" + +#include +#include + +#include "avcodec_list.h" +#include "securec.h" +#include "ui/rs_surface_node.h" +#include "wm_common.h" +#include "window.h" +#include "window_option.h" + +static const int32_t ES_R[325] = + { 11895, 8109, 1578, 1616, 1313, 572, 805, 837, 755, 706, 952, 879, 13193, 422, 389, 509, 725, 465, 479, 959, + 677, 364, 541, 696, 9306, 322, 318, 767, 590, 422, 530, 403, 505, 566, 445, 508, 7783, 460, 405, 343, 451, + 608, 431, 411, 543, 487, 527, 400, 6287, 385, 418, 391, 592, 434, 412, 398, 504, 492, 479, 561, 5413, 317, + 355, 422, 467, 452, 476, 460, 490, 492, 485, 451, 5036, 312, 408, 460, 432, 502, 388, 475, 407, 544, 401, + 487, 4404, 362, 378, 427, 416, 426, 456, 414, 438, 424, 442, 444, 4310, 362, 388, 393, 390, 441, 398, 423, + 369, 443, 406, 392, 4231, 343, 363, 355, 390, 459, 371, 378, 381, 405, 392, 426, 3975, 387, 337, 393, 439, + 378, 355, 374, 484, 381, 373, 423, 3869, 312, 350, 400, 345, 356, 320, 473, 431, 386, 338, 431, 3426, 268, + 315, 416, 383, 373, 381, 354, 383, 328, 348, 418, 3715, 324, 361, 331, 350, 302, 409, 377, 359, 384, 334, + 326, 3439, 266, 324, 329, 353, 405, 303, 357, 332, 292, 361, 333, 3542, 294, 284, 247, 331, 306, 322, 287, + 367, 341, 276, 258, 3980, 246, 245, 259, 309, 333, 250, 275, 334, 281, 253, 371, 3640, 213, 231, 301, 302, + 228, 289, 290, 281, 201, 284, 277, 4242, 205, 328, 237, 283, 295, 266, 230, 321, 348, 212, 308, 4103, 259, + 238, 245, 298, 330, 265, 271, 287, 267, 286, 290, 3856, 269, 242, 209, 314, 267, 278, 280, 314, 250, 433, + 238, 3654, 195, 246, 301, 298, 250, 270, 320, 269, 305, 258, 368, 3810, 231, 212, 279, 289, 252, 303, 287, + 295, 206, 264, 349, 4071, 242, 296, 271, 231, 307, 265, 254, 267, 317, 232, 348, 4077, 259, 222, 268, 235, + 324, 266, 256, 312, 246, 248, 325, 4000, 266, 201, 230, 293, 264, 265, 273, 301, 304, 253, 266, 3978, 228, + 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719 }; + +static const int32_t ES_W[183] = + { 2111, 109091, 9316, 969, 13656, 1349, 959, 10484, 1219, 14839, 1092, 23378, 1653, 1725, 1526, 8500, 15407, + 2058, 1346, 21066, 3758, 1734, 1950, 19955, 3997, 1732, 1784, 22687, 4392, 2448, 2180, 17456, 3930, 1851, + 1802, 24227, 4393, 2639, 2778, 18314, 4023, 2392, 2283, 20566, 4118, 2664, 2013, 18964, 2624, 45258, 5860, + 4124, 3473, 27772, 4687, 3140, 2939, 26288, 3808, 2967, 2823, 27219, 3943, 3242, 2667, 27372, 3522, 2899, + 2316, 26608, 3284, 2853, 2285, 19581, 2894, 2436, 24898, 4002, 2876, 2807, 25730, 3903, 2874, 2975, 26309, + 3771, 2763, 2666, 23404, 3826, 2410, 2644, 24629, 4145, 3121, 2878, 50773, 7040, 3945, 3292, 30828, 5210, + 2883, 3277, 31501, 4809, 3068, 3220, 30746, 4715, 3461, 3583, 32278, 4798, 3398, 3389, 31404, 4921, 3382, + 3766, 31821, 5848, 3860, 4047, 37642, 5793, 4271, 4094, 29853, 6163, 4399, 4063, 32151, 6038, 4332, 4041, + 30390, 5679, 4098, 3921, 29401, 5307, 3996, 3945, 45997, 7060, 3716, 4183, 26357, 6190, 3714, 4250, 29086, + 5929, 3491, 4489, 27772, 6656, 4219, 4348, 25851, 6088, 3617, 4477, 25722, 6303, 3856, 4208, 25348, 5896, + 3816, 4521, 22462, 5914, 3673, 4594, 18091, 6474, 3878, 4492, 10890, 4823, 4148 }; + +using namespace OHOS; +using namespace OHOS::Media; +using namespace std; +namespace { + constexpr uint32_t DEFAULT_WIDTH = 480; + constexpr uint32_t DEFAULT_HEIGHT = 360; + constexpr uint32_t DEFAULT_FRAME_RATE = 30; + constexpr uint32_t MAX_INPUT_BUFFER_SIZE = 30000; + constexpr uint32_t FRAME_DURATION_US = 33000; + constexpr uint32_t DEFAULT_FRAME_COUNT = 1; + const string CODEC_NAME_H264 = "OMX_hisi_video_encoder_avc"; + const string CODEC_NAME_MPEG4 = "avenc_mpeg4"; + constexpr uint32_t VIDEO_DATA_FORMAT_NV12 = 2; + constexpr uint32_t VIDEO_DATA_FORMAT_RGBA = 5; +} + +void VDecDemo::RunCase() +{ + CheckCodecType(); + CreateVdec(); + Format format; + format.PutIntValue("width", DEFAULT_WIDTH); + format.PutIntValue("height", DEFAULT_HEIGHT); + if (isW) { + format.PutIntValue("pixel_format", VIDEO_DATA_FORMAT_NV12); + } else { + format.PutIntValue("pixel_format", VIDEO_DATA_FORMAT_RGBA); + } + format.PutIntValue("frame_rate", DEFAULT_FRAME_RATE); + format.PutIntValue("max_input_size", MAX_INPUT_BUFFER_SIZE); + Configure(format); + SetSurface(); + Prepare(); + Start(); + sleep(3); + Stop(); + Release(); +} + +int32_t VDecDemo::CreateVdec() +{ + if (isW) { + vdec_ = VideoDecoderFactory::CreateByMime("video/avc"); + } else { + vdec_ = VideoDecoderFactory::CreateByMime("video/mp4v-es"); + } + + signal_ = make_shared(); + cb_ = make_unique(signal_); + vdec_->SetCallback(cb_); + return 0; +} + +int32_t VDecDemo::Configure(const Format &format) +{ + return vdec_->Configure(format); +} + +int32_t VDecDemo::Prepare() +{ + return vdec_->Prepare(); +} + +int32_t VDecDemo::Start() +{ + isRunning_.store(true); + + testFile_ = std::make_unique(); + testFile_->open("/data/media/video.es", std::ios::in | std::ios::binary); + + inputLoop_ = make_unique(&VDecDemo::InputFunc, this); + outputLoop_ = make_unique(&VDecDemo::OutputFunc, this); + return vdec_->Start(); +} + +int32_t VDecDemo::Stop() +{ + isRunning_.store(false); + + if (inputLoop_ != nullptr && inputLoop_->joinable()) { + unique_lock lock(signal_->inMutex_); + signal_->inQueue_.push(10000); + signal_->inCond_.notify_all(); + lock.unlock(); + inputLoop_->join(); + inputLoop_.reset(); + } + + if (outputLoop_ != nullptr && outputLoop_->joinable()) { + unique_lock lock(signal_->outMutex_); + signal_->outQueue_.push(10000); + signal_->outCond_.notify_all(); + lock.unlock(); + outputLoop_->join(); + outputLoop_.reset(); + } + + return vdec_->Stop(); +} + +int32_t VDecDemo::Flush() +{ + return vdec_->Flush(); +} + +int32_t VDecDemo::Reset() +{ + return vdec_->Reset(); +} + +int32_t VDecDemo::Release() +{ + return vdec_->Release(); +} + +void VDecDemo::SetOutputSurface(sptr surface) +{ + surface_ = surface; +} + +void VDecDemo::SetWindowSize(uint32_t width, uint32_t height) +{ + width_ = width; + height_ = height; +} + +int32_t VDecDemo::SetSurface() +{ + return vdec_->SetOutputSurface(surface_); +} + +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()); + } + + if (std::find(localCodecArray.begin(), localCodecArray.end(), + CODEC_NAME_H264) != localCodecArray.end()) { + cout << "device is W" << endl; + isW = true; + } else if (std::find(localCodecArray.begin(), localCodecArray.end(), + CODEC_NAME_MPEG4) != localCodecArray.end()) { + cout << "device is R" << endl; + isW = false; + } +} + +void VDecDemo::InputFunc() +{ + const int32_t *frameLen = nullptr; + if (isW) { + frameLen = ES_W; + } else { + frameLen = ES_R; + } + + while (true) { + if (!isRunning_.load()) { + break; + } + + unique_lock lock(signal_->inMutex_); + signal_->inCond_.wait(lock, [this](){ return signal_->inQueue_.size() > 0; }); + + if (!isRunning_.load()) { + break; + } + + uint32_t index = signal_->inQueue_.front(); + auto buffer = vdec_->GetInputBuffer(index); + + char *fileBuffer = (char *)malloc(sizeof(char) * (*frameLen) + 1); + + (void)testFile_->read(fileBuffer, *frameLen); + if (memcpy_s(buffer->GetBase(), buffer->GetSize(), fileBuffer, *frameLen) != EOK) { + free(fileBuffer); + cout << "Fatal: memcpy fail" << endl; + break; + } + + AVCodecBufferInfo info; + info.size = *frameLen; + info.offset = 0; + info.presentationTimeUs = timeStamp_; + + int32_t ret = 0; + if (isFirstFrame_) { + ret = vdec_->QueueInputBuffer(index, info, AVCODEC_BUFFER_FLAG_CODEC_DATA); + isFirstFrame_ = false; + } else { + ret = vdec_->QueueInputBuffer(index, info, AVCODEC_BUFFER_FLAG_NONE); + } + + free(fileBuffer); + frameLen++; + timeStamp_ += FRAME_DURATION_US; + signal_->inQueue_.pop(); + + frameCount_++; + if (frameCount_ == DEFAULT_FRAME_COUNT) { + cout << "Finish decode, exit" << endl; + break; + } + + if (ret != 0) { + cout << "Fatal error, exit" << endl; + break; + } + } +} + +void VDecDemo::OutputFunc() +{ + while (true) { + if (!isRunning_.load()) { + break; + } + + unique_lock lock(signal_->outMutex_); + signal_->outCond_.wait(lock, [this](){ return signal_->outQueue_.size() > 0; }); + + if (!isRunning_.load()) { + break; + } + + uint32_t index = signal_->outQueue_.front(); + if (vdec_->ReleaseOutputBuffer(index, true) != 0) { + cout << "Fatal: ReleaseOutputBuffer fail" << endl; + break; + } + + signal_->outQueue_.pop(); + } +} + +VDecDemoCallback::VDecDemoCallback(shared_ptr signal) + : signal_(signal) +{ +} + +void VDecDemoCallback::OnError(AVCodecErrorType errorType, int32_t errorCode) +{ + cout << "Error received, errorType:" << errorType << " errorCode:" << errorCode << endl; +} + +void VDecDemoCallback::OnOutputFormatChanged(const Format &format) +{ + cout << "OnOutputFormatChanged received" << endl; +} + +void VDecDemoCallback::OnInputBufferAvailable(uint32_t index) +{ + cout << "OnInputBufferAvailable received, index:" << index << endl; + unique_lock lock(signal_->inMutex_); + signal_->inQueue_.push(index); + signal_->inCond_.notify_all(); +} + +void VDecDemoCallback::OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) +{ + cout << "OnOutputBufferAvailable received, index:" << index << endl; + unique_lock lock(signal_->outMutex_); + signal_->outQueue_.push(index); + signal_->outCond_.notify_all(); +} diff --git a/services/screendemo/decoder_demo.h b/services/screendemo/decoder_demo.h new file mode 100644 index 00000000..7d7334a6 --- /dev/null +++ b/services/screendemo/decoder_demo.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AVCODEC_VDEC_DEMO_H +#define AVCODEC_VDEC_DEMO_H + +#include +#include +#include +#include +#include + +#include "avcodec_video_decoder.h" +#include "nocopyable.h" + +namespace OHOS { +namespace Media { +class VDecSignal { +public: + std::mutex inMutex_; + std::mutex outMutex_; + std::condition_variable inCond_; + std::condition_variable outCond_; + std::queue inQueue_; + std::queue outQueue_; +}; + +class VDecDemoCallback : public AVCodecCallback, public NoCopyable { +public: + explicit VDecDemoCallback(std::shared_ptr signal); + 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; + +private: + std::shared_ptr signal_; +}; + +class VDecDemo : public NoCopyable { +public: + VDecDemo() = default; + virtual ~VDecDemo() = default; + void RunCase(); + void SetOutputSurface(sptr surface); + void SetWindowSize(uint32_t width, uint32_t height); + +private: + int32_t CreateVdec(); + int32_t Configure(const Format &format); + int32_t Prepare(); + int32_t Start(); + int32_t Stop(); + int32_t Flush(); + int32_t Reset(); + int32_t Release(); + int32_t SetSurface(); + void InputFunc(); + void OutputFunc(); + void CheckCodecType(); + + std::atomic isRunning_ = false; + sptr surface_ = nullptr; + uint32_t width_ = 0; + uint32_t height_ = 0; + std::unique_ptr testFile_; + std::unique_ptr inputLoop_; + std::unique_ptr outputLoop_; + std::shared_ptr vdec_; + std::shared_ptr signal_; + std::shared_ptr cb_; + bool isFirstFrame_ = true; + bool isW = true; + int64_t timeStamp_ = 0; + uint32_t frameCount_ = 0; +}; +} // namespace Media +} // namespace OHOS +#endif // AVCODEC_VDEC_DEMO_H \ No newline at end of file diff --git a/services/screendemo/test.cpp b/services/screendemo/test.cpp new file mode 100644 index 00000000..ed32f37e --- /dev/null +++ b/services/screendemo/test.cpp @@ -0,0 +1,340 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "display.h" +#include "display_manager.h" +#include "dscreen_source_handler.h" +#include "dscreen_sink_handler.h" +#include "idistributed_hardware_sink.h" +#include "idistributed_hardware_source.h" +#include "screen.h" +#include "screen_client.h" +#include "screen_client_common.h" +#include "screen_manager.h" +#include "wm_common.h" +#include "window.h" +#include "window_option.h" + +#include "common.h" +#include "decoder_demo.h" +#include "softbus_adapter_mem.h" +#include "softbus_bus_center.h" +#include "softbus_common.h" + +using namespace std; +using namespace OHOS; +using namespace OHOS::DistributedHardware; +using namespace OHOS::Rosen; +using namespace OHOS::Media; + +namespace { + static char const *g_pkgName = "ohos.dsoftbus.tool"; +} + +vector> QueryRemoteScreenInfo() +{ + vector> allScreens = ScreenManager::GetInstance().GetAllScreens(); + sptr defaultDisplay = DisplayManager::GetInstance().GetDefaultDisplay(); + vector> remoteScreens; + for (const auto &screen : allScreens) { + if (screen == nullptr) { + continue; + } + if (!screen->IsReal() && screen->GetWidth() > 0) { + remoteScreens.push_back(screen); + } + } + cout << "-------------remote screen info---------------" << endl; + cout << "remote screen Num: " << remoteScreens.size() << endl; + for (const auto &screen : remoteScreens) { + if (screen == nullptr) { + continue; + } + cout << endl; + cout << "--------screen id " << screen->GetId() << "---------" << endl; + cout << "screen name: " << screen->GetName() << endl; + cout << "width: " << screen->GetWidth() << endl; + cout << "height: " << screen->GetHeight() << endl; + cout << "-------------------------------------------" << endl; + } + return remoteScreens; +} + +static void StartMirror() +{ + vector> remoteScreens = QueryRemoteScreenInfo(); + if (remoteScreens.size() == 0) { + cout << "Error: no remote screens enabled" << endl; + return; + } + + cout << "select remote screen id to mirror: " << endl; + uint64_t mirrorId; + cin >> mirrorId; + + bool isMirrorIdValid = false; + for (const auto &screen : remoteScreens) { + if (screen == nullptr) { + continue; + } + if (screen->GetId() == mirrorId) { + isMirrorIdValid = true; + break; + } + } + + if (!isMirrorIdValid) { + cout << "input mirrorId is not valid!" << endl; + return; + } + + sptr defaultDisplay = DisplayManager::GetInstance().GetDefaultDisplay(); + cout << "------------start mirror----------" < mirrorIds; + mirrorIds.push_back(mirrorId); + ScreenManager::GetInstance().MakeMirror(defaultDisplay->GetScreenId(), mirrorIds); +} + +static void StopMirror() +{ + vector> remoteScreens = QueryRemoteScreenInfo(); + if (remoteScreens.size() == 0) { + cout << "no remote screens enabled, no need stop mirror" << endl; + return; + } + + bool isStopMirrorIdValid = false; + cout << "select remote screen id to stop mirror: " << endl; + uint64_t stopMirrorId; + cin >> stopMirrorId; + + for (const auto &screen : remoteScreens) { + if (screen == nullptr) { + continue; + } + if (screen->GetId() == stopMirrorId) { + isStopMirrorIdValid = true; + break; + } + } + if (!isStopMirrorIdValid) { + cout << "input screenId is not valid!" << endl; + return; + } + + cout << "-------------- stop mirror ------------" << endl; + cout << "stop mirror screen id is " << stopMirrorId << endl; + vector stopMirrorIds; + stopMirrorIds.push_back(stopMirrorId); + ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(stopMirrorIds); +} + +static void StartExpand() +{ + vector> remoteScreens = QueryRemoteScreenInfo(); + if (remoteScreens.size() == 0) { + cout << "Error: no remote screens enabled" << endl; + return; + } + + cout << "select remote screen id to expand: " << endl; + uint64_t expandId; + cin >> expandId; + + bool isExpandIdValid = false; + for (const auto &screen : remoteScreens) { + if (screen == nullptr) { + continue; + } + if (screen->GetId() == expandId) { + isExpandIdValid = true; + break; + } + } + + if (!isExpandIdValid) { + cout << "input expandId is not valid!" << endl; + return; + } + + sptr defaultDisplay = DisplayManager::GetInstance().GetDefaultDisplay(); + cout << endl << "------------start expand----------" << endl; + cout << "expand screen Id is " << expandId << endl; + vector options = {{defaultDisplay->GetScreenId(), 0, 0}, {expandId, defaultDisplay->GetWidth(), 0}}; + ScreenManager::GetInstance().MakeExpand(options); +} + +static void StopExpand() +{ + vector> remoteScreens = QueryRemoteScreenInfo(); + if (remoteScreens.size() == 0) { + cout << "no remote screens enabled, no need stop expand" << endl; + return; + } + + bool isStopExpandIdValid = false; + cout << "select remote screen id to stop expand: " << endl; + uint64_t stopExpandId; + cin >> stopExpandId; + + for (const auto &screen : remoteScreens) { + if (screen == nullptr) { + continue; + } + if (screen->GetId() == stopExpandId) { + isStopExpandIdValid = true; + break; + } + } + if (!isStopExpandIdValid) { + cout << "input screenId is not valid!" << endl; + return; + } + + cout << "-------------- stop expand ------------" << endl; + cout << "stop expand screen id is " << stopExpandId << endl; + vector stopExpandIds; + stopExpandIds.push_back(stopExpandId); + ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(stopExpandIds); +} + +static void PrintNodeProperty(NodeBasicInfo *nodeInfo) +{ + if (nodeInfo == nullptr) { + cout << "nodeInfo is nullptr" << endl; + return; + } + + printf("DeviceName = %s\n", nodeInfo->deviceName); + printf("NetworkId = %s\n", nodeInfo->networkId); + NodeDeviceInfoKey key; + key = NODE_KEY_UDID; + unsigned char udid[UDID_BUF_LEN] = {0}; + if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key, udid, UDID_BUF_LEN) != 0) { + printf("GetNodeKeyInfo Fail!\n"); + } else { + printf("Udid = %s\n", udid); + } + key = NODE_KEY_UUID; + unsigned char uuid[UUID_BUF_LEN] = {0}; + if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key, uuid, UUID_BUF_LEN) != 0) { + printf("GetNodeKeyInfo Fail!\n"); + } else { + printf("Uuid = %s\n", uuid); + } +} + +static void QueryRemoteDeviceInfo() +{ + NodeBasicInfo localNodeinfo; + NodeBasicInfo *remoteNodeInfo = nullptr; + int32_t infoNum = 0; + printf("-----------Local Device Info------\n"); + if (GetLocalNodeDeviceInfo(g_pkgName, &localNodeinfo) != 0) { + printf("LnnGetLocalNodeInfo Fail!\n"); + return; + } + PrintNodeProperty(&localNodeinfo); + printf("-------Remote Device info---------\n"); + if (GetAllNodeDeviceInfo(g_pkgName, &remoteNodeInfo, &infoNum) != 0) { + printf("GetAllNodeDeviceInfo Fail!\n"); + return; + } + printf("Device Num = %d\n", infoNum); + for (int i = 0; i < infoNum; ++i) { + printf("\n[No.%d]", i + 1); + PrintNodeProperty(remoteNodeInfo + i); + } + FreeNodeInfo(remoteNodeInfo); + printf("SoftBusDumpDeviceInfo complete!\n"); +} + +static void CreateWindow() +{ + cout << "create window, please input window size" << endl; + cout << "width: "; + uint32_t windowWidth; + cin >> windowWidth; + cout << "height: "; + uint32_t windowHeight; + cin >> windowHeight; + + if (windowWidth <= 0 || windowHeight <= 0) { + cout << "Invalid window size." << endl; + return; + } + + sptr defaultDisplay = DisplayManager::GetInstance().GetDefaultDisplay(); + shared_ptr windowProperty = make_shared(); + windowProperty->displayId = defaultDisplay->GetId(); + windowProperty->startX = 0; + windowProperty->startY = 0; + windowProperty->width = windowWidth; + windowProperty->height = windowHeight; + int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty); + ScreenClient::GetInstance().ShowWindow(windowId); + sptr surface = ScreenClient::GetInstance().GetSurface(windowId); + cout << "create window success." << endl; + + auto vdec = make_shared(); + if (vdec == nullptr) { + cout << "videoDecoder is nullptr" << endl; + return; + } + vdec->SetWindowSize(windowWidth, windowHeight); + vdec->SetOutputSurface(surface); + cout << "start run decoder" << endl; + vdec->RunCase(); + cout << "create window success, window id: " << windowId + << ", width: " << windowWidth + << ", height: " << windowHeight << endl; + ScreenClient::GetInstance().RemoveWindow(windowId); +} + +int main() +{ + cout << "Please select a test scenario number(default StartMirror): " << endl; + cout << "0:StartMirror" << endl; + cout << "1:StopMirror" << endl; + cout << "2:StartExpand" << endl; + cout << "3:StopExpand" << endl; + cout << "4:CreateWindow" << endl; + cout << "5:QueryRemoteDeviceInfo" << endl; + cout << "6:QueryRemoteScreenInfo" << endl; + string mode; + (void)getline(cin, mode); + if (mode == "" || mode == "0") { + (void)StartMirror(); + } else if (mode == "1") { + (void)StopMirror(); + } else if (mode == "2") { + (void)StartExpand(); + } else if (mode == "3") { + (void)StopExpand(); + } else if (mode == "4") { + (void)CreateWindow(); + } else if (mode == "5") { + (void)QueryRemoteDeviceInfo(); + } else if (mode == "6") { + (void)QueryRemoteScreenInfo(); + } else { + cout << "no that selection" << endl; + } + return 0; +} diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp index 4a1edc4e..3d747f35 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp @@ -81,9 +81,15 @@ int32_t DScreenManager::UnInit() if (ret != DH_SUCCESS) { DHLOGE("DScreenManager UnInit failed, err: %d", ret); } + dScreenCallback_ = nullptr; - dScreenSourceCallbackProxy_ = nullptr; - dScreenGroupListener_ = nullptr; + if (dScreenSourceCallbackProxy_ != nullptr) { + dScreenSourceCallbackProxy_ = nullptr; + } + + if (dScreenGroupListener_ != nullptr) { + dScreenGroupListener_ = nullptr; + } { std::lock_guard lock(dScreenMapMtx_); -- Gitee From 9437ecaccf0a0b6b497dc3e6d773780d8bd47022 Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Mon, 30 May 2022 13:19:53 +0800 Subject: [PATCH 2/8] add screen demo Signed-off-by: qinlong0101 --- services/screendemo/BUILD.gn | 90 ++++++++++++++-------------- services/screendemo/common.h | 11 ++-- services/screendemo/decoder_demo.cpp | 60 ++++++++++--------- services/screendemo/test.cpp | 3 - 4 files changed, 82 insertions(+), 82 deletions(-) diff --git a/services/screendemo/BUILD.gn b/services/screendemo/BUILD.gn index a464d4f2..98c9f412 100644 --- a/services/screendemo/BUILD.gn +++ b/services/screendemo/BUILD.gn @@ -12,58 +12,58 @@ # limitations under the License. import("//build/ohos.gni") -import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni") +import( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") ohos_executable("distributedScreenTest") { - install_enable = false - include_dirs = [ - "${services_path}/common/utils/include", - "${interfaces_path}/innerkits/native_cpp/screen_sink/include", - "${interfaces_path}/innerkits/native_cpp/screen_source/include", - "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", - "${fwk_common_path}/utils/include", - "${windowmanager_path}/interfaces/innerkits/dm", - "${services_path}/screenclient/include", - "${windowmanager_path}/interfaces/innerkits/wm", - "${common_path}/include", - ] + install_enable = false + include_dirs = [ + "${services_path}/common/utils/include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${fwk_common_path}/utils/include", + "${windowmanager_path}/interfaces/innerkits/dm", + "${services_path}/screenclient/include", + "${windowmanager_path}/interfaces/innerkits/wm", + "${common_path}/include", + ] - include_dirs += [ - "foundation/multimedia/media_standard/interfaces/inner_api/native", - ] + include_dirs += + [ "foundation/multimedia/media_standard/interfaces/inner_api/native" ] - sources = [ - "./test.cpp", - "./decoder_demo.cpp", - ] + sources = [ + "./decoder_demo.cpp", + "./test.cpp", + ] - deps = [ - "${services_path}/screenclient:distributed_screen_client", - "${common_path}:distributed_screen_utils", - "${interfaces_path}/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk", - "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", - "${windowmanager_path}/dm:libdm", - "${windowmanager_path}/wm:libwm", - "//foundation/communication/dsoftbus/adapter:softbus_adapter", - "//foundation/communication/dsoftbus/sdk:softbus_client", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", - ] + deps = [ + "${common_path}:distributed_screen_utils", + "${interfaces_path}/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk", + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + "${services_path}/screenclient:distributed_screen_client", + "${windowmanager_path}/dm:libdm", + "${windowmanager_path}/wm:libwm", + "//foundation/communication/dsoftbus/adapter:softbus_adapter", + "//foundation/communication/dsoftbus/sdk:softbus_client", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + ] - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"distributedScreenTest\"", - "LOG_DOMAIN=0xD004100", - ] + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"distributedScreenTest\"", + "LOG_DOMAIN=0xD004100", + ] - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "multimedia_media_standard:media_client", - ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "multimedia_media_standard:media_client", + ] - cflags = ["-Wall"] - cflags_cc = cflags + cflags = [ "-Wall" ] + cflags_cc = cflags - part_name = "distributed_screen" - subsystem_name = "distributedhardware" + part_name = "distributed_screen" + subsystem_name = "distributedhardware" } diff --git a/services/screendemo/common.h b/services/screendemo/common.h index 4ba467b6..797c75d9 100644 --- a/services/screendemo/common.h +++ b/services/screendemo/common.h @@ -17,11 +17,10 @@ #define DISTRIBUTED_SCREEN_TEST_SA_H #include +#include +#include #include #include -#include -#include -#include #include #include #include @@ -36,7 +35,8 @@ namespace DistributedHardware { class DScreenMockRegisterCallback : public RegisterCallback { public: virtual ~DScreenMockRegisterCallback() = default; - int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, const std::string &data) + int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, + const std::string &data) { std::cout << "Register devId: " << devId << " dhId: " << dhId << ", status: " << status << std::endl; return 0; @@ -46,7 +46,8 @@ public: class DScreenMockUnRegisterCallback : public UnregisterCallback { public: virtual ~DScreenMockUnRegisterCallback() = default; - int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, const std::string &data) + int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, + const std::string &data) { std::cout << "Unregister devId: " << devId << " dhId: " << dhId << ", status: " << status << std::endl; return 0; diff --git a/services/screendemo/decoder_demo.cpp b/services/screendemo/decoder_demo.cpp index f320b1bf..f294abf7 100644 --- a/services/screendemo/decoder_demo.cpp +++ b/services/screendemo/decoder_demo.cpp @@ -25,36 +25,38 @@ #include "window.h" #include "window_option.h" -static const int32_t ES_R[325] = - { 11895, 8109, 1578, 1616, 1313, 572, 805, 837, 755, 706, 952, 879, 13193, 422, 389, 509, 725, 465, 479, 959, - 677, 364, 541, 696, 9306, 322, 318, 767, 590, 422, 530, 403, 505, 566, 445, 508, 7783, 460, 405, 343, 451, - 608, 431, 411, 543, 487, 527, 400, 6287, 385, 418, 391, 592, 434, 412, 398, 504, 492, 479, 561, 5413, 317, - 355, 422, 467, 452, 476, 460, 490, 492, 485, 451, 5036, 312, 408, 460, 432, 502, 388, 475, 407, 544, 401, - 487, 4404, 362, 378, 427, 416, 426, 456, 414, 438, 424, 442, 444, 4310, 362, 388, 393, 390, 441, 398, 423, - 369, 443, 406, 392, 4231, 343, 363, 355, 390, 459, 371, 378, 381, 405, 392, 426, 3975, 387, 337, 393, 439, - 378, 355, 374, 484, 381, 373, 423, 3869, 312, 350, 400, 345, 356, 320, 473, 431, 386, 338, 431, 3426, 268, - 315, 416, 383, 373, 381, 354, 383, 328, 348, 418, 3715, 324, 361, 331, 350, 302, 409, 377, 359, 384, 334, - 326, 3439, 266, 324, 329, 353, 405, 303, 357, 332, 292, 361, 333, 3542, 294, 284, 247, 331, 306, 322, 287, - 367, 341, 276, 258, 3980, 246, 245, 259, 309, 333, 250, 275, 334, 281, 253, 371, 3640, 213, 231, 301, 302, - 228, 289, 290, 281, 201, 284, 277, 4242, 205, 328, 237, 283, 295, 266, 230, 321, 348, 212, 308, 4103, 259, - 238, 245, 298, 330, 265, 271, 287, 267, 286, 290, 3856, 269, 242, 209, 314, 267, 278, 280, 314, 250, 433, - 238, 3654, 195, 246, 301, 298, 250, 270, 320, 269, 305, 258, 368, 3810, 231, 212, 279, 289, 252, 303, 287, - 295, 206, 264, 349, 4071, 242, 296, 271, 231, 307, 265, 254, 267, 317, 232, 348, 4077, 259, 222, 268, 235, - 324, 266, 256, 312, 246, 248, 325, 4000, 266, 201, 230, 293, 264, 265, 273, 301, 304, 253, 266, 3978, 228, - 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719 }; +static const int32_t ES_R[325] = { + 11895, 8109, 1578, 1616, 1313, 572, 805, 837, 755, 706, 952, 879, 13193, 422, 389, 509, 725, 465, 479, 959, + 677, 364, 541, 696, 9306, 322, 318, 767, 590, 422, 530, 403, 505, 566, 445, 508, 7783, 460, 405, 343, 451, + 608, 431, 411, 543, 487, 527, 400, 6287, 385, 418, 391, 592, 434, 412, 398, 504, 492, 479, 561, 5413, 317, + 355, 422, 467, 452, 476, 460, 490, 492, 485, 451, 5036, 312, 408, 460, 432, 502, 388, 475, 407, 544, 401, + 487, 4404, 362, 378, 427, 416, 426, 456, 414, 438, 424, 442, 444, 4310, 362, 388, 393, 390, 441, 398, 423, + 369, 443, 406, 392, 4231, 343, 363, 355, 390, 459, 371, 378, 381, 405, 392, 426, 3975, 387, 337, 393, 439, + 378, 355, 374, 484, 381, 373, 423, 3869, 312, 350, 400, 345, 356, 320, 473, 431, 386, 338, 431, 3426, 268, + 315, 416, 383, 373, 381, 354, 383, 328, 348, 418, 3715, 324, 361, 331, 350, 302, 409, 377, 359, 384, 334, + 326, 3439, 266, 324, 329, 353, 405, 303, 357, 332, 292, 361, 333, 3542, 294, 284, 247, 331, 306, 322, 287, + 367, 341, 276, 258, 3980, 246, 245, 259, 309, 333, 250, 275, 334, 281, 253, 371, 3640, 213, 231, 301, 302, + 228, 289, 290, 281, 201, 284, 277, 4242, 205, 328, 237, 283, 295, 266, 230, 321, 348, 212, 308, 4103, 259, + 238, 245, 298, 330, 265, 271, 287, 267, 286, 290, 3856, 269, 242, 209, 314, 267, 278, 280, 314, 250, 433, + 238, 3654, 195, 246, 301, 298, 250, 270, 320, 269, 305, 258, 368, 3810, 231, 212, 279, 289, 252, 303, 287, + 295, 206, 264, 349, 4071, 242, 296, 271, 231, 307, 265, 254, 267, 317, 232, 348, 4077, 259, 222, 268, 235, + 324, 266, 256, 312, 246, 248, 325, 4000, 266, 201, 230, 293, 264, 265, 273, 301, 304, 253, 266, 3978, 228, + 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719 +}; -static const int32_t ES_W[183] = - { 2111, 109091, 9316, 969, 13656, 1349, 959, 10484, 1219, 14839, 1092, 23378, 1653, 1725, 1526, 8500, 15407, - 2058, 1346, 21066, 3758, 1734, 1950, 19955, 3997, 1732, 1784, 22687, 4392, 2448, 2180, 17456, 3930, 1851, - 1802, 24227, 4393, 2639, 2778, 18314, 4023, 2392, 2283, 20566, 4118, 2664, 2013, 18964, 2624, 45258, 5860, - 4124, 3473, 27772, 4687, 3140, 2939, 26288, 3808, 2967, 2823, 27219, 3943, 3242, 2667, 27372, 3522, 2899, - 2316, 26608, 3284, 2853, 2285, 19581, 2894, 2436, 24898, 4002, 2876, 2807, 25730, 3903, 2874, 2975, 26309, - 3771, 2763, 2666, 23404, 3826, 2410, 2644, 24629, 4145, 3121, 2878, 50773, 7040, 3945, 3292, 30828, 5210, - 2883, 3277, 31501, 4809, 3068, 3220, 30746, 4715, 3461, 3583, 32278, 4798, 3398, 3389, 31404, 4921, 3382, - 3766, 31821, 5848, 3860, 4047, 37642, 5793, 4271, 4094, 29853, 6163, 4399, 4063, 32151, 6038, 4332, 4041, - 30390, 5679, 4098, 3921, 29401, 5307, 3996, 3945, 45997, 7060, 3716, 4183, 26357, 6190, 3714, 4250, 29086, - 5929, 3491, 4489, 27772, 6656, 4219, 4348, 25851, 6088, 3617, 4477, 25722, 6303, 3856, 4208, 25348, 5896, - 3816, 4521, 22462, 5914, 3673, 4594, 18091, 6474, 3878, 4492, 10890, 4823, 4148 }; +static const int32_t ES_W[183] = { + 2111, 109091, 9316, 969, 13656, 1349, 959, 10484, 1219, 14839, 1092, 23378, 1653, 1725, 1526, 8500, 15407, + 2058, 1346, 21066, 3758, 1734, 1950, 19955, 3997, 1732, 1784, 22687, 4392, 2448, 2180, 17456, 3930, 1851, + 1802, 24227, 4393, 2639, 2778, 18314, 4023, 2392, 2283, 20566, 4118, 2664, 2013, 18964, 2624, 45258, 5860, + 4124, 3473, 27772, 4687, 3140, 2939, 26288, 3808, 2967, 2823, 27219, 3943, 3242, 2667, 27372, 3522, 2899, + 2316, 26608, 3284, 2853, 2285, 19581, 2894, 2436, 24898, 4002, 2876, 2807, 25730, 3903, 2874, 2975, 26309, + 3771, 2763, 2666, 23404, 3826, 2410, 2644, 24629, 4145, 3121, 2878, 50773, 7040, 3945, 3292, 30828, 5210, + 2883, 3277, 31501, 4809, 3068, 3220, 30746, 4715, 3461, 3583, 32278, 4798, 3398, 3389, 31404, 4921, 3382, + 3766, 31821, 5848, 3860, 4047, 37642, 5793, 4271, 4094, 29853, 6163, 4399, 4063, 32151, 6038, 4332, 4041, + 30390, 5679, 4098, 3921, 29401, 5307, 3996, 3945, 45997, 7060, 3716, 4183, 26357, 6190, 3714, 4250, 29086, + 5929, 3491, 4489, 27772, 6656, 4219, 4348, 25851, 6088, 3617, 4477, 25722, 6303, 3856, 4208, 25348, 5896, + 3816, 4521, 22462, 5914, 3673, 4594, 18091, 6474, 3878, 4492, 10890, 4823, 4148 +}; using namespace OHOS; using namespace OHOS::Media; diff --git a/services/screendemo/test.cpp b/services/screendemo/test.cpp index ed32f37e..2c644732 100644 --- a/services/screendemo/test.cpp +++ b/services/screendemo/test.cpp @@ -13,9 +13,6 @@ * limitations under the License. */ -#include -#include - #include "display.h" #include "display_manager.h" #include "dscreen_source_handler.h" -- Gitee From bfa03a5d1a85d8686a05b1c0830d6ff7d1f89781 Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Mon, 30 May 2022 13:26:49 +0800 Subject: [PATCH 3/8] add screen demo Signed-off-by: qinlong0101 --- services/screendemo/decoder_demo.cpp | 64 ++++++++++++++-------------- services/screendemo/test.cpp | 2 +- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/services/screendemo/decoder_demo.cpp b/services/screendemo/decoder_demo.cpp index f294abf7..7ea2be6d 100644 --- a/services/screendemo/decoder_demo.cpp +++ b/services/screendemo/decoder_demo.cpp @@ -25,38 +25,38 @@ #include "window.h" #include "window_option.h" -static const int32_t ES_R[325] = { - 11895, 8109, 1578, 1616, 1313, 572, 805, 837, 755, 706, 952, 879, 13193, 422, 389, 509, 725, 465, 479, 959, - 677, 364, 541, 696, 9306, 322, 318, 767, 590, 422, 530, 403, 505, 566, 445, 508, 7783, 460, 405, 343, 451, - 608, 431, 411, 543, 487, 527, 400, 6287, 385, 418, 391, 592, 434, 412, 398, 504, 492, 479, 561, 5413, 317, - 355, 422, 467, 452, 476, 460, 490, 492, 485, 451, 5036, 312, 408, 460, 432, 502, 388, 475, 407, 544, 401, - 487, 4404, 362, 378, 427, 416, 426, 456, 414, 438, 424, 442, 444, 4310, 362, 388, 393, 390, 441, 398, 423, - 369, 443, 406, 392, 4231, 343, 363, 355, 390, 459, 371, 378, 381, 405, 392, 426, 3975, 387, 337, 393, 439, - 378, 355, 374, 484, 381, 373, 423, 3869, 312, 350, 400, 345, 356, 320, 473, 431, 386, 338, 431, 3426, 268, - 315, 416, 383, 373, 381, 354, 383, 328, 348, 418, 3715, 324, 361, 331, 350, 302, 409, 377, 359, 384, 334, - 326, 3439, 266, 324, 329, 353, 405, 303, 357, 332, 292, 361, 333, 3542, 294, 284, 247, 331, 306, 322, 287, - 367, 341, 276, 258, 3980, 246, 245, 259, 309, 333, 250, 275, 334, 281, 253, 371, 3640, 213, 231, 301, 302, - 228, 289, 290, 281, 201, 284, 277, 4242, 205, 328, 237, 283, 295, 266, 230, 321, 348, 212, 308, 4103, 259, - 238, 245, 298, 330, 265, 271, 287, 267, 286, 290, 3856, 269, 242, 209, 314, 267, 278, 280, 314, 250, 433, - 238, 3654, 195, 246, 301, 298, 250, 270, 320, 269, 305, 258, 368, 3810, 231, 212, 279, 289, 252, 303, 287, - 295, 206, 264, 349, 4071, 242, 296, 271, 231, 307, 265, 254, 267, 317, 232, 348, 4077, 259, 222, 268, 235, - 324, 266, 256, 312, 246, 248, 325, 4000, 266, 201, 230, 293, 264, 265, 273, 301, 304, 253, 266, 3978, 228, - 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719 -}; - -static const int32_t ES_W[183] = { - 2111, 109091, 9316, 969, 13656, 1349, 959, 10484, 1219, 14839, 1092, 23378, 1653, 1725, 1526, 8500, 15407, - 2058, 1346, 21066, 3758, 1734, 1950, 19955, 3997, 1732, 1784, 22687, 4392, 2448, 2180, 17456, 3930, 1851, - 1802, 24227, 4393, 2639, 2778, 18314, 4023, 2392, 2283, 20566, 4118, 2664, 2013, 18964, 2624, 45258, 5860, - 4124, 3473, 27772, 4687, 3140, 2939, 26288, 3808, 2967, 2823, 27219, 3943, 3242, 2667, 27372, 3522, 2899, - 2316, 26608, 3284, 2853, 2285, 19581, 2894, 2436, 24898, 4002, 2876, 2807, 25730, 3903, 2874, 2975, 26309, - 3771, 2763, 2666, 23404, 3826, 2410, 2644, 24629, 4145, 3121, 2878, 50773, 7040, 3945, 3292, 30828, 5210, - 2883, 3277, 31501, 4809, 3068, 3220, 30746, 4715, 3461, 3583, 32278, 4798, 3398, 3389, 31404, 4921, 3382, - 3766, 31821, 5848, 3860, 4047, 37642, 5793, 4271, 4094, 29853, 6163, 4399, 4063, 32151, 6038, 4332, 4041, - 30390, 5679, 4098, 3921, 29401, 5307, 3996, 3945, 45997, 7060, 3716, 4183, 26357, 6190, 3714, 4250, 29086, - 5929, 3491, 4489, 27772, 6656, 4219, 4348, 25851, 6088, 3617, 4477, 25722, 6303, 3856, 4208, 25348, 5896, - 3816, 4521, 22462, 5914, 3673, 4594, 18091, 6474, 3878, 4492, 10890, 4823, 4148 -}; + static const int32_t ES_R[325] = { + 11895, 8109, 1578, 1616, 1313, 572, 805, 837, 755, 706, 952, 879, 13193, 422, 389, 509, 725, 465, 479, 959, + 677, 364, 541, 696, 9306, 322, 318, 767, 590, 422, 530, 403, 505, 566, 445, 508, 7783, 460, 405, 343, 451, + 608, 431, 411, 543, 487, 527, 400, 6287, 385, 418, 391, 592, 434, 412, 398, 504, 492, 479, 561, 5413, 317, + 355, 422, 467, 452, 476, 460, 490, 492, 485, 451, 5036, 312, 408, 460, 432, 502, 388, 475, 407, 544, 401, + 487, 4404, 362, 378, 427, 416, 426, 456, 414, 438, 424, 442, 444, 4310, 362, 388, 393, 390, 441, 398, 423, + 369, 443, 406, 392, 4231, 343, 363, 355, 390, 459, 371, 378, 381, 405, 392, 426, 3975, 387, 337, 393, 439, + 378, 355, 374, 484, 381, 373, 423, 3869, 312, 350, 400, 345, 356, 320, 473, 431, 386, 338, 431, 3426, 268, + 315, 416, 383, 373, 381, 354, 383, 328, 348, 418, 3715, 324, 361, 331, 350, 302, 409, 377, 359, 384, 334, + 326, 3439, 266, 324, 329, 353, 405, 303, 357, 332, 292, 361, 333, 3542, 294, 284, 247, 331, 306, 322, 287, + 367, 341, 276, 258, 3980, 246, 245, 259, 309, 333, 250, 275, 334, 281, 253, 371, 3640, 213, 231, 301, 302, + 228, 289, 290, 281, 201, 284, 277, 4242, 205, 328, 237, 283, 295, 266, 230, 321, 348, 212, 308, 4103, 259, + 238, 245, 298, 330, 265, 271, 287, 267, 286, 290, 3856, 269, 242, 209, 314, 267, 278, 280, 314, 250, 433, + 238, 3654, 195, 246, 301, 298, 250, 270, 320, 269, 305, 258, 368, 3810, 231, 212, 279, 289, 252, 303, 287, + 295, 206, 264, 349, 4071, 242, 296, 271, 231, 307, 265, 254, 267, 317, 232, 348, 4077, 259, 222, 268, 235, + 324, 266, 256, 312, 246, 248, 325, 4000, 266, 201, 230, 293, 264, 265, 273, 301, 304, 253, 266, 3978, 228, + 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719 + }; + + static const int32_t ES_W[183] = { + 2111, 109091, 9316, 969, 13656, 1349, 959, 10484, 1219, 14839, 1092, 23378, 1653, 1725, 1526, 8500, 15407, + 2058, 1346, 21066, 3758, 1734, 1950, 19955, 3997, 1732, 1784, 22687, 4392, 2448, 2180, 17456, 3930, 1851, + 1802, 24227, 4393, 2639, 2778, 18314, 4023, 2392, 2283, 20566, 4118, 2664, 2013, 18964, 2624, 45258, 5860, + 4124, 3473, 27772, 4687, 3140, 2939, 26288, 3808, 2967, 2823, 27219, 3943, 3242, 2667, 27372, 3522, 2899, + 2316, 26608, 3284, 2853, 2285, 19581, 2894, 2436, 24898, 4002, 2876, 2807, 25730, 3903, 2874, 2975, 26309, + 3771, 2763, 2666, 23404, 3826, 2410, 2644, 24629, 4145, 3121, 2878, 50773, 7040, 3945, 3292, 30828, 5210, + 2883, 3277, 31501, 4809, 3068, 3220, 30746, 4715, 3461, 3583, 32278, 4798, 3398, 3389, 31404, 4921, 3382, + 3766, 31821, 5848, 3860, 4047, 37642, 5793, 4271, 4094, 29853, 6163, 4399, 4063, 32151, 6038, 4332, 4041, + 30390, 5679, 4098, 3921, 29401, 5307, 3996, 3945, 45997, 7060, 3716, 4183, 26357, 6190, 3714, 4250, 29086, + 5929, 3491, 4489, 27772, 6656, 4219, 4348, 25851, 6088, 3617, 4477, 25722, 6303, 3856, 4208, 25348, 5896, + 3816, 4521, 22462, 5914, 3673, 4594, 18091, 6474, 3878, 4492, 10890, 4823, 4148 + }; using namespace OHOS; using namespace OHOS::Media; diff --git a/services/screendemo/test.cpp b/services/screendemo/test.cpp index 2c644732..3545a096 100644 --- a/services/screendemo/test.cpp +++ b/services/screendemo/test.cpp @@ -144,7 +144,7 @@ static void StopMirror() static void StartExpand() { - vector> remoteScreens = QueryRemoteScreenInfo(); + vector> remoteScreens = QueryRemoteScreenInfo(); if (remoteScreens.size() == 0) { cout << "Error: no remote screens enabled" << endl; return; -- Gitee From 13fe1f9bf4f1ce41c146b4576575dedc72cd9554 Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Mon, 30 May 2022 13:28:25 +0800 Subject: [PATCH 4/8] add screen demo Signed-off-by: qinlong0101 --- services/screendemo/decoder_demo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/screendemo/decoder_demo.cpp b/services/screendemo/decoder_demo.cpp index 7ea2be6d..b70fdbd7 100644 --- a/services/screendemo/decoder_demo.cpp +++ b/services/screendemo/decoder_demo.cpp @@ -25,7 +25,7 @@ #include "window.h" #include "window_option.h" - static const int32_t ES_R[325] = { + static const int32_t ES_R[325] = { 11895, 8109, 1578, 1616, 1313, 572, 805, 837, 755, 706, 952, 879, 13193, 422, 389, 509, 725, 465, 479, 959, 677, 364, 541, 696, 9306, 322, 318, 767, 590, 422, 530, 403, 505, 566, 445, 508, 7783, 460, 405, 343, 451, 608, 431, 411, 543, 487, 527, 400, 6287, 385, 418, 391, 592, 434, 412, 398, 504, 492, 479, 561, 5413, 317, @@ -44,7 +44,7 @@ 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719 }; - static const int32_t ES_W[183] = { + static const int32_t ES_W[183] = { 2111, 109091, 9316, 969, 13656, 1349, 959, 10484, 1219, 14839, 1092, 23378, 1653, 1725, 1526, 8500, 15407, 2058, 1346, 21066, 3758, 1734, 1950, 19955, 3997, 1732, 1784, 22687, 4392, 2448, 2180, 17456, 3930, 1851, 1802, 24227, 4393, 2639, 2778, 18314, 4023, 2392, 2283, 20566, 4118, 2664, 2013, 18964, 2624, 45258, 5860, -- Gitee From c58b55f69079389e1b3e7b0f170733a87564dade Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Tue, 31 May 2022 08:52:59 +0800 Subject: [PATCH 5/8] add screen demo Signed-off-by: qinlong0101 --- services/screendemo/common.h | 58 --------------- services/screendemo/decoder_demo.cpp | 74 ++++++++++--------- services/screendemo/test.cpp | 6 +- .../dscreenmgr/src/dscreen_manager.cpp | 7 -- 4 files changed, 42 insertions(+), 103 deletions(-) delete mode 100644 services/screendemo/common.h diff --git a/services/screendemo/common.h b/services/screendemo/common.h deleted file mode 100644 index 797c75d9..00000000 --- a/services/screendemo/common.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DISTRIBUTED_SCREEN_TEST_SA_H -#define DISTRIBUTED_SCREEN_TEST_SA_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "idistributed_hardware_source.h" - -namespace OHOS { -namespace DistributedHardware { -class DScreenMockRegisterCallback : public RegisterCallback { -public: - virtual ~DScreenMockRegisterCallback() = default; - int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, - const std::string &data) - { - std::cout << "Register devId: " << devId << " dhId: " << dhId << ", status: " << status << std::endl; - return 0; - } -}; - -class DScreenMockUnRegisterCallback : public UnregisterCallback { -public: - virtual ~DScreenMockUnRegisterCallback() = default; - int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, - const std::string &data) - { - std::cout << "Unregister devId: " << devId << " dhId: " << dhId << ", status: " << status << std::endl; - return 0; - } -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // DISTRIBUTED_SCREEN_TEST_SA_H \ No newline at end of file diff --git a/services/screendemo/decoder_demo.cpp b/services/screendemo/decoder_demo.cpp index b70fdbd7..19b23293 100644 --- a/services/screendemo/decoder_demo.cpp +++ b/services/screendemo/decoder_demo.cpp @@ -25,38 +25,38 @@ #include "window.h" #include "window_option.h" - static const int32_t ES_R[325] = { - 11895, 8109, 1578, 1616, 1313, 572, 805, 837, 755, 706, 952, 879, 13193, 422, 389, 509, 725, 465, 479, 959, - 677, 364, 541, 696, 9306, 322, 318, 767, 590, 422, 530, 403, 505, 566, 445, 508, 7783, 460, 405, 343, 451, - 608, 431, 411, 543, 487, 527, 400, 6287, 385, 418, 391, 592, 434, 412, 398, 504, 492, 479, 561, 5413, 317, - 355, 422, 467, 452, 476, 460, 490, 492, 485, 451, 5036, 312, 408, 460, 432, 502, 388, 475, 407, 544, 401, - 487, 4404, 362, 378, 427, 416, 426, 456, 414, 438, 424, 442, 444, 4310, 362, 388, 393, 390, 441, 398, 423, - 369, 443, 406, 392, 4231, 343, 363, 355, 390, 459, 371, 378, 381, 405, 392, 426, 3975, 387, 337, 393, 439, - 378, 355, 374, 484, 381, 373, 423, 3869, 312, 350, 400, 345, 356, 320, 473, 431, 386, 338, 431, 3426, 268, - 315, 416, 383, 373, 381, 354, 383, 328, 348, 418, 3715, 324, 361, 331, 350, 302, 409, 377, 359, 384, 334, - 326, 3439, 266, 324, 329, 353, 405, 303, 357, 332, 292, 361, 333, 3542, 294, 284, 247, 331, 306, 322, 287, - 367, 341, 276, 258, 3980, 246, 245, 259, 309, 333, 250, 275, 334, 281, 253, 371, 3640, 213, 231, 301, 302, - 228, 289, 290, 281, 201, 284, 277, 4242, 205, 328, 237, 283, 295, 266, 230, 321, 348, 212, 308, 4103, 259, - 238, 245, 298, 330, 265, 271, 287, 267, 286, 290, 3856, 269, 242, 209, 314, 267, 278, 280, 314, 250, 433, - 238, 3654, 195, 246, 301, 298, 250, 270, 320, 269, 305, 258, 368, 3810, 231, 212, 279, 289, 252, 303, 287, - 295, 206, 264, 349, 4071, 242, 296, 271, 231, 307, 265, 254, 267, 317, 232, 348, 4077, 259, 222, 268, 235, - 324, 266, 256, 312, 246, 248, 325, 4000, 266, 201, 230, 293, 264, 265, 273, 301, 304, 253, 266, 3978, 228, - 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719 - }; - - static const int32_t ES_W[183] = { - 2111, 109091, 9316, 969, 13656, 1349, 959, 10484, 1219, 14839, 1092, 23378, 1653, 1725, 1526, 8500, 15407, - 2058, 1346, 21066, 3758, 1734, 1950, 19955, 3997, 1732, 1784, 22687, 4392, 2448, 2180, 17456, 3930, 1851, - 1802, 24227, 4393, 2639, 2778, 18314, 4023, 2392, 2283, 20566, 4118, 2664, 2013, 18964, 2624, 45258, 5860, - 4124, 3473, 27772, 4687, 3140, 2939, 26288, 3808, 2967, 2823, 27219, 3943, 3242, 2667, 27372, 3522, 2899, - 2316, 26608, 3284, 2853, 2285, 19581, 2894, 2436, 24898, 4002, 2876, 2807, 25730, 3903, 2874, 2975, 26309, - 3771, 2763, 2666, 23404, 3826, 2410, 2644, 24629, 4145, 3121, 2878, 50773, 7040, 3945, 3292, 30828, 5210, - 2883, 3277, 31501, 4809, 3068, 3220, 30746, 4715, 3461, 3583, 32278, 4798, 3398, 3389, 31404, 4921, 3382, - 3766, 31821, 5848, 3860, 4047, 37642, 5793, 4271, 4094, 29853, 6163, 4399, 4063, 32151, 6038, 4332, 4041, - 30390, 5679, 4098, 3921, 29401, 5307, 3996, 3945, 45997, 7060, 3716, 4183, 26357, 6190, 3714, 4250, 29086, - 5929, 3491, 4489, 27772, 6656, 4219, 4348, 25851, 6088, 3617, 4477, 25722, 6303, 3856, 4208, 25348, 5896, - 3816, 4521, 22462, 5914, 3673, 4594, 18091, 6474, 3878, 4492, 10890, 4823, 4148 - }; +static const int32_t ES_R[325] = { + 11895, 8109, 1578, 1616, 1313, 572, 805, 837, 755, 706, 952, 879, 13193, 422, 389, 509, 725, 465, 479, 959, + 677, 364, 541, 696, 9306, 322, 318, 767, 590, 422, 530, 403, 505, 566, 445, 508, 7783, 460, 405, 343, 451, + 608, 431, 411, 543, 487, 527, 400, 6287, 385, 418, 391, 592, 434, 412, 398, 504, 492, 479, 561, 5413, 317, + 355, 422, 467, 452, 476, 460, 490, 492, 485, 451, 5036, 312, 408, 460, 432, 502, 388, 475, 407, 544, 401, + 487, 4404, 362, 378, 427, 416, 426, 456, 414, 438, 424, 442, 444, 4310, 362, 388, 393, 390, 441, 398, 423, + 369, 443, 406, 392, 4231, 343, 363, 355, 390, 459, 371, 378, 381, 405, 392, 426, 3975, 387, 337, 393, 439, + 378, 355, 374, 484, 381, 373, 423, 3869, 312, 350, 400, 345, 356, 320, 473, 431, 386, 338, 431, 3426, 268, + 315, 416, 383, 373, 381, 354, 383, 328, 348, 418, 3715, 324, 361, 331, 350, 302, 409, 377, 359, 384, 334, + 326, 3439, 266, 324, 329, 353, 405, 303, 357, 332, 292, 361, 333, 3542, 294, 284, 247, 331, 306, 322, 287, + 367, 341, 276, 258, 3980, 246, 245, 259, 309, 333, 250, 275, 334, 281, 253, 371, 3640, 213, 231, 301, 302, + 228, 289, 290, 281, 201, 284, 277, 4242, 205, 328, 237, 283, 295, 266, 230, 321, 348, 212, 308, 4103, 259, + 238, 245, 298, 330, 265, 271, 287, 267, 286, 290, 3856, 269, 242, 209, 314, 267, 278, 280, 314, 250, 433, + 238, 3654, 195, 246, 301, 298, 250, 270, 320, 269, 305, 258, 368, 3810, 231, 212, 279, 289, 252, 303, 287, + 295, 206, 264, 349, 4071, 242, 296, 271, 231, 307, 265, 254, 267, 317, 232, 348, 4077, 259, 222, 268, 235, + 324, 266, 256, 312, 246, 248, 325, 4000, 266, 201, 230, 293, 264, 265, 273, 301, 304, 253, 266, 3978, 228, + 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719 +}; + +static const int32_t ES_W[183] = { + 2111, 109091, 9316, 969, 13656, 1349, 959, 10484, 1219, 14839, 1092, 23378, 1653, 1725, 1526, 8500, 15407, + 2058, 1346, 21066, 3758, 1734, 1950, 19955, 3997, 1732, 1784, 22687, 4392, 2448, 2180, 17456, 3930, 1851, + 1802, 24227, 4393, 2639, 2778, 18314, 4023, 2392, 2283, 20566, 4118, 2664, 2013, 18964, 2624, 45258, 5860, + 4124, 3473, 27772, 4687, 3140, 2939, 26288, 3808, 2967, 2823, 27219, 3943, 3242, 2667, 27372, 3522, 2899, + 2316, 26608, 3284, 2853, 2285, 19581, 2894, 2436, 24898, 4002, 2876, 2807, 25730, 3903, 2874, 2975, 26309, + 3771, 2763, 2666, 23404, 3826, 2410, 2644, 24629, 4145, 3121, 2878, 50773, 7040, 3945, 3292, 30828, 5210, + 2883, 3277, 31501, 4809, 3068, 3220, 30746, 4715, 3461, 3583, 32278, 4798, 3398, 3389, 31404, 4921, 3382, + 3766, 31821, 5848, 3860, 4047, 37642, 5793, 4271, 4094, 29853, 6163, 4399, 4063, 32151, 6038, 4332, 4041, + 30390, 5679, 4098, 3921, 29401, 5307, 3996, 3945, 45997, 7060, 3716, 4183, 26357, 6190, 3714, 4250, 29086, + 5929, 3491, 4489, 27772, 6656, 4219, 4348, 25851, 6088, 3617, 4477, 25722, 6303, 3856, 4208, 25348, 5896, + 3816, 4521, 22462, 5914, 3673, 4594, 18091, 6474, 3878, 4492, 10890, 4823, 4148 +}; using namespace OHOS; using namespace OHOS::Media; @@ -72,6 +72,7 @@ namespace { const string CODEC_NAME_MPEG4 = "avenc_mpeg4"; constexpr uint32_t VIDEO_DATA_FORMAT_NV12 = 2; constexpr uint32_t VIDEO_DATA_FORMAT_RGBA = 5; + constexpr uint32_t SLEEP_THREE_SECOND = 3; } void VDecDemo::RunCase() @@ -92,7 +93,7 @@ void VDecDemo::RunCase() SetSurface(); Prepare(); Start(); - sleep(3); + sleep(SLEEP_THREE_SECOND); Stop(); Release(); } @@ -225,7 +226,7 @@ void VDecDemo::InputFunc() } 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; }); if (!isRunning_.load()) { break; @@ -235,6 +236,9 @@ void VDecDemo::InputFunc() auto buffer = vdec_->GetInputBuffer(index); char *fileBuffer = (char *)malloc(sizeof(char) * (*frameLen) + 1); + if (fileBuffer == nullptr) { + break; + } (void)testFile_->read(fileBuffer, *frameLen); if (memcpy_s(buffer->GetBase(), buffer->GetSize(), fileBuffer, *frameLen) != EOK) { @@ -282,7 +286,7 @@ void VDecDemo::OutputFunc() } unique_lock lock(signal_->outMutex_); - signal_->outCond_.wait(lock, [this](){ return signal_->outQueue_.size() > 0; }); + signal_->outCond_.wait(lock, [this]() { return signal_->outQueue_.size() > 0; }); if (!isRunning_.load()) { break; diff --git a/services/screendemo/test.cpp b/services/screendemo/test.cpp index 3545a096..522aaec0 100644 --- a/services/screendemo/test.cpp +++ b/services/screendemo/test.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#include + #include "display.h" #include "display_manager.h" #include "dscreen_source_handler.h" @@ -27,7 +29,6 @@ #include "window.h" #include "window_option.h" -#include "common.h" #include "decoder_demo.h" #include "softbus_adapter_mem.h" #include "softbus_bus_center.h" @@ -220,8 +221,7 @@ static void PrintNodeProperty(NodeBasicInfo *nodeInfo) printf("DeviceName = %s\n", nodeInfo->deviceName); printf("NetworkId = %s\n", nodeInfo->networkId); - NodeDeviceInfoKey key; - key = NODE_KEY_UDID; + NodeDeviceInfoKey key = NODE_KEY_UDID; unsigned char udid[UDID_BUF_LEN] = {0}; if (GetNodeKeyInfo(g_pkgName, nodeInfo->networkId, key, udid, UDID_BUF_LEN) != 0) { printf("GetNodeKeyInfo Fail!\n"); diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp index 3d747f35..461f5805 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp @@ -83,13 +83,6 @@ int32_t DScreenManager::UnInit() } dScreenCallback_ = nullptr; - if (dScreenSourceCallbackProxy_ != nullptr) { - dScreenSourceCallbackProxy_ = nullptr; - } - - if (dScreenGroupListener_ != nullptr) { - dScreenGroupListener_ = nullptr; - } { std::lock_guard lock(dScreenMapMtx_); -- Gitee From 349e082d709e75d2fc2b92e8370bc84846780336 Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Tue, 31 May 2022 11:00:17 +0800 Subject: [PATCH 6/8] add screen demo Signed-off-by: qinlong0101 --- services/screendemo/decoder_demo.cpp | 13 +++++++++---- services/screendemo/decoder_demo.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/services/screendemo/decoder_demo.cpp b/services/screendemo/decoder_demo.cpp index 19b23293..729cc04a 100644 --- a/services/screendemo/decoder_demo.cpp +++ b/services/screendemo/decoder_demo.cpp @@ -140,7 +140,6 @@ int32_t VDecDemo::Stop() if (inputLoop_ != nullptr && inputLoop_->joinable()) { unique_lock lock(signal_->inMutex_); - signal_->inQueue_.push(10000); signal_->inCond_.notify_all(); lock.unlock(); inputLoop_->join(); @@ -149,7 +148,6 @@ int32_t VDecDemo::Stop() if (outputLoop_ != nullptr && outputLoop_->joinable()) { unique_lock lock(signal_->outMutex_); - signal_->outQueue_.push(10000); signal_->outCond_.notify_all(); lock.unlock(); outputLoop_->join(); @@ -211,14 +209,21 @@ void VDecDemo::CheckCodecType() } } -void VDecDemo::InputFunc() +const int32_t* VDecDemo::GetFrameLen() { - const int32_t *frameLen = nullptr; + const int32_t* frameLen = nullptr; if (isW) { frameLen = ES_W; + return frameLen; } else { frameLen = ES_R; + return frameLen; } +} + +void VDecDemo::InputFunc() +{ + const int32_t *frameLen =GetFrameLen(); while (true) { if (!isRunning_.load()) { diff --git a/services/screendemo/decoder_demo.h b/services/screendemo/decoder_demo.h index 7d7334a6..a9ca47c1 100644 --- a/services/screendemo/decoder_demo.h +++ b/services/screendemo/decoder_demo.h @@ -69,6 +69,7 @@ private: int32_t Reset(); int32_t Release(); int32_t SetSurface(); + const int32_t *GetFrameLen(); void InputFunc(); void OutputFunc(); void CheckCodecType(); -- Gitee From b169745c184026775a019be1f78103833f5df82e Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Tue, 31 May 2022 11:04:09 +0800 Subject: [PATCH 7/8] add screen demo Signed-off-by: qinlong0101 --- services/screendemo/decoder_demo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/screendemo/decoder_demo.cpp b/services/screendemo/decoder_demo.cpp index 729cc04a..1fb1f49a 100644 --- a/services/screendemo/decoder_demo.cpp +++ b/services/screendemo/decoder_demo.cpp @@ -223,7 +223,7 @@ const int32_t* VDecDemo::GetFrameLen() void VDecDemo::InputFunc() { - const int32_t *frameLen =GetFrameLen(); + const int32_t *frameLen = GetFrameLen(); while (true) { if (!isRunning_.load()) { -- Gitee From ef619d5dc9b8b57ba9377d4e114f3e2b4cb56fcb Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Tue, 31 May 2022 16:49:11 +0800 Subject: [PATCH 8/8] add screen demo Signed-off-by: qinlong0101 --- services/screendemo/decoder_demo.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/screendemo/decoder_demo.cpp b/services/screendemo/decoder_demo.cpp index 1fb1f49a..90242d37 100644 --- a/services/screendemo/decoder_demo.cpp +++ b/services/screendemo/decoder_demo.cpp @@ -68,11 +68,12 @@ namespace { constexpr uint32_t MAX_INPUT_BUFFER_SIZE = 30000; constexpr uint32_t FRAME_DURATION_US = 33000; constexpr uint32_t DEFAULT_FRAME_COUNT = 1; - const string CODEC_NAME_H264 = "OMX_hisi_video_encoder_avc"; - const string CODEC_NAME_MPEG4 = "avenc_mpeg4"; constexpr uint32_t VIDEO_DATA_FORMAT_NV12 = 2; constexpr uint32_t VIDEO_DATA_FORMAT_RGBA = 5; constexpr uint32_t SLEEP_THREE_SECOND = 3; + constexpr uint32_t INDEX_CONSTANT = 10000; + const string CODEC_NAME_H264 = "OMX_hisi_video_encoder_avc"; + const string CODEC_NAME_MPEG4 = "avenc_mpeg4"; } void VDecDemo::RunCase() @@ -140,6 +141,7 @@ int32_t VDecDemo::Stop() if (inputLoop_ != nullptr && inputLoop_->joinable()) { unique_lock lock(signal_->inMutex_); + signal_->inQueue_.push(INDEX_CONSTANT); signal_->inCond_.notify_all(); lock.unlock(); inputLoop_->join(); @@ -148,6 +150,7 @@ int32_t VDecDemo::Stop() if (outputLoop_ != nullptr && outputLoop_->joinable()) { unique_lock lock(signal_->outMutex_); + signal_->outQueue_.push(INDEX_CONSTANT); signal_->outCond_.notify_all(); lock.unlock(); outputLoop_->join(); -- Gitee