add options

This commit is contained in:
Andrey Semochkin 2021-01-06 17:58:38 +03:00
parent 23ad40b14b
commit 3c9911e11b

View File

@ -43,34 +43,34 @@ const (
) )
type RTSPClient struct { type RTSPClient struct {
control string control string
seq int seq int
session string session string
realm string realm string
nonce string nonce string
username string username string
password string password string
startVideoTS int64 startVideoTS int64
startAudioTS int64 startAudioTS int64
videoID int videoID int
audioID int audioID int
mediaSDP []sdp.Media mediaSDP []sdp.Media
SDPRaw []byte SDPRaw []byte
conn net.Conn conn net.Conn
connRW *bufio.ReadWriter connRW *bufio.ReadWriter
pURL *url.URL pURL *url.URL
headers map[string]string headers map[string]string
Signals chan int Signals chan int
OutgoingProxy chan *[]byte OutgoingProxyQueue chan *[]byte
OutgoingPacket chan *av.Packet OutgoingPacketQueue chan *av.Packet
clientDigest bool clientDigest bool
clientBasic bool clientBasic bool
fuStarted bool fuStarted bool
options RTSPClientOptions options RTSPClientOptions
BufferRtpPacket *bytes.Buffer BufferRtpPacket *bytes.Buffer
sps []byte sps []byte
pps []byte pps []byte
CodecData []av.CodecData CodecData []av.CodecData
} }
type RTSPClientOptions struct { type RTSPClientOptions struct {
@ -79,18 +79,19 @@ type RTSPClientOptions struct {
DialTimeout time.Duration DialTimeout time.Duration
ReadWriteTimeout time.Duration ReadWriteTimeout time.Duration
DisableAudio bool DisableAudio bool
OutgoingProxy bool
} }
func Dial(options RTSPClientOptions) (*RTSPClient, error) { func Dial(options RTSPClientOptions) (*RTSPClient, error) {
client := &RTSPClient{ client := &RTSPClient{
headers: make(map[string]string), headers: make(map[string]string),
Signals: make(chan int, 100), Signals: make(chan int, 100),
OutgoingProxy: make(chan *[]byte, 3000), OutgoingProxyQueue: make(chan *[]byte, 3000),
OutgoingPacket: make(chan *av.Packet, 3000), OutgoingPacketQueue: make(chan *av.Packet, 3000),
BufferRtpPacket: bytes.NewBuffer([]byte{}), BufferRtpPacket: bytes.NewBuffer([]byte{}),
videoID: 0, videoID: 0,
audioID: 2, audioID: 2,
options: options, options: options,
} }
client.headers["User-Agent"] = "Lavf58.20.100" client.headers["User-Agent"] = "Lavf58.20.100"
err := client.parseURL(html.UnescapeString(client.options.URL)) err := client.parseURL(html.UnescapeString(client.options.URL))
@ -205,22 +206,24 @@ func (client *RTSPClient) startStream() {
return return
} }
//atomic.AddInt64(&client.Bitrate, int64(length+4)) //atomic.AddInt64(&client.Bitrate, int64(length+4))
if len(client.OutgoingProxy) < 2000 { if client.options.OutgoingProxy {
client.OutgoingProxy <- &content if len(client.OutgoingProxyQueue) < 2000 {
} else { client.OutgoingProxyQueue <- &content
client.Println("RTSP Client OutgoingProxy Chanel Full") } else {
return client.Println("RTSP Client OutgoingProxy Chanel Full")
return
}
} }
pkt, got := client.RTPDemuxer(&content) pkt, got := client.RTPDemuxer(&content)
if !got { if !got {
continue continue
} }
for _, i2 := range pkt { for _, i2 := range pkt {
if len(client.OutgoingPacket) > 2000 { if len(client.OutgoingPacketQueue) > 2000 {
client.Println("RTSP Client OutgoingPacket Chanel Full") client.Println("RTSP Client OutgoingPacket Chanel Full")
return return
} }
client.OutgoingPacket <- i2 client.OutgoingPacketQueue <- i2
} }
case 0x52: case 0x52:
var responseTmp []byte var responseTmp []byte