mirror of https://bitbucket.org/ausocean/av.git
Merged Session.start()/close() into Open()/Close() respectively.
This commit is contained in:
parent
d4a0fad2be
commit
b3b1b04814
|
@ -127,54 +127,37 @@ func NewSession(url string, timeout uint, log Log) *Session {
|
|||
|
||||
// Open establishes an rtmp connection with the url passed into the constructor.
|
||||
func (s *Session) Open() error {
|
||||
s.log(DebugLevel, pkg+"Session.Open")
|
||||
if s.isConnected() {
|
||||
return errConnected
|
||||
}
|
||||
err := s.start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// start does the heavylifting for Open().
|
||||
func (s *Session) start() error {
|
||||
s.log(DebugLevel, pkg+"Session.start")
|
||||
err := setupURL(s)
|
||||
if err != nil {
|
||||
s.close()
|
||||
return err
|
||||
}
|
||||
|
||||
s.enableWrite()
|
||||
err = connect(s)
|
||||
if err != nil {
|
||||
s.close()
|
||||
s.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
err = connectStream(s)
|
||||
if err != nil {
|
||||
s.close()
|
||||
s.Close()
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close terminates the rtmp connection,
|
||||
// Close terminates the rtmp connection.
|
||||
// NB: The session object is cleared completely.
|
||||
func (s *Session) Close() error {
|
||||
s.log(DebugLevel, pkg+"Session.Close")
|
||||
if !s.isConnected() {
|
||||
return errNotConnected
|
||||
}
|
||||
s.close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// close does the heavylifting for Close().
|
||||
// Any errors are ignored as it is often called in response to an earlier error.
|
||||
func (s *Session) close() {
|
||||
s.log(DebugLevel, pkg+"Session.close")
|
||||
if s.isConnected() {
|
||||
if s.streamID > 0 {
|
||||
if s.link.protocol&RTMP_FEATURE_WRITE != 0 {
|
||||
sendFCUnpublish(s)
|
||||
|
@ -182,8 +165,8 @@ func (s *Session) close() {
|
|||
sendDeleteStream(s, float64(s.streamID))
|
||||
}
|
||||
s.link.conn.Close()
|
||||
}
|
||||
*s = Session{}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write writes a frame (flv tag) to the rtmp connection.
|
||||
|
@ -216,7 +199,10 @@ func (s *Session) Write(data []byte) (int, error) {
|
|||
}
|
||||
|
||||
// I/O functions
|
||||
// read from an RTMP connection.
|
||||
|
||||
// read from an RTMP connection. Sends a bytes received message if the
|
||||
// number of bytes received (nBytesIn) is greater than the number sent
|
||||
// (nBytesInSent) by 10% of the bandwidth.
|
||||
func (s *Session) read(buf []byte) error {
|
||||
err := s.link.conn.SetReadDeadline(time.Now().Add(time.Second * time.Duration(s.link.timeout)))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue