mirror of https://bitbucket.org/ausocean/av.git
Removed unused chunk type and associated unused code.
This commit is contained in:
parent
2219a26890
commit
9ca1a49178
|
@ -91,19 +91,11 @@ type packet struct {
|
||||||
info int32
|
info int32
|
||||||
bodySize uint32
|
bodySize uint32
|
||||||
bytesRead uint32
|
bytesRead uint32
|
||||||
chunk *chunk
|
|
||||||
header []byte
|
header []byte
|
||||||
body []byte
|
body []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// chunk defines an RTMP packet chunk.
|
// read reads an RTMP packet.
|
||||||
type chunk struct {
|
|
||||||
headerSize int32
|
|
||||||
data []byte
|
|
||||||
header [fullHeaderSize]byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// read reads a packet.
|
|
||||||
func (pkt *packet) read(s *Session) error {
|
func (pkt *packet) read(s *Session) error {
|
||||||
var hbuf [fullHeaderSize]byte
|
var hbuf [fullHeaderSize]byte
|
||||||
header := hbuf[:]
|
header := hbuf[:]
|
||||||
|
@ -222,13 +214,6 @@ func (pkt *packet) read(s *Session) error {
|
||||||
chunkSize = toRead
|
chunkSize = toRead
|
||||||
}
|
}
|
||||||
|
|
||||||
if pkt.chunk != nil {
|
|
||||||
panic("non-nil chunk")
|
|
||||||
pkt.chunk.headerSize = int32(hSize)
|
|
||||||
copy(pkt.chunk.header[:], hbuf[:hSize])
|
|
||||||
pkt.chunk.data = pkt.body[pkt.bytesRead : pkt.bytesRead+uint32(chunkSize)]
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = s.read(pkt.body[pkt.bytesRead:][:chunkSize])
|
_, err = s.read(pkt.body[pkt.bytesRead:][:chunkSize])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log(DebugLevel, pkg+"failed to read packet body", "error", err.Error())
|
s.log(DebugLevel, pkg+"failed to read packet body", "error", err.Error())
|
||||||
|
@ -237,7 +222,7 @@ func (pkt *packet) read(s *Session) error {
|
||||||
|
|
||||||
pkt.bytesRead += uint32(chunkSize)
|
pkt.bytesRead += uint32(chunkSize)
|
||||||
|
|
||||||
// keep the packet as ref for other packets on this channel
|
// keep the packet as a reference for other packets on this channel
|
||||||
if s.channelsIn[pkt.channel] == nil {
|
if s.channelsIn[pkt.channel] == nil {
|
||||||
s.channelsIn[pkt.channel] = &packet{}
|
s.channelsIn[pkt.channel] = &packet{}
|
||||||
}
|
}
|
||||||
|
@ -264,6 +249,7 @@ func (pkt *packet) read(s *Session) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// resize adjusts the packet's storage to accommodate a body of the given size and header type.
|
// resize adjusts the packet's storage to accommodate a body of the given size and header type.
|
||||||
|
// When headerSizeAuto is specified, the header type is computed based on packet type.
|
||||||
func (pkt *packet) resize(size uint32, ht uint8) {
|
func (pkt *packet) resize(size uint32, ht uint8) {
|
||||||
buf := make([]byte, fullHeaderSize+size)
|
buf := make([]byte, fullHeaderSize+size)
|
||||||
pkt.header = buf
|
pkt.header = buf
|
||||||
|
@ -287,7 +273,9 @@ func (pkt *packet) resize(size uint32, ht uint8) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// write sends a packet.
|
// write sends an RTMP packet.
|
||||||
|
// 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.
|
||||||
// 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) write(s *Session, queue bool) error {
|
||||||
if pkt.body == nil {
|
if pkt.body == nil {
|
||||||
|
@ -438,7 +426,6 @@ func (pkt *packet) write(s *Session, queue bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(kortschak): Rewrite this horrific peice of premature optimisation.
|
// TODO(kortschak): Rewrite this horrific peice of premature optimisation.
|
||||||
// NB: RTMP wants packets in chunks which are 128 bytes by default, but the server may request a different size.
|
|
||||||
s.log(DebugLevel, pkg+"sending packet", "la", s.link.conn.LocalAddr(), "ra", s.link.conn.RemoteAddr(), "size", size)
|
s.log(DebugLevel, pkg+"sending packet", "la", s.link.conn.LocalAddr(), "ra", s.link.conn.RemoteAddr(), "size", size)
|
||||||
for size+hSize != 0 {
|
for size+hSize != 0 {
|
||||||
if chunkSize > size {
|
if chunkSize > size {
|
||||||
|
@ -461,6 +448,7 @@ func (pkt *packet) write(s *Session, queue bool) error {
|
||||||
hSize = 0
|
hSize = 0
|
||||||
|
|
||||||
if size > 0 {
|
if size > 0 {
|
||||||
|
// We are writing the 2nd or subsequent chunk.
|
||||||
origIdx -= 1 + cSize
|
origIdx -= 1 + cSize
|
||||||
hSize = 1 + cSize
|
hSize = 1 + cSize
|
||||||
|
|
||||||
|
@ -486,7 +474,7 @@ func (pkt *packet) write(s *Session, queue bool) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We invoked a remote method
|
// We invoked a remote method,
|
||||||
if pkt.packetType == packetTypeInvoke {
|
if pkt.packetType == packetTypeInvoke {
|
||||||
buf := pkt.body[1:]
|
buf := pkt.body[1:]
|
||||||
meth := amf.DecodeString(buf)
|
meth := amf.DecodeString(buf)
|
||||||
|
|
Loading…
Reference in New Issue