blob: c6122d3f6ac3056ebcc654e1c268923f6057a738 [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 {
Erik Språng4da317f2022-05-17 13:51:01 +020034 return (numberOfTemporalLayers == other.numberOfTemporalLayers &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010035 denoisingOn == other.denoisingOn &&
36 automaticResizeOn == other.automaticResizeOn &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010037 keyFrameInterval == other.keyFrameInterval);
38}
39
40bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
Erik Språng4da317f2022-05-17 13:51:01 +020041 return (numberOfTemporalLayers == other.numberOfTemporalLayers &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010042 denoisingOn == other.denoisingOn &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010043 keyFrameInterval == other.keyFrameInterval &&
44 adaptiveQpMode == other.adaptiveQpMode &&
45 automaticResizeOn == other.automaticResizeOn &&
46 numberOfSpatialLayers == other.numberOfSpatialLayers &&
47 flexibleMode == other.flexibleMode);
48}
49
50bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
Niels Möllerbe2fb412022-05-17 15:39:41 +020051 return (keyFrameInterval == other.keyFrameInterval &&
Rasmus Brandt70c961f2019-04-11 13:26:25 +020052 numberOfTemporalLayers == other.numberOfTemporalLayers);
Niels Möllerdef1ef52018-03-19 13:48:44 +010053}
54
hta257dc392016-10-25 09:05:06 -070055VideoCodec::VideoCodec()
Kári Tristan Helgason84ccb2d2018-08-16 14:35:26 +020056 : codecType(kVideoCodecGeneric),
hta257dc392016-10-25 09:05:06 -070057 width(0),
58 height(0),
59 startBitrate(0),
60 maxBitrate(0),
61 minBitrate(0),
hta257dc392016-10-25 09:05:06 -070062 maxFramerate(0),
Seth Hampsonf6464c92018-01-17 13:55:14 -080063 active(true),
hta257dc392016-10-25 09:05:06 -070064 qpMax(0),
65 numberOfSimulcastStreams(0),
66 simulcastStream(),
67 spatialLayers(),
Niels Möllere3cf3d02018-06-13 11:52:16 +020068 mode(VideoCodecMode::kRealtimeVideo),
Erik Språng08127a92016-11-16 16:41:30 +010069 expect_encode_from_texture(false),
ilnik04f4d122017-06-19 07:18:55 -070070 timing_frame_thresholds({0, 0}),
Florent Castellid3511012020-08-04 11:40:23 +020071 legacy_conference_mode(false),
Erik Språng4da317f2022-05-17 13:51:01 +020072 codec_specific_(),
73 complexity_(VideoCodecComplexity::kComplexityNormal) {}
hta257dc392016-10-25 09:05:06 -070074
75VideoCodecVP8* VideoCodec::VP8() {
76 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080077 return &codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070078}
79
80const VideoCodecVP8& VideoCodec::VP8() const {
81 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080082 return codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070083}
84
85VideoCodecVP9* VideoCodec::VP9() {
86 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080087 return &codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -070088}
89
90const VideoCodecVP9& VideoCodec::VP9() const {
91 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080092 return codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -070093}
94
95VideoCodecH264* VideoCodec::H264() {
96 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -080097 return &codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -070098}
99
100const VideoCodecH264& VideoCodec::H264() const {
101 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800102 return codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700103}
104
kthelgason1cdddc92017-08-24 03:52:48 -0700105const char* CodecTypeToPayloadString(VideoCodecType type) {
Erik Språng08127a92016-11-16 16:41:30 +0100106 switch (type) {
107 case kVideoCodecVP8:
kthelgason1cdddc92017-08-24 03:52:48 -0700108 return kPayloadNameVp8;
Erik Språng08127a92016-11-16 16:41:30 +0100109 case kVideoCodecVP9:
kthelgason1cdddc92017-08-24 03:52:48 -0700110 return kPayloadNameVp9;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100111 case kVideoCodecAV1:
112 return kPayloadNameAv1;
Erik Språng08127a92016-11-16 16:41:30 +0100113 case kVideoCodecH264:
kthelgason1cdddc92017-08-24 03:52:48 -0700114 return kPayloadNameH264;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100115 case kVideoCodecMultiplex:
116 return kPayloadNameMultiplex;
117 case kVideoCodecGeneric:
kthelgason1cdddc92017-08-24 03:52:48 -0700118 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100119 }
Karl Wibergc95b9392020-11-08 00:49:37 +0100120 RTC_CHECK_NOTREACHED();
Erik Språng08127a92016-11-16 16:41:30 +0100121}
122
kthelgason1cdddc92017-08-24 03:52:48 -0700123VideoCodecType PayloadStringToCodecType(const std::string& name) {
Niels Möller039743e2018-10-23 10:07:25 +0200124 if (absl::EqualsIgnoreCase(name, kPayloadNameVp8))
kthelgason1cdddc92017-08-24 03:52:48 -0700125 return kVideoCodecVP8;
Niels Möller039743e2018-10-23 10:07:25 +0200126 if (absl::EqualsIgnoreCase(name, kPayloadNameVp9))
kthelgason1cdddc92017-08-24 03:52:48 -0700127 return kVideoCodecVP9;
Sergey Silkin6b19d822021-09-09 15:09:11 +0200128 if (absl::EqualsIgnoreCase(name, kPayloadNameAv1) ||
129 absl::EqualsIgnoreCase(name, kPayloadNameAv1x))
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100130 return kVideoCodecAV1;
Niels Möller039743e2018-10-23 10:07:25 +0200131 if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
kthelgason1cdddc92017-08-24 03:52:48 -0700132 return kVideoCodecH264;
Niels Möller039743e2018-10-23 10:07:25 +0200133 if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800134 return kVideoCodecMultiplex;
kthelgason1cdddc92017-08-24 03:52:48 -0700135 return kVideoCodecGeneric;
136}
137
“Michael3147e292022-02-19 16:48:50 -0600138VideoCodecComplexity VideoCodec::GetVideoEncoderComplexity() const {
Erik Språng4da317f2022-05-17 13:51:01 +0200139 return complexity_;
“Michael3147e292022-02-19 16:48:50 -0600140}
141
142void VideoCodec::SetVideoEncoderComplexity(
143 VideoCodecComplexity complexity_setting) {
144 complexity_ = complexity_setting;
145}
146
Niels Möller807328f2022-05-12 16:16:39 +0200147bool VideoCodec::GetFrameDropEnabled() const {
Niels Möllerbe2fb412022-05-17 15:39:41 +0200148 return frame_drop_enabled_;
Niels Möller807328f2022-05-12 16:16:39 +0200149}
150
151void VideoCodec::SetFrameDropEnabled(bool enabled) {
152 frame_drop_enabled_ = enabled;
153}
154
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000155} // namespace webrtc