diff --git a/rtsp/player.go b/rtsp/player.go index ee9ad672..0216936b 100644 --- a/rtsp/player.go +++ b/rtsp/player.go @@ -2,6 +2,7 @@ package rtsp import ( "sync" + "time" ) type Player struct { @@ -40,6 +41,7 @@ func (player *Player) QueueRTP(pack *RTPPack) *Player { func (player *Player) Start() { logger := player.logger + timer := time.Unix(0, 0) for !player.Stoped { var pack *RTPPack player.cond.L.Lock() @@ -60,5 +62,10 @@ func (player *Player) Start() { if err := player.SendRTP(pack); err != nil { logger.Println(err) } + elapsed := time.Now().Sub(timer) + if elapsed >= 30*time.Second { + logger.Printf("Send a package.type:%d\n", pack.Type) + timer = time.Now() + } } } diff --git a/rtsp/rtsp-session.go b/rtsp/rtsp-session.go index c80ae9bb..21740873 100644 --- a/rtsp/rtsp-session.go +++ b/rtsp/rtsp-session.go @@ -190,6 +190,7 @@ func (session *Session) Start() { buf1 := make([]byte, 1) buf2 := make([]byte, 2) logger := session.logger + timer := time.Unix(0, 0) for !session.Stoped { if _, err := io.ReadFull(session.connRW, buf1); err != nil { logger.Println(session, err) @@ -219,6 +220,11 @@ func (session *Session) Start() { Type: RTP_TYPE_AUDIO, Buffer: rtpBuf, } + elapsed := time.Now().Sub(timer) + if elapsed >= 30*time.Second { + logger.Println("Recv an audio RTP package") + timer = time.Now() + } case session.aRTPControlChannel: pack = &RTPPack{ Type: RTP_TYPE_AUDIOCONTROL, @@ -229,6 +235,11 @@ func (session *Session) Start() { Type: RTP_TYPE_VIDEO, Buffer: rtpBuf, } + elapsed := time.Now().Sub(timer) + if elapsed >= 30*time.Second { + logger.Println("Recv an video RTP package") + timer = time.Now() + } case session.vRTPControlChannel: pack = &RTPPack{ Type: RTP_TYPE_VIDEOCONTROL, diff --git a/rtsp/udp-server.go b/rtsp/udp-server.go index a4a66c3f..49de3caa 100644 --- a/rtsp/udp-server.go +++ b/rtsp/udp-server.go @@ -7,6 +7,7 @@ import ( "net" "strconv" "strings" + "time" "github.com/penggy/EasyGoLib/utils" ) @@ -27,7 +28,7 @@ type UDPServer struct { Stoped bool } -func (s* UDPServer)AddInputBytes(bytes int) { +func (s *UDPServer) AddInputBytes(bytes int) { if s.Session != nil { s.Session.InBytes += bytes return @@ -39,7 +40,7 @@ func (s* UDPServer)AddInputBytes(bytes int) { panic(fmt.Errorf("session and RTSPClient both nil")) } -func (s *UDPServer)HandleRTP(pack *RTPPack) { +func (s *UDPServer) HandleRTP(pack *RTPPack) { if s.Session != nil { for _, v := range s.Session.RTPHandles { v(pack) @@ -56,7 +57,7 @@ func (s *UDPServer)HandleRTP(pack *RTPPack) { panic(fmt.Errorf("session and RTSPClient both nil")) } -func (s *UDPServer) Logger() *log.Logger { +func (s *UDPServer) Logger() *log.Logger { if s.Session != nil { return s.Session.logger } @@ -116,8 +117,14 @@ func (s *UDPServer) SetupAudio() (err error) { bufUDP := make([]byte, UDP_BUF_SIZE) logger.Printf("udp server start listen audio port[%d]", s.APort) defer logger.Printf("udp server stop listen audio port[%d]", s.APort) + timer := time.Unix(0, 0) for !s.Stoped { if n, _, err := s.AConn.ReadFromUDP(bufUDP); err == nil { + elapsed := time.Now().Sub(timer) + if elapsed >= 30*time.Second { + logger.Printf("Package recv from AConn.len:%d\n", n) + timer = time.Now() + } rtpBytes := make([]byte, n) s.AddInputBytes(n) copy(rtpBytes, bufUDP) @@ -158,6 +165,7 @@ func (s *UDPServer) SetupAudio() (err error) { defer logger.Printf("udp server stop listen audio control port[%d]", s.AControlPort) for !s.Stoped { if n, _, err := s.AControlConn.ReadFromUDP(bufUDP); err == nil { + //logger.Printf("Package recv from AControlConn.len:%d\n", n) rtpBytes := make([]byte, n) s.AddInputBytes(n) copy(rtpBytes, bufUDP) @@ -202,8 +210,14 @@ func (s *UDPServer) SetupVideo() (err error) { bufUDP := make([]byte, UDP_BUF_SIZE) logger.Printf("udp server start listen video port[%d]", s.VPort) defer logger.Printf("udp server stop listen video port[%d]", s.VPort) + timer := time.Unix(0, 0) for !s.Stoped { if n, _, err := s.VConn.ReadFromUDP(bufUDP); err == nil { + elapsed := time.Now().Sub(timer) + if elapsed >= 30*time.Second { + logger.Printf("Package recv from VConn.len:%d\n", n) + timer = time.Now() + } rtpBytes := make([]byte, n) s.AddInputBytes(n) copy(rtpBytes, bufUDP) @@ -245,6 +259,7 @@ func (s *UDPServer) SetupVideo() (err error) { defer logger.Printf("udp server stop listen video control port[%d]", s.VControlPort) for !s.Stoped { if n, _, err := s.VControlConn.ReadFromUDP(bufUDP); err == nil { + //logger.Printf("Package recv from VControlConn.len:%d\n", n) rtpBytes := make([]byte, n) s.AddInputBytes(n) copy(rtpBytes, bufUDP)