项目作者: medooze

项目描述 :
WebRTC Semantic SDP - Minimal SDP information semantic data model and parsing tools
高级语言: JavaScript
项目地址: git://github.com/medooze/semantic-sdp-js.git
创建时间: 2017-02-20T09:40:10Z
项目社区:https://github.com/medooze/semantic-sdp-js

开源协议:MIT License

下载


WebRTC Semantic SDP

Minimal SDP information semantic data model and parsing tools.

Motivation

Have you ever tried to mangle or process an SDP and got stuck about how to you change the information instead of what information do you want to access?

This project provies an abstraction layer on top of SDP that allows to acces and modify the information semantically, that is, it stores the SDP information and their relationships and allows you to get free of the acutal SDP semantics.

As it is meant to be used on WebRTC to WebRTC scenarios, so some SDP information can be safelly ignored, allowing to provide a simple and intuitive API.

Both Unified and Plan B are currently supported

Assumptions

We assume that:

  • Bundle is used
  • Trickle ICE or ICE lite is used
  • DTLS is used
  • RTCP mux is used

For the future

If you think it further exchanging the SDP information is all that it is needed to perform a peer to peer SDP exchange, so the intention is to provide serialization functions to be able to use this over the wire and only parse/serialize it on the endpoints or server side.

Note also that there is some similarity ORTC RTP parameters, but well done ;)

Install

  1. npm i --save semantic-sdp

Usage

  1. const SemanticSDP = require('semantic-sdp');

API Documention

You can check the full object documentation here.

Example

  1. const SemanticSDP = require("semantic-sdp");
  2. //Process the sdp
  3. var offer = SemanticSDP.SDPInfo.process(sdp);
  4. //Set the local DTLS and ICE info
  5. const dtls = new DTLSInfo(Setup.PASSIVE,"sha-256","F2:AA:0E:C3:22:59:5E:14:95:69:92:3D:13:B4:84:24:2C:C2:A2:C0:3E:FD:34:8E:5E:EA:6F:AF:52:CE:E6:0F");
  6. const ice = new ICEInfo("af46F","a34FasdS++jdfofdslkjsd/SDV");
  7. //Get local candidte
  8. const candidate = new CandidateInfo(1,1, "udp", 2122260223, "192.168.0.196", 56143, "host");
  9. //Create local SDP info
  10. let answer = new SDPInfo();
  11. //Add ice and dtls info
  12. answer.setDTLS(dtls);
  13. answer.setICE(ice);
  14. answer.addCandidate(candidate);
  15. //Get remote audio m-line info
  16. let audioOffer = offer.getMedia("audio");
  17. //If we have audio
  18. if (audioOffer)
  19. {
  20. //Create audio media
  21. let audio = new MediaInfo("audio", "audio");
  22. //Get codec type
  23. let opus = audioOffer.getCodec("opus");
  24. //Add opus codec
  25. audio.addCodec(opus);
  26. //Add audio extensions
  27. for (let extension of audioOffer.getExtensions().entries())
  28. //Add it
  29. audio.addExtension(extension[0], extension[1]);
  30. //Add it to answer
  31. answer.addMedia(audio);
  32. }
  33. //Get remote video m-line info
  34. let videoOffer = offer.getMedia("video");
  35. //If offer had video
  36. if (videoOffer)
  37. {
  38. //Create video media
  39. let video = new MediaInfo("video", "video");
  40. //Get codec types
  41. let vp9 = videoOffer.getCodec("vp9");
  42. let fec = videoOffer.getCodec("flexfec-03");
  43. //Add video codecs
  44. video.addCodec(vp9);
  45. if (fec)
  46. video.addCodec(fec);
  47. //Limit incoming bitrate
  48. video.setBitrate(1024);
  49. //Add video extensions
  50. for (let extension of videoOffer.getExtensions().entries())
  51. //Add it
  52. video.addExtension(extension[0], extension[1]);
  53. //Add it to answer
  54. answer.addMedia(video);
  55. }
  56. let ssrc = 1000;
  57. //For each stream
  58. for (let i=1;i<4;i++)
  59. {
  60. let track;
  61. //Create stream
  62. let stream = new StreamInfo("sream"+i);
  63. //Create track
  64. track = new TrackInfo("video", "track1");
  65. //Get ssrc, rtx and fec
  66. const media = ssrc++;
  67. const rtx = ssrc++;
  68. const fec = ssrc++;
  69. //Add ssrcs to track
  70. track.addSSRC(media);
  71. track.addSSRC(rtx);
  72. track.addSSRC(fec);
  73. //Add RTX and FEC group
  74. track.addSourceGroup(new SourceGroupInfo("FID",[media,rtx]));
  75. track.addSourceGroup(new SourceGroupInfo("FEC-FR",[media,fec]));
  76. //Add it
  77. stream.addTrack(track);
  78. //Create track
  79. track = new TrackInfo("audio", "track2");
  80. //Add ssrc
  81. track.addSSRC(ssrc++);
  82. //Add it
  83. stream.addTrack(track);
  84. //Add stream
  85. answer.addStream(stream);
  86. }
  87. //Get answer SDP
  88. const str = answer.toString();
  89. const json = JSON.stringifu(answer.plain());

The SDP output will be :

  1. v=0
  2. o=- 1489500633629 1 IN IP4 127.0.0.1
  3. s=semantic-sdp
  4. c=IN IP4 0.0.0.0
  5. t=0 0
  6. a=msid-semantic: WMS *
  7. m=audio 9 UDP/TLS/RTP/SAVPF 111
  8. a=rtpmap:111 opus/48000/2
  9. a=rtcp-fb:111 transport-cc
  10. a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
  11. a=setup:passive
  12. a=mid:audio
  13. a=sendrecv
  14. a=ice-ufrag:af46F
  15. a=ice-pwd:a34FasdS++jdfofdslkjsd/SDV
  16. a=fingerprint:sha-256 F2:AA:0E:C3:22:59:5E:14:95:69:92:3D:13:B4:84:24:2C:C2:A2:C0:3E:FD:34:8E:5E:EA:6F:AF:52:CE:E6:0F
  17. a=candidate:1 1 udp 2122260223 192.168.0.196 56143 typ host
  18. a=ssrc:1003 cname:sream1
  19. a=ssrc:1003 msid:sream1 track2
  20. a=ssrc:1007 cname:sream2
  21. a=ssrc:1007 msid:sream2 track2
  22. a=ssrc:1011 cname:sream3
  23. a=ssrc:1011 msid:sream3 track2
  24. a=rtcp-mux
  25. a=rtcp-rsize
  26. m=video 9 UDP/TLS/RTP/SAVPF 98 99 125
  27. b=AS:1024
  28. a=rtpmap:98 VP9/90000
  29. a=rtpmap:99 rtx/90000
  30. a=rtpmap:125 flexfec-03/90000
  31. a=fmtp:99 apt=98
  32. a=rtcp-fb:98 transport-cc
  33. a=rtcp-fb:125 transport-cc
  34. a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
  35. a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
  36. a=extmap:4 urn:3gpp:video-orientation
  37. a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
  38. a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
  39. a=setup:passive
  40. a=mid:video
  41. a=sendrecv
  42. a=ice-ufrag:af46F
  43. a=ice-pwd:a34FasdS++jdfofdslkjsd/SDV
  44. a=fingerprint:sha-256 F2:AA:0E:C3:22:59:5E:14:95:69:92:3D:13:B4:84:24:2C:C2:A2:C0:3E:FD:34:8E:5E:EA:6F:AF:52:CE:E6:0F
  45. a=candidate:1 1 udp 2122260223 192.168.0.196 56143 typ host
  46. a=ssrc:1000 cname:sream1
  47. a=ssrc:1000 msid:sream1 track1
  48. a=ssrc:1001 cname:sream1
  49. a=ssrc:1001 msid:sream1 track1
  50. a=ssrc:1002 cname:sream1
  51. a=ssrc:1002 msid:sream1 track1
  52. a=ssrc:1004 cname:sream2
  53. a=ssrc:1004 msid:sream2 track1
  54. a=ssrc:1005 cname:sream2
  55. a=ssrc:1005 msid:sream2 track1
  56. a=ssrc:1006 cname:sream2
  57. a=ssrc:1006 msid:sream2 track1
  58. a=ssrc:1008 cname:sream3
  59. a=ssrc:1008 msid:sream3 track1
  60. a=ssrc:1009 cname:sream3
  61. a=ssrc:1009 msid:sream3 track1
  62. a=ssrc:1010 cname:sream3
  63. a=ssrc:1010 msid:sream3 track1
  64. a=ssrc-group:FID 1000 1001
  65. a=ssrc-group:FEC-FR 1000 1002
  66. a=ssrc-group:FID 1004 1005
  67. a=ssrc-group:FEC-FR 1004 1006
  68. a=ssrc-group:FID 1008 1009
  69. a=ssrc-group:FEC-FR 1008 1010
  70. a=rtcp-mux
  71. a=rtcp-rsize

And the serialized JSON string:

  1. {
  2. "version": 1,
  3. "streams": [
  4. {
  5. "tracks": [
  6. {
  7. "media": "video",
  8. "id": "track1",
  9. "ssrcs": [
  10. 1000,
  11. 1001,
  12. 1002
  13. ],
  14. "groups": [
  15. {
  16. "semantics": "FID",
  17. "ssrcs": [
  18. 1000,
  19. 1001
  20. ]
  21. },
  22. {
  23. "semantics": "FEC-FR",
  24. "ssrcs": [
  25. 1000,
  26. 1002
  27. ]
  28. }
  29. ]
  30. },
  31. {
  32. "media": "audio",
  33. "id": "track2",
  34. "ssrcs": [
  35. 1003
  36. ],
  37. "groups": [
  38. ]
  39. }
  40. ]
  41. },
  42. {
  43. "tracks": [
  44. {
  45. "media": "video",
  46. "id": "track1",
  47. "ssrcs": [
  48. 1004,
  49. 1005,
  50. 1006
  51. ],
  52. "groups": [
  53. {
  54. "semantics": "FID",
  55. "ssrcs": [
  56. 1004,
  57. 1005
  58. ]
  59. },
  60. {
  61. "semantics": "FEC-FR",
  62. "ssrcs": [
  63. 1004,
  64. 1006
  65. ]
  66. }
  67. ]
  68. },
  69. {
  70. "media": "audio",
  71. "id": "track2",
  72. "ssrcs": [
  73. 1007
  74. ],
  75. "groups": [
  76. ]
  77. }
  78. ]
  79. },
  80. {
  81. "tracks": [
  82. {
  83. "media": "video",
  84. "id": "track1",
  85. "ssrcs": [
  86. 1008,
  87. 1009,
  88. 1010
  89. ],
  90. "groups": [
  91. {
  92. "semantics": "FID",
  93. "ssrcs": [
  94. 1008,
  95. 1009
  96. ]
  97. },
  98. {
  99. "semantics": "FEC-FR",
  100. "ssrcs": [
  101. 1008,
  102. 1010
  103. ]
  104. }
  105. ]
  106. },
  107. {
  108. "media": "audio",
  109. "id": "track2",
  110. "ssrcs": [
  111. 1011
  112. ],
  113. "groups": [
  114. ]
  115. }
  116. ]
  117. }
  118. ],
  119. "medias": [
  120. {
  121. "type": "audio",
  122. "direction": "sendrecv",
  123. "extensions": {
  124. "1": "urn:ietf:params:rtp-hdrext:ssrc-audio-level"
  125. },
  126. "codecs": [
  127. {
  128. "codec": "opus",
  129. "type": 111,
  130. "params": {
  131. "minptime": "10",
  132. "useinbandfec": "1"
  133. }
  134. }
  135. ]
  136. },
  137. {
  138. "type": "video",
  139. "direction": "sendrecv",
  140. "extensions": {
  141. "2": "urn:ietf:params:rtp-hdrext:toffset",
  142. "3": "http:\/\/www.webrtc.org\/experiments\/rtp-hdrext\/abs-send-time",
  143. "4": "urn:3gpp:video-orientation",
  144. "5": "http:\/\/www.ietf.org\/id\/draft-holmer-rmcat-transport-wide-cc-extensions-01",
  145. "6": "http:\/\/www.webrtc.org\/experiments\/rtp-hdrext\/playout-delay"
  146. },
  147. "codecs": [
  148. {
  149. "codec": "VP9",
  150. "type": 98,
  151. "params": {
  152. }
  153. },
  154. {
  155. "codec": "flexfec-03",
  156. "type": 125,
  157. "params": {
  158. "repair-window": "10000000"
  159. }
  160. }
  161. ],
  162. "bitrate": 1024
  163. }
  164. ],
  165. "candidates": [
  166. {
  167. "foundation": 1,
  168. "componentId": 1,
  169. "transport": "udp",
  170. "priority": 2122260223,
  171. "address": "192.168.0.196",
  172. "port": 56143,
  173. "type": "host"
  174. }
  175. ],
  176. "ice": {
  177. "ufrag": "af46F",
  178. "pwd": "a34FasdS++jdfofdslkjsd\/SDV"
  179. },
  180. "dtls": {
  181. "hash": "sha-256",
  182. "fingerprint": "F2:AA:0E:C3:22:59:5E:14:95:69:92:3D:13:B4:84:24:2C:C2:A2:C0:3E:FD:34:8E:5E:EA:6F:AF:52:CE:E6:0F"
  183. }
  184. }

Author

Sergio Garcia Murillo @ Medooze

License

MIT