mirror of https://bitbucket.org/ausocean/av.git
Created startSession func
This commit is contained in:
parent
e83689c8e8
commit
6e8ef99953
31
rtmp/rtmp.go
31
rtmp/rtmp.go
|
@ -311,13 +311,42 @@ func (s *session) Open() error {
|
|||
return errors.New("rtmp: attempt to start already running session")
|
||||
}
|
||||
var err error
|
||||
s.rtmp, err = C.start_session(s.rtmp, C.CString(s.url), C.uint(s.timeout))
|
||||
s.rtmp, err = startSession(s.rtmp, s.url, uint32(s.timeout))
|
||||
if s.rtmp == nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func startSession(rtmp *C.RTMP, u string, timeout uint32) (*C.RTMP, error) {
|
||||
url := C.CString(u)
|
||||
connect_timeout := C.int(timeout)
|
||||
rtmp = C.RTMP_Alloc()
|
||||
C.RTMP_Init(rtmp)
|
||||
rtmp.Link.timeout = connect_timeout
|
||||
if C.RTMP_SetupURL(rtmp, url) == 0 {
|
||||
C.RTMP_Close(rtmp)
|
||||
C.RTMP_Free(rtmp)
|
||||
return nil, errors.New("rtmp startSession: Failed to setup URL!")
|
||||
}
|
||||
|
||||
C.RTMP_EnableWrite(rtmp)
|
||||
C.RTMP_SetBufferMS(rtmp, 3600*1000)
|
||||
if C.RTMP_Connect(rtmp, nil) == 0 {
|
||||
C.RTMP_Close(rtmp)
|
||||
C.RTMP_Free(rtmp)
|
||||
return nil, errors.New("rtmp startSession: Failed to connect!")
|
||||
}
|
||||
|
||||
if C.RTMP_ConnectStream(rtmp, 0) == 0 {
|
||||
C.RTMP_Close(rtmp)
|
||||
C.RTMP_Free(rtmp)
|
||||
return nil, errors.New("rtmp startSession: Failed to connect stream!")
|
||||
}
|
||||
|
||||
return rtmp, nil
|
||||
}
|
||||
|
||||
// Close terminates the rtmp connection
|
||||
func (s *session) Close() error {
|
||||
if s.rtmp == nil {
|
||||
|
|
Loading…
Reference in New Issue