revid: fixed silly rtp bug

This commit is contained in:
Saxon 2019-04-09 15:44:18 +09:30
parent 2d15e98445
commit 4978db2f2b
2 changed files with 9 additions and 3 deletions

View File

@ -74,10 +74,10 @@ func (p *Pkt) Bytes(buf []byte) []byte {
if p.X { if p.X {
headerExtensionLen = int(4 + 4*len(p.Extension.Header)) headerExtensionLen = int(4 + 4*len(p.Extension.Header))
} }
requiredPktLen := defaultHeadSize + uint8(4*p.CC) + uint8(headerExtensionLen) + uint8(len(p.Payload)) + uint8(len(p.Padding)) requiredPktLen := defaultHeadSize + int(4*p.CC) + headerExtensionLen + len(p.Payload) + len(p.Padding)
// Create new space if no buffer is given, or it doesn't have sufficient capacity. // Create new space if no buffer is given, or it doesn't have sufficient capacity.
if buf == nil || requiredPktLen > uint8(cap(buf)) { if buf == nil || requiredPktLen > cap(buf) {
buf = make([]byte, requiredPktLen, defPktSize) buf = make([]byte, requiredPktLen, defPktSize)
} }
buf = buf[:requiredPktLen] buf = buf[:requiredPktLen]

View File

@ -282,5 +282,11 @@ func newRtpSender(addr string, log func(lvl int8, msg string, args ...interface{
// Write implements io.Writer. // Write implements io.Writer.
func (s *rtpSender) Write(d []byte) (int, error) { func (s *rtpSender) Write(d []byte) (int, error) {
return s.encoder.Write(s.data) s.data = make([]byte, len(d))
copy(s.data, d)
_, err := s.encoder.Write(s.data)
if err != nil {
s.log(logger.Warning, pkg+"rtpSender: write error", err.Error())
}
return len(d), nil
} }