mirror of
https://github.com/Monibuca/plugin-rtsp.git
synced 2025-11-03 02:03:19 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e9cf9a4ca | ||
|
|
67da93d8e2 | ||
|
|
cb733b368f |
29
client.go
29
client.go
@@ -7,8 +7,6 @@ import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
. "github.com/Monibuca/engine/v2"
|
||||
. "github.com/Monibuca/plugin-rtp"
|
||||
"io"
|
||||
"net"
|
||||
"net/url"
|
||||
@@ -16,6 +14,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
. "github.com/Monibuca/engine/v2"
|
||||
. "github.com/Monibuca/plugin-rtp"
|
||||
)
|
||||
|
||||
// PullStream 从外部拉流
|
||||
@@ -229,7 +230,11 @@ func (client *RTSP) requestStream() (err error) {
|
||||
if audioInfo, ok := client.SDPMap["audio"]; ok {
|
||||
client.AControl = audioInfo.Control
|
||||
client.ACodec = audioInfo.Codec
|
||||
client.WriteASC(audioInfo.Config)
|
||||
if len(audioInfo.Config) < 2 {
|
||||
Printf("Setup audio err codec not support: %s", client.ACodec)
|
||||
} else {
|
||||
client.WriteASC(audioInfo.Config)
|
||||
}
|
||||
var _url = ""
|
||||
if strings.Index(strings.ToLower(client.AControl), "rtsp://") == 0 {
|
||||
_url = client.AControl
|
||||
@@ -272,7 +277,20 @@ func (client *RTSP) requestStream() (err error) {
|
||||
func (client *RTSP) startStream() {
|
||||
//startTime := time.Now()
|
||||
//loggerTime := time.Now().Add(-10 * time.Second)
|
||||
defer client.Stop()
|
||||
defer func() {
|
||||
if client.Err() == nil && config.Reconnect {
|
||||
Printf("reconnecting:%s", client.URL)
|
||||
client.RTSPClientInfo = RTSPClientInfo{}
|
||||
if err := client.requestStream(); err != nil {
|
||||
Println(err)
|
||||
client.Stop()
|
||||
return
|
||||
}
|
||||
go client.startStream()
|
||||
} else {
|
||||
client.Stop()
|
||||
}
|
||||
}()
|
||||
for client.Err() == nil {
|
||||
//if client.OptionIntervalMillis > 0 {
|
||||
// if time.Since(startTime) > time.Duration(client.OptionIntervalMillis)*time.Millisecond {
|
||||
@@ -314,6 +332,9 @@ func (client *RTSP) startStream() {
|
||||
pack = &RTPPack{
|
||||
Type: RTP_TYPE_AUDIO,
|
||||
}
|
||||
if client.ACodec == "" {
|
||||
continue
|
||||
}
|
||||
case client.aRTPControlChannel:
|
||||
pack = &RTPPack{
|
||||
Type: RTP_TYPE_AUDIOCONTROL,
|
||||
|
||||
Reference in New Issue
Block a user