OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 LOG(LS_INFO) << "WebRtcVideoEngine2::Init"; | 554 LOG(LS_INFO) << "WebRtcVideoEngine2::Init"; |
555 initialized_ = true; | 555 initialized_ = true; |
556 } | 556 } |
557 | 557 |
558 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( | 558 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( |
559 webrtc::Call* call, | 559 webrtc::Call* call, |
560 const MediaConfig& config, | 560 const MediaConfig& config, |
561 const VideoOptions& options) { | 561 const VideoOptions& options) { |
562 RTC_DCHECK(initialized_); | 562 RTC_DCHECK(initialized_); |
563 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); | 563 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); |
564 return new WebRtcVideoChannel2(call, config, options, video_codecs_, | 564 return new WebRtcVideoChannel2(call, config, options, |
565 external_encoder_factory_, | 565 external_encoder_factory_, |
566 external_decoder_factory_); | 566 external_decoder_factory_); |
567 } | 567 } |
568 | 568 |
569 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { | 569 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { |
570 return video_codecs_; | 570 return video_codecs_; |
571 } | 571 } |
572 | 572 |
573 RtpCapabilities WebRtcVideoEngine2::GetCapabilities() const { | 573 RtpCapabilities WebRtcVideoEngine2::GetCapabilities() const { |
574 RtpCapabilities capabilities; | 574 RtpCapabilities capabilities; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 << CodecVectorToString(supported_codecs); | 661 << CodecVectorToString(supported_codecs); |
662 LOG(LS_INFO) << "Codecs supported by the external encoder factory: " | 662 LOG(LS_INFO) << "Codecs supported by the external encoder factory: " |
663 << out.str(); | 663 << out.str(); |
664 return supported_codecs; | 664 return supported_codecs; |
665 } | 665 } |
666 | 666 |
667 WebRtcVideoChannel2::WebRtcVideoChannel2( | 667 WebRtcVideoChannel2::WebRtcVideoChannel2( |
668 webrtc::Call* call, | 668 webrtc::Call* call, |
669 const MediaConfig& config, | 669 const MediaConfig& config, |
670 const VideoOptions& options, | 670 const VideoOptions& options, |
671 const std::vector<VideoCodec>& recv_codecs, | |
672 WebRtcVideoEncoderFactory* external_encoder_factory, | 671 WebRtcVideoEncoderFactory* external_encoder_factory, |
673 WebRtcVideoDecoderFactory* external_decoder_factory) | 672 WebRtcVideoDecoderFactory* external_decoder_factory) |
674 : VideoMediaChannel(config), | 673 : VideoMediaChannel(config), |
675 call_(call), | 674 call_(call), |
676 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), | 675 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), |
677 video_config_(config.video), | 676 video_config_(config.video), |
678 external_encoder_factory_(external_encoder_factory), | 677 external_encoder_factory_(external_encoder_factory), |
679 external_decoder_factory_(external_decoder_factory), | 678 external_decoder_factory_(external_decoder_factory), |
680 default_send_options_(options), | 679 default_send_options_(options), |
681 red_disabled_by_remote_side_(false), | 680 red_disabled_by_remote_side_(false), |
682 last_stats_log_ms_(-1) { | 681 last_stats_log_ms_(-1) { |
683 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 682 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
684 | 683 |
685 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; | 684 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; |
686 sending_ = false; | 685 sending_ = false; |
687 RTC_DCHECK(ValidateCodecFormats(recv_codecs)); | 686 recv_codecs_ = MapCodecs(GetSupportedCodecs(external_encoder_factory)); |
688 recv_codecs_ = FilterSupportedCodecs(MapCodecs(recv_codecs)); | |
689 } | 687 } |
690 | 688 |
691 WebRtcVideoChannel2::~WebRtcVideoChannel2() { | 689 WebRtcVideoChannel2::~WebRtcVideoChannel2() { |
692 for (auto& kv : send_streams_) | 690 for (auto& kv : send_streams_) |
693 delete kv.second; | 691 delete kv.second; |
694 for (auto& kv : receive_streams_) | 692 for (auto& kv : receive_streams_) |
695 delete kv.second; | 693 delete kv.second; |
696 } | 694 } |
697 | 695 |
698 std::vector<WebRtcVideoChannel2::VideoCodecSettings> | 696 rtc::Optional<WebRtcVideoChannel2::VideoCodecSettings> |
699 WebRtcVideoChannel2::FilterSupportedCodecs( | 697 WebRtcVideoChannel2::SelectSendVideoCodec( |
700 const std::vector<VideoCodecSettings>& mapped_codecs) const { | 698 const std::vector<VideoCodecSettings>& remote_mapped_codecs) const { |
701 const std::vector<VideoCodec> supported_codecs = | 699 const std::vector<VideoCodec> local_supported_codecs = |
702 GetSupportedCodecs(external_encoder_factory_); | 700 GetSupportedCodecs(external_encoder_factory_); |
703 std::vector<VideoCodecSettings> filtered_codecs; | 701 // Select the first remote codec that is supported locally. |
704 for (const VideoCodecSettings& mapped_codec : mapped_codecs) { | 702 for (const VideoCodecSettings& remote_mapped_codec : remote_mapped_codecs) { |
705 if (IsCodecSupported(supported_codecs, mapped_codec.codec)) | 703 if (IsCodecSupported(local_supported_codecs, remote_mapped_codec.codec)) |
706 filtered_codecs.push_back(mapped_codec); | 704 return rtc::Optional<VideoCodecSettings>(remote_mapped_codec); |
707 } | 705 } |
708 return filtered_codecs; | 706 // No remote codec was supported. |
| 707 return rtc::Optional<VideoCodecSettings>(); |
709 } | 708 } |
710 | 709 |
711 bool WebRtcVideoChannel2::ReceiveCodecsHaveChanged( | 710 bool WebRtcVideoChannel2::ReceiveCodecsHaveChanged( |
712 std::vector<VideoCodecSettings> before, | 711 std::vector<VideoCodecSettings> before, |
713 std::vector<VideoCodecSettings> after) { | 712 std::vector<VideoCodecSettings> after) { |
714 if (before.size() != after.size()) { | 713 if (before.size() != after.size()) { |
715 return true; | 714 return true; |
716 } | 715 } |
717 // The receive codec order doesn't matter, so we sort the codecs before | 716 // The receive codec order doesn't matter, so we sort the codecs before |
718 // comparing. This is necessary because currently the | 717 // comparing. This is necessary because currently the |
(...skipping 13 matching lines...) Expand all Loading... |
732 } | 731 } |
733 | 732 |
734 bool WebRtcVideoChannel2::GetChangedSendParameters( | 733 bool WebRtcVideoChannel2::GetChangedSendParameters( |
735 const VideoSendParameters& params, | 734 const VideoSendParameters& params, |
736 ChangedSendParameters* changed_params) const { | 735 ChangedSendParameters* changed_params) const { |
737 if (!ValidateCodecFormats(params.codecs) || | 736 if (!ValidateCodecFormats(params.codecs) || |
738 !ValidateRtpExtensions(params.extensions)) { | 737 !ValidateRtpExtensions(params.extensions)) { |
739 return false; | 738 return false; |
740 } | 739 } |
741 | 740 |
742 // Handle send codec. | 741 // Select one of the remote codecs that will be used as send codec. |
743 const std::vector<VideoCodecSettings> supported_codecs = | 742 const rtc::Optional<VideoCodecSettings> selected_send_codec = |
744 FilterSupportedCodecs(MapCodecs(params.codecs)); | 743 SelectSendVideoCodec(MapCodecs(params.codecs)); |
745 | 744 |
746 if (supported_codecs.empty()) { | 745 if (!selected_send_codec) { |
747 LOG(LS_ERROR) << "No video codecs supported."; | 746 LOG(LS_ERROR) << "No video codecs supported."; |
748 return false; | 747 return false; |
749 } | 748 } |
750 | 749 |
751 if (!send_codec_ || supported_codecs.front() != *send_codec_) { | 750 if (!send_codec_ || *selected_send_codec != *send_codec_) |
752 changed_params->codec = | 751 changed_params->codec = selected_send_codec; |
753 rtc::Optional<VideoCodecSettings>(supported_codecs.front()); | |
754 } | |
755 | 752 |
756 // Handle RTP header extensions. | 753 // Handle RTP header extensions. |
757 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( | 754 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( |
758 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); | 755 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, true); |
759 if (!send_rtp_extensions_ || (*send_rtp_extensions_ != filtered_extensions)) { | 756 if (!send_rtp_extensions_ || (*send_rtp_extensions_ != filtered_extensions)) { |
760 changed_params->rtp_header_extensions = | 757 changed_params->rtp_header_extensions = |
761 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); | 758 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); |
762 } | 759 } |
763 | 760 |
764 // Handle max bitrate. | 761 // Handle max bitrate. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 } | 958 } |
962 | 959 |
963 // Handle receive codecs. | 960 // Handle receive codecs. |
964 const std::vector<VideoCodecSettings> mapped_codecs = | 961 const std::vector<VideoCodecSettings> mapped_codecs = |
965 MapCodecs(params.codecs); | 962 MapCodecs(params.codecs); |
966 if (mapped_codecs.empty()) { | 963 if (mapped_codecs.empty()) { |
967 LOG(LS_ERROR) << "SetRecvParameters called without any video codecs."; | 964 LOG(LS_ERROR) << "SetRecvParameters called without any video codecs."; |
968 return false; | 965 return false; |
969 } | 966 } |
970 | 967 |
971 std::vector<VideoCodecSettings> supported_codecs = | 968 // Verify that every mapped codec is supported locally. |
972 FilterSupportedCodecs(mapped_codecs); | 969 const std::vector<VideoCodec> local_supported_codecs = |
973 | 970 GetSupportedCodecs(external_encoder_factory_); |
974 if (mapped_codecs.size() != supported_codecs.size()) { | 971 for (const VideoCodecSettings& mapped_codec : mapped_codecs) { |
975 LOG(LS_ERROR) << "SetRecvParameters called with unsupported video codecs."; | 972 if (!IsCodecSupported(local_supported_codecs, mapped_codec.codec)) { |
976 return false; | 973 LOG(LS_ERROR) << "SetRecvParameters called with unsupported video codec: " |
| 974 << mapped_codec.codec.ToString(); |
| 975 return false; |
| 976 } |
977 } | 977 } |
978 | 978 |
979 if (ReceiveCodecsHaveChanged(recv_codecs_, supported_codecs)) { | 979 if (ReceiveCodecsHaveChanged(recv_codecs_, mapped_codecs)) { |
980 changed_params->codec_settings = | 980 changed_params->codec_settings = |
981 rtc::Optional<std::vector<VideoCodecSettings>>(supported_codecs); | 981 rtc::Optional<std::vector<VideoCodecSettings>>(mapped_codecs); |
982 } | 982 } |
983 | 983 |
984 // Handle RTP header extensions. | 984 // Handle RTP header extensions. |
985 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( | 985 std::vector<webrtc::RtpExtension> filtered_extensions = FilterRtpExtensions( |
986 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, false); | 986 params.extensions, webrtc::RtpExtension::IsSupportedForVideo, false); |
987 if (filtered_extensions != recv_rtp_extensions_) { | 987 if (filtered_extensions != recv_rtp_extensions_) { |
988 changed_params->rtp_header_extensions = | 988 changed_params->rtp_header_extensions = |
989 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); | 989 rtc::Optional<std::vector<webrtc::RtpExtension>>(filtered_extensions); |
990 } | 990 } |
991 | 991 |
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2563 rtx_mapping[video_codecs[i].codec.id] != | 2563 rtx_mapping[video_codecs[i].codec.id] != |
2564 ulpfec_config.red_payload_type) { | 2564 ulpfec_config.red_payload_type) { |
2565 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2565 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2566 } | 2566 } |
2567 } | 2567 } |
2568 | 2568 |
2569 return video_codecs; | 2569 return video_codecs; |
2570 } | 2570 } |
2571 | 2571 |
2572 } // namespace cricket | 2572 } // namespace cricket |
OLD | NEW |