Skip to content

Commit 8c8ce40

Browse files
committed
print SRT content on screen
1 parent c725e31 commit 8c8ce40

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

internal/staticsources/srt/source.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
package srt
33

44
import (
5+
"fmt"
6+
"io"
7+
"log"
58
"time"
69

710
"github.com/bluenviron/gortsplib/v4/pkg/description"
@@ -16,6 +19,25 @@ import (
1619
"github.com/bluenviron/mediamtx/internal/stream"
1720
)
1821

22+
type loggedConn struct {
23+
R io.Reader
24+
}
25+
26+
func (c *loggedConn) Read(p []byte) (int, error) {
27+
n, err := c.R.Read(p)
28+
log.Println("incoming:")
29+
30+
for i, x := range p[:n] {
31+
fmt.Printf("0x%.2x, ", x)
32+
if (i+1)%8 == 0 {
33+
fmt.Println("")
34+
}
35+
}
36+
fmt.Println("")
37+
38+
return n, err
39+
}
40+
1941
// Source is a SRT static source.
2042
type Source struct {
2143
ReadTimeout conf.Duration
@@ -70,7 +92,8 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
7092

7193
func (s *Source) runReader(sconn srt.Conn) error {
7294
sconn.SetReadDeadline(time.Now().Add(time.Duration(s.ReadTimeout)))
73-
r := &mcmpegts.Reader{R: mcmpegts.NewBufferedReader(sconn)}
95+
lconn := &loggedConn{R: sconn}
96+
r := &mcmpegts.Reader{R: mcmpegts.NewBufferedReader(lconn)}
7497
err := r.Initialize()
7598
if err != nil {
7699
return err

0 commit comments

Comments
 (0)