OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 for (const auto& codec : codecs) { | 99 for (const auto& codec : codecs) { |
100 if (codec.type == webrtc::kVideoCodecVP8) { | 100 if (codec.type == webrtc::kVideoCodecVP8) { |
101 return true; | 101 return true; |
102 } | 102 } |
103 } | 103 } |
104 return false; | 104 return false; |
105 } | 105 } |
106 | 106 |
107 webrtc::VideoEncoder* CreateVideoEncoder( | 107 webrtc::VideoEncoder* CreateVideoEncoder( |
108 webrtc::VideoCodecType type) override { | 108 webrtc::VideoCodecType type) override { |
109 DCHECK(factory_ != NULL); | 109 RTC_DCHECK(factory_ != NULL); |
110 // If it's a codec type we can simulcast, create a wrapped encoder. | 110 // If it's a codec type we can simulcast, create a wrapped encoder. |
111 if (type == webrtc::kVideoCodecVP8) { | 111 if (type == webrtc::kVideoCodecVP8) { |
112 return new webrtc::SimulcastEncoderAdapter( | 112 return new webrtc::SimulcastEncoderAdapter( |
113 new EncoderFactoryAdapter(factory_)); | 113 new EncoderFactoryAdapter(factory_)); |
114 } | 114 } |
115 webrtc::VideoEncoder* encoder = factory_->CreateVideoEncoder(type); | 115 webrtc::VideoEncoder* encoder = factory_->CreateVideoEncoder(type); |
116 if (encoder) { | 116 if (encoder) { |
117 non_simulcast_encoders_.push_back(encoder); | 117 non_simulcast_encoders_.push_back(encoder); |
118 } | 118 } |
119 return encoder; | 119 return encoder; |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 << codec.ToString(); | 593 << codec.ToString(); |
594 return false; | 594 return false; |
595 } | 595 } |
596 | 596 |
597 return true; | 597 return true; |
598 } | 598 } |
599 | 599 |
600 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( | 600 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( |
601 webrtc::Call* call, | 601 webrtc::Call* call, |
602 const VideoOptions& options) { | 602 const VideoOptions& options) { |
603 DCHECK(initialized_); | 603 RTC_DCHECK(initialized_); |
604 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); | 604 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); |
605 WebRtcVideoChannel2* channel = new WebRtcVideoChannel2(call, options, | 605 WebRtcVideoChannel2* channel = new WebRtcVideoChannel2(call, options, |
606 external_encoder_factory_, external_decoder_factory_); | 606 external_encoder_factory_, external_decoder_factory_); |
607 channel->SetRecvCodecs(video_codecs_); | 607 channel->SetRecvCodecs(video_codecs_); |
608 return channel; | 608 return channel; |
609 } | 609 } |
610 | 610 |
611 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { | 611 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { |
612 return video_codecs_; | 612 return video_codecs_; |
613 } | 613 } |
614 | 614 |
615 const std::vector<RtpHeaderExtension>& | 615 const std::vector<RtpHeaderExtension>& |
616 WebRtcVideoEngine2::rtp_header_extensions() const { | 616 WebRtcVideoEngine2::rtp_header_extensions() const { |
617 return rtp_header_extensions_; | 617 return rtp_header_extensions_; |
618 } | 618 } |
619 | 619 |
620 void WebRtcVideoEngine2::SetLogging(int min_sev, const char* filter) { | 620 void WebRtcVideoEngine2::SetLogging(int min_sev, const char* filter) { |
621 // TODO(pbos): Set up logging. | 621 // TODO(pbos): Set up logging. |
622 LOG(LS_VERBOSE) << "SetLogging: " << min_sev << '"' << filter << '"'; | 622 LOG(LS_VERBOSE) << "SetLogging: " << min_sev << '"' << filter << '"'; |
623 // if min_sev == -1, we keep the current log level. | 623 // if min_sev == -1, we keep the current log level. |
624 if (min_sev < 0) { | 624 if (min_sev < 0) { |
625 DCHECK(min_sev == -1); | 625 RTC_DCHECK(min_sev == -1); |
626 return; | 626 return; |
627 } | 627 } |
628 } | 628 } |
629 | 629 |
630 void WebRtcVideoEngine2::SetExternalDecoderFactory( | 630 void WebRtcVideoEngine2::SetExternalDecoderFactory( |
631 WebRtcVideoDecoderFactory* decoder_factory) { | 631 WebRtcVideoDecoderFactory* decoder_factory) { |
632 DCHECK(!initialized_); | 632 RTC_DCHECK(!initialized_); |
633 external_decoder_factory_ = decoder_factory; | 633 external_decoder_factory_ = decoder_factory; |
634 } | 634 } |
635 | 635 |
636 void WebRtcVideoEngine2::SetExternalEncoderFactory( | 636 void WebRtcVideoEngine2::SetExternalEncoderFactory( |
637 WebRtcVideoEncoderFactory* encoder_factory) { | 637 WebRtcVideoEncoderFactory* encoder_factory) { |
638 DCHECK(!initialized_); | 638 RTC_DCHECK(!initialized_); |
639 if (external_encoder_factory_ == encoder_factory) | 639 if (external_encoder_factory_ == encoder_factory) |
640 return; | 640 return; |
641 | 641 |
642 // No matter what happens we shouldn't hold on to a stale | 642 // No matter what happens we shouldn't hold on to a stale |
643 // WebRtcSimulcastEncoderFactory. | 643 // WebRtcSimulcastEncoderFactory. |
644 simulcast_encoder_factory_.reset(); | 644 simulcast_encoder_factory_.reset(); |
645 | 645 |
646 if (encoder_factory && | 646 if (encoder_factory && |
647 WebRtcSimulcastEncoderFactory::UseSimulcastEncoderFactory( | 647 WebRtcSimulcastEncoderFactory::UseSimulcastEncoderFactory( |
648 encoder_factory->codecs())) { | 648 encoder_factory->codecs())) { |
(...skipping 25 matching lines...) Expand all Loading... |
674 return false; | 674 return false; |
675 } | 675 } |
676 | 676 |
677 // Tells whether the |requested| codec can be transmitted or not. If it can be | 677 // Tells whether the |requested| codec can be transmitted or not. If it can be |
678 // transmitted |out| is set with the best settings supported. Aspect ratio will | 678 // transmitted |out| is set with the best settings supported. Aspect ratio will |
679 // be set as close to |current|'s as possible. If not set |requested|'s | 679 // be set as close to |current|'s as possible. If not set |requested|'s |
680 // dimensions will be used for aspect ratio matching. | 680 // dimensions will be used for aspect ratio matching. |
681 bool WebRtcVideoEngine2::CanSendCodec(const VideoCodec& requested, | 681 bool WebRtcVideoEngine2::CanSendCodec(const VideoCodec& requested, |
682 const VideoCodec& current, | 682 const VideoCodec& current, |
683 VideoCodec* out) { | 683 VideoCodec* out) { |
684 DCHECK(out != NULL); | 684 RTC_DCHECK(out != NULL); |
685 | 685 |
686 if (requested.width != requested.height && | 686 if (requested.width != requested.height && |
687 (requested.height == 0 || requested.width == 0)) { | 687 (requested.height == 0 || requested.width == 0)) { |
688 // 0xn and nx0 are invalid resolutions. | 688 // 0xn and nx0 are invalid resolutions. |
689 return false; | 689 return false; |
690 } | 690 } |
691 | 691 |
692 VideoCodec matching_codec; | 692 VideoCodec matching_codec; |
693 if (!FindFirstMatchingCodec(video_codecs_, requested, &matching_codec)) { | 693 if (!FindFirstMatchingCodec(video_codecs_, requested, &matching_codec)) { |
694 // Codec not supported. | 694 // Codec not supported. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 for (size_t i = 0; i < codecs.size(); ++i) { | 740 for (size_t i = 0; i < codecs.size(); ++i) { |
741 // Don't add internally-supported codecs twice. | 741 // Don't add internally-supported codecs twice. |
742 if (CodecIsInternallySupported(codecs[i].name)) { | 742 if (CodecIsInternallySupported(codecs[i].name)) { |
743 continue; | 743 continue; |
744 } | 744 } |
745 | 745 |
746 // External video encoders are given payloads 120-127. This also means that | 746 // External video encoders are given payloads 120-127. This also means that |
747 // we only support up to 8 external payload types. | 747 // we only support up to 8 external payload types. |
748 const int kExternalVideoPayloadTypeBase = 120; | 748 const int kExternalVideoPayloadTypeBase = 120; |
749 size_t payload_type = kExternalVideoPayloadTypeBase + i; | 749 size_t payload_type = kExternalVideoPayloadTypeBase + i; |
750 DCHECK(payload_type < 128); | 750 RTC_DCHECK(payload_type < 128); |
751 VideoCodec codec(static_cast<int>(payload_type), | 751 VideoCodec codec(static_cast<int>(payload_type), |
752 codecs[i].name, | 752 codecs[i].name, |
753 codecs[i].max_width, | 753 codecs[i].max_width, |
754 codecs[i].max_height, | 754 codecs[i].max_height, |
755 codecs[i].max_fps, | 755 codecs[i].max_fps, |
756 0); | 756 0); |
757 | 757 |
758 AddDefaultFeedbackParams(&codec); | 758 AddDefaultFeedbackParams(&codec); |
759 supported_codecs.push_back(codec); | 759 supported_codecs.push_back(codec); |
760 } | 760 } |
761 return supported_codecs; | 761 return supported_codecs; |
762 } | 762 } |
763 | 763 |
764 WebRtcVideoChannel2::WebRtcVideoChannel2( | 764 WebRtcVideoChannel2::WebRtcVideoChannel2( |
765 webrtc::Call* call, | 765 webrtc::Call* call, |
766 const VideoOptions& options, | 766 const VideoOptions& options, |
767 WebRtcVideoEncoderFactory* external_encoder_factory, | 767 WebRtcVideoEncoderFactory* external_encoder_factory, |
768 WebRtcVideoDecoderFactory* external_decoder_factory) | 768 WebRtcVideoDecoderFactory* external_decoder_factory) |
769 : call_(call), | 769 : call_(call), |
770 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), | 770 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), |
771 external_encoder_factory_(external_encoder_factory), | 771 external_encoder_factory_(external_encoder_factory), |
772 external_decoder_factory_(external_decoder_factory) { | 772 external_decoder_factory_(external_decoder_factory) { |
773 DCHECK(thread_checker_.CalledOnValidThread()); | 773 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
774 SetDefaultOptions(); | 774 SetDefaultOptions(); |
775 options_.SetAll(options); | 775 options_.SetAll(options); |
776 options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); | 776 options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); |
777 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; | 777 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; |
778 sending_ = false; | 778 sending_ = false; |
779 default_send_ssrc_ = 0; | 779 default_send_ssrc_ = 0; |
780 } | 780 } |
781 | 781 |
782 void WebRtcVideoChannel2::SetDefaultOptions() { | 782 void WebRtcVideoChannel2::SetDefaultOptions() { |
783 options_.cpu_overuse_detection.Set(true); | 783 options_.cpu_overuse_detection.Set(true); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 // Using same codec, avoid reconfiguring. | 956 // Using same codec, avoid reconfiguring. |
957 return true; | 957 return true; |
958 } | 958 } |
959 | 959 |
960 send_codec_.Set(supported_codecs.front()); | 960 send_codec_.Set(supported_codecs.front()); |
961 | 961 |
962 rtc::CritScope stream_lock(&stream_crit_); | 962 rtc::CritScope stream_lock(&stream_crit_); |
963 LOG(LS_INFO) << "Change the send codec because SetSendCodecs has a different " | 963 LOG(LS_INFO) << "Change the send codec because SetSendCodecs has a different " |
964 "first supported codec."; | 964 "first supported codec."; |
965 for (auto& kv : send_streams_) { | 965 for (auto& kv : send_streams_) { |
966 DCHECK(kv.second != nullptr); | 966 RTC_DCHECK(kv.second != nullptr); |
967 kv.second->SetCodec(supported_codecs.front()); | 967 kv.second->SetCodec(supported_codecs.front()); |
968 } | 968 } |
969 LOG(LS_INFO) << "SetNackAndRemb on all the receive streams because the send " | 969 LOG(LS_INFO) << "SetNackAndRemb on all the receive streams because the send " |
970 "codec has changed."; | 970 "codec has changed."; |
971 for (auto& kv : receive_streams_) { | 971 for (auto& kv : receive_streams_) { |
972 DCHECK(kv.second != nullptr); | 972 RTC_DCHECK(kv.second != nullptr); |
973 kv.second->SetNackAndRemb(HasNack(supported_codecs.front().codec), | 973 kv.second->SetNackAndRemb(HasNack(supported_codecs.front().codec), |
974 HasRemb(supported_codecs.front().codec)); | 974 HasRemb(supported_codecs.front().codec)); |
975 } | 975 } |
976 | 976 |
977 // TODO(holmer): Changing the codec parameters shouldn't necessarily mean that | 977 // TODO(holmer): Changing the codec parameters shouldn't necessarily mean that |
978 // we change the min/max of bandwidth estimation. Reevaluate this. | 978 // we change the min/max of bandwidth estimation. Reevaluate this. |
979 VideoCodec codec = supported_codecs.front().codec; | 979 VideoCodec codec = supported_codecs.front().codec; |
980 int bitrate_kbps; | 980 int bitrate_kbps; |
981 if (codec.GetParam(kCodecParamMinBitrate, &bitrate_kbps) && | 981 if (codec.GetParam(kCodecParamMinBitrate, &bitrate_kbps) && |
982 bitrate_kbps > 0) { | 982 bitrate_kbps > 0) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 new WebRtcVideoSendStream(call_, | 1101 new WebRtcVideoSendStream(call_, |
1102 sp, | 1102 sp, |
1103 config, | 1103 config, |
1104 external_encoder_factory_, | 1104 external_encoder_factory_, |
1105 options_, | 1105 options_, |
1106 bitrate_config_.max_bitrate_bps, | 1106 bitrate_config_.max_bitrate_bps, |
1107 send_codec_, | 1107 send_codec_, |
1108 send_rtp_extensions_); | 1108 send_rtp_extensions_); |
1109 | 1109 |
1110 uint32 ssrc = sp.first_ssrc(); | 1110 uint32 ssrc = sp.first_ssrc(); |
1111 DCHECK(ssrc != 0); | 1111 RTC_DCHECK(ssrc != 0); |
1112 send_streams_[ssrc] = stream; | 1112 send_streams_[ssrc] = stream; |
1113 | 1113 |
1114 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { | 1114 if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { |
1115 rtcp_receiver_report_ssrc_ = ssrc; | 1115 rtcp_receiver_report_ssrc_ = ssrc; |
1116 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " | 1116 LOG(LS_INFO) << "SetLocalSsrc on all the receive streams because we added " |
1117 "a send stream."; | 1117 "a send stream."; |
1118 for (auto& kv : receive_streams_) | 1118 for (auto& kv : receive_streams_) |
1119 kv.second->SetLocalSsrc(ssrc); | 1119 kv.second->SetLocalSsrc(ssrc); |
1120 } | 1120 } |
1121 if (default_send_ssrc_ == 0) { | 1121 if (default_send_ssrc_ == 0) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 receive_ssrcs_.erase(old_ssrc); | 1172 receive_ssrcs_.erase(old_ssrc); |
1173 delete stream; | 1173 delete stream; |
1174 } | 1174 } |
1175 | 1175 |
1176 bool WebRtcVideoChannel2::AddRecvStream(const StreamParams& sp) { | 1176 bool WebRtcVideoChannel2::AddRecvStream(const StreamParams& sp) { |
1177 return AddRecvStream(sp, false); | 1177 return AddRecvStream(sp, false); |
1178 } | 1178 } |
1179 | 1179 |
1180 bool WebRtcVideoChannel2::AddRecvStream(const StreamParams& sp, | 1180 bool WebRtcVideoChannel2::AddRecvStream(const StreamParams& sp, |
1181 bool default_stream) { | 1181 bool default_stream) { |
1182 DCHECK(thread_checker_.CalledOnValidThread()); | 1182 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
1183 | 1183 |
1184 LOG(LS_INFO) << "AddRecvStream" << (default_stream ? " (default stream)" : "") | 1184 LOG(LS_INFO) << "AddRecvStream" << (default_stream ? " (default stream)" : "") |
1185 << ": " << sp.ToString(); | 1185 << ": " << sp.ToString(); |
1186 if (!ValidateStreamParams(sp)) | 1186 if (!ValidateStreamParams(sp)) |
1187 return false; | 1187 return false; |
1188 | 1188 |
1189 uint32 ssrc = sp.first_ssrc(); | 1189 uint32 ssrc = sp.first_ssrc(); |
1190 DCHECK(ssrc != 0); // TODO(pbos): Is this ever valid? | 1190 RTC_DCHECK(ssrc != 0); // TODO(pbos): Is this ever valid? |
1191 | 1191 |
1192 rtc::CritScope stream_lock(&stream_crit_); | 1192 rtc::CritScope stream_lock(&stream_crit_); |
1193 // Remove running stream if this was a default stream. | 1193 // Remove running stream if this was a default stream. |
1194 auto prev_stream = receive_streams_.find(ssrc); | 1194 auto prev_stream = receive_streams_.find(ssrc); |
1195 if (prev_stream != receive_streams_.end()) { | 1195 if (prev_stream != receive_streams_.end()) { |
1196 if (default_stream || !prev_stream->second->IsDefaultStream()) { | 1196 if (default_stream || !prev_stream->second->IsDefaultStream()) { |
1197 LOG(LS_ERROR) << "Receive stream for SSRC '" << ssrc | 1197 LOG(LS_ERROR) << "Receive stream for SSRC '" << ssrc |
1198 << "' already exists."; | 1198 << "' already exists."; |
1199 return false; | 1199 return false; |
1200 } | 1200 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 stream != send_streams_.end(); | 1369 stream != send_streams_.end(); |
1370 ++stream) { | 1370 ++stream) { |
1371 stream->second->FillBandwidthEstimationInfo(&bwe_info); | 1371 stream->second->FillBandwidthEstimationInfo(&bwe_info); |
1372 } | 1372 } |
1373 video_media_info->bw_estimations.push_back(bwe_info); | 1373 video_media_info->bw_estimations.push_back(bwe_info); |
1374 } | 1374 } |
1375 | 1375 |
1376 bool WebRtcVideoChannel2::SetCapturer(uint32 ssrc, VideoCapturer* capturer) { | 1376 bool WebRtcVideoChannel2::SetCapturer(uint32 ssrc, VideoCapturer* capturer) { |
1377 LOG(LS_INFO) << "SetCapturer: " << ssrc << " -> " | 1377 LOG(LS_INFO) << "SetCapturer: " << ssrc << " -> " |
1378 << (capturer != NULL ? "(capturer)" : "NULL"); | 1378 << (capturer != NULL ? "(capturer)" : "NULL"); |
1379 DCHECK(ssrc != 0); | 1379 RTC_DCHECK(ssrc != 0); |
1380 { | 1380 { |
1381 rtc::CritScope stream_lock(&stream_crit_); | 1381 rtc::CritScope stream_lock(&stream_crit_); |
1382 if (send_streams_.find(ssrc) == send_streams_.end()) { | 1382 if (send_streams_.find(ssrc) == send_streams_.end()) { |
1383 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; | 1383 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; |
1384 return false; | 1384 return false; |
1385 } | 1385 } |
1386 if (!send_streams_[ssrc]->SetCapturer(capturer)) { | 1386 if (!send_streams_[ssrc]->SetCapturer(capturer)) { |
1387 return false; | 1387 return false; |
1388 } | 1388 } |
1389 } | 1389 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 } | 1484 } |
1485 | 1485 |
1486 void WebRtcVideoChannel2::OnReadyToSend(bool ready) { | 1486 void WebRtcVideoChannel2::OnReadyToSend(bool ready) { |
1487 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); | 1487 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); |
1488 call_->SignalNetworkState(ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); | 1488 call_->SignalNetworkState(ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); |
1489 } | 1489 } |
1490 | 1490 |
1491 bool WebRtcVideoChannel2::MuteStream(uint32 ssrc, bool mute) { | 1491 bool WebRtcVideoChannel2::MuteStream(uint32 ssrc, bool mute) { |
1492 LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> " | 1492 LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> " |
1493 << (mute ? "mute" : "unmute"); | 1493 << (mute ? "mute" : "unmute"); |
1494 DCHECK(ssrc != 0); | 1494 RTC_DCHECK(ssrc != 0); |
1495 rtc::CritScope stream_lock(&stream_crit_); | 1495 rtc::CritScope stream_lock(&stream_crit_); |
1496 if (send_streams_.find(ssrc) == send_streams_.end()) { | 1496 if (send_streams_.find(ssrc) == send_streams_.end()) { |
1497 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; | 1497 LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; |
1498 return false; | 1498 return false; |
1499 } | 1499 } |
1500 | 1500 |
1501 send_streams_[ssrc]->MuteStream(mute); | 1501 send_streams_[ssrc]->MuteStream(mute); |
1502 return true; | 1502 return true; |
1503 } | 1503 } |
1504 | 1504 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1787 // Frame input before send codecs are configured, dropping frame. | 1787 // Frame input before send codecs are configured, dropping frame. |
1788 return; | 1788 return; |
1789 } | 1789 } |
1790 | 1790 |
1791 // Not sending, abort early to prevent expensive reconfigurations while | 1791 // Not sending, abort early to prevent expensive reconfigurations while |
1792 // setting up codecs etc. | 1792 // setting up codecs etc. |
1793 if (!sending_) | 1793 if (!sending_) |
1794 return; | 1794 return; |
1795 | 1795 |
1796 if (format_.width == 0) { // Dropping frames. | 1796 if (format_.width == 0) { // Dropping frames. |
1797 DCHECK(format_.height == 0); | 1797 RTC_DCHECK(format_.height == 0); |
1798 LOG(LS_VERBOSE) << "VideoFormat 0x0 set, Dropping frame."; | 1798 LOG(LS_VERBOSE) << "VideoFormat 0x0 set, Dropping frame."; |
1799 return; | 1799 return; |
1800 } | 1800 } |
1801 if (muted_) { | 1801 if (muted_) { |
1802 // Create a black frame to transmit instead. | 1802 // Create a black frame to transmit instead. |
1803 CreateBlackFrame(&video_frame, | 1803 CreateBlackFrame(&video_frame, |
1804 static_cast<int>(frame->GetWidth()), | 1804 static_cast<int>(frame->GetWidth()), |
1805 static_cast<int>(frame->GetHeight())); | 1805 static_cast<int>(frame->GetHeight())); |
1806 } | 1806 } |
1807 | 1807 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1981 } else if (type == webrtc::kVideoCodecVP9) { | 1981 } else if (type == webrtc::kVideoCodecVP9) { |
1982 return AllocatedEncoder( | 1982 return AllocatedEncoder( |
1983 webrtc::VideoEncoder::Create(webrtc::VideoEncoder::kVp9), type, false); | 1983 webrtc::VideoEncoder::Create(webrtc::VideoEncoder::kVp9), type, false); |
1984 } else if (type == webrtc::kVideoCodecH264) { | 1984 } else if (type == webrtc::kVideoCodecH264) { |
1985 return AllocatedEncoder( | 1985 return AllocatedEncoder( |
1986 webrtc::VideoEncoder::Create(webrtc::VideoEncoder::kH264), type, false); | 1986 webrtc::VideoEncoder::Create(webrtc::VideoEncoder::kH264), type, false); |
1987 } | 1987 } |
1988 | 1988 |
1989 // This shouldn't happen, we should not be trying to create something we don't | 1989 // This shouldn't happen, we should not be trying to create something we don't |
1990 // support. | 1990 // support. |
1991 DCHECK(false); | 1991 RTC_DCHECK(false); |
1992 return AllocatedEncoder(NULL, webrtc::kVideoCodecUnknown, false); | 1992 return AllocatedEncoder(NULL, webrtc::kVideoCodecUnknown, false); |
1993 } | 1993 } |
1994 | 1994 |
1995 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( | 1995 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( |
1996 AllocatedEncoder* encoder) { | 1996 AllocatedEncoder* encoder) { |
1997 if (encoder->external) { | 1997 if (encoder->external) { |
1998 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); | 1998 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); |
1999 } | 1999 } |
2000 delete encoder->encoder; | 2000 delete encoder->encoder; |
2001 } | 2001 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2136 // Configured using the same parameters, do not reconfigure. | 2136 // Configured using the same parameters, do not reconfigure. |
2137 return; | 2137 return; |
2138 } | 2138 } |
2139 LOG(LS_INFO) << "SetDimensions: " << width << "x" << height | 2139 LOG(LS_INFO) << "SetDimensions: " << width << "x" << height |
2140 << (is_screencast ? " (screencast)" : " (not screencast)"); | 2140 << (is_screencast ? " (screencast)" : " (not screencast)"); |
2141 | 2141 |
2142 last_dimensions_.width = width; | 2142 last_dimensions_.width = width; |
2143 last_dimensions_.height = height; | 2143 last_dimensions_.height = height; |
2144 last_dimensions_.is_screencast = is_screencast; | 2144 last_dimensions_.is_screencast = is_screencast; |
2145 | 2145 |
2146 DCHECK(!parameters_.encoder_config.streams.empty()); | 2146 RTC_DCHECK(!parameters_.encoder_config.streams.empty()); |
2147 | 2147 |
2148 VideoCodecSettings codec_settings; | 2148 VideoCodecSettings codec_settings; |
2149 parameters_.codec_settings.Get(&codec_settings); | 2149 parameters_.codec_settings.Get(&codec_settings); |
2150 | 2150 |
2151 webrtc::VideoEncoderConfig encoder_config = | 2151 webrtc::VideoEncoderConfig encoder_config = |
2152 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); | 2152 CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); |
2153 | 2153 |
2154 encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( | 2154 encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( |
2155 codec_settings.codec, parameters_.options, is_screencast); | 2155 codec_settings.codec, parameters_.options, is_screencast); |
2156 | 2156 |
2157 bool stream_reconfigured = stream_->ReconfigureVideoEncoder(encoder_config); | 2157 bool stream_reconfigured = stream_->ReconfigureVideoEncoder(encoder_config); |
2158 | 2158 |
2159 encoder_config.encoder_specific_settings = NULL; | 2159 encoder_config.encoder_specific_settings = NULL; |
2160 | 2160 |
2161 if (!stream_reconfigured) { | 2161 if (!stream_reconfigured) { |
2162 LOG(LS_WARNING) << "Failed to reconfigure video encoder for dimensions: " | 2162 LOG(LS_WARNING) << "Failed to reconfigure video encoder for dimensions: " |
2163 << width << "x" << height; | 2163 << width << "x" << height; |
2164 return; | 2164 return; |
2165 } | 2165 } |
2166 | 2166 |
2167 parameters_.encoder_config = encoder_config; | 2167 parameters_.encoder_config = encoder_config; |
2168 } | 2168 } |
2169 | 2169 |
2170 void WebRtcVideoChannel2::WebRtcVideoSendStream::Start() { | 2170 void WebRtcVideoChannel2::WebRtcVideoSendStream::Start() { |
2171 rtc::CritScope cs(&lock_); | 2171 rtc::CritScope cs(&lock_); |
2172 DCHECK(stream_ != NULL); | 2172 RTC_DCHECK(stream_ != NULL); |
2173 stream_->Start(); | 2173 stream_->Start(); |
2174 sending_ = true; | 2174 sending_ = true; |
2175 } | 2175 } |
2176 | 2176 |
2177 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { | 2177 void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { |
2178 rtc::CritScope cs(&lock_); | 2178 rtc::CritScope cs(&lock_); |
2179 if (stream_ != NULL) { | 2179 if (stream_ != NULL) { |
2180 stream_->Stop(); | 2180 stream_->Stop(); |
2181 } | 2181 } |
2182 sending_ = false; | 2182 sending_ = false; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2413 webrtc::VideoDecoder::Create(webrtc::VideoDecoder::kVp9), type, false); | 2413 webrtc::VideoDecoder::Create(webrtc::VideoDecoder::kVp9), type, false); |
2414 } | 2414 } |
2415 | 2415 |
2416 if (type == webrtc::kVideoCodecH264) { | 2416 if (type == webrtc::kVideoCodecH264) { |
2417 return AllocatedDecoder( | 2417 return AllocatedDecoder( |
2418 webrtc::VideoDecoder::Create(webrtc::VideoDecoder::kH264), type, false); | 2418 webrtc::VideoDecoder::Create(webrtc::VideoDecoder::kH264), type, false); |
2419 } | 2419 } |
2420 | 2420 |
2421 // This shouldn't happen, we should not be trying to create something we don't | 2421 // This shouldn't happen, we should not be trying to create something we don't |
2422 // support. | 2422 // support. |
2423 DCHECK(false); | 2423 RTC_DCHECK(false); |
2424 return AllocatedDecoder(NULL, webrtc::kVideoCodecUnknown, false); | 2424 return AllocatedDecoder(NULL, webrtc::kVideoCodecUnknown, false); |
2425 } | 2425 } |
2426 | 2426 |
2427 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetRecvCodecs( | 2427 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetRecvCodecs( |
2428 const std::vector<VideoCodecSettings>& recv_codecs) { | 2428 const std::vector<VideoCodecSettings>& recv_codecs) { |
2429 std::vector<AllocatedDecoder> old_decoders = allocated_decoders_; | 2429 std::vector<AllocatedDecoder> old_decoders = allocated_decoders_; |
2430 allocated_decoders_.clear(); | 2430 allocated_decoders_.clear(); |
2431 config_.decoders.clear(); | 2431 config_.decoders.clear(); |
2432 for (size_t i = 0; i < recv_codecs.size(); ++i) { | 2432 for (size_t i = 0; i < recv_codecs.size(); ++i) { |
2433 AllocatedDecoder allocated_decoder = | 2433 AllocatedDecoder allocated_decoder = |
(...skipping 13 matching lines...) Expand all Loading... |
2447 HasNack(recv_codecs.begin()->codec) ? kNackHistoryMs : 0; | 2447 HasNack(recv_codecs.begin()->codec) ? kNackHistoryMs : 0; |
2448 | 2448 |
2449 ClearDecoders(&old_decoders); | 2449 ClearDecoders(&old_decoders); |
2450 LOG(LS_INFO) << "RecreateWebRtcStream (recv) because of SetRecvCodecs: " | 2450 LOG(LS_INFO) << "RecreateWebRtcStream (recv) because of SetRecvCodecs: " |
2451 << CodecSettingsVectorToString(recv_codecs); | 2451 << CodecSettingsVectorToString(recv_codecs); |
2452 RecreateWebRtcStream(); | 2452 RecreateWebRtcStream(); |
2453 } | 2453 } |
2454 | 2454 |
2455 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetLocalSsrc( | 2455 void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetLocalSsrc( |
2456 uint32_t local_ssrc) { | 2456 uint32_t local_ssrc) { |
2457 // TODO(pbos): Consider turning this sanity check into a DCHECK. You should | 2457 // TODO(pbos): Consider turning this sanity check into a RTC_DCHECK. You |
2458 // not be able to create a sender with the same SSRC as a receiver, but right | 2458 // should not be able to create a sender with the same SSRC as a receiver, but |
2459 // now this can't be done due to unittests depending on receiving what they | 2459 // right now this can't be done due to unittests depending on receiving what |
2460 // are sending from the same MediaChannel. | 2460 // they are sending from the same MediaChannel. |
2461 if (local_ssrc == config_.rtp.remote_ssrc) { | 2461 if (local_ssrc == config_.rtp.remote_ssrc) { |
2462 LOG(LS_INFO) << "Ignoring call to SetLocalSsrc because parameters are " | 2462 LOG(LS_INFO) << "Ignoring call to SetLocalSsrc because parameters are " |
2463 "unchanged; local_ssrc=" << local_ssrc; | 2463 "unchanged; local_ssrc=" << local_ssrc; |
2464 return; | 2464 return; |
2465 } | 2465 } |
2466 | 2466 |
2467 config_.rtp.local_ssrc = local_ssrc; | 2467 config_.rtp.local_ssrc = local_ssrc; |
2468 LOG(LS_INFO) | 2468 LOG(LS_INFO) |
2469 << "RecreateWebRtcStream (recv) because of SetLocalSsrc; local_ssrc=" | 2469 << "RecreateWebRtcStream (recv) because of SetLocalSsrc; local_ssrc=" |
2470 << local_ssrc; | 2470 << local_ssrc; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2645 rtx_payload_type == other.rtx_payload_type; | 2645 rtx_payload_type == other.rtx_payload_type; |
2646 } | 2646 } |
2647 | 2647 |
2648 bool WebRtcVideoChannel2::VideoCodecSettings::operator!=( | 2648 bool WebRtcVideoChannel2::VideoCodecSettings::operator!=( |
2649 const WebRtcVideoChannel2::VideoCodecSettings& other) const { | 2649 const WebRtcVideoChannel2::VideoCodecSettings& other) const { |
2650 return !(*this == other); | 2650 return !(*this == other); |
2651 } | 2651 } |
2652 | 2652 |
2653 std::vector<WebRtcVideoChannel2::VideoCodecSettings> | 2653 std::vector<WebRtcVideoChannel2::VideoCodecSettings> |
2654 WebRtcVideoChannel2::MapCodecs(const std::vector<VideoCodec>& codecs) { | 2654 WebRtcVideoChannel2::MapCodecs(const std::vector<VideoCodec>& codecs) { |
2655 DCHECK(!codecs.empty()); | 2655 RTC_DCHECK(!codecs.empty()); |
2656 | 2656 |
2657 std::vector<VideoCodecSettings> video_codecs; | 2657 std::vector<VideoCodecSettings> video_codecs; |
2658 std::map<int, bool> payload_used; | 2658 std::map<int, bool> payload_used; |
2659 std::map<int, VideoCodec::CodecType> payload_codec_type; | 2659 std::map<int, VideoCodec::CodecType> payload_codec_type; |
2660 // |rtx_mapping| maps video payload type to rtx payload type. | 2660 // |rtx_mapping| maps video payload type to rtx payload type. |
2661 std::map<int, int> rtx_mapping; | 2661 std::map<int, int> rtx_mapping; |
2662 | 2662 |
2663 webrtc::FecConfig fec_settings; | 2663 webrtc::FecConfig fec_settings; |
2664 | 2664 |
2665 for (size_t i = 0; i < codecs.size(); ++i) { | 2665 for (size_t i = 0; i < codecs.size(); ++i) { |
2666 const VideoCodec& in_codec = codecs[i]; | 2666 const VideoCodec& in_codec = codecs[i]; |
2667 int payload_type = in_codec.id; | 2667 int payload_type = in_codec.id; |
2668 | 2668 |
2669 if (payload_used[payload_type]) { | 2669 if (payload_used[payload_type]) { |
2670 LOG(LS_ERROR) << "Payload type already registered: " | 2670 LOG(LS_ERROR) << "Payload type already registered: " |
2671 << in_codec.ToString(); | 2671 << in_codec.ToString(); |
2672 return std::vector<VideoCodecSettings>(); | 2672 return std::vector<VideoCodecSettings>(); |
2673 } | 2673 } |
2674 payload_used[payload_type] = true; | 2674 payload_used[payload_type] = true; |
2675 payload_codec_type[payload_type] = in_codec.GetCodecType(); | 2675 payload_codec_type[payload_type] = in_codec.GetCodecType(); |
2676 | 2676 |
2677 switch (in_codec.GetCodecType()) { | 2677 switch (in_codec.GetCodecType()) { |
2678 case VideoCodec::CODEC_RED: { | 2678 case VideoCodec::CODEC_RED: { |
2679 // RED payload type, should not have duplicates. | 2679 // RED payload type, should not have duplicates. |
2680 DCHECK(fec_settings.red_payload_type == -1); | 2680 RTC_DCHECK(fec_settings.red_payload_type == -1); |
2681 fec_settings.red_payload_type = in_codec.id; | 2681 fec_settings.red_payload_type = in_codec.id; |
2682 continue; | 2682 continue; |
2683 } | 2683 } |
2684 | 2684 |
2685 case VideoCodec::CODEC_ULPFEC: { | 2685 case VideoCodec::CODEC_ULPFEC: { |
2686 // ULPFEC payload type, should not have duplicates. | 2686 // ULPFEC payload type, should not have duplicates. |
2687 DCHECK(fec_settings.ulpfec_payload_type == -1); | 2687 RTC_DCHECK(fec_settings.ulpfec_payload_type == -1); |
2688 fec_settings.ulpfec_payload_type = in_codec.id; | 2688 fec_settings.ulpfec_payload_type = in_codec.id; |
2689 continue; | 2689 continue; |
2690 } | 2690 } |
2691 | 2691 |
2692 case VideoCodec::CODEC_RTX: { | 2692 case VideoCodec::CODEC_RTX: { |
2693 int associated_payload_type; | 2693 int associated_payload_type; |
2694 if (!in_codec.GetParam(kCodecParamAssociatedPayloadType, | 2694 if (!in_codec.GetParam(kCodecParamAssociatedPayloadType, |
2695 &associated_payload_type) || | 2695 &associated_payload_type) || |
2696 !IsValidRtpPayloadType(associated_payload_type)) { | 2696 !IsValidRtpPayloadType(associated_payload_type)) { |
2697 LOG(LS_ERROR) | 2697 LOG(LS_ERROR) |
2698 << "RTX codec with invalid or no associated payload type: " | 2698 << "RTX codec with invalid or no associated payload type: " |
2699 << in_codec.ToString(); | 2699 << in_codec.ToString(); |
2700 return std::vector<VideoCodecSettings>(); | 2700 return std::vector<VideoCodecSettings>(); |
2701 } | 2701 } |
2702 rtx_mapping[associated_payload_type] = in_codec.id; | 2702 rtx_mapping[associated_payload_type] = in_codec.id; |
2703 continue; | 2703 continue; |
2704 } | 2704 } |
2705 | 2705 |
2706 case VideoCodec::CODEC_VIDEO: | 2706 case VideoCodec::CODEC_VIDEO: |
2707 break; | 2707 break; |
2708 } | 2708 } |
2709 | 2709 |
2710 video_codecs.push_back(VideoCodecSettings()); | 2710 video_codecs.push_back(VideoCodecSettings()); |
2711 video_codecs.back().codec = in_codec; | 2711 video_codecs.back().codec = in_codec; |
2712 } | 2712 } |
2713 | 2713 |
2714 // One of these codecs should have been a video codec. Only having FEC | 2714 // One of these codecs should have been a video codec. Only having FEC |
2715 // parameters into this code is a logic error. | 2715 // parameters into this code is a logic error. |
2716 DCHECK(!video_codecs.empty()); | 2716 RTC_DCHECK(!video_codecs.empty()); |
2717 | 2717 |
2718 for (std::map<int, int>::const_iterator it = rtx_mapping.begin(); | 2718 for (std::map<int, int>::const_iterator it = rtx_mapping.begin(); |
2719 it != rtx_mapping.end(); | 2719 it != rtx_mapping.end(); |
2720 ++it) { | 2720 ++it) { |
2721 if (!payload_used[it->first]) { | 2721 if (!payload_used[it->first]) { |
2722 LOG(LS_ERROR) << "RTX mapped to payload not in codec list."; | 2722 LOG(LS_ERROR) << "RTX mapped to payload not in codec list."; |
2723 return std::vector<VideoCodecSettings>(); | 2723 return std::vector<VideoCodecSettings>(); |
2724 } | 2724 } |
2725 if (payload_codec_type[it->first] != VideoCodec::CODEC_VIDEO && | 2725 if (payload_codec_type[it->first] != VideoCodec::CODEC_VIDEO && |
2726 payload_codec_type[it->first] != VideoCodec::CODEC_RED) { | 2726 payload_codec_type[it->first] != VideoCodec::CODEC_RED) { |
(...skipping 14 matching lines...) Expand all Loading... |
2741 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2741 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2742 } | 2742 } |
2743 } | 2743 } |
2744 | 2744 |
2745 return video_codecs; | 2745 return video_codecs; |
2746 } | 2746 } |
2747 | 2747 |
2748 } // namespace cricket | 2748 } // namespace cricket |
2749 | 2749 |
2750 #endif // HAVE_WEBRTC_VIDEO | 2750 #endif // HAVE_WEBRTC_VIDEO |
OLD | NEW |