mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
move media-related logics into serverStreamMedia
This commit is contained in:
@@ -1,10 +1,25 @@
|
||||
package gortsplib
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/pion/rtp"
|
||||
|
||||
"github.com/aler9/gortsplib/v2/pkg/media"
|
||||
)
|
||||
|
||||
type serverStreamMedia struct {
|
||||
media *media.Media
|
||||
formats map[uint8]*serverStreamFormat
|
||||
multicastHandler *serverMulticastHandler
|
||||
}
|
||||
|
||||
func newServerStreamMedia(medi *media.Media) *serverStreamMedia {
|
||||
return &serverStreamMedia{
|
||||
media: medi,
|
||||
}
|
||||
}
|
||||
|
||||
func (sm *serverStreamMedia) close() {
|
||||
for _, tr := range sm.formats {
|
||||
if tr.rtcpSender != nil {
|
||||
@@ -28,3 +43,29 @@ func (sm *serverStreamMedia) allocateMulticastHandler(s *Server) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sm *serverStreamMedia) WritePacketRTPWithNTP(ss *ServerStream, pkt *rtp.Packet, ntp time.Time) {
|
||||
byts := make([]byte, maxPacketSize)
|
||||
n, err := pkt.MarshalTo(byts)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
byts = byts[:n]
|
||||
|
||||
forma := sm.formats[pkt.PayloadType]
|
||||
|
||||
forma.rtcpSender.ProcessPacket(pkt, ntp, forma.format.PTSEqualsDTS(pkt))
|
||||
|
||||
// send unicast
|
||||
for r := range ss.activeUnicastReaders {
|
||||
sm, ok := r.setuppedMedias[sm.media]
|
||||
if ok {
|
||||
sm.writePacketRTP(byts)
|
||||
}
|
||||
}
|
||||
|
||||
// send multicast
|
||||
if sm.multicastHandler != nil {
|
||||
sm.multicastHandler.writePacketRTP(byts)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user