url -> uri

This commit is contained in:
danil_e71
2021-07-23 17:12:12 +03:00
parent 1250d72522
commit 67d4355660
2 changed files with 12 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
package rtsp
// Open rtsp stream of file
func Open(url string) (*Stream, error) {
stream := New(url)
// Open rtsp stream or file
func Open(uri string) (*Stream, error) {
stream := New(uri)
return stream, stream.Setup(Auto)
}

View File

@@ -23,13 +23,15 @@ const (
type Stream struct {
formatCtx *C.AVFormatContext
dictionary *C.AVDictionary
decoders map[int]*decoder
mu sync.RWMutex
url string
decoders map[int]*decoder
mu sync.RWMutex
uri string
}
func New(url string) (stream *Stream) {
stream = &Stream{url: url}
// New stream
func New(uri string) (stream *Stream) {
stream = &Stream{uri: uri}
stream.decoders = make(map[int]*decoder)
stream.formatCtx = C.avformat_alloc_context()
@@ -49,6 +51,7 @@ func free(stream *Stream) {
}
}
// Setup transport (tcp or udp)
func (stream *Stream) Setup(t Type) (err error) {
transport := C.CString("rtsp_transport")
defer C.free(unsafe.Pointer(transport))
@@ -67,7 +70,7 @@ func (stream *Stream) Setup(t Type) (err error) {
default:
}
uri := C.CString(stream.url)
uri := C.CString(stream.uri)
defer C.free(unsafe.Pointer(uri))
cerr := C.avformat_open_input(&stream.formatCtx, uri, nil, &stream.dictionary)