-
Notifications
You must be signed in to change notification settings - Fork 119
/
mediaframesession.go
80 lines (62 loc) · 1.85 KB
/
mediaframesession.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package mediaserver
import (
"fmt"
"strings"
native "github.com/notedit/media-server-go/wrapper"
"github.com/notedit/sdp"
)
type MediaFrameSession struct {
sources map[string]native.RTPIncomingSourceGroup
incoming *IncomingStreamTrack
session native.MediaFrameSessionFacade
}
// NewMediaFrameSession create media frame session
func NewMediaFrameSession(media *sdp.MediaInfo) *MediaFrameSession {
mediaSession := &MediaFrameSession{}
var mediaType native.MediaFrameType = 0
if strings.ToLower(media.GetType()) == "video" {
mediaType = 1
}
session := native.NewMediaFrameSessionFacade(mediaType)
properties := native.NewPropertiesFacade()
if media != nil {
num := 0
for _, codec := range media.GetCodecs() {
item := fmt.Sprintf("codecs.%d", num)
properties.SetPropertyStr(item+".codec", codec.GetCodec())
properties.SetPropertyInt(item+".pt", codec.GetType())
num = num + 1
}
properties.SetPropertyInt("codecs.length", num)
}
session.Init(properties)
native.DeletePropertiesFacade(properties)
sources := map[string]native.RTPIncomingSourceGroup{"": session.GetIncomingSourceGroup()}
mediaSession.sources = sources
mediaSession.session = session
mediaSession.incoming = NewIncomingStreamTrack(media.GetType(), media.GetType(), native.RTPSessionToReceiver(session), sources)
return mediaSession
}
// GetIncomingStreamTrack get incoming stream track
func (s *MediaFrameSession) GetIncomingStreamTrack() *IncomingStreamTrack {
return s.incoming
}
// Push push raw media frame
func (s *MediaFrameSession) Push(rtp []byte) {
if rtp == nil || len(rtp) == 0 {
return
}
s.session.OnRTPPacket(&rtp[0], len(rtp))
}
// Stop stop this
func (s *MediaFrameSession) Stop() {
if s.session == nil {
return
}
if s.incoming != nil {
s.incoming.Stop()
}
s.session.End()
native.DeleteMediaFrameSessionFacade(s.session)
s.session = nil
}