Skip to content

Commit 8889446

Browse files
committed
Write method (implements io.Writer for RawPacket) to RawPacket
1 parent 75c6a1c commit 8889446

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/net/rtp/packets.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ func (rp *RawPacket) Buffer() []byte {
112112
return rp.buffer
113113
}
114114

115+
// Write writes data bytes from data buffer to the underlying RawPacket.
116+
func (rp *RawPacket) Write(data []byte) (int, error) {
117+
rp.buffer = data
118+
rp.inUse = len(data)
119+
rp.isFree = true
120+
return rp.inUse, nil
121+
}
122+
115123
// InUse returns the number of valid bytes in the packet buffer.
116124
// Several function modify the inUse variable, for example when copying payload or setting extensions
117125
// in the RTP packet. Thus "buffer[0:inUse]" is the slice inside the buffer that will be sent or
@@ -123,6 +131,12 @@ func (rp *RawPacket) InUse() int {
123131
// *** RTP specific functions start here ***
124132

125133
// DataPacket RTP packet type to define RTP specific functions
134+
//
135+
// if you want to copy incoming RTP packet as-is. For example
136+
// when you need to redirect RTP packet from WebRTC to plain RTP:
137+
// pkt := rtp.DataPacket{}
138+
// pkt.Write(buf.Bytes())
139+
// session.WriteData(&pkt)
126140
type DataPacket struct {
127141
RawPacket
128142
payloadLength int16

0 commit comments

Comments
 (0)