From a9dbb24a0882344b27d114021c8e4a425fcb85cb Mon Sep 17 00:00:00 2001 From: langhuihui <178529795@qq.com> Date: Mon, 24 Apr 2023 14:18:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8B=B1=E6=96=87readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + subscriber.go | 20 ++++++++------ 3 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 README.en.md diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..ef5a87e --- /dev/null +++ b/README.en.md @@ -0,0 +1,76 @@ +_[简体中文](https://github.com/Monibuca/plugin-webrtc) | English_ +# WebRTC Plugin + +This plugin provides the functionality to stream videos to Monibuca through a web page and to play streams from Monibuca using WebRTC technology. It follows the WHIP specification. + +## Plugin URL + +https://github.com/Monibuca/plugin-webrtc + +## Plugin Import + +```go + import ( _ "m7s.live/plugin/webrtc/v4" ) +``` + +## Default Configuration + +```yaml +webrtc: + iceservers: [] + publicip: [] # can be an array or a single string (automatically converted to an array) + port: tcp:9000 # can be a range of ports like udp:8000-9000 or a single port like udp:9000 + pli: 2s # 2s +``` + +### ICE Server Configuration Format + +```yaml +webrtc: + iceservers: + - urls: + - stun:stun.l.google.com:19302 + - turn:turn.example.org + username: user + credential: pass +``` + +### Configuration for Local Testing + +If testing locally, no change in configuration is required. However, if you are accessing it remotely, then you need to configure the public IP. + +## Basic Principle + +The exchange of SDP messages between the browser and Monibuca takes place and RTP packets are read or sent to stream videos. + +## API + +### Play address +`/webrtc/play/[streamPath]` + +Body: `SDP` + +Content-Type: `application/sdp` + +Response Body: `SDP` + +### Push address + +`/webrtc/push/[streamPath]` + +Body: `SDP` + +Content-Type: `application/sdp` + +Response Body: `SDP` + +### Push Test Page + +`/webrtc/test/publish` + +## WHIP + +WebRTC-HTTP ingestion protocol +A specification for the exchange of SDP messages between WebRTC clients. + +[WHIP ietf](https://datatracker.ietf.org/doc/html/draft-ietf-wish-whip-02) \ No newline at end of file diff --git a/README.md b/README.md index f98338d..cf431c2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +_[English](https://github.com/Monibuca/plugin-webrtc/blob/v4/README.en.md) | 简体中文_ # WebRTC 插件 提供通过网页发布视频到monibuca,以及从monibuca拉流通过webrtc进行播放的功能,遵循WHIP规范 diff --git a/subscriber.go b/subscriber.go index c2ccda2..9b3f8b9 100644 --- a/subscriber.go +++ b/subscriber.go @@ -1,10 +1,13 @@ package webrtc import ( + "fmt" "net" + "strings" "github.com/pion/rtcp" . "github.com/pion/webrtc/v3" + "go.uber.org/zap" . "m7s.live/engine/v4" "m7s.live/engine/v4/codec" "m7s.live/engine/v4/track" @@ -53,14 +56,14 @@ func (suber *WebRTCSubscriber) OnEvent(event any) { case *track.Video: switch v.CodecID { case codec.CodecID_H264: - pli := "420028" - // pli = fmt.Sprintf("%x", v.GetDecoderConfiguration().Raw[0][1:4]) - // if !strings.Contains(suber.SDP, pli) { - // list := reg_level.FindAllStringSubmatch(suber.SDP, -1) - // if len(list) > 0 { - // pli = list[0][1] - // } - // } + pli := fmt.Sprintf("%x", v.SPS[1:4]) + // pli := "42001f" + if !strings.Contains(suber.SDP, pli) { + list := reg_level.FindAllStringSubmatch(suber.SDP, -1) + if len(list) > 0 { + pli = list[0][1] + } + } suber.videoTrack, _ = NewTrackLocalStaticRTP(RTPCodecCapability{MimeType: MimeTypeH264, SDPFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=" + pli}, v.Name, suber.Subscriber.Stream.Path) case codec.CodecID_H265: // suber.videoTrack, _ = NewTrackLocalStaticRTP(RTPCodecCapability{MimeType: MimeTypeH265, SDPFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=" + pli}, "video", suber.Subscriber.Stream.Path) @@ -114,6 +117,7 @@ func (suber *WebRTCSubscriber) OnEvent(event any) { } case VideoRTP: if suber.videoTrack != nil { + suber.Trace("video rtp", zap.Any("packet", v.Packet.Header)) suber.videoTrack.WriteRTP(v.Packet) } else if suber.DC != nil { suber.sendAvByDatachannel(9, &suber.VideoReader)