blob: 75c89e6985fcb5620ffbe1b32cba3d6b65f5478c [file] [log] [blame]
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +00001/*
2 * Copyright (c) 2012 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 */
10
Niels Möllera46bd4b2018-06-08 14:03:44 +020011#include "api/video_codecs/video_codec.h"
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000012
13#include <string.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Niels Möllera46bd4b2018-06-08 14:03:44 +020015#include <string>
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000016
Niels Möller3c7d5992018-10-19 15:29:54 +020017#include "absl/strings/match.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/checks.h"
magjed10165ab2016-11-22 10:16:57 -080019
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000020namespace webrtc {
Danil Chapovalovb529b7a2019-11-27 13:59:41 +010021namespace {
22constexpr char kPayloadNameVp8[] = "VP8";
23constexpr char kPayloadNameVp9[] = "VP9";
Sergey Silkin6b19d822021-09-09 15:09:11 +020024constexpr char kPayloadNameAv1[] = "AV1";
Emil Lundmark7194d832021-10-29 17:15:11 +020025// TODO(bugs.webrtc.org/13166): Remove AV1X when backwards compatibility is not
26// needed.
Sergey Silkin6b19d822021-09-09 15:09:11 +020027constexpr char kPayloadNameAv1x[] = "AV1X";
Danil Chapovalovb529b7a2019-11-27 13:59:41 +010028constexpr char kPayloadNameH264[] = "H264";
29constexpr char kPayloadNameGeneric[] = "Generic";
30constexpr char kPayloadNameMultiplex[] = "Multiplex";
31} // namespace
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000032
Niels Möllerdef1ef52018-03-19 13:48:44 +010033bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
Niels Möllerdef1ef52018-03-19 13:48:44 +010034 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010035 numberOfTemporalLayers == other.numberOfTemporalLayers &&
36 denoisingOn == other.denoisingOn &&
37 automaticResizeOn == other.automaticResizeOn &&
38 frameDroppingOn == other.frameDroppingOn &&
39 keyFrameInterval == other.keyFrameInterval);
40}
41
42bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
43 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010044 numberOfTemporalLayers == other.numberOfTemporalLayers &&
45 denoisingOn == other.denoisingOn &&
46 frameDroppingOn == other.frameDroppingOn &&
47 keyFrameInterval == other.keyFrameInterval &&
48 adaptiveQpMode == other.adaptiveQpMode &&
49 automaticResizeOn == other.automaticResizeOn &&
50 numberOfSpatialLayers == other.numberOfSpatialLayers &&
51 flexibleMode == other.flexibleMode);
52}
53
54bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
55 return (frameDroppingOn == other.frameDroppingOn &&
56 keyFrameInterval == other.keyFrameInterval &&
Rasmus Brandt70c961f2019-04-11 13:26:25 +020057 numberOfTemporalLayers == other.numberOfTemporalLayers);
Niels Möllerdef1ef52018-03-19 13:48:44 +010058}
59
hta257dc392016-10-25 09:05:06 -070060VideoCodec::VideoCodec()
Kári Tristan Helgason84ccb2d2018-08-16 14:35:26 +020061 : codecType(kVideoCodecGeneric),
hta257dc392016-10-25 09:05:06 -070062 width(0),
63 height(0),
64 startBitrate(0),
65 maxBitrate(0),
66 minBitrate(0),
hta257dc392016-10-25 09:05:06 -070067 maxFramerate(0),
Seth Hampsonf6464c92018-01-17 13:55:14 -080068 active(true),
hta257dc392016-10-25 09:05:06 -070069 qpMax(0),
70 numberOfSimulcastStreams(0),
71 simulcastStream(),
72 spatialLayers(),
Niels Möllere3cf3d02018-06-13 11:52:16 +020073 mode(VideoCodecMode::kRealtimeVideo),
Erik Språng08127a92016-11-16 16:41:30 +010074 expect_encode_from_texture(false),
ilnik04f4d122017-06-19 07:18:55 -070075 timing_frame_thresholds({0, 0}),
Florent Castellid3511012020-08-04 11:40:23 +020076 legacy_conference_mode(false),
hta527d3472016-11-16 23:23:04 -080077 codec_specific_() {}
hta257dc392016-10-25 09:05:06 -070078
79VideoCodecVP8* VideoCodec::VP8() {
80 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080081 return &codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070082}
83
84const VideoCodecVP8& VideoCodec::VP8() const {
85 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080086 return codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070087}
88
89VideoCodecVP9* VideoCodec::VP9() {
90 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080091 return &codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -070092}
93
94const VideoCodecVP9& VideoCodec::VP9() const {
95 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080096 return codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -070097}
98
99VideoCodecH264* VideoCodec::H264() {
100 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800101 return &codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700102}
103
104const VideoCodecH264& VideoCodec::H264() const {
105 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800106 return codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700107}
108
kthelgason1cdddc92017-08-24 03:52:48 -0700109const char* CodecTypeToPayloadString(VideoCodecType type) {
Erik Språng08127a92016-11-16 16:41:30 +0100110 switch (type) {
111 case kVideoCodecVP8:
kthelgason1cdddc92017-08-24 03:52:48 -0700112 return kPayloadNameVp8;
Erik Språng08127a92016-11-16 16:41:30 +0100113 case kVideoCodecVP9:
kthelgason1cdddc92017-08-24 03:52:48 -0700114 return kPayloadNameVp9;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100115 case kVideoCodecAV1:
116 return kPayloadNameAv1;
Erik Språng08127a92016-11-16 16:41:30 +0100117 case kVideoCodecH264:
kthelgason1cdddc92017-08-24 03:52:48 -0700118 return kPayloadNameH264;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100119 case kVideoCodecMultiplex:
120 return kPayloadNameMultiplex;
121 case kVideoCodecGeneric:
kthelgason1cdddc92017-08-24 03:52:48 -0700122 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100123 }
Karl Wibergc95b9392020-11-08 00:49:37 +0100124 RTC_CHECK_NOTREACHED();
Erik Språng08127a92016-11-16 16:41:30 +0100125}
126
kthelgason1cdddc92017-08-24 03:52:48 -0700127VideoCodecType PayloadStringToCodecType(const std::string& name) {
Niels Möller039743e2018-10-23 10:07:25 +0200128 if (absl::EqualsIgnoreCase(name, kPayloadNameVp8))
kthelgason1cdddc92017-08-24 03:52:48 -0700129 return kVideoCodecVP8;
Niels Möller039743e2018-10-23 10:07:25 +0200130 if (absl::EqualsIgnoreCase(name, kPayloadNameVp9))
kthelgason1cdddc92017-08-24 03:52:48 -0700131 return kVideoCodecVP9;
Sergey Silkin6b19d822021-09-09 15:09:11 +0200132 if (absl::EqualsIgnoreCase(name, kPayloadNameAv1) ||
133 absl::EqualsIgnoreCase(name, kPayloadNameAv1x))
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100134 return kVideoCodecAV1;
Niels Möller039743e2018-10-23 10:07:25 +0200135 if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
kthelgason1cdddc92017-08-24 03:52:48 -0700136 return kVideoCodecH264;
Niels Möller039743e2018-10-23 10:07:25 +0200137 if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800138 return kVideoCodecMultiplex;
kthelgason1cdddc92017-08-24 03:52:48 -0700139 return kVideoCodecGeneric;
140}
141
“Michael3147e292022-02-19 16:48:50 -0600142VideoCodecComplexity VideoCodec::GetVideoEncoderComplexity() const {
143 if (complexity_.has_value()) {
144 return complexity_.value();
145 }
146 switch (codecType) {
147 case kVideoCodecVP8:
148 return VP8().complexity;
149 case kVideoCodecVP9:
150 return VP9().complexity;
151 default:
152 return VideoCodecComplexity::kComplexityNormal;
153 }
154}
155
156void VideoCodec::SetVideoEncoderComplexity(
157 VideoCodecComplexity complexity_setting) {
158 complexity_ = complexity_setting;
159}
160
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000161} // namespace webrtc