blob: 65c7243c0084211c81a120987febb07f22b9330f [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
59bool SpatialLayer::operator==(const SpatialLayer& other) const {
Yves Gerey665174f2018-06-19 15:03:05 +020060 return (width == other.width && height == other.height &&
Florent Castelli907dc802019-12-06 15:03:19 +010061 maxFramerate == other.maxFramerate &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010062 numberOfTemporalLayers == other.numberOfTemporalLayers &&
63 maxBitrate == other.maxBitrate &&
64 targetBitrate == other.targetBitrate &&
Yves Gerey665174f2018-06-19 15:03:05 +020065 minBitrate == other.minBitrate && qpMax == other.qpMax &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010066 active == other.active);
67}
68
hta257dc392016-10-25 09:05:06 -070069VideoCodec::VideoCodec()
Kári Tristan Helgason84ccb2d2018-08-16 14:35:26 +020070 : codecType(kVideoCodecGeneric),
hta257dc392016-10-25 09:05:06 -070071 plType(0),
72 width(0),
73 height(0),
74 startBitrate(0),
75 maxBitrate(0),
76 minBitrate(0),
hta257dc392016-10-25 09:05:06 -070077 maxFramerate(0),
Seth Hampsonf6464c92018-01-17 13:55:14 -080078 active(true),
hta257dc392016-10-25 09:05:06 -070079 qpMax(0),
80 numberOfSimulcastStreams(0),
81 simulcastStream(),
82 spatialLayers(),
Niels Möllere3cf3d02018-06-13 11:52:16 +020083 mode(VideoCodecMode::kRealtimeVideo),
Erik Språng08127a92016-11-16 16:41:30 +010084 expect_encode_from_texture(false),
ilnik04f4d122017-06-19 07:18:55 -070085 timing_frame_thresholds({0, 0}),
Florent Castellid3511012020-08-04 11:40:23 +020086 legacy_conference_mode(false),
hta527d3472016-11-16 23:23:04 -080087 codec_specific_() {}
hta257dc392016-10-25 09:05:06 -070088
89VideoCodecVP8* VideoCodec::VP8() {
90 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080091 return &codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070092}
93
94const VideoCodecVP8& VideoCodec::VP8() const {
95 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080096 return codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070097}
98
99VideoCodecVP9* VideoCodec::VP9() {
100 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -0800101 return &codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -0700102}
103
104const VideoCodecVP9& VideoCodec::VP9() const {
105 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -0800106 return codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -0700107}
108
109VideoCodecH264* VideoCodec::H264() {
110 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800111 return &codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700112}
113
114const VideoCodecH264& VideoCodec::H264() const {
115 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800116 return codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700117}
118
kthelgason1cdddc92017-08-24 03:52:48 -0700119const char* CodecTypeToPayloadString(VideoCodecType type) {
Erik Språng08127a92016-11-16 16:41:30 +0100120 switch (type) {
121 case kVideoCodecVP8:
kthelgason1cdddc92017-08-24 03:52:48 -0700122 return kPayloadNameVp8;
Erik Språng08127a92016-11-16 16:41:30 +0100123 case kVideoCodecVP9:
kthelgason1cdddc92017-08-24 03:52:48 -0700124 return kPayloadNameVp9;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100125 case kVideoCodecAV1:
126 return kPayloadNameAv1;
Erik Språng08127a92016-11-16 16:41:30 +0100127 case kVideoCodecH264:
kthelgason1cdddc92017-08-24 03:52:48 -0700128 return kPayloadNameH264;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100129 case kVideoCodecMultiplex:
130 return kPayloadNameMultiplex;
131 case kVideoCodecGeneric:
kthelgason1cdddc92017-08-24 03:52:48 -0700132 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100133 }
134}
135
kthelgason1cdddc92017-08-24 03:52:48 -0700136VideoCodecType PayloadStringToCodecType(const std::string& name) {
Niels Möller039743e2018-10-23 10:07:25 +0200137 if (absl::EqualsIgnoreCase(name, kPayloadNameVp8))
kthelgason1cdddc92017-08-24 03:52:48 -0700138 return kVideoCodecVP8;
Niels Möller039743e2018-10-23 10:07:25 +0200139 if (absl::EqualsIgnoreCase(name, kPayloadNameVp9))
kthelgason1cdddc92017-08-24 03:52:48 -0700140 return kVideoCodecVP9;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100141 if (absl::EqualsIgnoreCase(name, kPayloadNameAv1))
142 return kVideoCodecAV1;
Niels Möller039743e2018-10-23 10:07:25 +0200143 if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
kthelgason1cdddc92017-08-24 03:52:48 -0700144 return kVideoCodecH264;
Niels Möller039743e2018-10-23 10:07:25 +0200145 if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800146 return kVideoCodecMultiplex;
kthelgason1cdddc92017-08-24 03:52:48 -0700147 return kVideoCodecGeneric;
148}
149
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000150} // namespace webrtc