mirror of
https://github.com/aler9/gortsplib
synced 2025-10-04 23:02:45 +08:00
improve write performance by
* buffering packets before sending them * removing mutexes
This commit is contained in:
@@ -2,6 +2,7 @@ package base
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -96,19 +97,13 @@ func (f *InterleavedFrame) Read(br *bufio.Reader) error {
|
||||
}
|
||||
|
||||
// Write writes an InterleavedFrame into a buffered writer.
|
||||
func (f InterleavedFrame) Write(bw *bufio.Writer) error {
|
||||
func (f InterleavedFrame) Write(bb *bytes.Buffer) {
|
||||
bb.Reset()
|
||||
|
||||
buf := []byte{0x24, byte(f.Channel), 0x00, 0x00}
|
||||
binary.BigEndian.PutUint16(buf[2:], uint16(len(f.Payload)))
|
||||
|
||||
_, err := bw.Write(buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bb.Write(buf)
|
||||
|
||||
_, err = bw.Write(f.Payload)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return bw.Flush()
|
||||
bb.Write(f.Payload)
|
||||
}
|
||||
|
Reference in New Issue
Block a user