Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 10 | #include "api/video_codecs/video_encoder_config.h" |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 11 | |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 12 | #include <string> |
| 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/checks.h" |
Jonas Olsson | 0a713b6 | 2018-04-04 15:49:32 +0200 | [diff] [blame] | 15 | #include "rtc_base/strings/string_builder.h" |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | VideoStream::VideoStream() |
| 19 | : width(0), |
| 20 | height(0), |
| 21 | max_framerate(-1), |
| 22 | min_bitrate_bps(-1), |
| 23 | target_bitrate_bps(-1), |
| 24 | max_bitrate_bps(-1), |
Florent Castelli | c1a0bcb | 2019-01-29 14:26:48 +0100 | [diff] [blame] | 25 | scale_resolution_down_by(-1.), |
Seth Hampson | dfe9ffc | 2018-01-08 11:41:14 -0800 | [diff] [blame] | 26 | max_qp(-1), |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 27 | num_temporal_layers(absl::nullopt), |
Seth Hampson | dfe9ffc | 2018-01-08 11:41:14 -0800 | [diff] [blame] | 28 | active(true) {} |
Seth Hampson | 36193c3 | 2017-12-14 11:41:18 -0800 | [diff] [blame] | 29 | VideoStream::VideoStream(const VideoStream& other) = default; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 30 | |
| 31 | VideoStream::~VideoStream() = default; |
| 32 | |
| 33 | std::string VideoStream::ToString() const { |
Jonas Olsson | 0a713b6 | 2018-04-04 15:49:32 +0200 | [diff] [blame] | 34 | char buf[1024]; |
| 35 | rtc::SimpleStringBuilder ss(buf); |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 36 | ss << "{width: " << width; |
| 37 | ss << ", height: " << height; |
| 38 | ss << ", max_framerate: " << max_framerate; |
| 39 | ss << ", min_bitrate_bps:" << min_bitrate_bps; |
| 40 | ss << ", target_bitrate_bps:" << target_bitrate_bps; |
| 41 | ss << ", max_bitrate_bps:" << max_bitrate_bps; |
| 42 | ss << ", max_qp: " << max_qp; |
Rasmus Brandt | 43bfe0b | 2020-01-21 13:54:11 +0100 | [diff] [blame] | 43 | ss << ", num_temporal_layers: " << num_temporal_layers.value_or(1); |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 44 | ss << ", bitrate_priority: " << bitrate_priority.value_or(0); |
Seth Hampson | dfe9ffc | 2018-01-08 11:41:14 -0800 | [diff] [blame] | 45 | ss << ", active: " << active; |
Åsa Persson | c5a74ff | 2020-09-20 17:50:00 +0200 | [diff] [blame] | 46 | ss << ", scale_down_by: " << scale_resolution_down_by; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 47 | |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 48 | return ss.str(); |
| 49 | } |
| 50 | |
| 51 | VideoEncoderConfig::VideoEncoderConfig() |
Kári Tristan Helgason | 84ccb2d | 2018-08-16 14:35:26 +0200 | [diff] [blame] | 52 | : codec_type(kVideoCodecGeneric), |
Niels Möller | 6dfc8d6 | 2018-04-17 12:51:59 +0200 | [diff] [blame] | 53 | video_format("Unset"), |
Niels Möller | 24a842a | 2018-03-22 08:52:50 +0100 | [diff] [blame] | 54 | content_type(ContentType::kRealtimeVideo), |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 55 | encoder_specific_settings(nullptr), |
| 56 | min_transmit_bitrate_bps(0), |
| 57 | max_bitrate_bps(0), |
Seth Hampson | f32795e | 2017-12-19 11:37:41 -0800 | [diff] [blame] | 58 | bitrate_priority(1.0), |
Florent Castelli | d351101 | 2020-08-04 11:40:23 +0200 | [diff] [blame] | 59 | number_of_streams(0), |
Sergey Silkin | d19e3b9 | 2021-03-16 10:05:30 +0000 | [diff] [blame^] | 60 | legacy_conference_mode(false), |
| 61 | is_quality_scaling_allowed(false) {} |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 62 | |
| 63 | VideoEncoderConfig::VideoEncoderConfig(VideoEncoderConfig&&) = default; |
| 64 | |
| 65 | VideoEncoderConfig::~VideoEncoderConfig() = default; |
| 66 | |
| 67 | std::string VideoEncoderConfig::ToString() const { |
Jonas Olsson | 0a713b6 | 2018-04-04 15:49:32 +0200 | [diff] [blame] | 68 | char buf[1024]; |
| 69 | rtc::SimpleStringBuilder ss(buf); |
Niels Möller | 24a842a | 2018-03-22 08:52:50 +0100 | [diff] [blame] | 70 | ss << "{codec_type: "; |
| 71 | ss << CodecTypeToPayloadString(codec_type); |
| 72 | ss << ", content_type: "; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 73 | switch (content_type) { |
| 74 | case ContentType::kRealtimeVideo: |
| 75 | ss << "kRealtimeVideo"; |
| 76 | break; |
| 77 | case ContentType::kScreen: |
| 78 | ss << "kScreenshare"; |
| 79 | break; |
| 80 | } |
| 81 | ss << ", encoder_specific_settings: "; |
| 82 | ss << (encoder_specific_settings != NULL ? "(ptr)" : "NULL"); |
| 83 | |
| 84 | ss << ", min_transmit_bitrate_bps: " << min_transmit_bitrate_bps; |
| 85 | ss << '}'; |
| 86 | return ss.str(); |
| 87 | } |
| 88 | |
| 89 | VideoEncoderConfig::VideoEncoderConfig(const VideoEncoderConfig&) = default; |
| 90 | |
| 91 | void VideoEncoderConfig::EncoderSpecificSettings::FillEncoderSpecificSettings( |
| 92 | VideoCodec* codec) const { |
| 93 | if (codec->codecType == kVideoCodecH264) { |
| 94 | FillVideoCodecH264(codec->H264()); |
| 95 | } else if (codec->codecType == kVideoCodecVP8) { |
| 96 | FillVideoCodecVp8(codec->VP8()); |
| 97 | } else if (codec->codecType == kVideoCodecVP9) { |
| 98 | FillVideoCodecVp9(codec->VP9()); |
| 99 | } else { |
| 100 | RTC_NOTREACHED() << "Encoder specifics set/used for unknown codec type."; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH264( |
| 105 | VideoCodecH264* h264_settings) const { |
| 106 | RTC_NOTREACHED(); |
| 107 | } |
| 108 | |
| 109 | void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp8( |
| 110 | VideoCodecVP8* vp8_settings) const { |
| 111 | RTC_NOTREACHED(); |
| 112 | } |
| 113 | |
| 114 | void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp9( |
| 115 | VideoCodecVP9* vp9_settings) const { |
| 116 | RTC_NOTREACHED(); |
| 117 | } |
| 118 | |
| 119 | VideoEncoderConfig::H264EncoderSpecificSettings::H264EncoderSpecificSettings( |
| 120 | const VideoCodecH264& specifics) |
| 121 | : specifics_(specifics) {} |
| 122 | |
| 123 | void VideoEncoderConfig::H264EncoderSpecificSettings::FillVideoCodecH264( |
| 124 | VideoCodecH264* h264_settings) const { |
| 125 | *h264_settings = specifics_; |
| 126 | } |
| 127 | |
| 128 | VideoEncoderConfig::Vp8EncoderSpecificSettings::Vp8EncoderSpecificSettings( |
| 129 | const VideoCodecVP8& specifics) |
| 130 | : specifics_(specifics) {} |
| 131 | |
| 132 | void VideoEncoderConfig::Vp8EncoderSpecificSettings::FillVideoCodecVp8( |
| 133 | VideoCodecVP8* vp8_settings) const { |
| 134 | *vp8_settings = specifics_; |
| 135 | } |
| 136 | |
| 137 | VideoEncoderConfig::Vp9EncoderSpecificSettings::Vp9EncoderSpecificSettings( |
| 138 | const VideoCodecVP9& specifics) |
| 139 | : specifics_(specifics) {} |
| 140 | |
| 141 | void VideoEncoderConfig::Vp9EncoderSpecificSettings::FillVideoCodecVp9( |
| 142 | VideoCodecVP9* vp9_settings) const { |
| 143 | *vp9_settings = specifics_; |
| 144 | } |
| 145 | |
| 146 | } // namespace webrtc |