github.com/cnotch/ipchub@v1.1.0/service/rtsp/pull_stream_factory.go (about) 1 // Copyright (c) 2019,CAOHONGJU All rights reserved. 2 // Use of this source code is governed by a MIT-style 3 // license that can be found in the LICENSE file. 4 5 package rtsp 6 7 import ( 8 "strings" 9 10 "github.com/cnotch/ipchub/media" 11 ) 12 13 func init() { 14 // 注册拉流工厂 15 media.RegistPullStreamFactory(NewPullStreamFacotry()) 16 } 17 18 type pullStreamFactory struct { 19 } 20 21 // NewPullStreamFacotry 创建拉流工厂 22 func NewPullStreamFacotry() media.PullStreamFactory { 23 return &pullStreamFactory{} 24 } 25 26 func (f *pullStreamFactory) Can(remoteURL string) bool { 27 if len(remoteURL) >= len(rtspURLPrefix) && strings.EqualFold(remoteURL[:len(rtspURLPrefix)], rtspURLPrefix) { 28 return true 29 } 30 return false 31 } 32 33 func (f *pullStreamFactory) Create(localPath, remoteURL string) (*media.Stream, error) { 34 client, err := NewPullClient(localPath, remoteURL) 35 if err != nil { 36 return nil, err 37 } 38 err = client.Open() 39 if err != nil { 40 return nil, err 41 } 42 43 return client.stream, nil 44 }