| 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 |
| 11 | #include "api/video_codecs/video_codec.h" |
| 12 |
| 13 | #include <string.h> |
| 14 |
| 15 | #include <string> |
| 16 |
| 17 | #include "absl/strings/match.h" |
| 18 | #include "rtc_base/checks.h" |
| 19 |
| 20 | namespace webrtc { |
| 21 | namespace { |
| 22 | constexpr char kPayloadNameVp8[] = "VP8"; |
| 23 | constexpr char kPayloadNameVp9[] = "VP9"; |
| 24 | // TODO(bugs.webrtc.org/11042): Rename to AV1 when rtp payload format for av1 is |
| 25 | // frozen. |
| 26 | constexpr char kPayloadNameAv1[] = "AV1X"; |
| 27 | constexpr char kPayloadNameH264[] = "H264"; |
| 28 | #ifndef DISABLE_H265 |
| 29 | constexpr char kPayloadNameH265[] = "H265"; |
| 30 | #endif |
| 31 | constexpr char kPayloadNameGeneric[] = "Generic"; |
| 32 | constexpr char kPayloadNameMultiplex[] = "Multiplex"; |
| 33 | } // namespace |
| 34 |
| 35 | bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const { |
| 36 | return (complexity == other.complexity && |
| 37 | numberOfTemporalLayers == other.numberOfTemporalLayers && |
| 38 | denoisingOn == other.denoisingOn && |
| 39 | automaticResizeOn == other.automaticResizeOn && |
| 40 | frameDroppingOn == other.frameDroppingOn && |
| 41 | keyFrameInterval == other.keyFrameInterval); |
| 42 | } |
| 43 |
| 44 | bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const { |
| 45 | return (complexity == other.complexity && |
| 46 | numberOfTemporalLayers == other.numberOfTemporalLayers && |
| 47 | denoisingOn == other.denoisingOn && |
| 48 | frameDroppingOn == other.frameDroppingOn && |
| 49 | keyFrameInterval == other.keyFrameInterval && |
| 50 | adaptiveQpMode == other.adaptiveQpMode && |
| 51 | automaticResizeOn == other.automaticResizeOn && |
| 52 | numberOfSpatialLayers == other.numberOfSpatialLayers && |
| 53 | flexibleMode == other.flexibleMode); |
| 54 | } |
| 55 |
| 56 | bool VideoCodecH264::operator==(const VideoCodecH264& other) const { |
| 57 | return (frameDroppingOn == other.frameDroppingOn && |
| 58 | keyFrameInterval == other.keyFrameInterval && |
| 59 | numberOfTemporalLayers == other.numberOfTemporalLayers); |
| 60 | } |
| 61 |
| 62 | #ifndef DISABLE_H265 |
| 63 | bool VideoCodecH265::operator==(const VideoCodecH265& other) const { |
| 64 | return (frameDroppingOn == other.frameDroppingOn && |
| 65 | keyFrameInterval == other.keyFrameInterval && |
| 66 | vpsLen == other.vpsLen && spsLen == other.spsLen && |
| 67 | ppsLen == other.ppsLen && |
| 68 | (spsLen == 0 || memcmp(spsData, other.spsData, spsLen) == 0) && |
| 69 | (ppsLen == 0 || memcmp(ppsData, other.ppsData, ppsLen) == 0)); |
| 70 | } |
| 71 | #endif |
| 72 |
| 73 | bool SpatialLayer::operator==(const SpatialLayer& other) const { |
| 74 | return (width == other.width && height == other.height && |
| 75 | maxFramerate == other.maxFramerate && |
| 76 | numberOfTemporalLayers == other.numberOfTemporalLayers && |
| 77 | maxBitrate == other.maxBitrate && |
| 78 | targetBitrate == other.targetBitrate && |
| 79 | minBitrate == other.minBitrate && qpMax == other.qpMax && |
| 80 | active == other.active); |
| 81 | } |
| 82 |
| 83 | VideoCodec::VideoCodec() |
| 84 | : codecType(kVideoCodecGeneric), |
| 85 | plType(0), |
| 86 | width(0), |
| 87 | height(0), |
| 88 | startBitrate(0), |
| 89 | maxBitrate(0), |
| 90 | minBitrate(0), |
| 91 | maxFramerate(0), |
| 92 | active(true), |
| 93 | qpMax(0), |
| 94 | numberOfSimulcastStreams(0), |
| 95 | simulcastStream(), |
| 96 | spatialLayers(), |
| 97 | mode(VideoCodecMode::kRealtimeVideo), |
| 98 | expect_encode_from_texture(false), |
| 99 | timing_frame_thresholds({0, 0}), |
| 100 | legacy_conference_mode(false), |
| 101 | codec_specific_() {} |
| 102 |
| 103 | VideoCodecVP8* VideoCodec::VP8() { |
| 104 | RTC_DCHECK_EQ(codecType, kVideoCodecVP8); |
| 105 | return &codec_specific_.VP8; |
| 106 | } |
| 107 |
| 108 | const VideoCodecVP8& VideoCodec::VP8() const { |
| 109 | RTC_DCHECK_EQ(codecType, kVideoCodecVP8); |
| 110 | return codec_specific_.VP8; |
| 111 | } |
| 112 |
| 113 | VideoCodecVP9* VideoCodec::VP9() { |
| 114 | RTC_DCHECK_EQ(codecType, kVideoCodecVP9); |
| 115 | return &codec_specific_.VP9; |
| 116 | } |
| 117 |
| 118 | const VideoCodecVP9& VideoCodec::VP9() const { |
| 119 | RTC_DCHECK_EQ(codecType, kVideoCodecVP9); |
| 120 | return codec_specific_.VP9; |
| 121 | } |
| 122 |
| 123 | VideoCodecH264* VideoCodec::H264() { |
| 124 | RTC_DCHECK_EQ(codecType, kVideoCodecH264); |
| 125 | return &codec_specific_.H264; |
| 126 | } |
| 127 |
| 128 | const VideoCodecH264& VideoCodec::H264() const { |
| 129 | RTC_DCHECK_EQ(codecType, kVideoCodecH264); |
| 130 | return codec_specific_.H264; |
| 131 | } |
| 132 |
| 133 | #ifndef DISABLE_H265 |
| 134 | VideoCodecH265* VideoCodec::H265() { |
| 135 | RTC_DCHECK_EQ(codecType, kVideoCodecH265); |
| 136 | return &codec_specific_.H265; |
| 137 | } |
| 138 |
| 139 | const VideoCodecH265& VideoCodec::H265() const { |
| 140 | RTC_DCHECK_EQ(codecType, kVideoCodecH265); |
| 141 | return codec_specific_.H265; |
| 142 | } |
| 143 | #endif |
| 144 |
| 145 | const char* CodecTypeToPayloadString(VideoCodecType type) { |
| 146 | switch (type) { |
| 147 | case kVideoCodecVP8: |
| 148 | return kPayloadNameVp8; |
| 149 | case kVideoCodecVP9: |
| 150 | return kPayloadNameVp9; |
| 151 | case kVideoCodecAV1: |
| 152 | return kPayloadNameAv1; |
| 153 | case kVideoCodecH264: |
| 154 | return kPayloadNameH264; |
| 155 | #ifndef DISABLE_H265 |
| 156 | case kVideoCodecH265: |
| 157 | return kPayloadNameH265; |
| 158 | #endif |
| 159 | case kVideoCodecMultiplex: |
| 160 | return kPayloadNameMultiplex; |
| 161 | case kVideoCodecGeneric: |
| 162 | default: |
| 163 | return kPayloadNameGeneric; |
| 164 | } |
| 165 | } |
| 166 |
| 167 | VideoCodecType PayloadStringToCodecType(const std::string& name) { |
| 168 | if (absl::EqualsIgnoreCase(name, kPayloadNameVp8)) |
| 169 | return kVideoCodecVP8; |
| 170 | if (absl::EqualsIgnoreCase(name, kPayloadNameVp9)) |
| 171 | return kVideoCodecVP9; |
| 172 | if (absl::EqualsIgnoreCase(name, kPayloadNameAv1)) |
| 173 | return kVideoCodecAV1; |
| 174 | if (absl::EqualsIgnoreCase(name, kPayloadNameH264)) |
| 175 | return kVideoCodecH264; |
| 176 | if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex)) |
| 177 | return kVideoCodecMultiplex; |
| 178 | #ifndef DISABLE_H265 |
| 179 | if (absl::EqualsIgnoreCase(name, kPayloadNameH265)) |
| 180 | return kVideoCodecH265; |
| 181 | #endif |
| 182 | return kVideoCodecGeneric; |
| 183 | } |
| 184 |
| 185 | } // namespace webrtc |
| 186 |