mirror of
				https://github.com/Monibuca/plugin-rtsp.git
				synced 2025-10-27 01:20:47 +08:00 
			
		
		
		
	Compare commits
	
		
			65 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | af053bb5e6 | ||
|   | bed7ba8a87 | ||
|   | 0cbc4beb0f | ||
|   | edbfc07275 | ||
|   | 329f93022e | ||
|   | 4895f2ec42 | ||
|   | 9eb117811d | ||
|   | 00ecd3469f | ||
|   | 4107d31c79 | ||
|   | 5094fd0db7 | ||
|   | ef106e42f8 | ||
|   | 0ac9513920 | ||
|   | a900613c70 | ||
|   | ac8aa96350 | ||
|   | f267b1ca52 | ||
|   | 229370c083 | ||
|   | bb1e8ba1d8 | ||
|   | 8cf3e0c0fc | ||
|   | 1ecb45d904 | ||
|   | 3ea5bb7f27 | ||
|   | 9aec4ec4be | ||
|   | da2fc9d462 | ||
|   | f68a3ee14b | ||
|   | a2f5cb87b1 | ||
|   | 5cdbc220de | ||
|   | f0a00f3db9 | ||
|   | fd8ebcd87c | ||
|   | cc731a25f0 | ||
|   | ba9f39853f | ||
|   | 0c8bd62e81 | ||
|   | dfe462a7d1 | ||
|   | cc7b899922 | ||
|   | b0c3cdb21a | ||
|   | d08230bf0c | ||
|   | 8a7fdedc0f | ||
|   | b7d59b0198 | ||
|   | dc65348ccb | ||
|   | 7fa6d0dcce | ||
|   | 0689154012 | ||
|   | 2e39eabcba | ||
|   | a9cb4cd853 | ||
|   | 7e61ba71f7 | ||
|   | d6384dcbd5 | ||
|   | 2159a6fd9b | ||
|   | 02f3e91085 | ||
|   | 7f40078b50 | ||
|   | bb563d64c7 | ||
|   | f7cb146b89 | ||
|   | 9bb49cb9f7 | ||
|   | 087d1aab4d | ||
|   | f949464328 | ||
|   | d89f1e2405 | ||
|   | 1d3fbfc20b | ||
|   | fd64a69a12 | ||
|   | 0e4406ad14 | ||
|   | 22f33886a9 | ||
|   | 8b1892209d | ||
|   | 2e9cf9a4ca | ||
|   | 67da93d8e2 | ||
|   | cb733b368f | ||
|   | fadeccddab | ||
|   | 93df7632a6 | ||
|   | 53c4788df2 | ||
|   | f5bdd6a298 | ||
|   | eaddc60775 | 
							
								
								
									
										65
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										65
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,26 +1,63 @@ | ||||
| # Monibuca 的RTSP 插件 | ||||
| # RTSP插件 | ||||
|  | ||||
| 主要功能是提供RTSP的端口监听接受RTSP推流,以及对RTSP地址进行拉流转发 | ||||
| ## 插件地址 | ||||
|  | ||||
| ## 插件名称 | ||||
| github.com/Monibuca/plugin-rtsp | ||||
|  | ||||
| RTSP | ||||
| ## 插件引入 | ||||
| ```go | ||||
| import ( | ||||
|     _ "github.com/Monibuca/plugin-rtsp" | ||||
| ) | ||||
| ``` | ||||
|  | ||||
| ## 默认插件配置 | ||||
|  | ||||
| ## 配置 | ||||
| ```toml | ||||
| [RTSP] | ||||
| # 端口接收推流 | ||||
| ListenAddr = ":554" | ||||
| BufferLength  = 2048 | ||||
| AutoPull     = false | ||||
| RemoteAddr   = "rtsp://localhost/${streamPath}" | ||||
| Reconnect = true | ||||
| [RTSP.AutoPullList] | ||||
| "live/rtsp1" = "rtsp://admin:admin@192.168.1.212:554/cam/realmonitor?channel=1&subtype=1" | ||||
| "live/rtsp2" = "rtsp://admin:admin@192.168.1.212:554/cam/realmonitor?channel=2&subtype=1" | ||||
| ``` | ||||
| - ListenAddr 是监听端口,可以将rtsp流推到Monibuca中 | ||||
| - BufferLength是指解析拉取的rtp包的缓冲大小 | ||||
| - AutoPull是指当有用户订阅一个新流的时候自动向远程拉流转发 | ||||
| - RemoteAddr 指远程拉流地址,其中${streamPath}是占位符,实际使用流路径替换。 | ||||
|  | ||||
| - `ListenAddr`是监听的地址 | ||||
| - `Reconnect` 是否自动重连 | ||||
| - `RTSP.AutoPullList` 可以配置多项,用于自动拉流,key是streamPath,value是远程rtsp地址 | ||||
|  | ||||
| ## 使用方法(拉流转发) | ||||
| ### 特殊功能 | ||||
|  | ||||
| 当自动拉流列表中当的streamPath为sub/xxx 这种形式的话,在gb28181的分屏显示时会优先采用rtsp流,已实现分屏观看子码流效果 | ||||
| ## 插件功能 | ||||
|  | ||||
| ### 接收RTSP协议的推流 | ||||
|  | ||||
| 例如通过ffmpeg向m7s进行推流 | ||||
|  | ||||
| ```bash | ||||
| ffmpeg -i **** rtsp://localhost/live/test | ||||
| ``` | ||||
|  | ||||
| 会在m7s内部形成一个名为live/test的流 | ||||
|  | ||||
| ### 从远程拉取rtsp到m7s中 | ||||
|  | ||||
| 可调用接口 | ||||
| `/api/rtsp/pull?target=[RTSP地址]&streamPath=[流标识]` | ||||
|  | ||||
| ## 使用编程方式拉流 | ||||
| ```go | ||||
| new(RTSP).PullStream("live/user1","rtsp://xxx.xxx.xxx.xxx/live/user1")  | ||||
| new(RTSPClient).PullStream("live/user1","rtsp://xxx.xxx.xxx.xxx/live/user1")  | ||||
| ``` | ||||
|  | ||||
| ### 罗列所有的rtsp协议的流 | ||||
|  | ||||
| 可调用接口 | ||||
| `/api/rtsp/list` | ||||
|  | ||||
| ### 从m7s中拉取rtsp协议流 | ||||
|  | ||||
| 直接通过协议rtsp://xxx.xxx.xxx.xxx/live/user1 即可播放 | ||||
| > h265 编码拉流尚未实现,敬请期待 | ||||
|   | ||||
							
								
								
									
										660
									
								
								client.go
									
									
									
									
									
								
							
							
						
						
									
										660
									
								
								client.go
									
									
									
									
									
								
							| @@ -1,548 +1,208 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"bufio" | ||||
| 	"bytes" | ||||
| 	"crypto/md5" | ||||
| 	"encoding/binary" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"net" | ||||
| 	"net/url" | ||||
| 	"regexp" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"time" | ||||
| 	"unsafe" | ||||
|  | ||||
| 	. "github.com/Monibuca/engine/v2" | ||||
| 	. "github.com/Monibuca/engine/v3" | ||||
| 	. "github.com/Monibuca/utils/v3" | ||||
| 	"github.com/Monibuca/utils/v3/codec" | ||||
| 	"github.com/aler9/gortsplib" | ||||
| 	"github.com/aler9/gortsplib/pkg/aac" | ||||
| 	"github.com/aler9/gortsplib/pkg/base" | ||||
| 	"github.com/pion/rtp" | ||||
| 	"github.com/pion/rtp/codecs" | ||||
| ) | ||||
|  | ||||
| // PullStream 从外部拉流 | ||||
| func (rtsp *RTSP) PullStream(streamPath string, rtspUrl string) (err error) { | ||||
| 	if result := rtsp.Publisher.Publish(streamPath); result { | ||||
| 		rtsp.Stream.Type = "RTSP" | ||||
| 		rtsp.RTSPInfo.StreamInfo = &rtsp.Stream.StreamInfo | ||||
| 		rtsp.TransType = TRANS_TYPE_TCP | ||||
| 		rtsp.vRTPChannel = 0 | ||||
| 		rtsp.vRTPControlChannel = 1 | ||||
| 		rtsp.aRTPChannel = 2 | ||||
| 		rtsp.aRTPControlChannel = 3 | ||||
| 		rtsp.URL = rtspUrl | ||||
| 		if err = rtsp.requestStream(); err != nil { | ||||
| 			Println(err) | ||||
| 			rtsp.Close() | ||||
| 			return | ||||
| type RTSPClient struct { | ||||
| 	RTSPublisher | ||||
| 	Transport         gortsplib.Transport | ||||
| 	*gortsplib.Client `json:"-"` | ||||
| } | ||||
|  | ||||
| // PullStream 从外部拉流 | ||||
| func (rtsp *RTSPClient) PullStream(streamPath string, rtspUrl string) (err error) { | ||||
| 	rtsp.Stream = &Stream{ | ||||
| 		StreamPath: streamPath, | ||||
| 		Type:       "RTSP Pull", | ||||
| 		ExtraProp:  rtsp, | ||||
| 	} | ||||
| 	if result := rtsp.Publish(); result { | ||||
| 		rtsp.URL = rtspUrl | ||||
| 		if config.Reconnect { | ||||
| 			go func() { | ||||
| 				for rtsp.pullStream(); rtsp.Err() == nil; rtsp.pullStream() { | ||||
| 					Printf("reconnecting:%s in 5 seconds", rtspUrl) | ||||
| 					if rtsp.Transport == gortsplib.TransportTCP { | ||||
| 						rtsp.Transport = gortsplib.TransportUDP | ||||
| 					} else { | ||||
| 						rtsp.Transport = gortsplib.TransportTCP | ||||
| 					} | ||||
| 					time.Sleep(time.Second * 5) | ||||
| 				} | ||||
| 				if rtsp.IsTimeout { | ||||
| 					go rtsp.PullStream(streamPath, rtspUrl) | ||||
| 				} | ||||
| 			}() | ||||
| 		} else { | ||||
| 			go rtsp.pullStream() | ||||
| 		} | ||||
| 		go rtsp.startStream() | ||||
| 		collection.Store(streamPath, rtsp) | ||||
| 		return | ||||
| 	} | ||||
| 	return errors.New("publish badname") | ||||
| } | ||||
| func DigestAuth(authLine string, method string, URL string) (string, error) { | ||||
| 	l, err := url.Parse(URL) | ||||
| 	if err != nil { | ||||
| 		return "", fmt.Errorf("Url parse error:%v,%v", URL, err) | ||||
| 	} | ||||
| 	realm := "" | ||||
| 	nonce := "" | ||||
| 	realmRex := regexp.MustCompile(`realm="(.*?)"`) | ||||
| 	result1 := realmRex.FindStringSubmatch(authLine) | ||||
|  | ||||
| 	nonceRex := regexp.MustCompile(`nonce="(.*?)"`) | ||||
| 	result2 := nonceRex.FindStringSubmatch(authLine) | ||||
|  | ||||
| 	if len(result1) == 2 { | ||||
| 		realm = result1[1] | ||||
| 	} else { | ||||
| 		return "", fmt.Errorf("auth error : no realm found") | ||||
| 	} | ||||
| 	if len(result2) == 2 { | ||||
| 		nonce = result2[1] | ||||
| 	} else { | ||||
| 		return "", fmt.Errorf("auth error : no nonce found") | ||||
| 	} | ||||
| 	// response= md5(md5(username:realm:password):nonce:md5(public_method:url)); | ||||
| 	username := l.User.Username() | ||||
| 	password, _ := l.User.Password() | ||||
| 	l.User = nil | ||||
| 	if l.Port() == "" { | ||||
| 		l.Host = fmt.Sprintf("%s:%s", l.Host, "554") | ||||
| 	} | ||||
| 	md5UserRealmPwd := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%s:%s:%s", username, realm, password)))) | ||||
| 	md5MethodURL := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%s:%s", method, l.String())))) | ||||
|  | ||||
| 	response := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%s:%s:%s", md5UserRealmPwd, nonce, md5MethodURL)))) | ||||
| 	Authorization := fmt.Sprintf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", response=\"%s\"", username, realm, nonce, l.String(), response) | ||||
| 	return Authorization, nil | ||||
| } | ||||
| func (client *RTSP) checkAuth(method string, resp *Response) (string, error) { | ||||
| 	if resp.StatusCode == 401 { | ||||
| 		// need auth. | ||||
| 		AuthHeaders := resp.Header["WWW-Authenticate"] | ||||
| 		auths, ok := AuthHeaders.([]string) | ||||
| 		if ok { | ||||
| 			for _, authLine := range auths { | ||||
| 				if strings.IndexAny(authLine, "Digest") == 0 { | ||||
| 					// 					realm="HipcamRealServer", | ||||
| 					// nonce="3b27a446bfa49b0c48c3edb83139543d" | ||||
| 					client.authLine = authLine | ||||
| 					return DigestAuth(authLine, method, client.URL) | ||||
| 				} else if strings.IndexAny(authLine, "Basic") == 0 { | ||||
| 					// not support yet | ||||
| 					// TODO.. | ||||
| 				} | ||||
| 			} | ||||
| 			return "", fmt.Errorf("auth error") | ||||
| 		} else { | ||||
| 			authLine, _ := AuthHeaders.(string) | ||||
| 			if strings.IndexAny(authLine, "Digest") == 0 { | ||||
| 				client.authLine = authLine | ||||
| 				return DigestAuth(authLine, method, client.URL) | ||||
| 			} else if strings.IndexAny(authLine, "Basic") == 0 { | ||||
| 				// not support yet | ||||
| 				// TODO.. | ||||
| 				return "", fmt.Errorf("not support Basic auth yet") | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return "", nil | ||||
| } | ||||
| func (client *RTSP) requestStream() (err error) { | ||||
| 	timeout := time.Duration(5) * time.Second | ||||
| 	l, err := url.Parse(client.URL) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if strings.ToLower(l.Scheme) != "rtsp" { | ||||
| 		err = fmt.Errorf("RTSP url is invalid") | ||||
| 		return err | ||||
| 	} | ||||
| 	if strings.ToLower(l.Hostname()) == "" { | ||||
| 		err = fmt.Errorf("RTSP url is invalid") | ||||
| 		return err | ||||
| 	} | ||||
| 	port := l.Port() | ||||
| 	if len(port) == 0 { | ||||
| 		port = "554" | ||||
| 	} | ||||
| 	conn, err := net.DialTimeout("tcp", l.Hostname()+":"+port, timeout) | ||||
| 	if err != nil { | ||||
| 		// handle error | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	networkBuffer := 204800 | ||||
|  | ||||
| 	timeoutConn := RichConn{ | ||||
| 		conn, | ||||
| 		timeout, | ||||
| 	} | ||||
| 	client.Conn = &timeoutConn | ||||
| 	client.connRW = bufio.NewReadWriter(bufio.NewReaderSize(&timeoutConn, networkBuffer), bufio.NewWriterSize(&timeoutConn, networkBuffer)) | ||||
|  | ||||
| 	headers := make(map[string]string) | ||||
| 	headers["Require"] = "implicit-play" | ||||
| 	// An OPTIONS request returns the request types the server will accept. | ||||
| 	resp, err := client.Request("OPTIONS", headers) | ||||
| 	if err != nil { | ||||
| 		if resp != nil { | ||||
| 			Authorization, _ := client.checkAuth("OPTIONS", resp) | ||||
| 			if len(Authorization) > 0 { | ||||
| 				headers := make(map[string]string) | ||||
| 				headers["Require"] = "implicit-play" | ||||
| 				headers["Authorization"] = Authorization | ||||
| 				// An OPTIONS request returns the request types the server will accept. | ||||
| 				resp, err = client.Request("OPTIONS", headers) | ||||
| 			} | ||||
| 			if err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| func (rtsp *RTSPClient) PushStream(streamPath string, rtspUrl string) (err error) { | ||||
| 	if s := FindStream(streamPath); s != nil { | ||||
| 		var tracks gortsplib.Tracks | ||||
| 		var sub RTSPSubscriber | ||||
| 		sub.Type = "RTSP push out" | ||||
| 		sub.vt = s.WaitVideoTrack("h264", "h265") | ||||
| 		sub.at = s.WaitAudioTrack("aac", "pcma", "pcmu") | ||||
| 		ssrc := uintptr(unsafe.Pointer(&sub)) | ||||
| 		var trackIds = 0 | ||||
| 		if sub.vt != nil { | ||||
| 			trackId := trackIds | ||||
| 			var vtrack *gortsplib.Track | ||||
| 			var vpacketer rtp.Packetizer | ||||
| 			switch sub.vt.CodecID { | ||||
| 			case codec.CodecID_H264: | ||||
| 				if vtrack, err = gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{ | ||||
| 					SPS: sub.vt.ExtraData.NALUs[0], | ||||
| 					PPS: sub.vt.ExtraData.NALUs[1], | ||||
| 				}); err == nil { | ||||
| 					vpacketer = rtp.NewPacketizer(1200, 96, uint32(ssrc), &codecs.H264Payloader{}, rtp.NewFixedSequencer(1), 90000) | ||||
| 				} else { | ||||
| 					return err | ||||
| 				} | ||||
| 			case codec.CodecID_H265: | ||||
| 				vtrack = NewH265Track(96, sub.vt.ExtraData.NALUs) | ||||
| 				vpacketer = rtp.NewPacketizer(1200, 96, uint32(ssrc), &H265Payloader{}, rtp.NewFixedSequencer(1), 90000) | ||||
| 			} | ||||
|  | ||||
| 	// A DESCRIBE request includes an RTSP URL (rtsp://...), and the type of reply data that can be handled. This reply includes the presentation description, | ||||
| 	// typically in Session Description Protocol (SDP) format. Among other things, the presentation description lists the media streams controlled with the aggregate URL. | ||||
| 	// In the typical case, there is one media stream each for audio and video. | ||||
| 	headers = make(map[string]string) | ||||
| 	headers["Accept"] = "application/sdp" | ||||
| 	resp, err = client.Request("DESCRIBE", headers) | ||||
| 	if err != nil { | ||||
| 		if resp != nil { | ||||
| 			authorization, _ := client.checkAuth("DESCRIBE", resp) | ||||
| 			if len(authorization) > 0 { | ||||
| 				headers := make(map[string]string) | ||||
| 				headers["Authorization"] = authorization | ||||
| 				headers["Accept"] = "application/sdp" | ||||
| 				resp, err = client.Request("DESCRIBE", headers) | ||||
| 			} | ||||
| 			if err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		} else { | ||||
| 			return err | ||||
| 			var st uint32 | ||||
| 			onVideo := func(ts uint32, pack *VideoPack) { | ||||
| 				for _, nalu := range pack.NALUs { | ||||
| 					for _, pack := range vpacketer.Packetize(nalu, (ts-st)*90) { | ||||
| 						rtp, _ := pack.Marshal() | ||||
| 						rtsp.WritePacketRTP(trackId, rtp) | ||||
| 					} | ||||
| 				} | ||||
| 	client.SDPRaw = resp.Body | ||||
| 	client.SDPMap = ParseSDP(client.SDPRaw) | ||||
| 	session := "" | ||||
| 	if videoInfo, ok := client.SDPMap["video"]; ok { | ||||
| 		client.VControl = videoInfo.Control | ||||
| 		client.VCodec = videoInfo.Codec | ||||
| 		client.SPS = videoInfo.SpropParameterSets[0] | ||||
| 		client.PPS = videoInfo.SpropParameterSets[1] | ||||
| 		var _url = "" | ||||
| 		if strings.Index(strings.ToLower(client.VControl), "rtsp://") == 0 { | ||||
| 			_url = client.VControl | ||||
| 		} else { | ||||
| 			_url = strings.TrimRight(client.URL, "/") + "/" + strings.TrimLeft(client.VControl, "/") | ||||
| 				st = ts | ||||
| 			} | ||||
| 		headers = make(map[string]string) | ||||
| 		if client.TransType == TRANS_TYPE_TCP { | ||||
| 			headers["Transport"] = fmt.Sprintf("RTP/AVP/TCP;unicast;interleaved=%d-%d", client.vRTPChannel, client.vRTPControlChannel) | ||||
| 		} else { | ||||
| 			if client.UDPServer == nil { | ||||
| 				client.UDPServer = &UDPServer{Session: client} | ||||
| 			sub.OnVideo = func(ts uint32, pack *VideoPack) { | ||||
| 				if st = ts; st != 0 { | ||||
| 					sub.OnVideo = onVideo | ||||
| 				} | ||||
| 			//RTP/AVP;unicast;client_port=64864-64865 | ||||
| 			err = client.UDPServer.SetupVideo() | ||||
| 			if err != nil { | ||||
| 				Printf("Setup video err.%v", err) | ||||
| 				return err | ||||
| 				onVideo(ts, pack) | ||||
| 			} | ||||
| 			headers["Transport"] = fmt.Sprintf("RTP/AVP/UDP;unicast;client_port=%d-%d", client.UDPServer.VPort, client.UDPServer.VControlPort) | ||||
| 			client.Conn.timeout = 0 //	UDP ignore timeout | ||||
| 			tracks = append(tracks, vtrack) | ||||
| 			trackIds++ | ||||
| 		} | ||||
| 		if session != "" { | ||||
| 			headers["Session"] = session | ||||
| 		if sub.at != nil { | ||||
| 			var st uint32 | ||||
| 			trackId := trackIds | ||||
| 			switch sub.at.CodecID { | ||||
| 			case codec.CodecID_PCMA, codec.CodecID_PCMU: | ||||
| 				atrack := NewG711Track(97, map[byte]string{7: "pcma", 8: "pcmu"}[sub.at.CodecID]) | ||||
| 				apacketizer := rtp.NewPacketizer(1200, 97, uint32(ssrc), &codecs.G711Payloader{}, rtp.NewFixedSequencer(1), 8000) | ||||
| 				sub.OnAudio = func(ts uint32, pack *AudioPack) { | ||||
| 					for _, pack := range apacketizer.Packetize(pack.Raw, (ts-st)*8) { | ||||
| 						buf, _ := pack.Marshal() | ||||
| 						rtsp.WritePacketRTP(trackId, buf) | ||||
| 					} | ||||
| 		Printf("Parse DESCRIBE response, VIDEO VControl:%s, VCode:%s, url:%s,Session:%s,vRTPChannel:%d,vRTPControlChannel:%d", client.VControl, client.VCodec, _url, session, client.vRTPChannel, client.vRTPControlChannel) | ||||
| 		if resp, err = client.RequestWithPath("SETUP", _url, headers, true); err != nil { | ||||
| 			return err | ||||
| 					st = ts | ||||
| 				} | ||||
| 		session, _ = resp.Header["Session"].(string) | ||||
| 		session = strings.Split(session, ";")[0] | ||||
| 				tracks = append(tracks, atrack) | ||||
| 			case codec.CodecID_AAC: | ||||
| 				var mpegConf aac.MPEG4AudioConfig | ||||
| 				mpegConf.Decode(sub.at.ExtraData[2:]) | ||||
| 				conf := &gortsplib.TrackConfigAAC{ | ||||
| 					Type:              int(mpegConf.Type), | ||||
| 					SampleRate:        mpegConf.SampleRate, | ||||
| 					ChannelCount:      mpegConf.ChannelCount, | ||||
| 					AOTSpecificConfig: mpegConf.AOTSpecificConfig, | ||||
| 				} | ||||
| 	if audioInfo, ok := client.SDPMap["audio"]; ok { | ||||
| 		client.AControl = audioInfo.Control | ||||
| 		client.ACodec = audioInfo.Codec | ||||
| 		client.AudioSpecificConfig = audioInfo.Config | ||||
| 		var _url = "" | ||||
| 		if strings.Index(strings.ToLower(client.AControl), "rtsp://") == 0 { | ||||
| 			_url = client.AControl | ||||
| 		} else { | ||||
| 			_url = strings.TrimRight(client.URL, "/") + "/" + strings.TrimLeft(client.AControl, "/") | ||||
| 				if atrack, err := gortsplib.NewTrackAAC(97, conf); err == nil { | ||||
| 					apacketizer := rtp.NewPacketizer(1200, 97, uint32(ssrc), &AACPayloader{}, rtp.NewFixedSequencer(1), uint32(mpegConf.SampleRate)) | ||||
| 					sub.OnAudio = func(ts uint32, pack *AudioPack) { | ||||
| 						for _, pack := range apacketizer.Packetize(pack.Raw, (ts-st)*uint32(mpegConf.SampleRate)/1000) { | ||||
| 							buf, _ := pack.Marshal() | ||||
| 							rtsp.WritePacketRTP(trackId, buf) | ||||
| 						} | ||||
| 		headers = make(map[string]string) | ||||
| 		if client.TransType == TRANS_TYPE_TCP { | ||||
| 			headers["Transport"] = fmt.Sprintf("RTP/AVP/TCP;unicast;interleaved=%d-%d", client.aRTPChannel, client.aRTPControlChannel) | ||||
| 		} else { | ||||
| 			if client.UDPServer == nil { | ||||
| 				client.UDPServer = &UDPServer{Session: client} | ||||
| 						st = ts | ||||
| 					} | ||||
| 			err = client.UDPServer.SetupAudio() | ||||
| 			if err != nil { | ||||
| 				Printf("Setup audio err.%v", err) | ||||
| 				return err | ||||
| 					tracks = append(tracks, atrack) | ||||
| 				} | ||||
| 			headers["Transport"] = fmt.Sprintf("RTP/AVP/UDP;unicast;client_port=%d-%d", client.UDPServer.APort, client.UDPServer.AControlPort) | ||||
| 			client.Conn.timeout = 0 //	UDP ignore timeout | ||||
| 			} | ||||
| 		if session != "" { | ||||
| 			headers["Session"] = session | ||||
| 		} | ||||
| 		Printf("Parse DESCRIBE response, AUDIO AControl:%s, ACodec:%s, url:%s,Session:%s, aRTPChannel:%d,aRTPControlChannel:%d", client.AControl, client.ACodec, _url, session, client.aRTPChannel, client.aRTPControlChannel) | ||||
| 		if resp, err = client.RequestWithPath("SETUP", _url, headers, true); err != nil { | ||||
| 			return err | ||||
| 		return rtsp.StartPublishing(rtspUrl, tracks) | ||||
| 	} | ||||
| 		session, _ = resp.Header["Session"].(string) | ||||
| 		session = strings.Split(session, ";")[0] | ||||
| 	return errors.New("stream not exist") | ||||
| } | ||||
| 	headers = make(map[string]string) | ||||
| 	if session != "" { | ||||
| 		headers["Session"] = session | ||||
| 	} | ||||
| 	resp, err = client.Request("PLAY", headers) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (client *RTSP) startStream() { | ||||
| 	//startTime := time.Now() | ||||
| 	//loggerTime := time.Now().Add(-10 * time.Second) | ||||
| 	defer client.Stop() | ||||
| 	for client.Err() == nil { | ||||
| 		//if client.OptionIntervalMillis > 0 { | ||||
| 		//	if time.Since(startTime) > time.Duration(client.OptionIntervalMillis)*time.Millisecond { | ||||
| 		//		startTime = time.Now() | ||||
| 		//		headers := make(map[string]string) | ||||
| 		//		headers["Require"] = "implicit-play" | ||||
| 		//		// An OPTIONS request returns the request types the server will accept. | ||||
| 		//		if err := client.RequestNoResp("OPTIONS", headers); err != nil { | ||||
| 		//			// ignore... | ||||
| 		//		} | ||||
| 		//	} | ||||
| 		//} | ||||
| 		b, err := client.connRW.ReadByte() | ||||
| 		if err != nil { | ||||
| 			Printf("client.connRW.ReadByte err:%v", err) | ||||
| func (client *RTSPClient) pullStream() { | ||||
| 	if client.Err() != nil { | ||||
| 		return | ||||
| 	} | ||||
| 		switch b { | ||||
| 		case 0x24: // rtp | ||||
| 			header := make([]byte, 4) | ||||
| 			header[0] = b | ||||
| 			_, err := io.ReadFull(client.connRW, header[1:]) | ||||
| 	client.Client = &gortsplib.Client{ | ||||
| 		OnPacketRTP: func(trackID int, payload []byte) { | ||||
| 			if f := client.processFunc[trackID]; f != nil { | ||||
| 				var clone []byte | ||||
| 				f(append(clone, payload...)) | ||||
| 			} | ||||
| 		}, | ||||
| 		Transport: &client.Transport, | ||||
| 	} | ||||
| 	// parse URL | ||||
| 	u, err := base.ParseURL(client.URL) | ||||
| 	if err != nil { | ||||
| 				Printf("io.ReadFull err:%v", err) | ||||
| 		Printf("ParseURL:%s error:%v", client.URL, err) | ||||
| 		return | ||||
| 	} | ||||
| 			channel := int(header[1]) | ||||
| 			length := binary.BigEndian.Uint16(header[2:]) | ||||
| 			content := make([]byte, length) | ||||
| 			_, err = io.ReadFull(client.connRW, content) | ||||
| 	// connect to the server | ||||
| 	if err = client.Start(u.Scheme, u.Host); err != nil { | ||||
| 		Printf("connect:%s error:%v", client.URL, err) | ||||
| 		return | ||||
| 	} | ||||
| 	//client.close should be after connected! | ||||
| 	defer client.Client.Close() | ||||
| 	var res *base.Response | ||||
| 	if res, err = client.Options(u); err != nil { | ||||
| 		Printf("option:%s error:%v", client.URL, err) | ||||
| 		return | ||||
| 	} | ||||
| 	Println(res) | ||||
| 	// find published tracks | ||||
| 	tracks, baseURL, res, err := client.Describe(u) | ||||
| 	if err != nil { | ||||
| 				Printf("io.ReadFull err:%v", err) | ||||
| 		Printf("Describe:%s error:%v", client.URL, err) | ||||
| 		return | ||||
| 	} | ||||
| 			rtpBuf := content | ||||
| 			var pack *RTPPack | ||||
| 			switch channel { | ||||
| 			case client.aRTPChannel: | ||||
| 				pack = &RTPPack{ | ||||
| 					Type:   RTP_TYPE_AUDIO, | ||||
| 					Buffer: rtpBuf, | ||||
| 	Println(res) | ||||
| 	if client.processFunc == nil { | ||||
| 		client.setTracks(tracks) | ||||
| 	} | ||||
| 			case client.aRTPControlChannel: | ||||
| 				pack = &RTPPack{ | ||||
| 					Type:   RTP_TYPE_AUDIOCONTROL, | ||||
| 					Buffer: rtpBuf, | ||||
| 				} | ||||
| 			case client.vRTPChannel: | ||||
| 				pack = &RTPPack{ | ||||
| 					Type:   RTP_TYPE_VIDEO, | ||||
| 					Buffer: rtpBuf, | ||||
| 				} | ||||
| 			case client.vRTPControlChannel: | ||||
| 				pack = &RTPPack{ | ||||
| 					Type:   RTP_TYPE_VIDEOCONTROL, | ||||
| 					Buffer: rtpBuf, | ||||
| 				} | ||||
| 			default: | ||||
| 				Printf("unknow rtp pack type, channel:%v", channel) | ||||
| 				continue | ||||
| 			} | ||||
| 			if pack == nil { | ||||
| 				Printf("session tcp got nil rtp pack") | ||||
| 				continue | ||||
| 			} | ||||
|  | ||||
| 			//if client.debugLogEnable { | ||||
| 			//	rtp := ParseRTP(pack.Buffer) | ||||
| 			//	if rtp != nil { | ||||
| 			//		rtpSN := uint16(rtp.SequenceNumber) | ||||
| 			//		if client.lastRtpSN != 0 && client.lastRtpSN+1 != rtpSN { | ||||
| 			//			Printf("%s, %d packets lost, current SN=%d, last SN=%d\n", client.String(), rtpSN-client.lastRtpSN, rtpSN, client.lastRtpSN) | ||||
| 			//		} | ||||
| 			//		client.lastRtpSN = rtpSN | ||||
| 			//	} | ||||
| 			// | ||||
| 			//	elapsed := time.Now().Sub(loggerTime) | ||||
| 			//	if elapsed >= 30*time.Second { | ||||
| 			//		Printf("%v read rtp frame.", client) | ||||
| 			//		loggerTime = time.Now() | ||||
| 			//	} | ||||
| 			//} | ||||
|  | ||||
| 			client.InBytes += int(length + 4) | ||||
| 			client.handleRTP(pack) | ||||
|  | ||||
| 		default: // rtsp | ||||
| 			builder := bytes.Buffer{} | ||||
| 			builder.WriteByte(b) | ||||
| 			contentLen := 0 | ||||
| 			for client.Err() == nil { | ||||
| 				line, prefix, err := client.connRW.ReadLine() | ||||
| 				if err != nil { | ||||
| 					Printf("client.connRW.ReadLine err:%v", err) | ||||
| 	for _, track := range tracks { | ||||
| 		if res, err = client.Setup(true, track, baseURL, 0, 0); err != nil { | ||||
| 			Printf("Setup:%s error:%v", baseURL.String(), err) | ||||
| 			return | ||||
| 		} | ||||
| 				if len(line) == 0 { | ||||
| 					if contentLen != 0 { | ||||
| 						content := make([]byte, contentLen) | ||||
| 						_, err = io.ReadFull(client.connRW, content) | ||||
| 						if err != nil { | ||||
| 							err = fmt.Errorf("Read content err.ContentLength:%d", contentLen) | ||||
| 		Println(res) | ||||
| 	} | ||||
| 	// start reading tracks | ||||
| 	if res, err = client.Play(nil); err != nil { | ||||
| 		Printf("Play:%s error:%v", baseURL.String(), err) | ||||
| 		return | ||||
| 	} | ||||
| 						builder.Write(content) | ||||
| 					} | ||||
| 					Printf("<<<[IN]\n%s", builder.String()) | ||||
| 					break | ||||
| 				} | ||||
| 				s := string(line) | ||||
| 				builder.Write(line) | ||||
| 				if !prefix { | ||||
| 					builder.WriteString("\r\n") | ||||
| 				} | ||||
|  | ||||
| 				if strings.Index(s, "Content-Length:") == 0 { | ||||
| 					splits := strings.Split(s, ":") | ||||
| 					contentLen, err = strconv.Atoi(strings.TrimSpace(splits[1])) | ||||
| 					if err != nil { | ||||
| 						Printf("strconv.Atoi err:%v, str:%v", err, splits[1]) | ||||
| 						return | ||||
| 	Println(res) | ||||
| 	// wait until a fatal error | ||||
| 	var fatalChan = make(chan error) | ||||
| 	go func() { | ||||
| 		fatalChan <- client.Wait() | ||||
| 	}() | ||||
| 	select { | ||||
| 	case err := <-fatalChan: | ||||
| 		Printf("Wait:%s error:%v", baseURL.String(), err) | ||||
| 	case <-client.Done(): | ||||
| 		Printf("client:%s done", client.URL) | ||||
| 	} | ||||
| } | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (client *RTSP) Request(method string, headers map[string]string) (*Response, error) { | ||||
| 	l, err := url.Parse(client.URL) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("Url parse error:%v", err) | ||||
| 	} | ||||
| 	l.User = nil | ||||
| 	return client.RequestWithPath(method, l.String(), headers, true) | ||||
| } | ||||
|  | ||||
| func (client *RTSP) RequestNoResp(method string, headers map[string]string) (err error) { | ||||
| 	l, err := url.Parse(client.URL) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("Url parse error:%v", err) | ||||
| 	} | ||||
| 	l.User = nil | ||||
| 	if _, err = client.RequestWithPath(method, l.String(), headers, false); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (client *RTSP) RequestWithPath(method string, path string, headers map[string]string, needResp bool) (resp *Response, err error) { | ||||
| 	headers["User-Agent"] = client.Agent | ||||
| 	if len(headers["Authorization"]) == 0 { | ||||
| 		if len(client.authLine) != 0 { | ||||
| 			Authorization, _ := DigestAuth(client.authLine, method, client.URL) | ||||
| 			if len(Authorization) > 0 { | ||||
| 				headers["Authorization"] = Authorization | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	if len(client.Session) > 0 { | ||||
| 		headers["Session"] = client.Session | ||||
| 	} | ||||
| 	client.Seq++ | ||||
| 	cseq := client.Seq | ||||
| 	builder := bytes.Buffer{} | ||||
| 	builder.WriteString(fmt.Sprintf("%s %s RTSP/1.0\r\n", method, path)) | ||||
| 	builder.WriteString(fmt.Sprintf("CSeq: %d\r\n", cseq)) | ||||
| 	for k, v := range headers { | ||||
| 		builder.WriteString(fmt.Sprintf("%s: %s\r\n", k, v)) | ||||
| 	} | ||||
| 	builder.WriteString(fmt.Sprintf("\r\n")) | ||||
| 	s := builder.String() | ||||
| 	Printf("[OUT]>>>\n%s", s) | ||||
| 	_, err = client.connRW.WriteString(s) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	client.connRW.Flush() | ||||
|  | ||||
| 	if !needResp { | ||||
| 		return nil, nil | ||||
| 	} | ||||
| 	lineCount := 0 | ||||
| 	statusCode := 200 | ||||
| 	status := "" | ||||
| 	sid := "" | ||||
| 	contentLen := 0 | ||||
| 	respHeader := make(map[string]interface{}) | ||||
| 	var line []byte | ||||
| 	builder.Reset() | ||||
| 	for { | ||||
| 		isPrefix := false | ||||
| 		if line, isPrefix, err = client.connRW.ReadLine(); err != nil { | ||||
| 			return | ||||
| 		} | ||||
| 		s := string(line) | ||||
| 		builder.Write(line) | ||||
| 		if !isPrefix { | ||||
| 			builder.WriteString("\r\n") | ||||
| 		} | ||||
| 		if len(line) == 0 { | ||||
| 			body := "" | ||||
| 			if contentLen > 0 { | ||||
| 				content := make([]byte, contentLen) | ||||
| 				_, err = io.ReadFull(client.connRW, content) | ||||
| 				if err != nil { | ||||
| 					err = fmt.Errorf("Read content err.ContentLength:%d", contentLen) | ||||
| 					return | ||||
| 				} | ||||
| 				body = string(content) | ||||
| 				builder.Write(content) | ||||
| 			} | ||||
| 			resp = NewResponse(statusCode, status, strconv.Itoa(cseq), sid, body) | ||||
| 			resp.Header = respHeader | ||||
| 			Printf("<<<[IN]\n%s", builder.String()) | ||||
|  | ||||
| 			if !(statusCode >= 200 && statusCode <= 300) { | ||||
| 				err = fmt.Errorf("Response StatusCode is :%d", statusCode) | ||||
| 				return | ||||
| 			} | ||||
| 			return | ||||
| 		} | ||||
| 		if lineCount == 0 { | ||||
| 			splits := strings.Split(s, " ") | ||||
| 			if len(splits) < 3 { | ||||
| 				err = fmt.Errorf("StatusCode Line error:%s", s) | ||||
| 				return | ||||
| 			} | ||||
| 			statusCode, err = strconv.Atoi(splits[1]) | ||||
| 			if err != nil { | ||||
| 				return | ||||
| 			} | ||||
| 			status = splits[2] | ||||
| 		} | ||||
| 		lineCount++ | ||||
| 		splits := strings.Split(s, ":") | ||||
| 		if len(splits) == 2 { | ||||
| 			if val, ok := respHeader[splits[0]]; ok { | ||||
| 				if slice, ok2 := val.([]string); ok2 { | ||||
| 					slice = append(slice, strings.TrimSpace(splits[1])) | ||||
| 					respHeader[splits[0]] = slice | ||||
| 				} else { | ||||
| 					str, _ := val.(string) | ||||
| 					slice := []string{str, strings.TrimSpace(splits[1])} | ||||
| 					respHeader[splits[0]] = slice | ||||
| 				} | ||||
| 			} else { | ||||
| 				respHeader[splits[0]] = strings.TrimSpace(splits[1]) | ||||
| 			} | ||||
| 		} | ||||
| 		if strings.Index(s, "Session:") == 0 { | ||||
| 			splits := strings.Split(s, ":") | ||||
| 			sid = strings.TrimSpace(splits[1]) | ||||
| 		} | ||||
| 		//if strings.Index(s, "CSeq:") == 0 { | ||||
| 		//	splits := strings.Split(s, ":") | ||||
| 		//	cseq, err = strconv.Atoi(strings.TrimSpace(splits[1])) | ||||
| 		//	if err != nil { | ||||
| 		//		err = fmt.Errorf("Atoi CSeq err. line:%s", s) | ||||
| 		//		return | ||||
| 		//	} | ||||
| 		//} | ||||
| 		if strings.Index(s, "Content-Length:") == 0 { | ||||
| 			splits := strings.Split(s, ":") | ||||
| 			contentLen, err = strconv.Atoi(strings.TrimSpace(splits[1])) | ||||
| 			if err != nil { | ||||
| 				return | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|   | ||||
							
								
								
									
										17
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								go.mod
									
									
									
									
									
								
							| @@ -1,14 +1,11 @@ | ||||
| module github.com/Monibuca/plugin-rtsp | ||||
| module github.com/Monibuca/plugin-rtsp/v3 | ||||
|  | ||||
| go 1.13 | ||||
| go 1.16 | ||||
|  | ||||
| require ( | ||||
| 	github.com/Monibuca/engine/v2 v2.0.0 | ||||
| 	github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee // indirect | ||||
| 	github.com/gobwas/pool v0.2.0 // indirect | ||||
| 	github.com/gobwas/ws v1.0.3 // indirect | ||||
| 	github.com/jinzhu/gorm v1.9.12 // indirect | ||||
| 	github.com/pixelbender/go-sdp v1.0.0 | ||||
| 	github.com/reactivex/rxgo v1.0.0 // indirect | ||||
| 	github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf | ||||
| 	github.com/Monibuca/engine/v3 v3.4.1 | ||||
| 	github.com/Monibuca/utils/v3 v3.0.5 | ||||
| 	github.com/aler9/gortsplib v0.0.0-20211212220644-6f374e396529 | ||||
| 	github.com/pion/rtp v1.7.4 | ||||
| 	github.com/pion/sdp/v3 v3.0.4 | ||||
| ) | ||||
|   | ||||
							
								
								
									
										141
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										141
									
								
								go.sum
									
									
									
									
									
								
							| @@ -1,88 +1,101 @@ | ||||
| github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= | ||||
| github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||||
| github.com/EasyDarwin/EasyDarwin v8.1.0+incompatible h1:Rr8dRbZtcJhiJvGx5Vs7IENM6RUUwGkZiIj5+WrNhm8= | ||||
| github.com/EasyDarwin/EasyDarwin v8.1.0+incompatible/go.mod h1:xnmC+Q2+wugEDpQGxivSFNYPOhmNlIQHBfl0hMeriSU= | ||||
| github.com/Monibuca/engine v1.2.1 h1:TJmC6eZA1lR1MScWgempZLiEZD4T6aY/nn/rlQ9UdK8= | ||||
| github.com/Monibuca/engine v1.2.1/go.mod h1:WbDkXENLjcPjyjCR1Mix1GA+uAlwORkv/+8aMVrDX2g= | ||||
| github.com/Monibuca/engine v1.2.2 h1:hNjsrZpOmui8lYhgCJ5ltJU8g/k0Rrdysx2tHNGGnbI= | ||||
| github.com/Monibuca/engine/v2 v2.0.0 h1:8FjaScrtN8QdbcxO9zZYABMC0Re3I1O1T4p94zAXYb0= | ||||
| github.com/Monibuca/engine/v2 v2.0.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc= | ||||
| github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk= | ||||
| github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= | ||||
| github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= | ||||
| github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= | ||||
| github.com/Monibuca/engine/v3 v3.4.1 h1:Ap2VbwTkMUkv80NPeUX2sNdV5Vz5nPVoU/6RU51PSAc= | ||||
| github.com/Monibuca/engine/v3 v3.4.1/go.mod h1:rgAUey5ziRhlh6WugWyA5fYKyGOvcwhtTMDk4sukE7E= | ||||
| github.com/Monibuca/utils/v3 v3.0.5 h1:w14x0HkWTbF4MmHbINLlOwe4VJNoSOeaQChMk5E/4es= | ||||
| github.com/Monibuca/utils/v3 v3.0.5/go.mod h1:RpNS95gapWs6gimwh8Xn2x72FN5tO7Powabj7dTFyvE= | ||||
| github.com/aler9/gortsplib v0.0.0-20211212220644-6f374e396529 h1:j2tfs+eUubyZnuwmYWzK+IS681IixfUyD8bivz4sqAw= | ||||
| github.com/aler9/gortsplib v0.0.0-20211212220644-6f374e396529/go.mod h1:fyQrQyHo8QvdR/h357tkv1g36VesZlzEPsdAu2VrHHc= | ||||
| github.com/asticode/go-astikit v0.20.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0= | ||||
| github.com/asticode/go-astits v1.10.0/go.mod h1:DkOWmBNQpnr9mv24KfZjq4JawCFX1FCqjLVGvO0DygQ= | ||||
| github.com/cnotch/apirouter v0.0.0-20200731232942-89e243a791f3/go.mod h1:5deJPLON/x/s2dLOQfuKS0lenhOIT4xX0pvtN/OEIuY= | ||||
| github.com/cnotch/ipchub v1.1.0 h1:hH0lh2mU3AZXPiqMwA0pdtqrwo7PFIMRGush9OobMUs= | ||||
| github.com/cnotch/ipchub v1.1.0/go.mod h1:2PbeBs2q2VxxTVCn1eYCDwpAWuVXbq1+N0FU7GimOH4= | ||||
| github.com/cnotch/loader v0.0.0-20200405015128-d9d964d09439/go.mod h1:oWpDagHB6p+Kqqq7RoRZKyC4XAXft50hR8pbTxdbYYs= | ||||
| github.com/cnotch/queue v0.0.0-20200326024423-6e88bdbf2ad4/go.mod h1:zOssjAlNusOxvtaqT+EMA+Iyi8rrtKr4/XfzN1Fgoeg= | ||||
| github.com/cnotch/queue v0.0.0-20201224060551-4191569ce8f6/go.mod h1:zOssjAlNusOxvtaqT+EMA+Iyi8rrtKr4/XfzN1Fgoeg= | ||||
| github.com/cnotch/scheduler v0.0.0-20200522024700-1d2da93eefc5/go.mod h1:F4GE3SZkJZ8an1Y0ZCqvSM3jeozNuKzoC67erG1PhIo= | ||||
| github.com/cnotch/xlog v0.0.0-20201208005456-cfda439cd3a0/go.mod h1:RW9oHsR79ffl3sR3yMGgxYupMn2btzdtJUwoxFPUE5E= | ||||
| github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM= | ||||
| github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= | ||||
| github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y= | ||||
| github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= | ||||
| github.com/falconray0704/gortmp v0.0.0-20170613085150-e3f9bb02c7c8 h1:Bkx+0neYCcHW7BUeVCbR2GOn47NesdImh8nHHOKccD4= | ||||
| github.com/falconray0704/gortmp v0.0.0-20170613085150-e3f9bb02c7c8/go.mod h1:/JBZajtCDe9Z4j84v5QWo4PLn1K6jcBHh6qXN/bm/vw= | ||||
| github.com/emitter-io/address v1.0.0/go.mod h1:GfZb5+S/o8694B1GMGK2imUYQyn2skszMvGNA5D84Ug= | ||||
| github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= | ||||
| github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478 h1:Db9StoJ6RZN3YttC0Pm0I4Y5izITRYch3RMbT59BYN0= | ||||
| github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478/go.mod h1:0j1+svBH8ABEIPdUP0AIg4qedsybnXGJBakCEw8cfoo= | ||||
| github.com/funny/utest v0.0.0-20161029064919-43870a374500 h1:Z0r1CZnoIWFB/Uiwh1BU5FYmuFe6L5NPi6XWQEmsTRg= | ||||
| github.com/funny/utest v0.0.0-20161029064919-43870a374500/go.mod h1:mUn39tBov9jKnTWV1RlOYoNzxdBFHiSzXWdY1FoNGGg= | ||||
| github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI= | ||||
| github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= | ||||
| github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= | ||||
| github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= | ||||
| github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= | ||||
| github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= | ||||
| github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= | ||||
| github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= | ||||
| github.com/gobwas/ws v1.0.3 h1:ZOigqf7iBxkA4jdQ3am7ATzdlOFp9YzA6NmuvEEZc9g= | ||||
| github.com/gobwas/ws v1.0.3/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= | ||||
| github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= | ||||
| github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= | ||||
| github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||||
| github.com/jinzhu/gorm v1.9.12 h1:Drgk1clyWT9t9ERbzHza6Mj/8FY/CqMyVzOiHviMo6Q= | ||||
| github.com/jinzhu/gorm v1.9.12/go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs= | ||||
| github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= | ||||
| github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= | ||||
| github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M= | ||||
| github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= | ||||
| github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4= | ||||
| github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | ||||
| github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 h1:bqDmpDG49ZRnB5PcgP0RXtQvnMSgIF14M7CBd2shtXs= | ||||
| github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= | ||||
| github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= | ||||
| github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= | ||||
| github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | ||||
| github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= | ||||
| github.com/icza/bitio v1.0.0 h1:squ/m1SHyFeCA6+6Gyol1AxV9nmPPlJFT8c2vKdj3U8= | ||||
| github.com/icza/bitio v1.0.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A= | ||||
| github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lToqnXgA8Mz1DP11X4zSJ159C3k= | ||||
| github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA= | ||||
| github.com/kelindar/process v0.0.0-20170730150328-69a29e249ec3/go.mod h1:+lTCLnZFXOkqwD8sLPl6u4erAc0cP8wFegQHfipz7KE= | ||||
| github.com/kelindar/rate v1.0.0/go.mod h1:AjT4G+hTItNwt30lucEGZIz8y7Uk5zPho6vurIZ+1Es= | ||||
| github.com/kelindar/tcp v1.0.0/go.mod h1:JB5hj1cshLU60XrLij2BBxW3JQ4hOye8vqbyvuKb52k= | ||||
| github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= | ||||
| github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= | ||||
| github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= | ||||
| github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= | ||||
| github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= | ||||
| github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= | ||||
| github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw= | ||||
| github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= | ||||
| github.com/pixelbender/go-sdp v1.0.0 h1:hLP2ALBN4sLpgp2r3EDcFUSN3AyOkg1jonuWEJniotY= | ||||
| github.com/pixelbender/go-sdp v1.0.0/go.mod h1:6IBlz9+BrUHoFTea7gcp4S54khtOhjCW/nVDLhmZBAs= | ||||
| github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | ||||
| github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= | ||||
| github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= | ||||
| github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= | ||||
| github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= | ||||
| github.com/pion/rtcp v1.2.4 h1:NT3H5LkUGgaEapvp0HGik+a+CpflRF7KTD7H+o7OWIM= | ||||
| github.com/pion/rtcp v1.2.4/go.mod h1:52rMNPWFsjr39z9B9MhnkqhPLoeHTv1aN63o/42bWE0= | ||||
| github.com/pion/rtp v1.6.1/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko= | ||||
| github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko= | ||||
| github.com/pion/rtp v1.7.4 h1:4dMbjb1SuynU5OpA3kz1zHK+u+eOCQjW3MAeVHf1ODA= | ||||
| github.com/pion/rtp v1.7.4/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko= | ||||
| github.com/pion/sdp/v3 v3.0.2/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk= | ||||
| github.com/pion/sdp/v3 v3.0.4 h1:2Kf+dgrzJflNCSw3TV5v2VLeI0s/qkzy2r5jlR0wzf8= | ||||
| github.com/pion/sdp/v3 v3.0.4/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk= | ||||
| github.com/pixelbender/go-sdp v1.1.0/go.mod h1:6IBlz9+BrUHoFTea7gcp4S54khtOhjCW/nVDLhmZBAs= | ||||
| github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||||
| github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||||
| github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE= | ||||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||
| github.com/reactivex/rxgo v1.0.0 h1:qpT8/kVwAJDSeGsqx4oUXxgk3UCtAq/EreBGWYRxEcA= | ||||
| github.com/reactivex/rxgo v1.0.0/go.mod h1:/S1ygE20oE1BvZGIwd3fXx/m6s6pOX5G6zmXg9ninlQ= | ||||
| github.com/shirou/gopsutil v2.20.1+incompatible h1:oIq9Cq4i84Hk8uQAUOG3eNdI/29hBawGrD5YRl6JRDY= | ||||
| github.com/shirou/gopsutil v2.20.1+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= | ||||
| github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= | ||||
| github.com/q191201771/naza v0.19.1 h1:4KLcxT2CHztO+7miPRtBG3FFgadSQYQw1gPPPKN7rnY= | ||||
| github.com/q191201771/naza v0.19.1/go.mod h1:5LeGupZZFtYP1g/S203n9vXoUNVdlRnPIfM6rExjqt0= | ||||
| github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518/go.mod h1:CKI4AZ4XmGV240rTHfO0hfE83S6/a3/Q1siZJ/vXf7A= | ||||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||||
| github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= | ||||
| github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||||
| github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= | ||||
| github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf h1:Z2X3Os7oRzpdJ75iPqWZc0HeJWFYNCvKsfpQwFpRNTA= | ||||
| github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0= | ||||
| github.com/zhangpeihao/goamf v0.0.0-20140409082417-3ff2c19514a8/go.mod h1:RZd/IqzNpFANwOB9rVmsnAYpo/6KesK4PqrN1a5cRgg= | ||||
| github.com/zhangpeihao/log v0.0.0-20170117094621-62e921e41859/go.mod h1:OAvmouyIV28taMw4SC4+hSnouObQqQkTQNOhU3Zowl0= | ||||
| github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= | ||||
| github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||||
| golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||||
| golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd h1:GGJVjV8waZKRHrgwvtH66z9ZGVurTD1MT0n1Bb+q4aM= | ||||
| golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||||
| golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||||
| golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= | ||||
| golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||||
| golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||||
| golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A= | ||||
| golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= | ||||
| golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs= | ||||
| golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= | ||||
| golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= | ||||
| golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= | ||||
| golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||
| google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= | ||||
| google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||||
| golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||||
| gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= | ||||
| gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= | ||||
| gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= | ||||
| gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||||
| gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||
|   | ||||
							
								
								
									
										344
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										344
									
								
								main.go
									
									
									
									
									
								
							| @@ -1,306 +1,112 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"bufio" | ||||
| 	"bytes" | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"net" | ||||
| 	"net/http" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
| 	"time" | ||||
|  | ||||
| 	. "github.com/Monibuca/engine/v2" | ||||
| 	. "github.com/Monibuca/engine/v2/avformat" | ||||
| 	"github.com/Monibuca/engine/v2/util" | ||||
| 	"github.com/teris-io/shortid" | ||||
| 	. "github.com/Monibuca/engine/v3" | ||||
| 	. "github.com/Monibuca/utils/v3" | ||||
| 	"github.com/aler9/gortsplib" | ||||
| ) | ||||
|  | ||||
| var collection = sync.Map{} | ||||
| var config = struct { | ||||
| 	ListenAddr   string | ||||
| 	AutoPull   bool | ||||
| 	RemoteAddr string | ||||
| 	UDPAddr      string | ||||
| 	RTCPAddr     string | ||||
| 	Timeout      int | ||||
| }{":554", false, "rtsp://localhost/${streamPath}", 0} | ||||
| 	Reconnect    bool | ||||
| 	AutoPullList map[string]string | ||||
| 	AutoPushList map[string]string | ||||
| }{":554", ":8000", ":8001", 0, false, nil, nil} | ||||
|  | ||||
| var pconfig = PluginConfig{ | ||||
| 	Name:   "RTSP", | ||||
| 	Config: &config, | ||||
| } | ||||
|  | ||||
| func init() { | ||||
| 	InstallPlugin(&PluginConfig{ | ||||
| 		Name:   "RTSP", | ||||
| 		Type:   PLUGIN_PUBLISHER | PLUGIN_HOOK, | ||||
| 		Config: &config, | ||||
| 		Run:    runPlugin, | ||||
| 		HotConfig: map[string]func(interface{}){ | ||||
| 			"AutoPull": func(value interface{}) { | ||||
| 				config.AutoPull = value.(bool) | ||||
| 			}, | ||||
| 		}, | ||||
| 	}) | ||||
| 	pconfig.Install(runPlugin) | ||||
| } | ||||
|  | ||||
| func getRtspList() (info []*Stream) { | ||||
| 	for _, s := range Streams.ToList() { | ||||
| 		switch s.ExtraProp.(type) { | ||||
| 		case *RTSPublisher: | ||||
| 			info = append(info, s) | ||||
| 		case *RTSPClient: | ||||
| 			info = append(info, s) | ||||
| 		} | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
| func runPlugin() { | ||||
| 	OnSubscribeHooks.AddHook(func(s *Subscriber) { | ||||
| 		if config.AutoPull && s.Publisher == nil { | ||||
| 			new(RTSP).PullStream(s.StreamPath, strings.Replace(config.RemoteAddr, "${streamPath}", s.StreamPath, -1)) | ||||
| 	http.HandleFunc("/api/rtsp/list", func(w http.ResponseWriter, r *http.Request) { | ||||
| 		CORS(w, r) | ||||
| 		if r.URL.Query().Get("json") != "" { | ||||
| 			if jsonData, err := json.Marshal(getRtspList()); err == nil { | ||||
| 				w.Write(jsonData) | ||||
| 			} else { | ||||
| 				w.WriteHeader(500) | ||||
| 			} | ||||
| 	}) | ||||
| 	http.HandleFunc("/rtsp/list", func(w http.ResponseWriter, r *http.Request) { | ||||
| 		sse := util.NewSSE(w, r.Context()) | ||||
| 			return | ||||
| 		} | ||||
| 		sse := NewSSE(w, r.Context()) | ||||
| 		var err error | ||||
| 		for tick := time.NewTicker(time.Second); err == nil; <-tick.C { | ||||
| 			var info []*RTSPInfo | ||||
| 			collection.Range(func(key, value interface{}) bool { | ||||
| 				rtsp := value.(*RTSP) | ||||
| 				pinfo := &rtsp.RTSPInfo | ||||
| 				info = append(info, pinfo) | ||||
| 				return true | ||||
| 			}) | ||||
| 			err = sse.WriteJSON(info) | ||||
| 			err = sse.WriteJSON(getRtspList()) | ||||
| 		} | ||||
| 	}) | ||||
| 	http.HandleFunc("/rtsp/pull", func(w http.ResponseWriter, r *http.Request) { | ||||
| 	http.HandleFunc("/api/rtsp/pull", func(w http.ResponseWriter, r *http.Request) { | ||||
| 		CORS(w, r) | ||||
| 		targetURL := r.URL.Query().Get("target") | ||||
| 		streamPath := r.URL.Query().Get("streamPath") | ||||
| 		if err := new(RTSP).PullStream(streamPath, targetURL); err == nil { | ||||
| 		save := r.URL.Query().Get("save") | ||||
| 		if err := (&RTSPClient{Transport: gortsplib.TransportTCP}).PullStream(streamPath, targetURL); err == nil { | ||||
| 			if save == "1" { | ||||
| 				if config.AutoPullList == nil { | ||||
| 					config.AutoPullList = make(map[string]string) | ||||
| 				} | ||||
| 				config.AutoPullList[streamPath] = targetURL | ||||
| 				if err := pconfig.Save(); err != nil { | ||||
| 					Println(err) | ||||
| 				} | ||||
| 			} | ||||
| 			w.Write([]byte(`{"code":0}`)) | ||||
| 		} else { | ||||
| 			w.Write([]byte(fmt.Sprintf(`{"code":1,"msg":"%s"}`, err.Error()))) | ||||
| 		} | ||||
| 	}) | ||||
| 	for streamPath, url := range config.AutoPullList { | ||||
| 		if err := (&RTSPClient{Transport: gortsplib.TransportTCP}).PullStream(streamPath, url); err != nil { | ||||
| 			Println(err) | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	go AddHook(HOOK_PUBLISH, func(s *Stream) { | ||||
| 		for streamPath, url := range config.AutoPushList { | ||||
| 			if s.StreamPath == streamPath { | ||||
| 				(&RTSPClient{}).PushStream(streamPath, url) | ||||
| 			} | ||||
| 		} | ||||
| 	}) | ||||
| 	if config.ListenAddr != "" { | ||||
| 		log.Fatal(ListenRtsp(config.ListenAddr)) | ||||
| 		go log.Fatal(ListenRtsp(config.ListenAddr)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func ListenRtsp(addr string) error { | ||||
| 	defer log.Println("rtsp server start!") | ||||
| 	listener, err := net.Listen("tcp", addr) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	var tempDelay time.Duration | ||||
| 	networkBuffer := 204800 | ||||
| 	timeoutMillis := config.Timeout | ||||
| 	for { | ||||
| 		conn, err := listener.Accept() | ||||
| 		conn.(*net.TCPConn).SetNoDelay(false) | ||||
| 		if err != nil { | ||||
| 			if ne, ok := err.(net.Error); ok && ne.Temporary() { | ||||
| 				if tempDelay == 0 { | ||||
| 					tempDelay = 5 * time.Millisecond | ||||
| 				} else { | ||||
| 					tempDelay *= 2 | ||||
| 				} | ||||
| 				if max := 1 * time.Second; tempDelay > max { | ||||
| 					tempDelay = max | ||||
| 				} | ||||
| 				fmt.Printf("rtsp: Accept error: %v; retrying in %v", err, tempDelay) | ||||
| 				time.Sleep(tempDelay) | ||||
| 				continue | ||||
| 			} | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		tempDelay = 0 | ||||
| 		timeoutTCPConn := &RichConn{conn, time.Duration(timeoutMillis) * time.Millisecond} | ||||
| 		go (&RTSP{ | ||||
| 			ID:                 shortid.MustGenerate(), | ||||
| 			Conn:               timeoutTCPConn, | ||||
| 			connRW:             bufio.NewReadWriter(bufio.NewReaderSize(timeoutTCPConn, networkBuffer), bufio.NewWriterSize(timeoutTCPConn, networkBuffer)), | ||||
| 			Timeout:            config.Timeout, | ||||
| 			vRTPChannel:        -1, | ||||
| 			vRTPControlChannel: -1, | ||||
| 			aRTPChannel:        -1, | ||||
| 			aRTPControlChannel: -1, | ||||
| 		}).AcceptPush() | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| type RTSP struct { | ||||
| 	Publisher | ||||
| 	RTSPInfo | ||||
| 	RTSPClientInfo | ||||
| 	ID        string | ||||
| 	Conn      *RichConn | ||||
| 	connRW    *bufio.ReadWriter | ||||
| 	connWLock sync.RWMutex | ||||
| 	Type      SessionType | ||||
| 	TransType TransType | ||||
|  | ||||
| 	SDPMap   map[string]*SDPInfo | ||||
| 	nonce    string | ||||
| 	closeOld bool | ||||
| 	AControl string | ||||
| 	VControl string | ||||
| 	ACodec   string | ||||
| 	VCodec   string | ||||
| 	avcsent  bool | ||||
| 	aacsent  bool | ||||
| 	Timeout  int | ||||
| 	// stats info | ||||
| 	fuBuffer []byte | ||||
| 	//tcp channels | ||||
| 	aRTPChannel         int | ||||
| 	aRTPControlChannel  int | ||||
| 	vRTPChannel         int | ||||
| 	vRTPControlChannel  int | ||||
| 	UDPServer           *UDPServer | ||||
| 	UDPClient           *UDPClient | ||||
| 	SPS                 []byte | ||||
| 	PPS                 []byte | ||||
| 	AudioSpecificConfig []byte | ||||
| 	Auth                func(string) string | ||||
| } | ||||
| type RTSPClientInfo struct { | ||||
| 	Agent    string | ||||
| 	Session  string | ||||
| 	authLine string | ||||
| 	Seq      int | ||||
| } | ||||
| type RTSPInfo struct { | ||||
| 	URL       string | ||||
| 	SyncCount int64 | ||||
| 	SDPRaw    string | ||||
| 	InBytes   int | ||||
| 	OutBytes  int | ||||
|  | ||||
| 	StreamInfo *StreamInfo | ||||
| } | ||||
|  | ||||
| type RichConn struct { | ||||
| 	net.Conn | ||||
| 	timeout time.Duration | ||||
| } | ||||
|  | ||||
| func (conn *RichConn) Read(b []byte) (n int, err error) { | ||||
| 	if conn.timeout > 0 { | ||||
| 		conn.Conn.SetReadDeadline(time.Now().Add(conn.timeout)) | ||||
| 	} else { | ||||
| 		var t time.Time | ||||
| 		conn.Conn.SetReadDeadline(t) | ||||
| 	} | ||||
| 	return conn.Conn.Read(b) | ||||
| } | ||||
|  | ||||
| func (conn *RichConn) Write(b []byte) (n int, err error) { | ||||
| 	if conn.timeout > 0 { | ||||
| 		conn.Conn.SetWriteDeadline(time.Now().Add(conn.timeout)) | ||||
| 	} else { | ||||
| 		var t time.Time | ||||
| 		conn.Conn.SetWriteDeadline(t) | ||||
| 	} | ||||
| 	return conn.Conn.Write(b) | ||||
| } | ||||
| func (rtsp *RTSP) handleNALU(nalType byte, payload []byte, ts int64) { | ||||
| 	rtsp.SyncCount++ | ||||
| 	vl := len(payload) | ||||
| 	switch nalType { | ||||
| 	// case NALU_SPS: | ||||
| 	// 	r := bytes.NewBuffer([]byte{}) | ||||
| 	// 	r.Write(RTMP_AVC_HEAD) | ||||
| 	// 	util.BigEndian.PutUint16(spsHead[1:], uint16(vl)) | ||||
| 	// 	r.Write(spsHead) | ||||
| 	// 	r.Write(payload) | ||||
| 	// case NALU_PPS: | ||||
| 	// 	r := bytes.NewBuffer([]byte{}) | ||||
| 	// 	util.BigEndian.PutUint16(ppsHead[1:], uint16(vl)) | ||||
| 	// 	r.Write(ppsHead) | ||||
| 	// 	r.Write(payload) | ||||
| 	// 	rtsp.PushVideo(0, r.Bytes()) | ||||
| 	// avcsent = true | ||||
| 	case NALU_IDR_Picture: | ||||
| 		if !rtsp.avcsent { | ||||
| 			r := bytes.NewBuffer([]byte{}) | ||||
| 			r.Write(RTMP_AVC_HEAD) | ||||
| 			spsHead := []byte{0xE1, 0, 0} | ||||
| 			util.BigEndian.PutUint16(spsHead[1:], uint16(len(rtsp.SPS))) | ||||
| 			r.Write(spsHead) | ||||
| 			r.Write(rtsp.SPS) | ||||
| 			ppsHead := []byte{0x01, 0, 0} | ||||
| 			util.BigEndian.PutUint16(ppsHead[1:], uint16(len(rtsp.PPS))) | ||||
| 			r.Write(ppsHead) | ||||
| 			r.Write(rtsp.PPS) | ||||
| 			rtsp.PushVideo(0, r.Bytes()) | ||||
| 			rtsp.avcsent = true | ||||
| 		} | ||||
| 		r := bytes.NewBuffer([]byte{}) | ||||
| 		iframeHead := []byte{0x17, 0x01, 0, 0, 0} | ||||
| 		util.BigEndian.PutUint24(iframeHead[2:], 0) | ||||
| 		r.Write(iframeHead) | ||||
| 		nalLength := []byte{0, 0, 0, 0} | ||||
| 		util.BigEndian.PutUint32(nalLength, uint32(vl)) | ||||
| 		r.Write(nalLength) | ||||
| 		r.Write(payload) | ||||
| 		rtsp.PushVideo(uint32(ts), r.Bytes()) | ||||
| 	case NALU_Non_IDR_Picture: | ||||
| 		r := bytes.NewBuffer([]byte{}) | ||||
| 		pframeHead := []byte{0x27, 0x01, 0, 0, 0} | ||||
| 		util.BigEndian.PutUint24(pframeHead[2:], 0) | ||||
| 		r.Write(pframeHead) | ||||
| 		nalLength := []byte{0, 0, 0, 0} | ||||
| 		util.BigEndian.PutUint32(nalLength, uint32(vl)) | ||||
| 		r.Write(nalLength) | ||||
| 		r.Write(payload) | ||||
| 		rtsp.PushVideo(uint32(ts), r.Bytes()) | ||||
| 	} | ||||
| } | ||||
| func (rtsp *RTSP) handleRTP(pack *RTPPack) { | ||||
| 	data := pack.Buffer | ||||
| 	switch pack.Type { | ||||
| 	case RTP_TYPE_AUDIO: | ||||
| 		if !rtsp.aacsent { | ||||
| 			rtsp.PushAudio(0, append([]byte{0xAF, 0x00}, rtsp.AudioSpecificConfig...)) | ||||
| 			rtsp.aacsent = true | ||||
| 		} | ||||
| 		cc := data[0] & 0xF | ||||
| 		rtphdr := 12 + cc*4 | ||||
| 		payload := data[rtphdr:] | ||||
| 		auHeaderLen := (int16(payload[0]) << 8) + int16(payload[1]) | ||||
| 		auHeaderLen = auHeaderLen >> 3 | ||||
| 		auHeaderCount := int(auHeaderLen / 2) | ||||
| 		var auLenArray []int | ||||
| 		for iIndex := 0; iIndex < int(auHeaderCount); iIndex++ { | ||||
| 			auHeaderInfo := (int16(payload[2+2*iIndex]) << 8) + int16(payload[2+2*iIndex+1]) | ||||
| 			auLen := auHeaderInfo >> 3 | ||||
| 			auLenArray = append(auLenArray, int(auLen)) | ||||
| 		} | ||||
| 		startOffset := 2 + 2*auHeaderCount | ||||
| 		for _, auLen := range auLenArray { | ||||
| 			endOffset := startOffset + auLen | ||||
| 			addHead := []byte{0xAF, 0x01} | ||||
| 			rtsp.PushAudio(0, append(addHead, payload[startOffset:endOffset]...)) | ||||
| 			startOffset = startOffset + auLen | ||||
| 		} | ||||
| 	case RTP_TYPE_VIDEO: | ||||
| 		cc := data[0] & 0xF | ||||
| 		//rtp header | ||||
| 		rtphdr := 12 + cc*4 | ||||
|  | ||||
| 		//packet time | ||||
| 		ts := (int64(data[4]) << 24) + (int64(data[5]) << 16) + (int64(data[6]) << 8) + (int64(data[7])) | ||||
|  | ||||
| 		//packet number | ||||
| 		//packno := (int64(data[6]) << 8) + int64(data[7]) | ||||
| 		data = data[rtphdr:] | ||||
| 		nalType := data[0] & 0x1F | ||||
|  | ||||
| 		if nalType >= 1 && nalType <= 23 { | ||||
| 			rtsp.handleNALU(nalType, data, ts) | ||||
| 		} else if nalType == 28 { | ||||
| 			isStart := data[1]&0x80 != 0 | ||||
| 			isEnd := data[1]&0x40 != 0 | ||||
| 			nalType := data[1] & 0x1F | ||||
| 			//nri := (data[1]&0x60)>>5 | ||||
| 			nal := data[0]&0xE0 | data[1]&0x1F | ||||
| 			if isStart { | ||||
| 				rtsp.fuBuffer = []byte{0} | ||||
| 			} | ||||
| 			rtsp.fuBuffer = append(rtsp.fuBuffer, data[2:]...) | ||||
| 			if isEnd { | ||||
| 				rtsp.fuBuffer[0] = nal | ||||
| 				rtsp.handleNALU(nalType, rtsp.fuBuffer, ts) | ||||
| 			} | ||||
| 		} | ||||
| 	s := &gortsplib.Server{ | ||||
| 		Handler:           &RTSPServer{}, | ||||
| 		RTSPAddress:       addr, | ||||
| 		UDPRTPAddress:     config.UDPAddr, | ||||
| 		UDPRTCPAddress:    config.RTCPAddr, | ||||
| 		MulticastIPRange:  "224.1.0.0/16", | ||||
| 		MulticastRTPPort:  8002, | ||||
| 		MulticastRTCPPort: 8003, | ||||
| 	} | ||||
| 	return s.StartAndWait() | ||||
| } | ||||
|   | ||||
							
								
								
									
										24
									
								
								payloader.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								payloader.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| package rtsp | ||||
|  | ||||
| // AACayloader payloads AAC packets | ||||
| type AACPayloader struct{} | ||||
|  | ||||
| // Payload fragments an AAC packet across one or more byte arrays | ||||
| func (p *AACPayloader) Payload(mtu uint16, payload []byte) [][]byte { | ||||
| 	var out [][]byte | ||||
| 	o := make([]byte, len(payload)+4) | ||||
| 	//AU_HEADER_LENGTH,因为单位是bit, 除以8就是auHeader的字节长度;又因为单个auheader字节长度2字节,所以再除以2就是auheader的个数。 | ||||
| 	o[0] = 0x00 //高位 | ||||
| 	o[1] = 0x10 //低位 | ||||
| 	//AU_HEADER | ||||
| 	o[2] = (byte)((len(payload) & 0x1fe0) >> 5) //高位 | ||||
| 	o[3] = (byte)((len(payload) & 0x1f) << 3)   //低位 | ||||
| 	copy(o[4:], payload) | ||||
| 	return append(out, o) | ||||
| } | ||||
|  | ||||
| type H265Payloader struct{} | ||||
|  | ||||
| func (p *H265Payloader) Payload(mtu uint16, payload []byte) [][]byte { | ||||
| 	return nil | ||||
| } | ||||
							
								
								
									
										121
									
								
								publisher.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								publisher.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,121 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"encoding/base64" | ||||
| 	"encoding/hex" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
|  | ||||
| 	. "github.com/Monibuca/engine/v3" | ||||
| 	. "github.com/Monibuca/utils/v3" | ||||
| 	"github.com/aler9/gortsplib" | ||||
| ) | ||||
|  | ||||
| type RTSPublisher struct { | ||||
| 	*Stream     `json:"-"` | ||||
| 	stream      *gortsplib.ServerStream | ||||
| 	processFunc []func([]byte) | ||||
| } | ||||
|  | ||||
| func (p *RTSPublisher) setTracks(tracks gortsplib.Tracks) { | ||||
| 	if p.processFunc != nil { | ||||
| 		p.processFunc = p.processFunc[:len(tracks)] | ||||
| 		return | ||||
| 	} else { | ||||
| 		p.processFunc = make([]func([]byte), len(tracks)) | ||||
| 	} | ||||
| 	for i, track := range tracks { | ||||
| 		v, ok := track.Media.Attribute("rtpmap") | ||||
| 		if !ok { | ||||
| 			continue | ||||
| 		} | ||||
|  | ||||
| 		fmtp := make(map[string]string) | ||||
| 		if v, ok := track.Media.Attribute("fmtp"); ok { | ||||
| 			if tmp := strings.SplitN(v, " ", 2); len(tmp) == 2 { | ||||
| 				for _, kv := range strings.Split(tmp[1], ";") { | ||||
| 					kv = strings.Trim(kv, " ") | ||||
|  | ||||
| 					if len(kv) == 0 { | ||||
| 						continue | ||||
| 					} | ||||
| 					tmp := strings.SplitN(kv, "=", 2) | ||||
| 					if len(tmp) == 2 { | ||||
| 						fmtp[strings.TrimSpace(tmp[0])] = tmp[1] | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		v = strings.TrimSpace(v) | ||||
| 		vals := strings.Split(v, " ") | ||||
| 		if len(vals) != 2 { | ||||
| 			continue | ||||
| 		} | ||||
| 		timeScale := 0 | ||||
| 		keyval := strings.Split(vals[1], "/") | ||||
| 		if i, err := strconv.Atoi(keyval[1]); err == nil { | ||||
| 			timeScale = i | ||||
| 		} | ||||
| 		if len(keyval) >= 2 { | ||||
| 			Printf("track %d is %s", i, keyval[0]) | ||||
| 			switch strings.ToLower(keyval[0]) { | ||||
| 			case "h264": | ||||
| 				vt := p.NewRTPVideo(7) | ||||
| 				if conf, err := track.ExtractConfigH264(); err == nil { | ||||
| 					vt.PushNalu(0, 0, conf.SPS, conf.PPS) | ||||
| 				} | ||||
| 				p.processFunc[i] = vt.Push | ||||
| 			case "h265", "hevc": | ||||
| 				vt := p.NewRTPVideo(12) | ||||
| 				if v, ok := fmtp["sprop-vps"]; ok { | ||||
| 					vps, _ := base64.StdEncoding.DecodeString(v) | ||||
| 					vt.PushNalu(0, 0, vps) | ||||
| 				} | ||||
| 				if v, ok := fmtp["sprop-sps"]; ok { | ||||
| 					sps, _ := base64.StdEncoding.DecodeString(v) | ||||
| 					vt.PushNalu(0, 0, sps) | ||||
| 				} | ||||
| 				if v, ok := fmtp["sprop-pps"]; ok { | ||||
| 					pps, _ := base64.StdEncoding.DecodeString(v) | ||||
| 					vt.PushNalu(0, 0, pps) | ||||
| 				} | ||||
| 				p.processFunc[i] = vt.Push | ||||
| 			case "pcma": | ||||
| 				at := p.NewRTPAudio(7) | ||||
| 				at.SoundRate = timeScale | ||||
| 				at.SoundSize = 16 | ||||
| 				if len(keyval) >= 3 { | ||||
| 					x, _ := strconv.Atoi(keyval[2]) | ||||
| 					at.Channels = byte(x) | ||||
| 				} else { | ||||
| 					at.Channels = 1 | ||||
| 				} | ||||
| 				at.ExtraData = []byte{(at.CodecID << 4) | (1 << 1)} | ||||
| 				p.processFunc[i] = at.Push | ||||
| 			case "pcmu": | ||||
| 				at := p.NewRTPAudio(8) | ||||
| 				at.SoundRate = timeScale | ||||
| 				at.SoundSize = 16 | ||||
| 				if len(keyval) >= 3 { | ||||
| 					x, _ := strconv.Atoi(keyval[2]) | ||||
| 					at.Channels = byte(x) | ||||
| 				} else { | ||||
| 					at.Channels = 1 | ||||
| 				} | ||||
| 				at.ExtraData = []byte{(at.CodecID << 4) | (1 << 1)} | ||||
| 				p.processFunc[i] = at.Push | ||||
| 			case "mpeg4-generic": | ||||
| 				at := p.NewRTPAudio(0) | ||||
| 				if config, ok := fmtp["config"]; ok { | ||||
| 					asc, _ := hex.DecodeString(config) | ||||
| 					at.SetASC(asc) | ||||
| 				} else { | ||||
| 					Println("aac no config") | ||||
| 				} | ||||
| 				at.SoundSize = 16 | ||||
| 				p.processFunc[i] = at.Push | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										100
									
								
								request.go
									
									
									
									
									
								
							
							
						
						
									
										100
									
								
								request.go
									
									
									
									
									
								
							| @@ -1,100 +0,0 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"log" | ||||
| 	"regexp" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	RTSP_VERSION = "RTSP/1.0" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	// Client to server for presentation and stream objects; recommended | ||||
| 	DESCRIBE = "DESCRIBE" | ||||
| 	// Bidirectional for client and stream objects; optional | ||||
| 	ANNOUNCE = "ANNOUNCE" | ||||
| 	// Bidirectional for client and stream objects; optional | ||||
| 	GET_PARAMETER = "GET_PARAMETER" | ||||
| 	// Bidirectional for client and stream objects; required for Client to server, optional for server to client | ||||
| 	OPTIONS = "OPTIONS" | ||||
| 	// Client to server for presentation and stream objects; recommended | ||||
| 	PAUSE = "PAUSE" | ||||
| 	// Client to server for presentation and stream objects; required | ||||
| 	PLAY = "PLAY" | ||||
| 	// Client to server for presentation and stream objects; optional | ||||
| 	RECORD = "RECORD" | ||||
| 	// Server to client for presentation and stream objects; optional | ||||
| 	REDIRECT = "REDIRECT" | ||||
| 	// Client to server for stream objects; required | ||||
| 	SETUP = "SETUP" | ||||
| 	// Bidirectional for presentation and stream objects; optional | ||||
| 	SET_PARAMETER = "SET_PARAMETER" | ||||
| 	// Client to server for presentation and stream objects; required | ||||
| 	TEARDOWN = "TEARDOWN" | ||||
| 	DATA     = "DATA" | ||||
| ) | ||||
|  | ||||
| type Request struct { | ||||
| 	Method  string | ||||
| 	URL     string | ||||
| 	Version string | ||||
| 	Header  map[string]string | ||||
| 	Content string | ||||
| 	Body    string | ||||
| } | ||||
|  | ||||
| func NewRequest(content string) *Request { | ||||
| 	lines := strings.Split(strings.TrimSpace(content), "\r\n") | ||||
| 	if len(lines) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	items := regexp.MustCompile("\\s+").Split(strings.TrimSpace(lines[0]), -1) | ||||
| 	if len(items) < 3 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	if !strings.HasPrefix(items[2], "RTSP") { | ||||
| 		log.Printf("invalid rtsp request, line[0] %s", lines[0]) | ||||
| 		return nil | ||||
| 	} | ||||
| 	header := make(map[string]string) | ||||
| 	for i := 1; i < len(lines); i++ { | ||||
| 		line := strings.TrimSpace(lines[i]) | ||||
| 		headerItems := regexp.MustCompile(":\\s+").Split(line, 2) | ||||
| 		if len(headerItems) < 2 { | ||||
| 			continue | ||||
| 		} | ||||
| 		header[headerItems[0]] = headerItems[1] | ||||
| 	} | ||||
| 	return &Request{ | ||||
| 		Method:  items[0], | ||||
| 		URL:     items[1], | ||||
| 		Version: items[2], | ||||
| 		Header:  header, | ||||
| 		Content: content, | ||||
| 		Body:    "", | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (r *Request) String() string { | ||||
| 	str := fmt.Sprintf("%s %s %s\r\n", r.Method, r.URL, r.Version) | ||||
| 	for key, value := range r.Header { | ||||
| 		str += fmt.Sprintf("%s: %s\r\n", key, value) | ||||
| 	} | ||||
| 	str += "\r\n" | ||||
| 	str += r.Body | ||||
| 	return str | ||||
| } | ||||
|  | ||||
| func (r *Request) GetContentLength() int { | ||||
| 	v, err := strconv.ParseInt(r.Header["Content-Length"], 10, 64) | ||||
| 	if err != nil { | ||||
| 		return 0 | ||||
| 	} else { | ||||
| 		return int(v) | ||||
| 	} | ||||
| } | ||||
|  | ||||
							
								
								
									
										51
									
								
								response.go
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								response.go
									
									
									
									
									
								
							| @@ -1,51 +0,0 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| ) | ||||
|  | ||||
| type Response struct { | ||||
| 	Version    string | ||||
| 	StatusCode int | ||||
| 	Status     string | ||||
| 	Header     map[string]interface{} | ||||
| 	Body       string | ||||
| } | ||||
|  | ||||
| func NewResponse(statusCode int, status, cSeq, sid, body string) *Response { | ||||
| 	res := &Response{ | ||||
| 		Version:    RTSP_VERSION, | ||||
| 		StatusCode: statusCode, | ||||
| 		Status:     status, | ||||
| 		Header:     map[string]interface{}{"CSeq": cSeq, "Session": sid}, | ||||
| 		Body:       body, | ||||
| 	} | ||||
| 	len := len(body) | ||||
| 	if len > 0 { | ||||
| 		res.Header["Content-Length"] = strconv.Itoa(len) | ||||
| 	} else { | ||||
| 		delete(res.Header, "Content-Length") | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
|  | ||||
| func (r *Response) String() string { | ||||
| 	str := fmt.Sprintf("%s %d %s\r\n", r.Version, r.StatusCode, r.Status) | ||||
| 	for key, value := range r.Header { | ||||
| 		str += fmt.Sprintf("%s: %s\r\n", key, value) | ||||
| 	} | ||||
| 	str += "\r\n" | ||||
| 	str += r.Body | ||||
| 	return str | ||||
| } | ||||
|  | ||||
| func (r *Response) SetBody(body string) { | ||||
| 	len := len(body) | ||||
| 	r.Body = body | ||||
| 	if len > 0 { | ||||
| 		r.Header["Content-Length"] = strconv.Itoa(len) | ||||
| 	} else { | ||||
| 		delete(r.Header, "Content-Length") | ||||
| 	} | ||||
| } | ||||
| @@ -1,68 +0,0 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"encoding/binary" | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	RTP_FIXED_HEADER_LENGTH = 12 | ||||
| ) | ||||
|  | ||||
| type RTPInfo struct { | ||||
| 	Version        int | ||||
| 	Padding        bool | ||||
| 	Extension      bool | ||||
| 	CSRCCnt        int | ||||
| 	Marker         bool | ||||
| 	PayloadType    int | ||||
| 	SequenceNumber int | ||||
| 	Timestamp      int | ||||
| 	SSRC           int | ||||
| 	Payload        []byte | ||||
| 	PayloadOffset  int | ||||
| } | ||||
|  | ||||
| func ParseRTP(rtpBytes []byte) *RTPInfo { | ||||
| 	if len(rtpBytes) < RTP_FIXED_HEADER_LENGTH { | ||||
| 		return nil | ||||
| 	} | ||||
| 	firstByte := rtpBytes[0] | ||||
| 	secondByte := rtpBytes[1] | ||||
| 	info := &RTPInfo{ | ||||
| 		Version:   int(firstByte >> 6), | ||||
| 		Padding:   (firstByte>>5)&1 == 1, | ||||
| 		Extension: (firstByte>>4)&1 == 1, | ||||
| 		CSRCCnt:   int(firstByte & 0x0f), | ||||
|  | ||||
| 		Marker:         secondByte>>7 == 1, | ||||
| 		PayloadType:    int(secondByte & 0x7f), | ||||
| 		SequenceNumber: int(binary.BigEndian.Uint16(rtpBytes[2:])), | ||||
| 		Timestamp:      int(binary.BigEndian.Uint32(rtpBytes[4:])), | ||||
| 		SSRC:           int(binary.BigEndian.Uint32(rtpBytes[8:])), | ||||
| 	} | ||||
| 	offset := RTP_FIXED_HEADER_LENGTH | ||||
| 	end := len(rtpBytes) | ||||
| 	if end-offset >= 4*info.CSRCCnt { | ||||
| 		offset += 4 * info.CSRCCnt | ||||
| 	} | ||||
| 	if info.Extension && end-offset >= 4 { | ||||
| 		extLen := 4 * int(binary.BigEndian.Uint16(rtpBytes[offset+2:])) | ||||
| 		offset += 4 | ||||
| 		if end-offset >= extLen { | ||||
| 			offset += extLen | ||||
| 		} | ||||
| 	} | ||||
| 	if info.Padding && end-offset > 0 { | ||||
| 		paddingLen := int(rtpBytes[end-1]) | ||||
| 		if end-offset >= paddingLen { | ||||
| 			end -= paddingLen | ||||
| 		} | ||||
| 	} | ||||
| 	info.Payload = rtpBytes[offset:end] | ||||
| 	info.PayloadOffset = offset | ||||
| 	if end-offset < 1 { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	return info | ||||
| } | ||||
							
								
								
									
										105
									
								
								sdp-parser.go
									
									
									
									
									
								
							
							
						
						
									
										105
									
								
								sdp-parser.go
									
									
									
									
									
								
							| @@ -1,105 +0,0 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"encoding/base64" | ||||
| 	"encoding/hex" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| ) | ||||
|  | ||||
| type SDPInfo struct { | ||||
| 	AVType             string | ||||
| 	Codec              string | ||||
| 	TimeScale          int | ||||
| 	Control            string | ||||
| 	Rtpmap             int | ||||
| 	Config             []byte | ||||
| 	SpropParameterSets [][]byte | ||||
| 	PayloadType        int | ||||
| 	SizeLength         int | ||||
| 	IndexLength        int | ||||
| } | ||||
|  | ||||
| func ParseSDP(sdpRaw string) map[string]*SDPInfo { | ||||
| 	sdpMap := make(map[string]*SDPInfo) | ||||
| 	var info *SDPInfo | ||||
| 	for _, line := range strings.Split(sdpRaw, "\n") { | ||||
| 		line = strings.TrimSpace(line) | ||||
| 		typeval := strings.SplitN(line, "=", 2) | ||||
| 		if len(typeval) == 2 { | ||||
| 			fields := strings.SplitN(typeval[1], " ", 2) | ||||
| 			switch typeval[0] { | ||||
| 			case "m": | ||||
| 				if len(fields) > 0 { | ||||
| 					switch fields[0] { | ||||
| 					case "audio", "video": | ||||
| 						sdpMap[fields[0]] = &SDPInfo{AVType: fields[0]} | ||||
| 						info = sdpMap[fields[0]] | ||||
| 						mfields := strings.Split(fields[1], " ") | ||||
| 						if len(mfields) >= 3 { | ||||
| 							info.PayloadType, _ = strconv.Atoi(mfields[2]) | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
|  | ||||
| 			case "a": | ||||
| 				if info != nil { | ||||
| 					for _, field := range fields { | ||||
| 						keyval := strings.SplitN(field, ":", 2) | ||||
| 						if len(keyval) >= 2 { | ||||
| 							key := keyval[0] | ||||
| 							val := keyval[1] | ||||
| 							switch key { | ||||
| 							case "control": | ||||
| 								info.Control = val | ||||
| 							case "rtpmap": | ||||
| 								info.Rtpmap, _ = strconv.Atoi(val) | ||||
| 							} | ||||
| 						} | ||||
| 						keyval = strings.Split(field, "/") | ||||
| 						if len(keyval) >= 2 { | ||||
| 							key := keyval[0] | ||||
| 							switch key { | ||||
| 							case "MPEG4-GENERIC": | ||||
| 								info.Codec = "aac" | ||||
| 							case "H264": | ||||
| 								info.Codec = "h264" | ||||
| 							case "H265": | ||||
| 								info.Codec = "h265" | ||||
| 							} | ||||
| 							if i, err := strconv.Atoi(keyval[1]); err == nil { | ||||
| 								info.TimeScale = i | ||||
| 							} | ||||
| 						} | ||||
| 						keyval = strings.Split(field, ";") | ||||
| 						if len(keyval) > 1 { | ||||
| 							for _, field := range keyval { | ||||
| 								keyval := strings.SplitN(field, "=", 2) | ||||
| 								if len(keyval) == 2 { | ||||
| 									key := strings.TrimSpace(keyval[0]) | ||||
| 									val := keyval[1] | ||||
| 									switch key { | ||||
| 									case "config": | ||||
| 										info.Config, _ = hex.DecodeString(val) | ||||
| 									case "sizelength": | ||||
| 										info.SizeLength, _ = strconv.Atoi(val) | ||||
| 									case "indexlength": | ||||
| 										info.IndexLength, _ = strconv.Atoi(val) | ||||
| 									case "sprop-parameter-sets": | ||||
| 										fields := strings.Split(val, ",") | ||||
| 										for _, field := range fields { | ||||
| 											val, _ := base64.StdEncoding.DecodeString(field) | ||||
| 											info.SpropParameterSets = append(info.SpropParameterSets, val) | ||||
| 										} | ||||
| 									} | ||||
| 								} | ||||
| 							} | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
|  | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return sdpMap | ||||
| } | ||||
							
								
								
									
										256
									
								
								server.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										256
									
								
								server.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,256 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"sync" | ||||
| 	"unsafe" | ||||
|  | ||||
| 	"github.com/Monibuca/engine/v3" | ||||
| 	. "github.com/Monibuca/utils/v3" | ||||
| 	"github.com/Monibuca/utils/v3/codec" | ||||
| 	"github.com/aler9/gortsplib" | ||||
| 	"github.com/aler9/gortsplib/pkg/aac" | ||||
| 	"github.com/aler9/gortsplib/pkg/base" | ||||
| 	"github.com/pion/rtp" | ||||
| 	"github.com/pion/rtp/codecs" | ||||
| ) | ||||
|  | ||||
| // 接收RTSP推流:OnConnOpen->OnAnnounce->OnSetup->OnSessionOpen | ||||
| // 接收RTSP拉流:OnConnOpen->OnDescribe->OnSetup->OnSessionOpen | ||||
| type RTSPServer struct { | ||||
| 	sync.Map | ||||
| } | ||||
| type RTSPSubscriber struct { | ||||
| 	stream *gortsplib.ServerStream | ||||
| 	engine.Subscriber | ||||
| 	vt *engine.VideoTrack | ||||
| 	at *engine.AudioTrack | ||||
| } | ||||
|  | ||||
| // called after a connection is opened. | ||||
| func (sh *RTSPServer) OnConnOpen(ctx *gortsplib.ServerHandlerOnConnOpenCtx) { | ||||
| 	Printf("rtsp conn opened") | ||||
| } | ||||
|  | ||||
| // called after a connection is closed. | ||||
| func (sh *RTSPServer) OnConnClose(ctx *gortsplib.ServerHandlerOnConnCloseCtx) { | ||||
| 	Printf("rtsp conn closed (%v)", ctx.Error) | ||||
| 	if p, ok := sh.Load(ctx.Conn); ok { | ||||
| 		switch v := p.(type) { | ||||
| 		case *RTSPublisher: | ||||
| 			v.Close() | ||||
| 		case *RTSPSubscriber: | ||||
| 			v.Close() | ||||
| 		} | ||||
| 		sh.Delete(ctx.Conn) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // called after a session is opened. | ||||
| func (sh *RTSPServer) OnSessionOpen(ctx *gortsplib.ServerHandlerOnSessionOpenCtx) { | ||||
| 	Printf("rtsp session opened") | ||||
| } | ||||
|  | ||||
| // called after a session is closed. | ||||
| func (sh *RTSPServer) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionCloseCtx) { | ||||
| 	Printf("rtsp session closed") | ||||
| 	if v, ok := sh.LoadAndDelete(ctx.Session); ok { | ||||
| 		switch v := v.(type) { | ||||
| 		case *RTSPublisher: | ||||
| 			v.Close() | ||||
| 		case *RTSPSubscriber: | ||||
| 			v.Close() | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // called after receiving a DESCRIBE request. | ||||
| func (sh *RTSPServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) { | ||||
| 	Printf("describe request") | ||||
| 	var err error | ||||
| 	if s := engine.FindStream(ctx.Path); s != nil { | ||||
| 		var tracks gortsplib.Tracks | ||||
| 		var stream *gortsplib.ServerStream | ||||
| 		var sub RTSPSubscriber | ||||
| 		sub.Type = "RTSP pull" | ||||
| 		sub.vt = s.WaitVideoTrack("h264", "h265") | ||||
| 		sub.at = s.WaitAudioTrack("aac", "pcma", "pcmu") | ||||
| 		ssrc := uintptr(unsafe.Pointer(stream)) | ||||
| 		var trackIds = 0 | ||||
| 		if sub.vt != nil { | ||||
| 			trackId := trackIds | ||||
| 			var vtrack *gortsplib.Track | ||||
| 			var vpacketer rtp.Packetizer | ||||
| 			switch sub.vt.CodecID { | ||||
| 			case codec.CodecID_H264: | ||||
| 				if vtrack, err = gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{ | ||||
| 					SPS: sub.vt.ExtraData.NALUs[0], | ||||
| 					PPS: sub.vt.ExtraData.NALUs[1], | ||||
| 				}); err == nil { | ||||
| 					vpacketer = rtp.NewPacketizer(1200, 96, uint32(ssrc), &codecs.H264Payloader{}, rtp.NewFixedSequencer(1), 90000) | ||||
| 				} else { | ||||
| 					return nil, nil, err | ||||
| 				} | ||||
| 			case codec.CodecID_H265: | ||||
| 				vtrack = NewH265Track(96, sub.vt.ExtraData.NALUs) | ||||
| 				vpacketer = rtp.NewPacketizer(1200, 96, uint32(ssrc), &H265Payloader{}, rtp.NewFixedSequencer(1), 90000) | ||||
| 			} | ||||
| 			var st uint32 | ||||
| 			onVideo := func(ts uint32, pack *engine.VideoPack) { | ||||
| 				for _, nalu := range pack.NALUs { | ||||
| 					for _, pack := range vpacketer.Packetize(nalu, (ts-st)*90) { | ||||
| 						rtp, _ := pack.Marshal() | ||||
| 						stream.WritePacketRTP(trackId, rtp) | ||||
| 					} | ||||
| 				} | ||||
| 				st = ts | ||||
| 			} | ||||
| 			sub.OnVideo = func(ts uint32, pack *engine.VideoPack) { | ||||
| 				if st = ts; st != 0 { | ||||
| 					sub.OnVideo = onVideo | ||||
| 				} | ||||
| 				onVideo(ts, pack) | ||||
| 			} | ||||
| 			tracks = append(tracks, vtrack) | ||||
| 			trackIds++ | ||||
| 		} | ||||
| 		if sub.at != nil { | ||||
| 			var st uint32 | ||||
| 			trackId := trackIds | ||||
| 			switch sub.at.CodecID { | ||||
| 			case codec.CodecID_PCMA, codec.CodecID_PCMU: | ||||
| 				atrack := NewG711Track(97, map[byte]string{7: "pcma", 8: "pcmu"}[sub.at.CodecID]) | ||||
| 				apacketizer := rtp.NewPacketizer(1200, 97, uint32(ssrc), &codecs.G711Payloader{}, rtp.NewFixedSequencer(1), 8000) | ||||
| 				sub.OnAudio = func(ts uint32, pack *engine.AudioPack) { | ||||
| 					for _, pack := range apacketizer.Packetize(pack.Raw, (ts-st)*8) { | ||||
| 						buf, _ := pack.Marshal() | ||||
| 						stream.WritePacketRTP(trackId, buf) | ||||
| 					} | ||||
| 					st = ts | ||||
| 				} | ||||
| 				tracks = append(tracks, atrack) | ||||
| 			case codec.CodecID_AAC: | ||||
| 				var mpegConf aac.MPEG4AudioConfig | ||||
| 				mpegConf.Decode(sub.at.ExtraData[2:]) | ||||
| 				conf := &gortsplib.TrackConfigAAC{ | ||||
| 					Type:              int(mpegConf.Type), | ||||
| 					SampleRate:        mpegConf.SampleRate, | ||||
| 					ChannelCount:      mpegConf.ChannelCount, | ||||
| 					AOTSpecificConfig: mpegConf.AOTSpecificConfig, | ||||
| 				} | ||||
| 				if atrack, err := gortsplib.NewTrackAAC(97, conf); err == nil { | ||||
| 					apacketizer := rtp.NewPacketizer(1200, 97, uint32(ssrc), &AACPayloader{}, rtp.NewFixedSequencer(1), uint32(mpegConf.SampleRate)) | ||||
| 					sub.OnAudio = func(ts uint32, pack *engine.AudioPack) { | ||||
| 						for _, pack := range apacketizer.Packetize(pack.Raw, (ts-st)*uint32(mpegConf.SampleRate)/1000) { | ||||
| 							buf, _ := pack.Marshal() | ||||
| 							stream.WritePacketRTP(trackId, buf) | ||||
| 						} | ||||
| 						st = ts | ||||
| 					} | ||||
| 					tracks = append(tracks, atrack) | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		stream = gortsplib.NewServerStream(tracks) | ||||
| 		sub.stream = stream | ||||
| 		sh.Store(ctx.Conn, &sub) | ||||
| 		return &base.Response{ | ||||
| 			StatusCode: base.StatusOK, | ||||
| 		}, stream, nil | ||||
| 		// if stream, ok := s.ExtraProp.(*gortsplib.ServerStream); ok { | ||||
| 		// 	return &base.Response{ | ||||
| 		// 		StatusCode: base.StatusOK, | ||||
| 		// 	}, stream, nil | ||||
| 		// } | ||||
| 	} | ||||
| 	return &base.Response{ | ||||
| 		StatusCode: base.StatusNotFound, | ||||
| 	}, nil, nil | ||||
| } | ||||
|  | ||||
| // called after receiving an ANNOUNCE request. | ||||
| func (sh *RTSPServer) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*base.Response, error) { | ||||
| 	Printf("announce request") | ||||
| 	p := &RTSPublisher{ | ||||
| 		Stream: &engine.Stream{ | ||||
| 			StreamPath: ctx.Path, | ||||
| 			Type:       "RTSP push", | ||||
| 		}, | ||||
| 	} | ||||
| 	p.ExtraProp = p | ||||
| 	p.URL = ctx.Req.URL.String() | ||||
| 	if p.Publish() { | ||||
| 		p.setTracks(ctx.Tracks) | ||||
| 		p.stream = gortsplib.NewServerStream(ctx.Tracks) | ||||
| 		sh.Store(ctx.Conn, p) | ||||
| 		sh.Store(ctx.Session, p) | ||||
| 	} else { | ||||
| 		return &base.Response{ | ||||
| 			StatusCode: base.StatusBadRequest, | ||||
| 		}, fmt.Errorf("streamPath is already exist") | ||||
| 	} | ||||
| 	return &base.Response{ | ||||
| 		StatusCode: base.StatusOK, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // called after receiving a SETUP request. | ||||
| func (sh *RTSPServer) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error) { | ||||
| 	Printf("setup request") | ||||
| 	if p, ok := sh.Load(ctx.Conn); ok { | ||||
| 		switch v := p.(type) { | ||||
| 		case *RTSPublisher: | ||||
| 			return &base.Response{ | ||||
| 				StatusCode: base.StatusOK, | ||||
| 			}, v.stream, nil | ||||
| 		case *RTSPSubscriber: | ||||
| 			return &base.Response{ | ||||
| 				StatusCode: base.StatusOK, | ||||
| 			}, v.stream, nil | ||||
| 		} | ||||
| 	} | ||||
| 	return &base.Response{ | ||||
| 		StatusCode: base.StatusNotFound, | ||||
| 	}, nil, nil | ||||
| } | ||||
|  | ||||
| // called after receiving a PLAY request. | ||||
| func (sh *RTSPServer) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) { | ||||
| 	Printf("play request") | ||||
| 	if p, ok := sh.Load(ctx.Conn); ok { | ||||
| 		if sub := p.(*RTSPSubscriber); sub.Subscribe(ctx.Path) == nil { | ||||
| 			go func() { | ||||
| 				sub.Play(sub.at, sub.vt) | ||||
| 				ctx.Conn.Close() | ||||
| 			}() | ||||
| 			return &base.Response{ | ||||
| 				StatusCode: base.StatusOK, | ||||
| 			}, nil | ||||
| 		} | ||||
| 	} | ||||
| 	return &base.Response{ | ||||
| 		StatusCode: base.StatusNotFound, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // called after receiving a RECORD request. | ||||
| func (sh *RTSPServer) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*base.Response, error) { | ||||
| 	Printf("record request") | ||||
| 	return &base.Response{ | ||||
| 		StatusCode: base.StatusOK, | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
| // called after receiving a frame. | ||||
| func (sh *RTSPServer) OnPacketRTP(ctx *gortsplib.ServerHandlerOnPacketRTPCtx) { | ||||
| 	if p, ok := sh.Load(ctx.Session); ok { | ||||
| 		rtsp := p.(*RTSPublisher) | ||||
| 		if rtsp.Err() != nil { | ||||
| 			ctx.Session.Close() | ||||
| 			return | ||||
| 		} | ||||
| 		if f := rtsp.processFunc[ctx.TrackID]; f != nil { | ||||
| 			f(ctx.Payload) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										640
									
								
								session.go
									
									
									
									
									
								
							
							
						
						
									
										640
									
								
								session.go
									
									
									
									
									
								
							| @@ -1,640 +0,0 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"crypto/md5" | ||||
| 	"encoding/binary" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"net/url" | ||||
| 	"regexp" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	. "github.com/Monibuca/engine/v2" | ||||
| 	"github.com/teris-io/shortid" | ||||
| ) | ||||
|  | ||||
| type RTPPack struct { | ||||
| 	Type   RTPType | ||||
| 	Buffer []byte | ||||
| } | ||||
|  | ||||
| type SessionType int | ||||
|  | ||||
| const ( | ||||
| 	SESSION_TYPE_PUSHER SessionType = iota | ||||
| 	SESSEION_TYPE_PLAYER | ||||
| ) | ||||
|  | ||||
| func (st SessionType) String() string { | ||||
| 	switch st { | ||||
| 	case SESSION_TYPE_PUSHER: | ||||
| 		return "pusher" | ||||
| 	case SESSEION_TYPE_PLAYER: | ||||
| 		return "player" | ||||
| 	} | ||||
| 	return "unknow" | ||||
| } | ||||
|  | ||||
| type RTPType int | ||||
|  | ||||
| const ( | ||||
| 	RTP_TYPE_AUDIO RTPType = iota | ||||
| 	RTP_TYPE_VIDEO | ||||
| 	RTP_TYPE_AUDIOCONTROL | ||||
| 	RTP_TYPE_VIDEOCONTROL | ||||
| ) | ||||
|  | ||||
| func (rt RTPType) String() string { | ||||
| 	switch rt { | ||||
| 	case RTP_TYPE_AUDIO: | ||||
| 		return "audio" | ||||
| 	case RTP_TYPE_VIDEO: | ||||
| 		return "video" | ||||
| 	case RTP_TYPE_AUDIOCONTROL: | ||||
| 		return "audio control" | ||||
| 	case RTP_TYPE_VIDEOCONTROL: | ||||
| 		return "video control" | ||||
| 	} | ||||
| 	return "unknow" | ||||
| } | ||||
|  | ||||
| type TransType int | ||||
|  | ||||
| const ( | ||||
| 	TRANS_TYPE_TCP TransType = iota | ||||
| 	TRANS_TYPE_UDP | ||||
| ) | ||||
|  | ||||
| func (tt TransType) String() string { | ||||
| 	switch tt { | ||||
| 	case TRANS_TYPE_TCP: | ||||
| 		return "TCP" | ||||
| 	case TRANS_TYPE_UDP: | ||||
| 		return "UDP" | ||||
| 	} | ||||
| 	return "unknow" | ||||
| } | ||||
|  | ||||
| const UDP_BUF_SIZE = 1048576 | ||||
|  | ||||
| func (session *RTSP) SessionString() string { | ||||
| 	return fmt.Sprintf("session[%v][%v][%s][%s][%s]", session.Type, session.TransType, session.StreamPath, session.ID, session.Conn.RemoteAddr().String()) | ||||
| } | ||||
|  | ||||
| func (session *RTSP) Stop() { | ||||
| 	if session.Conn != nil { | ||||
| 		session.connRW.Flush() | ||||
| 		session.Conn.Close() | ||||
| 		session.Conn = nil | ||||
| 	} | ||||
| 	if session.UDPClient != nil { | ||||
| 		session.UDPClient.Stop() | ||||
| 		session.UDPClient = nil | ||||
| 	} | ||||
| 	if session.UDPServer != nil { | ||||
| 		session.UDPServer.Stop() | ||||
| 		session.UDPServer = nil | ||||
| 	} | ||||
| 	if session.Running() { | ||||
| 		session.Cancel() | ||||
| 	} | ||||
| 	if session.Stream != nil { | ||||
| 		collection.Delete(session.StreamPath) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // AcceptPush 接受推流 | ||||
| func (session *RTSP) AcceptPush() { | ||||
| 	defer session.Stop() | ||||
| 	buf2 := make([]byte, 2) | ||||
| 	timer := time.Unix(0, 0) | ||||
| 	for { | ||||
| 		buf1, err := session.connRW.ReadByte() | ||||
| 		if err != nil { | ||||
| 			Println(err) | ||||
| 			return | ||||
| 		} | ||||
| 		if buf1 == 0x24 { //rtp data | ||||
| 			if buf1, err = session.connRW.ReadByte(); err != nil { | ||||
| 				Println(err) | ||||
| 				return | ||||
| 			} | ||||
| 			if _, err := io.ReadFull(session.connRW, buf2); err != nil { | ||||
| 				Println(err) | ||||
| 				return | ||||
| 			} | ||||
| 			channel := int(buf1) | ||||
| 			rtpLen := int(binary.BigEndian.Uint16(buf2)) | ||||
| 			rtpBytes := make([]byte, rtpLen) | ||||
| 			if _, err := io.ReadFull(session.connRW, rtpBytes); err != nil { | ||||
| 				Println(err) | ||||
| 				return | ||||
| 			} | ||||
| 			var pack *RTPPack | ||||
| 			switch channel { | ||||
| 			case session.aRTPChannel: | ||||
| 				pack = &RTPPack{ | ||||
| 					Type:   RTP_TYPE_AUDIO, | ||||
| 					Buffer: rtpBytes, | ||||
| 				} | ||||
| 				elapsed := time.Now().Sub(timer) | ||||
| 				if elapsed >= 30*time.Second { | ||||
| 					Println("Recv an audio RTP package") | ||||
| 					timer = time.Now() | ||||
| 				} | ||||
| 			case session.aRTPControlChannel: | ||||
| 				pack = &RTPPack{ | ||||
| 					Type:   RTP_TYPE_AUDIOCONTROL, | ||||
| 					Buffer: rtpBytes, | ||||
| 				} | ||||
| 			case session.vRTPChannel: | ||||
| 				pack = &RTPPack{ | ||||
| 					Type:   RTP_TYPE_VIDEO, | ||||
| 					Buffer: rtpBytes, | ||||
| 				} | ||||
| 				elapsed := time.Now().Sub(timer) | ||||
| 				if elapsed >= 30*time.Second { | ||||
| 					Println("Recv an video RTP package") | ||||
| 					timer = time.Now() | ||||
| 				} | ||||
| 			case session.vRTPControlChannel: | ||||
| 				pack = &RTPPack{ | ||||
| 					Type:   RTP_TYPE_VIDEOCONTROL, | ||||
| 					Buffer: rtpBytes, | ||||
| 				} | ||||
| 			default: | ||||
| 				Printf("unknow rtp pack type, %v", pack.Type) | ||||
| 				continue | ||||
| 			} | ||||
| 			if pack == nil { | ||||
| 				Printf("session tcp got nil rtp pack") | ||||
| 				continue | ||||
| 			} | ||||
| 			session.InBytes += rtpLen + 4 | ||||
| 			session.handleRTP(pack) | ||||
| 		} else { // rtsp cmd | ||||
| 			reqBuf := bytes.NewBuffer(nil) | ||||
| 			reqBuf.WriteByte(buf1) | ||||
| 			for { | ||||
| 				if line, isPrefix, err := session.connRW.ReadLine(); err != nil { | ||||
| 					Println(err) | ||||
| 					return | ||||
| 				} else { | ||||
| 					reqBuf.Write(line) | ||||
| 					if !isPrefix { | ||||
| 						reqBuf.WriteString("\r\n") | ||||
| 					} | ||||
| 					if len(line) == 0 { | ||||
| 						req := NewRequest(reqBuf.String()) | ||||
| 						if req == nil { | ||||
| 							break | ||||
| 						} | ||||
| 						session.InBytes += reqBuf.Len() | ||||
| 						contentLen := req.GetContentLength() | ||||
| 						session.InBytes += contentLen | ||||
| 						if contentLen > 0 { | ||||
| 							bodyBuf := make([]byte, contentLen) | ||||
| 							if n, err := io.ReadFull(session.connRW, bodyBuf); err != nil { | ||||
| 								Println(err) | ||||
| 								return | ||||
| 							} else if n != contentLen { | ||||
| 								Printf("read rtsp request body failed, expect size[%d], got size[%d]", contentLen, n) | ||||
| 								return | ||||
| 							} | ||||
| 							req.Body = string(bodyBuf) | ||||
| 						} | ||||
| 						session.handleRequest(req) | ||||
| 						break | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (session *RTSP) CheckAuth(authLine string, method string) error { | ||||
| 	realmRex := regexp.MustCompile(`realm="(.*?)"`) | ||||
| 	nonceRex := regexp.MustCompile(`nonce="(.*?)"`) | ||||
| 	usernameRex := regexp.MustCompile(`username="(.*?)"`) | ||||
| 	responseRex := regexp.MustCompile(`response="(.*?)"`) | ||||
| 	uriRex := regexp.MustCompile(`uri="(.*?)"`) | ||||
|  | ||||
| 	realm := "" | ||||
| 	nonce := "" | ||||
| 	username := "" | ||||
| 	response := "" | ||||
| 	uri := "" | ||||
| 	result1 := realmRex.FindStringSubmatch(authLine) | ||||
| 	if len(result1) == 2 { | ||||
| 		realm = result1[1] | ||||
| 	} else { | ||||
| 		return fmt.Errorf("CheckAuth error : no realm found") | ||||
| 	} | ||||
| 	result1 = nonceRex.FindStringSubmatch(authLine) | ||||
| 	if len(result1) == 2 { | ||||
| 		nonce = result1[1] | ||||
| 	} else { | ||||
| 		return fmt.Errorf("CheckAuth error : no nonce found") | ||||
| 	} | ||||
| 	if session.nonce != nonce { | ||||
| 		return fmt.Errorf("CheckAuth error : sessionNonce not same as nonce") | ||||
| 	} | ||||
|  | ||||
| 	result1 = usernameRex.FindStringSubmatch(authLine) | ||||
| 	if len(result1) == 2 { | ||||
| 		username = result1[1] | ||||
| 	} else { | ||||
| 		return fmt.Errorf("CheckAuth error : username not found") | ||||
| 	} | ||||
|  | ||||
| 	result1 = responseRex.FindStringSubmatch(authLine) | ||||
| 	if len(result1) == 2 { | ||||
| 		response = result1[1] | ||||
| 	} else { | ||||
| 		return fmt.Errorf("CheckAuth error : response not found") | ||||
| 	} | ||||
|  | ||||
| 	result1 = uriRex.FindStringSubmatch(authLine) | ||||
| 	if len(result1) == 2 { | ||||
| 		uri = result1[1] | ||||
| 	} else { | ||||
| 		return fmt.Errorf("CheckAuth error : uri not found") | ||||
| 	} | ||||
| 	// var user models.User | ||||
| 	// err := db.SQLite.Where("Username = ?", username).First(&user).Error | ||||
| 	// if err != nil { | ||||
| 	// 	return fmt.Errorf("CheckAuth error : user not exists") | ||||
| 	// } | ||||
| 	md5UserRealmPwd := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%s:%s:%s", username, realm, session.Auth(username))))) | ||||
| 	md5MethodURL := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%s:%s", method, uri)))) | ||||
| 	myResponse := fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%s:%s:%s", md5UserRealmPwd, nonce, md5MethodURL)))) | ||||
| 	if myResponse != response { | ||||
| 		return fmt.Errorf("CheckAuth error : response not equal") | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (session *RTSP) handleRequest(req *Request) { | ||||
| 	//if session.Timeout > 0 { | ||||
| 	//	session.Conn.SetDeadline(time.Now().Add(time.Duration(session.Timeout) * time.Second)) | ||||
| 	//} | ||||
| 	Printf("<<<\n%s", req) | ||||
| 	res := NewResponse(200, "OK", req.Header["CSeq"], session.ID, "") | ||||
| 	defer func() { | ||||
| 		if p := recover(); p != nil { | ||||
| 			Printf("handleRequest err ocurs:%v", p) | ||||
| 			res.StatusCode = 500 | ||||
| 			res.Status = fmt.Sprintf("Inner Server Error, %v", p) | ||||
| 		} | ||||
| 		Printf(">>>\n%s", res) | ||||
| 		outBytes := []byte(res.String()) | ||||
| 		session.connWLock.Lock() | ||||
| 		session.connRW.Write(outBytes) | ||||
| 		session.connRW.Flush() | ||||
| 		session.connWLock.Unlock() | ||||
| 		session.OutBytes += len(outBytes) | ||||
| 		switch req.Method { | ||||
| 		case "PLAY", "RECORD": | ||||
| 			switch session.Type { | ||||
| 			case SESSEION_TYPE_PLAYER: | ||||
| 				// if session.Pusher.HasPlayer(session.Player) { | ||||
| 				// 	session.Player.Pause(false) | ||||
| 				// } else { | ||||
| 				// 	session.Pusher.AddPlayer(session.Player) | ||||
| 				// } | ||||
| 			} | ||||
| 		case "TEARDOWN": | ||||
| 			{ | ||||
| 				session.Stop() | ||||
| 				return | ||||
| 			} | ||||
| 		} | ||||
| 		if res.StatusCode != 200 && res.StatusCode != 401 { | ||||
| 			Printf("Response request error[%d]. stop session.", res.StatusCode) | ||||
| 			session.Stop() | ||||
| 		} | ||||
| 	}() | ||||
| 	if req.Method != "OPTIONS" { | ||||
| 		if session.Auth != nil { | ||||
| 			authLine := req.Header["Authorization"] | ||||
| 			authFailed := true | ||||
| 			if authLine != "" { | ||||
| 				err := session.CheckAuth(authLine, req.Method) | ||||
| 				if err == nil { | ||||
| 					authFailed = false | ||||
| 				} else { | ||||
| 					Printf("%v", err) | ||||
| 				} | ||||
| 			} | ||||
| 			if authFailed { | ||||
| 				res.StatusCode = 401 | ||||
| 				res.Status = "Unauthorized" | ||||
| 				nonce := fmt.Sprintf("%x", md5.Sum([]byte(shortid.MustGenerate()))) | ||||
| 				session.nonce = nonce | ||||
| 				res.Header["WWW-Authenticate"] = fmt.Sprintf(`Digest realm="EasyDarwin", nonce="%s", algorithm="MD5"`, nonce) | ||||
| 				return | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	switch req.Method { | ||||
| 	case "OPTIONS": | ||||
| 		res.Header["Public"] = "DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD" | ||||
| 	case "ANNOUNCE": | ||||
| 		session.Type = SESSION_TYPE_PUSHER | ||||
| 		session.URL = req.URL | ||||
|  | ||||
| 		url, err := url.Parse(req.URL) | ||||
| 		if err != nil { | ||||
| 			res.StatusCode = 500 | ||||
| 			res.Status = "Invalid URL" | ||||
| 			return | ||||
| 		} | ||||
| 		streamPath := strings.TrimPrefix(url.Path, "/") | ||||
|  | ||||
| 		session.SDPRaw = req.Body | ||||
| 		session.SDPMap = ParseSDP(req.Body) | ||||
| 		sdp, ok := session.SDPMap["audio"] | ||||
| 		if ok { | ||||
| 			session.AControl = sdp.Control | ||||
| 			session.ACodec = sdp.Codec | ||||
| 			session.AudioSpecificConfig = sdp.Config | ||||
| 			Printf("audio codec[%s]\n", session.ACodec) | ||||
| 		} | ||||
| 		if sdp, ok = session.SDPMap["video"]; ok { | ||||
| 			session.VControl = sdp.Control | ||||
| 			session.VCodec = sdp.Codec | ||||
| 			session.SPS = sdp.SpropParameterSets[0] | ||||
| 			session.PPS = sdp.SpropParameterSets[1] | ||||
| 			Printf("video codec[%s]\n", session.VCodec) | ||||
| 		} | ||||
| 		if session.Publisher.Publish(streamPath) { | ||||
| 			session.Stream.Type = "RTSP" | ||||
| 			session.RTSPInfo.StreamInfo = &session.Stream.StreamInfo | ||||
| 			collection.Store(streamPath, session) | ||||
| 		} | ||||
| 	case "DESCRIBE": | ||||
| 		session.Type = SESSEION_TYPE_PLAYER | ||||
| 		session.URL = req.URL | ||||
| 		url, err := url.Parse(req.URL) | ||||
| 		if err != nil { | ||||
| 			res.StatusCode = 500 | ||||
| 			res.Status = "Invalid URL" | ||||
| 			return | ||||
| 		} | ||||
| 		streamPath := url.Path | ||||
| 		stream := FindStream(streamPath) | ||||
| 		if stream == nil { | ||||
| 			return | ||||
| 		} | ||||
| 		// | ||||
| 		//res.SetBody(session.SDPRaw) | ||||
| 	case "SETUP": | ||||
| 		ts := req.Header["Transport"] | ||||
| 		// control字段可能是`stream=1`字样,也可能是rtsp://...字样。即control可能是url的path,也可能是整个url | ||||
| 		// 例1: | ||||
| 		// a=control:streamid=1 | ||||
| 		// 例2: | ||||
| 		// a=control:rtsp://192.168.1.64/trackID=1 | ||||
| 		// 例3: | ||||
| 		// a=control:?ctype=video | ||||
| 		setupUrl, err := url.Parse(req.URL) | ||||
| 		if err != nil { | ||||
| 			res.StatusCode = 500 | ||||
| 			res.Status = "Invalid URL" | ||||
| 			return | ||||
| 		} | ||||
| 		if setupUrl.Port() == "" { | ||||
| 			setupUrl.Host = fmt.Sprintf("%s:554", setupUrl.Host) | ||||
| 		} | ||||
| 		setupPath := setupUrl.String() | ||||
|  | ||||
| 		// error status. SETUP without ANNOUNCE or DESCRIBE. | ||||
| 		//if session.Pusher == nil { | ||||
| 		//	res.StatusCode = 500 | ||||
| 		//	res.Status = "Error Status" | ||||
| 		//	return | ||||
| 		//} | ||||
| 		vPath := "" | ||||
| 		if strings.Index(strings.ToLower(session.VControl), "rtsp://") == 0 { | ||||
| 			vControlUrl, err := url.Parse(session.VControl) | ||||
| 			if err != nil { | ||||
| 				res.StatusCode = 500 | ||||
| 				res.Status = "Invalid VControl" | ||||
| 				return | ||||
| 			} | ||||
| 			if vControlUrl.Port() == "" { | ||||
| 				vControlUrl.Host = fmt.Sprintf("%s:554", vControlUrl.Host) | ||||
| 			} | ||||
| 			vPath = vControlUrl.String() | ||||
| 		} else { | ||||
| 			vPath = session.VControl | ||||
| 		} | ||||
|  | ||||
| 		aPath := "" | ||||
| 		if strings.Index(strings.ToLower(session.AControl), "rtsp://") == 0 { | ||||
| 			aControlUrl, err := url.Parse(session.AControl) | ||||
| 			if err != nil { | ||||
| 				res.StatusCode = 500 | ||||
| 				res.Status = "Invalid AControl" | ||||
| 				return | ||||
| 			} | ||||
| 			if aControlUrl.Port() == "" { | ||||
| 				aControlUrl.Host = fmt.Sprintf("%s:554", aControlUrl.Host) | ||||
| 			} | ||||
| 			aPath = aControlUrl.String() | ||||
| 		} else { | ||||
| 			aPath = session.AControl | ||||
| 		} | ||||
|  | ||||
| 		mtcp := regexp.MustCompile("interleaved=(\\d+)(-(\\d+))?") | ||||
| 		mudp := regexp.MustCompile("client_port=(\\d+)(-(\\d+))?") | ||||
|  | ||||
| 		if tcpMatchs := mtcp.FindStringSubmatch(ts); tcpMatchs != nil { | ||||
| 			session.TransType = TRANS_TYPE_TCP | ||||
| 			if setupPath == aPath || aPath != "" && strings.LastIndex(setupPath, aPath) == len(setupPath)-len(aPath) { | ||||
| 				session.aRTPChannel, _ = strconv.Atoi(tcpMatchs[1]) | ||||
| 				session.aRTPControlChannel, _ = strconv.Atoi(tcpMatchs[3]) | ||||
| 			} else if setupPath == vPath || vPath != "" && strings.LastIndex(setupPath, vPath) == len(setupPath)-len(vPath) { | ||||
| 				session.vRTPChannel, _ = strconv.Atoi(tcpMatchs[1]) | ||||
| 				session.vRTPControlChannel, _ = strconv.Atoi(tcpMatchs[3]) | ||||
| 			} else { | ||||
| 				res.StatusCode = 500 | ||||
| 				res.Status = fmt.Sprintf("SETUP [TCP] got UnKown control:%s", setupPath) | ||||
| 				Printf("SETUP [TCP] got UnKown control:%s", setupPath) | ||||
| 			} | ||||
| 			Printf("Parse SETUP req.TRANSPORT:TCP.Session.Type:%d,control:%s, AControl:%s,VControl:%s", session.Type, setupPath, aPath, vPath) | ||||
| 		} else if udpMatchs := mudp.FindStringSubmatch(ts); udpMatchs != nil { | ||||
| 			session.TransType = TRANS_TYPE_UDP | ||||
| 			// no need for tcp timeout. | ||||
| 			session.Conn.timeout = 0 | ||||
| 			if session.Type == SESSEION_TYPE_PLAYER && session.UDPClient == nil { | ||||
| 				session.UDPClient = &UDPClient{} | ||||
| 			} | ||||
| 			if session.Type == SESSION_TYPE_PUSHER && session.UDPServer == nil { | ||||
| 				session.UDPServer = &UDPServer{ | ||||
| 					Session: session, | ||||
| 				} | ||||
| 			} | ||||
| 			Printf("Parse SETUP req.TRANSPORT:UDP.Session.Type:%d,control:%s, AControl:%s,VControl:%s", session.Type, setupPath, aPath, vPath) | ||||
| 			if setupPath == aPath || aPath != "" && strings.LastIndex(setupPath, aPath) == len(setupPath)-len(aPath) { | ||||
| 				if session.Type == SESSEION_TYPE_PLAYER { | ||||
| 					session.UDPClient.APort, _ = strconv.Atoi(udpMatchs[1]) | ||||
| 					session.UDPClient.AControlPort, _ = strconv.Atoi(udpMatchs[3]) | ||||
| 					if err := session.UDPClient.SetupAudio(); err != nil { | ||||
| 						res.StatusCode = 500 | ||||
| 						res.Status = fmt.Sprintf("udp client setup audio error, %v", err) | ||||
| 						return | ||||
| 					} | ||||
| 				} | ||||
| 				if session.Type == SESSION_TYPE_PUSHER { | ||||
| 					if err := session.UDPServer.SetupAudio(); err != nil { | ||||
| 						res.StatusCode = 500 | ||||
| 						res.Status = fmt.Sprintf("udp server setup audio error, %v", err) | ||||
| 						return | ||||
| 					} | ||||
| 					tss := strings.Split(ts, ";") | ||||
| 					idx := -1 | ||||
| 					for i, val := range tss { | ||||
| 						if val == udpMatchs[0] { | ||||
| 							idx = i | ||||
| 						} | ||||
| 					} | ||||
| 					tail := append([]string{}, tss[idx+1:]...) | ||||
| 					tss = append(tss[:idx+1], fmt.Sprintf("server_port=%d-%d", session.UDPServer.APort, session.UDPServer.AControlPort)) | ||||
| 					tss = append(tss, tail...) | ||||
| 					ts = strings.Join(tss, ";") | ||||
| 				} | ||||
| 			} else if setupPath == vPath || vPath != "" && strings.LastIndex(setupPath, vPath) == len(setupPath)-len(vPath) { | ||||
| 				if session.Type == SESSEION_TYPE_PLAYER { | ||||
| 					session.UDPClient.VPort, _ = strconv.Atoi(udpMatchs[1]) | ||||
| 					session.UDPClient.VControlPort, _ = strconv.Atoi(udpMatchs[3]) | ||||
| 					if err := session.UDPClient.SetupVideo(); err != nil { | ||||
| 						res.StatusCode = 500 | ||||
| 						res.Status = fmt.Sprintf("udp client setup video error, %v", err) | ||||
| 						return | ||||
| 					} | ||||
| 				} | ||||
|  | ||||
| 				if session.Type == SESSION_TYPE_PUSHER { | ||||
| 					if err := session.UDPServer.SetupVideo(); err != nil { | ||||
| 						res.StatusCode = 500 | ||||
| 						res.Status = fmt.Sprintf("udp server setup video error, %v", err) | ||||
| 						return | ||||
| 					} | ||||
| 					tss := strings.Split(ts, ";") | ||||
| 					idx := -1 | ||||
| 					for i, val := range tss { | ||||
| 						if val == udpMatchs[0] { | ||||
| 							idx = i | ||||
| 						} | ||||
| 					} | ||||
| 					tail := append([]string{}, tss[idx+1:]...) | ||||
| 					tss = append(tss[:idx+1], fmt.Sprintf("server_port=%d-%d", session.UDPServer.VPort, session.UDPServer.VControlPort)) | ||||
| 					tss = append(tss, tail...) | ||||
| 					ts = strings.Join(tss, ";") | ||||
| 				} | ||||
| 			} else { | ||||
| 				Printf("SETUP [UDP] got UnKown control:%s", setupPath) | ||||
| 			} | ||||
| 		} | ||||
| 		res.Header["Transport"] = ts | ||||
| 	case "PLAY": | ||||
| 		// error status. PLAY without ANNOUNCE or DESCRIBE. | ||||
| 		// if session.Pusher == nil { | ||||
| 		// 	res.StatusCode = 500 | ||||
| 		// 	res.Status = "Error Status" | ||||
| 		// 	return | ||||
| 		// } | ||||
| 		res.Header["Range"] = req.Header["Range"] | ||||
| 	case "RECORD": | ||||
| 		// error status. RECORD without ANNOUNCE or DESCRIBE. | ||||
| 		// if session.Pusher == nil { | ||||
| 		// 	res.StatusCode = 500 | ||||
| 		// 	res.Status = "Error Status" | ||||
| 		// 	return | ||||
| 		// } | ||||
| 	case "PAUSE": | ||||
| 		// if session.Player == nil { | ||||
| 		// 	res.StatusCode = 500 | ||||
| 		// 	res.Status = "Error Status" | ||||
| 		// 	return | ||||
| 		// } | ||||
| 		// session.Player.Pause(true) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (session *RTSP) SendRTP(pack *RTPPack) (err error) { | ||||
| 	if pack == nil { | ||||
| 		err = fmt.Errorf("player send rtp got nil pack") | ||||
| 		return | ||||
| 	} | ||||
| 	if session.TransType == TRANS_TYPE_UDP { | ||||
| 		if session.UDPClient == nil { | ||||
| 			err = fmt.Errorf("player use udp transport but udp client not found") | ||||
| 			return | ||||
| 		} | ||||
| 		err = session.UDPClient.SendRTP(pack) | ||||
| 		session.OutBytes += len(pack.Buffer) | ||||
| 		return | ||||
| 	} | ||||
| 	switch pack.Type { | ||||
| 	case RTP_TYPE_AUDIO: | ||||
| 		bufChannel := make([]byte, 2) | ||||
| 		bufChannel[0] = 0x24 | ||||
| 		bufChannel[1] = byte(session.aRTPChannel) | ||||
| 		session.connWLock.Lock() | ||||
| 		session.connRW.Write(bufChannel) | ||||
| 		bufLen := make([]byte, 2) | ||||
| 		binary.BigEndian.PutUint16(bufLen, uint16(len(pack.Buffer))) | ||||
| 		session.connRW.Write(bufLen) | ||||
| 		session.connRW.Write(pack.Buffer) | ||||
| 		session.connRW.Flush() | ||||
| 		session.connWLock.Unlock() | ||||
| 		session.OutBytes += len(pack.Buffer) + 4 | ||||
| 	case RTP_TYPE_AUDIOCONTROL: | ||||
| 		bufChannel := make([]byte, 2) | ||||
| 		bufChannel[0] = 0x24 | ||||
| 		bufChannel[1] = byte(session.aRTPControlChannel) | ||||
| 		session.connWLock.Lock() | ||||
| 		session.connRW.Write(bufChannel) | ||||
| 		bufLen := make([]byte, 2) | ||||
| 		binary.BigEndian.PutUint16(bufLen, uint16(len(pack.Buffer))) | ||||
| 		session.connRW.Write(bufLen) | ||||
| 		session.connRW.Write(pack.Buffer) | ||||
| 		session.connRW.Flush() | ||||
| 		session.connWLock.Unlock() | ||||
| 		session.OutBytes += len(pack.Buffer) + 4 | ||||
| 	case RTP_TYPE_VIDEO: | ||||
| 		bufChannel := make([]byte, 2) | ||||
| 		bufChannel[0] = 0x24 | ||||
| 		bufChannel[1] = byte(session.vRTPChannel) | ||||
| 		session.connWLock.Lock() | ||||
| 		session.connRW.Write(bufChannel) | ||||
| 		bufLen := make([]byte, 2) | ||||
| 		binary.BigEndian.PutUint16(bufLen, uint16(len(pack.Buffer))) | ||||
| 		session.connRW.Write(bufLen) | ||||
| 		session.connRW.Write(pack.Buffer) | ||||
| 		session.connRW.Flush() | ||||
| 		session.connWLock.Unlock() | ||||
| 		session.OutBytes += len(pack.Buffer) + 4 | ||||
| 	case RTP_TYPE_VIDEOCONTROL: | ||||
| 		bufChannel := make([]byte, 2) | ||||
| 		bufChannel[0] = 0x24 | ||||
| 		bufChannel[1] = byte(session.vRTPControlChannel) | ||||
| 		session.connWLock.Lock() | ||||
| 		session.connRW.Write(bufChannel) | ||||
| 		bufLen := make([]byte, 2) | ||||
| 		binary.BigEndian.PutUint16(bufLen, uint16(len(pack.Buffer))) | ||||
| 		session.connRW.Write(bufLen) | ||||
| 		session.connRW.Write(pack.Buffer) | ||||
| 		session.connRW.Flush() | ||||
| 		session.connWLock.Unlock() | ||||
| 		session.OutBytes += len(pack.Buffer) + 4 | ||||
| 	default: | ||||
| 		err = fmt.Errorf("session tcp send rtp got unkown pack type[%v]", pack.Type) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
							
								
								
									
										87
									
								
								track.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								track.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"encoding/base64" | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
|  | ||||
| 	"github.com/aler9/gortsplib" | ||||
| 	psdp "github.com/pion/sdp/v3" | ||||
| ) | ||||
|  | ||||
| // func NewTrackAAC(payloadType uint8, conf *gortsplib.TrackConfigAAC) (*gortsplib.Track, error) { | ||||
| // 	mpegConf, err := aac.MPEG4AudioConfig{ | ||||
| // 		Type:              aac.MPEG4AudioType(conf.Type), | ||||
| // 		SampleRate:        conf.SampleRate, | ||||
| // 		ChannelCount:      conf.ChannelCount, | ||||
| // 		AOTSpecificConfig: conf.AOTSpecificConfig, | ||||
| // 	}.Encode() | ||||
| // 	if err != nil { | ||||
| // 		return nil, err | ||||
| // 	} | ||||
|  | ||||
| // 	typ := strconv.FormatInt(int64(payloadType), 10) | ||||
|  | ||||
| // 	return &gortsplib.Track{ | ||||
| // 		Media: &psdp.MediaDescription{ | ||||
| // 			MediaName: psdp.MediaName{ | ||||
| // 				Media:   "audio", | ||||
| // 				Protos:  []string{"RTP", "AVP"}, | ||||
| // 				Formats: []string{typ}, | ||||
| // 			}, | ||||
| // 			Attributes: []psdp.Attribute{ | ||||
| // 				{ | ||||
| // 					Key: "rtpmap", | ||||
| // 					Value: typ + " mpeg4-generic/" + strconv.FormatInt(int64(conf.SampleRate), 10) + | ||||
| // 						"/" + strconv.FormatInt(int64(conf.ChannelCount), 10), | ||||
| // 				}, | ||||
| // 				{ | ||||
| // 					Key: "fmtp", | ||||
| // 					Value: typ + " profile-level-id=1; " + | ||||
| // 						"mode=AAC-hbr; " + | ||||
| // 						"sizelength=6; " + | ||||
| // 						"indexlength=2; " + | ||||
| // 						"indexdeltalength=2; " + | ||||
| // 						"config=" + hex.EncodeToString(mpegConf), | ||||
| // 				}, | ||||
| // 			}, | ||||
| // 		}, | ||||
| // 	}, nil | ||||
| // } | ||||
| func NewG711Track(payloadType uint8, law string) *gortsplib.Track { | ||||
| 	return &gortsplib.Track{ | ||||
| 		Media: &psdp.MediaDescription{ | ||||
| 			MediaName: psdp.MediaName{ | ||||
| 				Media:   "audio", | ||||
| 				Protos:  []string{"RTP", "AVP"}, | ||||
| 				Formats: []string{strconv.FormatInt(int64(payloadType), 10)}}, | ||||
| 			Attributes: []psdp.Attribute{ | ||||
| 				{ | ||||
| 					Key:   "rtpmap", | ||||
| 					Value: fmt.Sprintf("%d %s/8000/1", payloadType, law), | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| func NewH265Track(payloadType uint8, sprop [][]byte) *gortsplib.Track { | ||||
| 	return &gortsplib.Track{ | ||||
| 		Media: &psdp.MediaDescription{ | ||||
| 			MediaName: psdp.MediaName{ | ||||
| 				Media:   "video", | ||||
| 				Protos:  []string{"RTP", "AVP"}, | ||||
| 				Formats: []string{fmt.Sprintf("%d", payloadType)}, | ||||
| 			}, | ||||
| 			Attributes: []psdp.Attribute{ | ||||
| 				{ | ||||
| 					Key:   "rtpmap", | ||||
| 					Value: fmt.Sprintf("%d H265/90000", payloadType), | ||||
| 				}, | ||||
| 				{ | ||||
| 					Key:   "fmtp", | ||||
| 					Value: fmt.Sprintf("%d packetization-mode=1;sprop-vps=%s;sprop-sps=%s;sprop-pps=%s;", payloadType, base64.StdEncoding.EncodeToString(sprop[0]), base64.StdEncoding.EncodeToString(sprop[1]), base64.StdEncoding.EncodeToString(sprop[2])), | ||||
| 				}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										160
									
								
								udp-client.go
									
									
									
									
									
								
							
							
						
						
									
										160
									
								
								udp-client.go
									
									
									
									
									
								
							| @@ -1,160 +0,0 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"net" | ||||
| 	"strings" | ||||
| 	. "github.com/Monibuca/engine/v2" | ||||
| ) | ||||
|  | ||||
| type UDPClient struct { | ||||
| 	APort        int | ||||
| 	AConn        *net.UDPConn | ||||
| 	AControlPort int | ||||
| 	AControlConn *net.UDPConn | ||||
| 	VPort        int | ||||
| 	VConn        *net.UDPConn | ||||
| 	VControlPort int | ||||
| 	VControlConn *net.UDPConn | ||||
|  | ||||
| 	Stoped bool | ||||
| } | ||||
|  | ||||
| func (s *UDPClient) Stop() { | ||||
| 	if s.Stoped { | ||||
| 		return | ||||
| 	} | ||||
| 	s.Stoped = true | ||||
| 	if s.AConn != nil { | ||||
| 		s.AConn.Close() | ||||
| 		s.AConn = nil | ||||
| 	} | ||||
| 	if s.AControlConn != nil { | ||||
| 		s.AControlConn.Close() | ||||
| 		s.AControlConn = nil | ||||
| 	} | ||||
| 	if s.VConn != nil { | ||||
| 		s.VConn.Close() | ||||
| 		s.VConn = nil | ||||
| 	} | ||||
| 	if s.VControlConn != nil { | ||||
| 		s.VControlConn.Close() | ||||
| 		s.VControlConn = nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (c *UDPClient) SetupAudio() (err error) { | ||||
| 	defer func() { | ||||
| 		if err != nil { | ||||
| 			Println(err) | ||||
| 			c.Stop() | ||||
| 		} | ||||
| 	}() | ||||
| 	host := c.AConn.RemoteAddr().String() | ||||
| 	host = host[:strings.LastIndex(host, ":")] | ||||
| 	addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, c.APort)) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	c.AConn, err = net.DialUDP("udp", nil, addr) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	networkBuffer := 1048576 | ||||
| 	if err := c.AConn.SetReadBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp client audio conn set read buffer error, %v", err) | ||||
| 	} | ||||
| 	if err := c.AConn.SetWriteBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp client audio conn set write buffer error, %v", err) | ||||
| 	} | ||||
|  | ||||
| 	addr, err = net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, c.AControlPort)) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	c.AControlConn, err = net.DialUDP("udp", nil, addr) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	if err := c.AControlConn.SetReadBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp client audio control conn set read buffer error, %v", err) | ||||
| 	} | ||||
| 	if err := c.AControlConn.SetWriteBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp client audio control conn set write buffer error, %v", err) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c *UDPClient) SetupVideo() (err error) { | ||||
| 	defer func() { | ||||
| 		if err != nil { | ||||
| 			Println(err) | ||||
| 			c.Stop() | ||||
| 		} | ||||
| 	}() | ||||
| 	host := c.VConn.RemoteAddr().String() | ||||
| 	host = host[:strings.LastIndex(host, ":")] | ||||
| 	addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, c.VPort)) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	c.VConn, err = net.DialUDP("udp", nil, addr) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	networkBuffer := 1048576 | ||||
| 	if err := c.VConn.SetReadBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp client video conn set read buffer error, %v", err) | ||||
| 	} | ||||
| 	if err := c.VConn.SetWriteBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp client video conn set write buffer error, %v", err) | ||||
| 	} | ||||
|  | ||||
| 	addr, err = net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, c.VControlPort)) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	c.VControlConn, err = net.DialUDP("udp", nil, addr) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	if err := c.VControlConn.SetReadBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp client video control conn set read buffer error, %v", err) | ||||
| 	} | ||||
| 	if err := c.VControlConn.SetWriteBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp client video control conn set write buffer error, %v", err) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c *UDPClient) SendRTP(pack *RTPPack) (err error) { | ||||
| 	if pack == nil { | ||||
| 		err = fmt.Errorf("udp client send rtp got nil pack") | ||||
| 		return | ||||
| 	} | ||||
| 	var conn *net.UDPConn | ||||
| 	switch pack.Type { | ||||
| 	case RTP_TYPE_AUDIO: | ||||
| 		conn = c.AConn | ||||
| 	case RTP_TYPE_AUDIOCONTROL: | ||||
| 		conn = c.AControlConn | ||||
| 	case RTP_TYPE_VIDEO: | ||||
| 		conn = c.VConn | ||||
| 	case RTP_TYPE_VIDEOCONTROL: | ||||
| 		conn = c.VControlConn | ||||
| 	default: | ||||
| 		err = fmt.Errorf("udp client send rtp got unkown pack type[%v]", pack.Type) | ||||
| 		return | ||||
| 	} | ||||
| 	if conn == nil { | ||||
| 		err = fmt.Errorf("udp client send rtp pack type[%v] failed, conn not found", pack.Type) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	if _, err = conn.Write(pack.Buffer);err != nil { | ||||
| 		err = fmt.Errorf("udp client write bytes error, %v", err) | ||||
| 		return | ||||
| 	} | ||||
| 	// Printf("udp client write [%d/%d]", n, pack.Buffer.Len()) | ||||
| 	return | ||||
| } | ||||
							
								
								
									
										242
									
								
								udp-server.go
									
									
									
									
									
								
							
							
						
						
									
										242
									
								
								udp-server.go
									
									
									
									
									
								
							| @@ -1,242 +0,0 @@ | ||||
| package rtsp | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"net" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
| 	"time" | ||||
|  | ||||
| 	. "github.com/Monibuca/engine/v2" | ||||
| ) | ||||
|  | ||||
| type UDPServer struct { | ||||
| 	Session    *RTSP | ||||
| 	UDPClient | ||||
| 	sync.Mutex | ||||
| } | ||||
|  | ||||
| func (s *UDPServer) AddInputBytes(bytes int) { | ||||
| 	if s.Session != nil { | ||||
| 		s.Session.InBytes += bytes | ||||
| 		return | ||||
| 	} | ||||
| 	panic(fmt.Errorf("session and RTSPClient both nil")) | ||||
| } | ||||
|  | ||||
| func (s *UDPServer) HandleRTP(pack *RTPPack) { | ||||
| 	s.Lock() | ||||
| 	defer s.Unlock() | ||||
| 	if s.Session != nil { | ||||
| 		s.Session.handleRTP(pack) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (s *UDPServer) Stop() { | ||||
| 	if s.Stoped { | ||||
| 		return | ||||
| 	} | ||||
| 	s.Stoped = true | ||||
| 	if s.AConn != nil { | ||||
| 		s.AConn.Close() | ||||
| 		s.AConn = nil | ||||
| 	} | ||||
| 	if s.AControlConn != nil { | ||||
| 		s.AControlConn.Close() | ||||
| 		s.AControlConn = nil | ||||
| 	} | ||||
| 	if s.VConn != nil { | ||||
| 		s.VConn.Close() | ||||
| 		s.VConn = nil | ||||
| 	} | ||||
| 	if s.VControlConn != nil { | ||||
| 		s.VControlConn.Close() | ||||
| 		s.VControlConn = nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (s *UDPServer) SetupAudio() (err error) { | ||||
| 	addr, err := net.ResolveUDPAddr("udp", ":0") | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	s.AConn, err = net.ListenUDP("udp", addr) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	networkBuffer := 1048576 | ||||
| 	if err := s.AConn.SetReadBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp server audio conn set read buffer error, %v", err) | ||||
| 	} | ||||
| 	if err := s.AConn.SetWriteBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp server audio conn set write buffer error, %v", err) | ||||
| 	} | ||||
| 	la := s.AConn.LocalAddr().String() | ||||
| 	strPort := la[strings.LastIndex(la, ":")+1:] | ||||
| 	s.APort, err = strconv.Atoi(strPort) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	go func() { | ||||
| 		bufUDP := make([]byte, UDP_BUF_SIZE) | ||||
| 		Printf("udp server start listen audio port[%d]", s.APort) | ||||
| 		defer Printf("udp server stop listen audio port[%d]", s.APort) | ||||
| 		timer := time.Unix(0, 0) | ||||
| 		for !s.Stoped { | ||||
| 			if n, _, err := s.AConn.ReadFromUDP(bufUDP); err == nil { | ||||
| 				elapsed := time.Now().Sub(timer) | ||||
| 				if elapsed >= 30*time.Second { | ||||
| 					Printf("Package recv from AConn.len:%d\n", n) | ||||
| 					timer = time.Now() | ||||
| 				} | ||||
| 				rtpBytes := make([]byte, n) | ||||
| 				s.AddInputBytes(n) | ||||
| 				copy(rtpBytes, bufUDP) | ||||
| 				pack := &RTPPack{ | ||||
| 					Type:   RTP_TYPE_AUDIO, | ||||
| 					Buffer: rtpBytes, | ||||
| 				} | ||||
| 				s.HandleRTP(pack) | ||||
| 			} else { | ||||
| 				Println("udp server read audio pack error", err) | ||||
| 				continue | ||||
| 			} | ||||
| 		} | ||||
| 	}() | ||||
| 	addr, err = net.ResolveUDPAddr("udp", ":0") | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	s.AControlConn, err = net.ListenUDP("udp", addr) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	if err := s.AControlConn.SetReadBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp server audio control conn set read buffer error, %v", err) | ||||
| 	} | ||||
| 	if err := s.AControlConn.SetWriteBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp server audio control conn set write buffer error, %v", err) | ||||
| 	} | ||||
| 	la = s.AControlConn.LocalAddr().String() | ||||
| 	strPort = la[strings.LastIndex(la, ":")+1:] | ||||
| 	s.AControlPort, err = strconv.Atoi(strPort) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	go func() { | ||||
| 		bufUDP := make([]byte, UDP_BUF_SIZE) | ||||
| 		Printf("udp server start listen audio control port[%d]", s.AControlPort) | ||||
| 		defer Printf("udp server stop listen audio control port[%d]", s.AControlPort) | ||||
| 		for !s.Stoped { | ||||
| 			if n, _, err := s.AControlConn.ReadFromUDP(bufUDP); err == nil { | ||||
| 				//Printf("Package recv from AControlConn.len:%d\n", n) | ||||
| 				rtpBytes := make([]byte, n) | ||||
| 				s.AddInputBytes(n) | ||||
| 				copy(rtpBytes, bufUDP) | ||||
| 				pack := &RTPPack{ | ||||
| 					Type:   RTP_TYPE_AUDIOCONTROL, | ||||
| 					Buffer: rtpBytes, | ||||
| 				} | ||||
| 				s.HandleRTP(pack) | ||||
| 			} else { | ||||
| 				Println("udp server read audio control pack error", err) | ||||
| 				continue | ||||
| 			} | ||||
| 		} | ||||
| 	}() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (s *UDPServer) SetupVideo() (err error) { | ||||
| 	addr, err := net.ResolveUDPAddr("udp", ":0") | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	s.VConn, err = net.ListenUDP("udp", addr) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	networkBuffer := 1048576 | ||||
| 	if err := s.VConn.SetReadBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp server video conn set read buffer error, %v", err) | ||||
| 	} | ||||
| 	if err := s.VConn.SetWriteBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp server video conn set write buffer error, %v", err) | ||||
| 	} | ||||
| 	la := s.VConn.LocalAddr().String() | ||||
| 	strPort := la[strings.LastIndex(la, ":")+1:] | ||||
| 	s.VPort, err = strconv.Atoi(strPort) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	go func() { | ||||
| 		bufUDP := make([]byte, UDP_BUF_SIZE) | ||||
| 		Printf("udp server start listen video port[%d]", s.VPort) | ||||
| 		defer Printf("udp server stop listen video port[%d]", s.VPort) | ||||
| 		timer := time.Unix(0, 0) | ||||
| 		for !s.Stoped { | ||||
| 			if n, _, err := s.VConn.ReadFromUDP(bufUDP); err == nil { | ||||
| 				elapsed := time.Now().Sub(timer) | ||||
| 				if elapsed >= 30*time.Second { | ||||
| 					Printf("Package recv from VConn.len:%d\n", n) | ||||
| 					timer = time.Now() | ||||
| 				} | ||||
| 				rtpBytes := make([]byte, n) | ||||
| 				s.AddInputBytes(n) | ||||
| 				copy(rtpBytes, bufUDP) | ||||
| 				pack := &RTPPack{ | ||||
| 					Type:   RTP_TYPE_VIDEO, | ||||
| 					Buffer: rtpBytes, | ||||
| 				} | ||||
| 				s.HandleRTP(pack) | ||||
| 			} else { | ||||
| 				Println("udp server read video pack error", err) | ||||
| 				continue | ||||
| 			} | ||||
| 		} | ||||
| 	}() | ||||
|  | ||||
| 	addr, err = net.ResolveUDPAddr("udp", ":0") | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	s.VControlConn, err = net.ListenUDP("udp", addr) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	if err := s.VControlConn.SetReadBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp server video control conn set read buffer error, %v", err) | ||||
| 	} | ||||
| 	if err := s.VControlConn.SetWriteBuffer(networkBuffer); err != nil { | ||||
| 		Printf("udp server video control conn set write buffer error, %v", err) | ||||
| 	} | ||||
| 	la = s.VControlConn.LocalAddr().String() | ||||
| 	strPort = la[strings.LastIndex(la, ":")+1:] | ||||
| 	s.VControlPort, err = strconv.Atoi(strPort) | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	go func() { | ||||
| 		bufUDP := make([]byte, UDP_BUF_SIZE) | ||||
| 		Printf("udp server start listen video control port[%d]", s.VControlPort) | ||||
| 		defer Printf("udp server stop listen video control port[%d]", s.VControlPort) | ||||
| 		for !s.Stoped { | ||||
| 			if n, _, err := s.VControlConn.ReadFromUDP(bufUDP); err == nil { | ||||
| 				//Printf("Package recv from VControlConn.len:%d\n", n) | ||||
| 				rtpBytes := make([]byte, n) | ||||
| 				s.AddInputBytes(n) | ||||
| 				copy(rtpBytes, bufUDP) | ||||
| 				pack := &RTPPack{ | ||||
| 					Type:   RTP_TYPE_VIDEOCONTROL, | ||||
| 					Buffer: rtpBytes, | ||||
| 				} | ||||
| 				s.HandleRTP(pack) | ||||
| 			} else { | ||||
| 				Println("udp server read video control pack error", err) | ||||
| 				continue | ||||
| 			} | ||||
| 		} | ||||
| 	}() | ||||
| 	return | ||||
| } | ||||
							
								
								
									
										19
									
								
								ui/dist/demo.html
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										19
									
								
								ui/dist/demo.html
									
									
									
									
										vendored
									
									
								
							| @@ -1,19 +0,0 @@ | ||||
| <meta charset="utf-8"> | ||||
| <title>plugin-rtsp demo</title> | ||||
| <script src="https://unpkg.com/vue"></script> | ||||
| <script src="./plugin-rtsp.umd.js"></script> | ||||
|  | ||||
| <link rel="stylesheet" href="./plugin-rtsp.css"> | ||||
|  | ||||
|  | ||||
| <div id="app"> | ||||
|   <demo></demo> | ||||
| </div> | ||||
|  | ||||
| <script> | ||||
| new Vue({ | ||||
|   components: { | ||||
|     demo: plugin-rtsp | ||||
|   } | ||||
| }).$mount('#app') | ||||
| </script> | ||||
							
								
								
									
										437
									
								
								ui/dist/plugin-rtsp.common.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										437
									
								
								ui/dist/plugin-rtsp.common.js
									
									
									
									
										vendored
									
									
								
							| @@ -1,437 +0,0 @@ | ||||
| module.exports = | ||||
| /******/ (function(modules) { // webpackBootstrap | ||||
| /******/ 	// The module cache | ||||
| /******/ 	var installedModules = {}; | ||||
| /******/ | ||||
| /******/ 	// The require function | ||||
| /******/ 	function __webpack_require__(moduleId) { | ||||
| /******/ | ||||
| /******/ 		// Check if module is in cache | ||||
| /******/ 		if(installedModules[moduleId]) { | ||||
| /******/ 			return installedModules[moduleId].exports; | ||||
| /******/ 		} | ||||
| /******/ 		// Create a new module (and put it into the cache) | ||||
| /******/ 		var module = installedModules[moduleId] = { | ||||
| /******/ 			i: moduleId, | ||||
| /******/ 			l: false, | ||||
| /******/ 			exports: {} | ||||
| /******/ 		}; | ||||
| /******/ | ||||
| /******/ 		// Execute the module function | ||||
| /******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||||
| /******/ | ||||
| /******/ 		// Flag the module as loaded | ||||
| /******/ 		module.l = true; | ||||
| /******/ | ||||
| /******/ 		// Return the exports of the module | ||||
| /******/ 		return module.exports; | ||||
| /******/ 	} | ||||
| /******/ | ||||
| /******/ | ||||
| /******/ 	// expose the modules object (__webpack_modules__) | ||||
| /******/ 	__webpack_require__.m = modules; | ||||
| /******/ | ||||
| /******/ 	// expose the module cache | ||||
| /******/ 	__webpack_require__.c = installedModules; | ||||
| /******/ | ||||
| /******/ 	// define getter function for harmony exports | ||||
| /******/ 	__webpack_require__.d = function(exports, name, getter) { | ||||
| /******/ 		if(!__webpack_require__.o(exports, name)) { | ||||
| /******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter }); | ||||
| /******/ 		} | ||||
| /******/ 	}; | ||||
| /******/ | ||||
| /******/ 	// define __esModule on exports | ||||
| /******/ 	__webpack_require__.r = function(exports) { | ||||
| /******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||||
| /******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||||
| /******/ 		} | ||||
| /******/ 		Object.defineProperty(exports, '__esModule', { value: true }); | ||||
| /******/ 	}; | ||||
| /******/ | ||||
| /******/ 	// create a fake namespace object | ||||
| /******/ 	// mode & 1: value is a module id, require it | ||||
| /******/ 	// mode & 2: merge all properties of value into the ns | ||||
| /******/ 	// mode & 4: return value when already ns object | ||||
| /******/ 	// mode & 8|1: behave like require | ||||
| /******/ 	__webpack_require__.t = function(value, mode) { | ||||
| /******/ 		if(mode & 1) value = __webpack_require__(value); | ||||
| /******/ 		if(mode & 8) return value; | ||||
| /******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | ||||
| /******/ 		var ns = Object.create(null); | ||||
| /******/ 		__webpack_require__.r(ns); | ||||
| /******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | ||||
| /******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | ||||
| /******/ 		return ns; | ||||
| /******/ 	}; | ||||
| /******/ | ||||
| /******/ 	// getDefaultExport function for compatibility with non-harmony modules | ||||
| /******/ 	__webpack_require__.n = function(module) { | ||||
| /******/ 		var getter = module && module.__esModule ? | ||||
| /******/ 			function getDefault() { return module['default']; } : | ||||
| /******/ 			function getModuleExports() { return module; }; | ||||
| /******/ 		__webpack_require__.d(getter, 'a', getter); | ||||
| /******/ 		return getter; | ||||
| /******/ 	}; | ||||
| /******/ | ||||
| /******/ 	// Object.prototype.hasOwnProperty.call | ||||
| /******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||||
| /******/ | ||||
| /******/ 	// __webpack_public_path__ | ||||
| /******/ 	__webpack_require__.p = ""; | ||||
| /******/ | ||||
| /******/ | ||||
| /******/ 	// Load entry module and return exports | ||||
| /******/ 	return __webpack_require__(__webpack_require__.s = "fb15"); | ||||
| /******/ }) | ||||
| /************************************************************************/ | ||||
| /******/ ({ | ||||
|  | ||||
| /***/ "034f": | ||||
| /***/ (function(module, __webpack_exports__, __webpack_require__) { | ||||
|  | ||||
| "use strict"; | ||||
| /* harmony import */ var _node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("85ec"); | ||||
| /* harmony import */ var _node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__); | ||||
| /* unused harmony reexport * */ | ||||
|  /* unused harmony default export */ var _unused_webpack_default_export = (_node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0___default.a);  | ||||
|  | ||||
| /***/ }), | ||||
|  | ||||
| /***/ "85ec": | ||||
| /***/ (function(module, exports, __webpack_require__) { | ||||
|  | ||||
| // extracted by mini-css-extract-plugin | ||||
|  | ||||
| /***/ }), | ||||
|  | ||||
| /***/ "f6fd": | ||||
| /***/ (function(module, exports) { | ||||
|  | ||||
| // document.currentScript polyfill by Adam Miller | ||||
|  | ||||
| // MIT license | ||||
|  | ||||
| (function(document){ | ||||
|   var currentScript = "currentScript", | ||||
|       scripts = document.getElementsByTagName('script'); // Live NodeList collection | ||||
|  | ||||
|   // If browser needs currentScript polyfill, add get currentScript() to the document object | ||||
|   if (!(currentScript in document)) { | ||||
|     Object.defineProperty(document, currentScript, { | ||||
|       get: function(){ | ||||
|  | ||||
|         // IE 6-10 supports script readyState | ||||
|         // IE 10+ support stack trace | ||||
|         try { throw new Error(); } | ||||
|         catch (err) { | ||||
|  | ||||
|           // Find the second match for the "at" string to get file src url from stack. | ||||
|           // Specifically works with the format of stack traces in IE. | ||||
|           var i, res = ((/.*at [^\(]*\((.*):.+:.+\)$/ig).exec(err.stack) || [false])[1]; | ||||
|  | ||||
|           // For all scripts on the page, if src matches or if ready state is interactive, return the script tag | ||||
|           for(i in scripts){ | ||||
|             if(scripts[i].src == res || scripts[i].readyState == "interactive"){ | ||||
|               return scripts[i]; | ||||
|             } | ||||
|           } | ||||
|  | ||||
|           // If no match, return null | ||||
|           return null; | ||||
|         } | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| })(document); | ||||
|  | ||||
|  | ||||
| /***/ }), | ||||
|  | ||||
| /***/ "fb15": | ||||
| /***/ (function(module, __webpack_exports__, __webpack_require__) { | ||||
|  | ||||
| "use strict"; | ||||
| // ESM COMPAT FLAG | ||||
| __webpack_require__.r(__webpack_exports__); | ||||
|  | ||||
| // CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js | ||||
| // This file is imported into lib/wc client bundles. | ||||
|  | ||||
| if (typeof window !== 'undefined') { | ||||
|   if (true) { | ||||
|     __webpack_require__("f6fd") | ||||
|   } | ||||
|  | ||||
|   var i | ||||
|   if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))) { | ||||
|     __webpack_require__.p = i[1] // eslint-disable-line | ||||
|   } | ||||
| } | ||||
|  | ||||
| // Indicate to webpack that this file can be concatenated | ||||
| /* harmony default export */ var setPublicPath = (null); | ||||
|  | ||||
| // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"29918b3a-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=template&id=de44c72c& | ||||
| var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_c('mu-data-table',{attrs:{"data":_vm.Streams,"columns":_vm.columns},scopedSlots:_vm._u([{key:"default",fn:function(ref){ | ||||
| var item = ref.row; | ||||
| return [_c('td',[_vm._v(_vm._s(item.StreamInfo.StreamPath))]),_c('td',[_c('StartTime',{attrs:{"value":item.StreamInfo.StartTime}})],1),_c('td',[_vm._v(_vm._s(_vm.unitFormat(item.InBytes)))]),_c('td',[_vm._v(_vm._s(_vm.unitFormat(item.OutBytes)))]),_c('td',[_c('mu-button',{attrs:{"flat":""},on:{"click":function($event){return _vm.showHeader(item)}}},[_vm._v("头信息")]),_c('mu-button',{attrs:{"flat":""},on:{"click":function($event){return _vm.stop(item)}}},[_vm._v("中止")])],1)]}}])}),_c('mu-dialog',{attrs:{"title":"拉流转发","width":"360","open":_vm.openPull},on:{"update:open":function($event){_vm.openPull=$event}}},[_c('mu-text-field',{attrs:{"label":"rtsp url","label-float":"","help-text":"Please enter URL of rtsp..."},model:{value:(_vm.remoteAddr),callback:function ($$v) {_vm.remoteAddr=$$v},expression:"remoteAddr"}}),_c('mu-text-field',{attrs:{"label":"streamPath","label-float":"","help-text":"Please enter streamPath to publish."},model:{value:(_vm.streamPath),callback:function ($$v) {_vm.streamPath=$$v},expression:"streamPath"}}),_c('mu-button',{attrs:{"slot":"actions","flat":"","color":"primary"},on:{"click":_vm.addPull},slot:"actions"},[_vm._v("确定")])],1)],1)} | ||||
| var staticRenderFns = [] | ||||
|  | ||||
|  | ||||
| // CONCATENATED MODULE: ./src/App.vue?vue&type=template&id=de44c72c& | ||||
|  | ||||
| // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js& | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
|  | ||||
| let listES = null; | ||||
| /* harmony default export */ var Appvue_type_script_lang_js_ = ({ | ||||
|   data() { | ||||
|     return { | ||||
|       currentStream: null, | ||||
|       Streams: null, | ||||
|       remoteAddr: "", | ||||
|       streamPath: "", | ||||
|       openPull: false, | ||||
|       columns: [ | ||||
|         "StreamPath", | ||||
|         "开始时间", | ||||
|         "总接收", | ||||
|         "总发送", | ||||
|         "操作" | ||||
|       ].map(title => ({ title })) | ||||
|     }; | ||||
|   }, | ||||
|  | ||||
|   methods: { | ||||
|     fetchlist() { | ||||
|       listES = new EventSource(this.apiHost + "/rtsp/list"); | ||||
|       listES.onmessage = evt => { | ||||
|         if (!evt.data) return; | ||||
|         this.Streams = JSON.parse(evt.data) || []; | ||||
|         this.Streams.sort((a, b) => | ||||
|           a.StreamInfo.StreamPath > b.StreamInfo.StreamPath ? 1 : -1 | ||||
|         ); | ||||
|       }; | ||||
|     }, | ||||
|     showHeader(item) { | ||||
|       this.$Modal.info({ | ||||
|         title: "RTSP SDPRaw", | ||||
|         width: "1000px", | ||||
|         scrollable: true, | ||||
|         content: item.SDPRaw | ||||
|       }); | ||||
|     }, | ||||
|     addPull() { | ||||
|       this.openPull = false; | ||||
|       this.ajax | ||||
|         .getJSON(this.apiHost + "/rtsp/pull", { | ||||
|           target: this.remoteAddr, | ||||
|           streamPath: this.streamPath | ||||
|         }) | ||||
|         .then(x => { | ||||
|           if (x.code == 0) { | ||||
|             this.$toast.success("已启动拉流"); | ||||
|           } else { | ||||
|             this.$toast.error(x.msg); | ||||
|           } | ||||
|         }); | ||||
|     }, | ||||
|     stop(item) { | ||||
|       this.ajax | ||||
|         .get(this.apiHost + "/api/stop", { | ||||
|           stream: item.StreamInfo.StreamPath | ||||
|         }) | ||||
|         .then(x => { | ||||
|           if (x == "success") { | ||||
|             this.$toast.success("已停止拉流"); | ||||
|           } else { | ||||
|             this.$toast.error(x.msg); | ||||
|           } | ||||
|         }); | ||||
|     } | ||||
|   }, | ||||
|   mounted() { | ||||
|     this.fetchlist(); | ||||
|     let _this = this; | ||||
|     this.$parent.titleOps = [ | ||||
|       { | ||||
|         template: '<m-button @click="onClick">拉流转发</m-button>', | ||||
|         methods: { | ||||
|           onClick() { | ||||
|             _this.openPull = true; | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|     ]; | ||||
|   }, | ||||
|   destroyed() { | ||||
|     listES.close(); | ||||
|   } | ||||
| }); | ||||
|  | ||||
| // CONCATENATED MODULE: ./src/App.vue?vue&type=script&lang=js& | ||||
|  /* harmony default export */ var src_Appvue_type_script_lang_js_ = (Appvue_type_script_lang_js_);  | ||||
| // EXTERNAL MODULE: ./src/App.vue?vue&type=style&index=0&lang=css& | ||||
| var Appvue_type_style_index_0_lang_css_ = __webpack_require__("034f"); | ||||
|  | ||||
| // CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js | ||||
| /* globals __VUE_SSR_CONTEXT__ */ | ||||
|  | ||||
| // IMPORTANT: Do NOT use ES2015 features in this file (except for modules). | ||||
| // This module is a runtime utility for cleaner component module output and will | ||||
| // be included in the final webpack user bundle. | ||||
|  | ||||
| function normalizeComponent ( | ||||
|   scriptExports, | ||||
|   render, | ||||
|   staticRenderFns, | ||||
|   functionalTemplate, | ||||
|   injectStyles, | ||||
|   scopeId, | ||||
|   moduleIdentifier, /* server only */ | ||||
|   shadowMode /* vue-cli only */ | ||||
| ) { | ||||
|   // Vue.extend constructor export interop | ||||
|   var options = typeof scriptExports === 'function' | ||||
|     ? scriptExports.options | ||||
|     : scriptExports | ||||
|  | ||||
|   // render functions | ||||
|   if (render) { | ||||
|     options.render = render | ||||
|     options.staticRenderFns = staticRenderFns | ||||
|     options._compiled = true | ||||
|   } | ||||
|  | ||||
|   // functional template | ||||
|   if (functionalTemplate) { | ||||
|     options.functional = true | ||||
|   } | ||||
|  | ||||
|   // scopedId | ||||
|   if (scopeId) { | ||||
|     options._scopeId = 'data-v-' + scopeId | ||||
|   } | ||||
|  | ||||
|   var hook | ||||
|   if (moduleIdentifier) { // server build | ||||
|     hook = function (context) { | ||||
|       // 2.3 injection | ||||
|       context = | ||||
|         context || // cached call | ||||
|         (this.$vnode && this.$vnode.ssrContext) || // stateful | ||||
|         (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional | ||||
|       // 2.2 with runInNewContext: true | ||||
|       if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') { | ||||
|         context = __VUE_SSR_CONTEXT__ | ||||
|       } | ||||
|       // inject component styles | ||||
|       if (injectStyles) { | ||||
|         injectStyles.call(this, context) | ||||
|       } | ||||
|       // register component module identifier for async chunk inferrence | ||||
|       if (context && context._registeredComponents) { | ||||
|         context._registeredComponents.add(moduleIdentifier) | ||||
|       } | ||||
|     } | ||||
|     // used by ssr in case component is cached and beforeCreate | ||||
|     // never gets called | ||||
|     options._ssrRegister = hook | ||||
|   } else if (injectStyles) { | ||||
|     hook = shadowMode | ||||
|       ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) } | ||||
|       : injectStyles | ||||
|   } | ||||
|  | ||||
|   if (hook) { | ||||
|     if (options.functional) { | ||||
|       // for template-only hot-reload because in that case the render fn doesn't | ||||
|       // go through the normalizer | ||||
|       options._injectStyles = hook | ||||
|       // register for functional component in vue file | ||||
|       var originalRender = options.render | ||||
|       options.render = function renderWithStyleInjection (h, context) { | ||||
|         hook.call(context) | ||||
|         return originalRender(h, context) | ||||
|       } | ||||
|     } else { | ||||
|       // inject component registration as beforeCreate hook | ||||
|       var existing = options.beforeCreate | ||||
|       options.beforeCreate = existing | ||||
|         ? [].concat(existing, hook) | ||||
|         : [hook] | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   return { | ||||
|     exports: scriptExports, | ||||
|     options: options | ||||
|   } | ||||
| } | ||||
|  | ||||
| // CONCATENATED MODULE: ./src/App.vue | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| /* normalize component */ | ||||
|  | ||||
| var component = normalizeComponent( | ||||
|   src_Appvue_type_script_lang_js_, | ||||
|   render, | ||||
|   staticRenderFns, | ||||
|   false, | ||||
|   null, | ||||
|   null, | ||||
|   null | ||||
|    | ||||
| ) | ||||
|  | ||||
| /* harmony default export */ var App = (component.exports); | ||||
| // CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib.js | ||||
|  | ||||
|  | ||||
| /* harmony default export */ var entry_lib = __webpack_exports__["default"] = (App); | ||||
|  | ||||
|  | ||||
|  | ||||
| /***/ }) | ||||
|  | ||||
| /******/ })["default"]; | ||||
| //# sourceMappingURL=plugin-rtsp.common.js.map | ||||
							
								
								
									
										1
									
								
								ui/dist/plugin-rtsp.common.js.map
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								ui/dist/plugin-rtsp.common.js.map
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										1
									
								
								ui/dist/plugin-rtsp.css
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								ui/dist/plugin-rtsp.css
									
									
									
									
										vendored
									
									
								
							| @@ -1 +0,0 @@ | ||||
| .empty{color:#eb5e46;width:100%;min-height:500px;display:flex;justify-content:center;align-items:center}.layout{padding-bottom:30px;display:flex;flex-wrap:wrap}.ts-info{width:300px}.hls-info{width:350px;display:flex;flex-direction:column} | ||||
							
								
								
									
										447
									
								
								ui/dist/plugin-rtsp.umd.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										447
									
								
								ui/dist/plugin-rtsp.umd.js
									
									
									
									
										vendored
									
									
								
							| @@ -1,447 +0,0 @@ | ||||
| (function webpackUniversalModuleDefinition(root, factory) { | ||||
| 	if(typeof exports === 'object' && typeof module === 'object') | ||||
| 		module.exports = factory(); | ||||
| 	else if(typeof define === 'function' && define.amd) | ||||
| 		define([], factory); | ||||
| 	else if(typeof exports === 'object') | ||||
| 		exports["plugin-rtsp"] = factory(); | ||||
| 	else | ||||
| 		root["plugin-rtsp"] = factory(); | ||||
| })((typeof self !== 'undefined' ? self : this), function() { | ||||
| return /******/ (function(modules) { // webpackBootstrap | ||||
| /******/ 	// The module cache | ||||
| /******/ 	var installedModules = {}; | ||||
| /******/ | ||||
| /******/ 	// The require function | ||||
| /******/ 	function __webpack_require__(moduleId) { | ||||
| /******/ | ||||
| /******/ 		// Check if module is in cache | ||||
| /******/ 		if(installedModules[moduleId]) { | ||||
| /******/ 			return installedModules[moduleId].exports; | ||||
| /******/ 		} | ||||
| /******/ 		// Create a new module (and put it into the cache) | ||||
| /******/ 		var module = installedModules[moduleId] = { | ||||
| /******/ 			i: moduleId, | ||||
| /******/ 			l: false, | ||||
| /******/ 			exports: {} | ||||
| /******/ 		}; | ||||
| /******/ | ||||
| /******/ 		// Execute the module function | ||||
| /******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); | ||||
| /******/ | ||||
| /******/ 		// Flag the module as loaded | ||||
| /******/ 		module.l = true; | ||||
| /******/ | ||||
| /******/ 		// Return the exports of the module | ||||
| /******/ 		return module.exports; | ||||
| /******/ 	} | ||||
| /******/ | ||||
| /******/ | ||||
| /******/ 	// expose the modules object (__webpack_modules__) | ||||
| /******/ 	__webpack_require__.m = modules; | ||||
| /******/ | ||||
| /******/ 	// expose the module cache | ||||
| /******/ 	__webpack_require__.c = installedModules; | ||||
| /******/ | ||||
| /******/ 	// define getter function for harmony exports | ||||
| /******/ 	__webpack_require__.d = function(exports, name, getter) { | ||||
| /******/ 		if(!__webpack_require__.o(exports, name)) { | ||||
| /******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter }); | ||||
| /******/ 		} | ||||
| /******/ 	}; | ||||
| /******/ | ||||
| /******/ 	// define __esModule on exports | ||||
| /******/ 	__webpack_require__.r = function(exports) { | ||||
| /******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||||
| /******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||||
| /******/ 		} | ||||
| /******/ 		Object.defineProperty(exports, '__esModule', { value: true }); | ||||
| /******/ 	}; | ||||
| /******/ | ||||
| /******/ 	// create a fake namespace object | ||||
| /******/ 	// mode & 1: value is a module id, require it | ||||
| /******/ 	// mode & 2: merge all properties of value into the ns | ||||
| /******/ 	// mode & 4: return value when already ns object | ||||
| /******/ 	// mode & 8|1: behave like require | ||||
| /******/ 	__webpack_require__.t = function(value, mode) { | ||||
| /******/ 		if(mode & 1) value = __webpack_require__(value); | ||||
| /******/ 		if(mode & 8) return value; | ||||
| /******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; | ||||
| /******/ 		var ns = Object.create(null); | ||||
| /******/ 		__webpack_require__.r(ns); | ||||
| /******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value }); | ||||
| /******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); | ||||
| /******/ 		return ns; | ||||
| /******/ 	}; | ||||
| /******/ | ||||
| /******/ 	// getDefaultExport function for compatibility with non-harmony modules | ||||
| /******/ 	__webpack_require__.n = function(module) { | ||||
| /******/ 		var getter = module && module.__esModule ? | ||||
| /******/ 			function getDefault() { return module['default']; } : | ||||
| /******/ 			function getModuleExports() { return module; }; | ||||
| /******/ 		__webpack_require__.d(getter, 'a', getter); | ||||
| /******/ 		return getter; | ||||
| /******/ 	}; | ||||
| /******/ | ||||
| /******/ 	// Object.prototype.hasOwnProperty.call | ||||
| /******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; | ||||
| /******/ | ||||
| /******/ 	// __webpack_public_path__ | ||||
| /******/ 	__webpack_require__.p = ""; | ||||
| /******/ | ||||
| /******/ | ||||
| /******/ 	// Load entry module and return exports | ||||
| /******/ 	return __webpack_require__(__webpack_require__.s = "fb15"); | ||||
| /******/ }) | ||||
| /************************************************************************/ | ||||
| /******/ ({ | ||||
|  | ||||
| /***/ "034f": | ||||
| /***/ (function(module, __webpack_exports__, __webpack_require__) { | ||||
|  | ||||
| "use strict"; | ||||
| /* harmony import */ var _node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("85ec"); | ||||
| /* harmony import */ var _node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0__); | ||||
| /* unused harmony reexport * */ | ||||
|  /* unused harmony default export */ var _unused_webpack_default_export = (_node_modules_mini_css_extract_plugin_dist_loader_js_ref_6_oneOf_1_0_node_modules_css_loader_dist_cjs_js_ref_6_oneOf_1_1_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_src_index_js_ref_6_oneOf_1_2_node_modules_cache_loader_dist_cjs_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_style_index_0_lang_css___WEBPACK_IMPORTED_MODULE_0___default.a);  | ||||
|  | ||||
| /***/ }), | ||||
|  | ||||
| /***/ "85ec": | ||||
| /***/ (function(module, exports, __webpack_require__) { | ||||
|  | ||||
| // extracted by mini-css-extract-plugin | ||||
|  | ||||
| /***/ }), | ||||
|  | ||||
| /***/ "f6fd": | ||||
| /***/ (function(module, exports) { | ||||
|  | ||||
| // document.currentScript polyfill by Adam Miller | ||||
|  | ||||
| // MIT license | ||||
|  | ||||
| (function(document){ | ||||
|   var currentScript = "currentScript", | ||||
|       scripts = document.getElementsByTagName('script'); // Live NodeList collection | ||||
|  | ||||
|   // If browser needs currentScript polyfill, add get currentScript() to the document object | ||||
|   if (!(currentScript in document)) { | ||||
|     Object.defineProperty(document, currentScript, { | ||||
|       get: function(){ | ||||
|  | ||||
|         // IE 6-10 supports script readyState | ||||
|         // IE 10+ support stack trace | ||||
|         try { throw new Error(); } | ||||
|         catch (err) { | ||||
|  | ||||
|           // Find the second match for the "at" string to get file src url from stack. | ||||
|           // Specifically works with the format of stack traces in IE. | ||||
|           var i, res = ((/.*at [^\(]*\((.*):.+:.+\)$/ig).exec(err.stack) || [false])[1]; | ||||
|  | ||||
|           // For all scripts on the page, if src matches or if ready state is interactive, return the script tag | ||||
|           for(i in scripts){ | ||||
|             if(scripts[i].src == res || scripts[i].readyState == "interactive"){ | ||||
|               return scripts[i]; | ||||
|             } | ||||
|           } | ||||
|  | ||||
|           // If no match, return null | ||||
|           return null; | ||||
|         } | ||||
|       } | ||||
|     }); | ||||
|   } | ||||
| })(document); | ||||
|  | ||||
|  | ||||
| /***/ }), | ||||
|  | ||||
| /***/ "fb15": | ||||
| /***/ (function(module, __webpack_exports__, __webpack_require__) { | ||||
|  | ||||
| "use strict"; | ||||
| // ESM COMPAT FLAG | ||||
| __webpack_require__.r(__webpack_exports__); | ||||
|  | ||||
| // CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js | ||||
| // This file is imported into lib/wc client bundles. | ||||
|  | ||||
| if (typeof window !== 'undefined') { | ||||
|   if (true) { | ||||
|     __webpack_require__("f6fd") | ||||
|   } | ||||
|  | ||||
|   var i | ||||
|   if ((i = window.document.currentScript) && (i = i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))) { | ||||
|     __webpack_require__.p = i[1] // eslint-disable-line | ||||
|   } | ||||
| } | ||||
|  | ||||
| // Indicate to webpack that this file can be concatenated | ||||
| /* harmony default export */ var setPublicPath = (null); | ||||
|  | ||||
| // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"29918b3a-vue-loader-template"}!./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=template&id=de44c72c& | ||||
| var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_c('mu-data-table',{attrs:{"data":_vm.Streams,"columns":_vm.columns},scopedSlots:_vm._u([{key:"default",fn:function(ref){ | ||||
| var item = ref.row; | ||||
| return [_c('td',[_vm._v(_vm._s(item.StreamInfo.StreamPath))]),_c('td',[_c('StartTime',{attrs:{"value":item.StreamInfo.StartTime}})],1),_c('td',[_vm._v(_vm._s(_vm.unitFormat(item.InBytes)))]),_c('td',[_vm._v(_vm._s(_vm.unitFormat(item.OutBytes)))]),_c('td',[_c('mu-button',{attrs:{"flat":""},on:{"click":function($event){return _vm.showHeader(item)}}},[_vm._v("头信息")]),_c('mu-button',{attrs:{"flat":""},on:{"click":function($event){return _vm.stop(item)}}},[_vm._v("中止")])],1)]}}])}),_c('mu-dialog',{attrs:{"title":"拉流转发","width":"360","open":_vm.openPull},on:{"update:open":function($event){_vm.openPull=$event}}},[_c('mu-text-field',{attrs:{"label":"rtsp url","label-float":"","help-text":"Please enter URL of rtsp..."},model:{value:(_vm.remoteAddr),callback:function ($$v) {_vm.remoteAddr=$$v},expression:"remoteAddr"}}),_c('mu-text-field',{attrs:{"label":"streamPath","label-float":"","help-text":"Please enter streamPath to publish."},model:{value:(_vm.streamPath),callback:function ($$v) {_vm.streamPath=$$v},expression:"streamPath"}}),_c('mu-button',{attrs:{"slot":"actions","flat":"","color":"primary"},on:{"click":_vm.addPull},slot:"actions"},[_vm._v("确定")])],1)],1)} | ||||
| var staticRenderFns = [] | ||||
|  | ||||
|  | ||||
| // CONCATENATED MODULE: ./src/App.vue?vue&type=template&id=de44c72c& | ||||
|  | ||||
| // CONCATENATED MODULE: ./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=script&lang=js& | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
| // | ||||
|  | ||||
| let listES = null; | ||||
| /* harmony default export */ var Appvue_type_script_lang_js_ = ({ | ||||
|   data() { | ||||
|     return { | ||||
|       currentStream: null, | ||||
|       Streams: null, | ||||
|       remoteAddr: "", | ||||
|       streamPath: "", | ||||
|       openPull: false, | ||||
|       columns: [ | ||||
|         "StreamPath", | ||||
|         "开始时间", | ||||
|         "总接收", | ||||
|         "总发送", | ||||
|         "操作" | ||||
|       ].map(title => ({ title })) | ||||
|     }; | ||||
|   }, | ||||
|  | ||||
|   methods: { | ||||
|     fetchlist() { | ||||
|       listES = new EventSource(this.apiHost + "/rtsp/list"); | ||||
|       listES.onmessage = evt => { | ||||
|         if (!evt.data) return; | ||||
|         this.Streams = JSON.parse(evt.data) || []; | ||||
|         this.Streams.sort((a, b) => | ||||
|           a.StreamInfo.StreamPath > b.StreamInfo.StreamPath ? 1 : -1 | ||||
|         ); | ||||
|       }; | ||||
|     }, | ||||
|     showHeader(item) { | ||||
|       this.$Modal.info({ | ||||
|         title: "RTSP SDPRaw", | ||||
|         width: "1000px", | ||||
|         scrollable: true, | ||||
|         content: item.SDPRaw | ||||
|       }); | ||||
|     }, | ||||
|     addPull() { | ||||
|       this.openPull = false; | ||||
|       this.ajax | ||||
|         .getJSON(this.apiHost + "/rtsp/pull", { | ||||
|           target: this.remoteAddr, | ||||
|           streamPath: this.streamPath | ||||
|         }) | ||||
|         .then(x => { | ||||
|           if (x.code == 0) { | ||||
|             this.$toast.success("已启动拉流"); | ||||
|           } else { | ||||
|             this.$toast.error(x.msg); | ||||
|           } | ||||
|         }); | ||||
|     }, | ||||
|     stop(item) { | ||||
|       this.ajax | ||||
|         .get(this.apiHost + "/api/stop", { | ||||
|           stream: item.StreamInfo.StreamPath | ||||
|         }) | ||||
|         .then(x => { | ||||
|           if (x == "success") { | ||||
|             this.$toast.success("已停止拉流"); | ||||
|           } else { | ||||
|             this.$toast.error(x.msg); | ||||
|           } | ||||
|         }); | ||||
|     } | ||||
|   }, | ||||
|   mounted() { | ||||
|     this.fetchlist(); | ||||
|     let _this = this; | ||||
|     this.$parent.titleOps = [ | ||||
|       { | ||||
|         template: '<m-button @click="onClick">拉流转发</m-button>', | ||||
|         methods: { | ||||
|           onClick() { | ||||
|             _this.openPull = true; | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|     ]; | ||||
|   }, | ||||
|   destroyed() { | ||||
|     listES.close(); | ||||
|   } | ||||
| }); | ||||
|  | ||||
| // CONCATENATED MODULE: ./src/App.vue?vue&type=script&lang=js& | ||||
|  /* harmony default export */ var src_Appvue_type_script_lang_js_ = (Appvue_type_script_lang_js_);  | ||||
| // EXTERNAL MODULE: ./src/App.vue?vue&type=style&index=0&lang=css& | ||||
| var Appvue_type_style_index_0_lang_css_ = __webpack_require__("034f"); | ||||
|  | ||||
| // CONCATENATED MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js | ||||
| /* globals __VUE_SSR_CONTEXT__ */ | ||||
|  | ||||
| // IMPORTANT: Do NOT use ES2015 features in this file (except for modules). | ||||
| // This module is a runtime utility for cleaner component module output and will | ||||
| // be included in the final webpack user bundle. | ||||
|  | ||||
| function normalizeComponent ( | ||||
|   scriptExports, | ||||
|   render, | ||||
|   staticRenderFns, | ||||
|   functionalTemplate, | ||||
|   injectStyles, | ||||
|   scopeId, | ||||
|   moduleIdentifier, /* server only */ | ||||
|   shadowMode /* vue-cli only */ | ||||
| ) { | ||||
|   // Vue.extend constructor export interop | ||||
|   var options = typeof scriptExports === 'function' | ||||
|     ? scriptExports.options | ||||
|     : scriptExports | ||||
|  | ||||
|   // render functions | ||||
|   if (render) { | ||||
|     options.render = render | ||||
|     options.staticRenderFns = staticRenderFns | ||||
|     options._compiled = true | ||||
|   } | ||||
|  | ||||
|   // functional template | ||||
|   if (functionalTemplate) { | ||||
|     options.functional = true | ||||
|   } | ||||
|  | ||||
|   // scopedId | ||||
|   if (scopeId) { | ||||
|     options._scopeId = 'data-v-' + scopeId | ||||
|   } | ||||
|  | ||||
|   var hook | ||||
|   if (moduleIdentifier) { // server build | ||||
|     hook = function (context) { | ||||
|       // 2.3 injection | ||||
|       context = | ||||
|         context || // cached call | ||||
|         (this.$vnode && this.$vnode.ssrContext) || // stateful | ||||
|         (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional | ||||
|       // 2.2 with runInNewContext: true | ||||
|       if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') { | ||||
|         context = __VUE_SSR_CONTEXT__ | ||||
|       } | ||||
|       // inject component styles | ||||
|       if (injectStyles) { | ||||
|         injectStyles.call(this, context) | ||||
|       } | ||||
|       // register component module identifier for async chunk inferrence | ||||
|       if (context && context._registeredComponents) { | ||||
|         context._registeredComponents.add(moduleIdentifier) | ||||
|       } | ||||
|     } | ||||
|     // used by ssr in case component is cached and beforeCreate | ||||
|     // never gets called | ||||
|     options._ssrRegister = hook | ||||
|   } else if (injectStyles) { | ||||
|     hook = shadowMode | ||||
|       ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) } | ||||
|       : injectStyles | ||||
|   } | ||||
|  | ||||
|   if (hook) { | ||||
|     if (options.functional) { | ||||
|       // for template-only hot-reload because in that case the render fn doesn't | ||||
|       // go through the normalizer | ||||
|       options._injectStyles = hook | ||||
|       // register for functional component in vue file | ||||
|       var originalRender = options.render | ||||
|       options.render = function renderWithStyleInjection (h, context) { | ||||
|         hook.call(context) | ||||
|         return originalRender(h, context) | ||||
|       } | ||||
|     } else { | ||||
|       // inject component registration as beforeCreate hook | ||||
|       var existing = options.beforeCreate | ||||
|       options.beforeCreate = existing | ||||
|         ? [].concat(existing, hook) | ||||
|         : [hook] | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   return { | ||||
|     exports: scriptExports, | ||||
|     options: options | ||||
|   } | ||||
| } | ||||
|  | ||||
| // CONCATENATED MODULE: ./src/App.vue | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| /* normalize component */ | ||||
|  | ||||
| var component = normalizeComponent( | ||||
|   src_Appvue_type_script_lang_js_, | ||||
|   render, | ||||
|   staticRenderFns, | ||||
|   false, | ||||
|   null, | ||||
|   null, | ||||
|   null | ||||
|    | ||||
| ) | ||||
|  | ||||
| /* harmony default export */ var App = (component.exports); | ||||
| // CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib.js | ||||
|  | ||||
|  | ||||
| /* harmony default export */ var entry_lib = __webpack_exports__["default"] = (App); | ||||
|  | ||||
|  | ||||
|  | ||||
| /***/ }) | ||||
|  | ||||
| /******/ })["default"]; | ||||
| }); | ||||
| //# sourceMappingURL=plugin-rtsp.umd.js.map | ||||
							
								
								
									
										1
									
								
								ui/dist/plugin-rtsp.umd.js.map
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								ui/dist/plugin-rtsp.umd.js.map
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										2
									
								
								ui/dist/plugin-rtsp.umd.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								ui/dist/plugin-rtsp.umd.min.js
									
									
									
									
										vendored
									
									
								
							| @@ -1,2 +0,0 @@ | ||||
| (function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports["plugin-rtsp"]=e():t["plugin-rtsp"]=e()})("undefined"!==typeof self?self:this,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t["default"]}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s="fb15")}({"034f":function(t,e,r){"use strict";var n=r("85ec"),o=r.n(n);o.a},"85ec":function(t,e,r){},f6fd:function(t,e){(function(t){var e="currentScript",r=t.getElementsByTagName("script");e in t||Object.defineProperty(t,e,{get:function(){try{throw new Error}catch(n){var t,e=(/.*at [^\(]*\((.*):.+:.+\)$/gi.exec(n.stack)||[!1])[1];for(t in r)if(r[t].src==e||"interactive"==r[t].readyState)return r[t];return null}}})})(document)},fb15:function(t,e,r){"use strict";var n;(r.r(e),"undefined"!==typeof window)&&(r("f6fd"),(n=window.document.currentScript)&&(n=n.src.match(/(.+\/)[^/]+\.js(\?.*)?$/))&&(r.p=n[1]));var o=function(){var t=this,e=t.$createElement,r=t._self._c||e;return r("div",[r("mu-data-table",{attrs:{data:t.Streams,columns:t.columns},scopedSlots:t._u([{key:"default",fn:function(e){var n=e.row;return[r("td",[t._v(t._s(n.StreamInfo.StreamPath))]),r("td",[r("StartTime",{attrs:{value:n.StreamInfo.StartTime}})],1),r("td",[t._v(t._s(t.unitFormat(n.InBytes)))]),r("td",[t._v(t._s(t.unitFormat(n.OutBytes)))]),r("td",[r("mu-button",{attrs:{flat:""},on:{click:function(e){return t.showHeader(n)}}},[t._v("头信息")]),r("mu-button",{attrs:{flat:""},on:{click:function(e){return t.stop(n)}}},[t._v("中止")])],1)]}}])}),r("mu-dialog",{attrs:{title:"拉流转发",width:"360",open:t.openPull},on:{"update:open":function(e){t.openPull=e}}},[r("mu-text-field",{attrs:{label:"rtsp url","label-float":"","help-text":"Please enter URL of rtsp..."},model:{value:t.remoteAddr,callback:function(e){t.remoteAddr=e},expression:"remoteAddr"}}),r("mu-text-field",{attrs:{label:"streamPath","label-float":"","help-text":"Please enter streamPath to publish."},model:{value:t.streamPath,callback:function(e){t.streamPath=e},expression:"streamPath"}}),r("mu-button",{attrs:{slot:"actions",flat:"",color:"primary"},on:{click:t.addPull},slot:"actions"},[t._v("确定")])],1)],1)},a=[];let s=null;var i={data(){return{currentStream:null,Streams:null,remoteAddr:"",streamPath:"",openPull:!1,columns:["StreamPath","开始时间","总接收","总发送","操作"].map(t=>({title:t}))}},methods:{fetchlist(){s=new EventSource(this.apiHost+"/rtsp/list"),s.onmessage=t=>{t.data&&(this.Streams=JSON.parse(t.data)||[],this.Streams.sort((t,e)=>t.StreamInfo.StreamPath>e.StreamInfo.StreamPath?1:-1))}},showHeader(t){this.$Modal.info({title:"RTSP SDPRaw",width:"1000px",scrollable:!0,content:t.SDPRaw})},addPull(){this.openPull=!1,this.ajax.getJSON(this.apiHost+"/rtsp/pull",{target:this.remoteAddr,streamPath:this.streamPath}).then(t=>{0==t.code?this.$toast.success("已启动拉流"):this.$toast.error(t.msg)})},stop(t){this.ajax.get(this.apiHost+"/api/stop",{stream:t.StreamInfo.StreamPath}).then(t=>{"success"==t?this.$toast.success("已停止拉流"):this.$toast.error(t.msg)})}},mounted(){this.fetchlist();let t=this;this.$parent.titleOps=[{template:'<m-button @click="onClick">拉流转发</m-button>',methods:{onClick(){t.openPull=!0}}}]},destroyed(){s.close()}},l=i;r("034f");function u(t,e,r,n,o,a,s,i){var l,u="function"===typeof t?t.options:t;if(e&&(u.render=e,u.staticRenderFns=r,u._compiled=!0),n&&(u.functional=!0),a&&(u._scopeId="data-v-"+a),s?(l=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"===typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),o&&o.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},u._ssrRegister=l):o&&(l=i?function(){o.call(this,this.$root.$options.shadowRoot)}:o),l)if(u.functional){u._injectStyles=l;var c=u.render;u.render=function(t,e){return l.call(e),c(t,e)}}else{var f=u.beforeCreate;u.beforeCreate=f?[].concat(f,l):[l]}return{exports:t,options:u}}var c=u(l,o,a,!1,null,null,null),f=c.exports;e["default"]=f}})["default"]})); | ||||
| //# sourceMappingURL=plugin-rtsp.umd.min.js.map | ||||
							
								
								
									
										1
									
								
								ui/dist/plugin-rtsp.umd.min.js.map
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								ui/dist/plugin-rtsp.umd.min.js.map
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										9560
									
								
								ui/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										9560
									
								
								ui/package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -1,15 +0,0 @@ | ||||
| { | ||||
|   "name": "dashboard", | ||||
|   "version": "1.0.0", | ||||
|   "description": "dashboard of rtsp plugin for monibuca", | ||||
|   "main": "index.js", | ||||
|   "scripts": { | ||||
|     "build": "vue-cli-service build --target lib --name plugin-rtsp" | ||||
|   }, | ||||
|   "author": "dexter", | ||||
|   "license": "ISC", | ||||
|   "devDependencies": { | ||||
|     "@vue/cli-service": "^4.2.3", | ||||
|     "vue-template-compiler": "^2.6.11" | ||||
|   } | ||||
| } | ||||
							
								
								
									
										147
									
								
								ui/src/App.vue
									
									
									
									
									
								
							
							
						
						
									
										147
									
								
								ui/src/App.vue
									
									
									
									
									
								
							| @@ -1,147 +0,0 @@ | ||||
| <template> | ||||
|   <div> | ||||
|     <mu-data-table :data="Streams" :columns="columns"> | ||||
|       <template #default="{row:item}"> | ||||
|         <td>{{item.StreamInfo.StreamPath}}</td> | ||||
|         <td> | ||||
|           <StartTime :value="item.StreamInfo.StartTime"></StartTime> | ||||
|         </td> | ||||
|         <td>{{unitFormat(item.InBytes)}}</td> | ||||
|         <td>{{unitFormat(item.OutBytes)}}</td> | ||||
|         <td> | ||||
|           <mu-button flat @click="showHeader(item)">头信息</mu-button> | ||||
|           <mu-button flat @click="stop(item)">中止</mu-button> | ||||
|         </td> | ||||
|       </template> | ||||
|     </mu-data-table> | ||||
|     <mu-dialog title="拉流转发" width="360" :open.sync="openPull"> | ||||
|       <mu-text-field | ||||
|         v-model="remoteAddr" | ||||
|         label="rtsp url" | ||||
|         label-float | ||||
|         help-text="Please enter URL of rtsp..." | ||||
|       ></mu-text-field> | ||||
|       <mu-text-field | ||||
|         v-model="streamPath" | ||||
|         label="streamPath" | ||||
|         label-float | ||||
|         help-text="Please enter streamPath to publish." | ||||
|       ></mu-text-field> | ||||
|       <mu-button slot="actions" flat color="primary" @click="addPull">确定</mu-button> | ||||
|     </mu-dialog> | ||||
|   </div> | ||||
| </template> | ||||
|  | ||||
| <script> | ||||
| let listES = null; | ||||
| export default { | ||||
|   data() { | ||||
|     return { | ||||
|       currentStream: null, | ||||
|       Streams: null, | ||||
|       remoteAddr: "", | ||||
|       streamPath: "", | ||||
|       openPull: false, | ||||
|       columns: [ | ||||
|         "StreamPath", | ||||
|         "开始时间", | ||||
|         "总接收", | ||||
|         "总发送", | ||||
|         "操作" | ||||
|       ].map(title => ({ title })) | ||||
|     }; | ||||
|   }, | ||||
|  | ||||
|   methods: { | ||||
|     fetchlist() { | ||||
|       listES = new EventSource(this.apiHost + "/rtsp/list"); | ||||
|       listES.onmessage = evt => { | ||||
|         if (!evt.data) return; | ||||
|         this.Streams = JSON.parse(evt.data) || []; | ||||
|         this.Streams.sort((a, b) => | ||||
|           a.StreamInfo.StreamPath > b.StreamInfo.StreamPath ? 1 : -1 | ||||
|         ); | ||||
|       }; | ||||
|     }, | ||||
|     showHeader(item) { | ||||
|       this.$Modal.info({ | ||||
|         title: "RTSP SDPRaw", | ||||
|         width: "1000px", | ||||
|         scrollable: true, | ||||
|         content: item.SDPRaw | ||||
|       }); | ||||
|     }, | ||||
|     addPull() { | ||||
|       this.openPull = false; | ||||
|       this.ajax | ||||
|         .getJSON(this.apiHost + "/rtsp/pull", { | ||||
|           target: this.remoteAddr, | ||||
|           streamPath: this.streamPath | ||||
|         }) | ||||
|         .then(x => { | ||||
|           if (x.code == 0) { | ||||
|             this.$toast.success("已启动拉流"); | ||||
|           } else { | ||||
|             this.$toast.error(x.msg); | ||||
|           } | ||||
|         }); | ||||
|     }, | ||||
|     stop(item) { | ||||
|       this.ajax | ||||
|         .get(this.apiHost + "/api/stop", { | ||||
|           stream: item.StreamInfo.StreamPath | ||||
|         }) | ||||
|         .then(x => { | ||||
|           if (x == "success") { | ||||
|             this.$toast.success("已停止拉流"); | ||||
|           } else { | ||||
|             this.$toast.error(x.msg); | ||||
|           } | ||||
|         }); | ||||
|     } | ||||
|   }, | ||||
|   mounted() { | ||||
|     this.fetchlist(); | ||||
|     let _this = this; | ||||
|     this.$parent.titleOps = [ | ||||
|       { | ||||
|         template: '<m-button @click="onClick">拉流转发</m-button>', | ||||
|         methods: { | ||||
|           onClick() { | ||||
|             _this.openPull = true; | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|     ]; | ||||
|   }, | ||||
|   destroyed() { | ||||
|     listES.close(); | ||||
|   } | ||||
| }; | ||||
| </script> | ||||
|  | ||||
| <style> | ||||
| .empty { | ||||
|   color: #eb5e46; | ||||
|   width: 100%; | ||||
|   min-height: 500px; | ||||
|   display: flex; | ||||
|   justify-content: center; | ||||
|   align-items: center; | ||||
| } | ||||
|  | ||||
| .layout { | ||||
|   padding-bottom: 30px; | ||||
|   display: flex; | ||||
|   flex-wrap: wrap; | ||||
| } | ||||
| .ts-info { | ||||
|   width: 300px; | ||||
| } | ||||
|  | ||||
| .hls-info { | ||||
|   width: 350px; | ||||
|   display: flex; | ||||
|   flex-direction: column; | ||||
| } | ||||
| </style> | ||||
		Reference in New Issue
	
	Block a user