mirror of
https://github.com/aler9/gortsplib
synced 2025-10-04 23:02:45 +08:00
update doc
This commit is contained in:
@@ -61,13 +61,13 @@ func main() {
|
|||||||
|
|
||||||
buf := make([]byte, 2048)
|
buf := make([]byte, 2048)
|
||||||
for {
|
for {
|
||||||
// read RTP frames from the source
|
// read RTP packets from the source
|
||||||
n, _, err := pc.ReadFrom(buf)
|
n, _, err := pc.ReadFrom(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// write RTP frames
|
// write RTP packets
|
||||||
err = conn.WriteFrame(0, gortsplib.StreamTypeRTP, buf[:n])
|
err = conn.WriteFrame(0, gortsplib.StreamTypeRTP, buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@@ -57,13 +57,13 @@ func main() {
|
|||||||
|
|
||||||
buf := make([]byte, 2048)
|
buf := make([]byte, 2048)
|
||||||
for {
|
for {
|
||||||
// read RTP frames from the source
|
// read RTP packets from the source
|
||||||
n, _, err := pc.ReadFrom(buf)
|
n, _, err := pc.ReadFrom(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// write RTP frames
|
// write RTP packets
|
||||||
err = conn.WriteFrame(0, gortsplib.StreamTypeRTP, buf[:n])
|
err = conn.WriteFrame(0, gortsplib.StreamTypeRTP, buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
|
@@ -49,13 +49,13 @@ func main() {
|
|||||||
|
|
||||||
buf := make([]byte, 2048)
|
buf := make([]byte, 2048)
|
||||||
for {
|
for {
|
||||||
// read RTP frames from the source
|
// read RTP packets from the source
|
||||||
n, _, err := pc.ReadFrom(buf)
|
n, _, err := pc.ReadFrom(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// write RTP frames
|
// write RTP packets
|
||||||
err = conn.WriteFrame(0, gortsplib.StreamTypeRTP, buf[:n])
|
err = conn.WriteFrame(0, gortsplib.StreamTypeRTP, buf[:n])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@@ -37,10 +37,10 @@ func main() {
|
|||||||
// instantiate a RTP/H264 decoder
|
// instantiate a RTP/H264 decoder
|
||||||
dec := rtph264.NewDecoder()
|
dec := rtph264.NewDecoder()
|
||||||
|
|
||||||
// read RTP frames
|
// read RTP packets
|
||||||
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
||||||
if streamType == gortsplib.StreamTypeRTP && trackID == h264Track {
|
if streamType == gortsplib.StreamTypeRTP && trackID == h264Track {
|
||||||
// convert RTP frames into H264 NALUs
|
// convert RTP packets into H264 NALUs
|
||||||
nalus, _, err := dec.Decode(payload)
|
nalus, _, err := dec.Decode(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@@ -29,7 +29,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
// read RTP frames
|
// read RTP packets
|
||||||
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
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))
|
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, streamType, len(payload))
|
||||||
})
|
})
|
||||||
|
@@ -51,7 +51,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// read RTP frames
|
// read RTP packets
|
||||||
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
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))
|
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, streamType, len(payload))
|
||||||
})
|
})
|
||||||
|
@@ -22,7 +22,7 @@ func main() {
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// read RTP frames
|
// read RTP packets
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
defer close(done)
|
defer close(done)
|
||||||
|
@@ -77,7 +77,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
mux.SetPCRPID(256)
|
mux.SetPCRPID(256)
|
||||||
|
|
||||||
// read RTP frames
|
// read RTP packets
|
||||||
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
||||||
if trackID != h264TrackID {
|
if trackID != h264TrackID {
|
||||||
return
|
return
|
||||||
@@ -94,7 +94,7 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert RTP frames into H264 NALUs
|
// convert RTP packets into H264 NALUs
|
||||||
nalus, pts, err := dec.DecodeRTP(&pkt)
|
nalus, pts, err := dec.DecodeRTP(&pkt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@@ -17,7 +17,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
// read RTP frames
|
// read RTP packets
|
||||||
err = conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
|
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))
|
fmt.Printf("frame from track %d, type %v, size %d\n", trackID, streamType, len(payload))
|
||||||
})
|
})
|
||||||
|
@@ -53,7 +53,7 @@ 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 packets.
|
||||||
func (rr *RTCPReceiver) ProcessFrame(ts time.Time, streamType base.StreamType, payload []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()
|
||||||
@@ -115,8 +115,8 @@ func (rr *RTCPReceiver) ProcessFrame(ts time.Time, streamType base.StreamType, p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// we can afford to unmarshal all RTCP frames
|
// we can afford to unmarshal all RTCP packets
|
||||||
// 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 packets
|
||||||
frames, err := rtcp.Unmarshal(payload)
|
frames, err := rtcp.Unmarshal(payload)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, frame := range frames {
|
for _, frame := range frames {
|
||||||
|
@@ -32,7 +32,7 @@ func New(clockRate int) *RTCPSender {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessFrame extracts the needed data from RTP or RTCP frames.
|
// ProcessFrame extracts the needed data from RTP or RTCP packets.
|
||||||
func (rs *RTCPSender) ProcessFrame(ts time.Time, streamType base.StreamType, payload []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()
|
||||||
|
@@ -512,7 +512,7 @@ func (sc *ServerConn) handleRequestOuter(req *base.Request) error {
|
|||||||
sc.tcpFrameBuffer = multibuffer.New(uint64(sc.s.ReadBufferCount), uint64(sc.s.ReadBufferSize))
|
sc.tcpFrameBuffer = multibuffer.New(uint64(sc.s.ReadBufferCount), uint64(sc.s.ReadBufferSize))
|
||||||
} else {
|
} else {
|
||||||
// when playing, tcpFrameBuffer is only used to receive RTCP receiver reports,
|
// when playing, tcpFrameBuffer is only used to receive RTCP receiver reports,
|
||||||
// that are much smaller than RTP frames and are sent at a fixed interval
|
// that are much smaller than RTP packets and are sent at a fixed interval
|
||||||
// (about 2 frames every 10 secs).
|
// (about 2 frames every 10 secs).
|
||||||
// decrease RAM consumption by allocating less buffers.
|
// decrease RAM consumption by allocating less buffers.
|
||||||
sc.tcpFrameBuffer = multibuffer.New(8, uint64(sc.s.ReadBufferSize))
|
sc.tcpFrameBuffer = multibuffer.New(8, uint64(sc.s.ReadBufferSize))
|
||||||
|
@@ -836,7 +836,7 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
|||||||
if *ss.setuppedProtocol == base.StreamProtocolUDP {
|
if *ss.setuppedProtocol == base.StreamProtocolUDP {
|
||||||
if *ss.setuppedDelivery == base.StreamDeliveryUnicast {
|
if *ss.setuppedDelivery == base.StreamDeliveryUnicast {
|
||||||
for trackID, track := range ss.setuppedTracks {
|
for trackID, track := range ss.setuppedTracks {
|
||||||
// readers can send RTCP frames
|
// readers can send RTCP packets
|
||||||
sc.s.udpRTCPListener.addClient(ss.ip(), track.udpRTCPPort, ss, trackID, false)
|
sc.s.udpRTCPListener.addClient(ss.ip(), track.udpRTCPPort, ss, trackID, false)
|
||||||
|
|
||||||
// open the firewall by sending packets to the counterpart
|
// open the firewall by sending packets to the counterpart
|
||||||
|
Reference in New Issue
Block a user