mirror of
https://github.com/Monibuca/plugin-rtsp.git
synced 2025-10-03 23:06:36 +08:00
增加重连功能
This commit is contained in:
25
client.go
25
client.go
@@ -7,8 +7,6 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
. "github.com/Monibuca/engine/v2"
|
|
||||||
. "github.com/Monibuca/plugin-rtp"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -16,6 +14,9 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
. "github.com/Monibuca/engine/v2"
|
||||||
|
. "github.com/Monibuca/plugin-rtp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PullStream 从外部拉流
|
// PullStream 从外部拉流
|
||||||
@@ -229,7 +230,11 @@ func (client *RTSP) requestStream() (err error) {
|
|||||||
if audioInfo, ok := client.SDPMap["audio"]; ok {
|
if audioInfo, ok := client.SDPMap["audio"]; ok {
|
||||||
client.AControl = audioInfo.Control
|
client.AControl = audioInfo.Control
|
||||||
client.ACodec = audioInfo.Codec
|
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 = ""
|
var _url = ""
|
||||||
if strings.Index(strings.ToLower(client.AControl), "rtsp://") == 0 {
|
if strings.Index(strings.ToLower(client.AControl), "rtsp://") == 0 {
|
||||||
_url = client.AControl
|
_url = client.AControl
|
||||||
@@ -272,7 +277,19 @@ func (client *RTSP) requestStream() (err error) {
|
|||||||
func (client *RTSP) startStream() {
|
func (client *RTSP) startStream() {
|
||||||
//startTime := time.Now()
|
//startTime := time.Now()
|
||||||
//loggerTime := time.Now().Add(-10 * time.Second)
|
//loggerTime := time.Now().Add(-10 * time.Second)
|
||||||
defer client.Stop()
|
if config.Reconnect {
|
||||||
|
defer func() {
|
||||||
|
Printf("reconnecting:", client.URL)
|
||||||
|
if err := client.requestStream(); err != nil {
|
||||||
|
Println(err)
|
||||||
|
client.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go client.startStream()
|
||||||
|
}()
|
||||||
|
} else {
|
||||||
|
defer client.Stop()
|
||||||
|
}
|
||||||
for client.Err() == nil {
|
for client.Err() == nil {
|
||||||
//if client.OptionIntervalMillis > 0 {
|
//if client.OptionIntervalMillis > 0 {
|
||||||
// if time.Since(startTime) > time.Duration(client.OptionIntervalMillis)*time.Millisecond {
|
// if time.Since(startTime) > time.Duration(client.OptionIntervalMillis)*time.Millisecond {
|
||||||
|
3
main.go
3
main.go
@@ -22,7 +22,8 @@ var config = struct {
|
|||||||
AutoPull bool
|
AutoPull bool
|
||||||
RemoteAddr string
|
RemoteAddr string
|
||||||
Timeout int
|
Timeout int
|
||||||
}{":554", false, "rtsp://localhost/${streamPath}", 0}
|
Reconnect bool
|
||||||
|
}{":554", false, "rtsp://localhost/${streamPath}", 0,false}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
InstallPlugin(&PluginConfig{
|
InstallPlugin(&PluginConfig{
|
||||||
|
Reference in New Issue
Block a user