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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 const int kVideoRtpBufferSize = 65536; | 321 const int kVideoRtpBufferSize = 65536; |
322 | 322 |
323 // This constant is really an on/off, lower-level configurable NACK history | 323 // This constant is really an on/off, lower-level configurable NACK history |
324 // duration hasn't been implemented. | 324 // duration hasn't been implemented. |
325 static const int kNackHistoryMs = 1000; | 325 static const int kNackHistoryMs = 1000; |
326 | 326 |
327 static const int kDefaultQpMax = 56; | 327 static const int kDefaultQpMax = 56; |
328 | 328 |
329 static const int kDefaultRtcpReceiverReportSsrc = 1; | 329 static const int kDefaultRtcpReceiverReportSsrc = 1; |
330 | 330 |
331 const int kMinBandwidthBps = 30000; | |
332 const int kStartBandwidthBps = 300000; | |
333 const int kMaxBandwidthBps = 2000000; | |
334 | |
335 std::vector<VideoCodec> DefaultVideoCodecList() { | 331 std::vector<VideoCodec> DefaultVideoCodecList() { |
336 std::vector<VideoCodec> codecs; | 332 std::vector<VideoCodec> codecs; |
337 if (CodecIsInternallySupported(kVp9CodecName)) { | 333 if (CodecIsInternallySupported(kVp9CodecName)) { |
338 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp9PlType, | 334 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp9PlType, |
339 kVp9CodecName)); | 335 kVp9CodecName)); |
340 // TODO(andresp): Add rtx codec for vp9 and verify it works. | 336 // TODO(andresp): Add rtx codec for vp9 and verify it works. |
341 } | 337 } |
342 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp8PlType, | 338 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp8PlType, |
343 kVp8CodecName)); | 339 kVp8CodecName)); |
344 if (CodecIsInternallySupported(kH264CodecName)) { | 340 if (CodecIsInternallySupported(kH264CodecName)) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; | 511 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; |
516 if (!channel->AddRecvStream(sp, true)) { | 512 if (!channel->AddRecvStream(sp, true)) { |
517 LOG(LS_WARNING) << "Could not create default receive stream."; | 513 LOG(LS_WARNING) << "Could not create default receive stream."; |
518 } | 514 } |
519 | 515 |
520 channel->SetRenderer(ssrc, default_renderer_); | 516 channel->SetRenderer(ssrc, default_renderer_); |
521 default_recv_ssrc_ = ssrc; | 517 default_recv_ssrc_ = ssrc; |
522 return kDeliverPacket; | 518 return kDeliverPacket; |
523 } | 519 } |
524 | 520 |
525 WebRtcCallFactory::~WebRtcCallFactory() { | |
526 } | |
527 webrtc::Call* WebRtcCallFactory::CreateCall( | |
528 const webrtc::Call::Config& config) { | |
529 return webrtc::Call::Create(config); | |
530 } | |
531 | |
532 VideoRenderer* DefaultUnsignalledSsrcHandler::GetDefaultRenderer() const { | 521 VideoRenderer* DefaultUnsignalledSsrcHandler::GetDefaultRenderer() const { |
533 return default_renderer_; | 522 return default_renderer_; |
534 } | 523 } |
535 | 524 |
536 void DefaultUnsignalledSsrcHandler::SetDefaultRenderer( | 525 void DefaultUnsignalledSsrcHandler::SetDefaultRenderer( |
537 VideoMediaChannel* channel, | 526 VideoMediaChannel* channel, |
538 VideoRenderer* renderer) { | 527 VideoRenderer* renderer) { |
539 default_renderer_ = renderer; | 528 default_renderer_ = renderer; |
540 if (default_recv_ssrc_ != 0) { | 529 if (default_recv_ssrc_ != 0) { |
541 channel->SetRenderer(default_recv_ssrc_, default_renderer_); | 530 channel->SetRenderer(default_recv_ssrc_, default_renderer_); |
542 } | 531 } |
543 } | 532 } |
544 | 533 |
545 WebRtcVideoEngine2::WebRtcVideoEngine2(WebRtcVoiceEngine* voice_engine) | 534 WebRtcVideoEngine2::WebRtcVideoEngine2() |
546 : voice_engine_(voice_engine), | 535 : initialized_(false), |
547 initialized_(false), | |
548 call_factory_(&default_call_factory_), | |
549 external_decoder_factory_(NULL), | 536 external_decoder_factory_(NULL), |
550 external_encoder_factory_(NULL) { | 537 external_encoder_factory_(NULL) { |
551 LOG(LS_INFO) << "WebRtcVideoEngine2::WebRtcVideoEngine2()"; | 538 LOG(LS_INFO) << "WebRtcVideoEngine2::WebRtcVideoEngine2()"; |
552 video_codecs_ = GetSupportedCodecs(); | 539 video_codecs_ = GetSupportedCodecs(); |
553 rtp_header_extensions_.push_back( | 540 rtp_header_extensions_.push_back( |
554 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, | 541 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, |
555 kRtpTimestampOffsetHeaderExtensionDefaultId)); | 542 kRtpTimestampOffsetHeaderExtensionDefaultId)); |
556 rtp_header_extensions_.push_back( | 543 rtp_header_extensions_.push_back( |
557 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, | 544 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, |
558 kRtpAbsoluteSenderTimeHeaderExtensionDefaultId)); | 545 kRtpAbsoluteSenderTimeHeaderExtensionDefaultId)); |
559 rtp_header_extensions_.push_back( | 546 rtp_header_extensions_.push_back( |
560 RtpHeaderExtension(kRtpVideoRotationHeaderExtension, | 547 RtpHeaderExtension(kRtpVideoRotationHeaderExtension, |
561 kRtpVideoRotationHeaderExtensionDefaultId)); | 548 kRtpVideoRotationHeaderExtensionDefaultId)); |
562 } | 549 } |
563 | 550 |
564 WebRtcVideoEngine2::~WebRtcVideoEngine2() { | 551 WebRtcVideoEngine2::~WebRtcVideoEngine2() { |
565 LOG(LS_INFO) << "WebRtcVideoEngine2::~WebRtcVideoEngine2"; | 552 LOG(LS_INFO) << "WebRtcVideoEngine2::~WebRtcVideoEngine2"; |
566 } | 553 } |
567 | 554 |
568 void WebRtcVideoEngine2::SetCallFactory(WebRtcCallFactory* call_factory) { | |
569 DCHECK(!initialized_); | |
570 call_factory_ = call_factory; | |
571 } | |
572 | |
573 void WebRtcVideoEngine2::Init() { | 555 void WebRtcVideoEngine2::Init() { |
574 LOG(LS_INFO) << "WebRtcVideoEngine2::Init"; | 556 LOG(LS_INFO) << "WebRtcVideoEngine2::Init"; |
575 initialized_ = true; | 557 initialized_ = true; |
576 } | 558 } |
577 | 559 |
578 int WebRtcVideoEngine2::GetCapabilities() { return VIDEO_RECV | VIDEO_SEND; } | 560 int WebRtcVideoEngine2::GetCapabilities() { return VIDEO_RECV | VIDEO_SEND; } |
579 | 561 |
580 bool WebRtcVideoEngine2::SetDefaultEncoderConfig( | 562 bool WebRtcVideoEngine2::SetDefaultEncoderConfig( |
581 const VideoEncoderConfig& config) { | 563 const VideoEncoderConfig& config) { |
582 const VideoCodec& codec = config.max_codec; | 564 const VideoCodec& codec = config.max_codec; |
(...skipping 11 matching lines...) Expand all Loading... | |
594 if (!supports_codec) { | 576 if (!supports_codec) { |
595 LOG(LS_ERROR) << "SetDefaultEncoderConfig, codec not supported: " | 577 LOG(LS_ERROR) << "SetDefaultEncoderConfig, codec not supported: " |
596 << codec.ToString(); | 578 << codec.ToString(); |
597 return false; | 579 return false; |
598 } | 580 } |
599 | 581 |
600 return true; | 582 return true; |
601 } | 583 } |
602 | 584 |
603 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( | 585 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( |
604 const VideoOptions& options, | 586 webrtc::Call* call, |
605 VoiceMediaChannel* voice_channel) { | 587 const VideoOptions& options) { |
606 DCHECK(initialized_); | 588 DCHECK(initialized_); |
607 LOG(LS_INFO) << "CreateChannel: " | 589 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); |
608 << (voice_channel != NULL ? "With" : "Without") | 590 WebRtcVideoChannel2* channel = new WebRtcVideoChannel2(call, options, |
609 << " voice channel. Options: " << options.ToString(); | 591 external_encoder_factory_, external_decoder_factory_); |
pthatcher1
2015/09/02 21:24:22
Why not pass the WebRtcVideoChannel2 into webrtc::
the sun
2015/09/03 15:00:46
Part of LoadObserver discussion.
| |
610 WebRtcVideoChannel2* channel = | |
611 new WebRtcVideoChannel2(call_factory_, voice_engine_, | |
612 static_cast<WebRtcVoiceMediaChannel*>(voice_channel), options, | |
613 external_encoder_factory_, external_decoder_factory_); | |
614 if (!channel->Init()) { | |
615 delete channel; | |
616 return NULL; | |
617 } | |
618 channel->SetRecvCodecs(video_codecs_); | 592 channel->SetRecvCodecs(video_codecs_); |
619 return channel; | 593 return channel; |
620 } | 594 } |
621 | 595 |
622 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { | 596 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { |
623 return video_codecs_; | 597 return video_codecs_; |
624 } | 598 } |
625 | 599 |
626 const std::vector<RtpHeaderExtension>& | 600 const std::vector<RtpHeaderExtension>& |
627 WebRtcVideoEngine2::rtp_header_extensions() const { | 601 WebRtcVideoEngine2::rtp_header_extensions() const { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 codecs[i].max_fps, | 740 codecs[i].max_fps, |
767 0); | 741 0); |
768 | 742 |
769 AddDefaultFeedbackParams(&codec); | 743 AddDefaultFeedbackParams(&codec); |
770 supported_codecs.push_back(codec); | 744 supported_codecs.push_back(codec); |
771 } | 745 } |
772 return supported_codecs; | 746 return supported_codecs; |
773 } | 747 } |
774 | 748 |
775 WebRtcVideoChannel2::WebRtcVideoChannel2( | 749 WebRtcVideoChannel2::WebRtcVideoChannel2( |
776 WebRtcCallFactory* call_factory, | 750 webrtc::Call* call, |
777 WebRtcVoiceEngine* voice_engine, | |
778 WebRtcVoiceMediaChannel* voice_channel, | |
779 const VideoOptions& options, | 751 const VideoOptions& options, |
780 WebRtcVideoEncoderFactory* external_encoder_factory, | 752 WebRtcVideoEncoderFactory* external_encoder_factory, |
781 WebRtcVideoDecoderFactory* external_decoder_factory) | 753 WebRtcVideoDecoderFactory* external_decoder_factory) |
782 : unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), | 754 : call_(call), |
783 voice_channel_(voice_channel), | 755 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), |
784 voice_channel_id_(voice_channel ? voice_channel->voe_channel() : -1), | |
785 external_encoder_factory_(external_encoder_factory), | 756 external_encoder_factory_(external_encoder_factory), |
786 external_decoder_factory_(external_decoder_factory) { | 757 external_decoder_factory_(external_decoder_factory) { |
787 DCHECK(thread_checker_.CalledOnValidThread()); | 758 DCHECK(thread_checker_.CalledOnValidThread()); |
788 SetDefaultOptions(); | 759 SetDefaultOptions(); |
789 options_.SetAll(options); | 760 options_.SetAll(options); |
790 options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); | 761 options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); |
791 webrtc::Call::Config config; | |
792 config.overuse_callback = this; | |
793 if (voice_engine != NULL) { | |
794 config.voice_engine = voice_engine->voe()->engine(); | |
795 } | |
796 config.bitrate_config.min_bitrate_bps = kMinBandwidthBps; | |
797 config.bitrate_config.start_bitrate_bps = kStartBandwidthBps; | |
798 config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; | |
799 call_.reset(call_factory->CreateCall(config)); | |
800 if (voice_channel_) { | |
801 voice_channel_->SetCall(call_.get()); | |
802 } | |
803 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; | 762 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; |
804 sending_ = false; | 763 sending_ = false; |
805 default_send_ssrc_ = 0; | 764 default_send_ssrc_ = 0; |
806 } | 765 } |
807 | 766 |
808 void WebRtcVideoChannel2::SetDefaultOptions() { | 767 void WebRtcVideoChannel2::SetDefaultOptions() { |
809 options_.cpu_overuse_detection.Set(true); | 768 options_.cpu_overuse_detection.Set(true); |
810 options_.dscp.Set(false); | 769 options_.dscp.Set(false); |
811 options_.suspend_below_min_bitrate.Set(false); | 770 options_.suspend_below_min_bitrate.Set(false); |
812 options_.video_noise_reduction.Set(true); | 771 options_.video_noise_reduction.Set(true); |
813 options_.screencast_min_bitrate.Set(0); | 772 options_.screencast_min_bitrate.Set(0); |
814 } | 773 } |
815 | 774 |
816 WebRtcVideoChannel2::~WebRtcVideoChannel2() { | 775 WebRtcVideoChannel2::~WebRtcVideoChannel2() { |
817 DetachVoiceChannel(); | |
818 for (auto& kv : send_streams_) | 776 for (auto& kv : send_streams_) |
819 delete kv.second; | 777 delete kv.second; |
820 for (auto& kv : receive_streams_) | 778 for (auto& kv : receive_streams_) |
821 delete kv.second; | 779 delete kv.second; |
822 } | 780 } |
823 | 781 |
824 bool WebRtcVideoChannel2::Init() { return true; } | |
825 | |
826 void WebRtcVideoChannel2::DetachVoiceChannel() { | |
827 DCHECK(thread_checker_.CalledOnValidThread()); | |
828 if (voice_channel_) { | |
829 voice_channel_->SetCall(nullptr); | |
830 voice_channel_ = nullptr; | |
831 } | |
832 } | |
833 | |
834 bool WebRtcVideoChannel2::CodecIsExternallySupported( | 782 bool WebRtcVideoChannel2::CodecIsExternallySupported( |
835 const std::string& name) const { | 783 const std::string& name) const { |
836 if (external_encoder_factory_ == NULL) { | 784 if (external_encoder_factory_ == NULL) { |
837 return false; | 785 return false; |
838 } | 786 } |
839 | 787 |
840 const std::vector<WebRtcVideoEncoderFactory::VideoCodec> external_codecs = | 788 const std::vector<WebRtcVideoEncoderFactory::VideoCodec> external_codecs = |
841 external_encoder_factory_->codecs(); | 789 external_encoder_factory_->codecs(); |
842 for (size_t c = 0; c < external_codecs.size(); ++c) { | 790 for (size_t c = 0; c < external_codecs.size(); ++c) { |
843 if (CodecNamesEq(name, external_codecs[c].name)) { | 791 if (CodecNamesEq(name, external_codecs[c].name)) { |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1111 | 1059 |
1112 rtc::CritScope stream_lock(&stream_crit_); | 1060 rtc::CritScope stream_lock(&stream_crit_); |
1113 | 1061 |
1114 if (!ValidateSendSsrcAvailability(sp)) | 1062 if (!ValidateSendSsrcAvailability(sp)) |
1115 return false; | 1063 return false; |
1116 | 1064 |
1117 for (uint32 used_ssrc : sp.ssrcs) | 1065 for (uint32 used_ssrc : sp.ssrcs) |
1118 send_ssrcs_.insert(used_ssrc); | 1066 send_ssrcs_.insert(used_ssrc); |
1119 | 1067 |
1120 WebRtcVideoSendStream* stream = | 1068 WebRtcVideoSendStream* stream = |
1121 new WebRtcVideoSendStream(call_.get(), | 1069 new WebRtcVideoSendStream(call_, |
1122 sp, | 1070 sp, |
1123 webrtc::VideoSendStream::Config(this), | 1071 webrtc::VideoSendStream::Config(this), |
1124 external_encoder_factory_, | 1072 external_encoder_factory_, |
1125 options_, | 1073 options_, |
1126 bitrate_config_.max_bitrate_bps, | 1074 bitrate_config_.max_bitrate_bps, |
1127 send_codec_, | 1075 send_codec_, |
1128 send_rtp_extensions_); | 1076 send_rtp_extensions_); |
1129 | 1077 |
1130 uint32 ssrc = sp.first_ssrc(); | 1078 uint32 ssrc = sp.first_ssrc(); |
1131 DCHECK(ssrc != 0); | 1079 DCHECK(ssrc != 0); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1234 // Set up A/V sync group based on sync label. | 1182 // Set up A/V sync group based on sync label. |
1235 config.sync_group = sp.sync_label; | 1183 config.sync_group = sp.sync_label; |
1236 | 1184 |
1237 config.rtp.remb = false; | 1185 config.rtp.remb = false; |
1238 VideoCodecSettings send_codec; | 1186 VideoCodecSettings send_codec; |
1239 if (send_codec_.Get(&send_codec)) { | 1187 if (send_codec_.Get(&send_codec)) { |
1240 config.rtp.remb = HasRemb(send_codec.codec); | 1188 config.rtp.remb = HasRemb(send_codec.codec); |
1241 } | 1189 } |
1242 | 1190 |
1243 receive_streams_[ssrc] = new WebRtcVideoReceiveStream( | 1191 receive_streams_[ssrc] = new WebRtcVideoReceiveStream( |
1244 call_.get(), sp, config, external_decoder_factory_, default_stream, | 1192 call_, sp, config, external_decoder_factory_, default_stream, |
1245 recv_codecs_); | 1193 recv_codecs_); |
1246 | 1194 |
1247 return true; | 1195 return true; |
1248 } | 1196 } |
1249 | 1197 |
1250 void WebRtcVideoChannel2::ConfigureReceiverRtp( | 1198 void WebRtcVideoChannel2::ConfigureReceiverRtp( |
1251 webrtc::VideoReceiveStream::Config* config, | 1199 webrtc::VideoReceiveStream::Config* config, |
1252 const StreamParams& sp) const { | 1200 const StreamParams& sp) const { |
1253 uint32 ssrc = sp.first_ssrc(); | 1201 uint32 ssrc = sp.first_ssrc(); |
1254 | 1202 |
(...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2744 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2692 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2745 } | 2693 } |
2746 } | 2694 } |
2747 | 2695 |
2748 return video_codecs; | 2696 return video_codecs; |
2749 } | 2697 } |
2750 | 2698 |
2751 } // namespace cricket | 2699 } // namespace cricket |
2752 | 2700 |
2753 #endif // HAVE_WEBRTC_VIDEO | 2701 #endif // HAVE_WEBRTC_VIDEO |
OLD | NEW |