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