kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 11 | #include "common_types.h" // NOLINT(build/include) |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 12 | |
| 13 | #include <string.h> |
eladalon | d0244c2 | 2017-06-08 04:19:13 -0700 | [diff] [blame] | 14 | #include <algorithm> |
danilchap | ef8d773 | 2017-04-19 02:59:48 -0700 | [diff] [blame] | 15 | #include <limits> |
| 16 | #include <type_traits> |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 17 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "rtc_base/checks.h" |
Erik Språng | bb60a3a | 2018-03-19 18:25:10 +0100 | [diff] [blame] | 19 | #include "rtc_base/strings/string_builder.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "rtc_base/stringutils.h" |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 21 | |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 22 | namespace webrtc { |
| 23 | |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 24 | bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const { |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 25 | return (complexity == other.complexity && |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 26 | numberOfTemporalLayers == other.numberOfTemporalLayers && |
| 27 | denoisingOn == other.denoisingOn && |
| 28 | automaticResizeOn == other.automaticResizeOn && |
| 29 | frameDroppingOn == other.frameDroppingOn && |
| 30 | keyFrameInterval == other.keyFrameInterval); |
| 31 | } |
| 32 | |
| 33 | bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const { |
| 34 | return (complexity == other.complexity && |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 35 | 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 | |
| 45 | bool 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 | |
| 55 | bool 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 | |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 66 | VideoCodec::VideoCodec() |
| 67 | : codecType(kVideoCodecUnknown), |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 68 | plType(0), |
| 69 | width(0), |
| 70 | height(0), |
| 71 | startBitrate(0), |
| 72 | maxBitrate(0), |
| 73 | minBitrate(0), |
| 74 | targetBitrate(0), |
| 75 | maxFramerate(0), |
Seth Hampson | f6464c9 | 2018-01-17 13:55:14 -0800 | [diff] [blame] | 76 | active(true), |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 77 | qpMax(0), |
| 78 | numberOfSimulcastStreams(0), |
| 79 | simulcastStream(), |
| 80 | spatialLayers(), |
| 81 | mode(kRealtimeVideo), |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 82 | expect_encode_from_texture(false), |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 83 | timing_frame_thresholds({0, 0}), |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 84 | codec_specific_() {} |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 85 | |
| 86 | VideoCodecVP8* VideoCodec::VP8() { |
| 87 | RTC_DCHECK_EQ(codecType, kVideoCodecVP8); |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 88 | return &codec_specific_.VP8; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | const VideoCodecVP8& VideoCodec::VP8() const { |
| 92 | RTC_DCHECK_EQ(codecType, kVideoCodecVP8); |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 93 | return codec_specific_.VP8; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | VideoCodecVP9* VideoCodec::VP9() { |
| 97 | RTC_DCHECK_EQ(codecType, kVideoCodecVP9); |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 98 | return &codec_specific_.VP9; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | const VideoCodecVP9& VideoCodec::VP9() const { |
| 102 | RTC_DCHECK_EQ(codecType, kVideoCodecVP9); |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 103 | return codec_specific_.VP9; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | VideoCodecH264* VideoCodec::H264() { |
| 107 | RTC_DCHECK_EQ(codecType, kVideoCodecH264); |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 108 | return &codec_specific_.H264; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | const VideoCodecH264& VideoCodec::H264() const { |
| 112 | RTC_DCHECK_EQ(codecType, kVideoCodecH264); |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 113 | return codec_specific_.H264; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 116 | static const char* kPayloadNameVp8 = "VP8"; |
| 117 | static const char* kPayloadNameVp9 = "VP9"; |
| 118 | static const char* kPayloadNameH264 = "H264"; |
| 119 | static const char* kPayloadNameI420 = "I420"; |
| 120 | static const char* kPayloadNameRED = "RED"; |
| 121 | static const char* kPayloadNameULPFEC = "ULPFEC"; |
Danil Chapovalov | 3c70697 | 2018-01-30 11:11:08 +0100 | [diff] [blame] | 122 | static const char* kPayloadNameFlexfec = "flexfec-03"; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 123 | static const char* kPayloadNameGeneric = "Generic"; |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 124 | static const char* kPayloadNameMultiplex = "Multiplex"; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 125 | |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 126 | static bool CodecNamesEq(const char* name1, const char* name2) { |
| 127 | return _stricmp(name1, name2) == 0; |
| 128 | } |
| 129 | |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 130 | const char* CodecTypeToPayloadString(VideoCodecType type) { |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 131 | switch (type) { |
| 132 | case kVideoCodecVP8: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 133 | return kPayloadNameVp8; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 134 | case kVideoCodecVP9: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 135 | return kPayloadNameVp9; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 136 | case kVideoCodecH264: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 137 | return kPayloadNameH264; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 138 | case kVideoCodecI420: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 139 | return kPayloadNameI420; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 140 | case kVideoCodecRED: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 141 | return kPayloadNameRED; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 142 | case kVideoCodecULPFEC: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 143 | return kPayloadNameULPFEC; |
Danil Chapovalov | 3c70697 | 2018-01-30 11:11:08 +0100 | [diff] [blame] | 144 | case kVideoCodecFlexfec: |
| 145 | return kPayloadNameFlexfec; |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 146 | // Other codecs default to generic. |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 147 | case kVideoCodecMultiplex: |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 148 | case kVideoCodecGeneric: |
| 149 | case kVideoCodecUnknown: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 150 | return kPayloadNameGeneric; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 151 | } |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 152 | return kPayloadNameGeneric; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 153 | } |
| 154 | |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 155 | VideoCodecType PayloadStringToCodecType(const std::string& name) { |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 156 | if (CodecNamesEq(name.c_str(), kPayloadNameVp8)) |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 157 | return kVideoCodecVP8; |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 158 | if (CodecNamesEq(name.c_str(), kPayloadNameVp9)) |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 159 | return kVideoCodecVP9; |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 160 | if (CodecNamesEq(name.c_str(), kPayloadNameH264)) |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 161 | return kVideoCodecH264; |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 162 | if (CodecNamesEq(name.c_str(), kPayloadNameI420)) |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 163 | return kVideoCodecI420; |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 164 | if (CodecNamesEq(name.c_str(), kPayloadNameRED)) |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 165 | return kVideoCodecRED; |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 166 | if (CodecNamesEq(name.c_str(), kPayloadNameULPFEC)) |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 167 | return kVideoCodecULPFEC; |
Danil Chapovalov | 3c70697 | 2018-01-30 11:11:08 +0100 | [diff] [blame] | 168 | if (CodecNamesEq(name.c_str(), kPayloadNameFlexfec)) |
| 169 | return kVideoCodecFlexfec; |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 170 | if (CodecNamesEq(name.c_str(), kPayloadNameMultiplex)) |
| 171 | return kVideoCodecMultiplex; |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 172 | return kVideoCodecGeneric; |
| 173 | } |
| 174 | |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 175 | } // namespace webrtc |