blob: a71024360192abc9d3239f8895964d61ea25a447 [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 &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010061 numberOfTemporalLayers == other.numberOfTemporalLayers &&
62 maxBitrate == other.maxBitrate &&
63 targetBitrate == other.targetBitrate &&
Yves Gerey665174f2018-06-19 15:03:05 +020064 minBitrate == other.minBitrate && qpMax == other.qpMax &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010065 active == other.active);
66}
67
hta257dc392016-10-25 09:05:06 -070068VideoCodec::VideoCodec()
Kári Tristan Helgason84ccb2d2018-08-16 14:35:26 +020069 : codecType(kVideoCodecGeneric),
hta257dc392016-10-25 09:05:06 -070070 plType(0),
71 width(0),
72 height(0),
73 startBitrate(0),
74 maxBitrate(0),
75 minBitrate(0),
hta257dc392016-10-25 09:05:06 -070076 maxFramerate(0),
Seth Hampsonf6464c92018-01-17 13:55:14 -080077 active(true),
hta257dc392016-10-25 09:05:06 -070078 qpMax(0),
79 numberOfSimulcastStreams(0),
80 simulcastStream(),
81 spatialLayers(),
Niels Möllere3cf3d02018-06-13 11:52:16 +020082 mode(VideoCodecMode::kRealtimeVideo),
Erik Språng08127a92016-11-16 16:41:30 +010083 expect_encode_from_texture(false),
ilnik04f4d122017-06-19 07:18:55 -070084 timing_frame_thresholds({0, 0}),
hta527d3472016-11-16 23:23:04 -080085 codec_specific_() {}
hta257dc392016-10-25 09:05:06 -070086
87VideoCodecVP8* VideoCodec::VP8() {
88 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080089 return &codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070090}
91
92const VideoCodecVP8& VideoCodec::VP8() const {
93 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080094 return codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070095}
96
97VideoCodecVP9* VideoCodec::VP9() {
98 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080099 return &codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -0700100}
101
102const VideoCodecVP9& VideoCodec::VP9() const {
103 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -0800104 return codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -0700105}
106
107VideoCodecH264* VideoCodec::H264() {
108 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800109 return &codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700110}
111
112const VideoCodecH264& VideoCodec::H264() const {
113 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800114 return codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700115}
116
kthelgason1cdddc92017-08-24 03:52:48 -0700117const char* CodecTypeToPayloadString(VideoCodecType type) {
Erik Språng08127a92016-11-16 16:41:30 +0100118 switch (type) {
119 case kVideoCodecVP8:
kthelgason1cdddc92017-08-24 03:52:48 -0700120 return kPayloadNameVp8;
Erik Språng08127a92016-11-16 16:41:30 +0100121 case kVideoCodecVP9:
kthelgason1cdddc92017-08-24 03:52:48 -0700122 return kPayloadNameVp9;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100123 case kVideoCodecAV1:
124 return kPayloadNameAv1;
Erik Språng08127a92016-11-16 16:41:30 +0100125 case kVideoCodecH264:
kthelgason1cdddc92017-08-24 03:52:48 -0700126 return kPayloadNameH264;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100127 case kVideoCodecMultiplex:
128 return kPayloadNameMultiplex;
129 case kVideoCodecGeneric:
kthelgason1cdddc92017-08-24 03:52:48 -0700130 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100131 }
132}
133
kthelgason1cdddc92017-08-24 03:52:48 -0700134VideoCodecType PayloadStringToCodecType(const std::string& name) {
Niels Möller039743e2018-10-23 10:07:25 +0200135 if (absl::EqualsIgnoreCase(name, kPayloadNameVp8))
kthelgason1cdddc92017-08-24 03:52:48 -0700136 return kVideoCodecVP8;
Niels Möller039743e2018-10-23 10:07:25 +0200137 if (absl::EqualsIgnoreCase(name, kPayloadNameVp9))
kthelgason1cdddc92017-08-24 03:52:48 -0700138 return kVideoCodecVP9;
Danil Chapovalovb529b7a2019-11-27 13:59:41 +0100139 if (absl::EqualsIgnoreCase(name, kPayloadNameAv1))
140 return kVideoCodecAV1;
Niels Möller039743e2018-10-23 10:07:25 +0200141 if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
kthelgason1cdddc92017-08-24 03:52:48 -0700142 return kVideoCodecH264;
Niels Möller039743e2018-10-23 10:07:25 +0200143 if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800144 return kVideoCodecMultiplex;
kthelgason1cdddc92017-08-24 03:52:48 -0700145 return kVideoCodecGeneric;
146}
147
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000148} // namespace webrtc