1 Star 0 Fork 0

Bin/media-server-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
incomingstreamtrackmirrored.go 2.53 KB
一键复制 编辑 原始数据 按行查看 历史
notedit 提交于 2019-05-22 17:54 . fix mirror stream
package mediaserver
import (
"github.com/notedit/media-server-go/wrapper"
"github.com/notedit/sdp"
)
type mirrorEncoding struct {
id string
source native.RTPIncomingMediaStreamMultiplexer
depacketizer native.StreamTrackDepacketizer
}
type IncomingStreamTrackMirrored struct {
track *IncomingStreamTrack
receiver native.RTPReceiverFacade
counter int
encodings []*mirrorEncoding
}
func NewMirrorIncomingTrack(track *IncomingStreamTrack, timeService native.TimeService) *IncomingStreamTrackMirrored {
mirror := &IncomingStreamTrackMirrored{}
mirror.track = track
mirror.receiver = track.receiver
mirror.counter = 0
mirror.encodings = []*mirrorEncoding{}
for _,encoding := range track.GetEncodings() {
source := native.NewRTPIncomingMediaStreamMultiplexer(encoding.source.GetMedia().GetSsrc(), timeService)
encoding.source.AddListener(source)
newEncoding := &mirrorEncoding{
id: encoding.id,
source: source,
depacketizer: native.NewStreamTrackDepacketizer(source.SwigGetRTPIncomingMediaStream()),
}
mirror.encodings = append(mirror.encodings, newEncoding)
}
mirror.track.Attached()
return mirror
}
func (t *IncomingStreamTrackMirrored) GetStats() map[string]*IncomingAllStats {
return t.track.GetStats()
}
func (t *IncomingStreamTrackMirrored) GetActiveLayers() *ActiveLayersInfo {
return t.track.GetActiveLayers()
}
func (t *IncomingStreamTrackMirrored) GetID() string {
return t.track.GetID()
}
func (t *IncomingStreamTrackMirrored) GetTrackInfo() *sdp.TrackInfo {
return t.GetTrackInfo()
}
func (t *IncomingStreamTrackMirrored) GetSSRCs() {
}
func (t *IncomingStreamTrackMirrored) GetMedia() string {
return t.track.GetMedia()
}
func (t *IncomingStreamTrackMirrored) Attached() bool {
t.counter += 1
if t.counter == 1 {
return true
}
return false
}
func (t *IncomingStreamTrackMirrored) Refresh() {
t.track.Refresh()
}
func (t *IncomingStreamTrackMirrored) Detached() bool {
if t.counter == 0 {
return true
}
t.counter -= 1
if t.counter == 0 {
return true
}
return false
}
func (t *IncomingStreamTrackMirrored) Stop() {
if t.track == nil {
return
}
for i,encoding := range t.track.GetEncodings() {
mencoding := t.encodings[i]
encoding.GetSource().RemoveListener(mencoding.source)
native.DeleteRTPIncomingMediaStreamMultiplexer(t.encodings[i].source)
mencoding.depacketizer.Stop()
native.DeleteStreamTrackDepacketizer(mencoding.depacketizer)
}
t.track.Detached()
t.encodings = nil
t.track = nil
t.receiver = nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huzbin/media-server-go.git
git@gitee.com:huzbin/media-server-go.git
huzbin
media-server-go
media-server-go
master

搜索帮助