通过替换推拉流库解决EasyDSS虚拟直播卡顿及不稳定的问题过程

推流平台EasyDSS里有个直播的类型叫虚拟直播,虚拟直播的直播源有两种类型,一个是点播资源,一个是在线资源。点播资源可以从EasyDSS里的点播服务里面去配置,在线资源必须是直播的源地址。

部分用户采用虚拟直播功能,当直播路数过多时,会出现卡顿问题,或者直播不稳定的问题。对此问题我们也进行了分析,原来的EasyDSS虚拟直播是采用FFmpeg方式来转码推流,内存占用高、不稳定,因此我们决定更换推拉流库,采用Nginx推拉流库,可以优化原本EasyDSS虚拟直播的问题。

Nginx优点:
1.可以高并发连接,官方测试Nginx能够支撑5万并发连接,实际生产环境中可以支撑2~4万并发连接数。
2.稳定性高。
3.内存消耗低。

虚拟直播推拉流的步骤:

a.接收到客户端开启虚拟直播的请求,后端对数据验证判断,并从数据库查找对应的虚拟直播记录。

b.根据这条虚拟直播记录新建一个ChannelInfo结构体,ChannelInfo包封装了推拉流的信息。

type ChannelInfo struct {
   Channel             string
   Name                string
   Online              int
   SnapURL             string
   ErrorString         string
   lock                sync.RWMutex
   delayTimer          *time.Timer
   stopRecordTimer     *time.Timer
   stopCMSRecordTimer  *time.Timer
   quit                chan bool
   snapTime            time.Time
   touchTime           time.Time
   cmsSnapTime         time.Time
   cleanSnapTime       time.Time
   cleanSnapDuration   time.Duration
   cleanRecordTime     time.Time
   cleanRecordDuration time.Duration
   snapTimeout         time.Duration
   snapDuration        time.Duration
   connectDuration     time.Duration
   loopDuration        time.Duration
   cmsSnapDuration     time.Duration
   touchDuration       time.Duration
   cmsSnapFunc         CMSSnapFunc
   vlive               *dao.TVlive
   client              *stream.StreamClient
   recordclient      *stream.StreamClient
   GbsId                  string
   gbsLiveStreamClient    *stream.StreamClient
   gbsRecordStreamClients map[string]*stream.StreamClient
   gbsRecordStreamM3u8    map[string]string
   // add by rookie for gbs
   localPusher     *stream.StreamPusher
   cdnPusher       *stream.StreamPusher
   recordPusher    *stream.StreamPusher
   cmsPusher       *stream.StreamPusher
   cmsRecordPusher *stream.StreamPusher
}

c.调用cgo代码开启拉流,推流:

拉流回调函数:

推流调CGo函数:

d.最后修改该条虚拟直播的状态为正在直播并保存到数据库中;

成功则状态为” living”:

开启失败则状态为”error”:

原文地址:https://www.cnblogs.com/easydss/p/14842021.html