mediamtx/internal/rtmp/client.go

39 lines
764 B
Go
Raw Normal View History

2021-04-03 09:39:19 +00:00
package rtmp
2021-04-03 09:35:45 +00:00
import (
"bufio"
"context"
"net"
"net/url"
2021-04-03 09:35:45 +00:00
"github.com/notedit/rtmp/format/rtmp"
)
// DialContext connects to a server in reading mode.
func DialContext(ctx context.Context, address string) (*Conn, error) {
// https://github.com/aler9/rtmp/blob/3be4a55359274dcd88762e72aa0a702e2d8ba2fd/format/rtmp/client.go#L74
u, err := url.Parse(address)
if err != nil {
return nil, err
}
host := rtmp.UrlGetHost(u)
var d net.Dialer
nconn, err := d.DialContext(ctx, "tcp", host)
2021-04-03 09:35:45 +00:00
if err != nil {
return nil, err
}
2021-12-22 16:37:15 +00:00
rconn := rtmp.NewConn(&bufio.ReadWriter{
Reader: bufio.NewReaderSize(nconn, readBufferSize),
Writer: bufio.NewWriterSize(nconn, writeBufferSize),
})
rconn.URL = u
return &Conn{
rconn: rconn,
nconn: nconn,
}, nil
2021-04-03 09:35:45 +00:00
}