From f7881ee1ae42ae68cb14dcc1e6cfafc8421f35b3 Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Sun, 26 Jan 2025 00:13:15 +0800 Subject: [PATCH] =?UTF-8?q?gb28181=20sdp=20=E5=BA=8F=E5=88=97=E5=8C=96?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/sdp_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/sdp_test.go b/test/sdp_test.go index e6a4f4b..31842ca 100644 --- a/test/sdp_test.go +++ b/test/sdp_test.go @@ -4,6 +4,7 @@ import ( "github.com/duke-git/lancet/v2/formatter" "github.com/pion/sdp" "io" + "net" "regexp" "strings" "testing" @@ -55,3 +56,48 @@ f= pretty, _ := formatter.Pretty(session) t.Logf("%s\n", pretty) } + +func TestSDP_Marshal(t *testing.T) { + description := sdp.NewJSEPSessionDescription(false) + description.SessionName = "Play" + + description.ConnectionInformation = &sdp.ConnectionInformation{ + NetworkType: "IN", + AddressType: "IP4", + Address: &sdp.Address{IP: net.ParseIP("10.10.10.200")}, + } + + description.Origin.Username = "00000000000000000002" + description.Origin.SessionID = 0 + description.Origin.SessionVersion = 0 + description.Origin.UnicastAddress = "10.10.10.200" + + media := &sdp.MediaDescription{ + MediaName: sdp.MediaName{ + Media: "video", + Port: sdp.RangedPort{Value: 5080}, + Protos: []string{"RTP", "AVP"}, + Formats: []string{"99", "125", "126", "96", "97", "98"}, + }, + Attributes: []sdp.Attribute{ + {Key: "rtpmap", Value: "99 H265/90000"}, + {Key: "fmtp", Value: "125 profile-level-id=42e01e"}, + {Key: "rtpmap", Value: "125 H264S/90000"}, + {Key: "fmtp", Value: "126 profile-level-id=42e01e"}, + {Key: "rtpmap", Value: "126 H264/90000"}, + {Key: "rtpmap", Value: "96 PS/90000"}, + {Key: "rtpmap", Value: "97 MPEG4/90000"}, + {Key: "rtpmap", Value: "98 H264/90000"}, + {Key: "sendonly"}, + }, + } + + description.MediaDescriptions = append(description.MediaDescriptions, media) + sdpResp := description.Marshal() + + // 添加 y= 和 f= 字段 + sdpResp += "y=501000001\r\n" + sdpResp += "f=\r\n" + + t.Logf("\n%s\n", sdpResp) +}