sdp_message_unittest.cc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "remoting/protocol/sdp_message.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. namespace remoting {
  7. namespace protocol {
  8. // Verify that SDP is normalized by removing empty lines and normalizing
  9. // line-endings to \r\n.
  10. TEST(SdpMessages, Normalize) {
  11. SdpMessage sdp_message("a=foo\n\r\nb=bar");
  12. EXPECT_EQ("a=foo\r\nb=bar\r\n", sdp_message.ToString());
  13. }
  14. // Verify that the normalized form of SDP for signature calculation has
  15. // line-endings of \n, for compatibility with existing clients.
  16. TEST(SdpMessages, NormalizedForSignature) {
  17. SdpMessage sdp_message("a=foo\nb=bar\r\n");
  18. EXPECT_EQ("a=foo\nb=bar\n", sdp_message.NormalizedForSignature());
  19. }
  20. TEST(SdpMessages, AddCodecParameter) {
  21. std::string kSourceSdp =
  22. "a=group:BUNDLE video\n"
  23. "m=video 9 UDP/TLS/RTP/SAVPF 96\n"
  24. "a=rtpmap:96 VP8/90000\n"
  25. "a=rtcp-fb:96 transport-cc\n";
  26. SdpMessage sdp_message(kSourceSdp);
  27. EXPECT_TRUE(sdp_message.AddCodecParameter("VP8", "test_param=1"));
  28. EXPECT_EQ(
  29. "a=group:BUNDLE video\r\n"
  30. "m=video 9 UDP/TLS/RTP/SAVPF 96\r\n"
  31. "a=rtpmap:96 VP8/90000\r\n"
  32. "a=fmtp:96 test_param=1\r\n"
  33. "a=rtcp-fb:96 transport-cc\r\n",
  34. sdp_message.ToString());
  35. }
  36. TEST(SdpMessages, AddCodecParameterMissingCodec) {
  37. std::string kSourceSdp =
  38. "a=group:BUNDLE audio video\r\n"
  39. "m=audio 9 UDP/TLS/RTP/SAVPF 111\r\n"
  40. "a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\n"
  41. "a=rtpmap:111 opus/48000/2\r\n"
  42. "a=rtcp-fb:111 transport-cc\r\n"
  43. "m=video 9 UDP/TLS/RTP/SAVPF 96\r\n"
  44. "a=rtpmap:96 VP9/90000\r\n"
  45. "a=rtcp-fb:96 transport-cc\r\n"
  46. "m=application 9 DTLS/SCTP 5000\r\n";
  47. SdpMessage sdp_message(kSourceSdp);
  48. EXPECT_FALSE(sdp_message.AddCodecParameter("VP8", "test_param=1"));
  49. EXPECT_EQ(kSourceSdp, sdp_message.ToString());
  50. }
  51. TEST(SdpMessages, AddCodecParameter_MultipleTypes) {
  52. const std::string kSourceSdp =
  53. "a=group:BUNDLE video\n"
  54. "m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99\n"
  55. "a=rtpmap:96 VP8/90000\n"
  56. "a=rtcp-fb:96 transport-cc\n"
  57. "a=rtpmap:97 VP9/90000\n"
  58. "a=rtcp-fb:97 transport-cc\n"
  59. "a=rtpmap:98 VP8/90000\n"
  60. "a=rtcp-fb:98 transport-cc\n"
  61. "a=rtpmap:99 VP8/90000\n"
  62. "a=rtcp-fb:99 transport-cc\n";
  63. SdpMessage sdp_message(kSourceSdp);
  64. EXPECT_TRUE(sdp_message.AddCodecParameter("VP8", "test_param=1"));
  65. EXPECT_EQ(
  66. "a=group:BUNDLE video\r\n"
  67. "m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99\r\n"
  68. "a=rtpmap:96 VP8/90000\r\n"
  69. "a=fmtp:96 test_param=1\r\n"
  70. "a=rtcp-fb:96 transport-cc\r\n"
  71. "a=rtpmap:97 VP9/90000\r\n"
  72. "a=rtcp-fb:97 transport-cc\r\n"
  73. "a=rtpmap:98 VP8/90000\r\n"
  74. "a=fmtp:98 test_param=1\r\n"
  75. "a=rtcp-fb:98 transport-cc\r\n"
  76. "a=rtpmap:99 VP8/90000\r\n"
  77. "a=fmtp:99 test_param=1\r\n"
  78. "a=rtcp-fb:99 transport-cc\r\n",
  79. sdp_message.ToString());
  80. }
  81. TEST(SdpMessages, PreferVideoCodec_SdpIsUnchanged) {
  82. static const std::string kSourceSdp =
  83. "m=video 98 UDP/TLS/RTP/SAVPF 96 97 98 99 100\r\n"
  84. "a=rtpmap:96 VP8/90000\r\n"
  85. "a=fmtp:96\r\n"
  86. "a=rtpmap:97 VP8.1/90000\r\n"
  87. "a=fmtp:97\r\n"
  88. "a=rtpmap:98 VP9/90000\r\n"
  89. "a=fmtp:98\r\n"
  90. "a=rtpmap:99 VP9.1/90000\r\n"
  91. "a=fmtp:99\r\n"
  92. "a=rtpmap:100 H264/90000\r\n"
  93. "a=fmtp:100\r\n";
  94. SdpMessage sdp_message(kSourceSdp);
  95. EXPECT_TRUE(sdp_message.PreferVideoCodec("VP8"));
  96. EXPECT_EQ(kSourceSdp, sdp_message.ToString());
  97. }
  98. TEST(SdpMessages, PreferVideoCodec_MoveToTheStartOfTheList) {
  99. static const std::string kSourceSdp =
  100. "m=video 98 UDP/TLS/RTP/SAVPF 96 97 98 99 100\n"
  101. "a=rtpmap:96 VP8/90000\n"
  102. "a=fmtp:96\n"
  103. "a=rtpmap:97 VP8.1/90000\n"
  104. "a=fmtp:97\n"
  105. "a=rtpmap:98 VP9/90000\n"
  106. "a=fmtp:98\n"
  107. "a=rtpmap:99 VP9.1/90000\n"
  108. "a=fmtp:99\n"
  109. "a=rtpmap:100 H264/90000\n"
  110. "a=fmtp:100\n";
  111. SdpMessage sdp_message(kSourceSdp);
  112. EXPECT_TRUE(sdp_message.PreferVideoCodec("VP8.1"));
  113. EXPECT_EQ(
  114. "m=video 98 UDP/TLS/RTP/SAVPF 97 96 98 99 100\r\n"
  115. "a=rtpmap:96 VP8/90000\r\n"
  116. "a=fmtp:96\r\n"
  117. "a=rtpmap:97 VP8.1/90000\r\n"
  118. "a=fmtp:97\r\n"
  119. "a=rtpmap:98 VP9/90000\r\n"
  120. "a=fmtp:98\r\n"
  121. "a=rtpmap:99 VP9.1/90000\r\n"
  122. "a=fmtp:99\r\n"
  123. "a=rtpmap:100 H264/90000\r\n"
  124. "a=fmtp:100\r\n",
  125. sdp_message.ToString());
  126. sdp_message = SdpMessage(kSourceSdp);
  127. EXPECT_TRUE(sdp_message.PreferVideoCodec("VP9"));
  128. EXPECT_EQ(
  129. "m=video 98 UDP/TLS/RTP/SAVPF 98 96 97 99 100\r\n"
  130. "a=rtpmap:96 VP8/90000\r\n"
  131. "a=fmtp:96\r\n"
  132. "a=rtpmap:97 VP8.1/90000\r\n"
  133. "a=fmtp:97\r\n"
  134. "a=rtpmap:98 VP9/90000\r\n"
  135. "a=fmtp:98\r\n"
  136. "a=rtpmap:99 VP9.1/90000\r\n"
  137. "a=fmtp:99\r\n"
  138. "a=rtpmap:100 H264/90000\r\n"
  139. "a=fmtp:100\r\n",
  140. sdp_message.ToString());
  141. sdp_message = SdpMessage(kSourceSdp);
  142. EXPECT_TRUE(sdp_message.PreferVideoCodec("VP9.1"));
  143. EXPECT_EQ(
  144. "m=video 98 UDP/TLS/RTP/SAVPF 99 96 97 98 100\r\n"
  145. "a=rtpmap:96 VP8/90000\r\n"
  146. "a=fmtp:96\r\n"
  147. "a=rtpmap:97 VP8.1/90000\r\n"
  148. "a=fmtp:97\r\n"
  149. "a=rtpmap:98 VP9/90000\r\n"
  150. "a=fmtp:98\r\n"
  151. "a=rtpmap:99 VP9.1/90000\r\n"
  152. "a=fmtp:99\r\n"
  153. "a=rtpmap:100 H264/90000\r\n"
  154. "a=fmtp:100\r\n",
  155. sdp_message.ToString());
  156. sdp_message = SdpMessage(kSourceSdp);
  157. EXPECT_TRUE(sdp_message.PreferVideoCodec("H264"));
  158. EXPECT_EQ(
  159. "m=video 98 UDP/TLS/RTP/SAVPF 100 96 97 98 99\r\n"
  160. "a=rtpmap:96 VP8/90000\r\n"
  161. "a=fmtp:96\r\n"
  162. "a=rtpmap:97 VP8.1/90000\r\n"
  163. "a=fmtp:97\r\n"
  164. "a=rtpmap:98 VP9/90000\r\n"
  165. "a=fmtp:98\r\n"
  166. "a=rtpmap:99 VP9.1/90000\r\n"
  167. "a=fmtp:99\r\n"
  168. "a=rtpmap:100 H264/90000\r\n"
  169. "a=fmtp:100\r\n",
  170. sdp_message.ToString());
  171. }
  172. TEST(SdpMessages, PreferVideoCodec_UnknownCodec) {
  173. static const std::string kSourceSdp =
  174. "m=video 98 UDP/TLS/RTP/SAVPF 96 97 98 99 100\n"
  175. "a=rtpmap:96 VP8/90000\n"
  176. "a=fmtp:96\n"
  177. "a=rtpmap:97 VP8.1/90000\n"
  178. "a=fmtp:97\n"
  179. "a=rtpmap:98 VP9/90000\n"
  180. "a=fmtp:98\n"
  181. "a=rtpmap:99 VP9.1/90000\n"
  182. "a=fmtp:99\n"
  183. "a=rtpmap:100 H264/90000\n"
  184. "a=fmtp:100\n";
  185. SdpMessage sdp_message(kSourceSdp);
  186. EXPECT_FALSE(sdp_message.PreferVideoCodec("VP7"));
  187. EXPECT_EQ(
  188. "m=video 98 UDP/TLS/RTP/SAVPF 96 97 98 99 100\r\n"
  189. "a=rtpmap:96 VP8/90000\r\n"
  190. "a=fmtp:96\r\n"
  191. "a=rtpmap:97 VP8.1/90000\r\n"
  192. "a=fmtp:97\r\n"
  193. "a=rtpmap:98 VP9/90000\r\n"
  194. "a=fmtp:98\r\n"
  195. "a=rtpmap:99 VP9.1/90000\r\n"
  196. "a=fmtp:99\r\n"
  197. "a=rtpmap:100 H264/90000\r\n"
  198. "a=fmtp:100\r\n",
  199. sdp_message.ToString());
  200. }
  201. TEST(SdpMessages, PreferVideoCodec_MultiplePlayloads) {
  202. static const std::string kSourceSdp =
  203. "m=video 98 UDP/TLS/RTP/SAVPF 96 97 100 101 102 98 99\n"
  204. "a=rtpmap:96 VP8/90000\n"
  205. "a=fmtp:96\n"
  206. "a=rtpmap:97 VP8.1/90000\n"
  207. "a=fmtp:97\n"
  208. "a=rtpmap:101 VP9/90000\n"
  209. "a=fmtp:101\n"
  210. "a=rtpmap:98 VP9/90000\n"
  211. "a=fmtp:98\n"
  212. "a=rtpmap:99 VP9.1/90000\n"
  213. "a=fmtp:99\n"
  214. "a=rtpmap:102 VP9/90000\n"
  215. "a=fmtp:102\n"
  216. "a=rtpmap:103 VP9/90000\n"
  217. "a=fmtp:103\n"
  218. "a=rtpmap:100 H264/90000\n"
  219. "a=fmtp:100\n";
  220. SdpMessage sdp_message(kSourceSdp);
  221. EXPECT_TRUE(sdp_message.PreferVideoCodec("VP9"));
  222. EXPECT_EQ(
  223. "m=video 98 UDP/TLS/RTP/SAVPF 102 98 101 96 97 100 99\r\n"
  224. "a=rtpmap:96 VP8/90000\r\n"
  225. "a=fmtp:96\r\n"
  226. "a=rtpmap:97 VP8.1/90000\r\n"
  227. "a=fmtp:97\r\n"
  228. "a=rtpmap:101 VP9/90000\r\n"
  229. "a=fmtp:101\r\n"
  230. "a=rtpmap:98 VP9/90000\r\n"
  231. "a=fmtp:98\r\n"
  232. "a=rtpmap:99 VP9.1/90000\r\n"
  233. "a=fmtp:99\r\n"
  234. "a=rtpmap:102 VP9/90000\r\n"
  235. "a=fmtp:102\r\n"
  236. "a=rtpmap:103 VP9/90000\r\n"
  237. "a=fmtp:103\r\n"
  238. "a=rtpmap:100 H264/90000\r\n"
  239. "a=fmtp:100\r\n",
  240. sdp_message.ToString());
  241. }
  242. } // namespace protocol
  243. } // namespace remoting