Chromium Code Reviews| 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 |
| 11 #include "webrtc/media/engine/webrtcvideoengine2.h" | 11 #include "webrtc/media/engine/webrtcvideoengine2.h" |
| 12 | 12 |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 #include <set> | 15 #include <set> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <utility> | 17 #include <utility> |
| 18 | 18 |
| 19 #include "webrtc/base/copyonwritebuffer.h" | 19 #include "webrtc/base/copyonwritebuffer.h" |
| 20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/base/stringutils.h" | 21 #include "webrtc/base/stringutils.h" |
| 22 #include "webrtc/base/timeutils.h" | 22 #include "webrtc/base/timeutils.h" |
| 23 #include "webrtc/base/trace_event.h" | 23 #include "webrtc/base/trace_event.h" |
| 24 #include "webrtc/call.h" | 24 #include "webrtc/call.h" |
| 25 #include "webrtc/media/engine/constants.h" | 25 #include "webrtc/media/engine/constants.h" |
| 26 #include "webrtc/media/engine/internalencoderfactory.h" | |
| 26 #include "webrtc/media/engine/simulcast.h" | 27 #include "webrtc/media/engine/simulcast.h" |
| 27 #include "webrtc/media/engine/videoencodersoftwarefallbackwrapper.h" | 28 #include "webrtc/media/engine/videoencodersoftwarefallbackwrapper.h" |
| 28 #include "webrtc/media/engine/webrtcmediaengine.h" | 29 #include "webrtc/media/engine/webrtcmediaengine.h" |
| 29 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" | 30 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" |
| 30 #include "webrtc/media/engine/webrtcvoiceengine.h" | 31 #include "webrtc/media/engine/webrtcvoiceengine.h" |
| 31 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" | |
| 32 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" | 32 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" |
| 33 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" | |
| 34 #include "webrtc/system_wrappers/include/field_trial.h" | 33 #include "webrtc/system_wrappers/include/field_trial.h" |
| 35 #include "webrtc/video_decoder.h" | 34 #include "webrtc/video_decoder.h" |
| 36 #include "webrtc/video_encoder.h" | 35 #include "webrtc/video_encoder.h" |
| 37 | 36 |
| 38 namespace cricket { | 37 namespace cricket { |
| 39 namespace { | 38 namespace { |
| 40 | 39 |
| 41 // Wrap cricket::WebRtcVideoEncoderFactory as a webrtc::VideoEncoderFactory. | 40 // Wrap cricket::WebRtcVideoEncoderFactory as a webrtc::VideoEncoderFactory. |
| 42 class EncoderFactoryAdapter : public webrtc::VideoEncoderFactory { | 41 class EncoderFactoryAdapter : public webrtc::VideoEncoderFactory { |
| 43 public: | 42 public: |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 | 161 |
| 163 void AddDefaultFeedbackParams(VideoCodec* codec) { | 162 void AddDefaultFeedbackParams(VideoCodec* codec) { |
| 164 codec->AddFeedbackParam(FeedbackParam(kRtcpFbParamCcm, kRtcpFbCcmParamFir)); | 163 codec->AddFeedbackParam(FeedbackParam(kRtcpFbParamCcm, kRtcpFbCcmParamFir)); |
| 165 codec->AddFeedbackParam(FeedbackParam(kRtcpFbParamNack, kParamValueEmpty)); | 164 codec->AddFeedbackParam(FeedbackParam(kRtcpFbParamNack, kParamValueEmpty)); |
| 166 codec->AddFeedbackParam(FeedbackParam(kRtcpFbParamNack, kRtcpFbNackParamPli)); | 165 codec->AddFeedbackParam(FeedbackParam(kRtcpFbParamNack, kRtcpFbNackParamPli)); |
| 167 codec->AddFeedbackParam(FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty)); | 166 codec->AddFeedbackParam(FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty)); |
| 168 codec->AddFeedbackParam( | 167 codec->AddFeedbackParam( |
| 169 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); | 168 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); |
| 170 } | 169 } |
| 171 | 170 |
| 172 static VideoCodec MakeVideoCodecWithDefaultFeedbackParams(int payload_type, | |
| 173 const char* name) { | |
| 174 VideoCodec codec(payload_type, name); | |
| 175 AddDefaultFeedbackParams(&codec); | |
| 176 return codec; | |
| 177 } | |
| 178 | |
| 179 static std::string CodecVectorToString(const std::vector<VideoCodec>& codecs) { | 171 static std::string CodecVectorToString(const std::vector<VideoCodec>& codecs) { |
| 180 std::stringstream out; | 172 std::stringstream out; |
| 181 out << '{'; | 173 out << '{'; |
| 182 for (size_t i = 0; i < codecs.size(); ++i) { | 174 for (size_t i = 0; i < codecs.size(); ++i) { |
| 183 out << codecs[i].ToString(); | 175 out << codecs[i].ToString(); |
| 184 if (i != codecs.size() - 1) { | 176 if (i != codecs.size() - 1) { |
| 185 out << ", "; | 177 out << ", "; |
| 186 } | 178 } |
| 187 } | 179 } |
| 188 out << '}'; | 180 out << '}'; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 // duration hasn't been implemented. | 376 // duration hasn't been implemented. |
| 385 static const int kNackHistoryMs = 1000; | 377 static const int kNackHistoryMs = 1000; |
| 386 | 378 |
| 387 static const int kDefaultQpMax = 56; | 379 static const int kDefaultQpMax = 56; |
| 388 | 380 |
| 389 static const int kDefaultRtcpReceiverReportSsrc = 1; | 381 static const int kDefaultRtcpReceiverReportSsrc = 1; |
| 390 | 382 |
| 391 // Minimum time interval for logging stats. | 383 // Minimum time interval for logging stats. |
| 392 static const int64_t kStatsLogIntervalMs = 10000; | 384 static const int64_t kStatsLogIntervalMs = 10000; |
| 393 | 385 |
| 394 // Adds |codec| to |list|, and also adds an RTX codec if |codec|'s name is | |
| 395 // recognized. | |
| 396 // TODO(deadbeef): Should we add RTX codecs for external codecs whose names we | |
| 397 // don't recognize? | |
| 398 void AddCodecAndMaybeRtxCodec(const VideoCodec& codec, | |
| 399 std::vector<VideoCodec>* codecs) { | |
| 400 codecs->push_back(codec); | |
| 401 int rtx_payload_type = 0; | |
| 402 if (CodecNamesEq(codec.name, kVp8CodecName)) { | |
| 403 rtx_payload_type = kDefaultRtxVp8PlType; | |
| 404 } else if (CodecNamesEq(codec.name, kVp9CodecName)) { | |
| 405 rtx_payload_type = kDefaultRtxVp9PlType; | |
| 406 } else if (CodecNamesEq(codec.name, kH264CodecName)) { | |
| 407 rtx_payload_type = kDefaultRtxH264PlType; | |
| 408 } else if (CodecNamesEq(codec.name, kRedCodecName)) { | |
| 409 rtx_payload_type = kDefaultRtxRedPlType; | |
| 410 } else { | |
| 411 return; | |
| 412 } | |
| 413 codecs->push_back(VideoCodec::CreateRtxCodec(rtx_payload_type, codec.id)); | |
| 414 } | |
| 415 | |
| 416 std::vector<VideoCodec> DefaultVideoCodecList() { | |
| 417 std::vector<VideoCodec> codecs; | |
| 418 AddCodecAndMaybeRtxCodec( | |
| 419 MakeVideoCodecWithDefaultFeedbackParams(kDefaultVp8PlType, kVp8CodecName), | |
| 420 &codecs); | |
| 421 if (webrtc::VP9Encoder::IsSupported() && webrtc::VP9Decoder::IsSupported()) { | |
| 422 AddCodecAndMaybeRtxCodec(MakeVideoCodecWithDefaultFeedbackParams( | |
| 423 kDefaultVp9PlType, kVp9CodecName), | |
| 424 &codecs); | |
| 425 } | |
| 426 if (webrtc::H264Encoder::IsSupported() && | |
| 427 webrtc::H264Decoder::IsSupported()) { | |
| 428 VideoCodec codec = MakeVideoCodecWithDefaultFeedbackParams( | |
| 429 kDefaultH264PlType, kH264CodecName); | |
| 430 // TODO(hta): Move all parameter generation for SDP into the codec | |
| 431 // implementation, for all codecs and parameters. | |
| 432 // TODO(hta): Move selection of profile-level-id to H.264 codec | |
| 433 // implementation. | |
| 434 // TODO(hta): Set FMTP parameters for all codecs of type H264. | |
| 435 codec.SetParam(kH264FmtpProfileLevelId, | |
| 436 kH264ProfileLevelConstrainedBaseline); | |
| 437 codec.SetParam(kH264FmtpLevelAsymmetryAllowed, "1"); | |
| 438 codec.SetParam(kH264FmtpPacketizationMode, "1"); | |
| 439 AddCodecAndMaybeRtxCodec(codec, &codecs); | |
| 440 } | |
| 441 AddCodecAndMaybeRtxCodec(VideoCodec(kDefaultRedPlType, kRedCodecName), | |
| 442 &codecs); | |
| 443 codecs.push_back(VideoCodec(kDefaultUlpfecType, kUlpfecCodecName)); | |
| 444 return codecs; | |
| 445 } | |
| 446 | |
| 447 static std::vector<VideoCodec> GetSupportedCodecs( | 386 static std::vector<VideoCodec> GetSupportedCodecs( |
| 448 const WebRtcVideoEncoderFactory* external_encoder_factory); | 387 const WebRtcVideoEncoderFactory* external_encoder_factory); |
| 449 | 388 |
| 450 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> | 389 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> |
| 451 WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( | 390 WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( |
| 452 const VideoCodec& codec) { | 391 const VideoCodec& codec) { |
| 453 RTC_DCHECK_RUN_ON(&thread_checker_); | 392 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 454 bool is_screencast = parameters_.options.is_screencast.value_or(false); | 393 bool is_screencast = parameters_.options.is_screencast.value_or(false); |
| 455 // No automatic resizing when using simulcast or screencast. | 394 // No automatic resizing when using simulcast or screencast. |
| 456 bool automatic_resize = | 395 bool automatic_resize = |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 encoder_factory->supported_codecs())) { | 551 encoder_factory->supported_codecs())) { |
| 613 simulcast_encoder_factory_.reset( | 552 simulcast_encoder_factory_.reset( |
| 614 new WebRtcSimulcastEncoderFactory(encoder_factory)); | 553 new WebRtcSimulcastEncoderFactory(encoder_factory)); |
| 615 encoder_factory = simulcast_encoder_factory_.get(); | 554 encoder_factory = simulcast_encoder_factory_.get(); |
| 616 } | 555 } |
| 617 external_encoder_factory_ = encoder_factory; | 556 external_encoder_factory_ = encoder_factory; |
| 618 | 557 |
| 619 video_codecs_ = GetSupportedCodecs(encoder_factory); | 558 video_codecs_ = GetSupportedCodecs(encoder_factory); |
| 620 } | 559 } |
| 621 | 560 |
| 561 // This is a helper function for AppendVideoCodecs below. It will return the | |
| 562 // first unused dynamic payload type (in the range [96, 127]), or nothing if no | |
| 563 // payload type is unused. | |
| 564 static rtc::Optional<int> NextFreePayloadType( | |
| 565 const std::vector<VideoCodec>& codecs) { | |
| 566 static const int kFirstDynamicPayloadType = 96; | |
| 567 static const int kLastDynamicPayloadType = 127; | |
| 568 bool is_payload_used[1 + kLastDynamicPayloadType - kFirstDynamicPayloadType] = | |
| 569 {false}; | |
| 570 for (const VideoCodec& codec : codecs) { | |
| 571 if (kFirstDynamicPayloadType <= codec.id && | |
| 572 codec.id <= kLastDynamicPayloadType) { | |
| 573 is_payload_used[codec.id - kFirstDynamicPayloadType] = true; | |
| 574 } | |
| 575 } | |
| 576 for (int i = kFirstDynamicPayloadType; i <= kLastDynamicPayloadType; ++i) { | |
| 577 if (!is_payload_used[i - kFirstDynamicPayloadType]) | |
| 578 return rtc::Optional<int>(i); | |
| 579 } | |
| 580 // No free payload type. | |
| 581 return rtc::Optional<int>(); | |
|
hta-webrtc
2016/11/15 20:36:24
Yep, I prefer this version. It's obviously correct
| |
| 582 } | |
| 583 | |
| 584 // This is a helper function for GetSupportedCodecs below. It will append new | |
| 585 // unique codecs from |input_codecs| to |unified_codecs|. It will add default | |
| 586 // feedback params to the codecs and will also add an associated RTX codec for | |
| 587 // recognized codecs (VP8, VP9, H264, and Red). | |
| 588 static void AppendVideoCodecs(const std::vector<VideoCodec>& input_codecs, | |
| 589 std::vector<VideoCodec>* unified_codecs) { | |
| 590 for (VideoCodec codec : input_codecs) { | |
| 591 const rtc::Optional<int> payload_type = | |
| 592 NextFreePayloadType(*unified_codecs); | |
| 593 if (!payload_type) | |
| 594 return; | |
| 595 codec.id = *payload_type; | |
| 596 // TODO(magjed): Move the responsibility of setting these parameters to the | |
| 597 // encoder factories instead. | |
| 598 if (codec.name != kRedCodecName && codec.name != kUlpfecCodecName) | |
| 599 AddDefaultFeedbackParams(&codec); | |
| 600 // Don't add same codec twice. | |
| 601 if (FindMatchingCodec(*unified_codecs, codec)) | |
| 602 continue; | |
| 603 | |
| 604 unified_codecs->push_back(codec); | |
| 605 | |
| 606 // Add associated RTX codec for recognized codecs. | |
| 607 // TODO(deadbeef): Should we add RTX codecs for external codecs whose names | |
| 608 // we don't recognize? | |
| 609 if (CodecNamesEq(codec.name, kVp8CodecName) || | |
| 610 CodecNamesEq(codec.name, kVp9CodecName) || | |
| 611 CodecNamesEq(codec.name, kH264CodecName) || | |
| 612 CodecNamesEq(codec.name, kRedCodecName)) { | |
| 613 const rtc::Optional<int> rtx_payload_type = | |
| 614 NextFreePayloadType(*unified_codecs); | |
| 615 if (!rtx_payload_type) | |
| 616 return; | |
| 617 unified_codecs->push_back( | |
| 618 VideoCodec::CreateRtxCodec(*rtx_payload_type, codec.id)); | |
| 619 } | |
| 620 } | |
| 621 } | |
| 622 | |
| 622 static std::vector<VideoCodec> GetSupportedCodecs( | 623 static std::vector<VideoCodec> GetSupportedCodecs( |
| 623 const WebRtcVideoEncoderFactory* external_encoder_factory) { | 624 const WebRtcVideoEncoderFactory* external_encoder_factory) { |
| 624 std::vector<VideoCodec> supported_codecs = DefaultVideoCodecList(); | 625 const std::vector<VideoCodec>& internal_codecs = |
| 626 InternalEncoderFactory::GetInstance().supported_codecs(); | |
| 627 LOG(LS_INFO) << "Internally supported codecs: " | |
| 628 << CodecVectorToString(internal_codecs); | |
| 625 | 629 |
| 626 if (external_encoder_factory == nullptr) { | 630 std::vector<VideoCodec> unified_codecs; |
| 627 LOG(LS_INFO) << "Supported codecs: " | 631 AppendVideoCodecs(internal_codecs, &unified_codecs); |
| 628 << CodecVectorToString(supported_codecs); | 632 |
| 629 return supported_codecs; | 633 if (external_encoder_factory != nullptr) { |
| 634 const std::vector<VideoCodec>& external_codecs = | |
| 635 external_encoder_factory->supported_codecs(); | |
| 636 AppendVideoCodecs(external_codecs, &unified_codecs); | |
| 637 LOG(LS_INFO) << "Codecs supported by the external encoder factory: " | |
| 638 << CodecVectorToString(external_codecs); | |
| 630 } | 639 } |
| 631 | 640 |
| 632 std::stringstream out; | 641 return unified_codecs; |
| 633 const std::vector<VideoCodec>& codecs = | |
| 634 external_encoder_factory->supported_codecs(); | |
| 635 for (size_t i = 0; i < codecs.size(); ++i) { | |
| 636 VideoCodec codec = codecs[i]; | |
| 637 out << codec.name; | |
| 638 if (i != codecs.size() - 1) { | |
| 639 out << ", "; | |
| 640 } | |
| 641 // Don't add internally-supported codecs twice. | |
| 642 if (FindMatchingCodec(supported_codecs, codec)) | |
| 643 continue; | |
| 644 | |
| 645 // External video encoders are given payloads 120-127. This also means that | |
| 646 // we only support up to 8 external payload types. | |
| 647 // TODO(deadbeef): mediasession.cc already has code to dynamically | |
| 648 // determine a payload type. We should be able to just leave the payload | |
| 649 // type empty and let mediasession determine it. However, currently RTX | |
| 650 // codecs are associated to codecs by payload type, meaning we DO need | |
| 651 // to allocate unique payload types here. So to make this change we would | |
| 652 // need to make RTX codecs associated by name instead. | |
| 653 const int kExternalVideoPayloadTypeBase = 120; | |
| 654 size_t payload_type = kExternalVideoPayloadTypeBase + i; | |
| 655 RTC_DCHECK(payload_type < 128); | |
| 656 codec.id = payload_type; | |
| 657 | |
| 658 AddDefaultFeedbackParams(&codec); | |
| 659 AddCodecAndMaybeRtxCodec(codec, &supported_codecs); | |
| 660 } | |
| 661 LOG(LS_INFO) << "Supported codecs (incl. external codecs): " | |
| 662 << CodecVectorToString(supported_codecs); | |
| 663 LOG(LS_INFO) << "Codecs supported by the external encoder factory: " | |
| 664 << out.str(); | |
| 665 return supported_codecs; | |
| 666 } | 642 } |
| 667 | 643 |
| 668 WebRtcVideoChannel2::WebRtcVideoChannel2( | 644 WebRtcVideoChannel2::WebRtcVideoChannel2( |
| 669 webrtc::Call* call, | 645 webrtc::Call* call, |
| 670 const MediaConfig& config, | 646 const MediaConfig& config, |
| 671 const VideoOptions& options, | 647 const VideoOptions& options, |
| 672 WebRtcVideoEncoderFactory* external_encoder_factory, | 648 WebRtcVideoEncoderFactory* external_encoder_factory, |
| 673 WebRtcVideoDecoderFactory* external_decoder_factory) | 649 WebRtcVideoDecoderFactory* external_decoder_factory) |
| 674 : VideoMediaChannel(config), | 650 : VideoMediaChannel(config), |
| 675 call_(call), | 651 call_(call), |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1533 int max_bitrate_bps, | 1509 int max_bitrate_bps, |
| 1534 const rtc::Optional<VideoCodecSettings>& codec_settings) | 1510 const rtc::Optional<VideoCodecSettings>& codec_settings) |
| 1535 : config(std::move(config)), | 1511 : config(std::move(config)), |
| 1536 options(options), | 1512 options(options), |
| 1537 max_bitrate_bps(max_bitrate_bps), | 1513 max_bitrate_bps(max_bitrate_bps), |
| 1538 conference_mode(false), | 1514 conference_mode(false), |
| 1539 codec_settings(codec_settings) {} | 1515 codec_settings(codec_settings) {} |
| 1540 | 1516 |
| 1541 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder( | 1517 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder::AllocatedEncoder( |
| 1542 webrtc::VideoEncoder* encoder, | 1518 webrtc::VideoEncoder* encoder, |
| 1543 webrtc::VideoCodecType type, | 1519 const cricket::VideoCodec& codec, |
| 1544 bool external) | 1520 bool external) |
| 1545 : encoder(encoder), | 1521 : encoder(encoder), |
| 1546 external_encoder(nullptr), | 1522 external_encoder(nullptr), |
| 1547 type(type), | 1523 codec(codec), |
| 1548 external(external) { | 1524 external(external) { |
| 1549 if (external) { | 1525 if (external) { |
| 1550 external_encoder = encoder; | 1526 external_encoder = encoder; |
| 1551 this->encoder = | 1527 this->encoder = |
| 1552 new webrtc::VideoEncoderSoftwareFallbackWrapper(type, encoder); | 1528 new webrtc::VideoEncoderSoftwareFallbackWrapper(codec, encoder); |
| 1553 } | 1529 } |
| 1554 } | 1530 } |
| 1555 | 1531 |
| 1556 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( | 1532 WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |
| 1557 webrtc::Call* call, | 1533 webrtc::Call* call, |
| 1558 const StreamParams& sp, | 1534 const StreamParams& sp, |
| 1559 webrtc::VideoSendStream::Config config, | 1535 webrtc::VideoSendStream::Config config, |
| 1560 const VideoOptions& options, | 1536 const VideoOptions& options, |
| 1561 WebRtcVideoEncoderFactory* external_encoder_factory, | 1537 WebRtcVideoEncoderFactory* external_encoder_factory, |
| 1562 bool enable_cpu_overuse_detection, | 1538 bool enable_cpu_overuse_detection, |
| 1563 int max_bitrate_bps, | 1539 int max_bitrate_bps, |
| 1564 const rtc::Optional<VideoCodecSettings>& codec_settings, | 1540 const rtc::Optional<VideoCodecSettings>& codec_settings, |
| 1565 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions, | 1541 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions, |
| 1566 // TODO(deadbeef): Don't duplicate information between send_params, | 1542 // TODO(deadbeef): Don't duplicate information between send_params, |
| 1567 // rtp_extensions, options, etc. | 1543 // rtp_extensions, options, etc. |
| 1568 const VideoSendParameters& send_params) | 1544 const VideoSendParameters& send_params) |
| 1569 : worker_thread_(rtc::Thread::Current()), | 1545 : worker_thread_(rtc::Thread::Current()), |
| 1570 ssrcs_(sp.ssrcs), | 1546 ssrcs_(sp.ssrcs), |
| 1571 ssrc_groups_(sp.ssrc_groups), | 1547 ssrc_groups_(sp.ssrc_groups), |
| 1572 call_(call), | 1548 call_(call), |
| 1573 enable_cpu_overuse_detection_(enable_cpu_overuse_detection), | 1549 enable_cpu_overuse_detection_(enable_cpu_overuse_detection), |
| 1574 source_(nullptr), | 1550 source_(nullptr), |
| 1575 external_encoder_factory_(external_encoder_factory), | 1551 external_encoder_factory_(external_encoder_factory), |
| 1576 stream_(nullptr), | 1552 stream_(nullptr), |
| 1577 encoder_sink_(nullptr), | 1553 encoder_sink_(nullptr), |
| 1578 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), | 1554 parameters_(std::move(config), options, max_bitrate_bps, codec_settings), |
| 1579 rtp_parameters_(CreateRtpParametersWithOneEncoding()), | 1555 rtp_parameters_(CreateRtpParametersWithOneEncoding()), |
| 1580 allocated_encoder_(nullptr, webrtc::kVideoCodecUnknown, false), | 1556 allocated_encoder_(nullptr, cricket::VideoCodec(), false), |
| 1581 sending_(false), | 1557 sending_(false), |
| 1582 last_frame_timestamp_us_(0) { | 1558 last_frame_timestamp_us_(0) { |
| 1583 parameters_.config.rtp.max_packet_size = kVideoMtu; | 1559 parameters_.config.rtp.max_packet_size = kVideoMtu; |
| 1584 parameters_.conference_mode = send_params.conference_mode; | 1560 parameters_.conference_mode = send_params.conference_mode; |
| 1585 | 1561 |
| 1586 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); | 1562 sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
| 1587 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, | 1563 sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
| 1588 ¶meters_.config.rtp.rtx.ssrcs); | 1564 ¶meters_.config.rtp.rtx.ssrcs); |
| 1589 parameters_.config.rtp.c_name = sp.cname; | 1565 parameters_.config.rtp.c_name = sp.cname; |
| 1590 if (rtp_extensions) { | 1566 if (rtp_extensions) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1705 | 1681 |
| 1706 const std::vector<uint32_t>& | 1682 const std::vector<uint32_t>& |
| 1707 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { | 1683 WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
| 1708 return ssrcs_; | 1684 return ssrcs_; |
| 1709 } | 1685 } |
| 1710 | 1686 |
| 1711 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder | 1687 WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder |
| 1712 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoder( | 1688 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoder( |
| 1713 const VideoCodec& codec) { | 1689 const VideoCodec& codec) { |
| 1714 RTC_DCHECK_RUN_ON(&thread_checker_); | 1690 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 1715 webrtc::VideoCodecType type = CodecTypeFromName(codec.name); | |
| 1716 | |
| 1717 // Do not re-create encoders of the same type. | 1691 // Do not re-create encoders of the same type. |
| 1718 if (type == allocated_encoder_.type && allocated_encoder_.encoder != NULL) { | 1692 if (codec == allocated_encoder_.codec && |
| 1693 allocated_encoder_.encoder != nullptr) { | |
| 1719 return allocated_encoder_; | 1694 return allocated_encoder_; |
| 1720 } | 1695 } |
| 1721 | 1696 |
| 1722 if (external_encoder_factory_ != NULL) { | 1697 // Try creating external encoder. |
| 1698 if (external_encoder_factory_ != nullptr && | |
| 1699 FindMatchingCodec(external_encoder_factory_->supported_codecs(), codec)) { | |
| 1723 webrtc::VideoEncoder* encoder = | 1700 webrtc::VideoEncoder* encoder = |
| 1724 external_encoder_factory_->CreateVideoEncoder(codec); | 1701 external_encoder_factory_->CreateVideoEncoder(codec); |
| 1725 if (encoder != NULL) { | 1702 if (encoder != nullptr) |
| 1726 return AllocatedEncoder(encoder, type, true); | 1703 return AllocatedEncoder(encoder, codec, true /* is_external */); |
| 1727 } | |
| 1728 } | 1704 } |
| 1729 | 1705 |
| 1730 if (type == webrtc::kVideoCodecVP8) { | 1706 // Try creating internal encoder. |
| 1731 return AllocatedEncoder( | 1707 WebRtcVideoEncoderFactory& internal_encoder_factory = |
| 1732 webrtc::VideoEncoder::Create(webrtc::VideoEncoder::kVp8), type, false); | 1708 InternalEncoderFactory::GetInstance(); |
| 1733 } else if (type == webrtc::kVideoCodecVP9) { | 1709 if (FindMatchingCodec(internal_encoder_factory.supported_codecs(), codec)) { |
| 1734 return AllocatedEncoder( | 1710 return AllocatedEncoder(internal_encoder_factory.CreateVideoEncoder(codec), |
| 1735 webrtc::VideoEncoder::Create(webrtc::VideoEncoder::kVp9), type, false); | 1711 codec, false /* is_external */); |
| 1736 } else if (type == webrtc::kVideoCodecH264) { | |
| 1737 return AllocatedEncoder( | |
| 1738 webrtc::VideoEncoder::Create(webrtc::VideoEncoder::kH264), type, false); | |
| 1739 } | 1712 } |
| 1740 | 1713 |
| 1741 // This shouldn't happen, we should not be trying to create something we don't | 1714 // This shouldn't happen, we should not be trying to create something we don't |
| 1742 // support. | 1715 // support. |
| 1743 RTC_DCHECK(false); | 1716 RTC_DCHECK(false); |
| 1744 return AllocatedEncoder(NULL, webrtc::kVideoCodecUnknown, false); | 1717 return AllocatedEncoder(NULL, cricket::VideoCodec(), false); |
| 1745 } | 1718 } |
| 1746 | 1719 |
| 1747 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( | 1720 void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( |
| 1748 AllocatedEncoder* encoder) { | 1721 AllocatedEncoder* encoder) { |
| 1749 RTC_DCHECK_RUN_ON(&thread_checker_); | 1722 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 1750 if (encoder->external) { | 1723 if (encoder->external) { |
| 1751 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); | 1724 external_encoder_factory_->DestroyVideoEncoder(encoder->external_encoder); |
| 1752 } | 1725 } |
| 1753 delete encoder->encoder; | 1726 delete encoder->encoder; |
| 1754 } | 1727 } |
| (...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2575 rtx_mapping[video_codecs[i].codec.id] != | 2548 rtx_mapping[video_codecs[i].codec.id] != |
| 2576 ulpfec_config.red_payload_type) { | 2549 ulpfec_config.red_payload_type) { |
| 2577 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2550 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
| 2578 } | 2551 } |
| 2579 } | 2552 } |
| 2580 | 2553 |
| 2581 return video_codecs; | 2554 return video_codecs; |
| 2582 } | 2555 } |
| 2583 | 2556 |
| 2584 } // namespace cricket | 2557 } // namespace cricket |
| OLD | NEW |