add some log

pull/154/head
milkywayrivers@gmail.com 6 years ago
parent 72d67f343b
commit ece3d4c444

@ -2,6 +2,7 @@ package rtsp
import ( import (
"sync" "sync"
"time"
) )
type Player struct { type Player struct {
@ -40,6 +41,7 @@ func (player *Player) QueueRTP(pack *RTPPack) *Player {
func (player *Player) Start() { func (player *Player) Start() {
logger := player.logger logger := player.logger
timer := time.Unix(0, 0)
for !player.Stoped { for !player.Stoped {
var pack *RTPPack var pack *RTPPack
player.cond.L.Lock() player.cond.L.Lock()
@ -60,5 +62,10 @@ func (player *Player) Start() {
if err := player.SendRTP(pack); err != nil { if err := player.SendRTP(pack); err != nil {
logger.Println(err) 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()
}
} }
} }

@ -190,6 +190,7 @@ func (session *Session) Start() {
buf1 := make([]byte, 1) buf1 := make([]byte, 1)
buf2 := make([]byte, 2) buf2 := make([]byte, 2)
logger := session.logger logger := session.logger
timer := time.Unix(0, 0)
for !session.Stoped { for !session.Stoped {
if _, err := io.ReadFull(session.connRW, buf1); err != nil { if _, err := io.ReadFull(session.connRW, buf1); err != nil {
logger.Println(session, err) logger.Println(session, err)
@ -219,6 +220,11 @@ func (session *Session) Start() {
Type: RTP_TYPE_AUDIO, Type: RTP_TYPE_AUDIO,
Buffer: rtpBuf, 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: case session.aRTPControlChannel:
pack = &RTPPack{ pack = &RTPPack{
Type: RTP_TYPE_AUDIOCONTROL, Type: RTP_TYPE_AUDIOCONTROL,
@ -229,6 +235,11 @@ func (session *Session) Start() {
Type: RTP_TYPE_VIDEO, Type: RTP_TYPE_VIDEO,
Buffer: rtpBuf, 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: case session.vRTPControlChannel:
pack = &RTPPack{ pack = &RTPPack{
Type: RTP_TYPE_VIDEOCONTROL, Type: RTP_TYPE_VIDEOCONTROL,

@ -7,6 +7,7 @@ import (
"net" "net"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/penggy/EasyGoLib/utils" "github.com/penggy/EasyGoLib/utils"
) )
@ -27,7 +28,7 @@ type UDPServer struct {
Stoped bool Stoped bool
} }
func (s* UDPServer)AddInputBytes(bytes int) { func (s *UDPServer) AddInputBytes(bytes int) {
if s.Session != nil { if s.Session != nil {
s.Session.InBytes += bytes s.Session.InBytes += bytes
return return
@ -39,7 +40,7 @@ func (s* UDPServer)AddInputBytes(bytes int) {
panic(fmt.Errorf("session and RTSPClient both nil")) panic(fmt.Errorf("session and RTSPClient both nil"))
} }
func (s *UDPServer)HandleRTP(pack *RTPPack) { func (s *UDPServer) HandleRTP(pack *RTPPack) {
if s.Session != nil { if s.Session != nil {
for _, v := range s.Session.RTPHandles { for _, v := range s.Session.RTPHandles {
v(pack) v(pack)
@ -56,7 +57,7 @@ func (s *UDPServer)HandleRTP(pack *RTPPack) {
panic(fmt.Errorf("session and RTSPClient both nil")) panic(fmt.Errorf("session and RTSPClient both nil"))
} }
func (s *UDPServer) Logger() *log.Logger { func (s *UDPServer) Logger() *log.Logger {
if s.Session != nil { if s.Session != nil {
return s.Session.logger return s.Session.logger
} }
@ -116,8 +117,14 @@ func (s *UDPServer) SetupAudio() (err error) {
bufUDP := make([]byte, UDP_BUF_SIZE) bufUDP := make([]byte, UDP_BUF_SIZE)
logger.Printf("udp server start listen audio port[%d]", s.APort) logger.Printf("udp server start listen audio port[%d]", s.APort)
defer logger.Printf("udp server stop 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 { for !s.Stoped {
if n, _, err := s.AConn.ReadFromUDP(bufUDP); err == nil { 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) rtpBytes := make([]byte, n)
s.AddInputBytes(n) s.AddInputBytes(n)
copy(rtpBytes, bufUDP) 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) defer logger.Printf("udp server stop listen audio control port[%d]", s.AControlPort)
for !s.Stoped { for !s.Stoped {
if n, _, err := s.AControlConn.ReadFromUDP(bufUDP); err == nil { if n, _, err := s.AControlConn.ReadFromUDP(bufUDP); err == nil {
//logger.Printf("Package recv from AControlConn.len:%d\n", n)
rtpBytes := make([]byte, n) rtpBytes := make([]byte, n)
s.AddInputBytes(n) s.AddInputBytes(n)
copy(rtpBytes, bufUDP) copy(rtpBytes, bufUDP)
@ -202,8 +210,14 @@ func (s *UDPServer) SetupVideo() (err error) {
bufUDP := make([]byte, UDP_BUF_SIZE) bufUDP := make([]byte, UDP_BUF_SIZE)
logger.Printf("udp server start listen video port[%d]", s.VPort) logger.Printf("udp server start listen video port[%d]", s.VPort)
defer logger.Printf("udp server stop 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 { for !s.Stoped {
if n, _, err := s.VConn.ReadFromUDP(bufUDP); err == nil { 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) rtpBytes := make([]byte, n)
s.AddInputBytes(n) s.AddInputBytes(n)
copy(rtpBytes, bufUDP) 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) defer logger.Printf("udp server stop listen video control port[%d]", s.VControlPort)
for !s.Stoped { for !s.Stoped {
if n, _, err := s.VControlConn.ReadFromUDP(bufUDP); err == nil { if n, _, err := s.VControlConn.ReadFromUDP(bufUDP); err == nil {
//logger.Printf("Package recv from VControlConn.len:%d\n", n)
rtpBytes := make([]byte, n) rtpBytes := make([]byte, n)
s.AddInputBytes(n) s.AddInputBytes(n)
copy(rtpBytes, bufUDP) copy(rtpBytes, bufUDP)

Loading…
Cancel
Save