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