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 package rtsp
// Open rtsp stream of file // Open rtsp stream or file
func Open(url string) (*Stream, error) { func Open(uri string) (*Stream, error) {
stream := New(url) stream := New(uri)
return stream, stream.Setup(Auto) return stream, stream.Setup(Auto)
} }

View File

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