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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 const int kVideoRtpBufferSize = 65536; | 333 const int kVideoRtpBufferSize = 65536; |
334 | 334 |
335 // This constant is really an on/off, lower-level configurable NACK history | 335 // This constant is really an on/off, lower-level configurable NACK history |
336 // duration hasn't been implemented. | 336 // duration hasn't been implemented. |
337 static const int kNackHistoryMs = 1000; | 337 static const int kNackHistoryMs = 1000; |
338 | 338 |
339 static const int kDefaultQpMax = 56; | 339 static const int kDefaultQpMax = 56; |
340 | 340 |
341 static const int kDefaultRtcpReceiverReportSsrc = 1; | 341 static const int kDefaultRtcpReceiverReportSsrc = 1; |
342 | 342 |
343 const int kMinBandwidthBps = 30000; | |
344 const int kStartBandwidthBps = 300000; | |
345 const int kMaxBandwidthBps = 2000000; | |
346 | |
347 std::vector<VideoCodec> DefaultVideoCodecList() { | 343 std::vector<VideoCodec> DefaultVideoCodecList() { |
348 std::vector<VideoCodec> codecs; | 344 std::vector<VideoCodec> codecs; |
349 if (CodecIsInternallySupported(kVp9CodecName)) { | 345 if (CodecIsInternallySupported(kVp9CodecName)) { |
350 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp9PlType, | 346 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp9PlType, |
351 kVp9CodecName)); | 347 kVp9CodecName)); |
352 // TODO(andresp): Add rtx codec for vp9 and verify it works. | 348 // TODO(andresp): Add rtx codec for vp9 and verify it works. |
353 } | 349 } |
354 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp8PlType, | 350 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp8PlType, |
355 kVp8CodecName)); | 351 kVp8CodecName)); |
356 if (CodecIsInternallySupported(kH264CodecName)) { | 352 if (CodecIsInternallySupported(kH264CodecName)) { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; | 526 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; |
531 if (!channel->AddRecvStream(sp, true)) { | 527 if (!channel->AddRecvStream(sp, true)) { |
532 LOG(LS_WARNING) << "Could not create default receive stream."; | 528 LOG(LS_WARNING) << "Could not create default receive stream."; |
533 } | 529 } |
534 | 530 |
535 channel->SetRenderer(ssrc, default_renderer_); | 531 channel->SetRenderer(ssrc, default_renderer_); |
536 default_recv_ssrc_ = ssrc; | 532 default_recv_ssrc_ = ssrc; |
537 return kDeliverPacket; | 533 return kDeliverPacket; |
538 } | 534 } |
539 | 535 |
540 WebRtcCallFactory::~WebRtcCallFactory() { | |
541 } | |
542 webrtc::Call* WebRtcCallFactory::CreateCall( | |
543 const webrtc::Call::Config& config) { | |
544 return webrtc::Call::Create(config); | |
545 } | |
546 | |
547 VideoRenderer* DefaultUnsignalledSsrcHandler::GetDefaultRenderer() const { | 536 VideoRenderer* DefaultUnsignalledSsrcHandler::GetDefaultRenderer() const { |
548 return default_renderer_; | 537 return default_renderer_; |
549 } | 538 } |
550 | 539 |
551 void DefaultUnsignalledSsrcHandler::SetDefaultRenderer( | 540 void DefaultUnsignalledSsrcHandler::SetDefaultRenderer( |
552 VideoMediaChannel* channel, | 541 VideoMediaChannel* channel, |
553 VideoRenderer* renderer) { | 542 VideoRenderer* renderer) { |
554 default_renderer_ = renderer; | 543 default_renderer_ = renderer; |
555 if (default_recv_ssrc_ != 0) { | 544 if (default_recv_ssrc_ != 0) { |
556 channel->SetRenderer(default_recv_ssrc_, default_renderer_); | 545 channel->SetRenderer(default_recv_ssrc_, default_renderer_); |
557 } | 546 } |
558 } | 547 } |
559 | 548 |
560 WebRtcVideoEngine2::WebRtcVideoEngine2(WebRtcVoiceEngine* voice_engine) | 549 WebRtcVideoEngine2::WebRtcVideoEngine2() |
561 : voice_engine_(voice_engine), | 550 : initialized_(false), |
562 initialized_(false), | |
563 call_factory_(&default_call_factory_), | |
564 external_decoder_factory_(NULL), | 551 external_decoder_factory_(NULL), |
565 external_encoder_factory_(NULL) { | 552 external_encoder_factory_(NULL) { |
566 LOG(LS_INFO) << "WebRtcVideoEngine2::WebRtcVideoEngine2()"; | 553 LOG(LS_INFO) << "WebRtcVideoEngine2::WebRtcVideoEngine2()"; |
567 video_codecs_ = GetSupportedCodecs(); | 554 video_codecs_ = GetSupportedCodecs(); |
568 rtp_header_extensions_.push_back( | 555 rtp_header_extensions_.push_back( |
569 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, | 556 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, |
570 kRtpTimestampOffsetHeaderExtensionDefaultId)); | 557 kRtpTimestampOffsetHeaderExtensionDefaultId)); |
571 rtp_header_extensions_.push_back( | 558 rtp_header_extensions_.push_back( |
572 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, | 559 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, |
573 kRtpAbsoluteSenderTimeHeaderExtensionDefaultId)); | 560 kRtpAbsoluteSenderTimeHeaderExtensionDefaultId)); |
574 rtp_header_extensions_.push_back( | 561 rtp_header_extensions_.push_back( |
575 RtpHeaderExtension(kRtpVideoRotationHeaderExtension, | 562 RtpHeaderExtension(kRtpVideoRotationHeaderExtension, |
576 kRtpVideoRotationHeaderExtensionDefaultId)); | 563 kRtpVideoRotationHeaderExtensionDefaultId)); |
577 } | 564 } |
578 | 565 |
579 WebRtcVideoEngine2::~WebRtcVideoEngine2() { | 566 WebRtcVideoEngine2::~WebRtcVideoEngine2() { |
580 LOG(LS_INFO) << "WebRtcVideoEngine2::~WebRtcVideoEngine2"; | 567 LOG(LS_INFO) << "WebRtcVideoEngine2::~WebRtcVideoEngine2"; |
581 } | 568 } |
582 | 569 |
583 void WebRtcVideoEngine2::SetCallFactory(WebRtcCallFactory* call_factory) { | |
584 DCHECK(!initialized_); | |
585 call_factory_ = call_factory; | |
586 } | |
587 | |
588 void WebRtcVideoEngine2::Init() { | 570 void WebRtcVideoEngine2::Init() { |
589 LOG(LS_INFO) << "WebRtcVideoEngine2::Init"; | 571 LOG(LS_INFO) << "WebRtcVideoEngine2::Init"; |
590 initialized_ = true; | 572 initialized_ = true; |
591 } | 573 } |
592 | 574 |
593 int WebRtcVideoEngine2::GetCapabilities() { return VIDEO_RECV | VIDEO_SEND; } | 575 int WebRtcVideoEngine2::GetCapabilities() { return VIDEO_RECV | VIDEO_SEND; } |
594 | 576 |
595 bool WebRtcVideoEngine2::SetDefaultEncoderConfig( | 577 bool WebRtcVideoEngine2::SetDefaultEncoderConfig( |
596 const VideoEncoderConfig& config) { | 578 const VideoEncoderConfig& config) { |
597 const VideoCodec& codec = config.max_codec; | 579 const VideoCodec& codec = config.max_codec; |
(...skipping 11 matching lines...) Expand all Loading... |
609 if (!supports_codec) { | 591 if (!supports_codec) { |
610 LOG(LS_ERROR) << "SetDefaultEncoderConfig, codec not supported: " | 592 LOG(LS_ERROR) << "SetDefaultEncoderConfig, codec not supported: " |
611 << codec.ToString(); | 593 << codec.ToString(); |
612 return false; | 594 return false; |
613 } | 595 } |
614 | 596 |
615 return true; | 597 return true; |
616 } | 598 } |
617 | 599 |
618 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( | 600 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( |
619 const VideoOptions& options, | 601 webrtc::Call* call, |
620 VoiceMediaChannel* voice_channel) { | 602 const VideoOptions& options) { |
621 DCHECK(initialized_); | 603 DCHECK(initialized_); |
622 LOG(LS_INFO) << "CreateChannel: " | 604 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); |
623 << (voice_channel != NULL ? "With" : "Without") | 605 WebRtcVideoChannel2* channel = new WebRtcVideoChannel2(call, options, |
624 << " voice channel. Options: " << options.ToString(); | 606 external_encoder_factory_, external_decoder_factory_); |
625 WebRtcVideoChannel2* channel = | |
626 new WebRtcVideoChannel2(call_factory_, voice_engine_, | |
627 static_cast<WebRtcVoiceMediaChannel*>(voice_channel), options, | |
628 external_encoder_factory_, external_decoder_factory_); | |
629 if (!channel->Init()) { | |
630 delete channel; | |
631 return NULL; | |
632 } | |
633 channel->SetRecvCodecs(video_codecs_); | 607 channel->SetRecvCodecs(video_codecs_); |
634 return channel; | 608 return channel; |
635 } | 609 } |
636 | 610 |
637 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { | 611 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { |
638 return video_codecs_; | 612 return video_codecs_; |
639 } | 613 } |
640 | 614 |
641 const std::vector<RtpHeaderExtension>& | 615 const std::vector<RtpHeaderExtension>& |
642 WebRtcVideoEngine2::rtp_header_extensions() const { | 616 WebRtcVideoEngine2::rtp_header_extensions() const { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 codecs[i].max_fps, | 755 codecs[i].max_fps, |
782 0); | 756 0); |
783 | 757 |
784 AddDefaultFeedbackParams(&codec); | 758 AddDefaultFeedbackParams(&codec); |
785 supported_codecs.push_back(codec); | 759 supported_codecs.push_back(codec); |
786 } | 760 } |
787 return supported_codecs; | 761 return supported_codecs; |
788 } | 762 } |
789 | 763 |
790 WebRtcVideoChannel2::WebRtcVideoChannel2( | 764 WebRtcVideoChannel2::WebRtcVideoChannel2( |
791 WebRtcCallFactory* call_factory, | 765 webrtc::Call* call, |
792 WebRtcVoiceEngine* voice_engine, | |
793 WebRtcVoiceMediaChannel* voice_channel, | |
794 const VideoOptions& options, | 766 const VideoOptions& options, |
795 WebRtcVideoEncoderFactory* external_encoder_factory, | 767 WebRtcVideoEncoderFactory* external_encoder_factory, |
796 WebRtcVideoDecoderFactory* external_decoder_factory) | 768 WebRtcVideoDecoderFactory* external_decoder_factory) |
797 : unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), | 769 : call_(call), |
798 voice_channel_(voice_channel), | 770 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), |
799 voice_channel_id_(voice_channel ? voice_channel->voe_channel() : -1), | |
800 external_encoder_factory_(external_encoder_factory), | 771 external_encoder_factory_(external_encoder_factory), |
801 external_decoder_factory_(external_decoder_factory) { | 772 external_decoder_factory_(external_decoder_factory) { |
802 DCHECK(thread_checker_.CalledOnValidThread()); | 773 DCHECK(thread_checker_.CalledOnValidThread()); |
803 SetDefaultOptions(); | 774 SetDefaultOptions(); |
804 options_.SetAll(options); | 775 options_.SetAll(options); |
805 options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); | 776 options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); |
806 webrtc::Call::Config config; | |
807 if (voice_engine != NULL) { | |
808 config.voice_engine = voice_engine->voe()->engine(); | |
809 } | |
810 config.bitrate_config.min_bitrate_bps = kMinBandwidthBps; | |
811 config.bitrate_config.start_bitrate_bps = kStartBandwidthBps; | |
812 config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; | |
813 call_.reset(call_factory->CreateCall(config)); | |
814 if (voice_channel_) { | |
815 voice_channel_->SetCall(call_.get()); | |
816 } | |
817 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; | 777 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; |
818 sending_ = false; | 778 sending_ = false; |
819 default_send_ssrc_ = 0; | 779 default_send_ssrc_ = 0; |
820 } | 780 } |
821 | 781 |
822 void WebRtcVideoChannel2::SetDefaultOptions() { | 782 void WebRtcVideoChannel2::SetDefaultOptions() { |
823 options_.cpu_overuse_detection.Set(true); | 783 options_.cpu_overuse_detection.Set(true); |
824 options_.dscp.Set(false); | 784 options_.dscp.Set(false); |
825 options_.suspend_below_min_bitrate.Set(false); | 785 options_.suspend_below_min_bitrate.Set(false); |
826 options_.video_noise_reduction.Set(true); | 786 options_.video_noise_reduction.Set(true); |
827 options_.screencast_min_bitrate.Set(0); | 787 options_.screencast_min_bitrate.Set(0); |
828 } | 788 } |
829 | 789 |
830 WebRtcVideoChannel2::~WebRtcVideoChannel2() { | 790 WebRtcVideoChannel2::~WebRtcVideoChannel2() { |
831 DetachVoiceChannel(); | |
832 for (auto& kv : send_streams_) | 791 for (auto& kv : send_streams_) |
833 delete kv.second; | 792 delete kv.second; |
834 for (auto& kv : receive_streams_) | 793 for (auto& kv : receive_streams_) |
835 delete kv.second; | 794 delete kv.second; |
836 } | 795 } |
837 | 796 |
838 bool WebRtcVideoChannel2::Init() { return true; } | |
839 | |
840 void WebRtcVideoChannel2::DetachVoiceChannel() { | |
841 DCHECK(thread_checker_.CalledOnValidThread()); | |
842 if (voice_channel_) { | |
843 voice_channel_->SetCall(nullptr); | |
844 voice_channel_ = nullptr; | |
845 } | |
846 } | |
847 | |
848 bool WebRtcVideoChannel2::CodecIsExternallySupported( | 797 bool WebRtcVideoChannel2::CodecIsExternallySupported( |
849 const std::string& name) const { | 798 const std::string& name) const { |
850 if (external_encoder_factory_ == NULL) { | 799 if (external_encoder_factory_ == NULL) { |
851 return false; | 800 return false; |
852 } | 801 } |
853 | 802 |
854 const std::vector<WebRtcVideoEncoderFactory::VideoCodec> external_codecs = | 803 const std::vector<WebRtcVideoEncoderFactory::VideoCodec> external_codecs = |
855 external_encoder_factory_->codecs(); | 804 external_encoder_factory_->codecs(); |
856 for (size_t c = 0; c < external_codecs.size(); ++c) { | 805 for (size_t c = 0; c < external_codecs.size(); ++c) { |
857 if (CodecNamesEq(name, external_codecs[c].name)) { | 806 if (CodecNamesEq(name, external_codecs[c].name)) { |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 if (!ValidateSendSsrcAvailability(sp)) | 1091 if (!ValidateSendSsrcAvailability(sp)) |
1143 return false; | 1092 return false; |
1144 | 1093 |
1145 for (uint32 used_ssrc : sp.ssrcs) | 1094 for (uint32 used_ssrc : sp.ssrcs) |
1146 send_ssrcs_.insert(used_ssrc); | 1095 send_ssrcs_.insert(used_ssrc); |
1147 | 1096 |
1148 webrtc::VideoSendStream::Config config(this); | 1097 webrtc::VideoSendStream::Config config(this); |
1149 config.overuse_callback = this; | 1098 config.overuse_callback = this; |
1150 | 1099 |
1151 WebRtcVideoSendStream* stream = | 1100 WebRtcVideoSendStream* stream = |
1152 new WebRtcVideoSendStream(call_.get(), | 1101 new WebRtcVideoSendStream(call_, |
1153 sp, | 1102 sp, |
1154 config, | 1103 config, |
1155 external_encoder_factory_, | 1104 external_encoder_factory_, |
1156 options_, | 1105 options_, |
1157 bitrate_config_.max_bitrate_bps, | 1106 bitrate_config_.max_bitrate_bps, |
1158 send_codec_, | 1107 send_codec_, |
1159 send_rtp_extensions_); | 1108 send_rtp_extensions_); |
1160 | 1109 |
1161 uint32 ssrc = sp.first_ssrc(); | 1110 uint32 ssrc = sp.first_ssrc(); |
1162 DCHECK(ssrc != 0); | 1111 DCHECK(ssrc != 0); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 // Set up A/V sync group based on sync label. | 1214 // Set up A/V sync group based on sync label. |
1266 config.sync_group = sp.sync_label; | 1215 config.sync_group = sp.sync_label; |
1267 | 1216 |
1268 config.rtp.remb = false; | 1217 config.rtp.remb = false; |
1269 VideoCodecSettings send_codec; | 1218 VideoCodecSettings send_codec; |
1270 if (send_codec_.Get(&send_codec)) { | 1219 if (send_codec_.Get(&send_codec)) { |
1271 config.rtp.remb = HasRemb(send_codec.codec); | 1220 config.rtp.remb = HasRemb(send_codec.codec); |
1272 } | 1221 } |
1273 | 1222 |
1274 receive_streams_[ssrc] = new WebRtcVideoReceiveStream( | 1223 receive_streams_[ssrc] = new WebRtcVideoReceiveStream( |
1275 call_.get(), sp, config, external_decoder_factory_, default_stream, | 1224 call_, sp, config, external_decoder_factory_, default_stream, |
1276 recv_codecs_); | 1225 recv_codecs_); |
1277 | 1226 |
1278 return true; | 1227 return true; |
1279 } | 1228 } |
1280 | 1229 |
1281 void WebRtcVideoChannel2::ConfigureReceiverRtp( | 1230 void WebRtcVideoChannel2::ConfigureReceiverRtp( |
1282 webrtc::VideoReceiveStream::Config* config, | 1231 webrtc::VideoReceiveStream::Config* config, |
1283 const StreamParams& sp) const { | 1232 const StreamParams& sp) const { |
1284 uint32 ssrc = sp.first_ssrc(); | 1233 uint32 ssrc = sp.first_ssrc(); |
1285 | 1234 |
(...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2792 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]; |
2793 } | 2742 } |
2794 } | 2743 } |
2795 | 2744 |
2796 return video_codecs; | 2745 return video_codecs; |
2797 } | 2746 } |
2798 | 2747 |
2799 } // namespace cricket | 2748 } // namespace cricket |
2800 | 2749 |
2801 #endif // HAVE_WEBRTC_VIDEO | 2750 #endif // HAVE_WEBRTC_VIDEO |
OLD | NEW |