blob: a8a660622d15b0b914f6684ea1c206263e663eaa [file] [log] [blame]
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:221/*
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
Mirko Bonadei71207422017-09-15 11:58:0911#include "common_types.h" // NOLINT(build/include)
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:2212
13#include <string.h>
eladalond0244c22017-06-08 11:19:1314#include <algorithm>
danilchapef8d7732017-04-19 09:59:4815#include <limits>
16#include <type_traits>
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:2217
Mirko Bonadei92ea95e2017-09-15 04:47:3118#include "rtc_base/checks.h"
Erik Språngbb60a3a2018-03-19 17:25:1019#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "rtc_base/stringutils.h"
magjed10165ab2016-11-22 18:16:5721
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:2222namespace webrtc {
23
Niels Möllerdef1ef52018-03-19 12:48:4424bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
Niels Möllerdef1ef52018-03-19 12:48:4425 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 12:48:4426 numberOfTemporalLayers == other.numberOfTemporalLayers &&
27 denoisingOn == other.denoisingOn &&
28 automaticResizeOn == other.automaticResizeOn &&
29 frameDroppingOn == other.frameDroppingOn &&
30 keyFrameInterval == other.keyFrameInterval);
31}
32
33bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
34 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 12:48:4435 numberOfTemporalLayers == other.numberOfTemporalLayers &&
36 denoisingOn == other.denoisingOn &&
37 frameDroppingOn == other.frameDroppingOn &&
38 keyFrameInterval == other.keyFrameInterval &&
39 adaptiveQpMode == other.adaptiveQpMode &&
40 automaticResizeOn == other.automaticResizeOn &&
41 numberOfSpatialLayers == other.numberOfSpatialLayers &&
42 flexibleMode == other.flexibleMode);
43}
44
45bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
46 return (frameDroppingOn == other.frameDroppingOn &&
47 keyFrameInterval == other.keyFrameInterval &&
48 spsLen == other.spsLen &&
49 ppsLen == other.ppsLen &&
50 profile == other.profile &&
51 (spsLen == 0 || memcmp(spsData, other.spsData, spsLen) == 0) &&
52 (ppsLen == 0 || memcmp(ppsData, other.ppsData, ppsLen) == 0));
53}
54
55bool SpatialLayer::operator==(const SpatialLayer& other) const {
56 return (width == other.width &&
57 height == other.height &&
58 numberOfTemporalLayers == other.numberOfTemporalLayers &&
59 maxBitrate == other.maxBitrate &&
60 targetBitrate == other.targetBitrate &&
61 minBitrate == other.minBitrate &&
62 qpMax == other.qpMax &&
63 active == other.active);
64}
65
hta257dc392016-10-25 16:05:0666VideoCodec::VideoCodec()
67 : codecType(kVideoCodecUnknown),
hta257dc392016-10-25 16:05:0668 plType(0),
69 width(0),
70 height(0),
71 startBitrate(0),
72 maxBitrate(0),
73 minBitrate(0),
74 targetBitrate(0),
75 maxFramerate(0),
Seth Hampsonf6464c92018-01-17 21:55:1476 active(true),
hta257dc392016-10-25 16:05:0677 qpMax(0),
78 numberOfSimulcastStreams(0),
79 simulcastStream(),
80 spatialLayers(),
81 mode(kRealtimeVideo),
Erik Språng08127a92016-11-16 15:41:3082 expect_encode_from_texture(false),
ilnik04f4d122017-06-19 14:18:5583 timing_frame_thresholds({0, 0}),
hta527d3472016-11-17 07:23:0484 codec_specific_() {}
hta257dc392016-10-25 16:05:0685
86VideoCodecVP8* VideoCodec::VP8() {
87 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-17 07:23:0488 return &codec_specific_.VP8;
hta257dc392016-10-25 16:05:0689}
90
91const VideoCodecVP8& VideoCodec::VP8() const {
92 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-17 07:23:0493 return codec_specific_.VP8;
hta257dc392016-10-25 16:05:0694}
95
96VideoCodecVP9* VideoCodec::VP9() {
97 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-17 07:23:0498 return &codec_specific_.VP9;
hta257dc392016-10-25 16:05:0699}
100
101const VideoCodecVP9& VideoCodec::VP9() const {
102 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-17 07:23:04103 return codec_specific_.VP9;
hta257dc392016-10-25 16:05:06104}
105
106VideoCodecH264* VideoCodec::H264() {
107 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-17 07:23:04108 return &codec_specific_.H264;
hta257dc392016-10-25 16:05:06109}
110
111const VideoCodecH264& VideoCodec::H264() const {
112 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-17 07:23:04113 return codec_specific_.H264;
hta257dc392016-10-25 16:05:06114}
115
Erik Språng08127a92016-11-16 15:41:30116static const char* kPayloadNameVp8 = "VP8";
117static const char* kPayloadNameVp9 = "VP9";
118static const char* kPayloadNameH264 = "H264";
119static const char* kPayloadNameI420 = "I420";
120static const char* kPayloadNameRED = "RED";
121static const char* kPayloadNameULPFEC = "ULPFEC";
Danil Chapovalov3c706972018-01-30 10:11:08122static const char* kPayloadNameFlexfec = "flexfec-03";
Erik Språng08127a92016-11-16 15:41:30123static const char* kPayloadNameGeneric = "Generic";
Emircan Uysalerd7ae3c32018-01-25 21:01:09124static const char* kPayloadNameMultiplex = "Multiplex";
Erik Språng08127a92016-11-16 15:41:30125
magjed10165ab2016-11-22 18:16:57126static bool CodecNamesEq(const char* name1, const char* name2) {
127 return _stricmp(name1, name2) == 0;
128}
129
kthelgason1cdddc92017-08-24 10:52:48130const char* CodecTypeToPayloadString(VideoCodecType type) {
Erik Språng08127a92016-11-16 15:41:30131 switch (type) {
132 case kVideoCodecVP8:
kthelgason1cdddc92017-08-24 10:52:48133 return kPayloadNameVp8;
Erik Språng08127a92016-11-16 15:41:30134 case kVideoCodecVP9:
kthelgason1cdddc92017-08-24 10:52:48135 return kPayloadNameVp9;
Erik Språng08127a92016-11-16 15:41:30136 case kVideoCodecH264:
kthelgason1cdddc92017-08-24 10:52:48137 return kPayloadNameH264;
Erik Språng08127a92016-11-16 15:41:30138 case kVideoCodecI420:
kthelgason1cdddc92017-08-24 10:52:48139 return kPayloadNameI420;
Erik Språng08127a92016-11-16 15:41:30140 case kVideoCodecRED:
kthelgason1cdddc92017-08-24 10:52:48141 return kPayloadNameRED;
Erik Språng08127a92016-11-16 15:41:30142 case kVideoCodecULPFEC:
kthelgason1cdddc92017-08-24 10:52:48143 return kPayloadNameULPFEC;
Danil Chapovalov3c706972018-01-30 10:11:08144 case kVideoCodecFlexfec:
145 return kPayloadNameFlexfec;
Emircan Uysaler0a375472017-12-11 06:51:02146 // Other codecs default to generic.
Emircan Uysalerd7ae3c32018-01-25 21:01:09147 case kVideoCodecMultiplex:
Emircan Uysaler0a375472017-12-11 06:51:02148 case kVideoCodecGeneric:
149 case kVideoCodecUnknown:
kthelgason1cdddc92017-08-24 10:52:48150 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 15:41:30151 }
Emircan Uysaler0a375472017-12-11 06:51:02152 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 15:41:30153}
154
kthelgason1cdddc92017-08-24 10:52:48155VideoCodecType PayloadStringToCodecType(const std::string& name) {
magjed10165ab2016-11-22 18:16:57156 if (CodecNamesEq(name.c_str(), kPayloadNameVp8))
kthelgason1cdddc92017-08-24 10:52:48157 return kVideoCodecVP8;
magjed10165ab2016-11-22 18:16:57158 if (CodecNamesEq(name.c_str(), kPayloadNameVp9))
kthelgason1cdddc92017-08-24 10:52:48159 return kVideoCodecVP9;
magjed10165ab2016-11-22 18:16:57160 if (CodecNamesEq(name.c_str(), kPayloadNameH264))
kthelgason1cdddc92017-08-24 10:52:48161 return kVideoCodecH264;
magjed10165ab2016-11-22 18:16:57162 if (CodecNamesEq(name.c_str(), kPayloadNameI420))
kthelgason1cdddc92017-08-24 10:52:48163 return kVideoCodecI420;
magjed10165ab2016-11-22 18:16:57164 if (CodecNamesEq(name.c_str(), kPayloadNameRED))
kthelgason1cdddc92017-08-24 10:52:48165 return kVideoCodecRED;
magjed10165ab2016-11-22 18:16:57166 if (CodecNamesEq(name.c_str(), kPayloadNameULPFEC))
kthelgason1cdddc92017-08-24 10:52:48167 return kVideoCodecULPFEC;
Danil Chapovalov3c706972018-01-30 10:11:08168 if (CodecNamesEq(name.c_str(), kPayloadNameFlexfec))
169 return kVideoCodecFlexfec;
Emircan Uysalerd7ae3c32018-01-25 21:01:09170 if (CodecNamesEq(name.c_str(), kPayloadNameMultiplex))
171 return kVideoCodecMultiplex;
kthelgason1cdddc92017-08-24 10:52:48172 return kVideoCodecGeneric;
173}
174
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22175} // namespace webrtc