Created startSession func

This commit is contained in:
saxon 2018-07-19 16:05:14 +09:30
parent e83689c8e8
commit 6e8ef99953
1 changed files with 30 additions and 1 deletions

View File

@ -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 {