mirror of https://bitbucket.org/ausocean/av.git
added uintToBool as common utility function
This commit is contained in:
parent
175afb89a2
commit
cd1e108dcf
12
rtmp/RTMP.go
12
rtmp/RTMP.go
|
@ -38,6 +38,7 @@ import (
|
||||||
_ "fmt"
|
_ "fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
"bitbucket.org/ausocean/av/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RTMPSession provides a crude interface for sending flv tags over rtmp
|
// RTMPSession provides a crude interface for sending flv tags over rtmp
|
||||||
|
@ -68,7 +69,7 @@ func NewRTMPSession(url string, connectTimeout uint) (session *rtmpSession) {
|
||||||
// constructor
|
// constructor
|
||||||
func (s *rtmpSession) StartSession() error {
|
func (s *rtmpSession) StartSession() error {
|
||||||
if !s.running {
|
if !s.running {
|
||||||
if !uintToBool(uint(C.RTMP_start_session(C.CString(s.url), C.uint(s.timeout)))) {
|
if !tools.UintToBool(uint(C.RTMP_start_session(C.CString(s.url), C.uint(s.timeout)))) {
|
||||||
return errors.New("RTMP start error! Check rtmp log for details!")
|
return errors.New("RTMP start error! Check rtmp log for details!")
|
||||||
}
|
}
|
||||||
s.running = true
|
s.running = true
|
||||||
|
@ -86,7 +87,7 @@ func (s *rtmpSession) WriteFrame(data []byte, dataLength uint) error {
|
||||||
if s.running {
|
if s.running {
|
||||||
dataCopy := make([]byte, len(data))
|
dataCopy := make([]byte, len(data))
|
||||||
copy(dataCopy, data)
|
copy(dataCopy, data)
|
||||||
if !uintToBool(uint(C.RTMP_write_frame((*C.char)(unsafe.Pointer(&dataCopy[0])), C.uint(dataLength)))) {
|
if !tools.UintToBool(uint(C.RTMP_write_frame((*C.char)(unsafe.Pointer(&dataCopy[0])), C.uint(dataLength)))) {
|
||||||
return errors.New("RTMP write error! Check rtmp log for details!")
|
return errors.New("RTMP write error! Check rtmp log for details!")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -98,7 +99,7 @@ func (s *rtmpSession) WriteFrame(data []byte, dataLength uint) error {
|
||||||
// EndSession terminates the rtmp connection
|
// EndSession terminates the rtmp connection
|
||||||
func (s *rtmpSession) EndSession() error {
|
func (s *rtmpSession) EndSession() error {
|
||||||
if s.running {
|
if s.running {
|
||||||
if !uintToBool(uint(C.RTMP_end_session())) {
|
if !tools.UintToBool(uint(C.RTMP_end_session())) {
|
||||||
return errors.New("RTMP end session error! Check rtmp log for details!")
|
return errors.New("RTMP end session error! Check rtmp log for details!")
|
||||||
}
|
}
|
||||||
s.running = false
|
s.running = false
|
||||||
|
@ -107,8 +108,3 @@ func (s *rtmpSession) EndSession() error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// uintToBool takes a uint and returns the bool equivalent
|
|
||||||
func uintToBool(x uint) bool {
|
|
||||||
return x != 0
|
|
||||||
}
|
|
||||||
|
|
|
@ -39,3 +39,8 @@ func BoolToByte(in bool) (out byte) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// uintToBool takes a uint and returns the bool equivalent
|
||||||
|
func UintToBool(x uint) bool {
|
||||||
|
return x != 0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue