mirror of https://bitbucket.org/ausocean/av.git
rtmp: created session.go file and moved librtmp wrapper functions into this file, i.e. NewSession, Open, Close and Write
This commit is contained in:
parent
4fa0637fa1
commit
9cb70ac06b
60
rtmp/rtmp.go
60
rtmp/rtmp.go
|
@ -150,66 +150,6 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
// session provides parameters required for an rtmp communication session.
|
||||
type Session struct {
|
||||
rtmp *C_RTMP
|
||||
url string
|
||||
timeout uint
|
||||
}
|
||||
|
||||
// NewSession returns a new session.
|
||||
func NewSession(url string, connectTimeout uint) *Session {
|
||||
return &Session{
|
||||
url: url,
|
||||
timeout: connectTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// Open establishes an rtmp connection with the url passed into the
|
||||
// constructor
|
||||
func (s *Session) Open() error {
|
||||
if s.rtmp != nil {
|
||||
return errors.New("rtmp: attempt to start already running session")
|
||||
}
|
||||
var err error
|
||||
s.rtmp, err = startSession(s.rtmp, s.url, uint32(s.timeout))
|
||||
if s.rtmp == nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close terminates the rtmp connection
|
||||
func (s *Session) Close() error {
|
||||
if s.rtmp == nil {
|
||||
return Err(3)
|
||||
}
|
||||
ret := endSession(s.rtmp)
|
||||
s.rtmp = nil
|
||||
if ret != 0 {
|
||||
return Err(ret)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write writes a frame (flv tag) to the rtmp connection
|
||||
func (s *Session) Write(data []byte) (int, error) {
|
||||
if s.rtmp == nil {
|
||||
return 0, Err(3)
|
||||
}
|
||||
|
||||
if C_RTMP_IsConnected(s.rtmp) == 0 {
|
||||
//if C.RTMP_IsConnected(s.rtmp) == 0 {
|
||||
return 0, Err(1)
|
||||
}
|
||||
|
||||
if C_RTMP_Write(s.rtmp, data) == 0 {
|
||||
//if C.RTMP_Write(s.rtmp, (*byte)(unsafe.Pointer(&data[0])), int32(len(data))) == 0 {
|
||||
return 0, Err(2)
|
||||
}
|
||||
return len(data), nil
|
||||
}
|
||||
|
||||
// int RTMP_IsConnected(RTMP *r);
|
||||
// rtmp.c +363
|
||||
func C_RTMP_IsConnected(r *C_RTMP) int32 {
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
package rtmp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// session provides parameters required for an rtmp communication session.
|
||||
type Session struct {
|
||||
rtmp *C_RTMP
|
||||
url string
|
||||
timeout uint
|
||||
}
|
||||
|
||||
// NewSession returns a new session.
|
||||
func NewSession(url string, connectTimeout uint) *Session {
|
||||
return &Session{
|
||||
url: url,
|
||||
timeout: connectTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// Open establishes an rtmp connection with the url passed into the
|
||||
// constructor
|
||||
func (s *Session) Open() error {
|
||||
if s.rtmp != nil {
|
||||
return errors.New("rtmp: attempt to start already running session")
|
||||
}
|
||||
var err error
|
||||
s.rtmp, err = startSession(s.rtmp, s.url, uint32(s.timeout))
|
||||
if s.rtmp == nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close terminates the rtmp connection
|
||||
func (s *Session) Close() error {
|
||||
if s.rtmp == nil {
|
||||
return Err(3)
|
||||
}
|
||||
ret := endSession(s.rtmp)
|
||||
s.rtmp = nil
|
||||
if ret != 0 {
|
||||
return Err(ret)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write writes a frame (flv tag) to the rtmp connection
|
||||
func (s *Session) Write(data []byte) (int, error) {
|
||||
if s.rtmp == nil {
|
||||
return 0, Err(3)
|
||||
}
|
||||
|
||||
if C_RTMP_IsConnected(s.rtmp) == 0 {
|
||||
//if C.RTMP_IsConnected(s.rtmp) == 0 {
|
||||
return 0, Err(1)
|
||||
}
|
||||
|
||||
if C_RTMP_Write(s.rtmp, data) == 0 {
|
||||
//if C.RTMP_Write(s.rtmp, (*byte)(unsafe.Pointer(&data[0])), int32(len(data))) == 0 {
|
||||
return 0, Err(2)
|
||||
}
|
||||
return len(data), nil
|
||||
}
|
Loading…
Reference in New Issue