C# 实现 Linux 视频会议(源码,支持信创环境,银河麒麟,统信UOS)
信创是现阶段国家发展的重要战略之一,面对这一趋势,所有的软件应用只有支持信创国产化的基础软硬件设施,在未来才不会被淘汰。那么,如何可以使用C#来实现支持信创环境的视频会议系统吗?答案是肯定的。
本文讲述如何使用C#来实现视频会议系统的Linux服务端与Linux客户端,并让其支持国产操作系统(如银河麒麟,统信UOS)和国产CPU(如鲲鹏、龙芯、海光、兆芯、飞腾等)。
先看看该Demo在统信UOS上的运行效果:

一.功能介绍
1.基本功能
(1)主持人:当进入同一房间的第一个用户默认成为主持人,默认打开麦克风。
(2)当进入会议房间的每个人,都能自由选择是否开启摄像头、扬声器和麦克风。
(3)当同一房间内无人开启桌面共享时,所有用户均可开启桌面共享,供其他用户观看其桌面,同一时间内只允许一个用户开启桌面共享。
(4)当用户为主持人时,可以选择是否开启电子白板;当主持人开启电子白板后,所有用户均可自由切换电子白板和会议视频。
(5)每个用户的视频窗口上方均显示声音分贝条,根据声音大小自动渲染。
(6)当用户关闭摄像头或者用户数量超过9个,不显示视频。
(7)所有用户均可收发文字消息,包括带表情的文字消息。
2.功能演示
在银河麒麟上运行:

3.布局风格
(1)当只有一个人开启视频时,采用大视窗显示
(2)当2~4人开启视频时,使用2x2布局
(3)当超过4人开启视频时,使用3x3布局
二.开发环境
1.开发工具:
Visual Studio 2022
2. 开发框架:
.NET Core 3.1,.NET 6,.NET 7
3.开发语言:
C#
4.其它框架:
CPF.net UI 框架、OMCS 语音视频框架
三.具体实现
1. 新用户进入会议房间
(1)视频显示窗口控件VideoPanel
预定SomeoneJoin事件,当新的用户加入房间时,将触发该事件:
this.chatGroup.SomeoneJoin += new CbGeneric<IChatUnit>(chatGroup_SomeoneJoin);
void chatGroup_SomeoneJoin(IChatUnit unit)
{
if (!Dispatcher.CheckAccess())
{
Dispatcher.BeginInvoke(new CbGeneric<IChatUnit>(this.chatGroup_SomeoneJoin), unit);
}
else
{
VideoPanel panel = new VideoPanel();
panel.Initialize(unit, false);
VideoHidePanel videoHidePanel = new VideoHidePanel();
videoHidePanel.Initialize(false, unit,false);
VideoAllPanel videoAllPanel;
videoAllPanel.videoPanel = panel;
videoAllPanel.videoHidePanel = videoHidePanel;
if (panel.ConnectCameraResult != ConnectResult.Succeed)
{
this.flowLayoutPanel2.Children.Insert(0, videoHidePanel);
videoHidePanel.cameraVisibilityChange(false);
}
else
{
if (this.isVideoShowBeyond)
{
this.flowLayoutPanel2.Children.Insert(0, videoHidePanel);
videoHidePanel.cameraVisibilityChange(true);
}
else
{
this.cameraViewbox.FlowLayoutPanel.Children.Insert(this.videoShowCount, panel);
}
}
this.TotalNumChange(this.chatGroup.GetOtherMembers().Count + 1);
panel.ChangeState += Panel_ChangeState;
panel.CameraStateChange += Panel_CameraStateChange;
panel.VideoByCount += Panel_VideoByCount;
panel.VideoConnect += Panel_VideoConnect;
unit.Tag = videoAllPanel;
this.VideoNumBeyond();
this.VideoSizeChange(new System.Windows.Size(this.cameraViewbox.FlowLayoutPanel.Width, this.cameraViewbox.FlowLayoutPanel.Height));
}
}
其中 VideoPanel 是视频窗口显示控件,初始化如下:
public void Initialize(IChatUnit unit, bool myself)
{ this.pictureBox_Mic.RenderSize = new System.Windows.Size(24, 24);
this.chatUnit = unit;
this.isMySelf = myself;
this.toolStrip1.Text = chatUnit.MemberID;
//初始化麦克风连接器
this.chatUnit.MicrophoneConnector.ConnectEnded += new CbGeneric<string, ConnectResult>(MicrophoneConnector_ConnectEnded);
this.chatUnit.MicrophoneConnector.OwnerOutputChanged += new CbGeneric<string>(MicrophoneConnector_OwnerOutputChanged); if (!this.isMySelf)
{
this.chatUnit.MicrophoneConnector.BeginConnect(unit.MemberID);
}
if (this.isMySelf)
{
this.videoSizeShow.Visibility = Visibility.Collapsed;
}
//初始化摄像头连接器
this.chatUnit.DynamicCameraConnector.SetViewer(this.cameraPanel1);
this.chatUnit.DynamicCameraConnector.VideoDrawMode = VideoDrawMode.Scale;
this.chatUnit.DynamicCameraConnector.ConnectEnded += new CbGeneric<string, ConnectResult>(DynamicCameraConnector_ConnectEnded);
this.chatUnit.DynamicCameraConnector.OwnerOutputChanged += new CbGeneric<string>(DynamicCameraConnector_OwnerOutputChanged);
this.chatUnit.DynamicCameraConnector.Disconnected += new CbGeneric<string, ConnectorDisconnectedType>(DynamicCameraConnector_Disconnected);
this.chatUnit.DynamicCameraConnector.OwnerVideoSizeChanged += DynamicCameraConnector_OwnerVideoSizeChanged;
this.chatUnit.DynamicCameraConnector.BeginConnect(unit.MemberID);
}
当新用户进入房间时,房间内其他用户通过MicrophoneConnector麦克风连接器和DynamicCameraConnector摄像头连接器连接到该用户的麦克风和摄像头
(2)开启或关闭摄像头、麦克风、扬声器
以开启或关闭摄像头为例:
private void skinCheckBox_camera_MouseDown(object sender, MouseButtonEventArgs e)
{
this.isMyselfVideo = !this.isMyselfVideo;
System.Windows.Controls.Image imageVideo = sender as System.Windows.Controls.Image;
imageVideo.Source = this.isMyselfVideo ? ResourceManager.Singleton.CameraOpenImage : ResourceManager.Singleton.CameraCloseImage;
imageVideo.ToolTip = this.isMyselfVideo ? "摄像头:开" : "摄像头:关";
VideoPanel myPanel = ((VideoAllPanel)this.chatGroup.GetMember(this.loginId).Tag).videoPanel;
VideoHidePanel myHidePanel = ((VideoAllPanel)this.chatGroup.GetMember(this.loginId).Tag).videoHidePanel;
this.VideoNumBeyond();
if (this.isVideoShowBeyond)
{
myHidePanel.cameraVisibilityChange(this.isMyselfVideo);
}
else
{
if (!isMyselfVideo)
{
this.cameraViewbox.FlowLayoutPanel.Children.Remove(myPanel);
myPanel.cameraPanel1.ClearImage();
this.flowLayoutPanel2.Children.Insert(0, myHidePanel);
myHidePanel.cameraVisibilityChange(false);
}
else
{
this.flowLayoutPanel2.Children.Remove(myHidePanel);
this.cameraViewbox.FlowLayoutPanel.Children.Insert(this.videoShowCount, myPanel);
}
} if (IsInitialized)
{
this.multimediaManager.OutputVideo = this.isMyselfVideo;
this.VideoSizeChange(new System.Windows.Size(this.cameraViewbox.FlowLayoutPanel.Width, this.cameraViewbox.FlowLayoutPanel.Height));
}
}
其中通过多媒体管理器multimediaManager的OutputVideo属性,设置是否将采集到的视频输出,进而控制摄像头的开启或关闭。
2. 布局切换
(1)根据开启视频的用户数量可分为 1x1、2x2、3x3三种布局格式
(2)根据不同的布局格式以及外部控件容器的宽高,手动计算视频控件的宽高。
private void VideoSizeChange(Size size)
{
if (this.cameraViewbox.FlowLayoutPanel.Children.Count > 4)
{
foreach (VideoPanel panel in this.cameraViewbox.FlowLayoutPanel.Children)
{
panel.Height = (size.Height - 6) / 3;
panel.Width = (size.Width - 12) / 3;
}
}
else if (this.cameraViewbox.FlowLayoutPanel.Children.Count <= 4 && this.cameraViewbox.FlowLayoutPanel.Children.Count > 1)
{
foreach (VideoPanel panel in this.cameraViewbox.FlowLayoutPanel.Children)
{
panel.Height = (size.Height - 4) / 2;
panel.Width = (size.Width - 8) / 2;
}
}
else if (this.cameraViewbox.FlowLayoutPanel.Children.Count == 1)
{
foreach (VideoPanel panel in this.cameraViewbox.FlowLayoutPanel.Children)
{
panel.Height = size.Height - 2;
panel.Width = size.Width - 4;
}
}
}
通过流式布局控件的特性:超过流式控件的宽度,子控件将自动换行,修改视频控件的宽高;
外部容器实际容纳所有视频控件的宽高为:外部容器的宽高减去所有视频控件的外边距;
当只有一个用户开启视频,即将使用1x1布局时,视频控件宽高即为外部容器实际容纳所有视频控件的宽高;
当2~4人开启视频,即将使用2x2布局时,视频控件宽高即为外部容器实际容纳所有视频控件的宽高的1/2,此时每个视频控件将占外部控件的1/4;
当超过4人开启视频,即将使用3x3布局时,视频控件宽高即为外部容器实际容纳所有视频控件的宽高的1/3,此时每个视频控件将占外部控件的1/9
3.自定义消息类型
public static class InformationTypes
{
#region 广播消息
/// <summary>
/// 广播聊天信息
/// </summary>
public const int BroadcastChat = 0;
/// <summary>
/// 广播共享桌面
/// </summary>
public const int BroadcastShareDesk = 1;
/// <summary>
/// 广播白板
/// </summary>
public const int BroadcastWhiteBoard = 2;
#endregion #region 给新加入成员发送消息
/// <summary>
/// 共享桌面
/// </summary>
public const int ShareDesk = 53;
/// <summary>
/// 电子白板
/// </summary>
public const int WhiteBoard = 54;
#endregion /// <summary>
/// 获取服务端 组扩展信息
/// </summary>
public const int GetGroupExtension = 101;
}
(1)当用户发送聊天消息时,将通过BroadcastChat向所有在线用户广播聊天消息;当用户开启桌面共享时,将通过BroadcastShareDesk向所有在线用户广播桌面共享消息;当主持人开启电子白板时,将通过BroadcastWhiteBoard
向所有在线用户广播电子白板消息。
(2)当用户上线时,如果有用户开启桌面共享,就将通过ShareDesk 向新用户发送桌面共享消息;如果主持人开启电子白板,就将通过WhiteBoard向新用户发送电子白板消息。
(3)用户将通过GetGroupExtension向服务端获取组扩展信息。
4.组扩展信息
public class GroupExtension
{
/// <summary>
/// 主持人ID
/// </summary>
public string ModeratorID { get; set; } /// <summary>
/// 正在共享远程桌面的用户ID
/// </summary>
public string DesktopSharedUserID { get; set; } /// <summary>
/// 主持人是否开启白板
/// </summary>
public bool IsModeratorWhiteBoardNow { get; set; }
}
(1)ModeratorID 表示当前房间主持人的ID;
(2)DesktopSharedUserID 正在桌面共享的用户ID;若值为null,表示当前房间内无人开启桌面共享,客户端通过该值判断当前是否有用户开启桌面共享;当用户开启或关闭桌面共享时,都将手动修改该值;
(3)IsModeratorWhiteBoardNow表示当前主持人是否开启电子白板;当主持人开启或关闭电子白板时,都将手动修改该值。
四.源码下载
1. 源码项目说明
(1)OVCS.ServerLinux :视频会议 Linux 服务端
(2)OVCS.ClientLinux :视频会议 Linux 客户端
注: Linux客户端内置的是x86/x64非托管so库,若需要其它架构的so,请联系QQ:2027224508 获取。
(3)另附上Android客户端的源码:Android端 。
2. 部署运行说明
在部署之前,需要在linux服务端和客户端上分别安装 .Net core 3.1版本,命令行安装命令如下:
yum install dotnet-sdk-3.1
检查版本安装情况
dotnet --version
运行:
(1)在CentOS上启动OVCS.ServerLinux服务端:拷贝OVCS.ServerLinux项目下的Debug文件夹,到CentOS操作系统上,打开Debug -> netcoreapp3.1目录 ,在目录下打开终端,执行以下命令启动服务端
dotnet OVCS.ServerLinux.dll

(2)在麒麟或统信UOS、Ubuntu上运行OVCS.ClientLinux客户端:拷贝OVCS.ClientLinux项目下的Debug文件夹,到麒麟或统信UOS、Ubuntu操作系统上,打开Debug -> netcoreapp3.1目录 ,在目录下打开终端,执行以下命令启动客户端
dotnet OVCS.ClientLinux.dll
C# 实现 Linux 视频会议(源码,支持信创环境,银河麒麟,统信UOS)的更多相关文章
- linux内核源码注解
轻松学习Linux操作系统内核源码的方法 针对好多Linux 爱好者对内核很有兴趣却无从下口,本文旨在介绍一种解读linux内核源码的入门方法,而不是解说linux复杂的内核机制:一.核心源程序的文件 ...
- ubuntu下linux内核源码阅读工具和调试方法总结
http://blog.chinaunix.net/uid-20940095-id-66148.html 一 linux内核源码阅读工具 windows下当然首选source insight, 但是l ...
- Linux基础系列—Linux内核源码目录结构
/** ****************************************************************************** * @author 暴走的小 ...
- Linux内核源码分析 day01——内存寻址
前言 Linux内核源码分析 Antz系统编写已经开始了内核部分了,在编写时同时也参考学习一点Linux内核知识. 自制Antz操作系统 一个自制的操作系统,Antz .半图形化半命令式系统,同时嵌入 ...
- linux内存源码分析 - 内存回收(整体流程)
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 概述 当linux系统内存压力就大时,就会对系统的每个压力大的zone进程内存回收,内存回收主要是针对匿名页和文 ...
- linux内存源码分析 - 内存压缩(同步关系)
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 概述 最近在看内存回收,内存回收在进行同步的一些情况非常复杂,然后就想,不会内存压缩的页面迁移过程中的同步关系也 ...
- linux内存源码分析 - 内存压缩(实现流程)
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 概述 本文章最好结合linux内存管理源码分析 - 页框分配器与linux内存源码分析 -伙伴系统(初始化和申请 ...
- Linux 从源码编译安装 OpenSSH
https://blog.csdn.net/bytxl/article/details/46639073 Linux 从源码编译安装 OpenSSH以及各问题解决 2015年06月25日 17:37: ...
- Linux内核源码分析--内核启动之(6)Image内核启动(do_basic_setup函数)(Linux-3.0 ARMv7)【转】
原文地址:Linux内核源码分析--内核启动之(6)Image内核启动(do_basic_setup函数)(Linux-3.0 ARMv7) 作者:tekkamanninja 转自:http://bl ...
- Linux内核源码分析--内核启动之(4)Image内核启动(setup_arch函数)(Linux-3.0 ARMv7)【转】
原文地址:Linux内核源码分析--内核启动之(4)Image内核启动(setup_arch函数)(Linux-3.0 ARMv7) 作者:tekkamanninja 转自:http://blog.c ...
随机推荐
- [极客大挑战 2019]BuyFlag 1
好吧,又是一道违背我思想的题目,哦不哦不不对,是本人操作太傻了 首先进入主页面 没有发现什么奇怪的东西,查看源代码,搜索.php 可以看到有一个pay.php,访问查看 给我们了一些提示 FLAG N ...
- Java笔记第十二弹
Lambda表达式的标准格式 三要素:形式参数.箭头.代码块 格式:(形式参数)->(代码块) 形式参数:如果有多个参数,参数之间用逗号隔开:如果没有参数,留空即可 ->代表指向动作 La ...
- 文件的上传&预览&下载学习(一)
注:主要是说明后端逻辑和数据库表设计 1.当前主流的几种文件上传&预览&下载方式 把文件直接存储在服务器 分布式存储OSS,比如阿里OSS.Minio 2.数据库表设计 由于文件都是跟 ...
- obs推流核心流程分析
前置步骤和录屏是一样的,见我的上一篇文章 https://www.cnblogs.com/billin/p/17219558.html bool obs_output_actual_start(obs ...
- flutter feature---->quick action
reference: https://www.filledstacks.com/snippet/managing-quick-actions-in-flutter/ code import 'dart ...
- go简易tcp/udp连接测试工具
package main import ( "fmt" "io" "log" "net" "os" ...
- kubernetes 安装 Prometheus + Grafana
kubernetes 安装 Prometheus + Grafana kubernetes install Prometheus + Grafana 官网 Official website https ...
- LeeCode 栈与队列问题(一)
LeeCode 20: 有效的括号 题目描述 给定一个只包括 '(', ')', '{', '}', '[', ']' 的字符串s,判断字符串是否有效. 有效字符串满足: 左括号必须用相同类型的右括号 ...
- Junit5 pom依赖
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter- ...
- 【观察者设计模式详解】C/Java/JS/Go/Python/TS不同语言实现
简介 观察者模式(Observer Pattern)是一种行为型模式.它定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被自动更新. 观察者模式使用三个类S ...