fajiao
2 years ago
9 changed files with 123 additions and 10 deletions
@ -0,0 +1,35 @@ |
|||
package ffmpeg |
|||
|
|||
import ( |
|||
"go.uber.org/zap" |
|||
"ycmediakit/internal/pkg/global" |
|||
"ycmediakit/internal/pkg/result" |
|||
"ycmediakit/internal/pkg/server/ffmpegServer" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
var ( |
|||
cfg *ffmpegServer.FfmpegConfig |
|||
log *zap.Logger |
|||
) |
|||
|
|||
func init() { |
|||
cfg = &global.AppConfig.Ffmpeg |
|||
log = zap.L() |
|||
} |
|||
|
|||
func ProbeStream(c *gin.Context) { |
|||
target := c.Query("target") |
|||
target, ok := ffmpegServer.PrepareUrl(target) |
|||
if !ok { |
|||
result.InvalidParams.WithVoidData().Failure(c) |
|||
return |
|||
} |
|||
jsonStr, err := ffmpegServer.ProbeStreamsWithTimeout(target, cfg.Timeout) |
|||
if err != nil { |
|||
result.Wrong.WithVoidData().WithMsg(err.Error()).Error(c) |
|||
return |
|||
} |
|||
result.Ok.WithData(jsonStr).Success(c) |
|||
} |
@ -0,0 +1,17 @@ |
|||
package ffmpegServer |
|||
|
|||
import ( |
|||
"fmt" |
|||
"testing" |
|||
) |
|||
|
|||
func TestProbeStreamsWithTimeout(t *testing.T) { |
|||
url := "rtsp://admin:hk123456@192.168.1.65:554/Streaming/Channels/101" |
|||
timeout := 5000 |
|||
str, err := ProbeStreamsWithTimeout(url, timeout) |
|||
if err != nil { |
|||
fmt.Println(err) |
|||
} else { |
|||
fmt.Println(str) |
|||
} |
|||
} |
Loading…
Reference in new issue