blob: d05eb456fce7d8a234a660e639b5e52d11ce2df8 [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";
24// TODO(bugs.webrtc.org/11042): Rename to AV1 when rtp payload format for av1 is
25// frozen.
26constexpr char kPayloadNameAv1[] = "AV1X";
27constexpr char kPayloadNameH264[] = "H264";
28constexpr char kPayloadNameGeneric[] = "Generic";
29constexpr char kPayloadNameMultiplex[] = "Multiplex";
30} // namespace
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000031
Niels Möllerdef1ef52018-03-19 13:48:44 +010032bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
Niels Möllerdef1ef52018-03-19 13:48:44 +010033 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010034 numberOfTemporalLayers == other.numberOfTemporalLayers &&
35 denoisingOn == other.denoisingOn &&
36 automaticResizeOn == other.automaticResizeOn &&
37 frameDroppingOn == other.frameDroppingOn &&
38 keyFrameInterval == other.keyFrameInterval);
39}
40
41bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
42 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010043 numberOfTemporalLayers == other.numberOfTemporalLayers &&
44 denoisingOn == other.denoisingOn &&
45 frameDroppingOn == other.frameDroppingOn &&
46 keyFrameInterval == other.keyFrameInterval &&
47 adaptiveQpMode == other.adaptiveQpMode &&
48 automaticResizeOn == other.automaticResizeOn &&
49 numberOfSpatialLayers == other.numberOfSpatialLayers &&
50 flexibleMode == other.flexibleMode);
51}
52
53bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
54 return (frameDroppingOn == other.frameDroppingOn &&
55 keyFrameInterval == other.keyFrameInterval &&
Rasmus Brandt70c961f2019-04-11 13:26:25 +020056 numberOfTemporalLayers == other.numberOfTemporalLayers);
Niels Möllerdef1ef52018-03-19 13:48:44 +010057}
58
hta257dc392016-10-25 09:05:06 -070059VideoCodec::VideoCodec()
Kári Tristan Helgason84ccb2d2018-08-16 14:35:26 +020060 : codecType(kVideoCodecGeneric),
hta257dc392016-10-25 09:05:06 -070061 width(0),
62 height(0),
63 startBitrate(0),
64 maxBitrate(0),
65 minBitrate(0),
hta257dc392016-10-25 09:05:06 -070066 maxFramerate(0),
Seth Hampsonf6464c92018-01-17 13:55:14 -080067 active(true),
hta257dc392016-10-25 09:05:06 -070068 qpMax(0),
69 numberOfSimulcastStreams(0),
70 simulcastStream(),
71 spatialLayers(),
Niels Möllere3cf3d02018-06-13 11:52:16 +020072 mode(VideoCodecMode::kRealtimeVideo),
Erik Språng08127a92016-11-16 16:41:30 +010073 expect_encode_from_texture(false),
ilnik04f4d122017-06-19 07:18:55 -070074 timing_frame_thresholds({0, 0}),
Florent Castellid3511012020-08-04 11:40:23 +020075 legacy_conference_mode(false),
hta527d3472016-11-16 23:23:04 -080076 codec_specific_() {}
hta257dc392016-10-25 09:05:06 -070077
78VideoCodecVP8* VideoCodec::VP8() {
79 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080080 return &codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070081}
82
83const VideoCodecVP8& VideoCodec::VP8() const {
84 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080085 return codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070086}
87
88VideoCodecVP9* VideoCodec::VP9() {
89 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080090 return &codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -070091}
92
93const VideoCodecVP9& VideoCodec::VP9() const {
94 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080095 return codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -070096}
97
98VideoCodecH264* VideoCodec::H264() {
99 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800100 return &codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700101}
102
103const VideoCodecH264& VideoCodec::H264() const {
104 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800105 return codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700106}
107
kthelgason1cdddc92017-08-24 03:52:48 -0700108const char* CodecTypeToPayloadString(VideoCodecType type) {
Erik Språng08127a92016-11-16 16:41:30 +0100109 switch (type) {
110 case kVideoCodecVP8:
kthelgason1cdddc92017-08-24 03:52:48 -0700111 return kPayloadNameVp8;
Erik Språng08127a92016-11-16 16:41:30 +0100112 case kVideoCodecVP9:
kthelgason1cdddc92017-08-24 03:52:48 -0700113 return kPayloadNameVp9;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100114 case kVideoCodecAV1:
115 return kPayloadNameAv1;
Erik Språng08127a92016-11-16 16:41:30 +0100116 case kVideoCodecH264:
kthelgason1cdddc92017-08-24 03:52:48 -0700117 return kPayloadNameH264;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100118 case kVideoCodecMultiplex:
119 return kPayloadNameMultiplex;
120 case kVideoCodecGeneric:
kthelgason1cdddc92017-08-24 03:52:48 -0700121 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100122 }
Karl Wibergc95b9392020-11-08 00:49:37 +0100123 RTC_CHECK_NOTREACHED();
Erik Språng08127a92016-11-16 16:41:30 +0100124}
125
kthelgason1cdddc92017-08-24 03:52:48 -0700126VideoCodecType PayloadStringToCodecType(const std::string& name) {
Niels Möller039743e2018-10-23 10:07:25 +0200127 if (absl::EqualsIgnoreCase(name, kPayloadNameVp8))
kthelgason1cdddc92017-08-24 03:52:48 -0700128 return kVideoCodecVP8;
Niels Möller039743e2018-10-23 10:07:25 +0200129 if (absl::EqualsIgnoreCase(name, kPayloadNameVp9))
kthelgason1cdddc92017-08-24 03:52:48 -0700130 return kVideoCodecVP9;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100131 if (absl::EqualsIgnoreCase(name, kPayloadNameAv1))
132 return kVideoCodecAV1;
Niels Möller039743e2018-10-23 10:07:25 +0200133 if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
kthelgason1cdddc92017-08-24 03:52:48 -0700134 return kVideoCodecH264;
Niels Möller039743e2018-10-23 10:07:25 +0200135 if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800136 return kVideoCodecMultiplex;
kthelgason1cdddc92017-08-24 03:52:48 -0700137 return kVideoCodecGeneric;
138}
139
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000140} // namespace webrtc