1688 商家基于 HarmonyOS 的多屏协同直播技术办法
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/c5cf1e8598634eeaa8c7714b0e794a0b~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=eYdao%2BI4JX%2FuATMpF%2FiybEYKJwE%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">作者:万合</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">距离HarmonyOS 2.0正式发布<span style="color: black;">已然</span>过去三个多月了,最新数据<span style="color: black;">表示</span>已有超过1亿台设备升级到了HarmonyOS操作系统。然而,<span style="color: black;">针对</span>广大的应用<span style="color: black;">研发</span>者而言,HarmonyOS似乎和Android<span style="color: black;">无</span>什么差异,<span style="color: black;">更加多</span>地<span style="color: black;">亦</span><span style="color: black;">便是</span>做<span style="color: black;">有些</span>原有功能的适配或迁移。针对HarmonyOS最核心的技术亮点——</span><strong style="color: blue;"><span style="color: black;">分布式软总线</span></strong><span style="color: black;">,还不清楚<span style="color: black;">怎样</span>实现,更不清楚该<span style="color: black;">怎样</span>与自己的业务相结合。</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在1688直播域供给侧,<span style="color: black;">咱们</span><span style="color: black;">始终</span>在<span style="color: black;">持续</span>探索<span style="color: black;">怎样</span><span style="color: black;">加强</span>商家开播能力、降低商家开播成本,当<span style="color: black;">认识</span>到分布式软总线的特性后,<span style="color: black;">咱们</span><span style="color: black;">发掘</span>HarmonyOS的这些能力非常切合1688商家多设备开播诉求,于是<span style="color: black;">咱们</span><span style="color: black;">开发</span>了这个结合分布式软总线的多设备开播<span style="color: black;">方法</span>。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">本文我将结合业务场景从技术<span style="color: black;">方向</span>,分享下<strong style="color: blue;">1688直播供给侧是<span style="color: black;">怎样</span>基于HarmonyOS的分布式软总线技术,实现多设备协同开播,助力1688商家降低开播成本、<span style="color: black;">加强</span>开播能力。</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">与<span style="color: black;">一般</span>的手机开播<span style="color: black;">区别</span>,<span style="color: black;">咱们</span>的<span style="color: black;">方法</span><span style="color: black;">触及</span>到多设备多屏幕,实现除了录制主播以外,还<span style="color: black;">能够</span>连接额外的摄像头专门录制商品,大屏展示直播的数据和预览,协播与主播大屏互动等功能。先<span style="color: black;">经过</span>一段视频<span style="color: black;">认识</span>下<span style="color: black;">咱们</span>技术<span style="color: black;">制品</span><span style="color: black;">方法</span>的实现效果,请点击下述链接查看视频:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><a style="color: black;">1688 商家基于 HarmonyOS 的多屏协同直播技术<span style="color: black;">方法</span></a></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">1、</span>业务背景</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">1688是国内领先的B2B电商平台,<span style="color: black;">咱们</span>服务的客户<span style="color: black;">重点</span><span style="color: black;">包含</span>工厂老板、淘宝卖家、实体店主、档口商家等。<span style="color: black;">因为</span>疫情<span style="color: black;">引起</span>线下实体生意的萎缩,越来越多的工厂、档口老板寻求线上直播带货转型,随着业务的发展,今年<span style="color: black;">咱们</span><span style="color: black;">亦</span>孵化了专门面向商家侧的App——1688商家版,<span style="color: black;">供给</span>给商家更加专业的服务,<span style="color: black;">包含</span>直播、洽谈、 工作台等,本文的实践案例正是在</span><strong style="color: blue;"><span style="color: black;">1688商家版直播域场景</span></strong><span style="color: black;">。</span></span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/98a01726d6c4456a97147fc4e263fb14~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=jnCcMpDIOMszML4IyWWD5HdXtqY%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">1.1 痛点</span></span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">区别</span>于淘宝直播的主播很<span style="color: black;">大都是</span>商家请来的专业MCN团队,1688直播的主播大<span style="color: black;">都数</span><span style="color: black;">便是</span>商家自己,<span style="color: black;">她们</span>对自己的货品如数家珍,但却对电商直播缺乏专业的开播能力和开播设备。<span style="color: black;">怎样</span>在1688商家投入有限资源的前提下,<span style="color: black;">帮忙</span>商家降低开播门槛、<span style="color: black;">加强</span>开播质量呢,<span style="color: black;">经过</span>线下走访商家,<span style="color: black;">咱们</span><span style="color: black;">发掘</span>几个<span style="color: black;">平常</span>的开播<span style="color: black;">关联</span>的问题。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/416023945d734c6cac1be0809e15aeef~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=Z%2Fs2HQ95dtrKXsts%2BdOUrLvzCjY%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">主播频繁走近摄像头展示商品细节</p>
</div>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/2f8ec404051a4b27b68c07c14aebf80b~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=5%2BcHfJ76NpWUbOJqErKtao81AFo%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">主播与协播单一设备互动</p>
</div>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/087e0390b48b4e4bae1576766b815b19~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=3%2FUUKpB5SWi1dYc%2BtQvQtTp3fcE%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">工厂环境简陋便携性困难</p>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">总结下,1688直播商家在开播设备方面<span style="color: black;">重点</span>存在以下三大痛点:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">1. </strong>直播缺乏特定功能设备</span></p><span style="color: black;">缺乏商品摄像头,当前摄像头距离商品远,主播<span style="color: black;">必须</span>频繁走近开播设备<span style="color: black;">才可</span>展示商品细节,影响直播观感;</span><span style="color: black;">缺乏互动大屏,手机直播互动屏幕小,主播<span style="color: black;">必须</span>走近开播设备<span style="color: black;">才可</span>看清观众留言与观众互动,影响直播体验。</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">2. </strong>直播设备之间难以协同</span></p><span style="color: black;">开播工具协同难,主播用到的录制设备、互动设备和协播<span style="color: black;">运用</span>的中控设备之间不互通操作困难;</span><span style="color: black;">主播协播互动难,<span style="color: black;">一般</span>主播讲解商品、协播上品发券,<span style="color: black;">因为</span>双方的设备间缺乏互动只能口播沟通缺乏私密性。</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">3. </strong>直播设备投入低能力差</span></p><span style="color: black;">开播设备投入低,1688的<span style="color: black;">非常多</span>主播本身是中小商家,直播投入追求性价比,开播设备参差不齐;</span><span style="color: black;">开播设备便携差,在工厂车间等<span style="color: black;">繁杂</span>场景<span style="color: black;">必须</span>驻播和走播协同开播,设备难以便携,缺乏多机位开播能力。</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">1.2 <span style="color: black;">状况</span></span></span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">现有的设备<span style="color: black;">是不是</span>满足商家<strong style="color: blue;">大屏多摄像头、设备间协同互动、便携低门槛</strong>的开播诉求呢?<span style="color: black;">咱们</span>先来对比下它们的特性:</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/0007b934a9ec443b85330162bbff154f~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=fnJfuLoAE4Qyzmfb4dOsowFKSV0%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">开播设备选型对比:</span></span></p><span style="color: black;">手机开播,手机分别负责推流、互动,有<span style="color: black;">必定</span>的协同便携能力,<span style="color: black;">然则</span>存在屏幕小和摄像头不可配等问题;</span><span style="color: black;">PC开播,具备可配置的摄像头和大屏,硬件成本不高,但设备大便携性差<span style="color: black;">况且</span>功能集中在一台设备缺乏互动性;</span><span style="color: black;">直播一体机开播,专门为直播开播定制的设备有大屏功能强,<span style="color: black;">然则</span>硬件门槛较高<span style="color: black;">况且</span>硬件都是烧录<span style="color: black;">没法</span>定制。</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">综上,<span style="color: black;">咱们</span>期望<span style="color: black;">供给</span>给商家直播的开播工具<span style="color: black;">必须</span>具备<strong style="color: blue;">多设备协同、大屏互动、连接线路少、硬件可配、高性价比</strong>,<span style="color: black;">那样</span>,有<span style="color: black;">无</span><span style="color: black;">同期</span>满足这些优点的开播<span style="color: black;">方法</span>呢?</span></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">2、</span><span style="color: black;">方法</span>设计</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">当前<span style="color: black;">咱们</span>App<span style="color: black;">已然</span>有<span style="color: black;">非常多</span>主播是HarmonyOS用户,针对<span style="color: black;">已然</span>具备HarmonyOS设备的中小商家,<span style="color: black;">咱们</span>提出了基于分布式软总线的多设备协同开播<span style="color: black;">方法</span>。</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">2.1 <span style="color: black;">方法</span>概述</span></span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">主播<span style="color: black;">运用</span>手机开播时,当遇到大屏设备,<span style="color: black;">能够</span>一键将直播能力流转到大屏设备上,<span style="color: black;">此时</span>候主播的手机呈现遥控器状态,大屏<span style="color: black;">表示</span>屏上分别展示实时数据看板、实时互动信息和主播讲解的采集画面。<span style="color: black;">倘若</span>场景中有商品摄像头,主播手机<span style="color: black;">亦</span><span style="color: black;">能够</span>唤起商品摄像头,商品摄像头会将采集的音视频数据传输给大屏设备<span style="color: black;">表示</span>,<span style="color: black;">最后</span>由大屏设备完成合流推流。协播<span style="color: black;">能够</span><span style="color: black;">经过</span>连接大屏设备,从而获取实时音视频流播放,实现与主播观众的协同互动。该<span style="color: black;">方法</span><span style="color: black;">重点</span>有两大核心技术能力,分别是<strong style="color: blue;">直播互动在跨设备上的迁移流转</strong>、<strong style="color: blue;">音视频流在多设备上的协同传输</strong>。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/8dce5a162f8e4ab3ae16d7ad5fd605cf~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=3gGTCQwPHQXf5M8AuAKmvfvtIB0%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">2.2 <span style="color: black;">方法</span>特点</span></span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">该<span style="color: black;">方法</span><span style="color: black;">同期</span>具备<span style="color: black;">以上</span>开播工具的优点:</span></p><span style="color: black;"><span style="color: black;">多设备间<span style="color: black;">有效</span>协同。专门录制主播讲解的摄像头,专门采集商品画面的摄像头,大屏设备展示主播讲解画面合并分发视频流,主播手机操控所有开播设备,协播手机播放视频流观看;</span></span><span style="color: black;"><span style="color: black;">大屏互动。大屏设备展示直播数据和互动信息,主播手机<span style="color: black;">能够</span>操控大屏互动,协播手机<span style="color: black;">能够</span>与主播、观众大屏互动;</span></span><span style="color: black;"><span style="color: black;">便携线路少。多设备间在同一局域网内完成无线连接;</span></span><span style="color: black;"><span style="color: black;">设备可配。录制主播和录制商品的摄像头可选配置,大屏互动设备可选配置;</span></span><span style="color: black;"><span style="color: black;">高性价比设备。主播、协播普通HarmonyOS手机,普通<span style="color: black;">表示</span>器外接HarmonyOS设备,摄像头<span style="color: black;">按照</span>清晰度需求可配。</span></span>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">3、</span>技术实现</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">实现<span style="color: black;">以上</span><span style="color: black;">制品</span><span style="color: black;">方法</span>的核心技术能力是直播互</span><strong style="color: blue;"><span style="color: black;">动的迁移流转</span></strong><span style="color: black;">和</span><strong style="color: blue;"><span style="color: black;">音视频流的协同传输</span></strong><span style="color: black;">,这两个技术能力的底层都是基于HarmonyOS的分布式软总线在<span style="color: black;">咱们</span>项目上的拓展封装。接下来,我先简单介绍下分布式软总线。</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">分布式总线是华为鸿蒙提出的概念,它的灵感应该来自于计算机系统,在计算机系统里把CPU、输入、输出设备等之间传送信息的公共通路叫总线。而软总线是<span style="color: black;">经过</span><span style="color: black;">创立</span>多设备间的虚拟通信连接,完成多设备间无<span style="color: black;">理学</span>线路连接的互联互通,从而低时延高带宽的设备间信息传输功能,使得各个设备之间<span style="color: black;">能够</span><span style="color: black;">经过</span>无线的方式实现<span style="color: black;">有效</span>的数据传输。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/a935de72a9624646aed6258d00396834~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=%2BufCvJfFwS1LurV7YCbyYKXCavY%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">从上面的架构图中,<span style="color: black;">咱们</span><span style="color: black;">能够</span>看到分布式软总线封装了多种通讯协议,并且将设备的<span style="color: black;">发掘</span>、连接、传输统一封装成对外透明的接口,<span style="color: black;">研发</span>者只<span style="color: black;">必须</span><span style="color: black;">经过</span>简单的调用就<span style="color: black;">能够</span>实现多设备间的互联互通,无需关心联通的细节。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">咱们</span><span style="color: black;">方法</span>中的直播互动正是基于分布式软总线实现多设备迁移流转,音视频流<span style="color: black;">亦</span>是<span style="color: black;">经过</span>软总线通道实现跨设备的传输,下面给<span style="color: black;">大众</span><span style="color: black;">仔细</span>介绍下这两个技术<span style="color: black;">制品</span>能力的实现。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">3.1 直播互动的迁移流转</span></span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">1 </span></span></strong><span style="color: black;"><strong style="color: blue;"><span style="color: black;">制品</span>功能</strong></span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/a5157a0f52c44cde81279870a301ee47~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=26703idh5uh9Cyz91dIG1KVcfvk%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">直播互动在多设备上迁移流转<span style="color: black;">重点</span>三个功能:</span></p><span style="color: black;">直播实时数据迁移大屏;</span><span style="color: black;">主播、协播互动迁移大屏;</span><span style="color: black;">主播中台<span style="color: black;">掌控</span>操作大屏。</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">2 </span></span></strong><span style="color: black;"><strong style="color: blue;">技术<span style="color: black;">方法</span></strong></span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/764c3d058f5c4dc2aa2e5456c1686ba8~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=G4td%2BzFN5dAnFpMk%2BOKub%2FhVbRA%3D" style="width: 50%; margin-bottom: 20px;"></div><span style="color: black;"><span style="color: black;">主播端App改造原有Android项目,<span style="color: black;">增多</span>HarmonyOS Ability依赖,新增开播<span style="color: black;">掌控</span>的FA;</span></span><span style="color: black;"><span style="color: black;">大屏端App是原有App上新增了大屏的HAP,<span style="color: black;">包含</span>直播数据FA 、实时互动FA;</span></span><span style="color: black;"><span style="color: black;">协播端APP是<span style="color: black;">亦</span>原有Android项目新增与主播和买家互动的FA。</span></span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">主播App<span style="color: black;">首要</span><span style="color: black;">发掘</span>并连接<span style="color: black;">周边</span>大屏,<span style="color: black;">而后</span>将直播数据FA和实时互动FA,无缝流转迁移到大屏设备,主播App<span style="color: black;">转</span>至开播<span style="color: black;">掌控</span>FA,主播App<span style="color: black;">经过</span>中台<span style="color: black;">掌控</span><span style="color: black;">能够</span>操作大屏和协播App,设备间的互动<span style="color: black;">经过</span>IDL通信实现。<span style="color: black;">必须</span><span style="color: black;">重视</span>的是,<span style="color: black;">以上</span>三个设备的App都是基于原有项目改造新增的能力,三者为同一个App。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">3 </span></span></strong><span style="color: black;"><strong style="color: blue;">代码实现</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">咱们</span>以主播端App唤起大屏端App<span style="color: black;">同期</span><span style="color: black;">自己</span><span style="color: black;">转</span>中台<span style="color: black;">掌控</span>为例:</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/0b995c88aa7c473db7bcfc4d5ffc1803~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=DP6zttq7MVtTiLoIrrWoJ%2Bh0zE4%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1、在LiveControlAbility的进行流转设备注册;</span></p><span style="color: black;">ContinuationRegisterManager</span> <span style="color: black;">continuationRegisterManager</span> <span style="color: black;">=</span> <span style="color: black;">getContinuationRegisterManager();</span>
<span style="color: black;">continuationRegisterManager.register(getBundleName(),</span> <span style="color: black;">null</span><span style="color: black;">,</span> <span style="color: black;">callback,</span> <span style="color: black;">requestCallback);</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2、在</p>ContinuationDeviceCallback连接设备回调成功后调用connectAbility唤起大屏PA ScreenServiceAbility并传递<span style="color: black;">关联</span>参数;<span style="color: black;">private</span> IContinuationDeviceCallback callback = <span style="color: black;">new</span>IContinuationDeviceCallback() {<span style="color: black;">@Override</span>
<span style="color: black;">public</span> <span style="color: black;">void</span> onDeviceConnectDone(<span style="color: black;">String</span> selectDeviceId, <span style="color: black;">String</span>deviceType) {
connectAa(selectDeviceId);
continuationRegisterManager.updateConnectStatus(abilityToken, selectDeviceId, DeviceConnectState.CONNECTED.getState(),<span style="color: black;">null</span>);
}
}
};<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3、在大屏ScreenServiceAbility的onConnect接收数据并拉起大屏FA ScreenPageAbility;</span></p><span style="color: black;"><span style="color: black;">public</span> IRemoteObject <span style="color: black;">onConnect</span><span style="color: black;">(Intent intent)</span> </span>{
jumpScreen();
<span style="color: black;">return</span> <span style="color: black;">new</span> ScreenRemoteForController();
}<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">4、ScreenRemoteForController继承自</p>HarmonyControllerInterfaceSkeletonScreen在OnConnect回调以后初始化,并且接收从主播App发送的指令如唤起其他设备,再<span style="color: black;">经过</span>EventHandler进行事件分发。
<span style="color: black;"><span style="color: black;">class</span> <span style="color: black;">ScreenRemoteForController</span> <span style="color: black;">extends</span> <span style="color: black;">HarmonyControllerInterfaceSkeleton</span> </span>{
ScreenRemoteForController() {
<span style="color: black;">super</span>(<span style="color: black;">"IScreenRemoteInterface"</span>);
}
<span style="color: black;">@Override</span>
<span style="color: black;"><span style="color: black;">public</span> <span style="color: black;">void</span> <span style="color: black;">sendCommand</span><span style="color: black;">(String command)</span> <span style="color: black;">throws</span> RemoteException </span>{
MyApplication.getHandler().sendEvent(command);
}<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">4</span></span></strong><span style="color: black;"><strong style="color: blue;"> 难点和限制</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">跨设备通信</span></strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">HarmonyOS的设备当前通信方式只支持以IDL的方式,并且IDL是单向通信的,为了实现设备之间双向通信,<span style="color: black;">咱们</span>采取在IDL中的<span style="color: black;">增多</span>回调的<span style="color: black;">办法</span>,<span style="color: black;">或</span>采用创建两个双向IDL的方式实现设备间的双通。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">Android与HarmonyOS混合兼容<span style="color: black;">研发</span></span></strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">当前<span style="color: black;">咱们</span>的所有功能都是在原有Android项目上进行的HarmonyOS增量<span style="color: black;">研发</span>,<span style="color: black;">而后</span>再进行混合打包。<span style="color: black;">这儿</span>的功能<span style="color: black;">研发</span>受限于还有<span style="color: black;">非常多</span><span style="color: black;">基本</span>库尚未完成HarmonyOS的迁移适配、HarmonyOS和Android间的兼容与通信等。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">3.2 音视频流的协同传输</span></span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">1 </span></span></strong><span style="color: black;"><strong style="color: blue;"><span style="color: black;">制品</span>功能</strong></span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/pgc-image/1fec3009486540a997365f2cee7e2f29~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=VGU%2FJk3qgpM%2BfEP%2FT0cWSNLVmZY%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">音视频流在跨设备上的协同传输<span style="color: black;">重点</span>四个功能:</span></p><span style="color: black;">主播音视频采集流转到大屏摄像头;</span><span style="color: black;">唤起商品摄像头采集商品画面并流转大屏设备;</span><span style="color: black;">大屏设备合并商品和主播画面播放并推流;</span><span style="color: black;">音视频流传输到协播手机播放观看。</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">2 </span></span></strong><span style="color: black;"><strong style="color: blue;">技术<span style="color: black;">方法</span></strong></span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/70388c056bff45668a018e13e2ce4fd4~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723110387&x-signature=K2z9QuDte%2FYaMtkel4IKINDljqQ%3D" style="width: 50%; margin-bottom: 20px;"></div><span style="color: black;"><span style="color: black;">主播App在连接大屏设备后将关闭音视频采集、预览功能;</span></span><span style="color: black;"><span style="color: black;">大屏App上新增录制预览能力和合流推流能力,<span style="color: black;">同期</span><span style="color: black;">必须</span><span style="color: black;">增多</span>编码将采集到的音视频流传输到协播App上;</span></span><span style="color: black;"><span style="color: black;">商品摄像头上<span style="color: black;">增多</span>采集音视频和传输到大屏设备的能力;</span></span><span style="color: black;"><span style="color: black;">协播App去掉之前从云端拉取流的方式,改为本地解码后播放音视频流。</span></span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">主播App 在连接大屏设备后,会唤起大屏设备的摄像头录制音视频并<span style="color: black;">表示</span>预览,大屏设备<span style="color: black;">起步</span>后拉起商品摄像头,<span style="color: black;">同期</span>对采集的音视频流编码,将流传输到大屏设备上合流并推流,协播手机<span style="color: black;">能够</span>获取大屏音视频流播放。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">3 </span></span></strong><span style="color: black;"><strong style="color: blue;">代码实现</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>以商品摄像头被唤起后采集音视频传输到大屏端为例:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1、当商品摄像头被唤起后,<span style="color: black;">首要</span>初始化SurfaceProvider,并在其surfaceCallback回调中连接后台ScreenServiceAbility服务,<span style="color: black;">同期</span>打开摄像头;</span></p><span style="color: black;">protected</span> SurfaceOps.Callback surfaceCallback = <span style="color: black;">new</span> SurfaceOps.Callback() {
<span style="color: black;">@Override</span>
<span style="color: black;"><span style="color: black;">public</span> <span style="color: black;">void</span> <span style="color: black;">surfaceCreated</span><span style="color: black;">(SurfaceOps surfaceOps)</span> </span>{
previewSurface = surfaceOps.getSurface();
Intent intent = <span style="color: black;">new</span> Intent();
Operation operation = <span style="color: black;">new</span>Intent.OperationBuilder()
.withDeviceId(<span style="color: black;">""</span>)
.withBundleName(mCameraAbility.getBundleName())
.withAbilityName(<span style="color: black;">"com.alibaba.screencamera.ScreenServiceAbility"</span>)
.build();
intent.setOperation(operation);
intent.setParam(<span style="color: black;">"client_role"</span>, <span style="color: black;">"camera"</span>);
mCameraAbility.connectAbility(intent, mAbilityConnection);
openCamera();
}
};<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2、<span style="color: black;">起步</span>的后台服务ScreenServiceAbility在onConnect时将音视频数据进行传输;</span></p><span style="color: black;"><span style="color: black;">public</span> IRemoteObject <span style="color: black;">onConnect</span><span style="color: black;">(Intent intent)</span> </span>{
<span style="color: black;">return</span> <span style="color: black;">new</span>ScreenRemoteFoSlave() {<span style="color: black;">@Override</span>
<span style="color: black;"><span style="color: black;">public</span> <span style="color: black;">void</span> <span style="color: black;">onPcmReady</span><span style="color: black;">(<span style="color: black;">byte</span>[] pcmData)</span> <span style="color: black;">throws</span> RemoteException </span>{
mControllerCallback.onPcmReady(pcmData);
}
<span style="color: black;">@Override</span>
<span style="color: black;"><span style="color: black;">public</span> <span style="color: black;">void</span> <span style="color: black;">onYuvData</span><span style="color: black;">(<span style="color: black;">int</span> type, <span style="color: black;">int</span> length, <span style="color: black;">int</span> seq, <span style="color: black;">byte</span>[] cameraData)</span> <span style="color: black;">throws</span> RemoteException </span>{
mControllerCallback.onReturnData(type, length, seq, cameraData);
}
}<span style="color: black;">return</span> <span style="color: black;">null</span>;
}<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3、以商品摄像头采集的视频数据为例,将YUV数据格式编码后发送;</span></p>mCodec.registerCodecListener(<span style="color: black;">new</span> Codec.ICodecListener() {
@<span style="color: black;">Override
<span style="color: black;">public</span> <span style="color: black;">void</span> <span style="color: black;">onReadBuffer</span>(<span style="color: black;">ByteBuffer byteBuffer, BufferInfo bufferInfo, <span style="color: black;">int</span> trackId</span>)</span> {
<span style="color: black;">byte</span>[] msg = <span style="color: black;">new</span> <span style="color: black;">byte</span>;
byteBuffer.clear();
byteBuffer.<span style="color: black;">get</span>(msg);
sendEncodedDataToRemote(msg, bufferInfo);
}
}
);
mCodec.setCodecFormat(fmt);
mCodec.start();<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">4、将转化后的YUV视频帧数据先做切片<span style="color: black;">而后</span><span style="color: black;">经过</span>ScreenService后台服务进行发送;</span></p><span style="color: black;"><span style="color: black;">private</span> <span style="color: black;">void</span> <span style="color: black;">sendEncodedDataToRemote</span>(<span style="color: black;"><span style="color: black;">byte</span>[] data, BufferInfo bufferInfo</span>)</span> {
<span style="color: black;">byte</span>[] msgTemp = <span style="color: black;">new</span> <span style="color: black;">byte</span>;
System.arraycopy(data, position, msgTemp,<span style="color: black;">0</span>, msgTemp.length);
mScreenServiceProxy.onYuvData(CameraUtil.IRemoteMsg.MSG_TYPE_SLICE_END, bufferInfo.size, <span style="color: black;">0</span>, data);
}<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">5、大屏设备收到商品摄像头发送的音视频数据进行解码后播放。</span></p><span style="color: black;">private</span> ControllerCallbackStub mControllerCallback = <span style="color: black;">new</span> ControllerCallbackStub(<span style="color: black;">"com.alibaba.cameraohos.IControlFaCallback"</span>) {
<span style="color: black;">@Override</span>
<span style="color: black;"><span style="color: black;">public</span> <span style="color: black;">void</span> <span style="color: black;">onPcmReady</span><span style="color: black;">(<span style="color: black;">byte</span>[] pcmData)</span> <span style="color: black;">throws</span> RemoteException </span>{
mPlayRecord.playTransData(pcmData);
}
<span style="color: black;">@Override</span>
<span style="color: black;"><span style="color: black;">public</span> <span style="color: black;">void</span> <span style="color: black;">onReturnData</span><span style="color: black;">(<span style="color: black;">int</span> type, <span style="color: black;">int</span> length, <span style="color: black;">int</span> seq, <span style="color: black;">byte</span>[] cameraData)</span> <span style="color: black;">throws</span> RemoteException </span>{
createMyDecoder();
initMuxer();
}
};<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">4 </span></span></strong><span style="color: black;"><strong style="color: blue;">难点和限制</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">音视频流本地编解码传输</span></strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">有别于传统的本地编码推流,本<span style="color: black;">方法</span>里面设备间音视频流都是在局域网内传输,<span style="color: black;">因为</span>分布式软总线的带宽有限,而视频数据<span style="color: black;">很强</span>,<span style="color: black;">咱们</span>采用对本地视频流YUV数据进行编解码,<span style="color: black;">经过</span>切片合流的方式,达到了720P的视频流传输。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">多设备的组网</span></strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">HarmonyOS的设备组网<span style="color: black;">必须</span>基于前提<span style="color: black;">要求</span>,<span style="color: black;">包含</span>同一WiFi、开启蓝牙、暂时只支持登录相同华为账号,之<span style="color: black;">因此</span>条件苛刻的<span style="color: black;">原由</span>我想<span style="color: black;">重点</span>还是安全性<span style="color: black;">思虑</span>,<span style="color: black;">不外</span>在<span style="color: black;">咱们</span>这个场景中,设备都是服务于同一个直播账号,登录相同的华为账号再进行开播场景<span style="color: black;">亦</span><span style="color: black;">恰当</span>。</span></span></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">4、</span>总结和展望</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">4.1 总结</span></span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">咱们</span>的<span style="color: black;">方法</span>具备以下三个特点:</span></span></p><span style="color: black;"><strong style="color: blue;"><span style="color: black;">软件<span style="color: black;">方法</span><span style="color: black;">处理</span>硬件限制。</span></strong>利用HarmonyOS分布式软总线技术,采用软件<span style="color: black;">方法</span>打破1688直播场景的硬件限制,将应用功能打散到最匹配的硬件设备上,实现硬件资源的互助互补</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">结合场景拓展开播能力。</span></strong>结合1688商家直播的场景特点,基于HarmonyOS的分布式软总线的特性,<span style="color: black;">处理</span>直播互动、音视频传输的无缝流转,实现大屏互动、多设备开播功能</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">低本<span style="color: black;">有效</span><span style="color: black;">处理</span>商家痛点。</span></strong>在基本不改变原有1688开播功能的<span style="color: black;">基本</span>上,软件层面实现同一个应用在多设备上<span style="color: black;">区别</span>能力表达,硬件层面可<span style="color: black;">按照</span>商家实力<span style="color: black;">选取</span>合适设备,<span style="color: black;">研发</span>成本低,商家投入少</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">分布式软总线是HarmonyOS操作系统独有的能力,当前<span style="color: black;">方法</span>最大的缺点<span style="color: black;">便是</span><span style="color: black;">没法</span>在其他操作系统的手机上实现,<span style="color: black;">因此</span><span style="color: black;">仅有</span>HarmonyOS的用户才具备这个能力。<span style="color: black;">将来</span><span style="color: black;">咱们</span>会探索在Android和iOS上实现类似的功能,<span style="color: black;">同期</span><span style="color: black;">亦</span><span style="color: black;">期盼</span><span style="color: black;">咱们</span>在电商直播的多设备协同开播的实践,能够带启发<span style="color: black;">更加多</span>技术<span style="color: black;">制品</span>利用分布式软总线能力落地业务场景。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">4.2 展望</span></span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">基于<span style="color: black;">咱们</span>沉淀的<strong style="color: blue;">直播互动迁移</strong>和<strong style="color: blue;">音视频协同传输</strong>两大技术能力,<span style="color: black;">将来</span><span style="color: black;">咱们</span>会在这两个方向进一步探索</span></p><span style="color: black;"><strong style="color: blue;"><span style="color: black;">多机位多摄像头开播,丰富直播内容</span>。</strong>随着集团Artc逐步适配HarmonyOS并<span style="color: black;">供给</span><span style="color: black;">更加多</span>流处理能力,<span style="color: black;">咱们</span><span style="color: black;">能够</span><span style="color: black;">供给</span>专业高清的摄像头录制商品,可移动的摄像头走播工厂,多<span style="color: black;">方向</span>的摄像头采集直播画面,进一步<span style="color: black;">提高</span><span style="color: black;">咱们</span>的直播内容质量</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">标准化的中控盒子,降低开播成本</span>。</strong>将音视频流合流分发、投屏展示、开播<span style="color: black;">掌控</span>的能力集中在一个中控设备上,主播只<span style="color: black;">必须</span><span style="color: black;">持有</span>该设备就<span style="color: black;">能够</span>实现以上打包的开播能力</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">当前<span style="color: black;">咱们</span>的<span style="color: black;">方法</span><span style="color: black;">重点</span>还是软件应用的<span style="color: black;">研发</span>并不<span style="color: black;">触及</span>硬件的<span style="color: black;">研发</span>,<span style="color: black;">因此</span><span style="color: black;">实质</span><span style="color: black;">运用</span>的时候<span style="color: black;">必须</span>的摄像头和大屏设备能力都是采用HarmonyOS的手机完成的,<span style="color: black;">倘若</span><span style="color: black;">咱们</span><span style="color: black;">拥有</span>烧录OpenHarmony的摄像头和投屏盒子,将进一步降低商家的成本、丰富开播的能力。随着5G和万物互联时代的发展,目之可及的前景还是<span style="color: black;">非常</span>广阔。</span></span></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">参考:</h1><span style="color: black;"><span style="color: black;">分布式语音照相 https://gitee.com/panthole/harmonyos-codelabs/tree/master/VoiceCamera</span></span><span style="color: black;"><span style="color: black;">跨设备迁移视频内容 https://gitee.com/panthole/harmonyos-codelabs/tree/master/DistributedVideoCodelab</span></span><span style="color: black;"><span style="color: black;">HamonyOS视频解码能力播放预览画面 https://gitee.com/panthole/harmonyos-codelabs/tree/master/CodecDemo</span></span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">关注<span style="color: black;">咱们</span>,每周 3 篇移动技术实践&干货给你思考!</span></strong></span></p>
外链发布论坛学习网络优化SEO。 你字句如珍珠,我珍藏这份情。 软文发布平台 http://www.fok120.com/ 感谢您的精彩评论,为我带来了新的思考角度。
页:
[1]