MCPcopy Create free account
hub / github.com/deepch/RTSPtoWebRTC / RTSPWorker

Function RTSPWorker

stream.go:40–82  ·  view source on GitHub ↗
(name, url string, OnDemand, DisableAudio, Debug bool)

Source from the content-addressed store, hash-verified

38 }
39}
40func RTSPWorker(name, url string, OnDemand, DisableAudio, Debug bool) error {
41 keyTest := time.NewTimer(20 * time.Second)
42 clientTest := time.NewTimer(20 * time.Second)
43 //add next TimeOut
44 RTSPClient, err := rtspv2.Dial(rtspv2.RTSPClientOptions{URL: url, DisableAudio: DisableAudio, DialTimeout: 3 * time.Second, ReadWriteTimeout: 3 * time.Second, Debug: Debug})
45 if err != nil {
46 return err
47 }
48 defer RTSPClient.Close()
49 if RTSPClient.CodecData != nil {
50 Config.coAd(name, RTSPClient.CodecData)
51 }
52 var AudioOnly bool
53 if len(RTSPClient.CodecData) == 1 && RTSPClient.CodecData[0].Type().IsAudio() {
54 AudioOnly = true
55 }
56 for {
57 select {
58 case <-clientTest.C:
59 if OnDemand {
60 if !Config.HasViewer(name) {
61 return ErrorStreamExitNoViewer
62 } else {
63 clientTest.Reset(20 * time.Second)
64 }
65 }
66 case <-keyTest.C:
67 return ErrorStreamExitNoVideoOnStream
68 case signals := <-RTSPClient.Signals:
69 switch signals {
70 case rtspv2.SignalCodecUpdate:
71 Config.coAd(name, RTSPClient.CodecData)
72 case rtspv2.SignalStreamRTPStop:
73 return ErrorStreamExitRtspDisconnect
74 }
75 case packetAV := <-RTSPClient.OutgoingPacketQueue:
76 if AudioOnly || packetAV.IsKeyFrame {
77 keyTest.Reset(20 * time.Second)
78 }
79 Config.cast(name, *packetAV)
80 }
81 }
82}

Callers 1

RTSPWorkerLoopFunction · 0.85

Calls 3

coAdMethod · 0.80
HasViewerMethod · 0.80
castMethod · 0.80

Tested by

no test coverage detected