Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
Cache byte slice only
  • Loading branch information
thinkski committed Sep 28, 2019
1 parent 76c366c commit bed4a89
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
5 changes: 0 additions & 5 deletions internal/packet/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,3 @@ func (w *Writer) Bytes() []byte {
func (w *Writer) Reset() {
w.offset = 0
}

// Return original byte slice (for sync.Pool)
func (w *Writer) Buffer() []byte {
return w.buffer
}
9 changes: 5 additions & 4 deletions internal/rtp/rtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func newRTPWriter(out io.Writer, ssrc uint32, crypto *cryptoContext) *rtpWriter
}
w.cache.OnEvicted = func(key lru.Key, value interface{}) {
// Recycle retransmission buffers to put less pressure on GC
w.pool.Put(value.(*packet.Writer).Buffer())
b := value.([]byte)
w.pool.Put(b[0:cap(b)])
}

return w
Expand Down Expand Up @@ -163,7 +164,7 @@ func (w *rtpWriter) writePacket(payloadType byte, marker bool, timestamp uint32,
w.totalBytes += uint64(len(payload))

// Add packet to cache for retransmission in case of nack.
w.cache.Add(uint16(index), p)
w.cache.Add(uint16(index), p.Bytes())

_, err := w.out.Write(p.Bytes())
return err
Expand All @@ -173,8 +174,8 @@ func (w *rtpWriter) writePacket(payloadType byte, marker bool, timestamp uint32,
func (w *rtpWriter) resend(sequenceNumber uint16) {
w.Lock()
defer w.Unlock()
if p, ok := w.cache.Get(sequenceNumber); ok {
if _, err := w.out.Write(p.(*packet.Writer).Bytes()); err != nil {
if b, ok := w.cache.Get(sequenceNumber); ok {
if _, err := w.out.Write(b.([]byte)); err != nil {
log.Error("Failed to retransmit: %s", err.Error())
}
} else {
Expand Down
6 changes: 1 addition & 5 deletions peer_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,7 @@ func (pc *PeerConnection) createAnswer() (sdp.Session, error) {
// Parse payload type from attribute. Will bin by payload type.
pt = -1
switch attr.Key {
case "rtpmap":
fallthrough
case "fmtp":
fallthrough
case "rtcp-fb":
case "fmtp", "rtcp-fb", "rtpmap":
if _, err := fmt.Sscanf(
attr.Value, "%3d %s", &pt, &text,
); err != nil {
Expand Down

0 comments on commit bed4a89

Please sign in to comment.