Merge Session.write() into Session.Write().

This commit is contained in:
scruzin 2019-01-10 23:05:24 +10:30
parent 56a3bf8b26
commit 26e8133a6e
2 changed files with 18 additions and 23 deletions

View File

@ -858,25 +858,3 @@ func handshake(s *Session) error {
}
return nil
}
// write prepares data to write then sends it.
func (s *Session) write(buf []byte) error {
if buf[0] == RTMP_PACKET_TYPE_INFO || (buf[0] == 'F' && buf[1] == 'L' && buf[2] == 'V') {
return errUnimplemented
}
if len(buf) < minDataSize {
return errTinyPacket
}
pkt := packet{
packetType: buf[0],
bodySize: C_AMF_DecodeInt24(buf[1:4]),
timestamp: C_AMF_DecodeInt24(buf[4:7]) | uint32(buf[7])<<24,
channel: RTMP_CHANNEL_SOURCE,
info: s.streamID,
}
resizePacket(&pkt, pkt.bodySize, RTMP_PACKET_SIZE_AUTO)
copy(pkt.body, buf[minDataSize:minDataSize+pkt.bodySize])
return sendPacket(s, &pkt, false)
}

View File

@ -159,7 +159,24 @@ func (s *Session) Write(data []byte) (int, error) {
if !s.isConnected() {
return 0, errNotConnected
}
err := s.write(data)
if data[0] == RTMP_PACKET_TYPE_INFO || (data[0] == 'F' && data[1] == 'L' && data[2] == 'V') {
return 0, errUnimplemented
}
if len(data) < minDataSize {
return 0, errTinyPacket
}
pkt := packet{
packetType: data[0],
bodySize: C_AMF_DecodeInt24(data[1:4]),
timestamp: C_AMF_DecodeInt24(data[4:7]) | uint32(data[7])<<24,
channel: RTMP_CHANNEL_SOURCE,
info: s.streamID,
}
resizePacket(&pkt, pkt.bodySize, RTMP_PACKET_SIZE_AUTO)
copy(pkt.body, data[minDataSize:minDataSize+pkt.bodySize])
err := sendPacket(s, &pkt, false)
if err != nil {
return 0, err
}