Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: talk/media/webrtc/webrtcvideoengine2.cc

Issue 1269863005: MediaController/Call instantiation. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase+comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; 525 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << ".";
530 if (!channel->AddRecvStream(sp, true)) { 526 if (!channel->AddRecvStream(sp, true)) {
531 LOG(LS_WARNING) << "Could not create default receive stream."; 527 LOG(LS_WARNING) << "Could not create default receive stream.";
532 } 528 }
533 529
534 channel->SetRenderer(ssrc, default_renderer_); 530 channel->SetRenderer(ssrc, default_renderer_);
535 default_recv_ssrc_ = ssrc; 531 default_recv_ssrc_ = ssrc;
536 return kDeliverPacket; 532 return kDeliverPacket;
537 } 533 }
538 534
539 WebRtcCallFactory::~WebRtcCallFactory() {
540 }
541 webrtc::Call* WebRtcCallFactory::CreateCall(
542 const webrtc::Call::Config& config) {
543 return webrtc::Call::Create(config);
544 }
545
546 VideoRenderer* DefaultUnsignalledSsrcHandler::GetDefaultRenderer() const { 535 VideoRenderer* DefaultUnsignalledSsrcHandler::GetDefaultRenderer() const {
547 return default_renderer_; 536 return default_renderer_;
548 } 537 }
549 538
550 void DefaultUnsignalledSsrcHandler::SetDefaultRenderer( 539 void DefaultUnsignalledSsrcHandler::SetDefaultRenderer(
551 VideoMediaChannel* channel, 540 VideoMediaChannel* channel,
552 VideoRenderer* renderer) { 541 VideoRenderer* renderer) {
553 default_renderer_ = renderer; 542 default_renderer_ = renderer;
554 if (default_recv_ssrc_ != 0) { 543 if (default_recv_ssrc_ != 0) {
555 channel->SetRenderer(default_recv_ssrc_, default_renderer_); 544 channel->SetRenderer(default_recv_ssrc_, default_renderer_);
556 } 545 }
557 } 546 }
558 547
559 WebRtcVideoEngine2::WebRtcVideoEngine2(WebRtcVoiceEngine* voice_engine) 548 WebRtcVideoEngine2::WebRtcVideoEngine2()
560 : voice_engine_(voice_engine), 549 : initialized_(false),
561 initialized_(false),
562 call_factory_(&default_call_factory_),
563 external_decoder_factory_(NULL), 550 external_decoder_factory_(NULL),
564 external_encoder_factory_(NULL) { 551 external_encoder_factory_(NULL) {
565 LOG(LS_INFO) << "WebRtcVideoEngine2::WebRtcVideoEngine2()"; 552 LOG(LS_INFO) << "WebRtcVideoEngine2::WebRtcVideoEngine2()";
566 video_codecs_ = GetSupportedCodecs(); 553 video_codecs_ = GetSupportedCodecs();
567 rtp_header_extensions_.push_back( 554 rtp_header_extensions_.push_back(
568 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 555 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension,
569 kRtpTimestampOffsetHeaderExtensionDefaultId)); 556 kRtpTimestampOffsetHeaderExtensionDefaultId));
570 rtp_header_extensions_.push_back( 557 rtp_header_extensions_.push_back(
571 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, 558 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension,
572 kRtpAbsoluteSenderTimeHeaderExtensionDefaultId)); 559 kRtpAbsoluteSenderTimeHeaderExtensionDefaultId));
573 rtp_header_extensions_.push_back( 560 rtp_header_extensions_.push_back(
574 RtpHeaderExtension(kRtpVideoRotationHeaderExtension, 561 RtpHeaderExtension(kRtpVideoRotationHeaderExtension,
575 kRtpVideoRotationHeaderExtensionDefaultId)); 562 kRtpVideoRotationHeaderExtensionDefaultId));
576 } 563 }
577 564
578 WebRtcVideoEngine2::~WebRtcVideoEngine2() { 565 WebRtcVideoEngine2::~WebRtcVideoEngine2() {
579 LOG(LS_INFO) << "WebRtcVideoEngine2::~WebRtcVideoEngine2"; 566 LOG(LS_INFO) << "WebRtcVideoEngine2::~WebRtcVideoEngine2";
580 } 567 }
581 568
582 void WebRtcVideoEngine2::SetCallFactory(WebRtcCallFactory* call_factory) {
583 DCHECK(!initialized_);
584 call_factory_ = call_factory;
585 }
586
587 void WebRtcVideoEngine2::Init() { 569 void WebRtcVideoEngine2::Init() {
588 LOG(LS_INFO) << "WebRtcVideoEngine2::Init"; 570 LOG(LS_INFO) << "WebRtcVideoEngine2::Init";
589 initialized_ = true; 571 initialized_ = true;
590 } 572 }
591 573
592 int WebRtcVideoEngine2::GetCapabilities() { return VIDEO_RECV | VIDEO_SEND; } 574 int WebRtcVideoEngine2::GetCapabilities() { return VIDEO_RECV | VIDEO_SEND; }
593 575
594 bool WebRtcVideoEngine2::SetDefaultEncoderConfig( 576 bool WebRtcVideoEngine2::SetDefaultEncoderConfig(
595 const VideoEncoderConfig& config) { 577 const VideoEncoderConfig& config) {
596 const VideoCodec& codec = config.max_codec; 578 const VideoCodec& codec = config.max_codec;
(...skipping 11 matching lines...) Expand all
608 if (!supports_codec) { 590 if (!supports_codec) {
609 LOG(LS_ERROR) << "SetDefaultEncoderConfig, codec not supported: " 591 LOG(LS_ERROR) << "SetDefaultEncoderConfig, codec not supported: "
610 << codec.ToString(); 592 << codec.ToString();
611 return false; 593 return false;
612 } 594 }
613 595
614 return true; 596 return true;
615 } 597 }
616 598
617 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( 599 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel(
618 const VideoOptions& options, 600 webrtc::Call* call,
619 VoiceMediaChannel* voice_channel) { 601 const VideoOptions& options) {
620 DCHECK(initialized_); 602 DCHECK(initialized_);
621 LOG(LS_INFO) << "CreateChannel: " 603 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString();
622 << (voice_channel != NULL ? "With" : "Without") 604 WebRtcVideoChannel2* channel = new WebRtcVideoChannel2(call, options,
623 << " voice channel. Options: " << options.ToString(); 605 external_encoder_factory_, external_decoder_factory_);
624 WebRtcVideoChannel2* channel =
625 new WebRtcVideoChannel2(call_factory_, voice_engine_,
626 static_cast<WebRtcVoiceMediaChannel*>(voice_channel), options,
627 external_encoder_factory_, external_decoder_factory_);
628 if (!channel->Init()) {
629 delete channel;
630 return NULL;
631 }
632 channel->SetRecvCodecs(video_codecs_); 606 channel->SetRecvCodecs(video_codecs_);
633 return channel; 607 return channel;
634 } 608 }
635 609
636 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { 610 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const {
637 return video_codecs_; 611 return video_codecs_;
638 } 612 }
639 613
640 const std::vector<RtpHeaderExtension>& 614 const std::vector<RtpHeaderExtension>&
641 WebRtcVideoEngine2::rtp_header_extensions() const { 615 WebRtcVideoEngine2::rtp_header_extensions() const {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 codecs[i].max_fps, 754 codecs[i].max_fps,
781 0); 755 0);
782 756
783 AddDefaultFeedbackParams(&codec); 757 AddDefaultFeedbackParams(&codec);
784 supported_codecs.push_back(codec); 758 supported_codecs.push_back(codec);
785 } 759 }
786 return supported_codecs; 760 return supported_codecs;
787 } 761 }
788 762
789 WebRtcVideoChannel2::WebRtcVideoChannel2( 763 WebRtcVideoChannel2::WebRtcVideoChannel2(
790 WebRtcCallFactory* call_factory, 764 webrtc::Call* call,
791 WebRtcVoiceEngine* voice_engine,
792 WebRtcVoiceMediaChannel* voice_channel,
793 const VideoOptions& options, 765 const VideoOptions& options,
794 WebRtcVideoEncoderFactory* external_encoder_factory, 766 WebRtcVideoEncoderFactory* external_encoder_factory,
795 WebRtcVideoDecoderFactory* external_decoder_factory) 767 WebRtcVideoDecoderFactory* external_decoder_factory)
796 : unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), 768 : call_(call),
797 voice_channel_(voice_channel), 769 unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_),
798 voice_channel_id_(voice_channel ? voice_channel->voe_channel() : -1),
799 external_encoder_factory_(external_encoder_factory), 770 external_encoder_factory_(external_encoder_factory),
800 external_decoder_factory_(external_decoder_factory) { 771 external_decoder_factory_(external_decoder_factory) {
801 DCHECK(thread_checker_.CalledOnValidThread()); 772 DCHECK(thread_checker_.CalledOnValidThread());
802 SetDefaultOptions(); 773 SetDefaultOptions();
803 options_.SetAll(options); 774 options_.SetAll(options);
804 options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); 775 options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_);
805 webrtc::Call::Config config;
806 if (voice_engine != NULL) {
807 config.voice_engine = voice_engine->voe()->engine();
808 }
809 config.bitrate_config.min_bitrate_bps = kMinBandwidthBps;
810 config.bitrate_config.start_bitrate_bps = kStartBandwidthBps;
811 config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps;
812 call_.reset(call_factory->CreateCall(config));
813 if (voice_channel_) {
814 voice_channel_->SetCall(call_.get());
815 }
816 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; 776 rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc;
817 sending_ = false; 777 sending_ = false;
818 default_send_ssrc_ = 0; 778 default_send_ssrc_ = 0;
819 } 779 }
820 780
821 void WebRtcVideoChannel2::SetDefaultOptions() { 781 void WebRtcVideoChannel2::SetDefaultOptions() {
822 options_.cpu_overuse_detection.Set(true); 782 options_.cpu_overuse_detection.Set(true);
823 options_.dscp.Set(false); 783 options_.dscp.Set(false);
824 options_.suspend_below_min_bitrate.Set(false); 784 options_.suspend_below_min_bitrate.Set(false);
825 options_.video_noise_reduction.Set(true); 785 options_.video_noise_reduction.Set(true);
826 options_.screencast_min_bitrate.Set(0); 786 options_.screencast_min_bitrate.Set(0);
827 } 787 }
828 788
829 WebRtcVideoChannel2::~WebRtcVideoChannel2() { 789 WebRtcVideoChannel2::~WebRtcVideoChannel2() {
830 DetachVoiceChannel();
831 for (auto& kv : send_streams_) 790 for (auto& kv : send_streams_)
832 delete kv.second; 791 delete kv.second;
833 for (auto& kv : receive_streams_) 792 for (auto& kv : receive_streams_)
834 delete kv.second; 793 delete kv.second;
835 } 794 }
836 795
837 bool WebRtcVideoChannel2::Init() { return true; }
838
839 void WebRtcVideoChannel2::DetachVoiceChannel() {
840 DCHECK(thread_checker_.CalledOnValidThread());
841 if (voice_channel_) {
842 voice_channel_->SetCall(nullptr);
843 voice_channel_ = nullptr;
844 }
845 }
846
847 bool WebRtcVideoChannel2::CodecIsExternallySupported( 796 bool WebRtcVideoChannel2::CodecIsExternallySupported(
848 const std::string& name) const { 797 const std::string& name) const {
849 if (external_encoder_factory_ == NULL) { 798 if (external_encoder_factory_ == NULL) {
850 return false; 799 return false;
851 } 800 }
852 801
853 const std::vector<WebRtcVideoEncoderFactory::VideoCodec> external_codecs = 802 const std::vector<WebRtcVideoEncoderFactory::VideoCodec> external_codecs =
854 external_encoder_factory_->codecs(); 803 external_encoder_factory_->codecs();
855 for (size_t c = 0; c < external_codecs.size(); ++c) { 804 for (size_t c = 0; c < external_codecs.size(); ++c) {
856 if (CodecNamesEq(name, external_codecs[c].name)) { 805 if (CodecNamesEq(name, external_codecs[c].name)) {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 if (!ValidateSendSsrcAvailability(sp)) 1076 if (!ValidateSendSsrcAvailability(sp))
1128 return false; 1077 return false;
1129 1078
1130 for (uint32 used_ssrc : sp.ssrcs) 1079 for (uint32 used_ssrc : sp.ssrcs)
1131 send_ssrcs_.insert(used_ssrc); 1080 send_ssrcs_.insert(used_ssrc);
1132 1081
1133 webrtc::VideoSendStream::Config config(this); 1082 webrtc::VideoSendStream::Config config(this);
1134 config.overuse_callback = this; 1083 config.overuse_callback = this;
1135 1084
1136 WebRtcVideoSendStream* stream = 1085 WebRtcVideoSendStream* stream =
1137 new WebRtcVideoSendStream(call_.get(), 1086 new WebRtcVideoSendStream(call_,
1138 sp, 1087 sp,
1139 config, 1088 config,
1140 external_encoder_factory_, 1089 external_encoder_factory_,
1141 options_, 1090 options_,
1142 bitrate_config_.max_bitrate_bps, 1091 bitrate_config_.max_bitrate_bps,
1143 send_codec_, 1092 send_codec_,
1144 send_rtp_extensions_); 1093 send_rtp_extensions_);
1145 1094
1146 uint32 ssrc = sp.first_ssrc(); 1095 uint32 ssrc = sp.first_ssrc();
1147 DCHECK(ssrc != 0); 1096 DCHECK(ssrc != 0);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 // Set up A/V sync group based on sync label. 1199 // Set up A/V sync group based on sync label.
1251 config.sync_group = sp.sync_label; 1200 config.sync_group = sp.sync_label;
1252 1201
1253 config.rtp.remb = false; 1202 config.rtp.remb = false;
1254 VideoCodecSettings send_codec; 1203 VideoCodecSettings send_codec;
1255 if (send_codec_.Get(&send_codec)) { 1204 if (send_codec_.Get(&send_codec)) {
1256 config.rtp.remb = HasRemb(send_codec.codec); 1205 config.rtp.remb = HasRemb(send_codec.codec);
1257 } 1206 }
1258 1207
1259 receive_streams_[ssrc] = new WebRtcVideoReceiveStream( 1208 receive_streams_[ssrc] = new WebRtcVideoReceiveStream(
1260 call_.get(), sp, config, external_decoder_factory_, default_stream, 1209 call_, sp, config, external_decoder_factory_, default_stream,
1261 recv_codecs_); 1210 recv_codecs_);
1262 1211
1263 return true; 1212 return true;
1264 } 1213 }
1265 1214
1266 void WebRtcVideoChannel2::ConfigureReceiverRtp( 1215 void WebRtcVideoChannel2::ConfigureReceiverRtp(
1267 webrtc::VideoReceiveStream::Config* config, 1216 webrtc::VideoReceiveStream::Config* config,
1268 const StreamParams& sp) const { 1217 const StreamParams& sp) const {
1269 uint32 ssrc = sp.first_ssrc(); 1218 uint32 ssrc = sp.first_ssrc();
1270 1219
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after
2773 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2722 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2774 } 2723 }
2775 } 2724 }
2776 2725
2777 return video_codecs; 2726 return video_codecs;
2778 } 2727 }
2779 2728
2780 } // namespace cricket 2729 } // namespace cricket
2781 2730
2782 #endif // HAVE_WEBRTC_VIDEO 2731 #endif // HAVE_WEBRTC_VIDEO
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698