You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

494 lines
18 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2017 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "pc/rtp_parameters_conversion.h"
  11. #include <cstdint>
  12. #include <set>
  13. #include <string>
  14. #include <unordered_map>
  15. #include <utility>
  16. #include "api/array_view.h"
  17. #include "api/media_types.h"
  18. #include "media/base/media_constants.h"
  19. #include "media/base/rtp_utils.h"
  20. #include "rtc_base/checks.h"
  21. #include "rtc_base/logging.h"
  22. #include "rtc_base/strings/string_builder.h"
  23. namespace webrtc {
  24. RTCErrorOr<cricket::FeedbackParam> ToCricketFeedbackParam(
  25. const RtcpFeedback& feedback) {
  26. switch (feedback.type) {
  27. case RtcpFeedbackType::CCM:
  28. if (!feedback.message_type) {
  29. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
  30. "Missing message type in CCM RtcpFeedback.");
  31. } else if (*feedback.message_type != RtcpFeedbackMessageType::FIR) {
  32. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
  33. "Invalid message type in CCM RtcpFeedback.");
  34. }
  35. return cricket::FeedbackParam(cricket::kRtcpFbParamCcm,
  36. cricket::kRtcpFbCcmParamFir);
  37. case RtcpFeedbackType::LNTF:
  38. if (feedback.message_type) {
  39. LOG_AND_RETURN_ERROR(
  40. RTCErrorType::INVALID_PARAMETER,
  41. "Didn't expect message type in LNTF RtcpFeedback.");
  42. }
  43. return cricket::FeedbackParam(cricket::kRtcpFbParamLntf);
  44. case RtcpFeedbackType::NACK:
  45. if (!feedback.message_type) {
  46. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
  47. "Missing message type in NACK RtcpFeedback.");
  48. }
  49. switch (*feedback.message_type) {
  50. case RtcpFeedbackMessageType::GENERIC_NACK:
  51. return cricket::FeedbackParam(cricket::kRtcpFbParamNack);
  52. case RtcpFeedbackMessageType::PLI:
  53. return cricket::FeedbackParam(cricket::kRtcpFbParamNack,
  54. cricket::kRtcpFbNackParamPli);
  55. default:
  56. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
  57. "Invalid message type in NACK RtcpFeedback.");
  58. }
  59. case RtcpFeedbackType::REMB:
  60. if (feedback.message_type) {
  61. LOG_AND_RETURN_ERROR(
  62. RTCErrorType::INVALID_PARAMETER,
  63. "Didn't expect message type in REMB RtcpFeedback.");
  64. }
  65. return cricket::FeedbackParam(cricket::kRtcpFbParamRemb);
  66. case RtcpFeedbackType::TRANSPORT_CC:
  67. if (feedback.message_type) {
  68. LOG_AND_RETURN_ERROR(
  69. RTCErrorType::INVALID_PARAMETER,
  70. "Didn't expect message type in transport-cc RtcpFeedback.");
  71. }
  72. return cricket::FeedbackParam(cricket::kRtcpFbParamTransportCc);
  73. }
  74. // Not reached; avoids compile warning.
  75. FATAL();
  76. }
  77. template <typename C>
  78. static RTCError ToCricketCodecTypeSpecific(const RtpCodecParameters& codec,
  79. C* cricket_codec);
  80. template <>
  81. RTCError ToCricketCodecTypeSpecific<cricket::AudioCodec>(
  82. const RtpCodecParameters& codec,
  83. cricket::AudioCodec* cricket_codec) {
  84. if (codec.kind != cricket::MEDIA_TYPE_AUDIO) {
  85. LOG_AND_RETURN_ERROR(
  86. RTCErrorType::INVALID_PARAMETER,
  87. "Can't use video codec with audio sender or receiver.");
  88. }
  89. if (!codec.num_channels) {
  90. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
  91. "Missing number of channels for audio codec.");
  92. }
  93. if (*codec.num_channels <= 0) {
  94. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
  95. "Number of channels must be positive.");
  96. }
  97. cricket_codec->channels = *codec.num_channels;
  98. if (!codec.clock_rate) {
  99. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
  100. "Missing codec clock rate.");
  101. }
  102. if (*codec.clock_rate <= 0) {
  103. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE,
  104. "Clock rate must be positive.");
  105. }
  106. cricket_codec->clockrate = *codec.clock_rate;
  107. return RTCError::OK();
  108. }
  109. // Video codecs don't use num_channels or clock_rate, but they should at least
  110. // be validated to ensure the application isn't trying to do something it
  111. // doesn't intend to.
  112. template <>
  113. RTCError ToCricketCodecTypeSpecific<cricket::VideoCodec>(
  114. const RtpCodecParameters& codec,
  115. cricket::VideoCodec*) {
  116. if (codec.kind != cricket::MEDIA_TYPE_VIDEO) {
  117. LOG_AND_RETURN_ERROR(
  118. RTCErrorType::INVALID_PARAMETER,
  119. "Can't use audio codec with video sender or receiver.");
  120. }
  121. if (codec.num_channels) {
  122. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
  123. "Video codec shouldn't have num_channels.");
  124. }
  125. if (!codec.clock_rate) {
  126. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
  127. "Missing codec clock rate.");
  128. }
  129. if (*codec.clock_rate != cricket::kVideoCodecClockrate) {
  130. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
  131. "Video clock rate must be 90000.");
  132. }
  133. return RTCError::OK();
  134. }
  135. template <typename C>
  136. RTCErrorOr<C> ToCricketCodec(const RtpCodecParameters& codec) {
  137. C cricket_codec;
  138. // Start with audio/video specific conversion.
  139. RTCError err = ToCricketCodecTypeSpecific(codec, &cricket_codec);
  140. if (!err.ok()) {
  141. return std::move(err);
  142. }
  143. cricket_codec.name = codec.name;
  144. if (!cricket::IsValidRtpPayloadType(codec.payload_type)) {
  145. char buf[40];
  146. rtc::SimpleStringBuilder sb(buf);
  147. sb << "Invalid payload type: " << codec.payload_type;
  148. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE, sb.str());
  149. }
  150. cricket_codec.id = codec.payload_type;
  151. for (const RtcpFeedback& feedback : codec.rtcp_feedback) {
  152. auto result = ToCricketFeedbackParam(feedback);
  153. if (!result.ok()) {
  154. return result.MoveError();
  155. }
  156. cricket_codec.AddFeedbackParam(result.MoveValue());
  157. }
  158. cricket_codec.params.insert(codec.parameters.begin(), codec.parameters.end());
  159. return std::move(cricket_codec);
  160. }
  161. template RTCErrorOr<cricket::AudioCodec> ToCricketCodec(
  162. const RtpCodecParameters& codec);
  163. template RTCErrorOr<cricket::VideoCodec> ToCricketCodec(
  164. const RtpCodecParameters& codec);
  165. template <typename C>
  166. RTCErrorOr<std::vector<C>> ToCricketCodecs(
  167. const std::vector<RtpCodecParameters>& codecs) {
  168. std::vector<C> cricket_codecs;
  169. std::set<int> seen_payload_types;
  170. for (const RtpCodecParameters& codec : codecs) {
  171. auto result = ToCricketCodec<C>(codec);
  172. if (!result.ok()) {
  173. return result.MoveError();
  174. }
  175. if (!seen_payload_types.insert(codec.payload_type).second) {
  176. char buf[40];
  177. rtc::SimpleStringBuilder sb(buf);
  178. sb << "Duplicate payload type: " << codec.payload_type;
  179. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, sb.str());
  180. }
  181. cricket_codecs.push_back(result.MoveValue());
  182. }
  183. return std::move(cricket_codecs);
  184. }
  185. template RTCErrorOr<std::vector<cricket::AudioCodec>> ToCricketCodecs<
  186. cricket::AudioCodec>(const std::vector<RtpCodecParameters>& codecs);
  187. template RTCErrorOr<std::vector<cricket::VideoCodec>> ToCricketCodecs<
  188. cricket::VideoCodec>(const std::vector<RtpCodecParameters>& codecs);
  189. RTCErrorOr<cricket::RtpHeaderExtensions> ToCricketRtpHeaderExtensions(
  190. const std::vector<RtpHeaderExtensionParameters>& extensions) {
  191. cricket::RtpHeaderExtensions cricket_extensions;
  192. std::set<int> seen_header_extension_ids;
  193. for (const RtpHeaderExtensionParameters& extension : extensions) {
  194. if (extension.id < RtpHeaderExtensionParameters::kMinId ||
  195. extension.id > RtpHeaderExtensionParameters::kMaxId) {
  196. char buf[50];
  197. rtc::SimpleStringBuilder sb(buf);
  198. sb << "Invalid header extension id: " << extension.id;
  199. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_RANGE, sb.str());
  200. }
  201. if (!seen_header_extension_ids.insert(extension.id).second) {
  202. char buf[50];
  203. rtc::SimpleStringBuilder sb(buf);
  204. sb << "Duplicate header extension id: " << extension.id;
  205. LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, sb.str());
  206. }
  207. cricket_extensions.push_back(extension);
  208. }
  209. return std::move(cricket_extensions);
  210. }
  211. RTCErrorOr<cricket::StreamParamsVec> ToCricketStreamParamsVec(
  212. const std::vector<RtpEncodingParameters>& encodings) {
  213. if (encodings.size() > 1u) {
  214. LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_PARAMETER,
  215. "ORTC API implementation doesn't currently "
  216. "support simulcast or layered encodings.");
  217. } else if (encodings.empty()) {
  218. return cricket::StreamParamsVec();
  219. }
  220. cricket::StreamParamsVec cricket_streams;
  221. const RtpEncodingParameters& encoding = encodings[0];
  222. if (encoding.rtx && encoding.rtx->ssrc && !encoding.ssrc) {
  223. LOG_AND_RETURN_ERROR(RTCErrorType::UNSUPPORTED_PARAMETER,
  224. "Setting an RTX SSRC explicitly while leaving the "
  225. "primary SSRC unset is not currently supported.");
  226. }
  227. if (encoding.ssrc) {
  228. cricket::StreamParams stream_params;
  229. stream_params.add_ssrc(*encoding.ssrc);
  230. if (encoding.rtx && encoding.rtx->ssrc) {
  231. stream_params.AddFidSsrc(*encoding.ssrc, *encoding.rtx->ssrc);
  232. }
  233. cricket_streams.push_back(std::move(stream_params));
  234. }
  235. return std::move(cricket_streams);
  236. }
  237. absl::optional<RtcpFeedback> ToRtcpFeedback(
  238. const cricket::FeedbackParam& cricket_feedback) {
  239. if (cricket_feedback.id() == cricket::kRtcpFbParamCcm) {
  240. if (cricket_feedback.param() == cricket::kRtcpFbCcmParamFir) {
  241. return RtcpFeedback(RtcpFeedbackType::CCM, RtcpFeedbackMessageType::FIR);
  242. } else {
  243. RTC_LOG(LS_WARNING) << "Unsupported parameter for CCM RTCP feedback: "
  244. << cricket_feedback.param();
  245. return absl::nullopt;
  246. }
  247. } else if (cricket_feedback.id() == cricket::kRtcpFbParamLntf) {
  248. if (cricket_feedback.param().empty()) {
  249. return RtcpFeedback(RtcpFeedbackType::LNTF);
  250. } else {
  251. RTC_LOG(LS_WARNING) << "Unsupported parameter for LNTF RTCP feedback: "
  252. << cricket_feedback.param();
  253. return absl::nullopt;
  254. }
  255. } else if (cricket_feedback.id() == cricket::kRtcpFbParamNack) {
  256. if (cricket_feedback.param().empty()) {
  257. return RtcpFeedback(RtcpFeedbackType::NACK,
  258. RtcpFeedbackMessageType::GENERIC_NACK);
  259. } else if (cricket_feedback.param() == cricket::kRtcpFbNackParamPli) {
  260. return RtcpFeedback(RtcpFeedbackType::NACK, RtcpFeedbackMessageType::PLI);
  261. } else {
  262. RTC_LOG(LS_WARNING) << "Unsupported parameter for NACK RTCP feedback: "
  263. << cricket_feedback.param();
  264. return absl::nullopt;
  265. }
  266. } else if (cricket_feedback.id() == cricket::kRtcpFbParamRemb) {
  267. if (!cricket_feedback.param().empty()) {
  268. RTC_LOG(LS_WARNING) << "Unsupported parameter for REMB RTCP feedback: "
  269. << cricket_feedback.param();
  270. return absl::nullopt;
  271. } else {
  272. return RtcpFeedback(RtcpFeedbackType::REMB);
  273. }
  274. } else if (cricket_feedback.id() == cricket::kRtcpFbParamTransportCc) {
  275. if (!cricket_feedback.param().empty()) {
  276. RTC_LOG(LS_WARNING)
  277. << "Unsupported parameter for transport-cc RTCP feedback: "
  278. << cricket_feedback.param();
  279. return absl::nullopt;
  280. } else {
  281. return RtcpFeedback(RtcpFeedbackType::TRANSPORT_CC);
  282. }
  283. }
  284. RTC_LOG(LS_WARNING) << "Unsupported RTCP feedback type: "
  285. << cricket_feedback.id();
  286. return absl::nullopt;
  287. }
  288. std::vector<RtpEncodingParameters> ToRtpEncodings(
  289. const cricket::StreamParamsVec& stream_params) {
  290. std::vector<RtpEncodingParameters> rtp_encodings;
  291. for (const cricket::StreamParams& stream_param : stream_params) {
  292. RtpEncodingParameters rtp_encoding;
  293. rtp_encoding.ssrc.emplace(stream_param.first_ssrc());
  294. uint32_t rtx_ssrc = 0;
  295. if (stream_param.GetFidSsrc(stream_param.first_ssrc(), &rtx_ssrc)) {
  296. RtpRtxParameters rtx_param(rtx_ssrc);
  297. rtp_encoding.rtx.emplace(rtx_param);
  298. }
  299. rtp_encodings.push_back(std::move(rtp_encoding));
  300. }
  301. return rtp_encodings;
  302. }
  303. template <typename C>
  304. cricket::MediaType KindOfCodec();
  305. template <>
  306. cricket::MediaType KindOfCodec<cricket::AudioCodec>() {
  307. return cricket::MEDIA_TYPE_AUDIO;
  308. }
  309. template <>
  310. cricket::MediaType KindOfCodec<cricket::VideoCodec>() {
  311. return cricket::MEDIA_TYPE_VIDEO;
  312. }
  313. template <typename C>
  314. static void ToRtpCodecCapabilityTypeSpecific(const C& cricket_codec,
  315. RtpCodecCapability* codec);
  316. template <>
  317. void ToRtpCodecCapabilityTypeSpecific<cricket::AudioCodec>(
  318. const cricket::AudioCodec& cricket_codec,
  319. RtpCodecCapability* codec) {
  320. codec->num_channels = static_cast<int>(cricket_codec.channels);
  321. }
  322. template <>
  323. void ToRtpCodecCapabilityTypeSpecific<cricket::VideoCodec>(
  324. const cricket::VideoCodec& cricket_codec,
  325. RtpCodecCapability* codec) {}
  326. template <typename C>
  327. RtpCodecCapability ToRtpCodecCapability(const C& cricket_codec) {
  328. RtpCodecCapability codec;
  329. codec.name = cricket_codec.name;
  330. codec.kind = KindOfCodec<C>();
  331. codec.clock_rate.emplace(cricket_codec.clockrate);
  332. codec.preferred_payload_type.emplace(cricket_codec.id);
  333. for (const cricket::FeedbackParam& cricket_feedback :
  334. cricket_codec.feedback_params.params()) {
  335. absl::optional<RtcpFeedback> feedback = ToRtcpFeedback(cricket_feedback);
  336. if (feedback) {
  337. codec.rtcp_feedback.push_back(feedback.value());
  338. }
  339. }
  340. ToRtpCodecCapabilityTypeSpecific(cricket_codec, &codec);
  341. codec.parameters.insert(cricket_codec.params.begin(),
  342. cricket_codec.params.end());
  343. return codec;
  344. }
  345. template RtpCodecCapability ToRtpCodecCapability<cricket::AudioCodec>(
  346. const cricket::AudioCodec& cricket_codec);
  347. template RtpCodecCapability ToRtpCodecCapability<cricket::VideoCodec>(
  348. const cricket::VideoCodec& cricket_codec);
  349. template <typename C>
  350. static void ToRtpCodecParametersTypeSpecific(const C& cricket_codec,
  351. RtpCodecParameters* codec);
  352. template <>
  353. void ToRtpCodecParametersTypeSpecific<cricket::AudioCodec>(
  354. const cricket::AudioCodec& cricket_codec,
  355. RtpCodecParameters* codec) {
  356. codec->num_channels = static_cast<int>(cricket_codec.channels);
  357. }
  358. template <>
  359. void ToRtpCodecParametersTypeSpecific<cricket::VideoCodec>(
  360. const cricket::VideoCodec& cricket_codec,
  361. RtpCodecParameters* codec) {}
  362. template <typename C>
  363. RtpCodecParameters ToRtpCodecParameters(const C& cricket_codec) {
  364. RtpCodecParameters codec_param;
  365. codec_param.name = cricket_codec.name;
  366. codec_param.kind = KindOfCodec<C>();
  367. codec_param.clock_rate.emplace(cricket_codec.clockrate);
  368. codec_param.payload_type = cricket_codec.id;
  369. for (const cricket::FeedbackParam& cricket_feedback :
  370. cricket_codec.feedback_params.params()) {
  371. absl::optional<RtcpFeedback> feedback = ToRtcpFeedback(cricket_feedback);
  372. if (feedback) {
  373. codec_param.rtcp_feedback.push_back(feedback.value());
  374. }
  375. }
  376. ToRtpCodecParametersTypeSpecific(cricket_codec, &codec_param);
  377. codec_param.parameters.insert(cricket_codec.params.begin(),
  378. cricket_codec.params.end());
  379. return codec_param;
  380. }
  381. template RtpCodecParameters ToRtpCodecParameters<cricket::AudioCodec>(
  382. const cricket::AudioCodec& cricket_codec);
  383. template RtpCodecParameters ToRtpCodecParameters<cricket::VideoCodec>(
  384. const cricket::VideoCodec& cricket_codec);
  385. template <class C>
  386. RtpCapabilities ToRtpCapabilities(
  387. const std::vector<C>& cricket_codecs,
  388. const cricket::RtpHeaderExtensions& cricket_extensions) {
  389. RtpCapabilities capabilities;
  390. bool have_red = false;
  391. bool have_ulpfec = false;
  392. bool have_flexfec = false;
  393. bool have_rtx = false;
  394. for (const C& cricket_codec : cricket_codecs) {
  395. if (cricket_codec.name == cricket::kRedCodecName) {
  396. have_red = true;
  397. } else if (cricket_codec.name == cricket::kUlpfecCodecName) {
  398. have_ulpfec = true;
  399. } else if (cricket_codec.name == cricket::kFlexfecCodecName) {
  400. have_flexfec = true;
  401. } else if (cricket_codec.name == cricket::kRtxCodecName) {
  402. if (have_rtx) {
  403. // There should only be one RTX codec entry
  404. continue;
  405. }
  406. have_rtx = true;
  407. }
  408. auto codec_capability = ToRtpCodecCapability(cricket_codec);
  409. if (cricket_codec.name == cricket::kRtxCodecName) {
  410. // RTX codec should not have any parameter
  411. codec_capability.parameters.clear();
  412. }
  413. capabilities.codecs.push_back(codec_capability);
  414. }
  415. for (const RtpExtension& cricket_extension : cricket_extensions) {
  416. capabilities.header_extensions.emplace_back(cricket_extension.uri,
  417. cricket_extension.id);
  418. }
  419. if (have_red) {
  420. capabilities.fec.push_back(FecMechanism::RED);
  421. }
  422. if (have_red && have_ulpfec) {
  423. capabilities.fec.push_back(FecMechanism::RED_AND_ULPFEC);
  424. }
  425. if (have_flexfec) {
  426. capabilities.fec.push_back(FecMechanism::FLEXFEC);
  427. }
  428. return capabilities;
  429. }
  430. template RtpCapabilities ToRtpCapabilities<cricket::AudioCodec>(
  431. const std::vector<cricket::AudioCodec>& cricket_codecs,
  432. const cricket::RtpHeaderExtensions& cricket_extensions);
  433. template RtpCapabilities ToRtpCapabilities<cricket::VideoCodec>(
  434. const std::vector<cricket::VideoCodec>& cricket_codecs,
  435. const cricket::RtpHeaderExtensions& cricket_extensions);
  436. template <class C>
  437. RtpParameters ToRtpParameters(
  438. const std::vector<C>& cricket_codecs,
  439. const cricket::RtpHeaderExtensions& cricket_extensions,
  440. const cricket::StreamParamsVec& stream_params) {
  441. RtpParameters rtp_parameters;
  442. for (const C& cricket_codec : cricket_codecs) {
  443. rtp_parameters.codecs.push_back(ToRtpCodecParameters(cricket_codec));
  444. }
  445. for (const RtpExtension& cricket_extension : cricket_extensions) {
  446. rtp_parameters.header_extensions.emplace_back(cricket_extension.uri,
  447. cricket_extension.id);
  448. }
  449. rtp_parameters.encodings = ToRtpEncodings(stream_params);
  450. return rtp_parameters;
  451. }
  452. template RtpParameters ToRtpParameters<cricket::AudioCodec>(
  453. const std::vector<cricket::AudioCodec>& cricket_codecs,
  454. const cricket::RtpHeaderExtensions& cricket_extensions,
  455. const cricket::StreamParamsVec& stream_params);
  456. template RtpParameters ToRtpParameters<cricket::VideoCodec>(
  457. const std::vector<cricket::VideoCodec>& cricket_codecs,
  458. const cricket::RtpHeaderExtensions& cricket_extensions,
  459. const cricket::StreamParamsVec& stream_params);
  460. } // namespace webrtc