流媒体跳坑: 02-视频会议:Webrtc服务器

视频会议:Webrtc服务器

 当前免费视频服务器选择:

1.Intel Collaboration Suite for WebRTC
2.janus
3.Jitsi VideoBridge
4.Kurento
5.Licode
6.Meedooze
7.MediaSoup

大体查看了一下,根本hold不住,  免费的都是各种坑, 一个个跳估计要很久,   想舒舒服服的使用基本不可能.........

 

没办法,自己实现一个SFU , 

1.  怎么简单怎么来,  使用golang , 再设计一个发布定阅:

type PublisherMap struct {
    mutex       sync.RWMutex          // 读写锁
    pub_keyList []string              // id列表 用于排序
    Publishers  map[string]*Publisher // 订阅者信息

    sub_keyList []string               // id列表 用于排序
    Sublishers  map[string]*Subscriber // 订阅者信息
}

var single *PublisherMap

func GetSingle() *PublisherMap {
    if single == nil {
        single = &PublisherMap{}
        single.Publishers = make(map[string]*Publisher)
        single.Sublishers = make(map[string]*Subscriber)
    }

    return single
}

func (this *PublisherMap) AddPublisher(publish *Publisher) {

    single.mutex.Lock()
    defer single.mutex.Unlock()

    single.pub_keyList = append(single.pub_keyList, publish.Id)
    single.Publishers[publish.Id] = publish

}

func (this *PublisherMap) RemovePublisher(publisher_id string) {
    single.mutex.Lock()
    defer single.mutex.Unlock()

    //删除指定
    new_list := single.pub_keyList[:0]
    for _, v := range single.pub_keyList {
        if v != publisher_id {
            new_list = append(new_list, v)
        }
    }
    single.pub_keyList = new_list
    delete(single.Publishers, publisher_id)

}

func (this *PublisherMap) GetPublisher(id string) *Publisher {

    single.mutex.Lock()
    defer single.mutex.Unlock()

    for k, v := range single.Publishers {

        fmt.Println(" for ------------- ", k, id)

        if k == id {
            return v
        }
    }

    return nil
}

func (this *PublisherMap) GetPublisherList() interface{} {

    //复制一份发布者列表..
    var cache []*Publisher

    single.mutex.Lock()
    defer single.mutex.Unlock()

    for _, v := range single.pub_keyList {
        single.Publishers[v].UpdateTimeLen()
        cache = append(cache, single.Publishers[v])
    }

    return cache
}

func (this *PublisherMap) AddSubscriber(sublisher *Subscriber) {

    single.mutex.Lock()
    defer single.mutex.Unlock()

    single.sub_keyList = append(single.sub_keyList, sublisher.Id)
    single.Sublishers[sublisher.Id] = sublisher

    //向发布中增加
    for _, publisher := range single.Publishers {
        if publisher.Id == sublisher.Publisher_id {
            publisher.AddSubscriber(sublisher)
        }
    }

}

func (this *PublisherMap) RemoveSublisher(sublisher_id string) error {
    single.mutex.Lock()
    defer single.mutex.Unlock()

    //删除指定
    new_list := single.sub_keyList[:0]
    for _, v := range single.sub_keyList {
        if v != sublisher_id {
            new_list = append(new_list, v)
        }
    }
    single.sub_keyList = new_list
    delete(single.Sublishers, sublisher_id)

    // 从发布中删除
    for _, publisher := range single.Publishers {
        publisher.RemoveSubscriber(sublisher_id)
    }

    return nil
}

func (this *PublisherMap) GetSubscriber(id string) *Subscriber {

    single.mutex.Lock()
    defer single.mutex.Unlock()

    for k, v := range single.Sublishers {

        fmt.Println(" for ------------- ", k, id)

        if k == id {
            return v
        }
    }

    return nil
}

func (this *PublisherMap) GetSublisherList() []*Subscriber {

    //复制一份发布者列表..
    var cache []*Subscriber

    single.mutex.Lock()
    defer single.mutex.Unlock()

    for _, v := range single.pub_keyList {
        sub_list := single.Publishers[v].GetSubscriberList()
        for _, sub := range sub_list {
            cache = append(cache, sub)
        }
    }

    return cache
}

 

2.  设计一个简单测试, 这部分有HTML 部分,太麻烦,不发了.  直接上个效果图

(左面原视频: 右边是远程视频) 

 

 

 

 

 

实时性没有问题.

画面细节有瑕疵(第一张图,毛细血管细微部分看不清), 感觉不好, 一般用足够,但如果医疗使用则有问题.

增加码率没用, 估计WebRTC有码率上限, 换换其它办法..再试

 

正在整.....

 

posted @ 2020-06-06 09:55  睡觉的虫  阅读(566)  评论(0编辑  收藏  举报