mirror of https://bitbucket.org/ausocean/av.git
packet.read/write -> readFrom/writeTo.
This commit is contained in:
parent
bef7177c5a
commit
82c010b6f7
|
@ -96,7 +96,7 @@ type packet struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// read reads an RTMP packet.
|
// read reads an RTMP packet.
|
||||||
func (pkt *packet) read(s *Session) error {
|
func (pkt *packet) readFrom(s *Session) error {
|
||||||
var hbuf [fullHeaderSize]byte
|
var hbuf [fullHeaderSize]byte
|
||||||
header := hbuf[:]
|
header := hbuf[:]
|
||||||
|
|
||||||
|
@ -197,7 +197,6 @@ func (pkt *packet) read(s *Session) error {
|
||||||
s.log(DebugLevel, pkg+"failed to read extended timestamp", "error", err.Error())
|
s.log(DebugLevel, pkg+"failed to read extended timestamp", "error", err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TODO: port this
|
|
||||||
pkt.timestamp = amf.DecodeInt32(header[size : size+4])
|
pkt.timestamp = amf.DecodeInt32(header[size : size+4])
|
||||||
hSize += 4
|
hSize += 4
|
||||||
}
|
}
|
||||||
|
@ -272,7 +271,7 @@ func (pkt *packet) resize(size uint32, ht uint8) {
|
||||||
// Packets are written in chunks which are Session.chunkSize in length (128 bytes in length).
|
// Packets are written in chunks which are Session.chunkSize in length (128 bytes in length).
|
||||||
// We defers sending small audio packets and combine consecutive small audio packets where possible to reduce I/O.
|
// We defers sending small audio packets and combine consecutive small audio packets where possible to reduce I/O.
|
||||||
// When queue is true, we expect a response to this request and cache the method on s.methodCalls.
|
// When queue is true, we expect a response to this request and cache the method on s.methodCalls.
|
||||||
func (pkt *packet) write(s *Session, queue bool) error {
|
func (pkt *packet) writeTo(s *Session, queue bool) error {
|
||||||
if pkt.body == nil {
|
if pkt.body == nil {
|
||||||
return errInvalidBody
|
return errInvalidBody
|
||||||
}
|
}
|
||||||
|
|
20
rtmp/rtmp.go
20
rtmp/rtmp.go
|
@ -218,7 +218,7 @@ func connectStream(s *Session) error {
|
||||||
var err error
|
var err error
|
||||||
for !s.isPlaying {
|
for !s.isPlaying {
|
||||||
pkt := packet{}
|
pkt := packet{}
|
||||||
err = pkt.read(s)
|
err = pkt.readFrom(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ func sendConnectPacket(s *Session) error {
|
||||||
|
|
||||||
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
||||||
|
|
||||||
return pkt.write(s, true) // response expected
|
return pkt.writeTo(s, true) // response expected
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendCreateStream(s *Session) error {
|
func sendCreateStream(s *Session) error {
|
||||||
|
@ -363,7 +363,7 @@ func sendCreateStream(s *Session) error {
|
||||||
|
|
||||||
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
||||||
|
|
||||||
return pkt.write(s, true) // response expected
|
return pkt.writeTo(s, true) // response expected
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendReleaseStream(s *Session) error {
|
func sendReleaseStream(s *Session) error {
|
||||||
|
@ -394,7 +394,7 @@ func sendReleaseStream(s *Session) error {
|
||||||
}
|
}
|
||||||
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
||||||
|
|
||||||
return pkt.write(s, false)
|
return pkt.writeTo(s, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendFCPublish(s *Session) error {
|
func sendFCPublish(s *Session) error {
|
||||||
|
@ -426,7 +426,7 @@ func sendFCPublish(s *Session) error {
|
||||||
|
|
||||||
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
||||||
|
|
||||||
return pkt.write(s, false)
|
return pkt.writeTo(s, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendFCUnpublish(s *Session) error {
|
func sendFCUnpublish(s *Session) error {
|
||||||
|
@ -458,7 +458,7 @@ func sendFCUnpublish(s *Session) error {
|
||||||
|
|
||||||
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
||||||
|
|
||||||
return pkt.write(s, false)
|
return pkt.writeTo(s, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendPublish(s *Session) error {
|
func sendPublish(s *Session) error {
|
||||||
|
@ -494,7 +494,7 @@ func sendPublish(s *Session) error {
|
||||||
|
|
||||||
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
||||||
|
|
||||||
return pkt.write(s, true) // response expected
|
return pkt.writeTo(s, true) // response expected
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendDeleteStream(s *Session, dStreamId float64) error {
|
func sendDeleteStream(s *Session, dStreamId float64) error {
|
||||||
|
@ -525,7 +525,7 @@ func sendDeleteStream(s *Session, dStreamId float64) error {
|
||||||
}
|
}
|
||||||
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
||||||
|
|
||||||
return pkt.write(s, false)
|
return pkt.writeTo(s, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendBytesReceived tells the server how many bytes the client has received.
|
// sendBytesReceived tells the server how many bytes the client has received.
|
||||||
|
@ -548,7 +548,7 @@ func sendBytesReceived(s *Session) error {
|
||||||
}
|
}
|
||||||
pkt.bodySize = 4
|
pkt.bodySize = 4
|
||||||
|
|
||||||
return pkt.write(s, false)
|
return pkt.writeTo(s, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendCheckBW(s *Session) error {
|
func sendCheckBW(s *Session) error {
|
||||||
|
@ -576,7 +576,7 @@ func sendCheckBW(s *Session) error {
|
||||||
|
|
||||||
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
pkt.bodySize = uint32((len(pbuf) - fullHeaderSize) - len(enc))
|
||||||
|
|
||||||
return pkt.write(s, false)
|
return pkt.writeTo(s, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func eraseMethod(m []method, i int) []method {
|
func eraseMethod(m []method, i int) []method {
|
||||||
|
|
|
@ -185,7 +185,7 @@ func (s *Session) Write(data []byte) (int, error) {
|
||||||
|
|
||||||
pkt.resize(pkt.bodySize, headerSizeAuto)
|
pkt.resize(pkt.bodySize, headerSizeAuto)
|
||||||
copy(pkt.body, data[flvTagheaderSize:flvTagheaderSize+pkt.bodySize])
|
copy(pkt.body, data[flvTagheaderSize:flvTagheaderSize+pkt.bodySize])
|
||||||
err := pkt.write(s, false)
|
err := pkt.writeTo(s, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue