mirror of
https://github.com/Danile71/go-rtsp.git
synced 2025-10-05 16:16:54 +08:00
url -> uri
This commit is contained in:
6
rtsp.go
6
rtsp.go
@@ -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)
|
||||||
}
|
}
|
||||||
|
11
stream.go
11
stream.go
@@ -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
|
decoders map[int]*decoder
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
url string
|
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)
|
||||||
|
Reference in New Issue
Block a user