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 | |
Niels Möller | a46bd4b | 2018-06-08 14:03:44 +0200 | [diff] [blame] | 11 | #include "api/video_codecs/video_codec.h" |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 12 | |
| 13 | #include <string.h> |
Niels Möller | a46bd4b | 2018-06-08 14:03:44 +0200 | [diff] [blame] | 14 | #include <string> |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 15 | |
Niels Möller | 3c7d599 | 2018-10-19 15:29:54 +0200 | [diff] [blame] | 16 | #include "absl/strings/match.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "rtc_base/checks.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 18 | #include "rtc_base/stringutils.h" |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 19 | |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 20 | namespace webrtc { |
| 21 | |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 22 | bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const { |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 23 | return (complexity == other.complexity && |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 24 | numberOfTemporalLayers == other.numberOfTemporalLayers && |
| 25 | denoisingOn == other.denoisingOn && |
| 26 | automaticResizeOn == other.automaticResizeOn && |
| 27 | frameDroppingOn == other.frameDroppingOn && |
| 28 | keyFrameInterval == other.keyFrameInterval); |
| 29 | } |
| 30 | |
| 31 | bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const { |
| 32 | return (complexity == other.complexity && |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 33 | numberOfTemporalLayers == other.numberOfTemporalLayers && |
| 34 | denoisingOn == other.denoisingOn && |
| 35 | frameDroppingOn == other.frameDroppingOn && |
| 36 | keyFrameInterval == other.keyFrameInterval && |
| 37 | adaptiveQpMode == other.adaptiveQpMode && |
| 38 | automaticResizeOn == other.automaticResizeOn && |
| 39 | numberOfSpatialLayers == other.numberOfSpatialLayers && |
| 40 | flexibleMode == other.flexibleMode); |
| 41 | } |
| 42 | |
| 43 | bool VideoCodecH264::operator==(const VideoCodecH264& other) const { |
| 44 | return (frameDroppingOn == other.frameDroppingOn && |
| 45 | keyFrameInterval == other.keyFrameInterval && |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 46 | spsLen == other.spsLen && ppsLen == other.ppsLen && |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 47 | profile == other.profile && |
| 48 | (spsLen == 0 || memcmp(spsData, other.spsData, spsLen) == 0) && |
| 49 | (ppsLen == 0 || memcmp(ppsData, other.ppsData, ppsLen) == 0)); |
| 50 | } |
| 51 | |
| 52 | bool SpatialLayer::operator==(const SpatialLayer& other) const { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 53 | return (width == other.width && height == other.height && |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 54 | numberOfTemporalLayers == other.numberOfTemporalLayers && |
| 55 | maxBitrate == other.maxBitrate && |
| 56 | targetBitrate == other.targetBitrate && |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 57 | minBitrate == other.minBitrate && qpMax == other.qpMax && |
Niels Möller | def1ef5 | 2018-03-19 13:48:44 +0100 | [diff] [blame] | 58 | active == other.active); |
| 59 | } |
| 60 | |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 61 | VideoCodec::VideoCodec() |
Kári Tristan Helgason | 84ccb2d | 2018-08-16 14:35:26 +0200 | [diff] [blame] | 62 | : codecType(kVideoCodecGeneric), |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 63 | plType(0), |
| 64 | width(0), |
| 65 | height(0), |
| 66 | startBitrate(0), |
| 67 | maxBitrate(0), |
| 68 | minBitrate(0), |
| 69 | targetBitrate(0), |
| 70 | maxFramerate(0), |
Seth Hampson | f6464c9 | 2018-01-17 13:55:14 -0800 | [diff] [blame] | 71 | active(true), |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 72 | qpMax(0), |
| 73 | numberOfSimulcastStreams(0), |
| 74 | simulcastStream(), |
| 75 | spatialLayers(), |
Niels Möller | e3cf3d0 | 2018-06-13 11:52:16 +0200 | [diff] [blame] | 76 | mode(VideoCodecMode::kRealtimeVideo), |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 77 | expect_encode_from_texture(false), |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 78 | timing_frame_thresholds({0, 0}), |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 79 | codec_specific_() {} |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 80 | |
| 81 | VideoCodecVP8* VideoCodec::VP8() { |
| 82 | RTC_DCHECK_EQ(codecType, kVideoCodecVP8); |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 83 | return &codec_specific_.VP8; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | const VideoCodecVP8& VideoCodec::VP8() const { |
| 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 | VideoCodecVP9* VideoCodec::VP9() { |
| 92 | RTC_DCHECK_EQ(codecType, kVideoCodecVP9); |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 93 | return &codec_specific_.VP9; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | const VideoCodecVP9& VideoCodec::VP9() const { |
| 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 | VideoCodecH264* VideoCodec::H264() { |
| 102 | RTC_DCHECK_EQ(codecType, kVideoCodecH264); |
hta | 527d347 | 2016-11-16 23:23:04 -0800 | [diff] [blame] | 103 | return &codec_specific_.H264; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | const VideoCodecH264& VideoCodec::H264() const { |
| 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 | |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 111 | static const char* kPayloadNameVp8 = "VP8"; |
| 112 | static const char* kPayloadNameVp9 = "VP9"; |
| 113 | static const char* kPayloadNameH264 = "H264"; |
| 114 | static const char* kPayloadNameI420 = "I420"; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 115 | static const char* kPayloadNameGeneric = "Generic"; |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 116 | static const char* kPayloadNameMultiplex = "Multiplex"; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 117 | |
Niels Möller | 3c7d599 | 2018-10-19 15:29:54 +0200 | [diff] [blame] | 118 | // TODO(nisse): Delete this wrapper. |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 119 | static bool CodecNamesEq(const char* name1, const char* name2) { |
Niels Möller | 3c7d599 | 2018-10-19 15:29:54 +0200 | [diff] [blame] | 120 | return absl::EqualsIgnoreCase(name1, name2); |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 121 | } |
| 122 | |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 123 | const char* CodecTypeToPayloadString(VideoCodecType type) { |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 124 | switch (type) { |
| 125 | case kVideoCodecVP8: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 126 | return kPayloadNameVp8; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 127 | case kVideoCodecVP9: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 128 | return kPayloadNameVp9; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 129 | case kVideoCodecH264: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 130 | return kPayloadNameH264; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 131 | case kVideoCodecI420: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 132 | return kPayloadNameI420; |
Emircan Uysaler | 0a37547 | 2017-12-11 12:21:02 +0530 | [diff] [blame] | 133 | // Other codecs default to generic. |
Kári Tristan Helgason | 84ccb2d | 2018-08-16 14:35:26 +0200 | [diff] [blame] | 134 | default: |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 135 | return kPayloadNameGeneric; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 139 | VideoCodecType PayloadStringToCodecType(const std::string& name) { |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 140 | if (CodecNamesEq(name.c_str(), kPayloadNameVp8)) |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 141 | return kVideoCodecVP8; |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 142 | if (CodecNamesEq(name.c_str(), kPayloadNameVp9)) |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 143 | return kVideoCodecVP9; |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 144 | if (CodecNamesEq(name.c_str(), kPayloadNameH264)) |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 145 | return kVideoCodecH264; |
magjed | 10165ab | 2016-11-22 10:16:57 -0800 | [diff] [blame] | 146 | if (CodecNamesEq(name.c_str(), kPayloadNameI420)) |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 147 | return kVideoCodecI420; |
Emircan Uysaler | d7ae3c3 | 2018-01-25 13:01:09 -0800 | [diff] [blame] | 148 | if (CodecNamesEq(name.c_str(), kPayloadNameMultiplex)) |
| 149 | return kVideoCodecMultiplex; |
kthelgason | 1cdddc9 | 2017-08-24 03:52:48 -0700 | [diff] [blame] | 150 | return kVideoCodecGeneric; |
| 151 | } |
| 152 | |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 153 | } // namespace webrtc |