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 |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 RTC_DCHECK(!initialized_); | 427 RTC_DCHECK(!initialized_); |
428 external_decoder_factory_ = decoder_factory; | 428 external_decoder_factory_ = decoder_factory; |
429 } | 429 } |
430 | 430 |
431 void WebRtcVideoEngine::SetExternalEncoderFactory( | 431 void WebRtcVideoEngine::SetExternalEncoderFactory( |
432 WebRtcVideoEncoderFactory* encoder_factory) { | 432 WebRtcVideoEncoderFactory* encoder_factory) { |
433 RTC_DCHECK(!initialized_); | 433 RTC_DCHECK(!initialized_); |
434 encoder_factory_.reset(new CricketEncoderFactoryAdapter(encoder_factory)); | 434 encoder_factory_.reset(new CricketEncoderFactoryAdapter(encoder_factory)); |
435 } | 435 } |
436 | 436 |
437 // This is a helper function for AppendVideoCodecs below. It will return the | 437 // This function will assign dynamic payload types (in the range [96, 127]) to |
438 // first unused dynamic payload type (in the range [96, 127]), or nothing if no | 438 // the input codecs, and also add associated RTX codecs for recognized codecs |
439 // payload type is unused. | 439 // (VP8, VP9, H264, and RED). It will also add default feedback params to the |
440 static rtc::Optional<int> NextFreePayloadType( | 440 // codecs. |
441 const std::vector<VideoCodec>& codecs) { | 441 static std::vector<VideoCodec> AssignPayloadTypesAndAddAssociatedRtxCodecs( |
| 442 const std::vector<VideoCodec>& input_codecs) { |
442 static const int kFirstDynamicPayloadType = 96; | 443 static const int kFirstDynamicPayloadType = 96; |
443 static const int kLastDynamicPayloadType = 127; | 444 static const int kLastDynamicPayloadType = 127; |
444 bool is_payload_used[1 + kLastDynamicPayloadType - kFirstDynamicPayloadType] = | 445 int payload_type = kFirstDynamicPayloadType; |
445 {false}; | 446 std::vector<VideoCodec> output_codecs; |
446 for (const VideoCodec& codec : codecs) { | 447 for (VideoCodec codec : input_codecs) { |
447 if (kFirstDynamicPayloadType <= codec.id && | 448 codec.id = payload_type; |
448 codec.id <= kLastDynamicPayloadType) { | 449 if (codec.name != kRedCodecName && codec.name != kUlpfecCodecName && |
449 is_payload_used[codec.id - kFirstDynamicPayloadType] = true; | 450 codec.name != kFlexfecCodecName) { |
| 451 AddDefaultFeedbackParams(&codec); |
450 } | 452 } |
451 } | 453 output_codecs.push_back(codec); |
452 for (int i = kFirstDynamicPayloadType; i <= kLastDynamicPayloadType; ++i) { | |
453 if (!is_payload_used[i - kFirstDynamicPayloadType]) | |
454 return rtc::Optional<int>(i); | |
455 } | |
456 // No free payload type. | |
457 return rtc::Optional<int>(); | |
458 } | |
459 | 454 |
460 // This is a helper function for GetSupportedCodecs below. It will append new | 455 // Increment payload type. |
461 // unique codecs from |input_codecs| to |unified_codecs|. It will add default | 456 ++payload_type; |
462 // feedback params to the codecs and will also add an associated RTX codec for | 457 if (payload_type > kLastDynamicPayloadType) |
463 // recognized codecs (VP8, VP9, H264, and RED). | 458 break; |
464 static void AppendVideoCodecs(const std::vector<VideoCodec>& input_codecs, | |
465 std::vector<VideoCodec>* unified_codecs) { | |
466 for (VideoCodec codec : input_codecs) { | |
467 const rtc::Optional<int> payload_type = | |
468 NextFreePayloadType(*unified_codecs); | |
469 if (!payload_type) | |
470 return; | |
471 codec.id = *payload_type; | |
472 // TODO(magjed): Move the responsibility of setting these parameters to the | |
473 // encoder factories instead. | |
474 if (codec.name != kRedCodecName && codec.name != kUlpfecCodecName && | |
475 codec.name != kFlexfecCodecName) | |
476 AddDefaultFeedbackParams(&codec); | |
477 // Don't add same codec twice. | |
478 if (FindMatchingCodec(*unified_codecs, codec)) | |
479 continue; | |
480 | |
481 unified_codecs->push_back(codec); | |
482 | 459 |
483 // Add associated RTX codec for recognized codecs. | 460 // Add associated RTX codec for recognized codecs. |
484 // TODO(deadbeef): Should we add RTX codecs for external codecs whose names | 461 // TODO(deadbeef): Should we add RTX codecs for external codecs whose names |
485 // we don't recognize? | 462 // we don't recognize? |
486 if (CodecNamesEq(codec.name, kVp8CodecName) || | 463 if (CodecNamesEq(codec.name, kVp8CodecName) || |
487 CodecNamesEq(codec.name, kVp9CodecName) || | 464 CodecNamesEq(codec.name, kVp9CodecName) || |
488 CodecNamesEq(codec.name, kH264CodecName) || | 465 CodecNamesEq(codec.name, kH264CodecName) || |
489 CodecNamesEq(codec.name, kRedCodecName)) { | 466 CodecNamesEq(codec.name, kRedCodecName)) { |
490 const rtc::Optional<int> rtx_payload_type = | 467 output_codecs.push_back( |
491 NextFreePayloadType(*unified_codecs); | 468 VideoCodec::CreateRtxCodec(payload_type, codec.id)); |
492 if (!rtx_payload_type) | 469 |
493 return; | 470 // Increment payload type. |
494 unified_codecs->push_back( | 471 ++payload_type; |
495 VideoCodec::CreateRtxCodec(*rtx_payload_type, codec.id)); | 472 if (payload_type > kLastDynamicPayloadType) |
| 473 break; |
496 } | 474 } |
497 } | 475 } |
| 476 return output_codecs; |
498 } | 477 } |
499 | 478 |
500 std::vector<VideoCodec> CricketEncoderFactoryAdapter::GetSupportedCodecs() | 479 std::vector<VideoCodec> CricketEncoderFactoryAdapter::GetSupportedCodecs() |
501 const { | 480 const { |
502 const std::vector<VideoCodec> internal_codecs = | 481 std::vector<VideoCodec> codecs = InternalEncoderFactory().supported_codecs(); |
503 InternalEncoderFactory().supported_codecs(); | |
504 LOG(LS_INFO) << "Internally supported codecs: " | 482 LOG(LS_INFO) << "Internally supported codecs: " |
505 << CodecVectorToString(internal_codecs); | 483 << CodecVectorToString(codecs); |
506 | 484 |
507 std::vector<VideoCodec> unified_codecs; | 485 // Add external codecs. |
508 AppendVideoCodecs(internal_codecs, &unified_codecs); | |
509 | |
510 if (external_encoder_factory_ != nullptr) { | 486 if (external_encoder_factory_ != nullptr) { |
511 const std::vector<VideoCodec>& external_codecs = | 487 const std::vector<VideoCodec>& external_codecs = |
512 external_encoder_factory_->supported_codecs(); | 488 external_encoder_factory_->supported_codecs(); |
513 AppendVideoCodecs(external_codecs, &unified_codecs); | 489 for (const VideoCodec& codec : external_codecs) { |
| 490 // Don't add same codec twice. |
| 491 if (!FindMatchingCodec(codecs, codec)) |
| 492 codecs.push_back(codec); |
| 493 } |
514 LOG(LS_INFO) << "Codecs supported by the external encoder factory: " | 494 LOG(LS_INFO) << "Codecs supported by the external encoder factory: " |
515 << CodecVectorToString(external_codecs); | 495 << CodecVectorToString(external_codecs); |
516 } | 496 } |
517 | 497 |
518 return unified_codecs; | 498 return AssignPayloadTypesAndAddAssociatedRtxCodecs(codecs); |
519 } | 499 } |
520 | 500 |
521 WebRtcVideoChannel::WebRtcVideoChannel( | 501 WebRtcVideoChannel::WebRtcVideoChannel( |
522 webrtc::Call* call, | 502 webrtc::Call* call, |
523 const MediaConfig& config, | 503 const MediaConfig& config, |
524 const VideoOptions& options, | 504 const VideoOptions& options, |
525 const EncoderFactoryAdapter& encoder_factory, | 505 const EncoderFactoryAdapter& encoder_factory, |
526 WebRtcVideoDecoderFactory* external_decoder_factory) | 506 WebRtcVideoDecoderFactory* external_decoder_factory) |
527 : VideoMediaChannel(config), | 507 : VideoMediaChannel(config), |
528 call_(call), | 508 call_(call), |
(...skipping 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2628 stream.temporal_layer_thresholds_bps.resize(GetDefaultVp9TemporalLayers() - | 2608 stream.temporal_layer_thresholds_bps.resize(GetDefaultVp9TemporalLayers() - |
2629 1); | 2609 1); |
2630 } | 2610 } |
2631 | 2611 |
2632 std::vector<webrtc::VideoStream> streams; | 2612 std::vector<webrtc::VideoStream> streams; |
2633 streams.push_back(stream); | 2613 streams.push_back(stream); |
2634 return streams; | 2614 return streams; |
2635 } | 2615 } |
2636 | 2616 |
2637 } // namespace cricket | 2617 } // namespace cricket |
OLD | NEW |