OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 for (std::vector<std::string>::const_iterator it = crypto_suites.begin(); | 181 for (std::vector<std::string>::const_iterator it = crypto_suites.begin(); |
182 it != crypto_suites.end(); ++it) { | 182 it != crypto_suites.end(); ++it) { |
183 if (!AddCryptoParams(*it, &cryptos)) { | 183 if (!AddCryptoParams(*it, &cryptos)) { |
184 return false; | 184 return false; |
185 } | 185 } |
186 } | 186 } |
187 AddMediaCryptos(cryptos, media); | 187 AddMediaCryptos(cryptos, media); |
188 return true; | 188 return true; |
189 } | 189 } |
190 | 190 |
191 const CryptoParamsVec* GetCryptos(const MediaContentDescription* media) { | 191 const CryptoParamsVec* GetCryptos(const ContentInfo* content) { |
192 if (!media) { | 192 if (!content) { |
193 return NULL; | 193 return nullptr; |
194 } | 194 } |
195 return &media->cryptos(); | 195 |
| 196 RTC_DCHECK(IsMediaContent(content)); |
| 197 return &(static_cast<const MediaContentDescription*>(content->description) |
| 198 ->cryptos()); |
196 } | 199 } |
197 | 200 |
198 bool FindMatchingCrypto(const CryptoParamsVec& cryptos, | 201 bool FindMatchingCrypto(const CryptoParamsVec& cryptos, |
199 const CryptoParams& crypto, | 202 const CryptoParams& crypto, |
200 CryptoParams* out) { | 203 CryptoParams* out) { |
201 for (CryptoParamsVec::const_iterator it = cryptos.begin(); | 204 for (CryptoParamsVec::const_iterator it = cryptos.begin(); |
202 it != cryptos.end(); ++it) { | 205 it != cryptos.end(); ++it) { |
203 if (crypto.Matches(*it)) { | 206 if (crypto.Matches(*it)) { |
204 *out = *it; | 207 *out = *it; |
205 return true; | 208 return true; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 // audio and video extensions. | 424 // audio and video extensions. |
422 class UsedRtpHeaderExtensionIds : public UsedIds<webrtc::RtpExtension> { | 425 class UsedRtpHeaderExtensionIds : public UsedIds<webrtc::RtpExtension> { |
423 public: | 426 public: |
424 UsedRtpHeaderExtensionIds() | 427 UsedRtpHeaderExtensionIds() |
425 : UsedIds<webrtc::RtpExtension>(webrtc::RtpExtension::kMinId, | 428 : UsedIds<webrtc::RtpExtension>(webrtc::RtpExtension::kMinId, |
426 webrtc::RtpExtension::kMaxId) {} | 429 webrtc::RtpExtension::kMaxId) {} |
427 | 430 |
428 private: | 431 private: |
429 }; | 432 }; |
430 | 433 |
431 // Adds a StreamParams for each Stream in Streams with media type | 434 // Adds a StreamParams for each SenderOptions in |sender_options| to |
432 // media_type to content_description. | 435 // content_description. |
433 // |current_params| - All currently known StreamParams of any media type. | 436 // |current_params| - All currently known StreamParams of any media type. |
434 template <class C> | 437 template <class C> |
435 static bool AddStreamParams(MediaType media_type, | 438 static bool AddStreamParams( |
436 const MediaSessionOptions& options, | 439 const std::vector<SenderOptions>& sender_options, |
437 StreamParamsVec* current_streams, | 440 const std::string& rtcp_cname, |
438 MediaContentDescriptionImpl<C>* content_description, | 441 StreamParamsVec* current_streams, |
439 const bool add_legacy_stream) { | 442 MediaContentDescriptionImpl<C>* content_description) { |
440 // SCTP streams are not negotiated using SDP/ContentDescriptions. | 443 // SCTP streams are not negotiated using SDP/ContentDescriptions. |
441 if (IsSctp(content_description->protocol())) { | 444 if (IsSctp(content_description->protocol())) { |
442 return true; | 445 return true; |
443 } | 446 } |
444 | 447 |
445 const bool include_rtx_streams = | 448 const bool include_rtx_streams = |
446 ContainsRtxCodec(content_description->codecs()); | 449 ContainsRtxCodec(content_description->codecs()); |
447 | 450 |
448 const MediaSessionOptions::Streams& streams = options.streams; | |
449 if (streams.empty() && add_legacy_stream) { | |
450 // TODO(perkj): Remove this legacy stream when all apps use StreamParams. | |
451 std::vector<uint32_t> ssrcs; | |
452 int num_ssrcs = include_rtx_streams ? 2 : 1; | |
453 GenerateSsrcs(*current_streams, num_ssrcs, &ssrcs); | |
454 if (include_rtx_streams) { | |
455 content_description->AddLegacyStream(ssrcs[0], ssrcs[1]); | |
456 content_description->set_multistream(true); | |
457 } else { | |
458 content_description->AddLegacyStream(ssrcs[0]); | |
459 } | |
460 return true; | |
461 } | |
462 | 451 |
463 const bool include_flexfec_stream = | 452 const bool include_flexfec_stream = |
464 ContainsFlexfecCodec(content_description->codecs()); | 453 ContainsFlexfecCodec(content_description->codecs()); |
465 | 454 |
466 MediaSessionOptions::Streams::const_iterator stream_it; | 455 for (const SenderOptions& sender : sender_options) { |
467 for (stream_it = streams.begin(); | |
468 stream_it != streams.end(); ++stream_it) { | |
469 if (stream_it->type != media_type) | |
470 continue; // Wrong media type. | |
471 | |
472 StreamParams* param = GetStreamByIds(*current_streams, "", stream_it->id); | |
473 // groupid is empty for StreamParams generated using | 456 // groupid is empty for StreamParams generated using |
474 // MediaSessionDescriptionFactory. | 457 // MediaSessionDescriptionFactory. |
| 458 StreamParams* param = |
| 459 GetStreamByIds(*current_streams, "" /*group_id*/, sender.track_id); |
475 if (!param) { | 460 if (!param) { |
476 // This is a new stream. | 461 // This is a new sender. |
477 std::vector<uint32_t> ssrcs; | 462 std::vector<uint32_t> ssrcs; |
478 GenerateSsrcs(*current_streams, stream_it->num_sim_layers, &ssrcs); | 463 GenerateSsrcs(*current_streams, sender.num_sim_layers, &ssrcs); |
479 StreamParams stream_param; | 464 StreamParams stream_param; |
480 stream_param.id = stream_it->id; | 465 stream_param.id = sender.track_id; |
481 // Add the generated ssrc. | 466 // Add the generated ssrc. |
482 for (size_t i = 0; i < ssrcs.size(); ++i) { | 467 for (size_t i = 0; i < ssrcs.size(); ++i) { |
483 stream_param.ssrcs.push_back(ssrcs[i]); | 468 stream_param.ssrcs.push_back(ssrcs[i]); |
484 } | 469 } |
485 if (stream_it->num_sim_layers > 1) { | 470 if (sender.num_sim_layers > 1) { |
486 SsrcGroup group(kSimSsrcGroupSemantics, stream_param.ssrcs); | 471 SsrcGroup group(kSimSsrcGroupSemantics, stream_param.ssrcs); |
487 stream_param.ssrc_groups.push_back(group); | 472 stream_param.ssrc_groups.push_back(group); |
488 } | 473 } |
489 // Generate extra ssrcs for include_rtx_streams case. | 474 // Generate extra ssrcs for include_rtx_streams case. |
490 if (include_rtx_streams) { | 475 if (include_rtx_streams) { |
491 // Generate an RTX ssrc for every ssrc in the group. | 476 // Generate an RTX ssrc for every ssrc in the group. |
492 std::vector<uint32_t> rtx_ssrcs; | 477 std::vector<uint32_t> rtx_ssrcs; |
493 GenerateSsrcs(*current_streams, static_cast<int>(ssrcs.size()), | 478 GenerateSsrcs(*current_streams, static_cast<int>(ssrcs.size()), |
494 &rtx_ssrcs); | 479 &rtx_ssrcs); |
495 for (size_t i = 0; i < ssrcs.size(); ++i) { | 480 for (size_t i = 0; i < ssrcs.size(); ++i) { |
496 stream_param.AddFidSsrc(ssrcs[i], rtx_ssrcs[i]); | 481 stream_param.AddFidSsrc(ssrcs[i], rtx_ssrcs[i]); |
497 } | 482 } |
498 content_description->set_multistream(true); | 483 content_description->set_multistream(true); |
499 } | 484 } |
500 // Generate extra ssrc for include_flexfec_stream case. | 485 // Generate extra ssrc for include_flexfec_stream case. |
501 if (include_flexfec_stream) { | 486 if (include_flexfec_stream) { |
502 // TODO(brandtr): Update when we support multistream protection. | 487 // TODO(brandtr): Update when we support multistream protection. |
503 if (ssrcs.size() == 1) { | 488 if (ssrcs.size() == 1) { |
504 std::vector<uint32_t> flexfec_ssrcs; | 489 std::vector<uint32_t> flexfec_ssrcs; |
505 GenerateSsrcs(*current_streams, 1, &flexfec_ssrcs); | 490 GenerateSsrcs(*current_streams, 1, &flexfec_ssrcs); |
506 stream_param.AddFecFrSsrc(ssrcs[0], flexfec_ssrcs[0]); | 491 stream_param.AddFecFrSsrc(ssrcs[0], flexfec_ssrcs[0]); |
507 content_description->set_multistream(true); | 492 content_description->set_multistream(true); |
508 } else if (!ssrcs.empty()) { | 493 } else if (!ssrcs.empty()) { |
509 LOG(LS_WARNING) | 494 LOG(LS_WARNING) |
510 << "Our FlexFEC implementation only supports protecting " | 495 << "Our FlexFEC implementation only supports protecting " |
511 << "a single media streams. This session has multiple " | 496 << "a single media streams. This session has multiple " |
512 << "media streams however, so no FlexFEC SSRC will be generated."; | 497 << "media streams however, so no FlexFEC SSRC will be generated."; |
513 } | 498 } |
514 } | 499 } |
515 stream_param.cname = options.rtcp_cname; | 500 stream_param.cname = rtcp_cname; |
516 stream_param.sync_label = stream_it->sync_label; | 501 stream_param.sync_label = sender.stream_id; |
517 content_description->AddStream(stream_param); | 502 content_description->AddStream(stream_param); |
518 | 503 |
519 // Store the new StreamParams in current_streams. | 504 // Store the new StreamParams in current_streams. |
520 // This is necessary so that we can use the CNAME for other media types. | 505 // This is necessary so that we can use the CNAME for other media types. |
521 current_streams->push_back(stream_param); | 506 current_streams->push_back(stream_param); |
522 } else { | 507 } else { |
523 // Use existing generated SSRCs/groups, but update the sync_label if | 508 // Use existing generated SSRCs/groups, but update the sync_label if |
524 // necessary. This may be needed if a MediaStreamTrack was moved from one | 509 // necessary. This may be needed if a MediaStreamTrack was moved from one |
525 // MediaStream to another. | 510 // MediaStream to another. |
526 param->sync_label = stream_it->sync_label; | 511 param->sync_label = sender.stream_id; |
527 content_description->AddStream(*param); | 512 content_description->AddStream(*param); |
528 } | 513 } |
529 } | 514 } |
530 return true; | 515 return true; |
531 } | 516 } |
532 | 517 |
533 // Updates the transport infos of the |sdesc| according to the given | 518 // Updates the transport infos of the |sdesc| according to the given |
534 // |bundle_group|. The transport infos of the content names within the | 519 // |bundle_group|. The transport infos of the content names within the |
535 // |bundle_group| should be updated to use the ufrag, pwd and DTLS role of the | 520 // |bundle_group| should be updated to use the ufrag, pwd and DTLS role of the |
536 // first content within the |bundle_group|. | 521 // first content within the |bundle_group|. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 } | 713 } |
729 } | 714 } |
730 return false; | 715 return false; |
731 } | 716 } |
732 | 717 |
733 template <class C> | 718 template <class C> |
734 static bool IsFlexfecCodec(const C& codec) { | 719 static bool IsFlexfecCodec(const C& codec) { |
735 return STR_CASE_CMP(codec.name.c_str(), kFlexfecCodecName) == 0; | 720 return STR_CASE_CMP(codec.name.c_str(), kFlexfecCodecName) == 0; |
736 } | 721 } |
737 | 722 |
738 static TransportOptions GetTransportOptions(const MediaSessionOptions& options, | 723 // Create a media content to be offered for the given |sender_options|, |
739 const std::string& content_name) { | 724 // according to the given options.rtcp_mux, session_options.is_muc, codecs, |
740 TransportOptions transport_options; | 725 // secure_transport, crypto, and current_streams. If we don't currently have |
741 auto it = options.transport_options.find(content_name); | 726 // crypto (in current_cryptos) and it is enabled (in secure_policy), crypto is |
742 if (it != options.transport_options.end()) { | 727 // created (according to crypto_suites). The created content is added to the |
743 transport_options = it->second; | 728 // offer. |
744 } | |
745 transport_options.enable_ice_renomination = options.enable_ice_renomination; | |
746 return transport_options; | |
747 } | |
748 | |
749 // Create a media content to be offered in a session-initiate, | |
750 // according to the given options.rtcp_mux, options.is_muc, | |
751 // options.streams, codecs, secure_transport, crypto, and streams. If we don't | |
752 // currently have crypto (in current_cryptos) and it is enabled (in | |
753 // secure_policy), crypto is created (according to crypto_suites). If | |
754 // add_legacy_stream is true, and current_streams is empty, a legacy | |
755 // stream is created. The created content is added to the offer. | |
756 template <class C> | 729 template <class C> |
757 static bool CreateMediaContentOffer( | 730 static bool CreateMediaContentOffer( |
758 const MediaSessionOptions& options, | 731 const std::vector<SenderOptions>& sender_options, |
| 732 const MediaSessionOptions& session_options, |
759 const std::vector<C>& codecs, | 733 const std::vector<C>& codecs, |
760 const SecurePolicy& secure_policy, | 734 const SecurePolicy& secure_policy, |
761 const CryptoParamsVec* current_cryptos, | 735 const CryptoParamsVec* current_cryptos, |
762 const std::vector<std::string>& crypto_suites, | 736 const std::vector<std::string>& crypto_suites, |
763 const RtpHeaderExtensions& rtp_extensions, | 737 const RtpHeaderExtensions& rtp_extensions, |
764 bool add_legacy_stream, | |
765 StreamParamsVec* current_streams, | 738 StreamParamsVec* current_streams, |
766 MediaContentDescriptionImpl<C>* offer) { | 739 MediaContentDescriptionImpl<C>* offer) { |
767 offer->AddCodecs(codecs); | 740 offer->AddCodecs(codecs); |
768 | 741 |
769 offer->set_rtcp_mux(options.rtcp_mux_enabled); | 742 offer->set_rtcp_mux(session_options.rtcp_mux_enabled); |
770 if (offer->type() == cricket::MEDIA_TYPE_VIDEO) { | 743 if (offer->type() == cricket::MEDIA_TYPE_VIDEO) { |
771 offer->set_rtcp_reduced_size(true); | 744 offer->set_rtcp_reduced_size(true); |
772 } | 745 } |
773 offer->set_multistream(options.is_muc); | 746 offer->set_multistream(session_options.is_muc); |
774 offer->set_rtp_header_extensions(rtp_extensions); | 747 offer->set_rtp_header_extensions(rtp_extensions); |
775 | 748 |
776 if (!AddStreamParams(offer->type(), options, current_streams, offer, | 749 if (!AddStreamParams(sender_options, session_options.rtcp_cname, |
777 add_legacy_stream)) { | 750 current_streams, offer)) { |
778 return false; | 751 return false; |
779 } | 752 } |
780 | 753 |
781 if (secure_policy != SEC_DISABLED) { | 754 if (secure_policy != SEC_DISABLED) { |
782 if (current_cryptos) { | 755 if (current_cryptos) { |
783 AddMediaCryptos(*current_cryptos, offer); | 756 AddMediaCryptos(*current_cryptos, offer); |
784 } | 757 } |
785 if (offer->cryptos().empty()) { | 758 if (offer->cryptos().empty()) { |
786 if (!CreateMediaCryptos(crypto_suites, offer)) { | 759 if (!CreateMediaCryptos(crypto_suites, offer)) { |
787 return false; | 760 return false; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 } | 848 } |
876 if (found_codec) { | 849 if (found_codec) { |
877 *found_codec = potential_match; | 850 *found_codec = potential_match; |
878 } | 851 } |
879 return true; | 852 return true; |
880 } | 853 } |
881 } | 854 } |
882 return false; | 855 return false; |
883 } | 856 } |
884 | 857 |
885 // Adds all codecs from |reference_codecs| to |offered_codecs| that dont' | 858 // Find the codec in |codec_list| that |rtx_codec| is associated with. |
| 859 template <class C> |
| 860 static const C* GetAssociatedCodec(const std::vector<C>& codec_list, |
| 861 const C& rtx_codec) { |
| 862 std::string associated_pt_str; |
| 863 if (!rtx_codec.GetParam(kCodecParamAssociatedPayloadType, |
| 864 &associated_pt_str)) { |
| 865 LOG(LS_WARNING) << "RTX codec " << rtx_codec.name |
| 866 << " is missing an associated payload type."; |
| 867 return nullptr; |
| 868 } |
| 869 |
| 870 int associated_pt; |
| 871 if (!rtc::FromString(associated_pt_str, &associated_pt)) { |
| 872 LOG(LS_WARNING) << "Couldn't convert payload type " << associated_pt_str |
| 873 << " of RTX codec " << rtx_codec.name << " to an integer."; |
| 874 return nullptr; |
| 875 } |
| 876 |
| 877 // Find the associated reference codec for the reference RTX codec. |
| 878 const C* associated_codec = FindCodecById(codec_list, associated_pt); |
| 879 if (!associated_codec) { |
| 880 LOG(LS_WARNING) << "Couldn't find associated codec with payload type " |
| 881 << associated_pt << " for RTX codec " << rtx_codec.name |
| 882 << "."; |
| 883 } |
| 884 return associated_codec; |
| 885 } |
| 886 |
| 887 // Adds all codecs from |reference_codecs| to |offered_codecs| that don't |
886 // already exist in |offered_codecs| and ensure the payload types don't | 888 // already exist in |offered_codecs| and ensure the payload types don't |
887 // collide. | 889 // collide. |
888 template <class C> | 890 template <class C> |
889 static void FindCodecsToOffer( | 891 static void MergeCodecs(const std::vector<C>& reference_codecs, |
890 const std::vector<C>& reference_codecs, | 892 std::vector<C>* offered_codecs, |
891 std::vector<C>* offered_codecs, | 893 UsedPayloadTypes* used_pltypes) { |
892 UsedPayloadTypes* used_pltypes) { | |
893 | |
894 // Add all new codecs that are not RTX codecs. | 894 // Add all new codecs that are not RTX codecs. |
895 for (const C& reference_codec : reference_codecs) { | 895 for (const C& reference_codec : reference_codecs) { |
896 if (!IsRtxCodec(reference_codec) && | 896 if (!IsRtxCodec(reference_codec) && |
897 !FindMatchingCodec<C>(reference_codecs, *offered_codecs, | 897 !FindMatchingCodec<C>(reference_codecs, *offered_codecs, |
898 reference_codec, nullptr)) { | 898 reference_codec, nullptr)) { |
899 C codec = reference_codec; | 899 C codec = reference_codec; |
900 used_pltypes->FindAndSetIdUsed(&codec); | 900 used_pltypes->FindAndSetIdUsed(&codec); |
901 offered_codecs->push_back(codec); | 901 offered_codecs->push_back(codec); |
902 } | 902 } |
903 } | 903 } |
904 | 904 |
905 // Add all new RTX codecs. | 905 // Add all new RTX codecs. |
906 for (const C& reference_codec : reference_codecs) { | 906 for (const C& reference_codec : reference_codecs) { |
907 if (IsRtxCodec(reference_codec) && | 907 if (IsRtxCodec(reference_codec) && |
908 !FindMatchingCodec<C>(reference_codecs, *offered_codecs, | 908 !FindMatchingCodec<C>(reference_codecs, *offered_codecs, |
909 reference_codec, nullptr)) { | 909 reference_codec, nullptr)) { |
910 C rtx_codec = reference_codec; | 910 C rtx_codec = reference_codec; |
911 | 911 const C* associated_codec = |
912 std::string associated_pt_str; | 912 GetAssociatedCodec(reference_codecs, rtx_codec); |
913 if (!rtx_codec.GetParam(kCodecParamAssociatedPayloadType, | 913 if (!associated_codec) { |
914 &associated_pt_str)) { | |
915 LOG(LS_WARNING) << "RTX codec " << rtx_codec.name | |
916 << " is missing an associated payload type."; | |
917 continue; | 914 continue; |
918 } | 915 } |
919 | |
920 int associated_pt; | |
921 if (!rtc::FromString(associated_pt_str, &associated_pt)) { | |
922 LOG(LS_WARNING) << "Couldn't convert payload type " << associated_pt_str | |
923 << " of RTX codec " << rtx_codec.name | |
924 << " to an integer."; | |
925 continue; | |
926 } | |
927 | |
928 // Find the associated reference codec for the reference RTX codec. | |
929 const C* associated_codec = | |
930 FindCodecById(reference_codecs, associated_pt); | |
931 if (!associated_codec) { | |
932 LOG(LS_WARNING) << "Couldn't find associated codec with payload type " | |
933 << associated_pt << " for RTX codec " << rtx_codec.name | |
934 << "."; | |
935 continue; | |
936 } | |
937 | |
938 // Find a codec in the offered list that matches the reference codec. | 916 // Find a codec in the offered list that matches the reference codec. |
939 // Its payload type may be different than the reference codec. | 917 // Its payload type may be different than the reference codec. |
940 C matching_codec; | 918 C matching_codec; |
941 if (!FindMatchingCodec<C>(reference_codecs, *offered_codecs, | 919 if (!FindMatchingCodec<C>(reference_codecs, *offered_codecs, |
942 *associated_codec, &matching_codec)) { | 920 *associated_codec, &matching_codec)) { |
943 LOG(LS_WARNING) << "Couldn't find matching " << associated_codec->name | 921 LOG(LS_WARNING) << "Couldn't find matching " << associated_codec->name |
944 << " codec."; | 922 << " codec."; |
945 continue; | 923 continue; |
946 } | 924 } |
947 | 925 |
948 rtx_codec.params[kCodecParamAssociatedPayloadType] = | 926 rtx_codec.params[kCodecParamAssociatedPayloadType] = |
949 rtc::ToString(matching_codec.id); | 927 rtc::ToString(matching_codec.id); |
950 used_pltypes->FindAndSetIdUsed(&rtx_codec); | 928 used_pltypes->FindAndSetIdUsed(&rtx_codec); |
951 offered_codecs->push_back(rtx_codec); | 929 offered_codecs->push_back(rtx_codec); |
952 } | 930 } |
953 } | 931 } |
954 } | 932 } |
955 | 933 |
| 934 static bool FindByUriAndEncryption(const RtpHeaderExtensions& extensions, |
| 935 const webrtc::RtpExtension& ext_to_match, |
| 936 webrtc::RtpExtension* found_extension) { |
| 937 for (RtpHeaderExtensions::const_iterator it = extensions.begin(); |
| 938 it != extensions.end(); ++it) { |
| 939 // We assume that all URIs are given in a canonical format. |
| 940 if (it->uri == ext_to_match.uri && it->encrypt == ext_to_match.encrypt) { |
| 941 if (found_extension) { |
| 942 *found_extension = *it; |
| 943 } |
| 944 return true; |
| 945 } |
| 946 } |
| 947 return false; |
| 948 } |
| 949 |
956 static bool FindByUri(const RtpHeaderExtensions& extensions, | 950 static bool FindByUri(const RtpHeaderExtensions& extensions, |
957 const webrtc::RtpExtension& ext_to_match, | 951 const webrtc::RtpExtension& ext_to_match, |
958 webrtc::RtpExtension* found_extension) { | 952 webrtc::RtpExtension* found_extension) { |
959 // We assume that all URIs are given in a canonical format. | 953 // We assume that all URIs are given in a canonical format. |
960 const webrtc::RtpExtension* found = | 954 const webrtc::RtpExtension* found = |
961 webrtc::RtpExtension::FindHeaderExtensionByUri(extensions, | 955 webrtc::RtpExtension::FindHeaderExtensionByUri(extensions, |
962 ext_to_match.uri); | 956 ext_to_match.uri); |
963 if (!found) { | 957 if (!found) { |
964 return false; | 958 return false; |
965 } | 959 } |
(...skipping 23 matching lines...) Expand all Loading... |
989 } | 983 } |
990 if (unencrypted_extension) { | 984 if (unencrypted_extension) { |
991 if (found_extension) { | 985 if (found_extension) { |
992 *found_extension = *unencrypted_extension; | 986 *found_extension = *unencrypted_extension; |
993 } | 987 } |
994 return true; | 988 return true; |
995 } | 989 } |
996 return false; | 990 return false; |
997 } | 991 } |
998 | 992 |
999 // Iterates through |offered_extensions|, adding each one to | 993 // Adds all extensions from |reference_extensions| to |offered_extensions| that |
1000 // |regular_extensions| (or |encrypted_extensions| if encrypted) and |used_ids|, | 994 // don't already exist in |offered_extensions| and ensure the IDs don't |
1001 // and resolving ID conflicts. | 995 // collide. If an extension is added, it's also added to |regular_extensions| or |
1002 // If an offered extension has the same URI as one in |regular_extensions| or | 996 // |encrypted_extensions|, and if the extension is in |regular_extensions| or |
1003 // |encrypted_extensions|, it will re-use the same ID and won't be treated as | 997 // |encrypted_extensions|, its ID is marked as used in |used_ids|. |
1004 // a conflict. | 998 // |offered_extensions| is for either audio or video while |regular_extensions| |
1005 static void FindAndSetRtpHdrExtUsed(RtpHeaderExtensions* offered_extensions, | 999 // and |encrypted_extensions| are used for both audio and video. There could be |
1006 RtpHeaderExtensions* regular_extensions, | 1000 // overlap between audio extensions and video extensions. |
1007 RtpHeaderExtensions* encrypted_extensions, | 1001 static void MergeRtpHdrExts(const RtpHeaderExtensions& reference_extensions, |
1008 UsedRtpHeaderExtensionIds* used_ids) { | 1002 RtpHeaderExtensions* offered_extensions, |
1009 for (auto& extension : *offered_extensions) { | 1003 RtpHeaderExtensions* regular_extensions, |
1010 webrtc::RtpExtension existing; | 1004 RtpHeaderExtensions* encrypted_extensions, |
1011 if ((extension.encrypt && | 1005 UsedRtpHeaderExtensionIds* used_ids) { |
1012 FindByUri(*encrypted_extensions, extension, &existing)) || | 1006 for (auto reference_extension : reference_extensions) { |
1013 (!extension.encrypt && | 1007 if (!FindByUriAndEncryption(*offered_extensions, reference_extension, |
1014 FindByUri(*regular_extensions, extension, &existing))) { | 1008 nullptr)) { |
1015 extension.id = existing.id; | 1009 webrtc::RtpExtension existing; |
1016 } else { | 1010 if (reference_extension.encrypt) { |
1017 used_ids->FindAndSetIdUsed(&extension); | 1011 if (FindByUriAndEncryption(*encrypted_extensions, reference_extension, |
1018 if (extension.encrypt) { | 1012 &existing)) { |
1019 encrypted_extensions->push_back(extension); | 1013 offered_extensions->push_back(existing); |
| 1014 } else { |
| 1015 used_ids->FindAndSetIdUsed(&reference_extension); |
| 1016 encrypted_extensions->push_back(reference_extension); |
| 1017 offered_extensions->push_back(reference_extension); |
| 1018 } |
1020 } else { | 1019 } else { |
1021 regular_extensions->push_back(extension); | 1020 if (FindByUriAndEncryption(*regular_extensions, reference_extension, |
| 1021 &existing)) { |
| 1022 offered_extensions->push_back(existing); |
| 1023 } else { |
| 1024 used_ids->FindAndSetIdUsed(&reference_extension); |
| 1025 regular_extensions->push_back(reference_extension); |
| 1026 offered_extensions->push_back(reference_extension); |
| 1027 } |
1022 } | 1028 } |
1023 } | 1029 } |
1024 } | 1030 } |
1025 } | |
1026 | |
1027 // Adds |reference_extensions| to |offered_extensions|, while updating | |
1028 // |all_extensions| and |used_ids|. | |
1029 static void FindRtpHdrExtsToOffer( | |
1030 const RtpHeaderExtensions& reference_extensions, | |
1031 RtpHeaderExtensions* offered_extensions, | |
1032 RtpHeaderExtensions* all_extensions, | |
1033 UsedRtpHeaderExtensionIds* used_ids) { | |
1034 for (auto reference_extension : reference_extensions) { | |
1035 if (!FindByUri(*offered_extensions, reference_extension, NULL)) { | |
1036 webrtc::RtpExtension existing; | |
1037 if (FindByUri(*all_extensions, reference_extension, &existing)) { | |
1038 offered_extensions->push_back(existing); | |
1039 } else { | |
1040 used_ids->FindAndSetIdUsed(&reference_extension); | |
1041 all_extensions->push_back(reference_extension); | |
1042 offered_extensions->push_back(reference_extension); | |
1043 } | |
1044 } | |
1045 } | |
1046 } | 1031 } |
1047 | 1032 |
1048 static void AddEncryptedVersionsOfHdrExts(RtpHeaderExtensions* extensions, | 1033 static void AddEncryptedVersionsOfHdrExts(RtpHeaderExtensions* extensions, |
1049 RtpHeaderExtensions* all_extensions, | 1034 RtpHeaderExtensions* all_extensions, |
1050 UsedRtpHeaderExtensionIds* used_ids) { | 1035 UsedRtpHeaderExtensionIds* used_ids) { |
1051 RtpHeaderExtensions encrypted_extensions; | 1036 RtpHeaderExtensions encrypted_extensions; |
1052 for (const webrtc::RtpExtension& extension : *extensions) { | 1037 for (const webrtc::RtpExtension& extension : *extensions) { |
1053 webrtc::RtpExtension existing; | 1038 webrtc::RtpExtension existing; |
1054 // Don't add encrypted extensions again that were already included in a | 1039 // Don't add encrypted extensions again that were already included in a |
1055 // previous offer or regular extensions that are also included as encrypted | 1040 // previous offer or regular extensions that are also included as encrypted |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 AudioCodecs::iterator iter = audio_codecs->begin(); | 1081 AudioCodecs::iterator iter = audio_codecs->begin(); |
1097 while (iter != audio_codecs->end()) { | 1082 while (iter != audio_codecs->end()) { |
1098 if (STR_CASE_CMP(iter->name.c_str(), kComfortNoiseCodecName) == 0) { | 1083 if (STR_CASE_CMP(iter->name.c_str(), kComfortNoiseCodecName) == 0) { |
1099 iter = audio_codecs->erase(iter); | 1084 iter = audio_codecs->erase(iter); |
1100 } else { | 1085 } else { |
1101 ++iter; | 1086 ++iter; |
1102 } | 1087 } |
1103 } | 1088 } |
1104 } | 1089 } |
1105 | 1090 |
1106 // Create a media content to be answered in a session-accept, | 1091 // Create a media content to be answered for the given |sender_options| |
1107 // according to the given options.rtcp_mux, options.streams, codecs, | 1092 // according to the given session_options.rtcp_mux, session_options.streams, |
1108 // crypto, and streams. If we don't currently have crypto (in | 1093 // codecs, crypto, and current_streams. If we don't currently have crypto (in |
1109 // current_cryptos) and it is enabled (in secure_policy), crypto is | 1094 // current_cryptos) and it is enabled (in secure_policy), crypto is created |
1110 // created (according to crypto_suites). If add_legacy_stream is | 1095 // (according to crypto_suites). The codecs, rtcp_mux, and crypto are all |
1111 // true, and current_streams is empty, a legacy stream is created. | 1096 // negotiated with the offer. If the negotiation fails, this method returns |
1112 // The codecs, rtcp_mux, and crypto are all negotiated with the offer | 1097 // false. The created content is added to the offer. |
1113 // from the incoming session-initiate. If the negotiation fails, this | |
1114 // method returns false. The created content is added to the offer. | |
1115 template <class C> | 1098 template <class C> |
1116 static bool CreateMediaContentAnswer( | 1099 static bool CreateMediaContentAnswer( |
1117 const MediaContentDescriptionImpl<C>* offer, | 1100 const MediaContentDescriptionImpl<C>* offer, |
1118 const MediaSessionOptions& options, | 1101 const MediaDescriptionOptions& media_description_options, |
| 1102 const MediaSessionOptions& session_options, |
1119 const std::vector<C>& local_codecs, | 1103 const std::vector<C>& local_codecs, |
1120 const SecurePolicy& sdes_policy, | 1104 const SecurePolicy& sdes_policy, |
1121 const CryptoParamsVec* current_cryptos, | 1105 const CryptoParamsVec* current_cryptos, |
1122 const RtpHeaderExtensions& local_rtp_extenstions, | 1106 const RtpHeaderExtensions& local_rtp_extenstions, |
1123 bool enable_encrypted_rtp_header_extensions, | 1107 bool enable_encrypted_rtp_header_extensions, |
1124 StreamParamsVec* current_streams, | 1108 StreamParamsVec* current_streams, |
1125 bool add_legacy_stream, | |
1126 bool bundle_enabled, | 1109 bool bundle_enabled, |
1127 MediaContentDescriptionImpl<C>* answer) { | 1110 MediaContentDescriptionImpl<C>* answer) { |
1128 std::vector<C> negotiated_codecs; | 1111 std::vector<C> negotiated_codecs; |
1129 NegotiateCodecs(local_codecs, offer->codecs(), &negotiated_codecs); | 1112 NegotiateCodecs(local_codecs, offer->codecs(), &negotiated_codecs); |
1130 answer->AddCodecs(negotiated_codecs); | 1113 answer->AddCodecs(negotiated_codecs); |
1131 answer->set_protocol(offer->protocol()); | 1114 answer->set_protocol(offer->protocol()); |
1132 RtpHeaderExtensions negotiated_rtp_extensions; | 1115 RtpHeaderExtensions negotiated_rtp_extensions; |
1133 NegotiateRtpHeaderExtensions(local_rtp_extenstions, | 1116 NegotiateRtpHeaderExtensions(local_rtp_extenstions, |
1134 offer->rtp_header_extensions(), | 1117 offer->rtp_header_extensions(), |
1135 enable_encrypted_rtp_header_extensions, | 1118 enable_encrypted_rtp_header_extensions, |
1136 &negotiated_rtp_extensions); | 1119 &negotiated_rtp_extensions); |
1137 answer->set_rtp_header_extensions(negotiated_rtp_extensions); | 1120 answer->set_rtp_header_extensions(negotiated_rtp_extensions); |
1138 | 1121 |
1139 answer->set_rtcp_mux(options.rtcp_mux_enabled && offer->rtcp_mux()); | 1122 answer->set_rtcp_mux(session_options.rtcp_mux_enabled && offer->rtcp_mux()); |
1140 if (answer->type() == cricket::MEDIA_TYPE_VIDEO) { | 1123 if (answer->type() == cricket::MEDIA_TYPE_VIDEO) { |
1141 answer->set_rtcp_reduced_size(offer->rtcp_reduced_size()); | 1124 answer->set_rtcp_reduced_size(offer->rtcp_reduced_size()); |
1142 } | 1125 } |
1143 | 1126 |
1144 if (sdes_policy != SEC_DISABLED) { | 1127 if (sdes_policy != SEC_DISABLED) { |
1145 CryptoParams crypto; | 1128 CryptoParams crypto; |
1146 if (SelectCrypto(offer, bundle_enabled, options.crypto_options, &crypto)) { | 1129 if (SelectCrypto(offer, bundle_enabled, session_options.crypto_options, |
| 1130 &crypto)) { |
1147 if (current_cryptos) { | 1131 if (current_cryptos) { |
1148 FindMatchingCrypto(*current_cryptos, crypto, &crypto); | 1132 FindMatchingCrypto(*current_cryptos, crypto, &crypto); |
1149 } | 1133 } |
1150 answer->AddCrypto(crypto); | 1134 answer->AddCrypto(crypto); |
1151 } | 1135 } |
1152 } | 1136 } |
1153 | 1137 |
1154 if (answer->cryptos().empty() && sdes_policy == SEC_REQUIRED) { | 1138 if (answer->cryptos().empty() && sdes_policy == SEC_REQUIRED) { |
1155 return false; | 1139 return false; |
1156 } | 1140 } |
1157 | 1141 |
1158 if (!AddStreamParams(answer->type(), options, current_streams, answer, | 1142 if (!AddStreamParams(media_description_options.sender_options, |
1159 add_legacy_stream)) { | 1143 session_options.rtcp_cname, current_streams, answer)) { |
1160 return false; // Something went seriously wrong. | 1144 return false; // Something went seriously wrong. |
1161 } | 1145 } |
1162 | 1146 |
1163 // Make sure the answer media content direction is per default set as | |
1164 // described in RFC3264 section 6.1. | |
1165 const bool is_data = !IsRtpProtocol(answer->protocol()); | |
1166 const bool has_send_streams = !answer->streams().empty(); | |
1167 const bool wants_send = has_send_streams || is_data; | |
1168 const bool recv_audio = | |
1169 answer->type() == cricket::MEDIA_TYPE_AUDIO && options.recv_audio; | |
1170 const bool recv_video = | |
1171 answer->type() == cricket::MEDIA_TYPE_VIDEO && options.recv_video; | |
1172 const bool recv_data = | |
1173 answer->type() == cricket::MEDIA_TYPE_DATA; | |
1174 const bool wants_receive = recv_audio || recv_video || recv_data; | |
1175 | |
1176 auto offer_rtd = | 1147 auto offer_rtd = |
1177 RtpTransceiverDirection::FromMediaContentDirection(offer->direction()); | 1148 RtpTransceiverDirection::FromMediaContentDirection(offer->direction()); |
1178 auto wants_rtd = RtpTransceiverDirection(wants_send, wants_receive); | 1149 |
1179 answer->set_direction(NegotiateRtpTransceiverDirection(offer_rtd, wants_rtd) | 1150 answer->set_direction(NegotiateRtpTransceiverDirection( |
1180 .ToMediaContentDirection()); | 1151 offer_rtd, media_description_options.direction) |
| 1152 .ToMediaContentDirection()); |
1181 return true; | 1153 return true; |
1182 } | 1154 } |
1183 | 1155 |
1184 static bool IsMediaProtocolSupported(MediaType type, | 1156 static bool IsMediaProtocolSupported(MediaType type, |
1185 const std::string& protocol, | 1157 const std::string& protocol, |
1186 bool secure_transport) { | 1158 bool secure_transport) { |
1187 // Since not all applications serialize and deserialize the media protocol, | 1159 // Since not all applications serialize and deserialize the media protocol, |
1188 // we will have to accept |protocol| to be empty. | 1160 // we will have to accept |protocol| to be empty. |
1189 if (protocol.empty()) { | 1161 if (protocol.empty()) { |
1190 return true; | 1162 return true; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 const TransportInfo* info = | 1204 const TransportInfo* info = |
1233 current_description->GetTransportInfoByName(content_name); | 1205 current_description->GetTransportInfoByName(content_name); |
1234 if (info) { | 1206 if (info) { |
1235 desc = &info->description; | 1207 desc = &info->description; |
1236 } | 1208 } |
1237 } | 1209 } |
1238 return desc; | 1210 return desc; |
1239 } | 1211 } |
1240 | 1212 |
1241 // Gets the current DTLS state from the transport description. | 1213 // Gets the current DTLS state from the transport description. |
1242 static bool IsDtlsActive( | 1214 static bool IsDtlsActive(const ContentInfo* content, |
1243 const std::string& content_name, | 1215 const SessionDescription* current_description) { |
1244 const SessionDescription* current_description) { | 1216 if (!content) { |
1245 if (!current_description) | |
1246 return false; | 1217 return false; |
| 1218 } |
1247 | 1219 |
1248 const ContentInfo* content = | 1220 size_t msection_index = content - ¤t_description->contents()[0]; |
1249 current_description->GetContentByName(content_name); | 1221 |
1250 if (!content) | 1222 if (current_description->transport_infos().size() <= msection_index) { |
1251 return false; | 1223 return false; |
| 1224 } |
1252 | 1225 |
1253 const TransportDescription* current_tdesc = | 1226 return current_description->transport_infos()[msection_index] |
1254 GetTransportDescription(content_name, current_description); | 1227 .description.secure(); |
1255 if (!current_tdesc) | |
1256 return false; | |
1257 | |
1258 return current_tdesc->secure(); | |
1259 } | 1228 } |
1260 | 1229 |
1261 std::string MediaContentDirectionToString(MediaContentDirection direction) { | 1230 std::string MediaContentDirectionToString(MediaContentDirection direction) { |
1262 std::string dir_str; | 1231 std::string dir_str; |
1263 switch (direction) { | 1232 switch (direction) { |
1264 case MD_INACTIVE: | 1233 case MD_INACTIVE: |
1265 dir_str = "inactive"; | 1234 dir_str = "inactive"; |
1266 break; | 1235 break; |
1267 case MD_SENDONLY: | 1236 case MD_SENDONLY: |
1268 dir_str = "sendonly"; | 1237 dir_str = "sendonly"; |
1269 break; | 1238 break; |
1270 case MD_RECVONLY: | 1239 case MD_RECVONLY: |
1271 dir_str = "recvonly"; | 1240 dir_str = "recvonly"; |
1272 break; | 1241 break; |
1273 case MD_SENDRECV: | 1242 case MD_SENDRECV: |
1274 dir_str = "sendrecv"; | 1243 dir_str = "sendrecv"; |
1275 break; | 1244 break; |
1276 default: | 1245 default: |
1277 RTC_NOTREACHED(); | 1246 RTC_NOTREACHED(); |
1278 break; | 1247 break; |
1279 } | 1248 } |
1280 | 1249 |
1281 return dir_str; | 1250 return dir_str; |
1282 } | 1251 } |
1283 | 1252 |
1284 void MediaSessionOptions::AddSendStream(MediaType type, | 1253 void MediaDescriptionOptions::AddAudioSender(const std::string& track_id, |
1285 const std::string& id, | 1254 const std::string& stream_id) { |
1286 const std::string& sync_label) { | 1255 RTC_DCHECK(type == MEDIA_TYPE_AUDIO); |
1287 AddSendStreamInternal(type, id, sync_label, 1); | 1256 AddSenderInternal(track_id, stream_id, 1); |
1288 } | 1257 } |
1289 | 1258 |
1290 void MediaSessionOptions::AddSendVideoStream( | 1259 void MediaDescriptionOptions::AddVideoSender(const std::string& track_id, |
1291 const std::string& id, | 1260 const std::string& stream_id, |
1292 const std::string& sync_label, | 1261 int num_sim_layers) { |
1293 int num_sim_layers) { | 1262 RTC_DCHECK(type == MEDIA_TYPE_VIDEO); |
1294 AddSendStreamInternal(MEDIA_TYPE_VIDEO, id, sync_label, num_sim_layers); | 1263 AddSenderInternal(track_id, stream_id, num_sim_layers); |
1295 } | 1264 } |
1296 | 1265 |
1297 void MediaSessionOptions::AddSendStreamInternal( | 1266 void MediaDescriptionOptions::AddRtpDataChannel(const std::string& track_id, |
1298 MediaType type, | 1267 const std::string& stream_id) { |
1299 const std::string& id, | 1268 RTC_DCHECK(type == MEDIA_TYPE_DATA); |
1300 const std::string& sync_label, | 1269 AddSenderInternal(track_id, stream_id, 1); |
1301 int num_sim_layers) { | |
1302 streams.push_back(Stream(type, id, sync_label, num_sim_layers)); | |
1303 | |
1304 // If we haven't already set the data_channel_type, and we add a | |
1305 // stream, we assume it's an RTP data stream. | |
1306 if (type == MEDIA_TYPE_DATA && data_channel_type == DCT_NONE) | |
1307 data_channel_type = DCT_RTP; | |
1308 } | 1270 } |
1309 | 1271 |
1310 void MediaSessionOptions::RemoveSendStream(MediaType type, | 1272 void MediaDescriptionOptions::AddSenderInternal(const std::string& track_id, |
1311 const std::string& id) { | 1273 const std::string& stream_id, |
1312 Streams::iterator stream_it = streams.begin(); | 1274 int num_sim_layers) { |
1313 for (; stream_it != streams.end(); ++stream_it) { | 1275 sender_options.push_back(SenderOptions{track_id, stream_id, num_sim_layers}); |
1314 if (stream_it->type == type && stream_it->id == id) { | |
1315 streams.erase(stream_it); | |
1316 return; | |
1317 } | |
1318 } | |
1319 RTC_NOTREACHED(); | |
1320 } | 1276 } |
1321 | 1277 |
1322 bool MediaSessionOptions::HasSendMediaStream(MediaType type) const { | 1278 bool MediaSessionOptions::HasMediaDescription(MediaType type) const { |
1323 Streams::const_iterator stream_it = streams.begin(); | 1279 return std::find_if(media_description_options.begin(), |
1324 for (; stream_it != streams.end(); ++stream_it) { | 1280 media_description_options.end(), |
1325 if (stream_it->type == type) { | 1281 [type](const MediaDescriptionOptions& t) { |
1326 return true; | 1282 return t.type == type; |
1327 } | 1283 }) != media_description_options.end(); |
1328 } | |
1329 return false; | |
1330 } | 1284 } |
1331 | 1285 |
1332 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( | 1286 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( |
1333 const TransportDescriptionFactory* transport_desc_factory) | 1287 const TransportDescriptionFactory* transport_desc_factory) |
1334 : secure_(SEC_DISABLED), | 1288 : transport_desc_factory_(transport_desc_factory) {} |
1335 add_legacy_(true), | |
1336 transport_desc_factory_(transport_desc_factory) { | |
1337 } | |
1338 | 1289 |
1339 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( | 1290 MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( |
1340 ChannelManager* channel_manager, | 1291 ChannelManager* channel_manager, |
1341 const TransportDescriptionFactory* transport_desc_factory) | 1292 const TransportDescriptionFactory* transport_desc_factory) |
1342 : secure_(SEC_DISABLED), | 1293 : transport_desc_factory_(transport_desc_factory) { |
1343 add_legacy_(true), | |
1344 transport_desc_factory_(transport_desc_factory) { | |
1345 channel_manager->GetSupportedAudioSendCodecs(&audio_send_codecs_); | 1294 channel_manager->GetSupportedAudioSendCodecs(&audio_send_codecs_); |
1346 channel_manager->GetSupportedAudioReceiveCodecs(&audio_recv_codecs_); | 1295 channel_manager->GetSupportedAudioReceiveCodecs(&audio_recv_codecs_); |
1347 channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); | 1296 channel_manager->GetSupportedAudioRtpHeaderExtensions(&audio_rtp_extensions_); |
1348 channel_manager->GetSupportedVideoCodecs(&video_codecs_); | 1297 channel_manager->GetSupportedVideoCodecs(&video_codecs_); |
1349 channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); | 1298 channel_manager->GetSupportedVideoRtpHeaderExtensions(&video_rtp_extensions_); |
1350 channel_manager->GetSupportedDataCodecs(&data_codecs_); | 1299 channel_manager->GetSupportedDataCodecs(&data_codecs_); |
1351 NegotiateCodecs(audio_recv_codecs_, audio_send_codecs_, | 1300 ComputeAudioCodecsIntersectionAndUnion(); |
1352 &audio_sendrecv_codecs_); | |
1353 } | 1301 } |
1354 | 1302 |
1355 const AudioCodecs& MediaSessionDescriptionFactory::audio_sendrecv_codecs() | 1303 const AudioCodecs& MediaSessionDescriptionFactory::audio_sendrecv_codecs() |
1356 const { | 1304 const { |
1357 return audio_sendrecv_codecs_; | 1305 return audio_sendrecv_codecs_; |
1358 } | 1306 } |
1359 | 1307 |
1360 const AudioCodecs& MediaSessionDescriptionFactory::audio_send_codecs() const { | 1308 const AudioCodecs& MediaSessionDescriptionFactory::audio_send_codecs() const { |
1361 return audio_send_codecs_; | 1309 return audio_send_codecs_; |
1362 } | 1310 } |
1363 | 1311 |
1364 const AudioCodecs& MediaSessionDescriptionFactory::audio_recv_codecs() const { | 1312 const AudioCodecs& MediaSessionDescriptionFactory::audio_recv_codecs() const { |
1365 return audio_recv_codecs_; | 1313 return audio_recv_codecs_; |
1366 } | 1314 } |
1367 | 1315 |
1368 void MediaSessionDescriptionFactory::set_audio_codecs( | 1316 void MediaSessionDescriptionFactory::set_audio_codecs( |
1369 const AudioCodecs& send_codecs, const AudioCodecs& recv_codecs) { | 1317 const AudioCodecs& send_codecs, const AudioCodecs& recv_codecs) { |
1370 audio_send_codecs_ = send_codecs; | 1318 audio_send_codecs_ = send_codecs; |
1371 audio_recv_codecs_ = recv_codecs; | 1319 audio_recv_codecs_ = recv_codecs; |
1372 audio_sendrecv_codecs_.clear(); | 1320 ComputeAudioCodecsIntersectionAndUnion(); |
1373 // Use NegotiateCodecs to merge our codec lists, since the operation is | |
1374 // essentially the same. Put send_codecs as the offered_codecs, which is the | |
1375 // order we'd like to follow. The reasoning is that encoding is usually more | |
1376 // expensive than decoding, and prioritizing a codec in the send list probably | |
1377 // means it's a codec we can handle efficiently. | |
1378 NegotiateCodecs(recv_codecs, send_codecs, &audio_sendrecv_codecs_); | |
1379 } | 1321 } |
1380 | 1322 |
1381 SessionDescription* MediaSessionDescriptionFactory::CreateOffer( | 1323 SessionDescription* MediaSessionDescriptionFactory::CreateOffer( |
1382 const MediaSessionOptions& options, | 1324 const MediaSessionOptions& session_options, |
1383 const SessionDescription* current_description) const { | 1325 const SessionDescription* current_description) const { |
1384 std::unique_ptr<SessionDescription> offer(new SessionDescription()); | 1326 std::unique_ptr<SessionDescription> offer(new SessionDescription()); |
1385 | 1327 |
1386 StreamParamsVec current_streams; | 1328 StreamParamsVec current_streams; |
1387 GetCurrentStreamParams(current_description, ¤t_streams); | 1329 GetCurrentStreamParams(current_description, ¤t_streams); |
1388 | 1330 |
1389 const bool wants_send = | 1331 AudioCodecs offer_audio_codecs; |
1390 options.HasSendMediaStream(MEDIA_TYPE_AUDIO) || add_legacy_; | 1332 VideoCodecs offer_video_codecs; |
1391 const AudioCodecs& supported_audio_codecs = | 1333 DataCodecs offer_data_codecs; |
1392 GetAudioCodecsForOffer({wants_send, options.recv_audio}); | 1334 GetCodecsForOffer(current_description, &offer_audio_codecs, |
| 1335 &offer_video_codecs, &offer_data_codecs); |
1393 | 1336 |
1394 AudioCodecs audio_codecs; | 1337 if (!session_options.vad_enabled) { |
1395 VideoCodecs video_codecs; | |
1396 DataCodecs data_codecs; | |
1397 GetCodecsToOffer(current_description, supported_audio_codecs, | |
1398 video_codecs_, data_codecs_, | |
1399 &audio_codecs, &video_codecs, &data_codecs); | |
1400 | |
1401 if (!options.vad_enabled) { | |
1402 // If application doesn't want CN codecs in offer. | 1338 // If application doesn't want CN codecs in offer. |
1403 StripCNCodecs(&audio_codecs); | 1339 StripCNCodecs(&offer_audio_codecs); |
1404 } | 1340 } |
| 1341 FilterDataCodecs(&offer_data_codecs, |
| 1342 session_options.data_channel_type == DCT_SCTP); |
1405 | 1343 |
1406 RtpHeaderExtensions audio_rtp_extensions; | 1344 RtpHeaderExtensions audio_rtp_extensions; |
1407 RtpHeaderExtensions video_rtp_extensions; | 1345 RtpHeaderExtensions video_rtp_extensions; |
1408 GetRtpHdrExtsToOffer(current_description, &audio_rtp_extensions, | 1346 GetRtpHdrExtsToOffer(current_description, &audio_rtp_extensions, |
1409 &video_rtp_extensions); | 1347 &video_rtp_extensions); |
1410 | 1348 |
1411 bool audio_added = false; | 1349 // Must have options for each existing section. |
1412 bool video_added = false; | |
1413 bool data_added = false; | |
1414 | |
1415 // Iterate through the contents of |current_description| to maintain the order | |
1416 // of the m-lines in the new offer. | |
1417 if (current_description) { | 1350 if (current_description) { |
1418 ContentInfos::const_iterator it = current_description->contents().begin(); | 1351 RTC_DCHECK(current_description->contents().size() <= |
1419 for (; it != current_description->contents().end(); ++it) { | 1352 session_options.media_description_options.size()); |
1420 if (IsMediaContentOfType(&*it, MEDIA_TYPE_AUDIO)) { | |
1421 if (!AddAudioContentForOffer(options, current_description, | |
1422 audio_rtp_extensions, audio_codecs, | |
1423 ¤t_streams, offer.get())) { | |
1424 return NULL; | |
1425 } | |
1426 audio_added = true; | |
1427 } else if (IsMediaContentOfType(&*it, MEDIA_TYPE_VIDEO)) { | |
1428 if (!AddVideoContentForOffer(options, current_description, | |
1429 video_rtp_extensions, video_codecs, | |
1430 ¤t_streams, offer.get())) { | |
1431 return NULL; | |
1432 } | |
1433 video_added = true; | |
1434 } else if (IsMediaContentOfType(&*it, MEDIA_TYPE_DATA)) { | |
1435 MediaSessionOptions options_copy(options); | |
1436 if (IsSctp(static_cast<const MediaContentDescription*>(it->description) | |
1437 ->protocol())) { | |
1438 options_copy.data_channel_type = DCT_SCTP; | |
1439 } | |
1440 if (!AddDataContentForOffer(options_copy, current_description, | |
1441 &data_codecs, ¤t_streams, | |
1442 offer.get())) { | |
1443 return NULL; | |
1444 } | |
1445 data_added = true; | |
1446 } else { | |
1447 RTC_NOTREACHED(); | |
1448 } | |
1449 } | |
1450 } | 1353 } |
1451 | 1354 |
1452 // Append contents that are not in |current_description|. | 1355 // Iterate through the media description options, matching with existing media |
1453 if (!audio_added && options.has_audio() && | 1356 // descriptions in |current_description|. |
1454 !AddAudioContentForOffer(options, current_description, | 1357 int msection_index = 0; |
1455 audio_rtp_extensions, audio_codecs, | 1358 for (const MediaDescriptionOptions& media_description_options : |
1456 ¤t_streams, offer.get())) { | 1359 session_options.media_description_options) { |
1457 return NULL; | 1360 const ContentInfo* current_content = nullptr; |
1458 } | 1361 if (current_description && |
1459 if (!video_added && options.has_video() && | 1362 msection_index < |
1460 !AddVideoContentForOffer(options, current_description, | 1363 static_cast<int>(current_description->contents().size())) { |
1461 video_rtp_extensions, video_codecs, | 1364 current_content = ¤t_description->contents()[msection_index]; |
1462 ¤t_streams, offer.get())) { | 1365 // Media type must match. |
1463 return NULL; | 1366 RTC_DCHECK(IsMediaContentOfType(current_content, |
1464 } | 1367 media_description_options.type)); |
1465 if (!data_added && options.has_data() && | 1368 } |
1466 !AddDataContentForOffer(options, current_description, &data_codecs, | 1369 switch (media_description_options.type) { |
1467 ¤t_streams, offer.get())) { | 1370 case MEDIA_TYPE_AUDIO: |
1468 return NULL; | 1371 if (!AddAudioContentForOffer(media_description_options, session_options, |
| 1372 current_content, current_description, |
| 1373 audio_rtp_extensions, offer_audio_codecs, |
| 1374 ¤t_streams, offer.get())) { |
| 1375 return nullptr; |
| 1376 } |
| 1377 break; |
| 1378 case MEDIA_TYPE_VIDEO: |
| 1379 if (!AddVideoContentForOffer(media_description_options, session_options, |
| 1380 current_content, current_description, |
| 1381 video_rtp_extensions, offer_video_codecs, |
| 1382 ¤t_streams, offer.get())) { |
| 1383 return nullptr; |
| 1384 } |
| 1385 break; |
| 1386 case MEDIA_TYPE_DATA: |
| 1387 if (!AddDataContentForOffer(media_description_options, session_options, |
| 1388 current_content, current_description, |
| 1389 offer_data_codecs, ¤t_streams, |
| 1390 offer.get())) { |
| 1391 return nullptr; |
| 1392 } |
| 1393 break; |
| 1394 default: |
| 1395 RTC_NOTREACHED(); |
| 1396 } |
| 1397 ++msection_index; |
1469 } | 1398 } |
1470 | 1399 |
1471 // Bundle the contents together, if we've been asked to do so, and update any | 1400 // Bundle the contents together, if we've been asked to do so, and update any |
1472 // parameters that need to be tweaked for BUNDLE. | 1401 // parameters that need to be tweaked for BUNDLE. |
1473 if (options.bundle_enabled) { | 1402 if (session_options.bundle_enabled && offer->contents().size() > 0u) { |
1474 ContentGroup offer_bundle(GROUP_TYPE_BUNDLE); | 1403 ContentGroup offer_bundle(GROUP_TYPE_BUNDLE); |
1475 for (ContentInfos::const_iterator content = offer->contents().begin(); | 1404 for (const ContentInfo& content : offer->contents()) { |
1476 content != offer->contents().end(); ++content) { | 1405 // TODO(deadbeef): There are conditions that make bundling two media |
1477 offer_bundle.AddContentName(content->name); | 1406 // descriptions together illegal. For example, they use the same payload |
| 1407 // type to represent different codecs, or same IDs for different header |
| 1408 // extensions. We need to detect this and not try to bundle those media |
| 1409 // descriptions together. |
| 1410 offer_bundle.AddContentName(content.name); |
1478 } | 1411 } |
1479 offer->AddGroup(offer_bundle); | 1412 offer->AddGroup(offer_bundle); |
1480 if (!UpdateTransportInfoForBundle(offer_bundle, offer.get())) { | 1413 if (!UpdateTransportInfoForBundle(offer_bundle, offer.get())) { |
1481 LOG(LS_ERROR) << "CreateOffer failed to UpdateTransportInfoForBundle."; | 1414 LOG(LS_ERROR) << "CreateOffer failed to UpdateTransportInfoForBundle."; |
1482 return NULL; | 1415 return nullptr; |
1483 } | 1416 } |
1484 if (!UpdateCryptoParamsForBundle(offer_bundle, offer.get())) { | 1417 if (!UpdateCryptoParamsForBundle(offer_bundle, offer.get())) { |
1485 LOG(LS_ERROR) << "CreateOffer failed to UpdateCryptoParamsForBundle."; | 1418 LOG(LS_ERROR) << "CreateOffer failed to UpdateCryptoParamsForBundle."; |
1486 return NULL; | 1419 return nullptr; |
1487 } | 1420 } |
1488 } | 1421 } |
1489 | |
1490 return offer.release(); | 1422 return offer.release(); |
1491 } | 1423 } |
1492 | 1424 |
1493 SessionDescription* MediaSessionDescriptionFactory::CreateAnswer( | 1425 SessionDescription* MediaSessionDescriptionFactory::CreateAnswer( |
1494 const SessionDescription* offer, const MediaSessionOptions& options, | 1426 const SessionDescription* offer, |
| 1427 const MediaSessionOptions& session_options, |
1495 const SessionDescription* current_description) const { | 1428 const SessionDescription* current_description) const { |
1496 if (!offer) { | 1429 if (!offer) { |
1497 return nullptr; | 1430 return nullptr; |
1498 } | 1431 } |
1499 // The answer contains the intersection of the codecs in the offer with the | 1432 // The answer contains the intersection of the codecs in the offer with the |
1500 // codecs we support. As indicated by XEP-0167, we retain the same payload ids | 1433 // codecs we support. As indicated by XEP-0167, we retain the same payload ids |
1501 // from the offer in the answer. | 1434 // from the offer in the answer. |
1502 std::unique_ptr<SessionDescription> answer(new SessionDescription()); | 1435 std::unique_ptr<SessionDescription> answer(new SessionDescription()); |
1503 | 1436 |
1504 StreamParamsVec current_streams; | 1437 StreamParamsVec current_streams; |
1505 GetCurrentStreamParams(current_description, ¤t_streams); | 1438 GetCurrentStreamParams(current_description, ¤t_streams); |
1506 | 1439 |
1507 // If the offer supports BUNDLE, and we want to use it too, create a BUNDLE | 1440 // If the offer supports BUNDLE, and we want to use it too, create a BUNDLE |
1508 // group in the answer with the appropriate content names. | 1441 // group in the answer with the appropriate content names. |
1509 const ContentGroup* offer_bundle = offer->GetGroupByName(GROUP_TYPE_BUNDLE); | 1442 const ContentGroup* offer_bundle = offer->GetGroupByName(GROUP_TYPE_BUNDLE); |
1510 ContentGroup answer_bundle(GROUP_TYPE_BUNDLE); | 1443 ContentGroup answer_bundle(GROUP_TYPE_BUNDLE); |
1511 // Transport info shared by the bundle group. | 1444 // Transport info shared by the bundle group. |
1512 std::unique_ptr<TransportInfo> bundle_transport; | 1445 std::unique_ptr<TransportInfo> bundle_transport; |
1513 | 1446 |
1514 ContentInfos::const_iterator it = offer->contents().begin(); | 1447 // Get list of all possible codecs that respects existing payload type |
1515 for (; it != offer->contents().end(); ++it) { | 1448 // mappings and uses a single payload type space. |
1516 if (IsMediaContentOfType(&*it, MEDIA_TYPE_AUDIO)) { | 1449 // |
1517 if (!AddAudioContentForAnswer(offer, options, current_description, | 1450 // Note that these lists may be further filtered for each m= section; this |
1518 bundle_transport.get(), ¤t_streams, | 1451 // step is done just to establish the payload type mappings shared by all |
1519 answer.get())) { | 1452 // sections. |
1520 return NULL; | 1453 AudioCodecs answer_audio_codecs; |
1521 } | 1454 VideoCodecs answer_video_codecs; |
1522 } else if (IsMediaContentOfType(&*it, MEDIA_TYPE_VIDEO)) { | 1455 DataCodecs answer_data_codecs; |
1523 if (!AddVideoContentForAnswer(offer, options, current_description, | 1456 GetCodecsForAnswer(current_description, offer, &answer_audio_codecs, |
1524 bundle_transport.get(), ¤t_streams, | 1457 &answer_video_codecs, &answer_data_codecs); |
1525 answer.get())) { | 1458 |
1526 return NULL; | 1459 if (!session_options.vad_enabled) { |
1527 } | 1460 // If application doesn't want CN codecs in answer. |
1528 } else { | 1461 StripCNCodecs(&answer_audio_codecs); |
1529 RTC_DCHECK(IsMediaContentOfType(&*it, MEDIA_TYPE_DATA)); | 1462 } |
1530 if (!AddDataContentForAnswer(offer, options, current_description, | 1463 FilterDataCodecs(&answer_data_codecs, |
1531 bundle_transport.get(), ¤t_streams, | 1464 session_options.data_channel_type == DCT_SCTP); |
1532 answer.get())) { | 1465 |
1533 return NULL; | 1466 // Must have options for exactly as many sections as in the offer. |
1534 } | 1467 RTC_DCHECK(offer->contents().size() == |
| 1468 session_options.media_description_options.size()); |
| 1469 // Iterate through the media description options, matching with existing |
| 1470 // media descriptions in |current_description|. |
| 1471 int msection_index = 0; |
| 1472 for (const MediaDescriptionOptions& media_description_options : |
| 1473 session_options.media_description_options) { |
| 1474 const ContentInfo* offer_content = &offer->contents()[msection_index]; |
| 1475 // Media types and MIDs must match between the remote offer and the |
| 1476 // MediaDescriptionOptions. |
| 1477 RTC_DCHECK( |
| 1478 IsMediaContentOfType(offer_content, media_description_options.type)); |
| 1479 RTC_DCHECK(media_description_options.mid == offer_content->name); |
| 1480 const ContentInfo* current_content = nullptr; |
| 1481 if (current_description && |
| 1482 msection_index < |
| 1483 static_cast<int>(current_description->contents().size())) { |
| 1484 current_content = ¤t_description->contents()[msection_index]; |
1535 } | 1485 } |
| 1486 switch (media_description_options.type) { |
| 1487 case MEDIA_TYPE_AUDIO: |
| 1488 if (!AddAudioContentForAnswer( |
| 1489 media_description_options, session_options, offer_content, |
| 1490 offer, current_content, current_description, |
| 1491 bundle_transport.get(), answer_audio_codecs, ¤t_streams, |
| 1492 answer.get())) { |
| 1493 return nullptr; |
| 1494 } |
| 1495 break; |
| 1496 case MEDIA_TYPE_VIDEO: |
| 1497 if (!AddVideoContentForAnswer( |
| 1498 media_description_options, session_options, offer_content, |
| 1499 offer, current_content, current_description, |
| 1500 bundle_transport.get(), answer_video_codecs, ¤t_streams, |
| 1501 answer.get())) { |
| 1502 return nullptr; |
| 1503 } |
| 1504 break; |
| 1505 case MEDIA_TYPE_DATA: |
| 1506 if (!AddDataContentForAnswer(media_description_options, session_options, |
| 1507 offer_content, offer, current_content, |
| 1508 current_description, |
| 1509 bundle_transport.get(), answer_data_codecs, |
| 1510 ¤t_streams, answer.get())) { |
| 1511 return nullptr; |
| 1512 } |
| 1513 break; |
| 1514 default: |
| 1515 RTC_NOTREACHED(); |
| 1516 } |
| 1517 ++msection_index; |
1536 // See if we can add the newly generated m= section to the BUNDLE group in | 1518 // See if we can add the newly generated m= section to the BUNDLE group in |
1537 // the answer. | 1519 // the answer. |
1538 ContentInfo& added = answer->contents().back(); | 1520 ContentInfo& added = answer->contents().back(); |
1539 if (!added.rejected && options.bundle_enabled && offer_bundle && | 1521 if (!added.rejected && session_options.bundle_enabled && offer_bundle && |
1540 offer_bundle->HasContentName(added.name)) { | 1522 offer_bundle->HasContentName(added.name)) { |
1541 answer_bundle.AddContentName(added.name); | 1523 answer_bundle.AddContentName(added.name); |
1542 bundle_transport.reset( | 1524 bundle_transport.reset( |
1543 new TransportInfo(*answer->GetTransportInfoByName(added.name))); | 1525 new TransportInfo(*answer->GetTransportInfoByName(added.name))); |
1544 } | 1526 } |
1545 } | 1527 } |
1546 | 1528 |
1547 // Only put BUNDLE group in answer if nonempty. | 1529 // Only put BUNDLE group in answer if nonempty. |
1548 if (answer_bundle.FirstContentName()) { | 1530 if (answer_bundle.FirstContentName()) { |
1549 answer->AddGroup(answer_bundle); | 1531 answer->AddGroup(answer_bundle); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1589 } else { | 1571 } else { |
1590 return audio_send_codecs_; | 1572 return audio_send_codecs_; |
1591 } | 1573 } |
1592 } else if (answer.send) { | 1574 } else if (answer.send) { |
1593 return audio_send_codecs_; | 1575 return audio_send_codecs_; |
1594 } else { | 1576 } else { |
1595 return audio_recv_codecs_; | 1577 return audio_recv_codecs_; |
1596 } | 1578 } |
1597 } | 1579 } |
1598 | 1580 |
1599 void MediaSessionDescriptionFactory::GetCodecsToOffer( | 1581 void MergeCodecsFromDescription(const SessionDescription* description, |
| 1582 AudioCodecs* audio_codecs, |
| 1583 VideoCodecs* video_codecs, |
| 1584 DataCodecs* data_codecs, |
| 1585 UsedPayloadTypes* used_pltypes) { |
| 1586 RTC_DCHECK(description); |
| 1587 for (const ContentInfo& content : description->contents()) { |
| 1588 if (IsMediaContentOfType(&content, MEDIA_TYPE_AUDIO)) { |
| 1589 const AudioContentDescription* audio = |
| 1590 static_cast<AudioContentDescription*>(content.description); |
| 1591 MergeCodecs<AudioCodec>(audio->codecs(), audio_codecs, used_pltypes); |
| 1592 } else if (IsMediaContentOfType(&content, MEDIA_TYPE_VIDEO)) { |
| 1593 const VideoContentDescription* video = |
| 1594 static_cast<VideoContentDescription*>(content.description); |
| 1595 MergeCodecs<VideoCodec>(video->codecs(), video_codecs, used_pltypes); |
| 1596 } else if (IsMediaContentOfType(&content, MEDIA_TYPE_DATA)) { |
| 1597 const DataContentDescription* data = |
| 1598 static_cast<DataContentDescription*>(content.description); |
| 1599 MergeCodecs<DataCodec>(data->codecs(), data_codecs, used_pltypes); |
| 1600 } |
| 1601 } |
| 1602 } |
| 1603 |
| 1604 // Getting codecs for an offer involves these steps: |
| 1605 // |
| 1606 // 1. Construct payload type -> codec mappings for current description. |
| 1607 // 2. Add any reference codecs that weren't already present |
| 1608 // 3. For each individual media description (m= section), filter codecs based |
| 1609 // on the directional attribute (happens in another method). |
| 1610 void MediaSessionDescriptionFactory::GetCodecsForOffer( |
1600 const SessionDescription* current_description, | 1611 const SessionDescription* current_description, |
1601 const AudioCodecs& supported_audio_codecs, | |
1602 const VideoCodecs& supported_video_codecs, | |
1603 const DataCodecs& supported_data_codecs, | |
1604 AudioCodecs* audio_codecs, | 1612 AudioCodecs* audio_codecs, |
1605 VideoCodecs* video_codecs, | 1613 VideoCodecs* video_codecs, |
1606 DataCodecs* data_codecs) const { | 1614 DataCodecs* data_codecs) const { |
1607 UsedPayloadTypes used_pltypes; | 1615 UsedPayloadTypes used_pltypes; |
1608 audio_codecs->clear(); | 1616 audio_codecs->clear(); |
1609 video_codecs->clear(); | 1617 video_codecs->clear(); |
1610 data_codecs->clear(); | 1618 data_codecs->clear(); |
1611 | 1619 |
| 1620 // First - get all codecs from the current description if the media type |
| 1621 // is used. Add them to |used_pltypes| so the payload type is not reused if a |
| 1622 // new media type is added. |
| 1623 if (current_description) { |
| 1624 MergeCodecsFromDescription(current_description, audio_codecs, video_codecs, |
| 1625 data_codecs, &used_pltypes); |
| 1626 } |
| 1627 |
| 1628 // Add our codecs that are not in |current_description|. |
| 1629 MergeCodecs<AudioCodec>(all_audio_codecs_, audio_codecs, &used_pltypes); |
| 1630 MergeCodecs<VideoCodec>(video_codecs_, video_codecs, &used_pltypes); |
| 1631 MergeCodecs<DataCodec>(data_codecs_, data_codecs, &used_pltypes); |
| 1632 } |
| 1633 |
| 1634 // Getting codecs for an answer involves these steps: |
| 1635 // |
| 1636 // 1. Construct payload type -> codec mappings for current description. |
| 1637 // 2. Add any codecs from the offer that weren't already present. |
| 1638 // 3. Add any remaining codecs that weren't already present. |
| 1639 // 4. For each individual media description (m= section), filter codecs based |
| 1640 // on the directional attribute (happens in another method). |
| 1641 void MediaSessionDescriptionFactory::GetCodecsForAnswer( |
| 1642 const SessionDescription* current_description, |
| 1643 const SessionDescription* remote_offer, |
| 1644 AudioCodecs* audio_codecs, |
| 1645 VideoCodecs* video_codecs, |
| 1646 DataCodecs* data_codecs) const { |
| 1647 UsedPayloadTypes used_pltypes; |
| 1648 audio_codecs->clear(); |
| 1649 video_codecs->clear(); |
| 1650 data_codecs->clear(); |
1612 | 1651 |
1613 // First - get all codecs from the current description if the media type | 1652 // First - get all codecs from the current description if the media type |
1614 // is used. | 1653 // is used. Add them to |used_pltypes| so the payload type is not reused if a |
1615 // Add them to |used_pltypes| so the payloadtype is not reused if a new media | 1654 // new media type is added. |
1616 // type is added. | |
1617 if (current_description) { | 1655 if (current_description) { |
1618 const AudioContentDescription* audio = | 1656 MergeCodecsFromDescription(current_description, audio_codecs, video_codecs, |
1619 GetFirstAudioContentDescription(current_description); | 1657 data_codecs, &used_pltypes); |
1620 if (audio) { | 1658 } |
1621 *audio_codecs = audio->codecs(); | 1659 |
1622 used_pltypes.FindAndSetIdUsed<AudioCodec>(audio_codecs); | 1660 // Second - filter out codecs that we don't support at all and should ignore. |
1623 } | 1661 AudioCodecs filtered_offered_audio_codecs; |
1624 const VideoContentDescription* video = | 1662 VideoCodecs filtered_offered_video_codecs; |
1625 GetFirstVideoContentDescription(current_description); | 1663 DataCodecs filtered_offered_data_codecs; |
1626 if (video) { | 1664 for (const ContentInfo& content : remote_offer->contents()) { |
1627 *video_codecs = video->codecs(); | 1665 if (IsMediaContentOfType(&content, MEDIA_TYPE_AUDIO)) { |
1628 used_pltypes.FindAndSetIdUsed<VideoCodec>(video_codecs); | 1666 const AudioContentDescription* audio = |
1629 } | 1667 static_cast<AudioContentDescription*>(content.description); |
1630 const DataContentDescription* data = | 1668 for (const AudioCodec& offered_audio_codec : audio->codecs()) { |
1631 GetFirstDataContentDescription(current_description); | 1669 if (!FindMatchingCodec<AudioCodec>(audio->codecs(), |
1632 if (data) { | 1670 filtered_offered_audio_codecs, |
1633 *data_codecs = data->codecs(); | 1671 offered_audio_codec, nullptr) && |
1634 used_pltypes.FindAndSetIdUsed<DataCodec>(data_codecs); | 1672 FindMatchingCodec<AudioCodec>(audio->codecs(), all_audio_codecs_, |
| 1673 offered_audio_codec, nullptr)) { |
| 1674 filtered_offered_audio_codecs.push_back(offered_audio_codec); |
| 1675 } |
| 1676 } |
| 1677 } else if (IsMediaContentOfType(&content, MEDIA_TYPE_VIDEO)) { |
| 1678 const VideoContentDescription* video = |
| 1679 static_cast<VideoContentDescription*>(content.description); |
| 1680 for (const VideoCodec& offered_video_codec : video->codecs()) { |
| 1681 if (!FindMatchingCodec<VideoCodec>(video->codecs(), |
| 1682 filtered_offered_video_codecs, |
| 1683 offered_video_codec, nullptr) && |
| 1684 FindMatchingCodec<VideoCodec>(video->codecs(), video_codecs_, |
| 1685 offered_video_codec, nullptr)) { |
| 1686 filtered_offered_video_codecs.push_back(offered_video_codec); |
| 1687 } |
| 1688 } |
| 1689 } else if (IsMediaContentOfType(&content, MEDIA_TYPE_DATA)) { |
| 1690 const DataContentDescription* data = |
| 1691 static_cast<DataContentDescription*>(content.description); |
| 1692 for (const DataCodec& offered_data_codec : data->codecs()) { |
| 1693 if (!FindMatchingCodec<DataCodec>(data->codecs(), |
| 1694 filtered_offered_data_codecs, |
| 1695 offered_data_codec, nullptr) && |
| 1696 FindMatchingCodec<DataCodec>(data->codecs(), data_codecs_, |
| 1697 offered_data_codec, nullptr)) { |
| 1698 filtered_offered_data_codecs.push_back(offered_data_codec); |
| 1699 } |
| 1700 } |
1635 } | 1701 } |
1636 } | 1702 } |
1637 | 1703 |
1638 // Add our codecs that are not in |current_description|. | 1704 // Add codecs that are not in |current_description| but were in |
1639 FindCodecsToOffer<AudioCodec>(supported_audio_codecs, audio_codecs, | 1705 // |remote_offer|. |
1640 &used_pltypes); | 1706 MergeCodecs<AudioCodec>(filtered_offered_audio_codecs, audio_codecs, |
1641 FindCodecsToOffer<VideoCodec>(supported_video_codecs, video_codecs, | 1707 &used_pltypes); |
1642 &used_pltypes); | 1708 MergeCodecs<VideoCodec>(filtered_offered_video_codecs, video_codecs, |
1643 FindCodecsToOffer<DataCodec>(supported_data_codecs, data_codecs, | 1709 &used_pltypes); |
1644 &used_pltypes); | 1710 MergeCodecs<DataCodec>(filtered_offered_data_codecs, data_codecs, |
| 1711 &used_pltypes); |
1645 } | 1712 } |
1646 | 1713 |
1647 void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( | 1714 void MediaSessionDescriptionFactory::GetRtpHdrExtsToOffer( |
1648 const SessionDescription* current_description, | 1715 const SessionDescription* current_description, |
1649 RtpHeaderExtensions* audio_extensions, | 1716 RtpHeaderExtensions* offer_audio_extensions, |
1650 RtpHeaderExtensions* video_extensions) const { | 1717 RtpHeaderExtensions* offer_video_extensions) const { |
1651 // All header extensions allocated from the same range to avoid potential | 1718 // All header extensions allocated from the same range to avoid potential |
1652 // issues when using BUNDLE. | 1719 // issues when using BUNDLE. |
1653 UsedRtpHeaderExtensionIds used_ids; | 1720 UsedRtpHeaderExtensionIds used_ids; |
1654 RtpHeaderExtensions all_regular_extensions; | 1721 RtpHeaderExtensions all_regular_extensions; |
1655 RtpHeaderExtensions all_encrypted_extensions; | 1722 RtpHeaderExtensions all_encrypted_extensions; |
1656 audio_extensions->clear(); | 1723 offer_audio_extensions->clear(); |
1657 video_extensions->clear(); | 1724 offer_video_extensions->clear(); |
1658 | 1725 |
1659 // First - get all extensions from the current description if the media type | 1726 // First - get all extensions from the current description if the media type |
1660 // is used. | 1727 // is used. |
1661 // Add them to |used_ids| so the local ids are not reused if a new media | 1728 // Add them to |used_ids| so the local ids are not reused if a new media |
1662 // type is added. | 1729 // type is added. |
1663 if (current_description) { | 1730 if (current_description) { |
1664 const AudioContentDescription* audio = | 1731 for (const ContentInfo& content : current_description->contents()) { |
1665 GetFirstAudioContentDescription(current_description); | 1732 if (IsMediaContentOfType(&content, MEDIA_TYPE_AUDIO)) { |
1666 if (audio) { | 1733 const AudioContentDescription* audio = |
1667 *audio_extensions = audio->rtp_header_extensions(); | 1734 static_cast<const AudioContentDescription*>(content.description); |
1668 FindAndSetRtpHdrExtUsed(audio_extensions, &all_regular_extensions, | 1735 MergeRtpHdrExts(audio->rtp_header_extensions(), offer_audio_extensions, |
1669 &all_encrypted_extensions, &used_ids); | 1736 &all_regular_extensions, &all_encrypted_extensions, |
1670 } | 1737 &used_ids); |
1671 const VideoContentDescription* video = | 1738 } else if (IsMediaContentOfType(&content, MEDIA_TYPE_VIDEO)) { |
1672 GetFirstVideoContentDescription(current_description); | 1739 const VideoContentDescription* video = |
1673 if (video) { | 1740 static_cast<const VideoContentDescription*>(content.description); |
1674 *video_extensions = video->rtp_header_extensions(); | 1741 MergeRtpHdrExts(video->rtp_header_extensions(), offer_video_extensions, |
1675 FindAndSetRtpHdrExtUsed(video_extensions, &all_regular_extensions, | 1742 &all_regular_extensions, &all_encrypted_extensions, |
1676 &all_encrypted_extensions, &used_ids); | 1743 &used_ids); |
| 1744 } |
1677 } | 1745 } |
1678 } | 1746 } |
1679 | 1747 |
1680 // Add our default RTP header extensions that are not in | 1748 // Add our default RTP header extensions that are not in |
1681 // |current_description|. | 1749 // |current_description|. |
1682 FindRtpHdrExtsToOffer(audio_rtp_header_extensions(), audio_extensions, | 1750 MergeRtpHdrExts(audio_rtp_header_extensions(), offer_audio_extensions, |
1683 &all_regular_extensions, &used_ids); | 1751 &all_regular_extensions, &all_encrypted_extensions, |
1684 FindRtpHdrExtsToOffer(video_rtp_header_extensions(), video_extensions, | 1752 &used_ids); |
1685 &all_regular_extensions, &used_ids); | 1753 MergeRtpHdrExts(video_rtp_header_extensions(), offer_video_extensions, |
| 1754 &all_regular_extensions, &all_encrypted_extensions, |
| 1755 &used_ids); |
| 1756 |
1686 // TODO(jbauch): Support adding encrypted header extensions to existing | 1757 // TODO(jbauch): Support adding encrypted header extensions to existing |
1687 // sessions. | 1758 // sessions. |
1688 if (enable_encrypted_rtp_header_extensions_ && !current_description) { | 1759 if (enable_encrypted_rtp_header_extensions_ && !current_description) { |
1689 AddEncryptedVersionsOfHdrExts(audio_extensions, &all_encrypted_extensions, | 1760 AddEncryptedVersionsOfHdrExts(offer_audio_extensions, |
1690 &used_ids); | 1761 &all_encrypted_extensions, &used_ids); |
1691 AddEncryptedVersionsOfHdrExts(video_extensions, &all_encrypted_extensions, | 1762 AddEncryptedVersionsOfHdrExts(offer_video_extensions, |
1692 &used_ids); | 1763 &all_encrypted_extensions, &used_ids); |
1693 } | 1764 } |
1694 } | 1765 } |
1695 | 1766 |
1696 bool MediaSessionDescriptionFactory::AddTransportOffer( | 1767 bool MediaSessionDescriptionFactory::AddTransportOffer( |
1697 const std::string& content_name, | 1768 const std::string& content_name, |
1698 const TransportOptions& transport_options, | 1769 const TransportOptions& transport_options, |
1699 const SessionDescription* current_desc, | 1770 const SessionDescription* current_desc, |
1700 SessionDescription* offer_desc) const { | 1771 SessionDescription* offer_desc) const { |
1701 if (!transport_desc_factory_) | 1772 if (!transport_desc_factory_) |
1702 return false; | 1773 return false; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1736 SessionDescription* answer_desc) const { | 1807 SessionDescription* answer_desc) const { |
1737 if (!answer_desc->AddTransportInfo(TransportInfo(content_name, | 1808 if (!answer_desc->AddTransportInfo(TransportInfo(content_name, |
1738 transport_desc))) { | 1809 transport_desc))) { |
1739 LOG(LS_ERROR) | 1810 LOG(LS_ERROR) |
1740 << "Failed to AddTransportAnswer, content name=" << content_name; | 1811 << "Failed to AddTransportAnswer, content name=" << content_name; |
1741 return false; | 1812 return false; |
1742 } | 1813 } |
1743 return true; | 1814 return true; |
1744 } | 1815 } |
1745 | 1816 |
| 1817 // |audio_codecs| = set of all possible codecs that can be used, with correct |
| 1818 // payload type mappings |
| 1819 // |
| 1820 // |supported_audio_codecs| = set of codecs that are supported for the direction |
| 1821 // of this m= section |
| 1822 // |
| 1823 // acd->codecs() = set of previously negotiated codecs for this m= section |
| 1824 // |
| 1825 // The payload types should come from audio_codecs, but the order should come |
| 1826 // from acd->codecs() and then supported_codecs, to ensure that re-offers don't |
| 1827 // change existing codec priority, and that new codecs are added with the right |
| 1828 // priority. |
1746 bool MediaSessionDescriptionFactory::AddAudioContentForOffer( | 1829 bool MediaSessionDescriptionFactory::AddAudioContentForOffer( |
1747 const MediaSessionOptions& options, | 1830 const MediaDescriptionOptions& media_description_options, |
| 1831 const MediaSessionOptions& session_options, |
| 1832 const ContentInfo* current_content, |
1748 const SessionDescription* current_description, | 1833 const SessionDescription* current_description, |
1749 const RtpHeaderExtensions& audio_rtp_extensions, | 1834 const RtpHeaderExtensions& audio_rtp_extensions, |
1750 const AudioCodecs& audio_codecs, | 1835 const AudioCodecs& audio_codecs, |
1751 StreamParamsVec* current_streams, | 1836 StreamParamsVec* current_streams, |
1752 SessionDescription* desc) const { | 1837 SessionDescription* desc) const { |
1753 const ContentInfo* current_audio_content = | 1838 // Filter audio_codecs (which includes all codecs, with correctly remapped |
1754 GetFirstAudioContent(current_description); | 1839 // payload types) based on transceiver direction. |
1755 std::string content_name = | 1840 const AudioCodecs& supported_audio_codecs = |
1756 current_audio_content ? current_audio_content->name : CN_AUDIO; | 1841 GetAudioCodecsForOffer(media_description_options.direction); |
| 1842 |
| 1843 AudioCodecs filtered_codecs; |
| 1844 // Add the codecs from current content if exists. |
| 1845 if (current_content) { |
| 1846 RTC_DCHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_AUDIO)); |
| 1847 const AudioContentDescription* acd = |
| 1848 static_cast<const AudioContentDescription*>( |
| 1849 current_content->description); |
| 1850 for (const AudioCodec& codec : acd->codecs()) { |
| 1851 if (FindMatchingCodec<AudioCodec>(supported_audio_codecs, audio_codecs, |
| 1852 codec, nullptr)) { |
| 1853 filtered_codecs.push_back(codec); |
| 1854 } |
| 1855 } |
| 1856 } |
| 1857 // Add other supported audio codecs. |
| 1858 AudioCodec found_codec; |
| 1859 for (const AudioCodec& codec : supported_audio_codecs) { |
| 1860 if (FindMatchingCodec<AudioCodec>(supported_audio_codecs, audio_codecs, |
| 1861 codec, &found_codec) && |
| 1862 !FindMatchingCodec<AudioCodec>(supported_audio_codecs, filtered_codecs, |
| 1863 codec, nullptr)) { |
| 1864 // Use the |found_codec| from |audio_codecs| because it has the correctly |
| 1865 // mapped payload type. |
| 1866 filtered_codecs.push_back(found_codec); |
| 1867 } |
| 1868 } |
1757 | 1869 |
1758 cricket::SecurePolicy sdes_policy = | 1870 cricket::SecurePolicy sdes_policy = |
1759 IsDtlsActive(content_name, current_description) ? cricket::SEC_DISABLED | 1871 IsDtlsActive(current_content, current_description) ? cricket::SEC_DISABLED |
1760 : secure(); | 1872 : secure(); |
1761 | 1873 |
1762 std::unique_ptr<AudioContentDescription> audio(new AudioContentDescription()); | 1874 std::unique_ptr<AudioContentDescription> audio(new AudioContentDescription()); |
1763 std::vector<std::string> crypto_suites; | 1875 std::vector<std::string> crypto_suites; |
1764 GetSupportedAudioSdesCryptoSuiteNames(options.crypto_options, &crypto_suites); | 1876 GetSupportedAudioSdesCryptoSuiteNames(session_options.crypto_options, |
| 1877 &crypto_suites); |
1765 if (!CreateMediaContentOffer( | 1878 if (!CreateMediaContentOffer( |
1766 options, | 1879 media_description_options.sender_options, session_options, |
1767 audio_codecs, | 1880 filtered_codecs, sdes_policy, GetCryptos(current_content), |
1768 sdes_policy, | 1881 crypto_suites, audio_rtp_extensions, current_streams, audio.get())) { |
1769 GetCryptos(GetFirstAudioContentDescription(current_description)), | |
1770 crypto_suites, | |
1771 audio_rtp_extensions, | |
1772 add_legacy_, | |
1773 current_streams, | |
1774 audio.get())) { | |
1775 return false; | 1882 return false; |
1776 } | 1883 } |
1777 audio->set_lang(lang_); | 1884 audio->set_lang(lang_); |
1778 | 1885 |
1779 bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); | 1886 bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); |
1780 SetMediaProtocol(secure_transport, audio.get()); | 1887 SetMediaProtocol(secure_transport, audio.get()); |
1781 | 1888 |
1782 auto offer_rtd = | 1889 audio->set_direction( |
1783 RtpTransceiverDirection(!audio->streams().empty(), options.recv_audio); | 1890 media_description_options.direction.ToMediaContentDirection()); |
1784 audio->set_direction(offer_rtd.ToMediaContentDirection()); | |
1785 | 1891 |
1786 desc->AddContent(content_name, NS_JINGLE_RTP, audio.release()); | 1892 desc->AddContent(media_description_options.mid, NS_JINGLE_RTP, |
1787 if (!AddTransportOffer(content_name, | 1893 media_description_options.stopped, audio.release()); |
1788 GetTransportOptions(options, content_name), | 1894 if (!AddTransportOffer(media_description_options.mid, |
| 1895 media_description_options.transport_options, |
1789 current_description, desc)) { | 1896 current_description, desc)) { |
1790 return false; | 1897 return false; |
1791 } | 1898 } |
1792 | 1899 |
1793 return true; | 1900 return true; |
1794 } | 1901 } |
1795 | 1902 |
1796 bool MediaSessionDescriptionFactory::AddVideoContentForOffer( | 1903 bool MediaSessionDescriptionFactory::AddVideoContentForOffer( |
1797 const MediaSessionOptions& options, | 1904 const MediaDescriptionOptions& media_description_options, |
| 1905 const MediaSessionOptions& session_options, |
| 1906 const ContentInfo* current_content, |
1798 const SessionDescription* current_description, | 1907 const SessionDescription* current_description, |
1799 const RtpHeaderExtensions& video_rtp_extensions, | 1908 const RtpHeaderExtensions& video_rtp_extensions, |
1800 const VideoCodecs& video_codecs, | 1909 const VideoCodecs& video_codecs, |
1801 StreamParamsVec* current_streams, | 1910 StreamParamsVec* current_streams, |
1802 SessionDescription* desc) const { | 1911 SessionDescription* desc) const { |
1803 const ContentInfo* current_video_content = | |
1804 GetFirstVideoContent(current_description); | |
1805 std::string content_name = | |
1806 current_video_content ? current_video_content->name : CN_VIDEO; | |
1807 | |
1808 cricket::SecurePolicy sdes_policy = | 1912 cricket::SecurePolicy sdes_policy = |
1809 IsDtlsActive(content_name, current_description) ? cricket::SEC_DISABLED | 1913 IsDtlsActive(current_content, current_description) ? cricket::SEC_DISABLED |
1810 : secure(); | 1914 : secure(); |
1811 | 1915 |
1812 std::unique_ptr<VideoContentDescription> video(new VideoContentDescription()); | 1916 std::unique_ptr<VideoContentDescription> video(new VideoContentDescription()); |
1813 std::vector<std::string> crypto_suites; | 1917 std::vector<std::string> crypto_suites; |
1814 GetSupportedVideoSdesCryptoSuiteNames(options.crypto_options, &crypto_suites); | 1918 GetSupportedVideoSdesCryptoSuiteNames(session_options.crypto_options, |
| 1919 &crypto_suites); |
| 1920 |
| 1921 VideoCodecs filtered_codecs; |
| 1922 // Add the codecs from current content if exists. |
| 1923 if (current_content) { |
| 1924 RTC_DCHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_VIDEO)); |
| 1925 const VideoContentDescription* vcd = |
| 1926 static_cast<const VideoContentDescription*>( |
| 1927 current_content->description); |
| 1928 for (const VideoCodec& codec : vcd->codecs()) { |
| 1929 if (FindMatchingCodec<VideoCodec>(video_codecs_, video_codecs, codec, |
| 1930 nullptr)) { |
| 1931 filtered_codecs.push_back(codec); |
| 1932 } |
| 1933 } |
| 1934 } |
| 1935 // Add other supported video codecs. |
| 1936 VideoCodec found_codec; |
| 1937 for (const VideoCodec& codec : video_codecs_) { |
| 1938 if (FindMatchingCodec<VideoCodec>(video_codecs_, video_codecs, codec, |
| 1939 &found_codec) && |
| 1940 !FindMatchingCodec<VideoCodec>(video_codecs_, filtered_codecs, codec, |
| 1941 nullptr)) { |
| 1942 // Use the |found_codec| from |video_codecs| because it has the correctly |
| 1943 // mapped payload type. |
| 1944 filtered_codecs.push_back(found_codec); |
| 1945 } |
| 1946 } |
| 1947 |
1815 if (!CreateMediaContentOffer( | 1948 if (!CreateMediaContentOffer( |
1816 options, | 1949 media_description_options.sender_options, session_options, |
1817 video_codecs, | 1950 filtered_codecs, sdes_policy, GetCryptos(current_content), |
1818 sdes_policy, | 1951 crypto_suites, video_rtp_extensions, current_streams, video.get())) { |
1819 GetCryptos(GetFirstVideoContentDescription(current_description)), | |
1820 crypto_suites, | |
1821 video_rtp_extensions, | |
1822 add_legacy_, | |
1823 current_streams, | |
1824 video.get())) { | |
1825 return false; | 1952 return false; |
1826 } | 1953 } |
1827 | 1954 |
1828 video->set_bandwidth(options.video_bandwidth); | 1955 video->set_bandwidth(kAutoBandwidth); |
1829 | 1956 |
1830 bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); | 1957 bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); |
1831 SetMediaProtocol(secure_transport, video.get()); | 1958 SetMediaProtocol(secure_transport, video.get()); |
1832 | 1959 |
1833 if (!video->streams().empty()) { | 1960 video->set_direction( |
1834 if (options.recv_video) { | 1961 media_description_options.direction.ToMediaContentDirection()); |
1835 video->set_direction(MD_SENDRECV); | |
1836 } else { | |
1837 video->set_direction(MD_SENDONLY); | |
1838 } | |
1839 } else { | |
1840 if (options.recv_video) { | |
1841 video->set_direction(MD_RECVONLY); | |
1842 } else { | |
1843 video->set_direction(MD_INACTIVE); | |
1844 } | |
1845 } | |
1846 | 1962 |
1847 desc->AddContent(content_name, NS_JINGLE_RTP, video.release()); | 1963 desc->AddContent(media_description_options.mid, NS_JINGLE_RTP, |
1848 if (!AddTransportOffer(content_name, | 1964 media_description_options.stopped, video.release()); |
1849 GetTransportOptions(options, content_name), | 1965 if (!AddTransportOffer(media_description_options.mid, |
| 1966 media_description_options.transport_options, |
1850 current_description, desc)) { | 1967 current_description, desc)) { |
1851 return false; | 1968 return false; |
1852 } | 1969 } |
1853 | |
1854 return true; | 1970 return true; |
1855 } | 1971 } |
1856 | 1972 |
1857 bool MediaSessionDescriptionFactory::AddDataContentForOffer( | 1973 bool MediaSessionDescriptionFactory::AddDataContentForOffer( |
1858 const MediaSessionOptions& options, | 1974 const MediaDescriptionOptions& media_description_options, |
| 1975 const MediaSessionOptions& session_options, |
| 1976 const ContentInfo* current_content, |
1859 const SessionDescription* current_description, | 1977 const SessionDescription* current_description, |
1860 DataCodecs* data_codecs, | 1978 const DataCodecs& data_codecs, |
1861 StreamParamsVec* current_streams, | 1979 StreamParamsVec* current_streams, |
1862 SessionDescription* desc) const { | 1980 SessionDescription* desc) const { |
1863 bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); | 1981 bool secure_transport = (transport_desc_factory_->secure() != SEC_DISABLED); |
1864 | 1982 |
1865 std::unique_ptr<DataContentDescription> data(new DataContentDescription()); | 1983 std::unique_ptr<DataContentDescription> data(new DataContentDescription()); |
1866 bool is_sctp = (options.data_channel_type == DCT_SCTP); | 1984 bool is_sctp = (session_options.data_channel_type == DCT_SCTP); |
1867 | 1985 // If the DataChannel type is not specified, use the DataChannel type in |
1868 FilterDataCodecs(data_codecs, is_sctp); | 1986 // the current description. |
1869 | 1987 if (session_options.data_channel_type == DCT_NONE && current_content) { |
1870 const ContentInfo* current_data_content = | 1988 is_sctp = (static_cast<const DataContentDescription*>( |
1871 GetFirstDataContent(current_description); | 1989 current_content->description) |
1872 std::string content_name = | 1990 ->protocol() == kMediaProtocolSctp); |
1873 current_data_content ? current_data_content->name : CN_DATA; | 1991 } |
1874 | 1992 |
1875 cricket::SecurePolicy sdes_policy = | 1993 cricket::SecurePolicy sdes_policy = |
1876 IsDtlsActive(content_name, current_description) ? cricket::SEC_DISABLED | 1994 IsDtlsActive(current_content, current_description) ? cricket::SEC_DISABLED |
1877 : secure(); | 1995 : secure(); |
1878 std::vector<std::string> crypto_suites; | 1996 std::vector<std::string> crypto_suites; |
1879 if (is_sctp) { | 1997 if (is_sctp) { |
1880 // SDES doesn't make sense for SCTP, so we disable it, and we only | 1998 // SDES doesn't make sense for SCTP, so we disable it, and we only |
1881 // get SDES crypto suites for RTP-based data channels. | 1999 // get SDES crypto suites for RTP-based data channels. |
1882 sdes_policy = cricket::SEC_DISABLED; | 2000 sdes_policy = cricket::SEC_DISABLED; |
1883 // Unlike SetMediaProtocol below, we need to set the protocol | 2001 // Unlike SetMediaProtocol below, we need to set the protocol |
1884 // before we call CreateMediaContentOffer. Otherwise, | 2002 // before we call CreateMediaContentOffer. Otherwise, |
1885 // CreateMediaContentOffer won't know this is SCTP and will | 2003 // CreateMediaContentOffer won't know this is SCTP and will |
1886 // generate SSRCs rather than SIDs. | 2004 // generate SSRCs rather than SIDs. |
1887 // TODO(deadbeef): Offer kMediaProtocolUdpDtlsSctp (or TcpDtlsSctp), once | 2005 // TODO(deadbeef): Offer kMediaProtocolUdpDtlsSctp (or TcpDtlsSctp), once |
1888 // it's safe to do so. Older versions of webrtc would reject these | 2006 // it's safe to do so. Older versions of webrtc would reject these |
1889 // protocols; see https://bugs.chromium.org/p/webrtc/issues/detail?id=7706. | 2007 // protocols; see https://bugs.chromium.org/p/webrtc/issues/detail?id=7706. |
1890 data->set_protocol( | 2008 data->set_protocol( |
1891 secure_transport ? kMediaProtocolDtlsSctp : kMediaProtocolSctp); | 2009 secure_transport ? kMediaProtocolDtlsSctp : kMediaProtocolSctp); |
1892 } else { | 2010 } else { |
1893 GetSupportedDataSdesCryptoSuiteNames(options.crypto_options, | 2011 GetSupportedDataSdesCryptoSuiteNames(session_options.crypto_options, |
1894 &crypto_suites); | 2012 &crypto_suites); |
1895 } | 2013 } |
1896 | 2014 |
| 2015 // Even SCTP uses a "codec". |
1897 if (!CreateMediaContentOffer( | 2016 if (!CreateMediaContentOffer( |
1898 options, | 2017 media_description_options.sender_options, session_options, |
1899 *data_codecs, | 2018 data_codecs, sdes_policy, GetCryptos(current_content), crypto_suites, |
1900 sdes_policy, | 2019 RtpHeaderExtensions(), current_streams, data.get())) { |
1901 GetCryptos(GetFirstDataContentDescription(current_description)), | |
1902 crypto_suites, | |
1903 RtpHeaderExtensions(), | |
1904 add_legacy_, | |
1905 current_streams, | |
1906 data.get())) { | |
1907 return false; | 2020 return false; |
1908 } | 2021 } |
1909 | 2022 |
1910 if (is_sctp) { | 2023 if (is_sctp) { |
1911 desc->AddContent(content_name, NS_JINGLE_DRAFT_SCTP, data.release()); | 2024 desc->AddContent(media_description_options.mid, NS_JINGLE_DRAFT_SCTP, |
1912 } else { | 2025 data.release()); |
1913 data->set_bandwidth(options.data_bandwidth); | 2026 } else { |
| 2027 data->set_bandwidth(kDataMaxBandwidth); |
1914 SetMediaProtocol(secure_transport, data.get()); | 2028 SetMediaProtocol(secure_transport, data.get()); |
1915 desc->AddContent(content_name, NS_JINGLE_RTP, data.release()); | 2029 desc->AddContent(media_description_options.mid, NS_JINGLE_RTP, |
1916 } | 2030 media_description_options.stopped, data.release()); |
1917 if (!AddTransportOffer(content_name, | 2031 } |
1918 GetTransportOptions(options, content_name), | 2032 if (!AddTransportOffer(media_description_options.mid, |
| 2033 media_description_options.transport_options, |
1919 current_description, desc)) { | 2034 current_description, desc)) { |
1920 return false; | 2035 return false; |
1921 } | 2036 } |
1922 return true; | 2037 return true; |
1923 } | 2038 } |
1924 | 2039 |
| 2040 // |audio_codecs| = set of all possible codecs that can be used, with correct |
| 2041 // payload type mappings |
| 2042 // |
| 2043 // |supported_audio_codecs| = set of codecs that are supported for the direction |
| 2044 // of this m= section |
| 2045 // |
| 2046 // acd->codecs() = set of previously negotiated codecs for this m= section |
| 2047 // |
| 2048 // The payload types should come from audio_codecs, but the order should come |
| 2049 // from acd->codecs() and then supported_codecs, to ensure that re-offers don't |
| 2050 // change existing codec priority, and that new codecs are added with the right |
| 2051 // priority. |
1925 bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( | 2052 bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( |
1926 const SessionDescription* offer, | 2053 const MediaDescriptionOptions& media_description_options, |
1927 const MediaSessionOptions& options, | 2054 const MediaSessionOptions& session_options, |
| 2055 const ContentInfo* offer_content, |
| 2056 const SessionDescription* offer_description, |
| 2057 const ContentInfo* current_content, |
1928 const SessionDescription* current_description, | 2058 const SessionDescription* current_description, |
1929 const TransportInfo* bundle_transport, | 2059 const TransportInfo* bundle_transport, |
| 2060 const AudioCodecs& audio_codecs, |
1930 StreamParamsVec* current_streams, | 2061 StreamParamsVec* current_streams, |
1931 SessionDescription* answer) const { | 2062 SessionDescription* answer) const { |
1932 const ContentInfo* audio_content = GetFirstAudioContent(offer); | 2063 const AudioContentDescription* offer_audio_description = |
1933 const AudioContentDescription* offer_audio = | 2064 static_cast<const AudioContentDescription*>(offer_content->description); |
1934 static_cast<const AudioContentDescription*>(audio_content->description); | |
1935 | 2065 |
1936 std::unique_ptr<TransportDescription> audio_transport( | 2066 std::unique_ptr<TransportDescription> audio_transport( |
1937 CreateTransportAnswer(audio_content->name, offer, | 2067 CreateTransportAnswer(media_description_options.mid, offer_description, |
1938 GetTransportOptions(options, audio_content->name), | 2068 media_description_options.transport_options, |
1939 current_description, bundle_transport != nullptr)); | 2069 current_description, bundle_transport != nullptr)); |
1940 if (!audio_transport) { | 2070 if (!audio_transport) { |
1941 return false; | 2071 return false; |
1942 } | 2072 } |
1943 | 2073 |
1944 // Pick codecs based on the requested communications direction in the offer. | 2074 // Pick codecs based on the requested communications direction in the offer |
1945 const bool wants_send = | 2075 // and the selected direction in the answer. |
1946 options.HasSendMediaStream(MEDIA_TYPE_AUDIO) || add_legacy_; | 2076 // Note these will be filtered one final time in CreateMediaContentAnswer. |
1947 auto wants_rtd = RtpTransceiverDirection(wants_send, options.recv_audio); | 2077 auto wants_rtd = media_description_options.direction; |
1948 auto offer_rtd = | 2078 auto offer_rtd = RtpTransceiverDirection::FromMediaContentDirection( |
1949 RtpTransceiverDirection::FromMediaContentDirection( | 2079 offer_audio_description->direction()); |
1950 offer_audio->direction()); | |
1951 auto answer_rtd = NegotiateRtpTransceiverDirection(offer_rtd, wants_rtd); | 2080 auto answer_rtd = NegotiateRtpTransceiverDirection(offer_rtd, wants_rtd); |
1952 AudioCodecs audio_codecs = GetAudioCodecsForAnswer(offer_rtd, answer_rtd); | 2081 AudioCodecs supported_audio_codecs = |
1953 if (!options.vad_enabled) { | 2082 GetAudioCodecsForAnswer(offer_rtd, answer_rtd); |
1954 StripCNCodecs(&audio_codecs); | 2083 |
1955 } | 2084 AudioCodecs filtered_codecs; |
1956 | 2085 // Add the codecs from current content if exists. |
1957 bool bundle_enabled = | 2086 if (current_content) { |
1958 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; | 2087 RTC_DCHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_AUDIO)); |
| 2088 const AudioContentDescription* acd = |
| 2089 static_cast<const AudioContentDescription*>( |
| 2090 current_content->description); |
| 2091 for (const AudioCodec& codec : acd->codecs()) { |
| 2092 if (FindMatchingCodec<AudioCodec>(supported_audio_codecs, audio_codecs, |
| 2093 codec, nullptr)) { |
| 2094 filtered_codecs.push_back(codec); |
| 2095 } |
| 2096 } |
| 2097 } |
| 2098 // Add other supported audio codecs. |
| 2099 AudioCodec found_codec; |
| 2100 for (const AudioCodec& codec : supported_audio_codecs) { |
| 2101 if (FindMatchingCodec<AudioCodec>(supported_audio_codecs, audio_codecs, |
| 2102 codec, &found_codec) && |
| 2103 !FindMatchingCodec<AudioCodec>(supported_audio_codecs, filtered_codecs, |
| 2104 codec, nullptr)) { |
| 2105 // Use the |found_codec| from |audio_codecs| because it has the correctly |
| 2106 // mapped payload type. |
| 2107 filtered_codecs.push_back(found_codec); |
| 2108 } |
| 2109 } |
| 2110 |
| 2111 bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) && |
| 2112 session_options.bundle_enabled; |
1959 std::unique_ptr<AudioContentDescription> audio_answer( | 2113 std::unique_ptr<AudioContentDescription> audio_answer( |
1960 new AudioContentDescription()); | 2114 new AudioContentDescription()); |
1961 // Do not require or create SDES cryptos if DTLS is used. | 2115 // Do not require or create SDES cryptos if DTLS is used. |
1962 cricket::SecurePolicy sdes_policy = | 2116 cricket::SecurePolicy sdes_policy = |
1963 audio_transport->secure() ? cricket::SEC_DISABLED : secure(); | 2117 audio_transport->secure() ? cricket::SEC_DISABLED : secure(); |
1964 if (!CreateMediaContentAnswer( | 2118 if (!CreateMediaContentAnswer( |
1965 offer_audio, | 2119 offer_audio_description, media_description_options, session_options, |
1966 options, | 2120 filtered_codecs, sdes_policy, GetCryptos(current_content), |
1967 audio_codecs, | 2121 audio_rtp_extensions_, enable_encrypted_rtp_header_extensions_, |
1968 sdes_policy, | 2122 current_streams, bundle_enabled, audio_answer.get())) { |
1969 GetCryptos(GetFirstAudioContentDescription(current_description)), | |
1970 audio_rtp_extensions_, | |
1971 enable_encrypted_rtp_header_extensions_, | |
1972 current_streams, | |
1973 add_legacy_, | |
1974 bundle_enabled, | |
1975 audio_answer.get())) { | |
1976 return false; // Fails the session setup. | 2123 return false; // Fails the session setup. |
1977 } | 2124 } |
1978 | 2125 |
1979 bool secure = bundle_transport ? bundle_transport->description.secure() | 2126 bool secure = bundle_transport ? bundle_transport->description.secure() |
1980 : audio_transport->secure(); | 2127 : audio_transport->secure(); |
1981 bool rejected = !options.has_audio() || audio_content->rejected || | 2128 bool rejected = media_description_options.stopped || |
| 2129 offer_content->rejected || |
1982 !IsMediaProtocolSupported(MEDIA_TYPE_AUDIO, | 2130 !IsMediaProtocolSupported(MEDIA_TYPE_AUDIO, |
1983 audio_answer->protocol(), secure); | 2131 audio_answer->protocol(), secure); |
1984 if (!rejected) { | 2132 if (!rejected) { |
1985 AddTransportAnswer(audio_content->name, *(audio_transport.get()), answer); | 2133 AddTransportAnswer(media_description_options.mid, *(audio_transport.get()), |
1986 } else { | 2134 answer); |
1987 // RFC 3264 | 2135 } else { |
1988 // The answer MUST contain the same number of m-lines as the offer. | 2136 LOG(LS_INFO) << "Audio m= section '" << media_description_options.mid |
1989 LOG(LS_INFO) << "Audio is not supported in the answer."; | 2137 << "' being rejected in answer."; |
1990 } | 2138 } |
1991 | 2139 |
1992 answer->AddContent(audio_content->name, audio_content->type, rejected, | 2140 answer->AddContent(media_description_options.mid, offer_content->type, |
1993 audio_answer.release()); | 2141 rejected, audio_answer.release()); |
1994 return true; | 2142 return true; |
1995 } | 2143 } |
1996 | 2144 |
1997 bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( | 2145 bool MediaSessionDescriptionFactory::AddVideoContentForAnswer( |
1998 const SessionDescription* offer, | 2146 const MediaDescriptionOptions& media_description_options, |
1999 const MediaSessionOptions& options, | 2147 const MediaSessionOptions& session_options, |
| 2148 const ContentInfo* offer_content, |
| 2149 const SessionDescription* offer_description, |
| 2150 const ContentInfo* current_content, |
2000 const SessionDescription* current_description, | 2151 const SessionDescription* current_description, |
2001 const TransportInfo* bundle_transport, | 2152 const TransportInfo* bundle_transport, |
| 2153 const VideoCodecs& video_codecs, |
2002 StreamParamsVec* current_streams, | 2154 StreamParamsVec* current_streams, |
2003 SessionDescription* answer) const { | 2155 SessionDescription* answer) const { |
2004 const ContentInfo* video_content = GetFirstVideoContent(offer); | 2156 const VideoContentDescription* offer_video_description = |
| 2157 static_cast<const VideoContentDescription*>(offer_content->description); |
| 2158 |
2005 std::unique_ptr<TransportDescription> video_transport( | 2159 std::unique_ptr<TransportDescription> video_transport( |
2006 CreateTransportAnswer(video_content->name, offer, | 2160 CreateTransportAnswer(media_description_options.mid, offer_description, |
2007 GetTransportOptions(options, video_content->name), | 2161 media_description_options.transport_options, |
2008 current_description, bundle_transport != nullptr)); | 2162 current_description, bundle_transport != nullptr)); |
2009 if (!video_transport) { | 2163 if (!video_transport) { |
2010 return false; | 2164 return false; |
2011 } | 2165 } |
2012 | 2166 |
| 2167 VideoCodecs filtered_codecs; |
| 2168 // Add the codecs from current content if exists. |
| 2169 if (current_content) { |
| 2170 RTC_DCHECK(IsMediaContentOfType(current_content, MEDIA_TYPE_VIDEO)); |
| 2171 const VideoContentDescription* vcd = |
| 2172 static_cast<const VideoContentDescription*>( |
| 2173 current_content->description); |
| 2174 for (const VideoCodec& codec : vcd->codecs()) { |
| 2175 if (FindMatchingCodec<VideoCodec>(video_codecs_, video_codecs, codec, |
| 2176 nullptr)) { |
| 2177 filtered_codecs.push_back(codec); |
| 2178 } |
| 2179 } |
| 2180 } |
| 2181 // Add other supported video codecs. |
| 2182 VideoCodec found_codec; |
| 2183 for (const VideoCodec& codec : video_codecs_) { |
| 2184 if (FindMatchingCodec<VideoCodec>(video_codecs_, video_codecs, codec, |
| 2185 &found_codec) && |
| 2186 !FindMatchingCodec<VideoCodec>(video_codecs_, filtered_codecs, codec, |
| 2187 nullptr)) { |
| 2188 // Use the |found_codec| from |video_codecs| because it has the correctly |
| 2189 // mapped payload type. |
| 2190 filtered_codecs.push_back(found_codec); |
| 2191 } |
| 2192 } |
| 2193 |
| 2194 bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) && |
| 2195 session_options.bundle_enabled; |
| 2196 |
2013 std::unique_ptr<VideoContentDescription> video_answer( | 2197 std::unique_ptr<VideoContentDescription> video_answer( |
2014 new VideoContentDescription()); | 2198 new VideoContentDescription()); |
2015 // Do not require or create SDES cryptos if DTLS is used. | 2199 // Do not require or create SDES cryptos if DTLS is used. |
2016 cricket::SecurePolicy sdes_policy = | 2200 cricket::SecurePolicy sdes_policy = |
2017 video_transport->secure() ? cricket::SEC_DISABLED : secure(); | 2201 video_transport->secure() ? cricket::SEC_DISABLED : secure(); |
2018 bool bundle_enabled = | |
2019 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; | |
2020 if (!CreateMediaContentAnswer( | 2202 if (!CreateMediaContentAnswer( |
2021 static_cast<const VideoContentDescription*>( | 2203 offer_video_description, media_description_options, session_options, |
2022 video_content->description), | 2204 filtered_codecs, sdes_policy, GetCryptos(current_content), |
2023 options, | 2205 video_rtp_extensions_, enable_encrypted_rtp_header_extensions_, |
2024 video_codecs_, | 2206 current_streams, bundle_enabled, video_answer.get())) { |
2025 sdes_policy, | 2207 return false; // Failed the sessin setup. |
2026 GetCryptos(GetFirstVideoContentDescription(current_description)), | |
2027 video_rtp_extensions_, | |
2028 enable_encrypted_rtp_header_extensions_, | |
2029 current_streams, | |
2030 add_legacy_, | |
2031 bundle_enabled, | |
2032 video_answer.get())) { | |
2033 return false; | |
2034 } | 2208 } |
2035 bool secure = bundle_transport ? bundle_transport->description.secure() | 2209 bool secure = bundle_transport ? bundle_transport->description.secure() |
2036 : video_transport->secure(); | 2210 : video_transport->secure(); |
2037 bool rejected = !options.has_video() || video_content->rejected || | 2211 bool rejected = media_description_options.stopped || |
| 2212 offer_content->rejected || |
2038 !IsMediaProtocolSupported(MEDIA_TYPE_VIDEO, | 2213 !IsMediaProtocolSupported(MEDIA_TYPE_VIDEO, |
2039 video_answer->protocol(), secure); | 2214 video_answer->protocol(), secure); |
2040 if (!rejected) { | 2215 if (!rejected) { |
2041 if (!AddTransportAnswer(video_content->name, *(video_transport.get()), | 2216 if (!AddTransportAnswer(media_description_options.mid, |
2042 answer)) { | 2217 *(video_transport.get()), answer)) { |
2043 return false; | 2218 return false; |
2044 } | 2219 } |
2045 video_answer->set_bandwidth(options.video_bandwidth); | 2220 video_answer->set_bandwidth(kAutoBandwidth); |
2046 } else { | 2221 } else { |
2047 // RFC 3264 | 2222 LOG(LS_INFO) << "Video m= section '" << media_description_options.mid |
2048 // The answer MUST contain the same number of m-lines as the offer. | 2223 << "' being rejected in answer."; |
2049 LOG(LS_INFO) << "Video is not supported in the answer."; | 2224 } |
2050 } | 2225 answer->AddContent(media_description_options.mid, offer_content->type, |
2051 answer->AddContent(video_content->name, video_content->type, rejected, | 2226 rejected, video_answer.release()); |
2052 video_answer.release()); | |
2053 return true; | 2227 return true; |
2054 } | 2228 } |
2055 | 2229 |
2056 bool MediaSessionDescriptionFactory::AddDataContentForAnswer( | 2230 bool MediaSessionDescriptionFactory::AddDataContentForAnswer( |
2057 const SessionDescription* offer, | 2231 const MediaDescriptionOptions& media_description_options, |
2058 const MediaSessionOptions& options, | 2232 const MediaSessionOptions& session_options, |
| 2233 const ContentInfo* offer_content, |
| 2234 const SessionDescription* offer_description, |
| 2235 const ContentInfo* current_content, |
2059 const SessionDescription* current_description, | 2236 const SessionDescription* current_description, |
2060 const TransportInfo* bundle_transport, | 2237 const TransportInfo* bundle_transport, |
| 2238 const DataCodecs& data_codecs, |
2061 StreamParamsVec* current_streams, | 2239 StreamParamsVec* current_streams, |
2062 SessionDescription* answer) const { | 2240 SessionDescription* answer) const { |
2063 const ContentInfo* data_content = GetFirstDataContent(offer); | |
2064 std::unique_ptr<TransportDescription> data_transport( | 2241 std::unique_ptr<TransportDescription> data_transport( |
2065 CreateTransportAnswer(data_content->name, offer, | 2242 CreateTransportAnswer(media_description_options.mid, offer_description, |
2066 GetTransportOptions(options, data_content->name), | 2243 media_description_options.transport_options, |
2067 current_description, bundle_transport != nullptr)); | 2244 current_description, bundle_transport != nullptr)); |
2068 if (!data_transport) { | 2245 if (!data_transport) { |
2069 return false; | 2246 return false; |
2070 } | 2247 } |
2071 bool is_sctp = (options.data_channel_type == DCT_SCTP); | |
2072 std::vector<DataCodec> data_codecs(data_codecs_); | |
2073 FilterDataCodecs(&data_codecs, is_sctp); | |
2074 | 2248 |
2075 std::unique_ptr<DataContentDescription> data_answer( | 2249 std::unique_ptr<DataContentDescription> data_answer( |
2076 new DataContentDescription()); | 2250 new DataContentDescription()); |
2077 // Do not require or create SDES cryptos if DTLS is used. | 2251 // Do not require or create SDES cryptos if DTLS is used. |
2078 cricket::SecurePolicy sdes_policy = | 2252 cricket::SecurePolicy sdes_policy = |
2079 data_transport->secure() ? cricket::SEC_DISABLED : secure(); | 2253 data_transport->secure() ? cricket::SEC_DISABLED : secure(); |
2080 bool bundle_enabled = | 2254 bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) && |
2081 offer->HasGroup(GROUP_TYPE_BUNDLE) && options.bundle_enabled; | 2255 session_options.bundle_enabled; |
2082 if (!CreateMediaContentAnswer( | 2256 if (!CreateMediaContentAnswer( |
2083 static_cast<const DataContentDescription*>( | 2257 static_cast<const DataContentDescription*>( |
2084 data_content->description), | 2258 offer_content->description), |
2085 options, | 2259 media_description_options, session_options, data_codecs, sdes_policy, |
2086 data_codecs_, | 2260 GetCryptos(current_content), RtpHeaderExtensions(), |
2087 sdes_policy, | 2261 enable_encrypted_rtp_header_extensions_, current_streams, |
2088 GetCryptos(GetFirstDataContentDescription(current_description)), | 2262 bundle_enabled, data_answer.get())) { |
2089 RtpHeaderExtensions(), | |
2090 enable_encrypted_rtp_header_extensions_, | |
2091 current_streams, | |
2092 add_legacy_, | |
2093 bundle_enabled, | |
2094 data_answer.get())) { | |
2095 return false; // Fails the session setup. | 2263 return false; // Fails the session setup. |
2096 } | 2264 } |
2097 | 2265 |
2098 // Respond with sctpmap if the offer uses sctpmap. | 2266 // Respond with sctpmap if the offer uses sctpmap. |
2099 const DataContentDescription* offer_data_description = | 2267 const DataContentDescription* offer_data_description = |
2100 static_cast<const DataContentDescription*>(data_content->description); | 2268 static_cast<const DataContentDescription*>(offer_content->description); |
2101 bool offer_uses_sctpmap = offer_data_description->use_sctpmap(); | 2269 bool offer_uses_sctpmap = offer_data_description->use_sctpmap(); |
2102 data_answer->set_use_sctpmap(offer_uses_sctpmap); | 2270 data_answer->set_use_sctpmap(offer_uses_sctpmap); |
2103 | 2271 |
2104 bool secure = bundle_transport ? bundle_transport->description.secure() | 2272 bool secure = bundle_transport ? bundle_transport->description.secure() |
2105 : data_transport->secure(); | 2273 : data_transport->secure(); |
2106 | 2274 |
2107 bool rejected = !options.has_data() || data_content->rejected || | 2275 bool rejected = session_options.data_channel_type == DCT_NONE || |
| 2276 media_description_options.stopped || |
| 2277 offer_content->rejected || |
2108 !IsMediaProtocolSupported(MEDIA_TYPE_DATA, | 2278 !IsMediaProtocolSupported(MEDIA_TYPE_DATA, |
2109 data_answer->protocol(), secure); | 2279 data_answer->protocol(), secure); |
2110 if (!rejected) { | 2280 if (!rejected) { |
2111 data_answer->set_bandwidth(options.data_bandwidth); | 2281 data_answer->set_bandwidth(kDataMaxBandwidth); |
2112 if (!AddTransportAnswer(data_content->name, *(data_transport.get()), | 2282 if (!AddTransportAnswer(media_description_options.mid, |
2113 answer)) { | 2283 *(data_transport.get()), answer)) { |
2114 return false; | 2284 return false; |
2115 } | 2285 } |
2116 } else { | 2286 } else { |
2117 // RFC 3264 | 2287 // RFC 3264 |
2118 // The answer MUST contain the same number of m-lines as the offer. | 2288 // The answer MUST contain the same number of m-lines as the offer. |
2119 LOG(LS_INFO) << "Data is not supported in the answer."; | 2289 LOG(LS_INFO) << "Data is not supported in the answer."; |
2120 } | 2290 } |
2121 answer->AddContent(data_content->name, data_content->type, rejected, | 2291 answer->AddContent(media_description_options.mid, offer_content->type, |
2122 data_answer.release()); | 2292 rejected, data_answer.release()); |
2123 return true; | 2293 return true; |
2124 } | 2294 } |
2125 | 2295 |
| 2296 void MediaSessionDescriptionFactory::ComputeAudioCodecsIntersectionAndUnion() { |
| 2297 audio_sendrecv_codecs_.clear(); |
| 2298 all_audio_codecs_.clear(); |
| 2299 // Compute the audio codecs union. |
| 2300 for (const AudioCodec& send : audio_send_codecs_) { |
| 2301 all_audio_codecs_.push_back(send); |
| 2302 if (!FindMatchingCodec<AudioCodec>(audio_send_codecs_, audio_recv_codecs_, |
| 2303 send, nullptr)) { |
| 2304 // It doesn't make sense to have an RTX codec we support sending but not |
| 2305 // receiving. |
| 2306 RTC_DCHECK(!IsRtxCodec(send)); |
| 2307 } |
| 2308 } |
| 2309 for (const AudioCodec& recv : audio_recv_codecs_) { |
| 2310 if (!FindMatchingCodec<AudioCodec>(audio_recv_codecs_, audio_send_codecs_, |
| 2311 recv, nullptr)) { |
| 2312 all_audio_codecs_.push_back(recv); |
| 2313 } |
| 2314 } |
| 2315 // Use NegotiateCodecs to merge our codec lists, since the operation is |
| 2316 // essentially the same. Put send_codecs as the offered_codecs, which is the |
| 2317 // order we'd like to follow. The reasoning is that encoding is usually more |
| 2318 // expensive than decoding, and prioritizing a codec in the send list probably |
| 2319 // means it's a codec we can handle efficiently. |
| 2320 NegotiateCodecs(audio_recv_codecs_, audio_send_codecs_, |
| 2321 &audio_sendrecv_codecs_); |
| 2322 } |
| 2323 |
2126 bool IsMediaContent(const ContentInfo* content) { | 2324 bool IsMediaContent(const ContentInfo* content) { |
2127 return (content && | 2325 return (content && |
2128 (content->type == NS_JINGLE_RTP || | 2326 (content->type == NS_JINGLE_RTP || |
2129 content->type == NS_JINGLE_DRAFT_SCTP)); | 2327 content->type == NS_JINGLE_DRAFT_SCTP)); |
2130 } | 2328 } |
2131 | 2329 |
2132 bool IsAudioContent(const ContentInfo* content) { | 2330 bool IsAudioContent(const ContentInfo* content) { |
2133 return IsMediaContentOfType(content, MEDIA_TYPE_AUDIO); | 2331 return IsMediaContentOfType(content, MEDIA_TYPE_AUDIO); |
2134 } | 2332 } |
2135 | 2333 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2276 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); | 2474 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_VIDEO)); |
2277 } | 2475 } |
2278 | 2476 |
2279 DataContentDescription* GetFirstDataContentDescription( | 2477 DataContentDescription* GetFirstDataContentDescription( |
2280 SessionDescription* sdesc) { | 2478 SessionDescription* sdesc) { |
2281 return static_cast<DataContentDescription*>( | 2479 return static_cast<DataContentDescription*>( |
2282 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); | 2480 GetFirstMediaContentDescription(sdesc, MEDIA_TYPE_DATA)); |
2283 } | 2481 } |
2284 | 2482 |
2285 } // namespace cricket | 2483 } // namespace cricket |
OLD | NEW |