mirror of
https://github.com/aler9/gortsplib
synced 2025-10-04 06:46:42 +08:00
rename buf into payload
This commit is contained in:
@@ -20,7 +20,7 @@ func main() {
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// check whether there's a H264 track
|
||||
// find the H264 track
|
||||
h264Track := func() int {
|
||||
for i, track := range conn.Tracks() {
|
||||
if track.IsH264() {
|
||||
@@ -34,14 +34,14 @@ func main() {
|
||||
}
|
||||
fmt.Printf("H264 track is number %d\n", h264Track+1)
|
||||
|
||||
// instantiate a decoder
|
||||
// instantiate a RTP/H264 decoder
|
||||
dec := rtph264.NewDecoder()
|
||||
|
||||
// read RTP frames
|
||||
err = conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
||||
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
||||
if trackID == h264Track {
|
||||
// convert RTP frames into H264 NALUs
|
||||
nalus, _, err := dec.Decode(buf)
|
||||
nalus, _, err := dec.Decode(payload)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@@ -30,8 +30,8 @@ func main() {
|
||||
defer conn.Close()
|
||||
|
||||
// read RTP frames
|
||||
err = conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
||||
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, streamType, len(payload))
|
||||
})
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -52,8 +52,8 @@ func main() {
|
||||
}
|
||||
|
||||
// read RTP frames
|
||||
err = conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
||||
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, streamType, len(payload))
|
||||
})
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -26,8 +26,8 @@ func main() {
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
||||
conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, streamType, len(payload))
|
||||
})
|
||||
}()
|
||||
|
||||
|
@@ -18,8 +18,8 @@ func main() {
|
||||
defer conn.Close()
|
||||
|
||||
// read RTP frames
|
||||
err = conn.ReadFrames(func(trackID int, typ gortsplib.StreamType, buf []byte) {
|
||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, typ, len(buf))
|
||||
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
||||
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, streamType, len(payload))
|
||||
})
|
||||
panic(err)
|
||||
}
|
||||
|
@@ -48,15 +48,15 @@ func New(receiverSSRC *uint32, clockRate int) *RTCPReceiver {
|
||||
}
|
||||
|
||||
// ProcessFrame extracts the needed data from RTP or RTCP frames.
|
||||
func (rr *RTCPReceiver) ProcessFrame(ts time.Time, streamType base.StreamType, buf []byte) {
|
||||
func (rr *RTCPReceiver) ProcessFrame(ts time.Time, streamType base.StreamType, payload []byte) {
|
||||
rr.mutex.Lock()
|
||||
defer rr.mutex.Unlock()
|
||||
|
||||
if streamType == base.StreamTypeRTP {
|
||||
// do not parse the entire packet, extract only the fields we need
|
||||
if len(buf) >= 8 {
|
||||
sequenceNumber := uint16(buf[2])<<8 | uint16(buf[3])
|
||||
rtpTime := uint32(buf[4])<<24 | uint32(buf[5])<<16 | uint32(buf[6])<<8 | uint32(buf[7])
|
||||
if len(payload) >= 8 {
|
||||
sequenceNumber := uint16(payload[2])<<8 | uint16(payload[3])
|
||||
rtpTime := uint32(payload[4])<<24 | uint32(payload[5])<<16 | uint32(payload[6])<<8 | uint32(payload[7])
|
||||
|
||||
// first frame
|
||||
if !rr.firstRTPReceived {
|
||||
@@ -111,7 +111,7 @@ func (rr *RTCPReceiver) ProcessFrame(ts time.Time, streamType base.StreamType, b
|
||||
} else {
|
||||
// we can afford to unmarshal all RTCP frames
|
||||
// since they are sent with a frequency much lower than the one of RTP frames
|
||||
frames, err := rtcp.Unmarshal(buf)
|
||||
frames, err := rtcp.Unmarshal(payload)
|
||||
if err == nil {
|
||||
for _, frame := range frames {
|
||||
if sr, ok := (frame).(*rtcp.SenderReport); ok {
|
||||
|
@@ -33,13 +33,13 @@ func New(clockRate int) *RTCPSender {
|
||||
}
|
||||
|
||||
// ProcessFrame extracts the needed data from RTP or RTCP frames.
|
||||
func (rs *RTCPSender) ProcessFrame(ts time.Time, streamType base.StreamType, buf []byte) {
|
||||
func (rs *RTCPSender) ProcessFrame(ts time.Time, streamType base.StreamType, payload []byte) {
|
||||
rs.mutex.Lock()
|
||||
defer rs.mutex.Unlock()
|
||||
|
||||
if streamType == base.StreamTypeRTP {
|
||||
pkt := rtp.Packet{}
|
||||
err := pkt.Unmarshal(buf)
|
||||
err := pkt.Unmarshal(payload)
|
||||
if err == nil {
|
||||
if !rs.firstRTPReceived {
|
||||
rs.firstRTPReceived = true
|
||||
|
Reference in New Issue
Block a user