商城网站建设定制/我要发布信息
推流平台EasyDSS里有个直播的类型叫虚拟直播,虚拟直播的直播源有两种类型,一个是点播资源,一个是在线资源。点播资源可以从EasyDSS里的点播服务里面去配置,在线资源必须是直播的源地址。
部分用户采用虚拟直播功能,当直播路数过多时,会出现卡顿问题,或者直播不稳定的问题。对此问题我们也进行了分析,原来的EasyDSS虚拟直播是采用FFmpeg方式来转码推流,内存占用高、不稳定,因此我们决定更换推拉流库,采用Nginx推拉流库,可以优化原本EasyDSS虚拟直播的问题。
Nginx优点:
1.可以高并发连接,官方测试Nginx能够支撑5万并发连接,实际生产环境中可以支撑2~4万并发连接数。
2.稳定性高。
3.内存消耗低。
虚拟直播推拉流的步骤:
a.接收到客户端开启虚拟直播的请求,后端对数据验证判断,并从数据库查找对应的虚拟直播记录。
b.根据这条虚拟直播记录新建一个ChannelInfo结构体,ChannelInfo包封装了推拉流的信息。
type ChannelInfo struct {Channel stringName stringOnline intSnapURL stringErrorString stringlock sync.RWMutexdelayTimer *time.TimerstopRecordTimer *time.TimerstopCMSRecordTimer *time.Timerquit chan boolsnapTime time.TimetouchTime time.TimecmsSnapTime time.TimecleanSnapTime time.TimecleanSnapDuration time.DurationcleanRecordTime time.TimecleanRecordDuration time.DurationsnapTimeout time.DurationsnapDuration time.DurationconnectDuration time.DurationloopDuration time.DurationcmsSnapDuration time.DurationtouchDuration time.DurationcmsSnapFunc CMSSnapFuncvlive *dao.TVliveclient *stream.StreamClientrecordclient *stream.StreamClientGbsId stringgbsLiveStreamClient *stream.StreamClientgbsRecordStreamClients map[string]*stream.StreamClientgbsRecordStreamM3u8 map[string]string// add by rookie for gbslocalPusher *stream.StreamPushercdnPusher *stream.StreamPusherrecordPusher *stream.StreamPushercmsPusher *stream.StreamPushercmsRecordPusher *stream.StreamPusher
}
c.调用cgo代码开启拉流,推流:
拉流回调函数:
推流调CGo函数:
d.最后修改该条虚拟直播的状态为正在直播并保存到数据库中;
成功则状态为” living”:
开启失败则状态为”error”: