blob: a8a660622d15b0b914f6684ea1c206263e663eaa [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
Mirko Bonadei71207422017-09-15 13:58:09 +020011#include "common_types.h" // NOLINT(build/include)
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000012
13#include <string.h>
eladalond0244c22017-06-08 04:19:13 -070014#include <algorithm>
danilchapef8d7732017-04-19 02:59:48 -070015#include <limits>
16#include <type_traits>
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/checks.h"
Erik Språngbb60a3a2018-03-19 18:25:10 +010019#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_base/stringutils.h"
magjed10165ab2016-11-22 10:16:57 -080021
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000022namespace webrtc {
23
Niels Möllerdef1ef52018-03-19 13:48:44 +010024bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
Niels Möllerdef1ef52018-03-19 13:48:44 +010025 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010026 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 13:48:44 +010035 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 09:05:06 -070066VideoCodec::VideoCodec()
67 : codecType(kVideoCodecUnknown),
hta257dc392016-10-25 09:05:06 -070068 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 13:55:14 -080076 active(true),
hta257dc392016-10-25 09:05:06 -070077 qpMax(0),
78 numberOfSimulcastStreams(0),
79 simulcastStream(),
80 spatialLayers(),
81 mode(kRealtimeVideo),
Erik Språng08127a92016-11-16 16:41:30 +010082 expect_encode_from_texture(false),
ilnik04f4d122017-06-19 07:18:55 -070083 timing_frame_thresholds({0, 0}),
hta527d3472016-11-16 23:23:04 -080084 codec_specific_() {}
hta257dc392016-10-25 09:05:06 -070085
86VideoCodecVP8* VideoCodec::VP8() {
87 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080088 return &codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070089}
90
91const VideoCodecVP8& VideoCodec::VP8() const {
92 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080093 return codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070094}
95
96VideoCodecVP9* VideoCodec::VP9() {
97 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080098 return &codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -070099}
100
101const VideoCodecVP9& VideoCodec::VP9() const {
102 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -0800103 return codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -0700104}
105
106VideoCodecH264* VideoCodec::H264() {
107 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800108 return &codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700109}
110
111const VideoCodecH264& VideoCodec::H264() const {
112 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800113 return codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700114}
115
Erik Språng08127a92016-11-16 16:41:30 +0100116static 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 11:11:08 +0100122static const char* kPayloadNameFlexfec = "flexfec-03";
Erik Språng08127a92016-11-16 16:41:30 +0100123static const char* kPayloadNameGeneric = "Generic";
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800124static const char* kPayloadNameMultiplex = "Multiplex";
Erik Språng08127a92016-11-16 16:41:30 +0100125
magjed10165ab2016-11-22 10:16:57 -0800126static bool CodecNamesEq(const char* name1, const char* name2) {
127 return _stricmp(name1, name2) == 0;
128}
129
kthelgason1cdddc92017-08-24 03:52:48 -0700130const char* CodecTypeToPayloadString(VideoCodecType type) {
Erik Språng08127a92016-11-16 16:41:30 +0100131 switch (type) {
132 case kVideoCodecVP8:
kthelgason1cdddc92017-08-24 03:52:48 -0700133 return kPayloadNameVp8;
Erik Språng08127a92016-11-16 16:41:30 +0100134 case kVideoCodecVP9:
kthelgason1cdddc92017-08-24 03:52:48 -0700135 return kPayloadNameVp9;
Erik Språng08127a92016-11-16 16:41:30 +0100136 case kVideoCodecH264:
kthelgason1cdddc92017-08-24 03:52:48 -0700137 return kPayloadNameH264;
Erik Språng08127a92016-11-16 16:41:30 +0100138 case kVideoCodecI420:
kthelgason1cdddc92017-08-24 03:52:48 -0700139 return kPayloadNameI420;
Erik Språng08127a92016-11-16 16:41:30 +0100140 case kVideoCodecRED:
kthelgason1cdddc92017-08-24 03:52:48 -0700141 return kPayloadNameRED;
Erik Språng08127a92016-11-16 16:41:30 +0100142 case kVideoCodecULPFEC:
kthelgason1cdddc92017-08-24 03:52:48 -0700143 return kPayloadNameULPFEC;
Danil Chapovalov3c706972018-01-30 11:11:08 +0100144 case kVideoCodecFlexfec:
145 return kPayloadNameFlexfec;
Emircan Uysaler0a375472017-12-11 12:21:02 +0530146 // Other codecs default to generic.
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800147 case kVideoCodecMultiplex:
Emircan Uysaler0a375472017-12-11 12:21:02 +0530148 case kVideoCodecGeneric:
149 case kVideoCodecUnknown:
kthelgason1cdddc92017-08-24 03:52:48 -0700150 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100151 }
Emircan Uysaler0a375472017-12-11 12:21:02 +0530152 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100153}
154
kthelgason1cdddc92017-08-24 03:52:48 -0700155VideoCodecType PayloadStringToCodecType(const std::string& name) {
magjed10165ab2016-11-22 10:16:57 -0800156 if (CodecNamesEq(name.c_str(), kPayloadNameVp8))
kthelgason1cdddc92017-08-24 03:52:48 -0700157 return kVideoCodecVP8;
magjed10165ab2016-11-22 10:16:57 -0800158 if (CodecNamesEq(name.c_str(), kPayloadNameVp9))
kthelgason1cdddc92017-08-24 03:52:48 -0700159 return kVideoCodecVP9;
magjed10165ab2016-11-22 10:16:57 -0800160 if (CodecNamesEq(name.c_str(), kPayloadNameH264))
kthelgason1cdddc92017-08-24 03:52:48 -0700161 return kVideoCodecH264;
magjed10165ab2016-11-22 10:16:57 -0800162 if (CodecNamesEq(name.c_str(), kPayloadNameI420))
kthelgason1cdddc92017-08-24 03:52:48 -0700163 return kVideoCodecI420;
magjed10165ab2016-11-22 10:16:57 -0800164 if (CodecNamesEq(name.c_str(), kPayloadNameRED))
kthelgason1cdddc92017-08-24 03:52:48 -0700165 return kVideoCodecRED;
magjed10165ab2016-11-22 10:16:57 -0800166 if (CodecNamesEq(name.c_str(), kPayloadNameULPFEC))
kthelgason1cdddc92017-08-24 03:52:48 -0700167 return kVideoCodecULPFEC;
Danil Chapovalov3c706972018-01-30 11:11:08 +0100168 if (CodecNamesEq(name.c_str(), kPayloadNameFlexfec))
169 return kVideoCodecFlexfec;
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800170 if (CodecNamesEq(name.c_str(), kPayloadNameMultiplex))
171 return kVideoCodecMultiplex;
kthelgason1cdddc92017-08-24 03:52:48 -0700172 return kVideoCodecGeneric;
173}
174
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000175} // namespace webrtc