-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtptransceiver.go
94 lines (79 loc) · 1.96 KB
/
rtptransceiver.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package rawrtc
/*
#cgo CFLAGS : -g -I../../include
#cgo linux LDFLAGS: -L../../lib -ldl
#cgo windows LDFLAGS: -L../../lib
#include "api.h"
*/
import "C"
import (
"fmt"
"unsafe"
)
type RtpTransceiver struct {
fd unsafe.Pointer
}
func (me *RtpTransceiver) Init() *RtpTransceiver {
return me
}
func (me *RtpTransceiver) Direction() string {
return C.GoString(C.RtpTransceiverGetDirection(me.fd))
}
func (me *RtpTransceiver) Mid() string {
mid := C.RtpTransceiverGetMid(me.fd)
defer func() {
C.Free(unsafe.Pointer(mid))
}()
return C.GoString(mid)
}
func (me *RtpTransceiver) Receiver() *RtpReceiver {
receiver := new(RtpReceiver).Init()
receiver.fd = C.RtpTransceiverGetReceiver(me.fd)
if receiver.fd == nil {
LogErrorf("Failed to RtpTransceiverGetReceiver.")
return nil
}
return receiver
}
func (me *RtpTransceiver) Sender() *RtpSender {
sender := new(RtpSender).Init()
sender.fd = C.RtpTransceiverGetSender(me.fd)
if sender.fd == nil {
LogErrorf("Failed to RtpTransceiverGetSender.")
return nil
}
return sender
}
func (me *RtpTransceiver) SetCodecPreferences(codecs []RtpCodecCapability) {
var (
size = len(codecs)
array = make([]unsafe.Pointer, size)
)
for i, codec := range codecs {
array[i] = codec.fd
}
if len(codecs) > 0 {
C.RtpTransceiverSetCodecPreferences(me.fd, (*unsafe.Pointer)(&array[0]), C.size_t(size))
}
}
func (me *RtpTransceiver) SetDirection(new_direction string) error {
var (
err C.raw_rtc_error_t
)
direction := C.CString(new_direction)
defer func() {
C.free(unsafe.Pointer(direction))
}()
eno := (int)(C.RtpTransceiverSetDirection(me.fd, direction, &err))
if eno != 0 {
LogErrorf("Failed to RtpTransceiverSetDirection: name=%s, message=%s", C.GoString(err.name), C.GoString(err.message))
return fmt.Errorf("%s: %s", C.GoString(err.name), C.GoString(err.message))
}
return nil
}
func (me *RtpTransceiver) Stop() {
C.RtpTransceiverStop(me.fd)
}
func (me *RtpTransceiver) Release() {
C.RtpTransceiverRelease(me.fd)
}