mirror of
https://github.com/openharmony/distributed_screen.git
synced 2026-06-30 21:57:58 -04:00
first add distributed screen code
Signed-off-by: sxzheng96 <zhengshuangxi2@huawei.com>
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- 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.
|
||||
|
||||
Notes:
|
||||
This is project config file for OpenHarmony OSS Audit Tool, if you have any questions or concerns, please email chenyaxun.
|
||||
-->
|
||||
<!-- OAT(OSS Audit Tool) configuration guide:
|
||||
basedir: Root dir, the basedir + project path is the real source file location.
|
||||
licensefile:
|
||||
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
|
||||
|
||||
tasklist(only for batch mode):
|
||||
1. task: Define oat check thread, each task will start a new thread.
|
||||
2. task name: Only an name, no practical effect.
|
||||
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
|
||||
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
|
||||
5. task project: Projects to be checked, the path field define the source root dir of the project.
|
||||
|
||||
|
||||
policyList:
|
||||
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
|
||||
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
|
||||
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
|
||||
3. policyitem type:
|
||||
"compatibility" is used to check license compatibility in the specified path;
|
||||
"license" is used to check source license header in the specified path;
|
||||
"copyright" is used to check source copyright header in the specified path;
|
||||
"import" is used to check source dependency in the specified path, such as import ... ,include ...
|
||||
"filetype" is used to check file type in the specified path, supported file types: archive, binary
|
||||
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
|
||||
|
||||
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
|
||||
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
|
||||
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
|
||||
7. policyitem filefilter: Used to bind filefilter which define filter rules.
|
||||
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
|
||||
|
||||
Note:If the text contains special characters, please escape them according to the following rules:
|
||||
" == >
|
||||
& == >
|
||||
' == >
|
||||
< == >
|
||||
> == >
|
||||
-->
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<filefilterlist>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for project binary file" >
|
||||
<filteritem type="filepath" name="figures/distributedscreen_arch.png" desc="pictures for project readme document"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
||||
@@ -0,0 +1,87 @@
|
||||
# **分布式屏幕组件**
|
||||
|
||||
## **简介**
|
||||
|
||||
分布式屏幕是一种屏幕虚拟化能力,支持用户指定任意设备的屏幕作为Display的显示区域。在分布式硬件子系统中,分布式屏幕提供跨设备屏幕能力调用,为OpenHarmony操作系统提供系统投屏、屏幕镜像、屏幕分割等能力的实现。
|
||||
|
||||
系统架构如下图所示:
|
||||
|
||||

|
||||
|
||||
**屏幕区域管理(ScreenRegionManager)**:管理主控端映射在被控端屏幕上的显示区域的状态,包括为显示区域指定显示的display,设置显示区域的宽高,解码类型等参数。
|
||||
|
||||
**分布式屏幕管理(DScreenManager)**:管理被控端屏幕的参数和状态,负责主控端相关对象的创建和销毁。
|
||||
|
||||
**屏幕服务(ScreenService)**:分布式屏幕主控端SA服务和分布式屏幕被控端SA服务,负责处理分布式硬件管理框架的IPC调用
|
||||
|
||||
**软总线适配器(SoftbusAdapter)**:对接软总线传输接口,为屏幕图像、输入事件等提供封装的统一调用接口,实现设备间的流数据、字节数据传输和交互。
|
||||
|
||||
**屏幕传输组件(ScreenTransport)**:分布式屏幕传输模块,实现屏幕图像数据编码、解码、发送、接收。
|
||||
|
||||
**屏幕代理客户端(ScreenClient)**:屏幕图像显示代理客户端,用于在设备上显示其他设备投射过来的屏幕图像数据。
|
||||
|
||||
|
||||
## **目录**
|
||||
|
||||
```
|
||||
/foundation/distributedhardware/distributedscreen
|
||||
├── common # 分布式屏幕公共数据定义,包括常量、错误码、日志、工具等
|
||||
├── interface # 分布式屏幕SDK,包含主控端和被控端服务调用接口
|
||||
├── sa_profile # 分布式屏幕的SA配置信息
|
||||
├── services # 分布式屏幕主控端和被控端功能主体业务实现
|
||||
│ └── common # 分布式屏幕功能主控端、被控端共用功能实现
|
||||
│ ├── databuffer # 屏幕数据存储定义
|
||||
│ └── screen_channel # 屏幕数据传输通道接口定义
|
||||
│ └── screenclient # 分布式屏幕代理客户端实现
|
||||
│ └── screenservice # 分布式屏幕主体功能实现
|
||||
│ └── sinkservice # 分布式屏幕被控端服务功能实现
|
||||
│ ├── dscreenservice # 分布式屏幕被控端SA
|
||||
│ └── screenregionmgr # 分布式屏幕被控端显示区域管理
|
||||
│ └── sourceservice # 分布式屏幕主控端服务功能实现
|
||||
│ ├── dscreenmgr # 分布式屏幕主控端屏幕管理
|
||||
│ └── dscreenservice # 分布式屏幕主控端SA
|
||||
│ └── screentransport # 分布式屏幕传输组件
|
||||
│ ├── screendatachannel # 屏幕数据传输通道,用于传输组件和编解码器之间数据传输
|
||||
│ ├── screensinkprocessor # 分布式屏幕被控端数据处理模块,包括解码等
|
||||
│ ├── screensinktrans # 分布式屏幕被控端数据传输组件,包含数据传输通道channel和数据处理模块processor
|
||||
│ ├── screensourceprocessor # 分布式屏幕主控端数据处理模块,包括编码等
|
||||
│ └── screensourcetrans # 分布式屏幕主控端数据传输组件,包含数据传输通道channel和数据处理模块processor
|
||||
│ └── softbusadapter # 软总线接口适配器,为屏幕传输、触控事件传输提供统一传输接口
|
||||
└── screenhandler # 分布式屏幕硬件信息上报、设备状态变化通知,由分布式硬件管理框架加载
|
||||
```
|
||||
|
||||
## **约束**
|
||||
**语言限制**:C++语言。
|
||||
**组网环境**:必须确保设备在同一个局域网中。
|
||||
**操作系统限制**:OpenHarmony操作系统。
|
||||
|
||||
## **说明**
|
||||
### **概念说明**
|
||||
主控端(source):控制端,通过调用分布式屏幕能力,使用被控端的屏幕用于显示主控端设备的屏幕内容。
|
||||
被控端(sink):被控制端,通过分布式屏幕接收主控端的控制,在本地对接窗口用于接收和显示主控端设备的屏幕内容。
|
||||
|
||||
### **接口说明**
|
||||
分布式屏幕实现分布式硬件管理框架提供的接口,由分布式硬件管理框架统一调用接口实现虚拟屏幕硬件的创建和注册功能。
|
||||
|
||||
### **流程说明**
|
||||
#### **1. 设备开机启动**
|
||||
系统拉起分布式屏幕的SA服务,Source侧被初始化,相关模块被初始化。
|
||||
|
||||
#### **2. 设备组网上线**
|
||||
设备上线后,分布式硬件管理框架同步到上线设备的屏幕硬件信息并使能,使能成功后在系统中会新增虚拟屏幕并通知到窗口子系统,窗口子系统统一管理本地屏幕和分布式屏幕;北向应用通过窗口子系统提供的接口可以查询到分布式屏幕,并按照窗口子系统提供的接口来使用分布式屏幕。
|
||||
|
||||
#### **3. 屏幕数据流转**
|
||||
(1)主控端图形子系统将需要发送屏幕数据保存在编码器创建的输入Surface中。
|
||||
(2)主控端编码器将输入数据进行编码,并将编码结果返回传输组件screensourcetrans。
|
||||
(3)主控端传输组件screensourcetrans将编码后的数据通过传输通道screendatachannel发送到softbusadapter,并经由软总线子系统发送到被控端端设备。
|
||||
(4)被控端设备软总线子系统收到屏幕数据后,通过softbusadapter返回给被控端传输通道screendatachannel。
|
||||
(5)被控端传输通道screendatachannel将获取到的屏幕数据传递给解码器进行解码。
|
||||
(6)解码器将屏幕数据解码,并将解码后的数据保存到被控端代理显示窗口设置到解码器的Surface中,最终由窗口将画面显示在屏幕上。
|
||||
|
||||
#### **4. 设备下线**
|
||||
设备下线后,分布式硬件管理框架去使能下线设备的屏幕硬件,本地移除对应的虚拟屏幕并通知窗口子系统,此时下线设备的分布式屏幕不可用。
|
||||
|
||||
## **涉及仓**
|
||||
****
|
||||
**分布式屏幕**
|
||||
[distributed_screen](https://gitee.com/openharmony/distributed_screen)
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
{
|
||||
"name":"@ohos/distributed_screen",
|
||||
"description":"distributed hardware screen",
|
||||
"version":"3.1",
|
||||
"author":{},
|
||||
"repository":"https://gitee.com/openharmony/distributed_screen",
|
||||
"license":"Apache License 2.0",
|
||||
"publishAs":"code-segment",
|
||||
"segment":{
|
||||
"destPath":"foundation/distributedhardware/distributedscreen/"
|
||||
},
|
||||
"dirs":{},
|
||||
"scripts":{},
|
||||
"component":{
|
||||
"name":"distributed_screen",
|
||||
"subsystem":"distributedhardware",
|
||||
"syscap":[
|
||||
"SystemCapability.distributedhardware.distributed_screen"
|
||||
],
|
||||
"features":[],
|
||||
"adapted_system_type":[
|
||||
"standard"
|
||||
],
|
||||
"rom":"2000k",
|
||||
"ram":"6M",
|
||||
"deps":{
|
||||
"components":[
|
||||
"appexecfwk_standard",
|
||||
"eventhandler",
|
||||
"hiviewdfx_hilog_native",
|
||||
"ipc",
|
||||
"safwk",
|
||||
"samgr_standard",
|
||||
"dsoftbus_standard",
|
||||
"utils_base",
|
||||
"graphic_standard",
|
||||
"distributed_hardware_fwk",
|
||||
"multimedia_media_standard"
|
||||
],
|
||||
"third_party":[
|
||||
"json"
|
||||
]
|
||||
},
|
||||
"build":{
|
||||
"sub_component":[
|
||||
"//foundation/distributedhardware/distributedscreen/common:distributed_screen_utils",
|
||||
"//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk",
|
||||
"//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/screen_source:distributed_screen_source_sdk",
|
||||
"//foundation/distributedhardware/distributedscreen/services/screenclient:distributed_screen_client",
|
||||
"//foundation/distributedhardware/distributedscreen/screenhandler:distributed_screen_handler",
|
||||
"//foundation/distributedhardware/distributedscreen/services/screentransport/screensinktrans:distributed_screen_sinktrans",
|
||||
"//foundation/distributedhardware/distributedscreen/services/screentransport/screensourcetrans:distributed_screen_sourcetrans",
|
||||
"//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"
|
||||
],
|
||||
"inner_kits":[
|
||||
{
|
||||
"type": "so",
|
||||
"name": "//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk",
|
||||
"header": {
|
||||
"header_base": "//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/screen_sink/include",
|
||||
"header_files": [
|
||||
"idscreen_sink.h"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "so",
|
||||
"name": "//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/screen_source:distributed_screen_source_sdk",
|
||||
"header": {
|
||||
"header_base": "//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/screen_source/include",
|
||||
"header_files": [
|
||||
"idscreen_source.h"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"test":[
|
||||
"//foundation/distributedhardware/distributedscreen/services/screentransport/test/unittest:screen_transport_test",
|
||||
"//foundation/distributedhardware/distributedscreen/services/softbusadapter/test/unittest:SoftBusAdapterTest",
|
||||
"//foundation/distributedhardware/distributedscreen/services/screenclient/test/unittest:screen_client_test",
|
||||
"//foundation/distributedhardware/distributedscreen/services/common/test/unittest:service_common_test"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
# 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("//build/ohos_var.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
ohos_shared_library("distributed_screen_utils") {
|
||||
include_dirs = [
|
||||
"//utils/native/base/include",
|
||||
"include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/dscreen_util.cpp",
|
||||
"src/dscreen_log.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"dsoftbus_standard:softbus_client",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreenutil\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_CONSTANTS_H
|
||||
#define OHOS_DSCREEN_CONSTANTS_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
enum RpcEventType {
|
||||
NOTIFY_SINK_SETUP = 1,
|
||||
NOTIFY_SOURCE_SETUP_RESULT = 2,
|
||||
};
|
||||
|
||||
enum DScreenState {
|
||||
DISABLED,
|
||||
ENABLED,
|
||||
DISABLING,
|
||||
ENABLING,
|
||||
CONNECTING,
|
||||
CONNECTED,
|
||||
DISCONNECTING,
|
||||
};
|
||||
|
||||
enum TaskType {
|
||||
TASK_ENABLE,
|
||||
TASK_DISABLE,
|
||||
TASK_CONNECT,
|
||||
TASK_DISCONNECT,
|
||||
};
|
||||
|
||||
enum CodecType : uint8_t {
|
||||
VIDEO_CODEC_TYPE_VIDEO_H264 = 0,
|
||||
VIDEO_CODEC_TYPE_VIDEO_H265 = 1,
|
||||
};
|
||||
|
||||
enum VideoFormat : uint8_t {
|
||||
VIDEO_DATA_FORMAT_YUVI420 = 0,
|
||||
VIDEO_DATA_FORMAT_NV12 = 1,
|
||||
VIDEO_DATA_FORMAT_NV21 = 2,
|
||||
};
|
||||
|
||||
/* Screen package name */
|
||||
const std::string PKG_NAME = "DBinderBus_" + std::to_string(getpid());
|
||||
|
||||
/* Screen data session name */
|
||||
const std::string DATA_SESSION_NAME = "DBinder.ohos.dhardware.dscreen.data";
|
||||
|
||||
/* Screen session name max len */
|
||||
constexpr uint32_t DSCREEN_MAX_SESSION_NAME_LEN = 50;
|
||||
|
||||
constexpr uint32_t DSCREEN_MAX_DEVICE_ID_LEN = 100;
|
||||
/* Screen data received max length */
|
||||
constexpr uint32_t DSCREEN_MAX_RECV_DATA_LEN = 104857600;
|
||||
|
||||
/* Screen max video data width */
|
||||
constexpr uint32_t DSCREEN_MAX_VIDEO_DATA_WIDTH = 2560;
|
||||
|
||||
/* Screen max video data height */
|
||||
constexpr uint32_t DSCREEN_MAX_VIDEO_DATA_HEIGHT = 1600;
|
||||
|
||||
/* Screen max screen data width */
|
||||
constexpr uint32_t DSCREEN_MAX_SCREEN_DATA_WIDTH = 2560;
|
||||
|
||||
/* Screen max screen data height */
|
||||
constexpr uint32_t DSCREEN_MAX_SCREEN_DATA_HEIGHT = 1600;
|
||||
|
||||
/* YUV420 buffer size max size */
|
||||
constexpr int64_t MAX_YUV420_BUFFER_SIZE = 2560 * 1600 * (3 / 2) * 2;
|
||||
constexpr int32_t LOG_MAX_LEN = 4096;
|
||||
|
||||
constexpr int32_t INVALID_WINDOW_ID = -1;
|
||||
|
||||
const std::string DSCREEN_LOG_TITLE_TAG = "DSCREEN";
|
||||
const std::string DSCREEN_PREFIX = "DISTRIBUTED_SCREEN";
|
||||
const std::string SCREEN_PREFIX = "SCREEN";
|
||||
const std::string DSCREEN_VERSION = "1.0";
|
||||
const std::string SEPERATOR = "#";
|
||||
const std::string KEY_VERSION = "screenVersion";
|
||||
const std::string KEY_DISPLAY_ID = "displayId";
|
||||
const std::string KEY_SCREEN_ID = "screenId";
|
||||
const std::string KEY_DISPLAY_RECT = "displayRect";
|
||||
const std::string KEY_SCREEN_RECT = "screenRect";
|
||||
const std::string KEY_POINT_START_X = "startX";
|
||||
const std::string KEY_POINT_START_Y = "startY";
|
||||
const std::string KEY_WIDTH = "width";
|
||||
const std::string KEY_HEIGHT = "height";
|
||||
const std::string KEY_SCREEN_WIDTH = "screenWidth";
|
||||
const std::string KEY_SCREEN_HEIGHT = "screenHeight";
|
||||
const std::string KEY_VIDEO_WIDTH = "videoWidth";
|
||||
const std::string KEY_VIDEO_HEIGHT = "videoHeight";
|
||||
const std::string KEY_FPS = "fps";
|
||||
const std::string KEY_CODECTYPE = "codecType";
|
||||
const std::string SCREEN_CLIENT_WINDOW = "screenClientWindow";
|
||||
const std::string KEY_DH_ID = "dhId";
|
||||
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";
|
||||
constexpr float DEFAULT_DENSITY = 2.0;
|
||||
constexpr int32_t DEFAULT_SCREEN_FLAGS = 0;
|
||||
constexpr uint32_t DEFAULT_FPS = 30;
|
||||
constexpr uint8_t DEFAULT_CODECTYPE = VIDEO_CODEC_TYPE_VIDEO_H264;
|
||||
constexpr uint8_t DEFAULT_VIDEO_FORMAT = VIDEO_DATA_FORMAT_NV21;
|
||||
constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID = 4807;
|
||||
constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID = 4808;
|
||||
constexpr uint64_t SCREEN_ID_INVALID = -1ULL;
|
||||
constexpr uint64_t SCREEN_ID_DEFAULT = 0;
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_ERRCODE_H
|
||||
#define OHOS_DSCREEN_ERRCODE_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
enum DScreenErrorCode {
|
||||
DH_SUCCESS = 0,
|
||||
// SA error code
|
||||
ERR_DH_SCREEN_SA_GET_SAMGR_FAIL = -50000,
|
||||
ERR_DH_SCREEN_SA_GET_SOURCESERVICE_FAIL = -50001,
|
||||
ERR_DH_SCREEN_SA_GET_SOURCEPROXY_FAIL = -50002,
|
||||
ERR_DH_SCREEN_SA_GET_SOURCECALLBACKPROXY_FAIL = -50003,
|
||||
ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT = -50004,
|
||||
ERR_DH_SCREEN_SA_SOURCEPCALLBACK_NOT_INIT = -50005,
|
||||
ERR_DH_SCREEN_SA_GET_SINKSERVICE_FAIL = -50006,
|
||||
ERR_DH_SCREEN_SA_GET_SINKPROXY_FAIL = -50007,
|
||||
ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT = -50008,
|
||||
ERR_DH_SCREEN_SA_REGISTERCALLBACK_NOT_FOUND = -50009,
|
||||
ERR_DH_SCREEN_SA_UNREGISTERCALLBACK_NOT_FOUND = -50010,
|
||||
ERR_DH_SCREEN_SA_REQUEST_CODE_INVALID = -50011,
|
||||
ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED = -50012,
|
||||
ERR_DH_SCREEN_SA_WRITEPARAM_FAILED = -50013,
|
||||
ERR_DH_SCREEN_SA_READPARAM_FAILED = -50014,
|
||||
ERR_DH_SCREEN_SA_DSCREENMGR_NOT_INIT = -50015,
|
||||
ERR_DH_SCREEN_SA_ENABLE_FAILED = -50016,
|
||||
ERR_DH_SCREEN_SA_DISABLE_FAILED = -50017,
|
||||
ERR_DH_SCREEN_SA_SOURCETRANS_NOT_INIT = -50018,
|
||||
ERR_DH_SCREEN_SA_SCREENREGIONMGR_NOT_INIT = -50019,
|
||||
ERR_DH_SCREEN_SA_SINKTRANS_NOT_INIT = -50020,
|
||||
ERR_DH_SCREEN_SA_GET_REMOTE_SOURCE_SERVICE_FAIL = -50021,
|
||||
ERR_DH_SCREEN_SA_GET_REMOTE_SINK_SERVICE_FAIL = -50022,
|
||||
ERR_DH_SCREEN_SA_SCREENREGION_SETUP_FAIL = -50023,
|
||||
ERR_DH_SCREEN_SA_SCREENREGION_START_FAIL = -50024,
|
||||
ERR_DH_SCREEN_SA_REMOVE_VIRTUALSCREEN_FAIL = -50025,
|
||||
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,
|
||||
// Transport component error code
|
||||
ERR_DH_SCREEN_TRANS_ERROR = -51000,
|
||||
ERR_DH_SCREEN_TRANS_TIMEOUT = -51001,
|
||||
ERR_DH_SCREEN_TRANS_NULL_VALUE = -51002,
|
||||
ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM = -51003,
|
||||
ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION = -51004,
|
||||
ERR_DH_SCREEN_TRANS_SESSION_CLOSED = -51005,
|
||||
ERR_DH_SCREEN_TRANS_CREATE_CODEC_FAILED = -51006,
|
||||
ERR_DH_SCREEN_TRANS_RELEASE_CODEC_FAILED = -51007,
|
||||
ERR_DH_SCREEN_TRANS_START_CODEC_FAILED = -51008,
|
||||
ERR_DH_SCREEN_TRANS_STOP_CODEC_FAILED = -51009,
|
||||
ERR_DH_SCREEN_TRANS_CREATE_SURFACE_FAILED = -51010,
|
||||
ERR_DH_SCREEN_TRANS_SESSION_NOT_OPEN = -51011,
|
||||
// adapter
|
||||
ERR_DH_SCREEN_ADAPTER_SESSION_ID_NOT_FIND = -52000,
|
||||
ERR_DH_SCREEN_ADAPTER_UNREGISTER_SOFTBUS_LISTENER_FAIL = -52001,
|
||||
ERR_DH_SCREEN_ADAPTER_REGISTER_SOFTBUS_LISTENER_FAIL = -52002,
|
||||
ERR_DH_SCREEN_ADAPTER_FIND_SOFTBUS_LISTENER_FAIL = -52003,
|
||||
ERR_DH_SCREEN_ADAPTER_BAD_VALUE = -52004,
|
||||
ERR_DH_SCREEN_ADAPTER_OPEN_SESSION_FAIL = -52005,
|
||||
ERR_DH_SCREEN_ADAPTER_PARA_ERROR = -52006,
|
||||
// Encoder & Decoder
|
||||
ERR_DH_SCREEN_CODEC_RELEASE_FAILED = -53000,
|
||||
ERR_DH_SCREEN_CODEC_PREPARE_FAILED = -53001,
|
||||
ERR_DH_SCREEN_CODEC_START_FAILED = -53002,
|
||||
ERR_DH_SCREEN_CODEC_FLUSH_FAILED = -53003,
|
||||
ERR_DH_SCREEN_CODEC_STOP_FAILED = -53004,
|
||||
ERR_DH_SCREEN_CODEC_SET_CALLBACK_FAILED = -53005,
|
||||
ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED = -53006,
|
||||
ERR_DH_SCREEN_CODEC_SURFACE_ERROR = -53007,
|
||||
// ScreenClient error code
|
||||
ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR = -54000,
|
||||
ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR = -54001,
|
||||
ERR_DH_SCREEN_SCREENCLIENT_ADD_WINDOW_ERROR = -54002,
|
||||
ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR = -54003,
|
||||
ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR = -54004,
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_LOG_H
|
||||
#define OHOS_DSCREEN_LOG_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
typedef enum {
|
||||
DH_LOG_DEBUG,
|
||||
DH_LOG_INFO,
|
||||
DH_LOG_WARN,
|
||||
DH_LOG_ERROR,
|
||||
} DHLogLevel;
|
||||
|
||||
void DHLog(DHLogLevel logLevel, const char *fmt, ...);
|
||||
|
||||
#define DHLOGD(fmt, ...) DHLog(DH_LOG_DEBUG, \
|
||||
(std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
|
||||
|
||||
#define DHLOGI(fmt, ...) DHLog(DH_LOG_INFO, \
|
||||
(std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
|
||||
|
||||
#define DHLOGW(fmt, ...) DHLog(DH_LOG_WARN, \
|
||||
(std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
|
||||
|
||||
#define DHLOGE(fmt, ...) DHLog(DH_LOG_ERROR, \
|
||||
(std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_UTIL_H
|
||||
#define OHOS_DSCREEN_UTIL_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
int32_t GetLocalDeviceNetworkId(std::string &networkId);
|
||||
std::string GetRandomID();
|
||||
std::string GetAnonyString(const std::string &value);
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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 "dscreen_log.h"
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef HI_LOG_ENABLE
|
||||
#include "hilog/log.h"
|
||||
#else
|
||||
#include <cstdio>
|
||||
#endif
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
static void DHLogOut(DHLogLevel logLevel, const char *logBuf)
|
||||
{
|
||||
#ifdef HI_LOG_ENABLE
|
||||
LogLevel hiLogLevel = LOG_INFO;
|
||||
switch (logLevel) {
|
||||
case DH_LOG_DEBUG:
|
||||
hiLogLevel = LOG_DEBUG;
|
||||
break;
|
||||
case DH_LOG_INFO:
|
||||
hiLogLevel = LOG_INFO;
|
||||
break;
|
||||
case DH_LOG_WARN:
|
||||
hiLogLevel = LOG_WARN;
|
||||
break;
|
||||
case DH_LOG_ERROR:
|
||||
hiLogLevel = LOG_ERROR;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
(void)HiLogPrint(LOG_CORE, hiLogLevel, LOG_DOMAIN, DSCREEN_LOG_TITLE_TAG.c_str(), "%{public}s", logBuf);
|
||||
#else
|
||||
switch (logLevel) {
|
||||
case DH_LOG_DEBUG:
|
||||
printf("[D]%s\n", logBuf);
|
||||
break;
|
||||
case DH_LOG_INFO:
|
||||
printf("[I]%s\n", logBuf);
|
||||
break;
|
||||
case DH_LOG_WARN:
|
||||
printf("[W]%s\n", logBuf);
|
||||
break;
|
||||
case DH_LOG_ERROR:
|
||||
printf("[E]%s\n", logBuf);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void DHLog(DHLogLevel logLevel, const char *fmt, ...)
|
||||
{
|
||||
char logBuf[LOG_MAX_LEN] = {0};
|
||||
va_list arg;
|
||||
|
||||
(void)memset_s(&arg, sizeof(va_list), 0, sizeof(va_list));
|
||||
va_start(arg, fmt);
|
||||
int32_t ret = vsprintf_s(logBuf, sizeof(logBuf), fmt, arg);
|
||||
va_end(arg);
|
||||
if (ret < 0) {
|
||||
DHLogOut(logLevel, "DH log length error.");
|
||||
return;
|
||||
}
|
||||
DHLogOut(logLevel, logBuf);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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 "dscreen_util.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "softbus_bus_center.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
constexpr int32_t WORD_WIDTH_8 = 8;
|
||||
constexpr int32_t WORD_WIDTH_4 = 4;
|
||||
|
||||
int32_t GetLocalDeviceNetworkId(std::string &networkId)
|
||||
{
|
||||
NodeBasicInfo basicInfo = { { 0 } };
|
||||
int32_t ret = GetLocalNodeDeviceInfo(PKG_NAME.c_str(), &basicInfo);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("GetLocalDeviceNetworkId failed ret: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
networkId = std::string(basicInfo.networkId);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
std::string GetRandomID()
|
||||
{
|
||||
static std::random_device rd;
|
||||
static std::uniform_int_distribution<uint64_t> dist(0ULL, 0xFFFFFFFFFFFFFFFFULL);
|
||||
uint64_t ab = dist(rd);
|
||||
uint64_t cd = dist(rd);
|
||||
uint32_t a, b, c, d;
|
||||
std::stringstream ss;
|
||||
ab = (ab & 0xFFFFFFFFFFFF0FFFULL) | 0x0000000000004000ULL;
|
||||
cd = (cd & 0x3FFFFFFFFFFFFFFFULL) | 0x8000000000000000ULL;
|
||||
a = (ab >> 32U);
|
||||
b = (ab & 0xFFFFFFFFU);
|
||||
c = (cd >> 32U);
|
||||
d = (cd & 0xFFFFFFFFU);
|
||||
ss << std::hex << std::nouppercase << std::setfill('0');
|
||||
ss << std::setw(WORD_WIDTH_8) << (a);
|
||||
ss << std::setw(WORD_WIDTH_4) << (b >> 16U);
|
||||
ss << std::setw(WORD_WIDTH_4) << (b & 0xFFFFU);
|
||||
ss << std::setw(WORD_WIDTH_4) << (c >> 16U);
|
||||
ss << std::setw(WORD_WIDTH_4) << (c & 0xFFFFU);
|
||||
ss << std::setw(WORD_WIDTH_8) << d;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string GetAnonyString(const std::string &value)
|
||||
{
|
||||
constexpr size_t INT32_SHORT_ID_LENGTH = 20;
|
||||
constexpr size_t INT32_MIN_ID_LENGTH = 3;
|
||||
std::string res;
|
||||
std::string tmpStr("******");
|
||||
size_t strLen = value.length();
|
||||
if (strLen < INT32_MIN_ID_LENGTH) {
|
||||
return tmpStr;
|
||||
}
|
||||
|
||||
if (strLen <= INT32_SHORT_ID_LENGTH) {
|
||||
res += value[0];
|
||||
res += tmpStr;
|
||||
res += value[strLen - 1];
|
||||
} else {
|
||||
constexpr size_t INT32_PLAINTEXT_LENGTH = 4;
|
||||
res.append(value, 0, INT32_PLAINTEXT_LENGTH);
|
||||
res += tmpStr;
|
||||
res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,25 @@
|
||||
# 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.
|
||||
|
||||
distributedscreen_path = "//foundation/distributedhardware/distributedscreen"
|
||||
distributedhardwarefwk_path = "//foundation/distributedhardware/distributedhardwarefwk"
|
||||
windowmanager_path = "//foundation/windowmanager"
|
||||
mediastandard_path = "//foundation/multimedia/media_standard"
|
||||
graphicstandard_path = "//foundation/graphic/standard"
|
||||
common_path = "${distributedscreen_path}/common"
|
||||
services_path = "${distributedscreen_path}/services"
|
||||
interfaces_path = "${distributedscreen_path}/interfaces"
|
||||
fwk_utils_path = "${distributedhardwarefwk_path}/utils"
|
||||
fwk_common_path = "${distributedhardwarefwk_path}/common"
|
||||
fwk_services_path = "${distributedhardwarefwk_path}/services"
|
||||
build_flags = ["-Werror"]
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
@@ -0,0 +1,55 @@
|
||||
# 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("//build/ohos_var.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
ohos_shared_library("distributed_screen_sink_sdk") {
|
||||
include_dirs = [
|
||||
"//utils/system/safwk/native/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"include",
|
||||
"${common_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/dscreen_sink_handler.cpp",
|
||||
"src/dscreen_sink_proxy.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"${common_path}:distributed_screen_utils",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreensinksdk\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SINK_HANDLER_H
|
||||
#define OHOS_DSCREEN_SINK_HANDLER_H
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "idistributed_hardware_sink.h"
|
||||
#include "single_instance.h"
|
||||
|
||||
#include "idscreen_sink.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSinkHandler : public IDistributedHardwareSink {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DScreenSinkHandler);
|
||||
public:
|
||||
int32_t InitSink(const std::string ¶ms) override;
|
||||
int32_t ReleaseSink() override;
|
||||
int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override;
|
||||
int32_t UnsubscribeLocalHardware(const std::string &dhId) override;
|
||||
void OnRemoteSinkSvrDied(const wptr<IRemoteObject> &remote);
|
||||
private:
|
||||
class DScreenSinkSvrRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
|
||||
};
|
||||
|
||||
DScreenSinkHandler();
|
||||
~DScreenSinkHandler();
|
||||
|
||||
std::mutex mutex_;
|
||||
sptr<IDScreenSink> dScreenSinkProxy_ = nullptr;
|
||||
sptr<DScreenSinkSvrRecipient> sinkSvrRecipient_ = nullptr;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
__attribute__((visibility("default"))) IDistributedHardwareSink *GetSinkHardwareHandler();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SINK_PROXY_H
|
||||
#define OHOS_DSCREEN_SINK_PROXY_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
#include "idscreen_sink.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSinkProxy : public IRemoteProxy<IDScreenSink> {
|
||||
public:
|
||||
explicit DScreenSinkProxy(const sptr<IRemoteObject> impl)
|
||||
: IRemoteProxy<IDScreenSink>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
~DScreenSinkProxy() {}
|
||||
int32_t InitSink(const std::string ¶ms) override;
|
||||
int32_t ReleaseSink() override;
|
||||
int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override;
|
||||
int32_t UnsubscribeLocalHardware(const std::string &dhId) override;
|
||||
void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<DScreenSinkProxy> delegator_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 OHOS_IDSCREEN_SINK_H
|
||||
#define OHOS_IDSCREEN_SINK_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class IDScreenSink : public OHOS::IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.distributedscreensink");
|
||||
enum {
|
||||
INIT_SINK = 0,
|
||||
RELEASE_SINK = 1,
|
||||
SUBSCRIBE_DISTRIBUTED_HARDWARE = 2,
|
||||
UNSUBSCRIBE_DISTRIBUTED_HARDWARE = 3,
|
||||
DSCREEN_NOTIFY = 4,
|
||||
};
|
||||
|
||||
IDScreenSink() = default;
|
||||
virtual ~IDScreenSink() = default;
|
||||
virtual int32_t InitSink(const std::string ¶ms) = 0;
|
||||
virtual int32_t ReleaseSink() = 0;
|
||||
virtual int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) = 0;
|
||||
virtual int32_t UnsubscribeLocalHardware(const std::string &dhId) = 0;
|
||||
virtual void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) = 0;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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 "dscreen_sink_handler.h"
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DScreenSinkHandler);
|
||||
|
||||
DScreenSinkHandler::DScreenSinkHandler()
|
||||
{
|
||||
DHLOGI("DScreenSinkHandler construct.");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!sinkSvrRecipient_) {
|
||||
sinkSvrRecipient_ = new DScreenSinkSvrRecipient();
|
||||
}
|
||||
}
|
||||
|
||||
DScreenSinkHandler::~DScreenSinkHandler()
|
||||
{
|
||||
DHLOGI("~DScreenSinkHandler.");
|
||||
}
|
||||
|
||||
int32_t DScreenSinkHandler::InitSink(const std::string ¶ms)
|
||||
{
|
||||
DHLOGD("InitSink");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (!dScreenSinkProxy_) {
|
||||
sptr<ISystemAbilityManager> samgr =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (!samgr) {
|
||||
DHLOGE("Failed to get system ability mgr.");
|
||||
return ERR_DH_SCREEN_SA_GET_SAMGR_FAIL;
|
||||
}
|
||||
sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID);
|
||||
if (!remoteObject) {
|
||||
DHLOGE("Failed to get dscreen sink service.");
|
||||
return ERR_DH_SCREEN_SA_GET_SINKSERVICE_FAIL;
|
||||
}
|
||||
|
||||
remoteObject->AddDeathRecipient(sinkSvrRecipient_);
|
||||
dScreenSinkProxy_ = iface_cast<IDScreenSink>(remoteObject);
|
||||
if ((!dScreenSinkProxy_) || (!dScreenSinkProxy_->AsObject())) {
|
||||
DHLOGE("Failed to get dscreen sink proxy.");
|
||||
return ERR_DH_SCREEN_SA_GET_SINKPROXY_FAIL;
|
||||
}
|
||||
}
|
||||
int32_t ret = dScreenSinkProxy_->InitSink(params);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkHandler::ReleaseSink()
|
||||
{
|
||||
DHLOGD("ReleaseSink");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!dScreenSinkProxy_) {
|
||||
DHLOGE("screen sink proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT;
|
||||
}
|
||||
|
||||
int32_t ret = dScreenSinkProxy_->ReleaseSink();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkHandler::SubscribeLocalHardware(const std::string &dhId, const std::string ¶m)
|
||||
{
|
||||
DHLOGD("SubscribeLocalHardware");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!dScreenSinkProxy_) {
|
||||
DHLOGE("screen sink proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT;
|
||||
}
|
||||
int32_t ret = dScreenSinkProxy_->SubscribeLocalHardware(dhId, param);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkHandler::UnsubscribeLocalHardware(const std::string &dhId)
|
||||
{
|
||||
DHLOGD("UnsubscribeLocalHardware");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!dScreenSinkProxy_) {
|
||||
DHLOGE("screen sink proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT;
|
||||
}
|
||||
int32_t ret = dScreenSinkProxy_->UnsubscribeLocalHardware(dhId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DScreenSinkHandler::DScreenSinkSvrRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
DHLOGI("DScreenSinkSvrRecipient OnRemoteDied.");
|
||||
DScreenSinkHandler::GetInstance().OnRemoteSinkSvrDied(remote);
|
||||
}
|
||||
|
||||
void DScreenSinkHandler::OnRemoteSinkSvrDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
DHLOGI("OnRemoteSinkSvrDied");
|
||||
sptr<IRemoteObject> remoteObject = remote.promote();
|
||||
if (!remoteObject) {
|
||||
DHLOGE("OnRemoteDied remote promoted failed");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!dScreenSinkProxy_) {
|
||||
dScreenSinkProxy_->AsObject()->RemoveDeathRecipient(sinkSvrRecipient_);
|
||||
dScreenSinkProxy_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
IDistributedHardwareSink *GetSinkHardwareHandler()
|
||||
{
|
||||
DHLOGD("GetSinkHardwareHandler");
|
||||
return &DScreenSinkHandler::GetInstance();
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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 "dscreen_sink_proxy.h"
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
int32_t DScreenSinkProxy::InitSink(const std::string ¶ms)
|
||||
{
|
||||
DHLOGD("InitSink");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
if (!data.WriteString(params)) {
|
||||
DHLOGE("Write param failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
|
||||
}
|
||||
|
||||
Remote()->SendRequest(INIT_SINK, data, reply, option);
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkProxy::ReleaseSink()
|
||||
{
|
||||
DHLOGD("ReleaseSink");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
Remote()->SendRequest(RELEASE_SINK, data, reply, option);
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkProxy::SubscribeLocalHardware(const std::string &dhId, const std::string ¶m)
|
||||
{
|
||||
DHLOGD("SubscribeLocalHardware");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
if (!data.WriteString(dhId) || !data.WriteString(param)) {
|
||||
DHLOGE("Write param failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
|
||||
}
|
||||
|
||||
Remote()->SendRequest(SUBSCRIBE_DISTRIBUTED_HARDWARE, data, reply, option);
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkProxy::UnsubscribeLocalHardware(const std::string &dhId)
|
||||
{
|
||||
DHLOGD("UnsubscribeLocalHardware");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
if (!data.WriteString(dhId)) {
|
||||
DHLOGE("Write param failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
|
||||
}
|
||||
|
||||
Remote()->SendRequest(UNSUBSCRIBE_DISTRIBUTED_HARDWARE, data, reply, option);
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DScreenSinkProxy::DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent)
|
||||
{
|
||||
DHLOGD("DScreenNotify");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteString(devId) || !data.WriteInt32(eventCode) || !data.WriteString(eventContent)) {
|
||||
DHLOGE("Write param failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
Remote()->SendRequest(DSCREEN_NOTIFY, data, reply, option);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,58 @@
|
||||
# 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("//build/ohos_var.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
ohos_shared_library("distributed_screen_source_sdk") {
|
||||
include_dirs = [
|
||||
"//utils/system/safwk/native/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"include",
|
||||
"include/callback",
|
||||
"${common_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/dscreen_source_handler.cpp",
|
||||
"src/dscreen_source_proxy.cpp",
|
||||
"src/callback/dscreen_source_callback_stub.cpp",
|
||||
"src/callback/dscreen_source_callback.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"${common_path}:distributed_screen_utils",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreensourcesdk\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SOURCE_CALLBACK_H
|
||||
#define OHOS_DSCREEN_SOURCE_CALLBACK_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "idistributed_hardware_source.h"
|
||||
|
||||
#include "dscreen_source_callback_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSourceCallback : public DScreenSourceCallbackStub {
|
||||
public:
|
||||
DScreenSourceCallback() = default;
|
||||
~DScreenSourceCallback();
|
||||
|
||||
int32_t OnNotifyRegResult(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId, int32_t status, const std::string &data) override;
|
||||
int32_t OnNotifyUnregResult(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId, int32_t status, const std::string &data) override;
|
||||
|
||||
void PushRegRegisterCallback(const std::string &reqId, const std::shared_ptr<RegisterCallback> &callback);
|
||||
void PopRegRegisterCallback(const std::string &reqId);
|
||||
void PushUnregisterCallback(const std::string &reqId, const std::shared_ptr<UnregisterCallback> &callback);
|
||||
void PopUnregisterCallback(const std::string &reqId);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::shared_ptr<RegisterCallback>> registerCallbackMap_;
|
||||
std::map<std::string, std::shared_ptr<UnregisterCallback>> unregisterCallbackMap_;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SOURCE_CALLBACK_STUB_H
|
||||
#define OHOS_DSCREEN_SOURCE_CALLBACK_STUB_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "iremote_stub.h"
|
||||
|
||||
#include "idscreen_source_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSourceCallbackStub : public IRemoteStub<IDScreenSourceCallback> {
|
||||
public:
|
||||
DScreenSourceCallbackStub();
|
||||
virtual ~DScreenSourceCallbackStub();
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option) override;
|
||||
private:
|
||||
using DScreenFunc = int32_t (DScreenSourceCallbackStub::*)(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
std::map<int32_t, DScreenFunc> memberFuncMap_;
|
||||
|
||||
int32_t OnNotifyRegResultInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
int32_t OnNotifyUnregResultInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 OHOS_IDSCREEN_SOURCE_CALLBACK_H
|
||||
#define OHOS_IDSCREEN_SOURCE_CALLBACK_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class IDScreenSourceCallback : public OHOS::IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.dscreensourcecallback");
|
||||
enum {
|
||||
NOTIFY_REG_RESULT = 0,
|
||||
NOTIFY_UNREG_RESULT,
|
||||
};
|
||||
|
||||
virtual ~IDScreenSourceCallback() {}
|
||||
virtual int32_t OnNotifyRegResult(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId, int32_t status, const std::string &data) = 0;
|
||||
virtual int32_t OnNotifyUnregResult(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId, int32_t status, const std::string &data) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SOURCE_HANDLER_H
|
||||
#define OHOS_DSCREEN_SOURCE_HANDLER_H
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "dscreen_source_callback.h"
|
||||
#include "idscreen_source.h"
|
||||
#include "idistributed_hardware_source.h"
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSourceHandler : public IDistributedHardwareSource {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DScreenSourceHandler);
|
||||
public:
|
||||
int32_t InitSource(const std::string ¶ms) override;
|
||||
int32_t ReleaseSource() override;
|
||||
int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const EnableParam ¶m, std::shared_ptr<RegisterCallback> callback) override;
|
||||
int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
std::shared_ptr<UnregisterCallback> callback) override;
|
||||
int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const std::string &key, const std::string &value) override;
|
||||
void OnRemoteSourceSvrDied(const wptr<IRemoteObject> &remote);
|
||||
private:
|
||||
class DScreenSourceSvrRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
|
||||
};
|
||||
|
||||
DScreenSourceHandler();
|
||||
~DScreenSourceHandler();
|
||||
|
||||
std::mutex mutex_;
|
||||
sptr<IDScreenSource> dScreenSourceProxy_ = nullptr;
|
||||
sptr<DScreenSourceCallback> dScreenSourceCallback_ = nullptr;
|
||||
sptr<DScreenSourceSvrRecipient> sourceSvrRecipient_ = nullptr;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
__attribute__((visibility("default"))) IDistributedHardwareSource *GetSourceHardwareHandler();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SOURCE_PROXY_H
|
||||
#define OHOS_DSCREEN_SOURCE_PROXY_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "idscreen_source.h"
|
||||
#include "idistributed_hardware_source.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSourceProxy : public IRemoteProxy<IDScreenSource> {
|
||||
public:
|
||||
explicit DScreenSourceProxy(const sptr<IRemoteObject> impl)
|
||||
: IRemoteProxy<IDScreenSource>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
~DScreenSourceProxy() {}
|
||||
int32_t InitSource(const std::string ¶ms, const sptr<IDScreenSourceCallback> &callback) override;
|
||||
int32_t ReleaseSource() override;
|
||||
int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const EnableParam ¶m, const std::string &reqId) override;
|
||||
int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId) override;
|
||||
int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const std::string &key, const std::string &value) override;
|
||||
void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<DScreenSourceProxy> delegator_;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 OHOS_IDSCREEN_SOURCE_H
|
||||
#define OHOS_IDSCREEN_SOURCE_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
#include "idscreen_source_callback.h"
|
||||
#include "idistributed_hardware_source.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class IDScreenSource : public OHOS::IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.distributedscreensource");
|
||||
enum {
|
||||
INIT_SOURCE = 0,
|
||||
RELEASE_SOURCE,
|
||||
REGISTER_DISTRIBUTED_HARDWARE,
|
||||
UNREGISTER_DISTRIBUTED_HARDWARE,
|
||||
CONFIG_DISTRIBUTED_HARDWARE,
|
||||
DSCREEN_NOTIFY,
|
||||
};
|
||||
|
||||
virtual ~IDScreenSource() {}
|
||||
virtual int32_t InitSource(const std::string ¶ms, const sptr<IDScreenSourceCallback> &callback) = 0;
|
||||
virtual int32_t ReleaseSource() = 0;
|
||||
virtual int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const EnableParam ¶m, const std::string &reqId) = 0;
|
||||
virtual int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId) = 0;
|
||||
virtual int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const std::string &key, const std::string &value) = 0;
|
||||
virtual void DScreenNotify(const std::string &devId, int32_t eventCode,
|
||||
const std::string &eventContent) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 "dscreen_source_callback.h"
|
||||
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
DScreenSourceCallback::~DScreenSourceCallback() {}
|
||||
|
||||
int32_t DScreenSourceCallback::OnNotifyRegResult(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId, int32_t status, const std::string &data)
|
||||
{
|
||||
DHLOGD("OnNotifyRegResult");
|
||||
auto iter = registerCallbackMap_.find(reqId);
|
||||
if (iter != registerCallbackMap_.end()) {
|
||||
iter->second->OnRegisterResult(devId, dhId, status, data);
|
||||
registerCallbackMap_.erase(reqId);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
return ERR_DH_SCREEN_SA_REGISTERCALLBACK_NOT_FOUND;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceCallback::OnNotifyUnregResult(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId, int32_t status, const std::string &data)
|
||||
{
|
||||
DHLOGD("OnNotifyUnregResult");
|
||||
auto iter = unregisterCallbackMap_.find(reqId);
|
||||
if (iter != unregisterCallbackMap_.end()) {
|
||||
iter->second->OnUnregisterResult(devId, dhId, status, data);
|
||||
unregisterCallbackMap_.erase(reqId);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
return ERR_DH_SCREEN_SA_UNREGISTERCALLBACK_NOT_FOUND;
|
||||
}
|
||||
|
||||
void DScreenSourceCallback::PushRegRegisterCallback(const std::string &reqId,
|
||||
const std::shared_ptr<RegisterCallback> &callback)
|
||||
{
|
||||
DHLOGD("PushRegRegisterCallback");
|
||||
registerCallbackMap_.emplace(reqId, callback);
|
||||
}
|
||||
|
||||
void DScreenSourceCallback::PopRegRegisterCallback(const std::string &reqId)
|
||||
{
|
||||
DHLOGD("PopRegRegisterCallback");
|
||||
registerCallbackMap_.erase(reqId);
|
||||
}
|
||||
|
||||
void DScreenSourceCallback::PushUnregisterCallback(const std::string &reqId,
|
||||
const std::shared_ptr<UnregisterCallback> &callback)
|
||||
{
|
||||
DHLOGD("PushUnregisterCallback");
|
||||
unregisterCallbackMap_.emplace(reqId, callback);
|
||||
}
|
||||
|
||||
void DScreenSourceCallback::PopUnregisterCallback(const std::string &reqId)
|
||||
{
|
||||
DHLOGD("PopUnregisterCallback");
|
||||
unregisterCallbackMap_.erase(reqId);
|
||||
}
|
||||
}
|
||||
}
|
||||
+69
@@ -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.
|
||||
*/
|
||||
|
||||
#include "dscreen_source_callback_stub.h"
|
||||
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
DScreenSourceCallbackStub::DScreenSourceCallbackStub()
|
||||
{
|
||||
memberFuncMap_[NOTIFY_REG_RESULT] = &DScreenSourceCallbackStub::OnNotifyRegResultInner;
|
||||
memberFuncMap_[NOTIFY_UNREG_RESULT] = &DScreenSourceCallbackStub::OnNotifyUnregResultInner;
|
||||
}
|
||||
|
||||
DScreenSourceCallbackStub::~DScreenSourceCallbackStub()
|
||||
{
|
||||
}
|
||||
|
||||
int32_t DScreenSourceCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
std::map<int32_t, DScreenFunc>::iterator iter = memberFuncMap_.find(code);
|
||||
if (iter == memberFuncMap_.end()) {
|
||||
DHLOGE("invalid request code.");
|
||||
return ERR_DH_SCREEN_SA_REQUEST_CODE_INVALID;
|
||||
}
|
||||
DScreenFunc &func = iter->second;
|
||||
return (this->*func)(data, reply, option);
|
||||
}
|
||||
|
||||
int32_t DScreenSourceCallbackStub::OnNotifyRegResultInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
std::string devId = data.ReadString();
|
||||
std::string dhId = data.ReadString();
|
||||
std::string reqId = data.ReadString();
|
||||
int32_t status = data.ReadInt32();
|
||||
std::string resultData = data.ReadString();
|
||||
int32_t ret = OnNotifyRegResult(devId, dhId, reqId, status, resultData);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceCallbackStub::OnNotifyUnregResultInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
std::string devId = data.ReadString();
|
||||
std::string dhId = data.ReadString();
|
||||
std::string reqId = data.ReadString();
|
||||
int32_t status = data.ReadInt32();
|
||||
std::string resultData = data.ReadString();
|
||||
int32_t ret = OnNotifyRegResult(devId, dhId, reqId, status, resultData);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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 "dscreen_source_handler.h"
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DScreenSourceHandler);
|
||||
|
||||
DScreenSourceHandler::DScreenSourceHandler()
|
||||
{
|
||||
DHLOGI("DScreenSourceHandler construct.");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!sourceSvrRecipient_) {
|
||||
sourceSvrRecipient_ = new DScreenSourceSvrRecipient();
|
||||
}
|
||||
|
||||
if (!dScreenSourceCallback_) {
|
||||
dScreenSourceCallback_ = new DScreenSourceCallback();
|
||||
}
|
||||
}
|
||||
|
||||
DScreenSourceHandler::~DScreenSourceHandler()
|
||||
{
|
||||
DHLOGI("~DScreenSourceHandler.");
|
||||
}
|
||||
|
||||
int32_t DScreenSourceHandler::InitSource(const std::string ¶ms)
|
||||
{
|
||||
DHLOGD("InitSource");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (!dScreenSourceProxy_) {
|
||||
sptr<ISystemAbilityManager> samgr =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (!samgr) {
|
||||
DHLOGE("Failed to get system ability mgr.");
|
||||
return ERR_DH_SCREEN_SA_GET_SAMGR_FAIL;
|
||||
}
|
||||
sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID);
|
||||
if (!remoteObject) {
|
||||
DHLOGE("Failed to get dscreen source service.");
|
||||
return ERR_DH_SCREEN_SA_GET_SOURCESERVICE_FAIL;
|
||||
}
|
||||
|
||||
remoteObject->AddDeathRecipient(sourceSvrRecipient_);
|
||||
dScreenSourceProxy_ = iface_cast<IDScreenSource>(remoteObject);
|
||||
if ((!dScreenSourceProxy_) || (!dScreenSourceProxy_->AsObject())) {
|
||||
DHLOGE("Failed to get dscreen source proxy.");
|
||||
return ERR_DH_SCREEN_SA_GET_SOURCEPROXY_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ret = dScreenSourceProxy_->InitSource(params, dScreenSourceCallback_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceHandler::ReleaseSource()
|
||||
{
|
||||
DHLOGD("ReleaseSource");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!dScreenSourceProxy_) {
|
||||
DHLOGE("screen source proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT;
|
||||
}
|
||||
int32_t ret = dScreenSourceProxy_->ReleaseSource();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceHandler::RegisterDistributedHardware(const std::string &devId,
|
||||
const std::string &dhId, const EnableParam ¶m, std::shared_ptr<RegisterCallback> callback)
|
||||
{
|
||||
DHLOGD("RegisterDistributedHardware, devId: %s, dhId: %s", GetAnonyString(devId).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!dScreenSourceProxy_) {
|
||||
DHLOGE("screen source proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT;
|
||||
}
|
||||
if (!dScreenSourceCallback_) {
|
||||
DHLOGE("screen source callback is null.");
|
||||
return ERR_DH_SCREEN_SA_SOURCEPCALLBACK_NOT_INIT;
|
||||
}
|
||||
|
||||
std::string reqId = GetRandomID();
|
||||
dScreenSourceCallback_->PushRegRegisterCallback(reqId, callback);
|
||||
int ret = dScreenSourceProxy_->RegisterDistributedHardware(devId, dhId, param, reqId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceHandler::UnregisterDistributedHardware(const std::string &devId,
|
||||
const std::string &dhId, std::shared_ptr<UnregisterCallback> callback)
|
||||
{
|
||||
DHLOGD("UnregisterDistributedHardware, devId: %s, dhId: %s", GetAnonyString(devId).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!dScreenSourceProxy_) {
|
||||
DHLOGE("screen source proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT;
|
||||
}
|
||||
if (!dScreenSourceCallback_) {
|
||||
DHLOGE("screen source callback is null.");
|
||||
return ERR_DH_SCREEN_SA_SOURCEPCALLBACK_NOT_INIT;
|
||||
}
|
||||
|
||||
std::string reqId = GetRandomID();
|
||||
dScreenSourceCallback_->PushUnregisterCallback(reqId, callback);
|
||||
int ret = dScreenSourceProxy_->UnregisterDistributedHardware(devId, dhId, reqId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceHandler::ConfigDistributedHardware(const std::string &devId,
|
||||
const std::string &dhId, const std::string &key, const std::string &value)
|
||||
{
|
||||
DHLOGD("ConfigDistributedHardware");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DScreenSourceHandler::DScreenSourceSvrRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
DHLOGI("DScreenSourceSvrRecipient OnRemoteDied");
|
||||
DScreenSourceHandler::GetInstance().OnRemoteSourceSvrDied(remote);
|
||||
}
|
||||
|
||||
void DScreenSourceHandler::OnRemoteSourceSvrDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
DHLOGI("OnRemoteSourceSvrDied");
|
||||
sptr<IRemoteObject> remoteObject = remote.promote();
|
||||
if (!remoteObject) {
|
||||
DHLOGE("OnRemoteDied remote promoted failed");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!dScreenSourceProxy_) {
|
||||
dScreenSourceProxy_->AsObject()->RemoveDeathRecipient(sourceSvrRecipient_);
|
||||
dScreenSourceProxy_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
IDistributedHardwareSource *GetSourceHardwareHandler()
|
||||
{
|
||||
DHLOGD("GetSourceHardwareHandler");
|
||||
return &DScreenSourceHandler::GetInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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 "dscreen_source_proxy.h"
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
int32_t DScreenSourceProxy::InitSource(const std::string ¶ms, const sptr<IDScreenSourceCallback> &callback)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
if (!data.WriteString(params)
|
||||
|| !data.WriteRemoteObject(callback->AsObject())) {
|
||||
DHLOGE("Write param failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
|
||||
}
|
||||
|
||||
Remote()->SendRequest(INIT_SOURCE, data, reply, option);
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceProxy::ReleaseSource()
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
Remote()->SendRequest(RELEASE_SOURCE, data, reply, option);
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceProxy::RegisterDistributedHardware(const std::string &devId,
|
||||
const std::string &dhId, const EnableParam ¶m, const std::string &reqId)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
if (!data.WriteString(devId) || !data.WriteString(dhId)
|
||||
|| !data.WriteString(param.version) || !data.WriteString(param.attrs)
|
||||
|| !data.WriteString(reqId)) {
|
||||
DHLOGE("Write param failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
|
||||
}
|
||||
Remote()->SendRequest(REGISTER_DISTRIBUTED_HARDWARE, data, reply, option);
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceProxy::UnregisterDistributedHardware(const std::string &devId,
|
||||
const std::string &dhId, const std::string &reqId)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
if (!data.WriteString(devId) || !data.WriteString(dhId)
|
||||
|| !data.WriteString(reqId)) {
|
||||
DHLOGE("Write param failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
|
||||
}
|
||||
Remote()->SendRequest(UNREGISTER_DISTRIBUTED_HARDWARE, data, reply, option);
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceProxy::ConfigDistributedHardware(const std::string &devId,
|
||||
const std::string &dhId, const std::string &key, const std::string &value)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
if (!data.WriteString(devId) || !data.WriteString(dhId)
|
||||
|| !data.WriteString(key) || !data.WriteString(value)) {
|
||||
DHLOGE("Write param failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
|
||||
}
|
||||
Remote()->SendRequest(CONFIG_DISTRIBUTED_HARDWARE, data, reply, option);
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DScreenSourceProxy::DScreenNotify(const std::string &devId,
|
||||
int32_t eventCode, const std::string &eventContent)
|
||||
{
|
||||
DHLOGD("DScreenNotify");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteString(devId) || !data.WriteInt32(eventCode) || !data.WriteString(eventContent)) {
|
||||
DHLOGE("Write param failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
Remote()->SendRequest(DSCREEN_NOTIFY, data, reply, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
* 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.
|
||||
-->
|
||||
<info>
|
||||
<process>dhardware</process>
|
||||
<systemability> <!-- Declare a sytem ability and its profile -->
|
||||
<name>4807</name> <!-- Declare the name of system ability -->
|
||||
<libpath>libdistributed_screen_source.z.so</libpath> <!-- Declare the path of .so file which includes the system ability; Note: 1 .so file can have 1 to N system abilities. -->
|
||||
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on, using ";" as separator among names. If there are dependencies, it needs to check if all those dependencies are avliable in service manager before starting the system ability. -->
|
||||
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are avaliable before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
|
||||
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
|
||||
<distributed>true</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not. -->
|
||||
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
|
||||
</systemability>
|
||||
</info>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
* 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.
|
||||
-->
|
||||
<info>
|
||||
<process>dhardware</process>
|
||||
<systemability> <!-- Declare a sytem ability and its profile -->
|
||||
<name>4808</name> <!-- Declare the name of system ability -->
|
||||
<libpath>libdistributed_screen_sink.z.so</libpath> <!-- Declare the path of .so file which includes the system ability; Note: 1 .so file can have 1 to N system abilities. -->
|
||||
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on, using ";" as separator among names. If there are dependencies, it needs to check if all those dependencies are avliable in service manager before starting the system ability. -->
|
||||
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are avaliable before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
|
||||
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
|
||||
<distributed>true</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not. -->
|
||||
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
|
||||
</systemability>
|
||||
</info>
|
||||
@@ -0,0 +1,23 @@
|
||||
# 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/sa_profile/sa_profile.gni")
|
||||
|
||||
ohos_sa_profile("dscreen_sa_profile") {
|
||||
sources = [
|
||||
"4807.xml",
|
||||
"4808.xml",
|
||||
]
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
# 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("//build/ohos_var.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
ohos_shared_library("distributed_screen_handler") {
|
||||
include_dirs = [
|
||||
"//third_party/json/include",
|
||||
"${windowmanager_path}/interfaces/innerkits/dm",
|
||||
"${mediastandard_path}/interfaces/innerkits/native/media/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"include",
|
||||
"${common_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/dscreen_handler.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"${mediastandard_path}/interfaces/innerkits/native/media:media_client",
|
||||
"${windowmanager_path}/interfaces/innerkits:wm_interface",
|
||||
"${windowmanager_path}/dm:libdm",
|
||||
"${common_path}:distributed_screen_utils",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreenhandler\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_HANDLER_H
|
||||
#define OHOS_DSCREEN_HANDLER_H
|
||||
|
||||
#include "screen_manager.h"
|
||||
|
||||
#include "ihardware_handler.h"
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenHandler : public IHardwareHandler, public Rosen::ScreenManager::IScreenListener {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DScreenHandler);
|
||||
public:
|
||||
void OnConnect(uint64_t screenId) override;
|
||||
void OnDisconnect(uint64_t screenId) override;
|
||||
void OnChange(uint64_t screenId) override {};
|
||||
int32_t Initialize() override;
|
||||
std::vector<DHItem> Query() override;
|
||||
std::map<std::string, std::string> QueryExtraInfo() override;
|
||||
bool IsSupportPlugin() override;
|
||||
void RegisterPluginListener(std::shared_ptr<PluginListener> listener) override;
|
||||
|
||||
private:
|
||||
DScreenHandler();
|
||||
~DScreenHandler();
|
||||
std::string QueryCodecInfo();
|
||||
|
||||
std::shared_ptr<PluginListener> listener_ = nullptr;
|
||||
std::string codecInfoStr_;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
__attribute__((visibility("default"))) IHardwareHandler* GetHardwareHandler();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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 "dscreen_handler.h"
|
||||
|
||||
#include "avcodec_info.h"
|
||||
#include "avcodec_list.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "screen.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_util.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DScreenHandler);
|
||||
|
||||
DScreenHandler::DScreenHandler()
|
||||
{
|
||||
DHLOGI("DScreenHandler constructor.");
|
||||
}
|
||||
|
||||
DScreenHandler::~DScreenHandler()
|
||||
{
|
||||
DHLOGI("~DScreenHandler");
|
||||
}
|
||||
|
||||
int32_t DScreenHandler::Initialize()
|
||||
{
|
||||
DHLOGI("DScreenHandler Initialize");
|
||||
bool ret = Rosen::ScreenManager::GetInstance().RegisterScreenListener(this);
|
||||
if (!ret) {
|
||||
DHLOGE("register screen listener failed.");
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DScreenHandler::OnConnect(uint64_t screenId)
|
||||
{
|
||||
DHLOGI("on screen connect");
|
||||
if (screenId != SCREEN_ID_DEFAULT) {
|
||||
return;
|
||||
}
|
||||
std::string dhId = DSCREEN_PREFIX + SEPERATOR + std::to_string(screenId);
|
||||
sptr<Rosen::Screen> screen = Rosen::ScreenManager::GetInstance().GetScreenById(screenId);
|
||||
uint32_t screenWidth = screen->GetWidth();
|
||||
uint32_t screenHeight = screen->GetHeight();
|
||||
|
||||
json attrJson;
|
||||
attrJson[KEY_VERSION] = DSCREEN_VERSION;
|
||||
attrJson[KEY_SCREEN_WIDTH] = screenWidth;
|
||||
attrJson[KEY_SCREEN_HEIGHT] = screenHeight;
|
||||
attrJson[KEY_CODECTYPE] = QueryCodecInfo();
|
||||
|
||||
if (listener_ != nullptr) {
|
||||
listener_->PluginHardware(dhId, attrJson.dump());
|
||||
}
|
||||
}
|
||||
|
||||
void DScreenHandler::OnDisconnect(uint64_t screenId)
|
||||
{
|
||||
DHLOGI("on screen disconnect");
|
||||
std::string dhId = DSCREEN_PREFIX + SEPERATOR + std::to_string(screenId);
|
||||
if (listener_ != nullptr) {
|
||||
listener_->UnPluginHardware(dhId);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DHItem> DScreenHandler::Query()
|
||||
{
|
||||
DHLOGI("DScreenHandler query hardware info");
|
||||
std::vector<DHItem> dhItemVec;
|
||||
std::vector<sptr<Rosen::Screen>> screens = Rosen::ScreenManager::GetInstance().GetAllScreens();
|
||||
sptr<Rosen::Screen> screen = screens[SCREEN_ID_DEFAULT];
|
||||
std::string dhId = SCREEN_PREFIX + SEPERATOR + std::to_string(screen->GetId());
|
||||
uint32_t screenWidth = screen->GetWidth();
|
||||
uint32_t screenHeight = screen->GetHeight();
|
||||
|
||||
json attrJson;
|
||||
attrJson[KEY_VERSION] = DSCREEN_VERSION;
|
||||
attrJson[KEY_SCREEN_WIDTH] = screenWidth;
|
||||
attrJson[KEY_SCREEN_HEIGHT] = screenHeight;
|
||||
attrJson[KEY_CODECTYPE] = QueryCodecInfo();
|
||||
|
||||
DHItem dhItem;
|
||||
dhItem.dhId = dhId;
|
||||
dhItem.attrs = attrJson.dump();
|
||||
dhItemVec.push_back(dhItem);
|
||||
DHLOGD("query result: dhId: %s, attrs: %s", GetAnonyString(dhId).c_str(), attrJson.dump().c_str());
|
||||
|
||||
return dhItemVec;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> DScreenHandler::QueryExtraInfo()
|
||||
{
|
||||
DHLOGD("DScreenHandler queryExtraInfo");
|
||||
std::map<std::string, std::string> extraInfo;
|
||||
return extraInfo;
|
||||
}
|
||||
|
||||
bool DScreenHandler::IsSupportPlugin()
|
||||
{
|
||||
DHLOGD("DScreenHandler IsSupportPlugin");
|
||||
return true;
|
||||
}
|
||||
|
||||
void DScreenHandler::RegisterPluginListener(std::shared_ptr<PluginListener> listener)
|
||||
{
|
||||
DHLOGD("DScreenHandler register plugin listener");
|
||||
listener_ = listener;
|
||||
}
|
||||
|
||||
std::string DScreenHandler::QueryCodecInfo()
|
||||
{
|
||||
DHLOGD("DScreenHandler QueryCodecInfo");
|
||||
if (!codecInfoStr_.empty()) {
|
||||
return codecInfoStr_;
|
||||
}
|
||||
|
||||
// query codec info
|
||||
std::shared_ptr<Media::AVCodecList> codecList = Media::AVCodecListFactory::CreateAVCodecList();
|
||||
std::vector<std::shared_ptr<Media::VideoCaps>> caps = codecList->GetVideoEncoderCaps();
|
||||
for (const auto &cap : caps) {
|
||||
std::shared_ptr<Media::AVCodecInfo> codecInfo = cap->GetCodecInfo();
|
||||
codecInfoStr_.append(codecInfo->GetName());
|
||||
codecInfoStr_.append(SEPERATOR);
|
||||
}
|
||||
return codecInfoStr_;
|
||||
}
|
||||
|
||||
IHardwareHandler* GetHardwareHandler()
|
||||
{
|
||||
return &DScreenHandler::GetInstance();
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 OHOS_DATA_BUFFER_H
|
||||
#define OHOS_DATA_BUFFER_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DataBuffer {
|
||||
public:
|
||||
explicit DataBuffer(size_t capacity);
|
||||
~DataBuffer();
|
||||
|
||||
size_t Capacity() const;
|
||||
uint8_t *Data() const;
|
||||
|
||||
private:
|
||||
size_t capacity_ = 0;
|
||||
uint8_t *data_ = nullptr;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 "data_buffer.h"
|
||||
|
||||
#include <new>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
DataBuffer::DataBuffer(size_t capacity)
|
||||
{
|
||||
if (capacity != 0) {
|
||||
data_ = new (std::nothrow) uint8_t[capacity] {0};
|
||||
if (data_ != nullptr) {
|
||||
capacity_ = capacity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DataBuffer::~DataBuffer()
|
||||
{
|
||||
if (data_ != nullptr) {
|
||||
delete []data_;
|
||||
data_ = nullptr;
|
||||
}
|
||||
|
||||
capacity_ = 0;
|
||||
}
|
||||
|
||||
size_t DataBuffer::Capacity() const
|
||||
{
|
||||
return capacity_;
|
||||
}
|
||||
|
||||
uint8_t *DataBuffer::Data() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespcae OHOS
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 OHOS_ISCREEN_CHANNEL_H
|
||||
#define OHOS_ISCREEN_CHANNEL_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "data_buffer.h"
|
||||
#include "iscreen_channel_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class IScreenChannel {
|
||||
public:
|
||||
virtual ~IScreenChannel() = default;
|
||||
|
||||
virtual int32_t CreateSession(const std::shared_ptr<IScreenChannelListener> &listener) = 0;
|
||||
virtual int32_t ReleaseSession() = 0;
|
||||
virtual int32_t OpenSession() = 0;
|
||||
virtual int32_t CloseSession() = 0;
|
||||
virtual int32_t SendData(const std::shared_ptr<DataBuffer> &data) = 0;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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 OHOS_ISCREEN_CHANNEL_LISTENER_H
|
||||
#define OHOS_ISCREEN_CHANNEL_LISTENER_H
|
||||
|
||||
#include "data_buffer.h"
|
||||
#include <memory>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class IScreenChannelListener {
|
||||
public:
|
||||
virtual ~IScreenChannelListener() = default;
|
||||
|
||||
virtual void OnSessionOpened() = 0;
|
||||
virtual void OnSessionClosed() = 0;
|
||||
virtual void OnDataReceived(const std::shared_ptr<DataBuffer> &data) = 0;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
# 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.
|
||||
|
||||
group("service_common_test") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"databuffer:data_buffer_test",
|
||||
"utils:utils_test",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
# 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/test.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
module_out_path = "distributed_screen/services/data_buffer_test"
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"${windowmanager_path}/interfaces/innerkits/wm",
|
||||
"${graphicstandard_path}/interfaces/innerkits/surface",
|
||||
"${graphicstandard_path}/rosen/modules/render_service_client/core/ui",
|
||||
"${fwk_common_path}/utils/include",
|
||||
"${fwk_common_path}/log/include",
|
||||
"${fwk_utils_path}/include/log",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"include",
|
||||
"${common_path}/include",
|
||||
"${services_path}/common/databuffer/include",
|
||||
"${services_path}/common/utils/include",
|
||||
]
|
||||
}
|
||||
|
||||
## UnitTest data_buffer_test
|
||||
ohos_unittest("DataBufferTest") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/common/test/unittest/databuffer/data_buffer_test.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${graphicstandard_path}/frameworks/surface:surface",
|
||||
"${graphicstandard_path}/rosen/modules/render_service_client:librender_service_client",
|
||||
"${windowmanager_path}/interfaces/innerkits:wm_interface",
|
||||
"${windowmanager_path}/wm:libwm",
|
||||
"//foundation/distributedhardware/distributedscreen/services/screentransport/screensinktrans:distributed_screen_sinktrans",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
}
|
||||
|
||||
group("data_buffer_test") {
|
||||
testonly = true
|
||||
deps = [ ":DataBufferTest" ]
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define private public
|
||||
#include "data_buffer_test.h"
|
||||
#undef private
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
void DataBufferTest::SetUpTestCase(void) {}
|
||||
|
||||
void DataBufferTest::TearDownTestCase(void) {}
|
||||
|
||||
void DataBufferTest::SetUp()
|
||||
{
|
||||
dataBuffer_ = std::make_shared<DataBuffer>(capacity);
|
||||
}
|
||||
|
||||
void DataBufferTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: Capacity_001
|
||||
* @tc.desc: Verify the Capacity function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(DataBufferTest, Capacity_001, TestSize.Level1)
|
||||
{
|
||||
size_t actual = dataBuffer_->Capacity();
|
||||
EXPECT_EQ(capacity, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Data_001
|
||||
* @tc.desc: Verify the Data function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(DataBufferTest, Data_001, TestSize.Level1)
|
||||
{
|
||||
uint8_t *actual = dataBuffer_->Data();
|
||||
EXPECT_NE(nullptr, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
#include <new>
|
||||
|
||||
#include "data_buffer.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DataBufferTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
size_t capacity = 1;
|
||||
std::shared_ptr<DataBuffer> dataBuffer_ = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
# 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/test.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
module_out_path = "distributed_screen/services/utils_test"
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"//third_party/json/include",
|
||||
"${windowmanager_path}/interfaces/innerkits/wm",
|
||||
"${graphicstandard_path}/interfaces/innerkits/surface",
|
||||
"${graphicstandard_path}/rosen/modules/render_service_client/core/ui",
|
||||
"${fwk_common_path}/utils/include",
|
||||
"${fwk_common_path}/log/include",
|
||||
"${fwk_utils_path}/include/log",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"include",
|
||||
"${common_path}/include",
|
||||
"${services_path}/common/databuffer/include",
|
||||
"${services_path}/common/utils/include",
|
||||
]
|
||||
}
|
||||
|
||||
## UnitTest utils_test
|
||||
ohos_unittest("UtilsTest") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/common/test/unittest/utils/video_param_test.cpp",
|
||||
"${services_path}/common/test/unittest/utils/dscreen_maprelation_test.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${graphicstandard_path}/frameworks/surface:surface",
|
||||
"${graphicstandard_path}/rosen/modules/render_service_client:librender_service_client",
|
||||
"${windowmanager_path}/interfaces/innerkits:wm_interface",
|
||||
"${windowmanager_path}/wm:libwm",
|
||||
"//foundation/distributedhardware/distributedscreen/services/screenservice/sinkservice:distributed_screen_sink",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
}
|
||||
|
||||
group("utils_test") {
|
||||
testonly = true
|
||||
deps = [ ":UtilsTest" ]
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define private public
|
||||
#include "dscreen_maprelation_test.h"
|
||||
#undef private
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
void DScreenMapRelationTest::SetUpTestCase(void) {}
|
||||
|
||||
void DScreenMapRelationTest::TearDownTestCase(void) {}
|
||||
|
||||
void DScreenMapRelationTest::SetUp()
|
||||
{
|
||||
dscreenMapRelation = std::make_shared<DScreenMapRelation>();
|
||||
}
|
||||
|
||||
void DScreenMapRelationTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDisplayId_001
|
||||
* @tc.desc: Verify the GetDisplayId function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(DScreenMapRelationTest, GetDisplayId_001, TestSize.Level1)
|
||||
{
|
||||
uint64_t displayId = 0;
|
||||
dscreenMapRelation->SetDisplayId(displayId);
|
||||
uint64_t actual = dscreenMapRelation->GetDisplayId();
|
||||
EXPECT_EQ(displayId, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetScreenId_001
|
||||
* @tc.desc: Verify the GetScreenId function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(DScreenMapRelationTest, GetScreenId_001, TestSize.Level1)
|
||||
{
|
||||
uint64_t screenId = 0;
|
||||
dscreenMapRelation->SetScreenId(screenId);
|
||||
uint64_t actual = dscreenMapRelation->GetScreenId();
|
||||
EXPECT_EQ(screenId, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDisplayRect_001
|
||||
* @tc.desc: Verify the GetDisplayRect function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(DScreenMapRelationTest, GetDisplayRect_001, TestSize.Level1)
|
||||
{
|
||||
DisplayRect res;
|
||||
int32_t startX = 10;
|
||||
res.startX = startX;
|
||||
dscreenMapRelation->SetDisplayRect(res);
|
||||
DisplayRect actual = dscreenMapRelation->GetDisplayRect();
|
||||
EXPECT_EQ(startX, actual.startX);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetScreenRect_001
|
||||
* @tc.desc: Verify the GetScreenRect function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(DScreenMapRelationTest, GetScreenRect_001, TestSize.Level1)
|
||||
{
|
||||
ScreenRect res;
|
||||
int32_t startX = 10;
|
||||
res.startX = startX;
|
||||
dscreenMapRelation->SetScreenRect(res);
|
||||
ScreenRect actual = dscreenMapRelation->GetScreenRect();
|
||||
EXPECT_EQ(startX, actual.startX);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_maprelation.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenMapRelationTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
std::shared_ptr<DScreenMapRelation> dscreenMapRelation = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define private public
|
||||
#include "video_param_test.h"
|
||||
#undef private
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
void VideoParamTest::SetUpTestCase(void) {}
|
||||
|
||||
void VideoParamTest::TearDownTestCase(void) {}
|
||||
|
||||
void VideoParamTest::SetUp()
|
||||
{
|
||||
videoParam_ = std::make_shared<VideoParam>();
|
||||
}
|
||||
|
||||
void VideoParamTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: GetScreenWidth_001
|
||||
* @tc.desc: Verify the GetScreenWidth function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(VideoParamTest, GetScreenWidth_001, TestSize.Level1)
|
||||
{
|
||||
uint32_t screenWidth = 1;
|
||||
videoParam_->SetScreenWidth(screenWidth);
|
||||
uint32_t actual = videoParam_->GetScreenWidth();
|
||||
EXPECT_EQ(screenWidth, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetScreenHeight_001
|
||||
* @tc.desc: Verify the GetScreenHeight function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(VideoParamTest, GetScreenHeight_001, TestSize.Level1)
|
||||
{
|
||||
uint32_t screenHeight = 1;
|
||||
videoParam_->SetScreenHeight(screenHeight);
|
||||
uint32_t actual = videoParam_->GetScreenHeight();
|
||||
EXPECT_EQ(screenHeight, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetVideoWidth_001
|
||||
* @tc.desc: Verify the GetVideoWidth function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(VideoParamTest, GetVideoWidth_001, TestSize.Level1)
|
||||
{
|
||||
uint32_t videoWidth = 1;
|
||||
videoParam_->SetVideoWidth(videoWidth);
|
||||
uint32_t actual = videoParam_->GetVideoWidth();
|
||||
EXPECT_EQ(videoWidth, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetVideoHeight_001
|
||||
* @tc.desc: Verify the GetVideoHeight function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(VideoParamTest, GetVideoHeight_001, TestSize.Level1)
|
||||
{
|
||||
uint32_t videoHeight = 1;
|
||||
videoParam_->SetVideoHeight(videoHeight);
|
||||
uint32_t actual = videoParam_->GetVideoHeight();
|
||||
EXPECT_EQ(videoHeight, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetFps_001
|
||||
* @tc.desc: Verify the GetFps function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(VideoParamTest, GetFps_001, TestSize.Level1)
|
||||
{
|
||||
uint32_t fps = 1;
|
||||
videoParam_->SetFps(fps);
|
||||
uint32_t actual = videoParam_->GetFps();
|
||||
EXPECT_EQ(fps, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetCodecType_001
|
||||
* @tc.desc: Verify the GetCodecType function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(VideoParamTest, GetCodecType_001, TestSize.Level1)
|
||||
{
|
||||
uint8_t codecType = 1;
|
||||
videoParam_->SetCodecType(codecType);
|
||||
uint8_t actual = videoParam_->GetCodecType();
|
||||
EXPECT_EQ(codecType, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetVideoFormat_001
|
||||
* @tc.desc: Verify the GetVideoFormat function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(VideoParamTest, GetVideoFormat_001, TestSize.Level1)
|
||||
{
|
||||
uint8_t videoFormat = 1;
|
||||
videoParam_->SetVideoFormat(videoFormat);
|
||||
uint8_t actual = videoParam_->GetVideoFormat();
|
||||
EXPECT_EQ(videoFormat, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "video_param.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class VideoParamTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
std::shared_ptr<VideoParam> videoParam_ = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_MAP_RELATION_H
|
||||
#define OHOS_DSCREEN_MAP_RELATION_H
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
struct ScreenRect {
|
||||
int32_t startX;
|
||||
int32_t startY;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
};
|
||||
struct DisplayRect {
|
||||
int32_t startX;
|
||||
int32_t startY;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
};
|
||||
|
||||
class DScreenMapRelation {
|
||||
public:
|
||||
void SetDisplayId(uint64_t displayId);
|
||||
uint64_t GetDisplayId() const;
|
||||
void SetScreenId(uint64_t screenId);
|
||||
uint64_t GetScreenId() const;
|
||||
void SetDisplayRect(const DisplayRect &displayRect);
|
||||
DisplayRect& GetDisplayRect();
|
||||
void SetScreenRect(const ScreenRect &screenRect);
|
||||
ScreenRect& GetScreenRect();
|
||||
private:
|
||||
friend void to_json(json &j, const DScreenMapRelation &dScreenMapRelation);
|
||||
friend void from_json(const json &j, DScreenMapRelation &dScreenMapRelation);
|
||||
|
||||
uint64_t displayId_;
|
||||
uint64_t screenId_;
|
||||
DisplayRect displayRect_;
|
||||
ScreenRect screenRect_;
|
||||
};
|
||||
void to_json(const json &j, const DScreenMapRelation &dScreenMapRelation);
|
||||
void from_json(const json &j, DScreenMapRelation &dScreenMapRelation);
|
||||
void to_json(json &j, const DisplayRect &rect);
|
||||
void to_json(json &j, const ScreenRect &rect);
|
||||
void from_json(const json &j, DisplayRect &rect);
|
||||
void from_json(const json &j, ScreenRect &rect);
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_VIDEO_PARAM_H
|
||||
#define OHOS_DSCREEN_VIDEO_PARAM_H
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class VideoParam {
|
||||
public:
|
||||
void SetScreenWidth(uint32_t screenWidth);
|
||||
uint32_t GetScreenWidth() const;
|
||||
void SetScreenHeight(uint32_t screenHeight);
|
||||
uint32_t GetScreenHeight() const;
|
||||
void SetVideoWidth(uint32_t videoWidth);
|
||||
uint32_t GetVideoWidth() const;
|
||||
void SetVideoHeight(uint32_t videoHeight);
|
||||
uint32_t GetVideoHeight() const;
|
||||
void SetFps(uint32_t fps);
|
||||
uint32_t GetFps() const;
|
||||
void SetCodecType(uint8_t codecType);
|
||||
uint8_t GetCodecType() const;
|
||||
void SetVideoFormat(uint8_t videoFormat);
|
||||
uint8_t GetVideoFormat() const;
|
||||
private:
|
||||
friend void to_json(json &j, const VideoParam &videoParam);
|
||||
friend void from_json(const json &j, VideoParam &videoParam);
|
||||
|
||||
uint32_t screenWidth_;
|
||||
uint32_t screenHeight_;
|
||||
uint32_t videoWidth_;
|
||||
uint32_t videoHeight_;
|
||||
uint32_t fps_ = DEFAULT_FPS;
|
||||
uint8_t codecType_ = DEFAULT_CODECTYPE;
|
||||
uint8_t videoFormat_ = DEFAULT_VIDEO_FORMAT;
|
||||
};
|
||||
void to_json(json &j, const VideoParam &videoParam);
|
||||
void from_json(const json &j, VideoParam &videoParam);
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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 "dscreen_maprelation.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
void DScreenMapRelation::SetDisplayId(uint64_t displayId)
|
||||
{
|
||||
displayId_ = displayId;
|
||||
}
|
||||
|
||||
uint64_t DScreenMapRelation::GetDisplayId() const
|
||||
{
|
||||
return displayId_;
|
||||
}
|
||||
|
||||
void DScreenMapRelation::SetScreenId(uint64_t screenId)
|
||||
{
|
||||
screenId_ = screenId;
|
||||
}
|
||||
|
||||
uint64_t DScreenMapRelation::GetScreenId() const
|
||||
{
|
||||
return screenId_;
|
||||
}
|
||||
|
||||
void DScreenMapRelation::SetDisplayRect(const DisplayRect &displayRect)
|
||||
{
|
||||
displayRect_ = displayRect;
|
||||
}
|
||||
|
||||
DisplayRect& DScreenMapRelation::GetDisplayRect()
|
||||
{
|
||||
return displayRect_;
|
||||
}
|
||||
|
||||
void DScreenMapRelation::SetScreenRect(const ScreenRect &screenRect)
|
||||
{
|
||||
screenRect_ = screenRect;
|
||||
}
|
||||
|
||||
ScreenRect& DScreenMapRelation::GetScreenRect()
|
||||
{
|
||||
return screenRect_;
|
||||
}
|
||||
|
||||
void to_json(json &j, const DScreenMapRelation &dScreenMapRelation)
|
||||
{
|
||||
json displayRectJson;
|
||||
json screenRectJson;
|
||||
to_json(displayRectJson, dScreenMapRelation.displayRect_);
|
||||
to_json(screenRectJson, dScreenMapRelation.screenRect_);
|
||||
j = json {
|
||||
{KEY_DISPLAY_ID, dScreenMapRelation.displayId_},
|
||||
{KEY_SCREEN_ID, dScreenMapRelation.screenId_},
|
||||
{KEY_DISPLAY_RECT, displayRectJson},
|
||||
{KEY_SCREEN_RECT, screenRectJson}
|
||||
};
|
||||
}
|
||||
|
||||
void from_json(const json &j, DScreenMapRelation &dScreenMapRelation)
|
||||
{
|
||||
j.at(KEY_DISPLAY_ID).get_to(dScreenMapRelation.displayId_);
|
||||
j.at(KEY_SCREEN_ID).get_to(dScreenMapRelation.screenId_);
|
||||
from_json(j.at(KEY_DISPLAY_RECT), dScreenMapRelation.displayRect_);
|
||||
from_json(j.at(KEY_SCREEN_RECT), dScreenMapRelation.screenRect_);
|
||||
}
|
||||
|
||||
void to_json(json &j, const DisplayRect &rect)
|
||||
{
|
||||
j = json {
|
||||
{KEY_POINT_START_X, rect.startX},
|
||||
{KEY_POINT_START_Y, rect.startY},
|
||||
{KEY_WIDTH, rect.width},
|
||||
{KEY_HEIGHT, rect.height}
|
||||
};
|
||||
}
|
||||
|
||||
void from_json(const json &j, DisplayRect &rect)
|
||||
{
|
||||
j.at(KEY_POINT_START_X).get_to(rect.startX);
|
||||
j.at(KEY_POINT_START_Y).get_to(rect.startY);
|
||||
j.at(KEY_WIDTH).get_to(rect.width);
|
||||
j.at(KEY_HEIGHT).get_to(rect.height);
|
||||
}
|
||||
|
||||
void to_json(json &j, const ScreenRect &rect)
|
||||
{
|
||||
j = json {
|
||||
{KEY_POINT_START_X, rect.startX},
|
||||
{KEY_POINT_START_Y, rect.startY},
|
||||
{KEY_WIDTH, rect.width},
|
||||
{KEY_HEIGHT, rect.height}
|
||||
};
|
||||
}
|
||||
|
||||
void from_json(const json &j, ScreenRect &rect)
|
||||
{
|
||||
j.at(KEY_POINT_START_X).get_to(rect.startX);
|
||||
j.at(KEY_POINT_START_Y).get_to(rect.startY);
|
||||
j.at(KEY_WIDTH).get_to(rect.width);
|
||||
j.at(KEY_HEIGHT).get_to(rect.height);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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 "video_param.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
void VideoParam::SetScreenWidth(uint32_t screenWidth)
|
||||
{
|
||||
screenWidth_ = screenWidth;
|
||||
}
|
||||
|
||||
uint32_t VideoParam::GetScreenWidth() const
|
||||
{
|
||||
return screenWidth_;
|
||||
}
|
||||
|
||||
void VideoParam::SetScreenHeight(uint32_t screenHeight)
|
||||
{
|
||||
screenHeight_ = screenHeight;
|
||||
}
|
||||
|
||||
uint32_t VideoParam::GetScreenHeight() const
|
||||
{
|
||||
return screenHeight_;
|
||||
}
|
||||
|
||||
void VideoParam::SetVideoWidth(uint32_t videoWidth)
|
||||
{
|
||||
videoWidth_ = videoWidth;
|
||||
}
|
||||
|
||||
uint32_t VideoParam::GetVideoWidth() const
|
||||
{
|
||||
return videoWidth_;
|
||||
}
|
||||
|
||||
void VideoParam::SetVideoHeight(uint32_t videoHeight)
|
||||
{
|
||||
videoHeight_ = videoHeight;
|
||||
}
|
||||
|
||||
uint32_t VideoParam::GetVideoHeight() const
|
||||
{
|
||||
return videoHeight_;
|
||||
}
|
||||
|
||||
void VideoParam::SetFps(uint32_t fps)
|
||||
{
|
||||
fps_ = fps;
|
||||
}
|
||||
|
||||
uint32_t VideoParam::GetFps() const
|
||||
{
|
||||
return fps_;
|
||||
}
|
||||
|
||||
void VideoParam::SetCodecType(uint8_t codecType)
|
||||
{
|
||||
codecType_ = codecType;
|
||||
}
|
||||
|
||||
uint8_t VideoParam::GetCodecType() const
|
||||
{
|
||||
return codecType_;
|
||||
}
|
||||
|
||||
void VideoParam::SetVideoFormat(uint8_t videoFormat)
|
||||
{
|
||||
videoFormat_ = videoFormat;
|
||||
}
|
||||
|
||||
uint8_t VideoParam::GetVideoFormat() const
|
||||
{
|
||||
return videoFormat_;
|
||||
}
|
||||
|
||||
void to_json(json &j, const DistributedHardware::VideoParam &videoParam)
|
||||
{
|
||||
j = json {
|
||||
{KEY_SCREEN_WIDTH, videoParam.screenWidth_},
|
||||
{KEY_SCREEN_HEIGHT, videoParam.screenHeight_},
|
||||
{KEY_VIDEO_WIDTH, videoParam.videoWidth_},
|
||||
{KEY_VIDEO_HEIGHT, videoParam.videoHeight_},
|
||||
{KEY_FPS, videoParam.fps_},
|
||||
{KEY_CODECTYPE, videoParam.codecType_}
|
||||
};
|
||||
}
|
||||
|
||||
void from_json(const json &j, DistributedHardware::VideoParam &videoParam)
|
||||
{
|
||||
j.at(KEY_SCREEN_WIDTH).get_to(videoParam.screenWidth_);
|
||||
j.at(KEY_SCREEN_HEIGHT).get_to(videoParam.screenHeight_);
|
||||
j.at(KEY_VIDEO_WIDTH).get_to(videoParam.videoWidth_);
|
||||
j.at(KEY_VIDEO_HEIGHT).get_to(videoParam.videoHeight_);
|
||||
j.at(KEY_FPS).get_to(videoParam.fps_);
|
||||
j.at(KEY_CODECTYPE).get_to(videoParam.codecType_);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,59 @@
|
||||
# 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("//build/ohos_var.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
ohos_shared_library("distributed_screen_client") {
|
||||
|
||||
include_dirs = [
|
||||
"${windowmanager_path}/interfaces/innerkits/wm",
|
||||
"${graphicstandard_path}/interfaces/innerkits/surface",
|
||||
"${graphicstandard_path}/rosen/modules/render_service_client/core/ui",
|
||||
"${fwk_common_path}/utils/include",
|
||||
"//foundation/multimodalinput/input/interfaces/native/innerkits/event/include/"
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"include",
|
||||
"${common_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${services_path}/screenclient/src/screen_client.cpp",
|
||||
"${services_path}/screenclient/src/screen_client_window_adapter.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${common_path}:distributed_screen_utils",
|
||||
"${graphicstandard_path}/frameworks/surface:surface",
|
||||
"${windowmanager_path}/interfaces/innerkits:wm_interface",
|
||||
"${windowmanager_path}/wm:libwm",
|
||||
"//foundation/multimodalinput/input:mmi_uinject",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreenclient\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
|
||||
part_name = "distributed_screen"
|
||||
subsystem_name = "distributedhardware"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 OHOS_SCREEN_CLIENT_H
|
||||
#define OHOS_SCREEN_CLIENT_H
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "single_instance.h"
|
||||
#include "surface.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "screen_client_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ScreenClient {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(ScreenClient);
|
||||
public:
|
||||
int32_t AddWindow(std::shared_ptr<WindowProperty> windowProperty);
|
||||
sptr<Surface> GetSurface(int32_t windowId);
|
||||
int32_t ShowWindow(int32_t windowId);
|
||||
int32_t MoveWindow(int32_t windowId, int32_t startX, int32_t startY);
|
||||
int32_t RemoveWindow(int32_t windowId);
|
||||
int32_t HideWindow(int32_t windowId);
|
||||
private:
|
||||
ScreenClient() = default;
|
||||
~ScreenClient();
|
||||
std::map<int32_t, sptr<Surface>> surfaceMap_;
|
||||
std::atomic<int32_t> windowId_ = INVALID_WINDOW_ID;
|
||||
std::mutex surfaceMapMutex_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_CLIENT_COMMON_H
|
||||
#define OHOS_DSCREEN_CLIENT_COMMON_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
struct WindowProperty {
|
||||
int32_t type;
|
||||
uint64_t displayId;
|
||||
int32_t startX;
|
||||
int32_t startY;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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 OHOS_SCREEN_CLIENT_WINDOW_H
|
||||
#define OHOS_SCREEN_CLIENT_WINDOW_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <refbase.h>
|
||||
|
||||
#include "i_input_event_consumer.h"
|
||||
#include "single_instance.h"
|
||||
#include "surface.h"
|
||||
#include "window.h"
|
||||
|
||||
#include "screen_client.h"
|
||||
#include "screen_client_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ScreenClientWindowAdapter {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(ScreenClientWindowAdapter);
|
||||
public:
|
||||
sptr<Surface> CreateWindow(std::shared_ptr<WindowProperty> windowProperty, int32_t windowId);
|
||||
int32_t ShowWindow(int32_t windowId);
|
||||
int32_t HideWindow(int32_t windowId);
|
||||
int32_t MoveWindow(int32_t windowId, int32_t startX, int32_t startY);
|
||||
int32_t RemoveWindow(int32_t windowId);
|
||||
private:
|
||||
ScreenClientWindowAdapter() = default;
|
||||
~ScreenClientWindowAdapter();
|
||||
std::map<int32_t, sptr<Rosen::Window>> windowIdMap_;
|
||||
std::mutex windowIdMapMutex_;
|
||||
};
|
||||
|
||||
class ScreenClientInputEventListener : public RefBase, public MMI::IInputEventConsumer {
|
||||
public:
|
||||
ScreenClientInputEventListener() = default;
|
||||
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const override;
|
||||
void OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const override;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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 "screen_client.h"
|
||||
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "screen_client_window_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
IMPLEMENT_SINGLE_INSTANCE(ScreenClient);
|
||||
|
||||
ScreenClient::~ScreenClient()
|
||||
{
|
||||
DHLOGD("~ScreenClient");
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(surfaceMapMutex_);
|
||||
for (const auto &item : surfaceMap_) {
|
||||
int32_t ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(item.first);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("windowId (ID = %d) remove failed.", item.first);
|
||||
return;
|
||||
}
|
||||
}
|
||||
surfaceMap_.clear();
|
||||
windowId_ = INVALID_WINDOW_ID;
|
||||
}
|
||||
DHLOGD("ScreenClient Destory.");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t ScreenClient::AddWindow(std::shared_ptr<WindowProperty> windowProperty)
|
||||
{
|
||||
if (windowProperty == nullptr) {
|
||||
DHLOGE("windowProperty is nullptr.");
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_ADD_WINDOW_ERROR;
|
||||
}
|
||||
int32_t windowId = ++windowId_;
|
||||
sptr<Surface> surface = ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId);
|
||||
if (surface == nullptr) {
|
||||
DHLOGE("Surface is nullptr.");
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_ADD_WINDOW_ERROR;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(surfaceMapMutex_);
|
||||
surfaceMap_.emplace(windowId, surface);
|
||||
}
|
||||
DHLOGI("Add window (ID = %d) success.", windowId);
|
||||
return windowId;
|
||||
}
|
||||
|
||||
int32_t ScreenClient::ShowWindow(int32_t windowId)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(surfaceMapMutex_);
|
||||
auto iter = surfaceMap_.find(windowId);
|
||||
if (iter == surfaceMap_.end()) {
|
||||
DHLOGE("windowId (ID = %d) is non-existent.", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR;
|
||||
}
|
||||
}
|
||||
int32_t ret = ScreenClientWindowAdapter::GetInstance().ShowWindow(windowId);
|
||||
if (DH_SUCCESS != ret) {
|
||||
DHLOGE("Show window (ID = %d) failed.", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR;
|
||||
}
|
||||
DHLOGI("Show window (ID = %d) success.", windowId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ScreenClient::HideWindow(int32_t windowId)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(surfaceMapMutex_);
|
||||
auto iter = surfaceMap_.find(windowId);
|
||||
if (iter == surfaceMap_.end()) {
|
||||
DHLOGE("windowId (ID = %d) is non-existent.", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR;
|
||||
}
|
||||
}
|
||||
int32_t ret = ScreenClientWindowAdapter::GetInstance().HideWindow(windowId);
|
||||
if (DH_SUCCESS != ret) {
|
||||
DHLOGE("Hide window (ID = %d) failed.", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR;
|
||||
}
|
||||
DHLOGI("Hide window (ID = %d) success.", windowId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t ScreenClient::MoveWindow(int32_t windowId, int32_t startX, int32_t startY)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(surfaceMapMutex_);
|
||||
auto iter = surfaceMap_.find(windowId);
|
||||
if (iter == surfaceMap_.end()) {
|
||||
DHLOGE("windowId (ID = %d) is non-existent.", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR;
|
||||
}
|
||||
}
|
||||
int32_t ret = ScreenClientWindowAdapter::GetInstance().MoveWindow(windowId, startX, startY);
|
||||
if (DH_SUCCESS != ret) {
|
||||
DHLOGE("Move window (ID = %d) failed.", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR;
|
||||
}
|
||||
DHLOGD("Move window (ID = %d) success.", windowId);
|
||||
return ret;
|
||||
}
|
||||
|
||||
sptr<Surface> ScreenClient::GetSurface(int32_t windowId)
|
||||
{
|
||||
sptr<Surface> surface = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(surfaceMapMutex_);
|
||||
auto iter = surfaceMap_.find(windowId);
|
||||
if (iter == surfaceMap_.end()) {
|
||||
DHLOGE("windowId (ID = %d) is non-existent.", windowId);
|
||||
return nullptr;
|
||||
}
|
||||
surface = iter->second;
|
||||
}
|
||||
if (surface == nullptr) {
|
||||
DHLOGE("Get surface is null(ID = %d).", windowId);
|
||||
return nullptr;
|
||||
}
|
||||
DHLOGD("Get surface (ID = %d) success.", windowId);
|
||||
return surface;
|
||||
}
|
||||
|
||||
int32_t ScreenClient::RemoveWindow(int32_t windowId)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(surfaceMapMutex_);
|
||||
auto iter = surfaceMap_.find(windowId);
|
||||
if (iter == surfaceMap_.end()) {
|
||||
DHLOGE("windowId (ID = %d) is non-existent.", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR;
|
||||
}
|
||||
surfaceMap_.erase(windowId);
|
||||
}
|
||||
int32_t ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("windowId (ID = %d) remove failed.", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR;
|
||||
}
|
||||
DHLOGD("windowId (ID = %d) remove success.", windowId);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,215 @@
|
||||
/*
|
||||
* 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 "screen_client_window_adapter.h"
|
||||
|
||||
#include "rs_surface_node.h"
|
||||
#include "window_option.h"
|
||||
#include "wm_common.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
IMPLEMENT_SINGLE_INSTANCE(ScreenClientWindowAdapter);
|
||||
ScreenClientWindowAdapter::~ScreenClientWindowAdapter()
|
||||
{
|
||||
DHLOGD("~ScreenClientWindowAdapter");
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(windowIdMapMutex_);
|
||||
for (const auto &item : windowIdMap_) {
|
||||
auto window = item.second;
|
||||
if (window == nullptr) {
|
||||
DHLOGE("window is nullptr(windowId = %d).", item.first);
|
||||
return;
|
||||
}
|
||||
if (OHOS::Rosen::WMError::WM_OK != window->Destroy()) {
|
||||
DHLOGE("screenclientSurface is nullptr(windowId = %d).", item.first);
|
||||
return;
|
||||
}
|
||||
}
|
||||
windowIdMap_.clear();
|
||||
}
|
||||
DHLOGD("ScreenClientWindowAdapter Destory.");
|
||||
return;
|
||||
}
|
||||
|
||||
sptr<Surface> ScreenClientWindowAdapter::CreateWindow(std::shared_ptr<WindowProperty> windowProperty,
|
||||
int32_t windowId)
|
||||
{
|
||||
if (windowProperty == nullptr) {
|
||||
DHLOGE("windowProperty is nullptr.");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<Rosen::WindowOption> option = new Rosen::WindowOption();
|
||||
option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_LAUNCHING);
|
||||
option->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
|
||||
option->SetDisplayId(windowProperty->displayId);
|
||||
std::string windowName = SCREEN_CLIENT_WINDOW + std::to_string(windowId);
|
||||
sptr<Rosen::Window> window = Rosen::Window::Create(windowName, option);
|
||||
if (window == nullptr || window->GetSurfaceNode() == nullptr) {
|
||||
DHLOGE("Create screen client window failed.");
|
||||
return nullptr;
|
||||
}
|
||||
auto surface = window->GetSurfaceNode()->GetSurface();
|
||||
if (surface == nullptr) {
|
||||
window->Destroy();
|
||||
DHLOGE("surface is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<MMI::IInputEventConsumer> listener =
|
||||
std::make_shared<ScreenClientInputEventListener>(ScreenClientInputEventListener());
|
||||
window->AddInputEventListener(listener);
|
||||
DHLOGD("Create window name is %s.", windowName.c_str());
|
||||
if (OHOS::Rosen::WMError::WM_OK != window->Resize(windowProperty->width, windowProperty->height)) {
|
||||
window->Destroy();
|
||||
DHLOGE("Window resize failed.");
|
||||
return nullptr;
|
||||
}
|
||||
if (OHOS::Rosen::WMError::WM_OK != window->MoveTo(windowProperty->startX, windowProperty->startY)) {
|
||||
window->Destroy();
|
||||
DHLOGE("Window moveto failed.");
|
||||
return nullptr;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(windowIdMapMutex_);
|
||||
windowIdMap_.emplace(windowId, window);
|
||||
}
|
||||
DHLOGD("Get surface(windowId = %d) success.", windowId);
|
||||
return surface;
|
||||
}
|
||||
|
||||
int32_t ScreenClientWindowAdapter::ShowWindow(int32_t windowId)
|
||||
{
|
||||
sptr<Rosen::Window> window = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(windowIdMapMutex_);
|
||||
auto iter = windowIdMap_.find(windowId);
|
||||
if (iter == windowIdMap_.end()) {
|
||||
DHLOGE("ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR.");
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR;
|
||||
}
|
||||
window = iter->second;
|
||||
}
|
||||
if (window == nullptr) {
|
||||
DHLOGE("Current window is null.");
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR;
|
||||
}
|
||||
if (OHOS::Rosen::WMError::WM_OK != window->Show()) {
|
||||
DHLOGE("Show window failed.");
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR;
|
||||
}
|
||||
DHLOGD("Show window (windowId = %d) success.", windowId);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenClientWindowAdapter::HideWindow(int32_t windowId)
|
||||
{
|
||||
sptr<Rosen::Window> window = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(windowIdMapMutex_);
|
||||
auto iter = windowIdMap_.find(windowId);
|
||||
if (iter == windowIdMap_.end()) {
|
||||
DHLOGE("ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR.");
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR;
|
||||
}
|
||||
window = iter->second;
|
||||
}
|
||||
if (window == nullptr) {
|
||||
DHLOGE("Current window is null.");
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR;
|
||||
}
|
||||
if (OHOS::Rosen::WMError::WM_OK != window->Hide()) {
|
||||
DHLOGE("Hide window failed.");
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_HIDE_WINDOW_ERROR;
|
||||
}
|
||||
DHLOGD("Hide window (windowId = %d) success.", windowId);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenClientWindowAdapter::MoveWindow(int32_t windowId, int32_t startX, int32_t startY)
|
||||
{
|
||||
sptr<Rosen::Window> window = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(windowIdMapMutex_);
|
||||
auto iter = windowIdMap_.find(windowId);
|
||||
if (iter == windowIdMap_.end()) {
|
||||
DHLOGE("Invalid windowId (windowId = %d).", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR;
|
||||
}
|
||||
window = iter->second;
|
||||
}
|
||||
if (window == nullptr) {
|
||||
DHLOGE("Current window is null(windowId = %d).", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR;
|
||||
}
|
||||
if (OHOS::Rosen::WMError::WM_OK != window->MoveTo(startX, startY)) {
|
||||
DHLOGE("Move window failed (windowId = %d).", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR;
|
||||
}
|
||||
DHLOGD("MoveTo window (windowId = %d) success.", windowId);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenClientWindowAdapter::RemoveWindow(int32_t windowId)
|
||||
{
|
||||
sptr<Rosen::Window> window = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> dataLock(windowIdMapMutex_);
|
||||
auto iter = windowIdMap_.find(windowId);
|
||||
if (iter == windowIdMap_.end()) {
|
||||
DHLOGE("Invalid windowId(windowId = %d).", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR;
|
||||
}
|
||||
window = iter->second;
|
||||
windowIdMap_.erase(windowId);
|
||||
}
|
||||
if (window == nullptr) {
|
||||
DHLOGE("Current window is null(windowId = %d).", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR;
|
||||
}
|
||||
if (OHOS::Rosen::WMError::WM_OK != window->Hide()) {
|
||||
DHLOGE("Remove window window failed(windowId = %d).", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR;
|
||||
}
|
||||
if (OHOS::Rosen::WMError::WM_OK != window->Destroy()) {
|
||||
DHLOGE("Remove window window failed(windowId = %d).", windowId);
|
||||
return ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR;
|
||||
}
|
||||
DHLOGD("Remove window success(windowId = %d).", windowId);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void ScreenClientInputEventListener::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
|
||||
{
|
||||
DHLOGI("onInputEvent, pointerEvent");
|
||||
pointerEvent->MarkProcessed();
|
||||
}
|
||||
|
||||
void ScreenClientInputEventListener::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
|
||||
{
|
||||
DHLOGI("onInputEvent, keyEvent");
|
||||
keyEvent->MarkProcessed();
|
||||
}
|
||||
|
||||
void ScreenClientInputEventListener::OnInputEvent(std::shared_ptr<MMI::AxisEvent> axisEvent) const
|
||||
{
|
||||
DHLOGI("onInputEvent, axisEvent");
|
||||
axisEvent->MarkProcessed();
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,69 @@
|
||||
# Copyright (c) 2021 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/test.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
module_out_path = "distributed_screen/screen_client_test"
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"${windowmanager_path}/interfaces/innerkits/wm",
|
||||
"${graphicstandard_path}/interfaces/innerkits/surface",
|
||||
"${graphicstandard_path}/rosen/modules/render_service_client/core/ui",
|
||||
"${fwk_common_path}/utils/include",
|
||||
"${fwk_utils_path}/include/log",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"include",
|
||||
"${common_path}/include",
|
||||
"${services_path}/screenclient/include",
|
||||
"${services_path}/screenclient/test/unittest/include",
|
||||
]
|
||||
}
|
||||
|
||||
## UnitTest screen_client_test
|
||||
ohos_unittest("ScreenClientTest") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [
|
||||
"${services_path}/screenclient/test/unittest/src/screen_client_test.cpp",
|
||||
"${services_path}/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${graphicstandard_path}/frameworks/surface:surface",
|
||||
"${graphicstandard_path}/rosen/modules/render_service_client:librender_service_client",
|
||||
"${windowmanager_path}/interfaces/innerkits:wm_interface",
|
||||
"${windowmanager_path}/wm:libwm",
|
||||
"//foundation/distributedhardware/distributedscreen/services/screenclient:distributed_screen_client",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
}
|
||||
|
||||
group("screen_client_test") {
|
||||
testonly = true
|
||||
deps = [ ":ScreenClientTest" ]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "screen_client.h"
|
||||
#include "screen_client_window_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ScreenClientTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
|
||||
#include "rs_surface_node.h"
|
||||
#include "window_option.h"
|
||||
#include "wm_common.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "screen_client_window_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ScreenClientWindowAdapterTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define private public
|
||||
#include "screen_client_test.h"
|
||||
#undef private
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
void ScreenClientTest::SetUpTestCase(void) {}
|
||||
|
||||
void ScreenClientTest::TearDownTestCase(void) {}
|
||||
|
||||
void ScreenClientTest::SetUp() {}
|
||||
|
||||
void ScreenClientTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: ShowWindow_001
|
||||
* @tc.desc: Verify the ShowWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientTest, ShowWindow_001, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 0;
|
||||
int32_t actual = ScreenClient::GetInstance().ShowWindow(windowId);
|
||||
EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ShowWindow_002
|
||||
* @tc.desc: Verify the ShowWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientTest, ShowWindow_002, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
|
||||
ScreenClient::GetInstance().windowId_ = 0;
|
||||
int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty);
|
||||
int32_t actual = ScreenClient::GetInstance().ShowWindow(windowId);
|
||||
EXPECT_EQ(DH_SUCCESS, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddWindow_001
|
||||
* @tc.desc: Verify the AddWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientTest, AddWindow_001, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<WindowProperty> windowProperty = nullptr;
|
||||
int32_t actual = ScreenClient::GetInstance().AddWindow(windowProperty);
|
||||
EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_ADD_WINDOW_ERROR, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddWindow_002
|
||||
* @tc.desc: Verify the AddWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientTest, AddWindow_002, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
|
||||
ScreenClient::GetInstance().windowId_ = 2;
|
||||
int32_t actual = ScreenClient::GetInstance().AddWindow(windowProperty);
|
||||
EXPECT_EQ(3, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MoveWindow_001
|
||||
* @tc.desc: Verify the MoveWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientTest, MoveWindow_001, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 0;
|
||||
int32_t startX = 0;
|
||||
int32_t startY = 0;
|
||||
int32_t actual = ScreenClient::GetInstance().MoveWindow(windowId, startX, startY);
|
||||
EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MoveWindow_002
|
||||
* @tc.desc: Verify the MoveWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientTest, MoveWindow_002, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 1;
|
||||
int32_t startX = 0;
|
||||
int32_t startY = 0;
|
||||
int32_t actual = ScreenClient::GetInstance().MoveWindow(windowId, startX, startY);
|
||||
EXPECT_EQ(DH_SUCCESS, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemoveWindow_001
|
||||
* @tc.desc: Verify the RemoveWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientTest, RemoveWindow_001, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 0;
|
||||
int32_t actual = ScreenClient::GetInstance().RemoveWindow(windowId);
|
||||
EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemoveWindow_002
|
||||
* @tc.desc: Verify the RemoveWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientTest, RemoveWindow_002, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 1;
|
||||
int32_t actual = ScreenClient::GetInstance().RemoveWindow(windowId);
|
||||
EXPECT_EQ(DH_SUCCESS, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetSurface_001
|
||||
* @tc.desc: Verify the GetSurface function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientTest, GetSurface_001, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 0;
|
||||
sptr<Surface> actualSurface = ScreenClient::GetInstance().GetSurface(windowId);
|
||||
EXPECT_EQ(nullptr, actualSurface);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetSurface_002
|
||||
* @tc.desc: Verify the GetSurface function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientTest, GetSurface_002, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
|
||||
ScreenClient::GetInstance().windowId_ = 0;
|
||||
int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty);
|
||||
sptr<Surface> actualSurface = ScreenClient::GetInstance().GetSurface(windowId);
|
||||
EXPECT_NE(nullptr, actualSurface);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define private public
|
||||
#include "screen_client_window_adapter_test.h"
|
||||
#undef private
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
void ScreenClientWindowAdapterTest::SetUpTestCase(void) {}
|
||||
|
||||
void ScreenClientWindowAdapterTest::TearDownTestCase(void) {}
|
||||
|
||||
void ScreenClientWindowAdapterTest::SetUp() {}
|
||||
|
||||
void ScreenClientWindowAdapterTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: CreateWindow_001
|
||||
* @tc.desc: Verify the CreateWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientWindowAdapterTest, CreateWindow_001, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<WindowProperty> windowProperty = nullptr;
|
||||
int32_t windowId = 0;
|
||||
sptr<Surface> actualSurface = ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId);
|
||||
EXPECT_EQ(nullptr, actualSurface);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CreateWindow_002
|
||||
* @tc.desc: Verify the CreateWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientWindowAdapterTest, CreateWindow_002, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
|
||||
int32_t windowId = 2;
|
||||
sptr<Surface> surface = nullptr;
|
||||
sptr<Surface> actualSurface = ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId);
|
||||
EXPECT_NE(surface, actualSurface);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ShowWindow_001
|
||||
* @tc.desc: Verify the ShowWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientWindowAdapterTest, ShowWindow_001, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 0;
|
||||
int32_t actual = ScreenClientWindowAdapter::GetInstance().ShowWindow(windowId);
|
||||
EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_SHOW_WINDOW_ERROR, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ShowWindow_002
|
||||
* @tc.desc: Verify the ShowWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientWindowAdapterTest, ShowWindow_002, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 1;
|
||||
int32_t actual = ScreenClientWindowAdapter::GetInstance().ShowWindow(windowId);
|
||||
EXPECT_EQ(DH_SUCCESS, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MoveWindow_001
|
||||
* @tc.desc: Verify the MoveWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientWindowAdapterTest, MoveWindow_001, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 0;
|
||||
int32_t startX = 0;
|
||||
int32_t startY = 0;
|
||||
int32_t actual = ScreenClientWindowAdapter::GetInstance().MoveWindow(windowId, startX, startY);
|
||||
EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_MOVE_WINDOW_ERROR, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: MoveWindow_002
|
||||
* @tc.desc: Verify the MoveWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientWindowAdapterTest, MoveWindow_002, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 1;
|
||||
int32_t startX = 0;
|
||||
int32_t startY = 0;
|
||||
int32_t actual = ScreenClientWindowAdapter::GetInstance().MoveWindow(windowId, startX, startY);
|
||||
EXPECT_EQ(DH_SUCCESS, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemoveWindow_001
|
||||
* @tc.desc: Verify the RemoveWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientWindowAdapterTest, RemoveWindow_001, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 0;
|
||||
int32_t actual = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId);
|
||||
EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_REMOVE_WINDOW_ERROR, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RemoveWindow_002
|
||||
* @tc.desc: Verify the RemoveWindow function.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: Issue Number
|
||||
*/
|
||||
HWTEST_F(ScreenClientWindowAdapterTest, RemoveWindow_002, TestSize.Level1)
|
||||
{
|
||||
int32_t windowId = 1;
|
||||
int32_t actual = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId);
|
||||
EXPECT_EQ(DH_SUCCESS, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
# 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("//build/ohos_var.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
ohos_shared_library("distributed_screen_sink") {
|
||||
include_dirs = [
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"//foundation/graphic/standard/interfaces/innerkits/surface",
|
||||
"${windowmanager_path}/interfaces/innerkits/dm",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"./dscreenservice/include",
|
||||
"./screenregionmgr/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/screensinktrans/include",
|
||||
"${services_path}/screentransport/screensinkprocessor/include",
|
||||
"${services_path}/screentransport/screensinkprocessor/decoder/include",
|
||||
"${services_path}/screenclient/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/dscreen_sink_service.cpp",
|
||||
"./dscreenservice/src/dscreen_sink_stub.cpp",
|
||||
"./screenregionmgr/src/screenregion.cpp",
|
||||
"./screenregionmgr/src/screenregionmgr.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"${common_path}:distributed_screen_utils",
|
||||
"${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans",
|
||||
"${services_path}/screenclient:distributed_screen_client",
|
||||
"//foundation/graphic/standard/frameworks/surface:surface",
|
||||
"${windowmanager_path}/interfaces/innerkits:wm_interface",
|
||||
"${windowmanager_path}/dm:libdm",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreensink\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"multimedia_media_standard:media_client",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SINK_SERVICE_H
|
||||
#define OHOS_DSCREEN_SINK_SERVICE_H
|
||||
|
||||
#include "ipc_object_stub.h"
|
||||
#include "system_ability.h"
|
||||
|
||||
#include "dscreen_sink_stub.h"
|
||||
#include "screenregionmgr.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSinkService : public SystemAbility, public DScreenSinkStub,
|
||||
public std::enable_shared_from_this<DScreenSinkService> {
|
||||
DECLARE_SYSTEM_ABILITY(DScreenSinkService);
|
||||
public:
|
||||
DScreenSinkService(int32_t saId, bool runOnCreate);
|
||||
~DScreenSinkService() = default;
|
||||
int32_t InitSink(const std::string ¶ms) override;
|
||||
int32_t ReleaseSink() override;
|
||||
int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override;
|
||||
int32_t UnsubscribeLocalHardware(const std::string &dhId) override;
|
||||
void DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) override;
|
||||
|
||||
protected:
|
||||
void OnStart() override;
|
||||
void OnStop() override;
|
||||
DISALLOW_COPY_AND_MOVE(DScreenSinkService);
|
||||
|
||||
private:
|
||||
std::shared_ptr<ScreenRegionManager> screenRegionMgr_ = nullptr;
|
||||
bool registerToService_ = false;
|
||||
|
||||
bool Init();
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SINK_STUB_H
|
||||
#define OHOS_DSCREEN_SINK_STUB_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "iremote_stub.h"
|
||||
|
||||
#include "idscreen_sink.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSinkStub : public IRemoteStub<IDScreenSink> {
|
||||
public:
|
||||
DScreenSinkStub();
|
||||
virtual ~DScreenSinkStub();
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option) override;
|
||||
private:
|
||||
using DScreenSinkFunc = int32_t (DScreenSinkStub::*)(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
std::map<int32_t, DScreenSinkFunc> memberFuncMap_;
|
||||
|
||||
int32_t InitSinkInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
int32_t ReleaseSinkInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
int32_t SubscribeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
int32_t UnsubscribeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
int32_t DScreenNotifyInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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 "dscreen_sink_service.h"
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ipc_types.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
REGISTER_SYSTEM_ABILITY_BY_ID(DScreenSinkService, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, true);
|
||||
|
||||
DScreenSinkService::DScreenSinkService(int32_t saId, bool runOnCreate) : SystemAbility(saId, runOnCreate)
|
||||
{
|
||||
DHLOGI("DScreenSinkService construct.");
|
||||
}
|
||||
|
||||
void DScreenSinkService::OnStart()
|
||||
{
|
||||
DHLOGI("dscreen sink service start.");
|
||||
if (!Init()) {
|
||||
DHLOGE("DScreenSinkService init failed.");
|
||||
return;
|
||||
}
|
||||
DHLOGI("DScreenSinkService start success.");
|
||||
}
|
||||
|
||||
void DScreenSinkService::OnStop()
|
||||
{
|
||||
DHLOGI("dscreen sink service stop.");
|
||||
registerToService_ = false;
|
||||
}
|
||||
|
||||
bool DScreenSinkService::Init()
|
||||
{
|
||||
DHLOGI("dscreen sink service start init.");
|
||||
if (!registerToService_) {
|
||||
bool ret = Publish(this);
|
||||
if (!ret) {
|
||||
DHLOGE("dscreen sink publish service failed.");
|
||||
return false;
|
||||
}
|
||||
registerToService_ = true;
|
||||
}
|
||||
DHLOGI("dscreenService init success.");
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkService::InitSink(const std::string ¶ms)
|
||||
{
|
||||
DHLOGI("InitSink");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkService::ReleaseSink()
|
||||
{
|
||||
DHLOGI("ReleaseSink");
|
||||
return ScreenRegionManager::GetInstance().ReleaseAllRegions();
|
||||
}
|
||||
|
||||
int32_t DScreenSinkService::SubscribeLocalHardware(const std::string &dhId, const std::string ¶m)
|
||||
{
|
||||
DHLOGI("SubscribeLocalHardware");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkService::UnsubscribeLocalHardware(const std::string &dhId)
|
||||
{
|
||||
DHLOGI("UnsubscribeLocalHardware");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DScreenSinkService::DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent)
|
||||
{
|
||||
DHLOGI("DScreenNotify, devId:%s, eventCode: %d, eventContent:%s", GetAnonyString(devId).c_str(),
|
||||
eventCode, eventContent.c_str());
|
||||
ScreenRegionManager::GetInstance().HandleDScreenNotify(devId, eventCode, eventContent);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 "dscreen_sink_stub.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
DScreenSinkStub::DScreenSinkStub()
|
||||
{
|
||||
DHLOGI("DScreenSinkStub construct.");
|
||||
memberFuncMap_[INIT_SINK] = &DScreenSinkStub::InitSinkInner;
|
||||
memberFuncMap_[RELEASE_SINK] = &DScreenSinkStub::ReleaseSinkInner;
|
||||
memberFuncMap_[SUBSCRIBE_DISTRIBUTED_HARDWARE] = &DScreenSinkStub::SubscribeDistributedHardwareInner;
|
||||
memberFuncMap_[UNSUBSCRIBE_DISTRIBUTED_HARDWARE] = &DScreenSinkStub::UnsubscribeDistributedHardwareInner;
|
||||
memberFuncMap_[DSCREEN_NOTIFY] = &DScreenSinkStub::DScreenNotifyInner;
|
||||
}
|
||||
|
||||
DScreenSinkStub::~DScreenSinkStub()
|
||||
{
|
||||
DHLOGI("DScreenSinkStub deconstruct.");
|
||||
}
|
||||
|
||||
int32_t DScreenSinkStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("OnRemoteRequest, code: %d", code);
|
||||
std::u16string desc = DScreenSinkStub::GetDescriptor();
|
||||
std::u16string remoteDesc = data.ReadInterfaceToken();
|
||||
if (desc != remoteDesc) {
|
||||
DHLOGE("DScreenSinkStub::OnRemoteRequest remoteDesc is invalid!");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
|
||||
const auto &iter = memberFuncMap_.find(code);
|
||||
if (iter == memberFuncMap_.end()) {
|
||||
DHLOGE("invalid request code.");
|
||||
return ERR_DH_SCREEN_SA_INVALID_IPC_CALL;
|
||||
}
|
||||
DScreenSinkFunc &func = iter->second;
|
||||
return (this->*func)(data, reply, option);
|
||||
}
|
||||
|
||||
int32_t DScreenSinkStub::InitSinkInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("InitSinkInner");
|
||||
std::string param = data.ReadString();
|
||||
int32_t ret = InitSink(param);
|
||||
reply.WriteInt32(ret);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkStub::ReleaseSinkInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("ReleaseSinkInner");
|
||||
int32_t ret = ReleaseSink();
|
||||
reply.WriteInt32(ret);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkStub::SubscribeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("SubscribeDistributedHardwareInner");
|
||||
std::string dhId = data.ReadString();
|
||||
std::string param = data.ReadString();
|
||||
int32_t ret = SubscribeLocalHardware(dhId, param);
|
||||
reply.WriteInt32(ret);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkStub::UnsubscribeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("UnsubscribeDistributedHardwareInner");
|
||||
std::string dhId = data.ReadString();
|
||||
int32_t ret = UnsubscribeLocalHardware(dhId);
|
||||
reply.WriteInt32(ret);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkStub::DScreenNotifyInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("DScreenNotifyInner");
|
||||
std::string devId = data.ReadString();
|
||||
int32_t eventCode = data.ReadInt32();
|
||||
std::string eventContent = data.ReadString();
|
||||
|
||||
DScreenNotify(devId, eventCode, eventContent);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SCREEN_REGION_H
|
||||
#define OHOS_DSCREEN_SCREEN_REGION_H
|
||||
|
||||
#include "surface.h"
|
||||
|
||||
#include "iscreen_sink_trans_callback.h"
|
||||
#include "iscreen_sink_trans.h"
|
||||
#include "dscreen_maprelation.h"
|
||||
#include "video_param.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ScreenSinkTransCallback : public IScreenSinkTransCallback {
|
||||
public:
|
||||
~ScreenSinkTransCallback() override {};
|
||||
virtual void OnTransError(int32_t err, const std::string &content) = 0;
|
||||
virtual void OnError(int32_t err, const std::string &content) override
|
||||
{
|
||||
OnTransError(err, content);
|
||||
}
|
||||
};
|
||||
|
||||
class ScreenRegion : public ScreenSinkTransCallback, public std::enable_shared_from_this<ScreenRegion> {
|
||||
public:
|
||||
ScreenRegion(const std::string &remoteDevId, uint64_t screenId, uint64_t displayId);
|
||||
~ScreenRegion();
|
||||
void OnTransError(int32_t err, const std::string &content) override;
|
||||
void SetVideoParam(std::shared_ptr<VideoParam> &videoParam);
|
||||
void SetMapRelation(std::shared_ptr<DScreenMapRelation> &mapRElation);
|
||||
std::string GetRemoteDevId();
|
||||
uint64_t GetScreenId();
|
||||
uint64_t GetDisplayId();
|
||||
int32_t SetUp();
|
||||
int32_t Start();
|
||||
int32_t Stop();
|
||||
|
||||
private:
|
||||
std::string remoteDevId_;
|
||||
uint64_t screenId_; // local screen id
|
||||
uint64_t displayId_; // local display id
|
||||
bool isRunning = false;
|
||||
|
||||
std::shared_ptr<VideoParam> videoParam_ = nullptr;
|
||||
std::shared_ptr<DScreenMapRelation> mapRelation_ = nullptr;
|
||||
sptr<OHOS::Surface> surface_ = nullptr;
|
||||
int32_t windowId_ = INVALID_WINDOW_ID;
|
||||
std::shared_ptr<IScreenSinkTrans> sinkTrans_ = nullptr;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SCREEN_REGION_MGR_H
|
||||
#define OHOS_DSCREEN_SCREEN_REGION_MGR_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "single_instance.h"
|
||||
|
||||
#include "screenregion.h"
|
||||
#include "idscreen_source.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ScreenRegionManager {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(ScreenRegionManager);
|
||||
public:
|
||||
int32_t ReleaseAllRegions();
|
||||
void HandleDScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent);
|
||||
|
||||
private:
|
||||
ScreenRegionManager();
|
||||
~ScreenRegionManager();
|
||||
std::map<std::string, std::shared_ptr<ScreenRegion>> screenRegions_;
|
||||
std::mutex screenRegionsMtx_;
|
||||
|
||||
sptr<IDScreenSource> GetDScreenSourceSA(const std::string &devId);
|
||||
int32_t NotifyRemoteScreenService(const std::string &remoteDevId, const std::string &dhId,
|
||||
int32_t eventCode, const std::string &eventContent);
|
||||
void HandleNotifySetUp(const std::string &remoteDevId, const std::string &eventContent);
|
||||
void NotifyRemoteSourceSetUpResult(const std::string &remoteDevId, const std::string &dhId,
|
||||
int32_t errCode, const std::string &errContent);
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* 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 "screenregion.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_util.h"
|
||||
#include "screen_client.h"
|
||||
#include "screen_client_common.h"
|
||||
#include "screen_sink_trans.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
ScreenRegion::ScreenRegion(const std::string &remoteDevId, uint64_t screenId, uint64_t displayId)
|
||||
{
|
||||
DHLOGD("ScreenRegion construct");
|
||||
remoteDevId_ = remoteDevId;
|
||||
screenId_ = screenId;
|
||||
displayId_ = displayId;
|
||||
windowId_ = INVALID_WINDOW_ID;
|
||||
}
|
||||
|
||||
ScreenRegion::~ScreenRegion()
|
||||
{
|
||||
DHLOGD("ScreenRegion deConstruct");
|
||||
if (!sinkTrans_) {
|
||||
sinkTrans_->Release();
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenRegion::OnTransError(int32_t err, const std::string &content)
|
||||
{
|
||||
DHLOGE("OnTransError, err: %d", err);
|
||||
Stop();
|
||||
}
|
||||
|
||||
void ScreenRegion::SetVideoParam(std::shared_ptr<VideoParam> &videoParam)
|
||||
{
|
||||
videoParam_ = videoParam;
|
||||
}
|
||||
|
||||
void ScreenRegion::SetMapRelation(std::shared_ptr<DScreenMapRelation> &mapRelation)
|
||||
{
|
||||
mapRelation_ = mapRelation;
|
||||
}
|
||||
|
||||
uint64_t ScreenRegion::GetScreenId()
|
||||
{
|
||||
return screenId_;
|
||||
}
|
||||
|
||||
uint64_t ScreenRegion::GetDisplayId()
|
||||
{
|
||||
return displayId_;
|
||||
}
|
||||
|
||||
std::string ScreenRegion::GetRemoteDevId()
|
||||
{
|
||||
return remoteDevId_;
|
||||
}
|
||||
|
||||
int32_t ScreenRegion::SetUp()
|
||||
{
|
||||
DHLOGI("ScreenRegion::SetUp, remoteDevId: %s", GetAnonyString(remoteDevId_).c_str());
|
||||
|
||||
std::shared_ptr<WindowProperty> windowProperty = std::make_shared<WindowProperty>();
|
||||
windowProperty->displayId = displayId_;
|
||||
|
||||
ScreenRect screenRect = mapRelation_->GetScreenRect();
|
||||
windowProperty->startX = screenRect.startX;
|
||||
windowProperty->startY = screenRect.startY;
|
||||
windowProperty->width = screenRect.width;
|
||||
windowProperty->height = screenRect.height;
|
||||
|
||||
windowId_ = ScreenClient::GetInstance().AddWindow(windowProperty);
|
||||
if (windowId_ < 0) {
|
||||
DHLOGE("AddWindow failed.");
|
||||
return ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED;
|
||||
}
|
||||
int32_t ret = ScreenClient::GetInstance().ShowWindow(windowId_);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("show window failed.");
|
||||
return ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED;
|
||||
}
|
||||
|
||||
sptr<Surface> surface = ScreenClient::GetInstance().GetSurface(windowId_);
|
||||
if (!surface) {
|
||||
DHLOGE("get window surface failed.");
|
||||
return ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED;
|
||||
}
|
||||
|
||||
surface_ = surface;
|
||||
|
||||
if (!sinkTrans_) {
|
||||
sinkTrans_ = std::make_shared<ScreenSinkTrans>();
|
||||
}
|
||||
|
||||
sinkTrans_->RegisterStateCallback(shared_from_this());
|
||||
sinkTrans_->SetImageSurface(surface_);
|
||||
ret = sinkTrans_->SetUp(*videoParam_, *videoParam_, remoteDevId_);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("sinkTrans setup failed.");
|
||||
return ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenRegion::Start()
|
||||
{
|
||||
DHLOGI("ScreenRegion::Start remoteDevId: %s", GetAnonyString(remoteDevId_).c_str());
|
||||
if (!sinkTrans_) {
|
||||
DHLOGE("sink trans not init.");
|
||||
return ERR_DH_SCREEN_SA_SINKTRANS_NOT_INIT;
|
||||
}
|
||||
|
||||
int32_t ret = sinkTrans_->Start();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("sink trans start failed.");
|
||||
return ret;
|
||||
}
|
||||
isRunning = true;
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenRegion::Stop()
|
||||
{
|
||||
DHLOGI("ScreenRegion::Stop remoteDevId: %s", GetAnonyString(remoteDevId_).c_str());
|
||||
if (!isRunning) {
|
||||
DHLOGI("ScreenRegion not running, no need stop");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
if (!sinkTrans_) {
|
||||
DHLOGE("sink trans not init.");
|
||||
return ERR_DH_SCREEN_SA_SINKTRANS_NOT_INIT;
|
||||
}
|
||||
|
||||
int32_t ret = sinkTrans_->Stop();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("sink trans stop failed.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = sinkTrans_->Release();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("sink trans release failed.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = ScreenClient::GetInstance().RemoveWindow(windowId_);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("remove window failed.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
isRunning = false;
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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 "screenregionmgr.h"
|
||||
|
||||
#include "display_manager.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_maprelation.h"
|
||||
#include "dscreen_util.h"
|
||||
#include "idscreen_source.h"
|
||||
#include "screen_client.h"
|
||||
#include "screen_client_common.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
IMPLEMENT_SINGLE_INSTANCE(ScreenRegionManager);
|
||||
ScreenRegionManager::ScreenRegionManager()
|
||||
{
|
||||
DHLOGI("ScreenRegionManager");
|
||||
}
|
||||
|
||||
ScreenRegionManager::~ScreenRegionManager()
|
||||
{
|
||||
DHLOGI("~ScreenRegionManager");
|
||||
}
|
||||
|
||||
int32_t ScreenRegionManager::ReleaseAllRegions()
|
||||
{
|
||||
DHLOGI("ScreenRegionManager::ReleaseAllRegion");
|
||||
std::lock_guard<std::mutex> lock(screenRegionsMtx_);
|
||||
for (const auto &item : screenRegions_) {
|
||||
std::shared_ptr<ScreenRegion> screenRegion = item.second;
|
||||
if (!screenRegion) {
|
||||
continue;
|
||||
}
|
||||
int32_t ret = screenRegion->Stop();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Release region failed, remoteDevId: %s, err: %d",
|
||||
GetAnonyString(screenRegion->GetRemoteDevId()).c_str(), ret);
|
||||
}
|
||||
}
|
||||
screenRegions_.clear();
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void ScreenRegionManager::HandleDScreenNotify(const std::string &remoteDevId, int32_t eventCode,
|
||||
const std::string &eventContent)
|
||||
{
|
||||
DHLOGI("HandleDScreenNotify, remoteDevId: %s, eventCode: %d", GetAnonyString(remoteDevId).c_str(), eventCode);
|
||||
if (eventCode == NOTIFY_SINK_SETUP) {
|
||||
HandleNotifySetUp(remoteDevId, eventContent);
|
||||
return;
|
||||
}
|
||||
DHLOGE("invalid event.");
|
||||
}
|
||||
|
||||
void ScreenRegionManager::HandleNotifySetUp(const std::string &remoteDevId, const std::string &eventContent)
|
||||
{
|
||||
DHLOGI("HandleNotifySetUp, remoteDevId: %s", GetAnonyString(remoteDevId).c_str());
|
||||
json eventContentJson = json::parse(eventContent, nullptr, false);
|
||||
if (eventContentJson.is_discarded()) {
|
||||
DHLOGE("HandleNotifySetUp, eventJsonContent is invalid.");
|
||||
NotifyRemoteSourceSetUpResult(remoteDevId, "", ERR_DH_SCREEN_SA_SCREENREGION_SETUP_FAIL, "");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!eventContentJson.contains(KEY_SCREEN_ID) || !eventContentJson.contains(KEY_DH_ID) ||
|
||||
!eventContentJson.contains(KEY_VIDEO_PARAM) || !eventContentJson.contains(KEY_MAPRELATION)) {
|
||||
DHLOGE("HandleNotifySetUp, eventJsonContent is invalid.");
|
||||
NotifyRemoteSourceSetUpResult(remoteDevId, "", ERR_DH_SCREEN_SA_SCREENREGION_SETUP_FAIL, "");
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t screenId = eventContentJson[KEY_SCREEN_ID];
|
||||
std::string dhId = eventContentJson[KEY_DH_ID];
|
||||
std::shared_ptr<VideoParam> videoParam =
|
||||
std::make_shared<VideoParam>(eventContentJson[KEY_VIDEO_PARAM].get<VideoParam>());
|
||||
std::shared_ptr<DScreenMapRelation> mapRelation =
|
||||
std::make_shared<DScreenMapRelation>(eventContentJson[KEY_MAPRELATION].get<DScreenMapRelation>());
|
||||
|
||||
uint64_t displayId = Rosen::DisplayManager::GetInstance().GetDefaultDisplayId();
|
||||
std::shared_ptr<ScreenRegion> screenRegion = std::make_shared<ScreenRegion>(remoteDevId, screenId, displayId);
|
||||
screenRegion->SetVideoParam(videoParam);
|
||||
screenRegion->SetMapRelation(mapRelation);
|
||||
|
||||
int32_t ret = DH_SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(screenRegionsMtx_);
|
||||
if (screenRegions_.count(remoteDevId) != 0) {
|
||||
ret = screenRegions_[remoteDevId]->Stop();
|
||||
}
|
||||
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("screenRegion stop failed, remoteDevId: %s, err: %d",
|
||||
GetAnonyString(screenRegions_[remoteDevId]->GetRemoteDevId()).c_str(), ret);
|
||||
NotifyRemoteSourceSetUpResult(remoteDevId, dhId, ERR_DH_SCREEN_SA_SCREENREGION_SETUP_FAIL, "");
|
||||
return;
|
||||
}
|
||||
screenRegions_[remoteDevId] = screenRegion;
|
||||
}
|
||||
|
||||
ret = screenRegion->SetUp();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("screen region start 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;
|
||||
}
|
||||
|
||||
NotifyRemoteSourceSetUpResult(remoteDevId, dhId, DH_SUCCESS, "");
|
||||
}
|
||||
|
||||
void ScreenRegionManager::NotifyRemoteSourceSetUpResult(const std::string &remoteDevId, const std::string &dhId,
|
||||
int32_t errCode, const std::string &errContent)
|
||||
{
|
||||
DHLOGI("NotifyRemoteSourceSetUpResult, sourceDevId: %s, dhId: %s, errCode: %d",
|
||||
GetAnonyString(remoteDevId).c_str(), GetAnonyString(dhId).c_str(), errCode);
|
||||
int32_t eventCode = NOTIFY_SOURCE_SETUP_RESULT;
|
||||
|
||||
json eventContentJson;
|
||||
eventContentJson[KEY_DH_ID] = dhId;
|
||||
eventContentJson[KEY_ERR_CODE] = errCode;
|
||||
eventContentJson[KEY_ERR_CONTENT] = errContent;
|
||||
|
||||
std::string eventContent = eventContentJson.dump();
|
||||
|
||||
NotifyRemoteScreenService(remoteDevId, dhId, eventCode, eventContent);
|
||||
}
|
||||
|
||||
int32_t ScreenRegionManager::NotifyRemoteScreenService(const std::string &remoteDevId, const std::string &dhId,
|
||||
int32_t eventCode, const std::string &eventContent)
|
||||
{
|
||||
DHLOGI("Notify remote source screen service, remote devId: %s, eventCode: %d",
|
||||
GetAnonyString(remoteDevId).c_str(), eventCode);
|
||||
sptr<IDScreenSource> remoteSourceSA = GetDScreenSourceSA(remoteDevId);
|
||||
if (!remoteSourceSA) {
|
||||
DHLOGE("get remote source sa failed.");
|
||||
return ERR_DH_SCREEN_SA_GET_REMOTE_SOURCE_SERVICE_FAIL;
|
||||
}
|
||||
std::string localDevId;
|
||||
int32_t ret = GetLocalDeviceNetworkId(localDevId);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("notify remote screen service failed, cannot get local device id");
|
||||
return ret;
|
||||
}
|
||||
remoteSourceSA->DScreenNotify(localDevId, eventCode, eventContent);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
sptr<IDScreenSource> ScreenRegionManager::GetDScreenSourceSA(const std::string &devId)
|
||||
{
|
||||
DHLOGI("GetDScreenSourceSA, devId: %s", GetAnonyString(devId).c_str());
|
||||
sptr<ISystemAbilityManager> samgr =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (samgr == nullptr) {
|
||||
DHLOGE("Failed to get system ability mgr.");
|
||||
return nullptr;
|
||||
}
|
||||
auto remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, devId);
|
||||
if (remoteObject == nullptr) {
|
||||
DHLOGE("remoteObject is null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sptr<IDScreenSource> remoteSourceSA = iface_cast<IDScreenSource>(remoteObject);
|
||||
if (remoteSourceSA == nullptr) {
|
||||
DHLOGE("Failed to get remote dscreen source sa");
|
||||
return nullptr;
|
||||
}
|
||||
return remoteSourceSA;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,83 @@
|
||||
# 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("//build/ohos_var.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 += [
|
||||
"./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",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"${common_path}:distributed_screen_utils",
|
||||
"${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans",
|
||||
"//foundation/graphic/standard/frameworks/surface:surface",
|
||||
"${windowmanager_path}/interfaces/innerkits:wm_interface",
|
||||
"${windowmanager_path}/dm:libdm",
|
||||
]
|
||||
|
||||
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",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_H
|
||||
#define OHOS_DSCREEN_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "iscreen_source_trans.h"
|
||||
#include "iscreen_source_trans_callback.h"
|
||||
#include "video_param.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreen;
|
||||
class IDScreenCallback {
|
||||
public:
|
||||
virtual ~IDScreenCallback() {};
|
||||
virtual void OnRegResult(const std::shared_ptr<DScreen> &dScreen,
|
||||
const std::string &reqId, int32_t status, const std::string &data) = 0;
|
||||
virtual void OnUnregResult(const std::shared_ptr<DScreen> &dScreen,
|
||||
const std::string &reqId, int32_t status, const std::string &data) = 0;
|
||||
};
|
||||
|
||||
class ScreenSourceTransCallback : public IScreenSourceTransCallback {
|
||||
public:
|
||||
~ScreenSourceTransCallback() override {};
|
||||
virtual void OnTransError(int32_t err, const std::string &content) = 0;
|
||||
virtual void OnError(int32_t err, const std::string &content) override
|
||||
{
|
||||
OnTransError(err, content);
|
||||
}
|
||||
};
|
||||
|
||||
class Task {
|
||||
public:
|
||||
Task(TaskType taskType, const std::string &taskId, const std::string &taskParam) : taskType_(taskType),
|
||||
taskId_(taskId), taskParam_(taskParam) {};
|
||||
Task(TaskType taskType, const std::string &taskParam) : taskType_(taskType),
|
||||
taskId_(""), taskParam_(taskParam) {};
|
||||
~Task() {};
|
||||
|
||||
TaskType GetTaskType()
|
||||
{
|
||||
return taskType_;
|
||||
};
|
||||
std::string GetTaskId()
|
||||
{
|
||||
return taskId_;
|
||||
};
|
||||
std::string GetTaskParam()
|
||||
{
|
||||
return taskParam_;
|
||||
};
|
||||
|
||||
private:
|
||||
TaskType taskType_;
|
||||
std::string taskId_;
|
||||
std::string taskParam_;
|
||||
};
|
||||
|
||||
class DScreen : public ScreenSourceTransCallback, public std::enable_shared_from_this<DScreen> {
|
||||
public:
|
||||
~DScreen();
|
||||
DScreen(const std::string &devId, const std::string &dhId, std::shared_ptr<IDScreenCallback> dscreenCallback);
|
||||
void OnTransError(int32_t err, const std::string &content) override;
|
||||
|
||||
void SetVideoParam(std::shared_ptr<VideoParam> &videoParam);
|
||||
std::shared_ptr<VideoParam> GetVideoParam();
|
||||
void SetState(DScreenState state);
|
||||
DScreenState GetState() const;
|
||||
uint64_t GetScreenId() const;
|
||||
std::string GetDHId() const;
|
||||
std::string GetDevId() const;
|
||||
int32_t AddTask(const std::shared_ptr<Task> &task);
|
||||
|
||||
private:
|
||||
void TaskThreadLoop();
|
||||
void HandleTask(const std::shared_ptr<Task> &task);
|
||||
void HandleEnable(const std::string ¶m, const std::string &taskId);
|
||||
void HandleDisable(const std::string &taskId);
|
||||
void HandleConnect();
|
||||
void HandleDisconnect();
|
||||
int32_t SetUp();
|
||||
int32_t Start();
|
||||
int32_t Stop();
|
||||
|
||||
static constexpr uint8_t TASK_WAIT_SECONDS = 1;
|
||||
|
||||
std::string devId_;
|
||||
std::string dhId_;
|
||||
uint64_t screenId_ = SCREEN_ID_INVALID;
|
||||
std::shared_ptr<VideoParam> videoParam_ = nullptr;
|
||||
std::shared_ptr<IScreenSourceTrans> sourceTrans_ = nullptr;
|
||||
std::shared_ptr<IDScreenCallback> dscreenCallback_ = nullptr;
|
||||
|
||||
DScreenState curState_;
|
||||
std::mutex stateMtx_;
|
||||
std::thread taskQueueThread_;
|
||||
std::condition_variable taskQueueCond_;
|
||||
std::mutex taskQueueMtx_;
|
||||
std::queue<std::shared_ptr<Task>> taskQueue_;
|
||||
bool taskThreadRunning_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_MGR_H
|
||||
#define OHOS_DSCREEN_MGR_H
|
||||
|
||||
#include "dm_common.h"
|
||||
#include "single_instance.h"
|
||||
#include "screen_manager.h"
|
||||
|
||||
#include "dscreen.h"
|
||||
#include "dscreen_maprelation.h"
|
||||
#include "idscreen_sink.h"
|
||||
#include "idscreen_source_callback.h"
|
||||
#include "video_param.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenCallback : public IDScreenCallback {
|
||||
public:
|
||||
void OnRegResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId,
|
||||
int32_t status, const std::string &data) override;
|
||||
void OnUnregResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId,
|
||||
int32_t status, const std::string &data) override;
|
||||
};
|
||||
|
||||
class DScreenManager : public Rosen::ScreenManager::IScreenGroupListener,
|
||||
public std::enable_shared_from_this<DScreenManager> {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DScreenManager);
|
||||
public:
|
||||
void OnChange(const std::vector<uint64_t> &screenIds, Rosen::ScreenGroupChangeEvent event) override;
|
||||
|
||||
void OnRegResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId,
|
||||
int32_t status, const std::string &data);
|
||||
void OnUnregResult(const std::shared_ptr<DScreen> &dScreen, const std::string &reqId,
|
||||
int32_t status, const std::string &data);
|
||||
|
||||
int32_t Init();
|
||||
int32_t UnInit();
|
||||
int32_t EnableDistributedScreen(const std::string &devId, const std::string &dhId, const std::string ¶m,
|
||||
const std::string &reqId);
|
||||
int32_t DisableDistributedScreen(const std::string &devId, const std::string &dhId, const std::string &reqId);
|
||||
void HandleDScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent);
|
||||
void RegisterDScreenCallback(const sptr<IDScreenSourceCallback> &callback);
|
||||
|
||||
private:
|
||||
~DScreenManager();
|
||||
DScreenManager();
|
||||
std::mutex dScreenMapMtx_;
|
||||
std::mutex dScreenMapRelationMtx_;
|
||||
std::map<uint64_t, std::shared_ptr<DScreenMapRelation>> mapRelations_;
|
||||
std::map<std::string, std::shared_ptr<DScreen>> dScreens_;
|
||||
sptr<IDScreenSourceCallback> dScreenSourceCallbackProxy_ = nullptr;
|
||||
std::shared_ptr<IDScreenCallback> dScreenCallback_ = nullptr;
|
||||
|
||||
void HandleScreenChange(const std::shared_ptr<DScreen> &changedScreen, Rosen::ScreenGroupChangeEvent event);
|
||||
std::shared_ptr<DScreen> FindDScreenByScreenId(uint64_t screenId);
|
||||
sptr<IDScreenSink> GetDScreenSinkSA(const std::string &devId);
|
||||
int32_t NotifyRemoteScreenService(const std::string &devId, int32_t eventCode, const std::string &eventContent);
|
||||
void NotifyRemoteSinkSetUp(const std::shared_ptr<DScreen> &dScreen);
|
||||
void HandleNotifySetUpResult(const std::string &remoteDevId, const std::string &eventContent);
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 OHOS_SCREEN_MGR_ADAPTER_H
|
||||
#define OHOS_SCREEN_MGR_ADAPTER_H
|
||||
|
||||
#include <surface.h>
|
||||
|
||||
#include "single_instance.h"
|
||||
#include "screen_manager.h"
|
||||
|
||||
#include "dscreen_maprelation.h"
|
||||
#include "video_param.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ScreenMgrAdapter {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(ScreenMgrAdapter);
|
||||
|
||||
public:
|
||||
uint64_t CreateVirtualScreen(const std::string &devId, const std::string &dhId,
|
||||
const std::shared_ptr<VideoParam> &videoParam);
|
||||
int32_t RegisterScreenGroupListener(sptr<Rosen::ScreenManager::IScreenGroupListener> listener);
|
||||
int32_t UnregisterScreenGroupListener(sptr<Rosen::ScreenManager::IScreenGroupListener> listener);
|
||||
int32_t RemoveVirtualScreen(uint64_t screenId);
|
||||
int32_t SetImageSurface(uint64_t screenId, sptr<OHOS::Surface> surface);
|
||||
std::shared_ptr<DScreenMapRelation> GetMapRelation(uint64_t screenId);
|
||||
void RemoveScreenFromGroup(uint64_t screenId);
|
||||
|
||||
private:
|
||||
ScreenMgrAdapter() = default;
|
||||
~ScreenMgrAdapter();
|
||||
|
||||
bool listenerRegistered = false;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,348 @@
|
||||
/*
|
||||
* 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 "dscreen.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_util.h"
|
||||
#include "screen_manager_adapter.h"
|
||||
#include "screen_source_trans.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
DScreen::DScreen(const std::string &devId, const std::string &dhId,
|
||||
std::shared_ptr<IDScreenCallback> dscreenCallback)
|
||||
{
|
||||
DHLOGD("DScreen construct, devId: %s, dhId: %s", GetAnonyString(devId).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
devId_ = devId;
|
||||
dhId_ = dhId;
|
||||
dscreenCallback_ = dscreenCallback;
|
||||
SetState(DISABLED);
|
||||
taskThreadRunning_ = true;
|
||||
taskQueueThread_ = std::thread(&DScreen::TaskThreadLoop, this);
|
||||
}
|
||||
|
||||
DScreen::~DScreen()
|
||||
{
|
||||
DHLOGD("DScreen deconstruct, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str());
|
||||
taskThreadRunning_ = false;
|
||||
taskQueueCond_.notify_all();
|
||||
if (taskQueueThread_.joinable()) {
|
||||
taskQueueThread_.join();
|
||||
}
|
||||
int32_t ret = DH_SUCCESS;
|
||||
if (sourceTrans_) {
|
||||
ret = sourceTrans_->Release();
|
||||
}
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("source trans release failed. ret: %d", ret);
|
||||
}
|
||||
|
||||
if (screenId_ != SCREEN_ID_INVALID) {
|
||||
ret = ScreenMgrAdapter::GetInstance().RemoveVirtualScreen(screenId_);
|
||||
}
|
||||
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("remove virtual screen failed.");
|
||||
}
|
||||
videoParam_ = nullptr;
|
||||
sourceTrans_ = nullptr;
|
||||
DHLOGD("DScreen deconstruct end.");
|
||||
}
|
||||
|
||||
void DScreen::OnTransError(int32_t err, const std::string &content)
|
||||
{
|
||||
DHLOGD("OnTransError, err: %d", err);
|
||||
AddTask(std::make_shared<Task>(TaskType::TASK_DISCONNECT, ""));
|
||||
ScreenMgrAdapter::GetInstance().RemoveScreenFromGroup(screenId_);
|
||||
}
|
||||
|
||||
void DScreen::SetVideoParam(std::shared_ptr<VideoParam> &videoParam)
|
||||
{
|
||||
videoParam_ = videoParam;
|
||||
}
|
||||
|
||||
std::shared_ptr<VideoParam> DScreen::GetVideoParam()
|
||||
{
|
||||
return videoParam_;
|
||||
}
|
||||
|
||||
void DScreen::SetState(DScreenState state)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(stateMtx_);
|
||||
curState_ = state;
|
||||
}
|
||||
|
||||
DScreenState DScreen::GetState() const
|
||||
{
|
||||
return curState_;
|
||||
}
|
||||
|
||||
uint64_t DScreen::GetScreenId() const
|
||||
{
|
||||
return screenId_;
|
||||
}
|
||||
|
||||
std::string DScreen::GetDHId() const
|
||||
{
|
||||
return dhId_;
|
||||
}
|
||||
|
||||
std::string DScreen::GetDevId() const
|
||||
{
|
||||
return devId_;
|
||||
}
|
||||
|
||||
int32_t DScreen::AddTask(const std::shared_ptr<Task> &task)
|
||||
{
|
||||
DHLOGI("DScreen::AddTask, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str());
|
||||
if (!task) {
|
||||
DHLOGE("AddTask, task is invalid.");
|
||||
return ERR_DH_SCREEN_SA_DSCREEN_TASK_NOT_VALID;
|
||||
}
|
||||
DHLOGI("AddTask, task type: %d", task->GetTaskType());
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(taskQueueMtx_);
|
||||
taskQueue_.push(task);
|
||||
}
|
||||
taskQueueCond_.notify_all();
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DScreen::TaskThreadLoop()
|
||||
{
|
||||
DHLOGI("DScreen taskThread start. devId: %s, dhId: %s", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str());
|
||||
while (taskThreadRunning_) {
|
||||
std::shared_ptr<Task> task;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(taskQueueMtx_);
|
||||
taskQueueCond_.wait_for(lock, std::chrono::seconds(TASK_WAIT_SECONDS),
|
||||
[this]() { return !taskQueue_.empty(); });
|
||||
if (taskQueue_.empty()) {
|
||||
continue;
|
||||
}
|
||||
task = taskQueue_.front();
|
||||
taskQueue_.pop();
|
||||
}
|
||||
|
||||
if (task == nullptr) {
|
||||
DHLOGD("task is null.");
|
||||
continue;
|
||||
}
|
||||
|
||||
DHLOGD("run task, task queue size: %zu", taskQueue_.size());
|
||||
HandleTask(task);
|
||||
}
|
||||
}
|
||||
|
||||
void DScreen::HandleTask(const std::shared_ptr<Task> &task)
|
||||
{
|
||||
int32_t taskType = task->GetTaskType();
|
||||
DHLOGI("HandleTask, devId: %s, dhId: %s, task type: %d", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str(), taskType);
|
||||
switch (taskType) {
|
||||
case TaskType::TASK_ENABLE:
|
||||
HandleEnable(task->GetTaskParam(), task->GetTaskId());
|
||||
break;
|
||||
case TaskType::TASK_DISABLE:
|
||||
HandleDisable(task->GetTaskId());
|
||||
break;
|
||||
case TaskType::TASK_CONNECT:
|
||||
HandleConnect();
|
||||
break;
|
||||
case TaskType::TASK_DISCONNECT:
|
||||
HandleDisconnect();
|
||||
break;
|
||||
default:
|
||||
DHLOGD("task type unkown.");
|
||||
}
|
||||
}
|
||||
|
||||
void DScreen::HandleEnable(const std::string ¶m, const std::string &taskId)
|
||||
{
|
||||
DHLOGI("HandleEnable, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
|
||||
if (curState_ == ENABLED || curState_ == ENABLING ||
|
||||
curState_ == CONNECTING || curState_ == CONNECTED) {
|
||||
dscreenCallback_->OnRegResult(shared_from_this(), taskId, DH_SUCCESS, "");
|
||||
return;
|
||||
}
|
||||
|
||||
SetState(ENABLING);
|
||||
if (!videoParam_) {
|
||||
videoParam_ = std::make_shared<VideoParam>();
|
||||
}
|
||||
|
||||
json attrJson = json::parse(param, nullptr, false);
|
||||
if (attrJson.is_discarded()) {
|
||||
DHLOGE("enable param json is invalid.");
|
||||
dscreenCallback_->OnRegResult(shared_from_this(), taskId, ERR_DH_SCREEN_SA_ENABLE_FAILED,
|
||||
"enable param json is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!attrJson.contains(KEY_SCREEN_WIDTH) ||
|
||||
!attrJson.contains(KEY_SCREEN_HEIGHT) ||
|
||||
!attrJson.contains(KEY_CODECTYPE)) {
|
||||
DHLOGE("enable param is invalid.");
|
||||
dscreenCallback_->OnRegResult(shared_from_this(), taskId, ERR_DH_SCREEN_SA_ENABLE_FAILED,
|
||||
"enable param is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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.");
|
||||
}
|
||||
screenId_ = screenId;
|
||||
SetState(ENABLED);
|
||||
dscreenCallback_->OnRegResult(shared_from_this(), taskId, DH_SUCCESS, "");
|
||||
}
|
||||
|
||||
void DScreen::HandleDisable(const std::string &taskId)
|
||||
{
|
||||
DHLOGI("HandleDisable, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str());
|
||||
SetState(DISABLING);
|
||||
Stop();
|
||||
int32_t ret = ScreenMgrAdapter::GetInstance().RemoveVirtualScreen(screenId_);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("remove virtual screen failed.");
|
||||
dscreenCallback_->OnUnregResult(shared_from_this(), taskId, ERR_DH_SCREEN_SA_DISABLE_FAILED,
|
||||
"remove virtual screen failed.");
|
||||
return;
|
||||
}
|
||||
SetState(DISABLED);
|
||||
dscreenCallback_->OnUnregResult(shared_from_this(), taskId, DH_SUCCESS, "");
|
||||
}
|
||||
|
||||
void DScreen::HandleConnect()
|
||||
{
|
||||
DHLOGI("HandleConnect, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str());
|
||||
|
||||
int32_t ret = SetUp();
|
||||
if (ret != DH_SUCCESS) {
|
||||
SetState(ENABLED);
|
||||
ScreenMgrAdapter::GetInstance().RemoveScreenFromGroup(screenId_);
|
||||
DHLOGE("dScreen SetUp failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
ret = Start();
|
||||
if (ret != DH_SUCCESS) {
|
||||
SetState(ENABLED);
|
||||
ScreenMgrAdapter::GetInstance().RemoveScreenFromGroup(screenId_);
|
||||
DHLOGE("dScreen Start failed.");
|
||||
return;
|
||||
}
|
||||
SetState(CONNECTED);
|
||||
}
|
||||
|
||||
void DScreen::HandleDisconnect()
|
||||
{
|
||||
DHLOGD("HandleDisconnect, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str());
|
||||
if (curState_ != CONNECTED) {
|
||||
DHLOGE("dscreen is not connected, cannot disconnect");
|
||||
return;
|
||||
}
|
||||
SetState(DISCONNECTING);
|
||||
int32_t ret = Stop();
|
||||
if (ret != DH_SUCCESS) {
|
||||
SetState(CONNECTED);
|
||||
DHLOGE("dScreen Stop failed.");
|
||||
return;
|
||||
}
|
||||
SetState(ENABLED);
|
||||
}
|
||||
|
||||
int32_t DScreen::SetUp()
|
||||
{
|
||||
DHLOGD("SetUp, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str());
|
||||
|
||||
if (!sourceTrans_) {
|
||||
sourceTrans_ = std::make_shared<ScreenSourceTrans>();
|
||||
}
|
||||
|
||||
sourceTrans_->RegisterStateCallback(shared_from_this());
|
||||
int32_t ret = sourceTrans_->SetUp(*videoParam_, *videoParam_, devId_);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("source trans SetUp failed.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
sptr<OHOS::Surface> surface = sourceTrans_->GetImageSurface();
|
||||
|
||||
ScreenMgrAdapter::GetInstance().SetImageSurface(screenId_, surface);
|
||||
DHLOGI("DScreen SetUp success.");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreen::Start()
|
||||
{
|
||||
DHLOGD("Start, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str());
|
||||
if (!sourceTrans_) {
|
||||
DHLOGE("source trans not init.");
|
||||
return ERR_DH_SCREEN_SA_SOURCETRANS_NOT_INIT;
|
||||
}
|
||||
|
||||
int32_t ret = sourceTrans_->Start();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("source trans start failed.");
|
||||
return ret;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreen::Stop()
|
||||
{
|
||||
DHLOGD("Stop, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(),
|
||||
GetAnonyString(dhId_).c_str());
|
||||
if (!sourceTrans_) {
|
||||
DHLOGE("source trans not init.");
|
||||
return ERR_DH_SCREEN_SA_SOURCETRANS_NOT_INIT;
|
||||
}
|
||||
|
||||
int32_t ret = sourceTrans_->Stop();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("source trans stop failed.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = sourceTrans_->Release();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("source trans release failed.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
sourceTrans_ = nullptr;
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,400 @@
|
||||
/*
|
||||
* 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 "dscreen_manager.h"
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_util.h"
|
||||
#include "idscreen_sink.h"
|
||||
#include "screen_manager_adapter.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DScreenManager);
|
||||
DScreenManager::DScreenManager()
|
||||
{
|
||||
DHLOGI("DScreenMgr construct.");
|
||||
}
|
||||
|
||||
DScreenManager::~DScreenManager()
|
||||
{
|
||||
DHLOGI("DScreenMgr deConstruct.");
|
||||
}
|
||||
|
||||
int32_t DScreenManager::Init()
|
||||
{
|
||||
DHLOGI("DScreenManager::Init");
|
||||
int32_t ret = ScreenMgrAdapter::GetInstance().RegisterScreenGroupListener(this);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("DScreenManager Init failed, err: %d", ret);
|
||||
}
|
||||
if (!dScreenCallback_) {
|
||||
dScreenCallback_ = std::make_shared<DScreenCallback>();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenManager::UnInit()
|
||||
{
|
||||
DHLOGI("DScreenManager::UnInit");
|
||||
int32_t ret = ScreenMgrAdapter::GetInstance().UnregisterScreenGroupListener(this);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("DScreenManager UnInit failed, err: %d", ret);
|
||||
}
|
||||
dScreenCallback_ = nullptr;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(dScreenMapMtx_);
|
||||
dScreens_.clear();
|
||||
}
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(dScreenMapRelationMtx_);
|
||||
mapRelations_.clear();
|
||||
}
|
||||
DHLOGI("DScreenManager::UnInit success");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DScreenManager::OnChange(const std::vector<uint64_t> &screenIds, Rosen::ScreenGroupChangeEvent event)
|
||||
{
|
||||
DHLOGI("On Screen change, screenIds size: %d", screenIds.size());
|
||||
for (uint64_t screenId : screenIds) {
|
||||
std::shared_ptr<DScreen> changedScreen = nullptr;
|
||||
changedScreen = FindDScreenByScreenId(screenId);
|
||||
if (!changedScreen) {
|
||||
DHLOGD("screen change not about remote screen, screenId: %ulld", screenId);
|
||||
continue;
|
||||
}
|
||||
HandleScreenChange(changedScreen, event);
|
||||
}
|
||||
}
|
||||
|
||||
void DScreenManager::HandleScreenChange(const std::shared_ptr<DScreen> &changedScreen,
|
||||
Rosen::ScreenGroupChangeEvent event)
|
||||
{
|
||||
if (!changedScreen) {
|
||||
DHLOGE("DScreenManager::HandleScreenChange, dScreen is null.");
|
||||
return;
|
||||
}
|
||||
uint64_t screenId = changedScreen->GetScreenId();
|
||||
DHLOGI("DScreenManager::HandleScreenChange, screenId: %ulld, changeEvent: %", screenId, event);
|
||||
if (event == Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP) {
|
||||
if (changedScreen->GetState() == CONNECTING) {
|
||||
DHLOGD("screen is connecting, no need handle change");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<DScreenMapRelation> mapRelation =
|
||||
ScreenMgrAdapter::GetInstance().GetMapRelation(screenId);
|
||||
if (!mapRelation) {
|
||||
DHLOGE("mapRelation construct failed. screenId: %ulld", screenId);
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<VideoParam> videoParam = changedScreen->GetVideoParam();
|
||||
DisplayRect displayRect = mapRelation->GetDisplayRect();
|
||||
videoParam->SetVideoWidth(displayRect.width);
|
||||
videoParam->SetVideoHeight(displayRect.height);
|
||||
changedScreen->SetState(CONNECTING);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(dScreenMapRelationMtx_);
|
||||
mapRelations_[screenId] = mapRelation;
|
||||
}
|
||||
NotifyRemoteSinkSetUp(changedScreen);
|
||||
} else if (event == Rosen::ScreenGroupChangeEvent::REMOVE_FROM_GROUP) {
|
||||
if (changedScreen->GetState() == DISCONNECTING) {
|
||||
DHLOGD("screen is disconnecting, no need handle change");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<DScreenMapRelation> mapRelation = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(dScreenMapRelationMtx_);
|
||||
if (mapRelations_.count(screenId) == 0) {
|
||||
DHLOGE("destroyed relation not found.");
|
||||
return;
|
||||
}
|
||||
mapRelation = mapRelations_[screenId];
|
||||
mapRelations_.erase(screenId);
|
||||
}
|
||||
changedScreen->AddTask(std::make_shared<Task>(TaskType::TASK_DISCONNECT, ""));
|
||||
} else if (event == Rosen::ScreenGroupChangeEvent::CHANGE_GROUP) {
|
||||
DHLOGE("CHANGE_GROUP not implement.");
|
||||
} else {
|
||||
DHLOGE("unknown change type.");
|
||||
}
|
||||
}
|
||||
|
||||
void DScreenCallback::OnRegResult(const std::shared_ptr<DScreen> &dScreen,
|
||||
const std::string &reqId, int32_t status, const std::string &data)
|
||||
{
|
||||
DHLOGI("DScreenCallback::OnRegResult, devId: %s, dhId: %s, reqId: %s",
|
||||
GetAnonyString(dScreen->GetDevId()).c_str(), GetAnonyString(dScreen->GetDHId()).c_str(), reqId.c_str());
|
||||
DScreenManager::GetInstance().OnRegResult(dScreen, reqId, status, data);
|
||||
}
|
||||
|
||||
void DScreenCallback::OnUnregResult(const std::shared_ptr<DScreen> &dScreen,
|
||||
const std::string &reqId, int32_t status, const std::string &data)
|
||||
{
|
||||
DHLOGI("DScreenCallback::OnUnregResult, devId: %s, dhId: %s, reqId: %s",
|
||||
GetAnonyString(dScreen->GetDevId()).c_str(), GetAnonyString(dScreen->GetDHId()).c_str(), reqId.c_str());
|
||||
DScreenManager::GetInstance().OnUnregResult(dScreen, reqId, status, data);
|
||||
}
|
||||
|
||||
void DScreenManager::OnRegResult(const std::shared_ptr<DScreen> &dScreen,
|
||||
const std::string &reqId, int32_t status, const std::string &data)
|
||||
{
|
||||
DHLOGI("DScreenManager::OnRegResult, devId: %s, dhId: %s, reqId: %s",
|
||||
GetAnonyString(dScreen->GetDevId()).c_str(), GetAnonyString(dScreen->GetDHId()).c_str(), reqId.c_str());
|
||||
if (!dScreenSourceCallbackProxy_) {
|
||||
DHLOGE("dScreenSourceCallbackProxy is null");
|
||||
return;
|
||||
}
|
||||
dScreenSourceCallbackProxy_->OnNotifyRegResult(dScreen->GetDevId(), dScreen->GetDHId(), reqId, status, data);
|
||||
}
|
||||
|
||||
void DScreenManager::OnUnregResult(const std::shared_ptr<DScreen> &dScreen,
|
||||
const std::string &reqId, int32_t status, const std::string &data)
|
||||
{
|
||||
DHLOGI("DScreenManager::OnUnregResult, devId: %s, dhId: %s, reqId: %s",
|
||||
GetAnonyString(dScreen->GetDevId()).c_str(), GetAnonyString(dScreen->GetDHId()).c_str(), reqId.c_str());
|
||||
if (!dScreenSourceCallbackProxy_) {
|
||||
DHLOGE("dScreenSourceCallbackProxy is null");
|
||||
return;
|
||||
}
|
||||
dScreenSourceCallbackProxy_->OnNotifyUnregResult(dScreen->GetDevId(), dScreen->GetDHId(), reqId, status, data);
|
||||
}
|
||||
|
||||
int32_t DScreenManager::EnableDistributedScreen(const std::string &devId, const std::string &dhId,
|
||||
const std::string &attrs, const std::string &reqId)
|
||||
{
|
||||
DHLOGI("EnableDistributedScreen, devId: %s, dhId:%s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
std::string dScreenIdx = devId + SEPERATOR + dhId;
|
||||
std::shared_ptr<DScreen> dScreen = nullptr;
|
||||
if (dScreens_.count(dScreenIdx) != 0) {
|
||||
dScreen = dScreens_[dScreenIdx];
|
||||
}
|
||||
|
||||
if (dScreen == nullptr) {
|
||||
dScreen = std::make_shared<DScreen>(devId, dhId, dScreenCallback_);
|
||||
}
|
||||
|
||||
int32_t dScreenState = dScreen->GetState();
|
||||
if (dScreenState != DISABLED && dScreenState != DISABLING) {
|
||||
DHLOGE("dScreen state is invalid.");
|
||||
return ERR_DH_SCREEN_SA_ENABLE_FAILED;
|
||||
}
|
||||
|
||||
dScreens_[dScreenIdx] = dScreen;
|
||||
int32_t ret = dScreen->AddTask(std::make_shared<Task>(TaskType::TASK_ENABLE, reqId, attrs));
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("EnableDistributedScreen, add task failed. devId: %s, dhId:%s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenManager::DisableDistributedScreen(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId)
|
||||
{
|
||||
DHLOGI("DisableDistributedScreen, devId: %s, dhId:%s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
|
||||
std::string dScreenIdx = devId + SEPERATOR + dhId;
|
||||
if (dScreens_.count(dScreenIdx) == 0) {
|
||||
DHLOGE("dscreen not found, devId: %s, dhId: %s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
|
||||
return ERR_DH_SCREEN_SA_DISABLE_FAILED;
|
||||
}
|
||||
|
||||
int32_t dScreenState = dScreens_[dScreenIdx]->GetState();
|
||||
int32_t ret = DH_SUCCESS;
|
||||
switch (dScreenState) {
|
||||
case DISABLED:
|
||||
case DISABLING:
|
||||
DHLOGE("dScreen state is invalid.");
|
||||
ret = ERR_DH_SCREEN_SA_DISABLE_FAILED;
|
||||
break;
|
||||
case ENABLED:
|
||||
case ENABLING:
|
||||
ret = dScreens_[dScreenIdx]->AddTask(std::make_shared<Task>(TaskType::TASK_DISABLE, reqId, ""));
|
||||
break;
|
||||
case CONNECTING:
|
||||
case CONNECTED:
|
||||
case DISCONNECTING:
|
||||
ret = dScreens_[dScreenIdx]->AddTask(std::make_shared<Task>(TaskType::TASK_DISCONNECT, ""));
|
||||
if (ret == DH_SUCCESS) {
|
||||
ret = dScreens_[dScreenIdx]->AddTask(std::make_shared<Task>(TaskType::TASK_DISABLE, reqId, ""));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = ERR_DH_SCREEN_SA_DISABLE_FAILED;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DScreenManager::RegisterDScreenCallback(const sptr<IDScreenSourceCallback> &callback)
|
||||
{
|
||||
DHLOGI("RegisterDScreenCallback");
|
||||
dScreenSourceCallbackProxy_ = callback;
|
||||
}
|
||||
|
||||
std::shared_ptr<DScreen> DScreenManager::FindDScreenByScreenId(uint64_t screenId)
|
||||
{
|
||||
DHLOGD("FindDScreenByScreenId, screenId: %ulld", screenId);
|
||||
std::lock_guard<std::mutex> lock(dScreenMapMtx_);
|
||||
for (const auto &iter : dScreens_) {
|
||||
std::shared_ptr<DScreen> dScreen = iter.second;
|
||||
if (!dScreen) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dScreen->GetScreenId() == screenId) {
|
||||
return dScreen;
|
||||
}
|
||||
}
|
||||
DHLOGD("DScreen not found, screenId: %ulld", screenId);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DScreenManager::HandleDScreenNotify(const std::string &devId, int32_t eventCode,
|
||||
const std::string &eventContent)
|
||||
{
|
||||
DHLOGI("HandleDScreenNotify, devId: %s, eventCode: %d", GetAnonyString(devId).c_str(), eventCode);
|
||||
if (eventCode == NOTIFY_SOURCE_SETUP_RESULT) {
|
||||
HandleNotifySetUpResult(devId, eventContent);
|
||||
return;
|
||||
}
|
||||
|
||||
DHLOGE("invalid eventCode, eventCode: %d", eventCode);
|
||||
}
|
||||
|
||||
int32_t DScreenManager::NotifyRemoteScreenService(const std::string &devId, int32_t eventCode,
|
||||
const std::string &eventContent)
|
||||
{
|
||||
DHLOGI("Notify remote sink screen service, remote devId: %s, eventCode: %d",
|
||||
GetAnonyString(devId).c_str(), eventCode);
|
||||
sptr<IDScreenSink> remoteSinkSA = GetDScreenSinkSA(devId);
|
||||
if (!remoteSinkSA) {
|
||||
DHLOGE("get remote sink sa failed.");
|
||||
return ERR_DH_SCREEN_SA_GET_REMOTE_SINK_SERVICE_FAIL;
|
||||
}
|
||||
std::string localDevId;
|
||||
int32_t ret = GetLocalDeviceNetworkId(localDevId);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("notify remote screen service failed, cannot get local device id");
|
||||
return ret;
|
||||
}
|
||||
remoteSinkSA->DScreenNotify(localDevId, eventCode, eventContent);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
sptr<IDScreenSink> DScreenManager::GetDScreenSinkSA(const std::string &devId)
|
||||
{
|
||||
DHLOGI("GetDScreenSinkSA, devId: %s", GetAnonyString(devId).c_str());
|
||||
sptr<ISystemAbilityManager> samgr =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (!samgr) {
|
||||
DHLOGE("Failed to get system ability mgr.");
|
||||
return nullptr;
|
||||
}
|
||||
auto remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, devId);
|
||||
if (remoteObject == nullptr) {
|
||||
DHLOGE("remoteObject is null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sptr<IDScreenSink> remoteSinkSA = iface_cast<IDScreenSink>(remoteObject);
|
||||
if (remoteSinkSA == nullptr) {
|
||||
DHLOGE("Failed to get remote dscreen sink sa");
|
||||
return nullptr;
|
||||
}
|
||||
return remoteSinkSA;
|
||||
}
|
||||
|
||||
void DScreenManager::NotifyRemoteSinkSetUp(const std::shared_ptr<DScreen> &dScreen)
|
||||
{
|
||||
DHLOGI("NotifyRemoteSinkSetUp");
|
||||
int32_t eventCode = NOTIFY_SINK_SETUP;
|
||||
std::string devId = dScreen->GetDevId();
|
||||
json eventContentJson;
|
||||
eventContentJson[KEY_SCREEN_ID] = dScreen->GetScreenId();
|
||||
eventContentJson[KEY_DH_ID] = dScreen->GetDHId();
|
||||
if (dScreen->GetVideoParam() == nullptr) {
|
||||
DHLOGE("videoParam is null, back to enabled state screedId: %ulld", dScreen->GetScreenId());
|
||||
dScreen->SetState(ENABLED);
|
||||
return;
|
||||
}
|
||||
eventContentJson[KEY_VIDEO_PARAM] = *(dScreen->GetVideoParam());
|
||||
|
||||
if (mapRelations_.count(dScreen->GetScreenId()) == 0) {
|
||||
DHLOGE("mapRelation not found, back to enabled state screedId: %ulld", dScreen->GetScreenId());
|
||||
dScreen->SetState(ENABLED);
|
||||
return;
|
||||
}
|
||||
eventContentJson[KEY_MAPRELATION] = *(mapRelations_[dScreen->GetScreenId()]);
|
||||
|
||||
std::string eventContent = eventContentJson.dump();
|
||||
DHLOGD("start notify remote screen, eventContent: %s", eventContent.c_str());
|
||||
NotifyRemoteScreenService(devId, eventCode, eventContent);
|
||||
}
|
||||
|
||||
void DScreenManager::HandleNotifySetUpResult(const std::string &remoteDevId, const std::string &eventContent)
|
||||
{
|
||||
DHLOGI("HandleNotifySetUpResult, remoteDevId:%s", GetAnonyString(remoteDevId).c_str());
|
||||
json eventContentJson = json::parse(eventContent, nullptr, false);
|
||||
if (eventContentJson.is_discarded()) {
|
||||
DHLOGE("HandleNotifySetUpResult, eventContent is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!eventContentJson.contains(KEY_DH_ID) ||
|
||||
!eventContentJson.contains(KEY_ERR_CODE) ||
|
||||
!eventContentJson.contains(KEY_ERR_CONTENT)) {
|
||||
DHLOGE("HandleNotifySetUpResult, eventContent is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string dhId = eventContentJson[KEY_DH_ID];
|
||||
int32_t errCode = eventContentJson[KEY_ERR_CODE];
|
||||
std::string errContent = eventContentJson[KEY_ERR_CONTENT];
|
||||
|
||||
std::string dScreenIdx = remoteDevId + SEPERATOR + dhId;
|
||||
if (dScreens_.count(dScreenIdx) == 0) {
|
||||
DHLOGE("dScreen not found, remoteDevId:%s, dhId:%s",
|
||||
GetAnonyString(remoteDevId).c_str(), GetAnonyString(dhId).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (errCode != DH_SUCCESS) {
|
||||
DHLOGE("remote sink set up failed, errCode: %d, reason: %s", errCode, errContent.c_str());
|
||||
dScreens_[dScreenIdx]->SetState(ENABLED);
|
||||
return;
|
||||
}
|
||||
|
||||
dScreens_[dScreenIdx]->AddTask(std::make_shared<Task>(TaskType::TASK_CONNECT, ""));
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 "screen_manager_adapter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "display_manager.h"
|
||||
#include "dm_common.h"
|
||||
#include "screen.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
IMPLEMENT_SINGLE_INSTANCE(ScreenMgrAdapter);
|
||||
ScreenMgrAdapter::~ScreenMgrAdapter()
|
||||
{
|
||||
DHLOGI("~ScreenMgrAdapter");
|
||||
}
|
||||
|
||||
uint64_t ScreenMgrAdapter::CreateVirtualScreen(const std::string &devId, const std::string &dhId,
|
||||
const std::shared_ptr<VideoParam> &videoParam)
|
||||
{
|
||||
DHLOGI("CreateVirtualScreen, width: %u, height: %u", videoParam->GetScreenWidth(),
|
||||
videoParam->GetScreenHeight());
|
||||
std::string screenName = DSCREEN_PREFIX + SEPERATOR + devId + SEPERATOR + dhId;
|
||||
Rosen::VirtualScreenOption option = {
|
||||
screenName,
|
||||
videoParam->GetScreenWidth(),
|
||||
videoParam->GetScreenHeight(),
|
||||
DEFAULT_DENSITY,
|
||||
nullptr,
|
||||
DEFAULT_SCREEN_FLAGS,
|
||||
false
|
||||
};
|
||||
|
||||
uint64_t screenId = Rosen::ScreenManager::GetInstance().CreateVirtualScreen(option);
|
||||
return screenId;
|
||||
}
|
||||
|
||||
int32_t ScreenMgrAdapter::RegisterScreenGroupListener(sptr<Rosen::ScreenManager::IScreenGroupListener> listener)
|
||||
{
|
||||
DHLOGI("RegisterScreenGroupListener");
|
||||
if (listenerRegistered) {
|
||||
DHLOGI("already registered listener.");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
bool ret = Rosen::ScreenManager::GetInstance().RegisterScreenGroupListener(listener);
|
||||
if (!ret) {
|
||||
DHLOGE("RegisterScreenGroupListener Failed.");
|
||||
return ERR_DH_SCREEN_SA_REGISTER_SCREENLISTENER_FAIL;
|
||||
}
|
||||
listenerRegistered = true;
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenMgrAdapter::UnregisterScreenGroupListener(sptr<Rosen::ScreenManager::IScreenGroupListener> listener)
|
||||
{
|
||||
DHLOGI("UnregisterScreenGroupListener");
|
||||
if (!listenerRegistered) {
|
||||
DHLOGI("listener already unregistered.");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
bool ret = Rosen::ScreenManager::GetInstance().UnregisterScreenGroupListener(listener);
|
||||
if (!ret) {
|
||||
DHLOGE("UnregisterScreenGroupListener Failed.");
|
||||
return ERR_DH_SCREEN_SA_UNREGISTER_SCREENLISTENER_FAIL;
|
||||
}
|
||||
listenerRegistered = false;
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void ScreenMgrAdapter::RemoveScreenFromGroup(uint64_t screenId)
|
||||
{
|
||||
DHLOGI("remove screen from group, screenId: %ulld", screenId);
|
||||
std::vector<uint64_t> screenIds;
|
||||
screenIds.push_back(screenId);
|
||||
Rosen::ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(screenIds);
|
||||
}
|
||||
|
||||
int32_t ScreenMgrAdapter::RemoveVirtualScreen(uint64_t screenId)
|
||||
{
|
||||
DHLOGI("remove virtual screen");
|
||||
Rosen::DMError err = Rosen::ScreenManager::GetInstance().DestroyVirtualScreen(screenId);
|
||||
if (err != Rosen::DMError::DM_OK) {
|
||||
DHLOGE("remove virtual screen failed, screenId:%ulld", screenId);
|
||||
return ERR_DH_SCREEN_SA_REMOVE_VIRTUALSCREEN_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenMgrAdapter::SetImageSurface(uint64_t screenId, sptr<OHOS::Surface> surface)
|
||||
{
|
||||
DHLOGI("SetImageSurface for virtualscreen, screenId: %ulld", screenId);
|
||||
Rosen::ScreenManager::GetInstance().SetVirtualScreenSurface(screenId, surface);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
std::shared_ptr<DScreenMapRelation> ScreenMgrAdapter::GetMapRelation(uint64_t screenId)
|
||||
{
|
||||
DHLOGI("GetMapRelation");
|
||||
std::shared_ptr<DScreenMapRelation> mapRelation = std::make_shared<DScreenMapRelation>();
|
||||
sptr<Rosen::Screen> screen = Rosen::ScreenManager::GetInstance().GetScreenById(screenId);
|
||||
sptr<Rosen::Display> display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
|
||||
mapRelation->SetDisplayId(display->GetId());
|
||||
mapRelation->SetScreenId(screenId);
|
||||
|
||||
ScreenRect screenRect = {0, 0, screen->GetWidth(), screen->GetHeight()};
|
||||
DisplayRect displayRect = {0, 0, display->GetWidth(), display->GetHeight()};
|
||||
mapRelation->SetDisplayRect(displayRect);
|
||||
mapRelation->SetScreenRect(screenRect);
|
||||
return mapRelation;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SOURCE_CALLBACK_PROXY_H
|
||||
#define OHOS_DSCREEN_SOURCE_CALLBACK_PROXY_H
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
#include "idscreen_source_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSourceCallbackProxy : public IRemoteProxy<IDScreenSourceCallback> {
|
||||
public:
|
||||
explicit DScreenSourceCallbackProxy(const sptr<IRemoteObject> impl)
|
||||
: IRemoteProxy<IDScreenSourceCallback>(impl)
|
||||
{
|
||||
}
|
||||
|
||||
~DScreenSourceCallbackProxy() {}
|
||||
int32_t OnNotifyRegResult(const std::string &devId, const std::string &dhId, const std::string &reqId,
|
||||
int32_t status, const std::string &resultData) override;
|
||||
int32_t OnNotifyUnregResult(const std::string &devId, const std::string &dhId, const std::string &reqId,
|
||||
int32_t status, const std::string &resultData) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<DScreenSourceCallbackProxy> delegator_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -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 OHOS_DSCREEN_SOURCE_SERVICE_H
|
||||
#define OHOS_DSCREEN_SOURCE_SERVICE_H
|
||||
|
||||
#include "system_ability.h"
|
||||
#include "ipc_object_stub.h"
|
||||
|
||||
#include "dscreen_manager.h"
|
||||
#include "dscreen_source_stub.h"
|
||||
#include "idscreen_source_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSourceService : public SystemAbility, public DScreenSourceStub,
|
||||
public std::enable_shared_from_this<DScreenSourceService> {
|
||||
DECLARE_SYSTEM_ABILITY(DScreenSourceService);
|
||||
public:
|
||||
DScreenSourceService(int32_t saId, bool runOnCreate);
|
||||
~DScreenSourceService();
|
||||
int32_t InitSource(const std::string ¶ms, const sptr<IDScreenSourceCallback> &callback) override;
|
||||
int32_t ReleaseSource() override;
|
||||
int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const EnableParam ¶m, const std::string &reqId) override;
|
||||
int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId) override;
|
||||
int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key,
|
||||
const std::string &value) override;
|
||||
void DScreenNotify(const std::string &devId, const int32_t eventCode, const std::string &eventContent) override;
|
||||
|
||||
protected:
|
||||
void OnStart() override;
|
||||
void OnStop() override;
|
||||
DISALLOW_COPY_AND_MOVE(DScreenSourceService);
|
||||
|
||||
private:
|
||||
bool Init();
|
||||
|
||||
sptr<IDScreenSourceCallback> dScreenSourceCallbackProxy_ = nullptr;
|
||||
bool registerToService_ = false;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 OHOS_DSCREEN_SOURCE_STUB_H
|
||||
#define OHOS_DSCREEN_SOURCE_STUB_H
|
||||
|
||||
#include <map>
|
||||
#include "iremote_stub.h"
|
||||
#include "idscreen_source.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSourceStub : public IRemoteStub<IDScreenSource> {
|
||||
public:
|
||||
DScreenSourceStub();
|
||||
virtual ~DScreenSourceStub();
|
||||
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option) override;
|
||||
|
||||
private:
|
||||
int32_t InitSourceInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
int32_t ReleaseSourceInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
int32_t RegisterDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
int32_t UnregisterDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
int32_t ConfigDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
int32_t DScreenNotifyInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
|
||||
using DScreenSourceFunc = int32_t (DScreenSourceStub::*)(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option);
|
||||
std::map<int32_t, DScreenSourceFunc> memberFuncMap_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 "dscreen_source_callback_proxy.h"
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
int32_t DScreenSourceCallbackProxy::OnNotifyRegResult(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId, int32_t status, const std::string &resultData)
|
||||
{
|
||||
DHLOGD("OnNotifyRegResult, devId: %s, dhId: %s, reqId: %s, status: %d",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), reqId.c_str(), status);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
if (!data.WriteString(devId) || !data.WriteString(dhId) ||
|
||||
!data.WriteString(reqId) || !data.WriteInt32(status) ||
|
||||
!data.WriteString(resultData)) {
|
||||
DHLOGE("Write param failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
|
||||
}
|
||||
|
||||
Remote()->SendRequest(NOTIFY_REG_RESULT, data, reply, option);
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t DScreenSourceCallbackProxy::OnNotifyUnregResult(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId, int32_t status, const std::string &resultData)
|
||||
{
|
||||
DHLOGD("OnNotifyUnregResult, devId: %s, dhId: %s, reqId: %s, status: %d",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), reqId.c_str(), status);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
DHLOGE("WriteInterfaceToken failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
|
||||
}
|
||||
|
||||
if (!data.WriteString(devId) || !data.WriteString(dhId) ||
|
||||
!data.WriteString(reqId) || !data.WriteInt32(status) ||
|
||||
!data.WriteString(resultData)) {
|
||||
DHLOGE("Write param failed.");
|
||||
return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
|
||||
}
|
||||
|
||||
Remote()->SendRequest(NOTIFY_UNREG_RESULT, data, reply, option);
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* 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 "dscreen_source_service.h"
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ipc_types.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
REGISTER_SYSTEM_ABILITY_BY_ID(DScreenSourceService, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, true);
|
||||
|
||||
DScreenSourceService::DScreenSourceService(int32_t saId, bool runOnCreate) : SystemAbility(saId, runOnCreate)
|
||||
{
|
||||
DHLOGI("dscreen source service create.");
|
||||
}
|
||||
|
||||
DScreenSourceService::~DScreenSourceService()
|
||||
{
|
||||
DHLOGI("~DScreenSourceService.");
|
||||
}
|
||||
|
||||
void DScreenSourceService::OnStart()
|
||||
{
|
||||
DHLOGI("dscreen source service start.");
|
||||
Init();
|
||||
}
|
||||
|
||||
void DScreenSourceService::OnStop()
|
||||
{
|
||||
DHLOGI("dscreen source service stop.");
|
||||
dScreenSourceCallbackProxy_ = nullptr;
|
||||
registerToService_ = false;
|
||||
}
|
||||
|
||||
bool DScreenSourceService::Init()
|
||||
{
|
||||
DHLOGI("dscreen source service start init.");
|
||||
if (!registerToService_) {
|
||||
bool ret = Publish(this);
|
||||
if (!ret) {
|
||||
DHLOGE("dscreen source publish service failed.");
|
||||
return false;
|
||||
}
|
||||
registerToService_ = true;
|
||||
}
|
||||
DHLOGI("dscreen init success.");
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceService::InitSource(const std::string ¶ms, const sptr<IDScreenSourceCallback> &callback)
|
||||
{
|
||||
DHLOGI("InitSource");
|
||||
dScreenSourceCallbackProxy_ = callback;
|
||||
int32_t ret = DScreenManager::GetInstance().Init();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("Init DScreenManager failed. err: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
DScreenManager::GetInstance().RegisterDScreenCallback(callback);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceService::ReleaseSource()
|
||||
{
|
||||
DHLOGI("ReleaseSource");
|
||||
dScreenSourceCallbackProxy_ = nullptr;
|
||||
int32_t ret = DScreenManager::GetInstance().UnInit();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("UnInit DScreenManager failed. err: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceService::RegisterDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const EnableParam ¶m, const std::string &reqId)
|
||||
{
|
||||
DHLOGI("RegisterDistributedHardware");
|
||||
std::string version = param.version;
|
||||
std::string attrs = param.attrs;
|
||||
DHLOGD("enable distributedScreen. devId: %s, dhId: %s, reqId: %s, attrs: %s, version: %s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), reqId.c_str(), attrs.c_str(), version.c_str());
|
||||
int ret = DScreenManager::GetInstance().EnableDistributedScreen(devId, dhId, attrs, reqId);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("enable distributedScreen failed. devId: %s, dhId: %s, reqId: %s, attrs: %s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), reqId.c_str(), attrs.c_str());
|
||||
return ERR_DH_SCREEN_SA_ENABLE_FAILED;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceService::UnregisterDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const std::string &reqId)
|
||||
{
|
||||
DHLOGI("UnregisterDistributedHardware");
|
||||
int ret = DScreenManager::GetInstance().DisableDistributedScreen(devId, dhId, reqId);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("disable distributedScreen failed. devId: %s, dhId: %s, reqId: %s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), reqId.c_str());
|
||||
return ERR_DH_SCREEN_SA_DISABLE_FAILED;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceService::ConfigDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const std::string &key, const std::string &value)
|
||||
{
|
||||
DHLOGI("ConfigDistributedHardware");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DScreenSourceService::DScreenNotify(const std::string &devId, const int32_t eventCode,
|
||||
const std::string &eventContent)
|
||||
{
|
||||
DHLOGI("DScreenNotify, devId: %s, eventCode: %d", GetAnonyString(devId).c_str(), eventCode);
|
||||
DScreenManager::GetInstance().HandleDScreenNotify(devId, eventCode, eventContent);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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 "dscreen_source_stub.h"
|
||||
|
||||
#include "iservice_registry.h"
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_source_callback_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
DScreenSourceStub::DScreenSourceStub()
|
||||
{
|
||||
DHLOGI("DScreenSourceStub construct.");
|
||||
memberFuncMap_[INIT_SOURCE] = &DScreenSourceStub::InitSourceInner;
|
||||
memberFuncMap_[RELEASE_SOURCE] = &DScreenSourceStub::ReleaseSourceInner;
|
||||
memberFuncMap_[REGISTER_DISTRIBUTED_HARDWARE] = &DScreenSourceStub::RegisterDistributedHardwareInner;
|
||||
memberFuncMap_[UNREGISTER_DISTRIBUTED_HARDWARE] = &DScreenSourceStub::UnregisterDistributedHardwareInner;
|
||||
memberFuncMap_[CONFIG_DISTRIBUTED_HARDWARE] = &DScreenSourceStub::ConfigDistributedHardwareInner;
|
||||
memberFuncMap_[DSCREEN_NOTIFY] = &DScreenSourceStub::DScreenNotifyInner;
|
||||
}
|
||||
|
||||
DScreenSourceStub::~DScreenSourceStub()
|
||||
{
|
||||
DHLOGI("DScreenSourceStub deconstruct.");
|
||||
}
|
||||
|
||||
int32_t DScreenSourceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("OnRemoteRequest, code: %d", code);
|
||||
std::u16string desc = DScreenSourceStub::GetDescriptor();
|
||||
std::u16string remoteDesc = data.ReadInterfaceToken();
|
||||
if (desc != remoteDesc) {
|
||||
DHLOGE("DScreenSourceStub::OnRemoteRequest remoteDesc is invalid!");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
|
||||
std::map<int32_t, DScreenSourceFunc>::iterator iter = memberFuncMap_.find(code);
|
||||
if (iter == memberFuncMap_.end()) {
|
||||
DHLOGE("invalid request code.");
|
||||
return ERR_DH_SCREEN_SA_REQUEST_CODE_INVALID;
|
||||
}
|
||||
DScreenSourceFunc &func = iter->second;
|
||||
return (this->*func)(data, reply, option);
|
||||
}
|
||||
|
||||
int32_t DScreenSourceStub::InitSourceInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("InitSourceInner");
|
||||
std::string param = data.ReadString();
|
||||
sptr<IRemoteObject> remoteObject = data.ReadRemoteObject();
|
||||
if (remoteObject == nullptr) {
|
||||
DHLOGE("Read param failed.");
|
||||
return ERR_DH_SCREEN_SA_READPARAM_FAILED;
|
||||
}
|
||||
|
||||
sptr<DScreenSourceCallbackProxy> dScreenSourceCallbackProxy(new DScreenSourceCallbackProxy(remoteObject));
|
||||
int32_t ret = InitSource(param, dScreenSourceCallbackProxy);
|
||||
reply.WriteInt32(ret);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceStub::ReleaseSourceInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("ReleaseSourceInner");
|
||||
int32_t ret = ReleaseSource();
|
||||
reply.WriteInt32(ret);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceStub::RegisterDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("RegisterDistributedHardwareInner");
|
||||
std::string devId = data.ReadString();
|
||||
std::string dhId = data.ReadString();
|
||||
std::string version = data.ReadString();
|
||||
std::string attrs = data.ReadString();
|
||||
std::string reqId = data.ReadString();
|
||||
EnableParam enableParam;
|
||||
enableParam.version = version;
|
||||
enableParam.attrs = attrs;
|
||||
|
||||
int32_t ret = RegisterDistributedHardware(devId, dhId, enableParam, reqId);
|
||||
reply.WriteInt32(ret);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceStub::UnregisterDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("RegisterDistributedHardwareInner");
|
||||
std::string devId = data.ReadString();
|
||||
std::string dhId = data.ReadString();
|
||||
std::string reqId = data.ReadString();
|
||||
|
||||
int32_t ret = UnregisterDistributedHardware(devId, dhId, reqId);
|
||||
reply.WriteInt32(ret);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceStub::ConfigDistributedHardwareInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("ConfigDistributedHardwareInner");
|
||||
std::string devId = data.ReadString();
|
||||
std::string dhId = data.ReadString();
|
||||
std::string key = data.ReadString();
|
||||
std::string value = data.ReadString();
|
||||
|
||||
int32_t ret = ConfigDistributedHardware(devId, dhId, key, value);
|
||||
reply.WriteInt32(ret);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSourceStub::DScreenNotifyInner(MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
DHLOGI("DScreenNotifyInner");
|
||||
std::string devId = data.ReadString();
|
||||
int32_t eventCode = data.ReadInt32();
|
||||
std::string eventContent = data.ReadString();
|
||||
|
||||
DScreenNotify(devId, eventCode, eventContent);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 OHOS_SCREEN_DATA_CHANNEL_IMPL_H
|
||||
#define OHOS_SCREEN_DATA_CHANNEL_IMPL_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "data_buffer.h"
|
||||
#include "iscreen_channel.h"
|
||||
#include "softbus_adapter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ScreenDataChannelImpl : public IScreenChannel,
|
||||
public ISoftbusListener,
|
||||
public std::enable_shared_from_this<ScreenDataChannelImpl> {
|
||||
public:
|
||||
ScreenDataChannelImpl(std::string peerDevId) : peerDevId_(peerDevId) {};
|
||||
~ScreenDataChannelImpl() = default;
|
||||
|
||||
int32_t CreateSession(const std::shared_ptr<IScreenChannelListener> &listener) override;
|
||||
int32_t ReleaseSession() override;
|
||||
int32_t OpenSession() override;
|
||||
int32_t CloseSession() override;
|
||||
int32_t SendData(const std::shared_ptr<DataBuffer> &screenData) override;
|
||||
|
||||
void OnSessionOpened(int32_t sessionId, int32_t result) override;
|
||||
void OnSessionClosed(int32_t sessionId) override;
|
||||
void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) override;
|
||||
void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext,
|
||||
const StreamFrameInfo *param) override;
|
||||
|
||||
private:
|
||||
static const constexpr char *LOG_TAG = "ScreenDataChannel";
|
||||
|
||||
const std::string peerDevId_;
|
||||
int32_t sessionId_ = 0;
|
||||
std::weak_ptr<IScreenChannelListener> channelListener_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* 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 "screen_data_channel_impl.h"
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
int32_t ScreenDataChannelImpl::CreateSession(const std::shared_ptr<IScreenChannelListener> &listener)
|
||||
{
|
||||
DHLOGI("%s: CreateSession, peerDevId(%s)", LOG_TAG, GetAnonyString(peerDevId_).c_str());
|
||||
if (!listener) {
|
||||
DHLOGE("%s: Channel listener is null", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret =
|
||||
SoftbusAdapter::GetInstance().CreateSoftbusSessionServer(PKG_NAME, DATA_SESSION_NAME, peerDevId_);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: Create softbus session failed ret: %d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<ISoftbusListener> softbusListener = shared_from_this();
|
||||
ret = SoftbusAdapter::GetInstance().RegisterSoftbusListener(softbusListener, DATA_SESSION_NAME, peerDevId_);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: Register softbus adapter listener failed ret: %d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
channelListener_ = listener;
|
||||
DHLOGI("%s: Create softbus session success.", LOG_TAG);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenDataChannelImpl::ReleaseSession()
|
||||
{
|
||||
DHLOGI("%s: ReleaseSession, peerDevId(%s)", LOG_TAG, GetAnonyString(peerDevId_).c_str());
|
||||
int32_t ret = SoftbusAdapter::GetInstance().RemoveSoftbusSessionServer(PKG_NAME, DATA_SESSION_NAME, peerDevId_);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: Release softbus session failed ret: %d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = SoftbusAdapter::GetInstance().UnRegisterSoftbusListener(DATA_SESSION_NAME, peerDevId_);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: UnRegister softbus adapter listener failed ret: %d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
DHLOGI("%s: Release softbus session success.", LOG_TAG);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenDataChannelImpl::OpenSession()
|
||||
{
|
||||
DHLOGI("%s: OpenSession, peerDevId(%s)", LOG_TAG, GetAnonyString(peerDevId_).c_str());
|
||||
int32_t sessionId =
|
||||
SoftbusAdapter::GetInstance().OpenSoftbusSession(DATA_SESSION_NAME, DATA_SESSION_NAME, peerDevId_);
|
||||
if (sessionId < 0) {
|
||||
DHLOGE("%s: Open screen session failed, ret: %d", LOG_TAG, sessionId);
|
||||
return ERR_DH_SCREEN_TRANS_ERROR;
|
||||
}
|
||||
sessionId_ = sessionId;
|
||||
|
||||
DHLOGI("%s: Open screen session success, sessionId(%d)", LOG_TAG, sessionId_);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenDataChannelImpl::CloseSession()
|
||||
{
|
||||
DHLOGI("%s: CloseSession, sessionId(%d)", LOG_TAG, sessionId_);
|
||||
if (sessionId_ == 0) {
|
||||
DHLOGD("%s: Session is not opened.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_SESSION_NOT_OPEN;
|
||||
}
|
||||
|
||||
int32_t ret = SoftbusAdapter::GetInstance().CloseSoftbusSession(sessionId_);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: Close screen session failed ret: %d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
sessionId_ = 0;
|
||||
|
||||
DHLOGI("%s: Close screen session success.", LOG_TAG);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ScreenDataChannelImpl::SendData(const std::shared_ptr<DataBuffer> &screenData)
|
||||
{
|
||||
DHLOGD("%s: SendData, sessionId(%d)", LOG_TAG, sessionId_);
|
||||
if (!screenData) {
|
||||
DHLOGE("%s: Screen data is null", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
StreamData data = {(char *)screenData->Data(), screenData->Capacity()};
|
||||
StreamData ext = {0};
|
||||
StreamFrameInfo frameInfo = {0};
|
||||
|
||||
int32_t ret = SoftbusAdapter::GetInstance().SendSoftbusStream(sessionId_, &data, &ext, &frameInfo);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: Send screen data failed ret: %d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void ScreenDataChannelImpl::OnSessionOpened(int32_t sessionId, int32_t result)
|
||||
{
|
||||
DHLOGI("%s: OnScreenSessionOpened, sessionId: %d, result: %d", LOG_TAG, sessionId, result);
|
||||
if (result != 0) {
|
||||
DHLOGE("Session open failed.", LOG_TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<IScreenChannelListener> listener = channelListener_.lock();
|
||||
if (!listener) {
|
||||
DHLOGE("%s: Channel listener is null", LOG_TAG);
|
||||
return;
|
||||
}
|
||||
listener->OnSessionOpened();
|
||||
sessionId_ = sessionId;
|
||||
}
|
||||
|
||||
void ScreenDataChannelImpl::OnSessionClosed(int32_t sessionId)
|
||||
{
|
||||
DHLOGI("%s: OnScreenSessionClosed, sessionId(%d).", LOG_TAG, sessionId);
|
||||
std::shared_ptr<IScreenChannelListener> listener = channelListener_.lock();
|
||||
if (!listener) {
|
||||
DHLOGE("%s: Channel listener is null", LOG_TAG);
|
||||
return;
|
||||
}
|
||||
listener->OnSessionClosed();
|
||||
}
|
||||
|
||||
void ScreenDataChannelImpl::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen)
|
||||
{
|
||||
(void) sessionId;
|
||||
(void) data;
|
||||
(void) dataLen;
|
||||
|
||||
DHLOGD("%s: OnScreenBytesReceived data channel not support yet.", LOG_TAG);
|
||||
}
|
||||
|
||||
void ScreenDataChannelImpl::OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext,
|
||||
const StreamFrameInfo *param)
|
||||
{
|
||||
(void)ext;
|
||||
(void)param;
|
||||
|
||||
if (data == nullptr) {
|
||||
DHLOGE("%s: Stream data is null.", LOG_TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<IScreenChannelListener> listener = channelListener_.lock();
|
||||
if (!listener) {
|
||||
DHLOGE("%s: Channel listener is null.", LOG_TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
DHLOGI("%s: OnScreenStreamReceived, sessionId(%d) dataSize(%zu).", LOG_TAG, sessionId, data->bufLen);
|
||||
auto dataBuffer = std::make_shared<DataBuffer>(data->bufLen);
|
||||
if (!dataBuffer) {
|
||||
DHLOGE("%s: DataBuffer is null.", LOG_TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t ret = memcpy_s(dataBuffer->Data(), dataBuffer->Capacity(), (uint8_t *)data->buf, data->bufLen);
|
||||
if (ret != EOK) {
|
||||
DHLOGE("%s: Data memcpy_s failed.", LOG_TAG);
|
||||
return;
|
||||
}
|
||||
listener->OnDataReceived(dataBuffer);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 OHOS_IMAGE_DECODER_CALLBACK_H
|
||||
#define OHOS_IMAGE_DECODER_CALLBACK_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "media_errors.h"
|
||||
#include "avcodec_common.h"
|
||||
#include "format.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ImageSinkDecoder;
|
||||
class ImageDecoderCallback : public Media::AVCodecCallback {
|
||||
public:
|
||||
explicit ImageDecoderCallback(const std::shared_ptr<ImageSinkDecoder> &decoder)
|
||||
: videoDecoder_(decoder) {};
|
||||
~ImageDecoderCallback() = default;
|
||||
|
||||
void OnError(Media::AVCodecErrorType errorType, int32_t errorCode) override;
|
||||
void OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, Media::AVCodecBufferFlag flag) override;
|
||||
void OnInputBufferAvailable(uint32_t index) override;
|
||||
void OnOutputFormatChanged(const Media::Format &format) override;
|
||||
|
||||
private:
|
||||
static const constexpr char *LOG_TAG = "ImageDecoderCallback";
|
||||
|
||||
std::weak_ptr<ImageSinkDecoder> videoDecoder_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 OHOS_IMAGE_SINK_DECODER_H
|
||||
#define OHOS_IMAGE_SINK_DECODER_H
|
||||
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <condition_variable>
|
||||
|
||||
#include "avsharedmemory.h"
|
||||
#include "avcodec_common.h"
|
||||
#include "avcodec_video_decoder.h"
|
||||
#include "media_errors.h"
|
||||
#include "format.h"
|
||||
#include "surface.h"
|
||||
|
||||
#include "data_buffer.h"
|
||||
#include "iimage_sink_processor_listener.h"
|
||||
#include "image_decoder_callback.h"
|
||||
#include "video_param.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ImageSinkDecoder : public std::enable_shared_from_this<ImageSinkDecoder> {
|
||||
public:
|
||||
ImageSinkDecoder(const std::shared_ptr<IImageSinkProcessorListener> &imageListener)
|
||||
: imageProcessorListener_(imageListener) {};
|
||||
~ImageSinkDecoder() = default;
|
||||
|
||||
int32_t ConfigureDecoder(const VideoParam &configParam);
|
||||
int32_t ReleaseDecoder();
|
||||
int32_t StartDecoder();
|
||||
int32_t StopDecoder();
|
||||
int32_t SetOutputSurface(sptr<Surface> &surface);
|
||||
int32_t InputScreenData(const std::shared_ptr<DataBuffer> &data);
|
||||
|
||||
void OnError(Media::AVCodecErrorType errorType, int32_t errorCode);
|
||||
void OnInputBufferAvailable(uint32_t index);
|
||||
void OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info, Media::AVCodecBufferFlag flag);
|
||||
void OnOutputFormatChanged(const Media::Format &format);
|
||||
|
||||
private:
|
||||
int32_t SetDecoderFormat(const VideoParam &configParam);
|
||||
int32_t InitVideoDecoder(const VideoParam &configParam);
|
||||
int32_t StartInputThread();
|
||||
int32_t StopInputThread();
|
||||
void DecodeScreenData();
|
||||
int32_t ProcessData(const std::shared_ptr<DataBuffer> &screenData, const int32_t bufferIndex);
|
||||
|
||||
private:
|
||||
static const constexpr char *LOG_TAG = "ImageSinkDecoder";
|
||||
static constexpr uint32_t DECODE_WAIT_MILLISECONDS = 5000;
|
||||
static constexpr size_t DATA_QUEUE_MAX_SIZE = 10;
|
||||
|
||||
std::mutex dataMutex_;
|
||||
std::mutex decodeMutex_;
|
||||
std::thread decodeThread_;
|
||||
std::condition_variable decodeCond_;
|
||||
|
||||
Media::Format imageFormat_;
|
||||
Media::AVCodecBufferInfo decoderBufferInfo_;
|
||||
|
||||
bool isDecoderReady_ = false;
|
||||
std::queue<std::shared_ptr<DataBuffer>> videoDataQueue_;
|
||||
std::queue<int32_t> bufferIndexQueue_;
|
||||
std::shared_ptr<Media::VideoDecoder> videoDecoder_;
|
||||
std::shared_ptr<Media::AVCodecCallback> decodeVideoCallback_;
|
||||
std::weak_ptr<IImageSinkProcessorListener> imageProcessorListener_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 "image_decoder_callback.h"
|
||||
|
||||
#include "dscreen_log.h"
|
||||
#include "image_sink_decoder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
void ImageDecoderCallback::OnError(Media::AVCodecErrorType errorType, int32_t errorCode)
|
||||
{
|
||||
DHLOGD("%s: OnError.", LOG_TAG);
|
||||
std::shared_ptr<ImageSinkDecoder> decoder = videoDecoder_.lock();
|
||||
if (decoder == nullptr) {
|
||||
DHLOGE("decoder is nullptr.");
|
||||
return;
|
||||
}
|
||||
decoder->OnError(errorType, errorCode);
|
||||
}
|
||||
|
||||
void ImageDecoderCallback::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info,
|
||||
Media::AVCodecBufferFlag flag)
|
||||
{
|
||||
DHLOGD("%s: OnOutputBufferAvailable.", LOG_TAG);
|
||||
std::shared_ptr<ImageSinkDecoder> decoder = videoDecoder_.lock();
|
||||
if (decoder == nullptr) {
|
||||
DHLOGE("decoder is nullptr.");
|
||||
return;
|
||||
}
|
||||
decoder->OnOutputBufferAvailable(index, info, flag);
|
||||
}
|
||||
|
||||
void ImageDecoderCallback::OnInputBufferAvailable(uint32_t index)
|
||||
{
|
||||
DHLOGD("%s: OnInputBufferAvailable.", LOG_TAG);
|
||||
std::shared_ptr<ImageSinkDecoder> decoder = videoDecoder_.lock();
|
||||
if (decoder == nullptr) {
|
||||
DHLOGE("decoder is nullptr.");
|
||||
return;
|
||||
}
|
||||
decoder->OnInputBufferAvailable(index);
|
||||
}
|
||||
|
||||
void ImageDecoderCallback::OnOutputFormatChanged(const Media::Format &format)
|
||||
{
|
||||
DHLOGD("%s: OnOutputFormatChanged.", LOG_TAG);
|
||||
std::shared_ptr<ImageSinkDecoder> decoder = videoDecoder_.lock();
|
||||
if (decoder == nullptr) {
|
||||
DHLOGE("decoder is nullptr.");
|
||||
return;
|
||||
}
|
||||
decoder->OnOutputFormatChanged(format);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* 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 "image_sink_decoder.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <securec.h>
|
||||
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
int32_t ImageSinkDecoder::ConfigureDecoder(const VideoParam &configParam)
|
||||
{
|
||||
DHLOGI("%s: ConfigureDecoder.", LOG_TAG);
|
||||
int32_t ret = InitVideoDecoder(configParam);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: InitVideoDecoder failed.", LOG_TAG);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = SetDecoderFormat(configParam);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: SetDecoderFormat failed.", LOG_TAG);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkDecoder::ReleaseDecoder()
|
||||
{
|
||||
DHLOGI("%s: ReleaseDecoder.", LOG_TAG);
|
||||
if (!videoDecoder_) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret = videoDecoder_->Release();
|
||||
if (ret != Media::MSERR_OK) {
|
||||
DHLOGE("%s: ReleaseDecoder failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_RELEASE_FAILED;
|
||||
}
|
||||
decodeVideoCallback_ = nullptr;
|
||||
videoDecoder_ = nullptr;
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkDecoder::StartDecoder()
|
||||
{
|
||||
DHLOGI("%s: StartDecoder.", LOG_TAG);
|
||||
if (!videoDecoder_) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret = videoDecoder_->Prepare();
|
||||
if (ret != Media::MSERR_OK) {
|
||||
DHLOGE("%s: Prepare decoder failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_PREPARE_FAILED;
|
||||
}
|
||||
|
||||
ret = videoDecoder_->Start();
|
||||
if (ret != Media::MSERR_OK) {
|
||||
DHLOGE("%s: Start decoder failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_START_FAILED;
|
||||
}
|
||||
StartInputThread();
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkDecoder::StopDecoder()
|
||||
{
|
||||
DHLOGI("%s: StopDecoder.", LOG_TAG);
|
||||
if (!videoDecoder_) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret = videoDecoder_->Flush();
|
||||
if (ret != Media::MSERR_OK) {
|
||||
DHLOGE("%s: Flush decoder failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_FLUSH_FAILED;
|
||||
}
|
||||
|
||||
ret = videoDecoder_->Stop();
|
||||
if (ret != Media::MSERR_OK) {
|
||||
DHLOGE("%s: Stop decoder failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_STOP_FAILED;
|
||||
}
|
||||
StopInputThread();
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkDecoder::InitVideoDecoder(const VideoParam &configParam)
|
||||
{
|
||||
DHLOGI("%s: InitVideoDecoder.", LOG_TAG);
|
||||
switch (configParam.GetCodecType()) {
|
||||
case VIDEO_CODEC_TYPE_VIDEO_H264:
|
||||
videoDecoder_ = Media::VideoDecoderFactory::CreateByName("OMX_hisi_video_decoder_avc");
|
||||
break;
|
||||
case VIDEO_CODEC_TYPE_VIDEO_H265:
|
||||
videoDecoder_ = Media::VideoDecoderFactory::CreateByMime("video/hevc");
|
||||
break;
|
||||
default:
|
||||
DHLOGE("%s: codecType is invalid!", LOG_TAG);
|
||||
videoDecoder_ = nullptr;
|
||||
}
|
||||
|
||||
if (videoDecoder_ == nullptr) {
|
||||
DHLOGE("%s: Create videoEncode failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
decodeVideoCallback_ = std::make_shared<ImageDecoderCallback>(shared_from_this());
|
||||
int32_t ret = videoDecoder_->SetCallback(decodeVideoCallback_);
|
||||
if (ret != Media::MSERR_OK) {
|
||||
DHLOGE("%s: Set decoder callback failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_SET_CALLBACK_FAILED;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkDecoder::SetDecoderFormat(const VideoParam &configParam)
|
||||
{
|
||||
DHLOGI("%s: SetDecoderFormat.", LOG_TAG);
|
||||
if (!videoDecoder_) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
switch (configParam.GetCodecType()) {
|
||||
case VIDEO_CODEC_TYPE_VIDEO_H264:
|
||||
imageFormat_.PutStringValue("codec_mime", "video/avc");
|
||||
break;
|
||||
case VIDEO_CODEC_TYPE_VIDEO_H265:
|
||||
imageFormat_.PutStringValue("codec_mime", "video/hevc");
|
||||
break;
|
||||
default:
|
||||
DHLOGE("The current codec type does not support decoding.");
|
||||
return ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION;
|
||||
}
|
||||
switch (configParam.GetVideoFormat()) {
|
||||
case VIDEO_DATA_FORMAT_YUVI420:
|
||||
imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::YUVI420);
|
||||
break;
|
||||
case VIDEO_DATA_FORMAT_NV12:
|
||||
imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV12);
|
||||
break;
|
||||
case VIDEO_DATA_FORMAT_NV21:
|
||||
imageFormat_.PutIntValue("pixel_format", Media::VideoPixelFormat::NV21);
|
||||
break;
|
||||
default:
|
||||
DHLOGE("The current pixel format does not support decoding.");
|
||||
return ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION;
|
||||
}
|
||||
|
||||
imageFormat_.PutLongValue("max_input_size", MAX_YUV420_BUFFER_SIZE);
|
||||
imageFormat_.PutIntValue("width", configParam.GetVideoWidth());
|
||||
imageFormat_.PutIntValue("height", configParam.GetVideoHeight());
|
||||
imageFormat_.PutIntValue("frame_rate", configParam.GetFps());
|
||||
|
||||
int32_t ret = videoDecoder_->Configure(imageFormat_);
|
||||
if (ret != Media::MSERR_OK) {
|
||||
DHLOGE("%s: configure decoder format param failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_CONFIGURE_FAILED;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkDecoder::SetOutputSurface(sptr<Surface> &surface)
|
||||
{
|
||||
DHLOGI("%s: SetOutputSurface.", LOG_TAG);
|
||||
if (!videoDecoder_) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret = videoDecoder_->SetOutputSurface(surface);
|
||||
if (ret != Media::MSERR_OK) {
|
||||
DHLOGE("%s: SetOutputSurface failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_SURFACE_ERROR;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkDecoder::InputScreenData(const std::shared_ptr<DataBuffer> &data)
|
||||
{
|
||||
DHLOGD("%s: InputScreenData.", LOG_TAG);
|
||||
std::lock_guard<std::mutex> dataLock(dataMutex_);
|
||||
while (videoDataQueue_.size() >= DATA_QUEUE_MAX_SIZE) {
|
||||
DHLOGE("%s: videoData queue overflow.", LOG_TAG);
|
||||
videoDataQueue_.pop();
|
||||
}
|
||||
videoDataQueue_.push(data);
|
||||
decodeCond_.notify_all();
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void ImageSinkDecoder::OnError(Media::AVCodecErrorType errorType, int32_t errorCode)
|
||||
{
|
||||
DHLOGI("%s: OnImageDecodeError, errorType(%d), errorCode(%d)", LOG_TAG, errorType, errorCode);
|
||||
std::shared_ptr<IImageSinkProcessorListener> listener = imageProcessorListener_.lock();
|
||||
if (!listener) {
|
||||
DHLOGE("%s: Listener is null.", LOG_TAG);
|
||||
return;
|
||||
}
|
||||
listener->OnProcessorStateNotify(errorCode);
|
||||
}
|
||||
|
||||
void ImageSinkDecoder::OnInputBufferAvailable(uint32_t index)
|
||||
{
|
||||
DHLOGI("%s: OnDecodeInputBufferAvailable: %u.", LOG_TAG, index);
|
||||
std::lock_guard<std::mutex> dataLock(dataMutex_);
|
||||
bufferIndexQueue_.push(index);
|
||||
}
|
||||
|
||||
void ImageSinkDecoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBufferInfo info,
|
||||
Media::AVCodecBufferFlag flag)
|
||||
{
|
||||
DHLOGI("%s: OnDecodeOutputBufferAvailable.", LOG_TAG);
|
||||
if (!videoDecoder_) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
decoderBufferInfo_ = info;
|
||||
int32_t ret = videoDecoder_->ReleaseOutputBuffer(index, true);
|
||||
if (ret != Media::MSERR_OK) {
|
||||
DHLOGD("%s: ReleaseOutputBuffer failed.", LOG_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageSinkDecoder::OnOutputFormatChanged(const Media::Format &format)
|
||||
{
|
||||
(void) format;
|
||||
}
|
||||
|
||||
int32_t ImageSinkDecoder::StartInputThread()
|
||||
{
|
||||
DHLOGI("%s: StartInputThread.", LOG_TAG);
|
||||
isDecoderReady_ = true;
|
||||
decodeThread_ = std::thread(&ImageSinkDecoder::DecodeScreenData, this);
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkDecoder::StopInputThread()
|
||||
{
|
||||
DHLOGI("%s: StopInputThread.", LOG_TAG);
|
||||
isDecoderReady_ = false;
|
||||
decodeThread_.join();
|
||||
std::lock_guard<std::mutex> dataLock(dataMutex_);
|
||||
while (!bufferIndexQueue_.empty()) {
|
||||
bufferIndexQueue_.pop();
|
||||
}
|
||||
while (!videoDataQueue_.empty()) {
|
||||
videoDataQueue_.pop();
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void ImageSinkDecoder::DecodeScreenData()
|
||||
{
|
||||
while (isDecoderReady_) {
|
||||
std::shared_ptr<DataBuffer> screenData;
|
||||
int32_t bufferIndex = 0;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(dataMutex_);
|
||||
decodeCond_.wait_for(lock, std::chrono::milliseconds(DECODE_WAIT_MILLISECONDS),
|
||||
[this]() { return (!videoDataQueue_.empty() && !bufferIndexQueue_.empty()); });
|
||||
|
||||
if (videoDataQueue_.empty() || bufferIndexQueue_.empty()) {
|
||||
DHLOGD("%s: Index queue or data queue is empty.", LOG_TAG);
|
||||
continue;
|
||||
}
|
||||
bufferIndex = bufferIndexQueue_.front();
|
||||
bufferIndexQueue_.pop();
|
||||
screenData = videoDataQueue_.front();
|
||||
videoDataQueue_.pop();
|
||||
}
|
||||
|
||||
int32_t ret = ProcessData(screenData, bufferIndex);
|
||||
if (ret == ERR_DH_SCREEN_TRANS_NULL_VALUE) {
|
||||
return;
|
||||
} else if (ret != DH_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ImageSinkDecoder::ProcessData(const std::shared_ptr<DataBuffer> &screenData, const int32_t bufferIndex)
|
||||
{
|
||||
if (!videoDecoder_) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
auto inputBuffer = videoDecoder_->GetInputBuffer(bufferIndex);
|
||||
if (inputBuffer == nullptr) {
|
||||
DHLOGE("%s: GetInputBuffer failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_SURFACE_ERROR;
|
||||
}
|
||||
|
||||
int32_t ret = memcpy_s(inputBuffer->GetBase(), inputBuffer->GetSize(), screenData->Data(), screenData->Capacity());
|
||||
if (ret != EOK) {
|
||||
DHLOGE("%s: Copy data failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_SURFACE_ERROR;
|
||||
}
|
||||
|
||||
DHLOGD("%s: Decode screen data.", LOG_TAG);
|
||||
Media::AVCodecBufferInfo bufferInfo;
|
||||
bufferInfo.presentationTimeUs = 0;
|
||||
bufferInfo.size = static_cast<int32_t>(screenData->Capacity());
|
||||
bufferInfo.offset = 0;
|
||||
ret = videoDecoder_->QueueInputBuffer(bufferIndex, bufferInfo, Media::AVCODEC_BUFFER_FLAG_NONE);
|
||||
if (ret != Media::MSERR_OK) {
|
||||
DHLOGE("%s: QueueInputBuffer failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_CODEC_SURFACE_ERROR;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 OHOS_IIMAGE_SINK_PROCESSOR_H
|
||||
#define OHOS_IIMAGE_SINK_PROCESSOR_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "surface.h"
|
||||
|
||||
#include "data_buffer.h"
|
||||
#include "video_param.h"
|
||||
#include "iimage_sink_processor_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class IImageSinkProcessor {
|
||||
public:
|
||||
virtual ~IImageSinkProcessor() = default;
|
||||
|
||||
virtual int32_t ConfigureImageProcessor(const VideoParam &localParam, const VideoParam &remoteParam,
|
||||
const std::shared_ptr<IImageSinkProcessorListener> &listener) = 0;
|
||||
virtual int32_t ReleaseImageProcessor() = 0;
|
||||
virtual int32_t StartImageProcessor() = 0;
|
||||
virtual int32_t StopImageProcessor() = 0;
|
||||
virtual int32_t SetImageSurface(sptr<Surface> &surface) = 0;
|
||||
virtual int32_t ProcessImage(const std::shared_ptr<DataBuffer> &data) = 0;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 OHOS_IIMAGE_SINK_PROCESSOR_LISTENER_H
|
||||
#define OHOS_IIMAGE_SINK_PROCESSOR_LISTENER_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class IImageSinkProcessorListener {
|
||||
public:
|
||||
virtual ~IImageSinkProcessorListener() = default;
|
||||
|
||||
virtual void OnProcessorStateNotify(int32_t state) = 0;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namsspace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 IMAGE_SINK_PROCESSOR_H
|
||||
#define IMAGE_SINK_PROCESSOR_H
|
||||
|
||||
#include "iimage_sink_processor.h"
|
||||
#include "image_sink_decoder.h"
|
||||
#include "video_param.h"
|
||||
#include "data_buffer.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ImageSinkProcessor : public IImageSinkProcessor {
|
||||
public:
|
||||
ImageSinkProcessor() = default;
|
||||
~ImageSinkProcessor() = default;
|
||||
|
||||
int32_t ConfigureImageProcessor(const VideoParam &localParam, const VideoParam &remoteParam,
|
||||
const std::shared_ptr<IImageSinkProcessorListener> &imageListener) override;
|
||||
int32_t ReleaseImageProcessor() override;
|
||||
int32_t StartImageProcessor() override;
|
||||
int32_t StopImageProcessor() override;
|
||||
int32_t SetImageSurface(sptr<Surface> &surface) override;
|
||||
int32_t ProcessImage(const std::shared_ptr<DataBuffer> &data) override;
|
||||
|
||||
private:
|
||||
static const constexpr char *LOG_TAG = "ImageSinkProcessor";
|
||||
VideoParam localParam_;
|
||||
VideoParam remoteParam_;
|
||||
std::shared_ptr<ImageSinkDecoder> imageDecoder_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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 "image_sink_processor.h"
|
||||
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
int32_t ImageSinkProcessor::ConfigureImageProcessor(
|
||||
const VideoParam &localParam, const VideoParam &remoteParam,
|
||||
const std::shared_ptr<IImageSinkProcessorListener> &imageListener)
|
||||
{
|
||||
DHLOGI("%s: ConfigureImageProcessor.", LOG_TAG);
|
||||
localParam_ = localParam;
|
||||
remoteParam_ = remoteParam;
|
||||
|
||||
imageDecoder_ = std::make_shared<ImageSinkDecoder>(imageListener);
|
||||
if (imageDecoder_ == nullptr) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret = imageDecoder_->ConfigureDecoder(localParam);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: ConfigureDecoder failed ret:%d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkProcessor::ReleaseImageProcessor()
|
||||
{
|
||||
DHLOGI("%s: ReleaseImageProcessor.", LOG_TAG);
|
||||
if (imageDecoder_ == nullptr) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret = imageDecoder_->ReleaseDecoder();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: ReleaseDecoder failed.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_ERROR;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkProcessor::StartImageProcessor()
|
||||
{
|
||||
DHLOGI("%s: StartImageProcessor.", LOG_TAG);
|
||||
if (imageDecoder_ == nullptr) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret = imageDecoder_->StartDecoder();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: StartDecoder failed ret:%d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkProcessor::StopImageProcessor()
|
||||
{
|
||||
DHLOGI("%s: StopImageProcessor.", LOG_TAG);
|
||||
if (imageDecoder_ == nullptr) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret = imageDecoder_->StopDecoder();
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: StopDecoder failed ret:%d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkProcessor::SetImageSurface(sptr<Surface> &surface)
|
||||
{
|
||||
DHLOGI("%s: SetImageSurface.", LOG_TAG);
|
||||
if (imageDecoder_ == nullptr) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret = imageDecoder_->SetOutputSurface(surface);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: SetOutputSurface failed ret:%d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ImageSinkProcessor::ProcessImage(const std::shared_ptr<DataBuffer> &data)
|
||||
{
|
||||
DHLOGI("%s: ProcessImage.", LOG_TAG);
|
||||
if (imageDecoder_ == nullptr) {
|
||||
DHLOGE("%s: Decoder is null.", LOG_TAG);
|
||||
return ERR_DH_SCREEN_TRANS_NULL_VALUE;
|
||||
}
|
||||
|
||||
int32_t ret = imageDecoder_->InputScreenData(data);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: InputScreenData failed ret:%d.", LOG_TAG, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,70 @@
|
||||
# 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("//build/ohos_var.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
ohos_shared_library("distributed_screen_sinktrans") {
|
||||
include_dirs = [
|
||||
"//third_party/json/include",
|
||||
"//foundation/graphic/standard/interfaces/innerkits/surface",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"./include",
|
||||
"${common_path}/include",
|
||||
"${services_path}/common/databuffer/include",
|
||||
"${services_path}/common/screen_channel/include",
|
||||
"${services_path}/common/utils/include",
|
||||
"${services_path}/screentransport/screendatachannel/include",
|
||||
"${services_path}/screentransport/screensinktrans/include",
|
||||
"${services_path}/screentransport/screensinkprocessor/include",
|
||||
"${services_path}/screentransport/screensinkprocessor/decoder/include",
|
||||
"${services_path}/softbusadapter/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"./src/screen_sink_trans.cpp",
|
||||
"${services_path}/common/databuffer/src/data_buffer.cpp",
|
||||
"${services_path}/common/utils/src/video_param.cpp",
|
||||
"${services_path}/screentransport/screendatachannel/src/screen_data_channel_impl.cpp",
|
||||
"${services_path}/screentransport/screensinkprocessor/src/image_sink_processor.cpp",
|
||||
"${services_path}/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp",
|
||||
"${services_path}/screentransport/screensinkprocessor/decoder/src/image_decoder_callback.cpp",
|
||||
"${services_path}/softbusadapter/src/softbus_adapter.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${common_path}:distributed_screen_utils",
|
||||
"//foundation/graphic/standard/frameworks/surface:surface",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreensinktrans\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"dsoftbus_standard:softbus_client",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"multimedia_media_standard:media_client",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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 OHOS_ISCREEN_SINK_TRANS_H
|
||||
#define OHOS_ISCREEN_SINK_TRANS_H
|
||||
|
||||
#include "surface.h"
|
||||
|
||||
#include "iscreen_sink_trans_callback.h"
|
||||
#include "video_param.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class IScreenSinkTrans {
|
||||
public:
|
||||
virtual ~IScreenSinkTrans() = default;
|
||||
|
||||
virtual int32_t SetUp(const VideoParam &localParam, const VideoParam &remoteParam,
|
||||
const std::string &peerDevId) = 0;
|
||||
virtual int32_t Release() = 0;
|
||||
virtual int32_t Start() = 0;
|
||||
virtual int32_t Stop() = 0;
|
||||
virtual int32_t RegisterStateCallback(const std::shared_ptr<IScreenSinkTransCallback> &callBack) = 0;
|
||||
virtual int32_t SetImageSurface(const sptr<Surface> &surface) = 0;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 OHOS_ISCREEN_SINK_TRANS_CALLBACK_H
|
||||
#define OHOS_ISCREEN_SINK_TRANS_CALLBACK_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class IScreenSinkTransCallback {
|
||||
public:
|
||||
virtual ~IScreenSinkTransCallback() = default;
|
||||
|
||||
virtual void OnError(int32_t err, const std::string &content) = 0;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 OHOS_SCREEN_SINK_TRANS_H
|
||||
#define OHOS_SCREEN_SINK_TRANS_H
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include "iscreen_sink_trans.h"
|
||||
#include "iscreen_sink_trans_callback.h"
|
||||
#include "iimage_sink_processor.h"
|
||||
#include "iscreen_channel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class ScreenSinkTrans : public IScreenSinkTrans,
|
||||
public IScreenChannelListener,
|
||||
public IImageSinkProcessorListener,
|
||||
public std::enable_shared_from_this<ScreenSinkTrans> {
|
||||
public:
|
||||
ScreenSinkTrans() = default;
|
||||
~ScreenSinkTrans() = default;
|
||||
|
||||
int32_t SetUp(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId) override;
|
||||
int32_t Release() override;
|
||||
int32_t Start() override;
|
||||
int32_t Stop() override;
|
||||
int32_t RegisterStateCallback(const std::shared_ptr<IScreenSinkTransCallback> &callBack) override;
|
||||
int32_t SetImageSurface(const sptr<Surface> &surface) override;
|
||||
|
||||
void OnSessionOpened() override;
|
||||
void OnSessionClosed() override;
|
||||
void OnDataReceived(const std::shared_ptr<DataBuffer> &data) override;
|
||||
void OnProcessorStateNotify(int32_t state) override;
|
||||
|
||||
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,
|
||||
const std::string &peerDevId);
|
||||
|
||||
private:
|
||||
static const constexpr char *LOG_TAG = "ScreenSinkTrans";
|
||||
|
||||
sptr<Surface> decoderSurface_;
|
||||
std::shared_ptr<IImageSinkProcessor> imageProcessor_;
|
||||
std::shared_ptr<IScreenChannel> screenChannel_;
|
||||
std::weak_ptr<IScreenSinkTransCallback> transCallback_;
|
||||
};
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user