blob: 0819c822a06de799c13d7a5d2d8206f470ed3708 [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
Niels Möllera46bd4b2018-06-08 14:03:44 +020011#include "api/video_codecs/video_codec.h"
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000012
13#include <string.h>
Niels Möllera46bd4b2018-06-08 14:03:44 +020014#include <string>
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000015
Niels Möller3c7d5992018-10-19 15:29:54 +020016#include "absl/strings/match.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "rtc_base/checks.h"
Yves Gerey988cc082018-10-23 12:03:01 +020018#include "rtc_base/stringutils.h"
magjed10165ab2016-11-22 10:16:57 -080019
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000020namespace webrtc {
21
Niels Möllerdef1ef52018-03-19 13:48:44 +010022bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
Niels Möllerdef1ef52018-03-19 13:48:44 +010023 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010024 numberOfTemporalLayers == other.numberOfTemporalLayers &&
25 denoisingOn == other.denoisingOn &&
26 automaticResizeOn == other.automaticResizeOn &&
27 frameDroppingOn == other.frameDroppingOn &&
28 keyFrameInterval == other.keyFrameInterval);
29}
30
31bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
32 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010033 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
43bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
44 return (frameDroppingOn == other.frameDroppingOn &&
45 keyFrameInterval == other.keyFrameInterval &&
Yves Gerey665174f2018-06-19 15:03:05 +020046 spsLen == other.spsLen && ppsLen == other.ppsLen &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010047 profile == other.profile &&
48 (spsLen == 0 || memcmp(spsData, other.spsData, spsLen) == 0) &&
49 (ppsLen == 0 || memcmp(ppsData, other.ppsData, ppsLen) == 0));
50}
51
52bool SpatialLayer::operator==(const SpatialLayer& other) const {
Yves Gerey665174f2018-06-19 15:03:05 +020053 return (width == other.width && height == other.height &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010054 numberOfTemporalLayers == other.numberOfTemporalLayers &&
55 maxBitrate == other.maxBitrate &&
56 targetBitrate == other.targetBitrate &&
Yves Gerey665174f2018-06-19 15:03:05 +020057 minBitrate == other.minBitrate && qpMax == other.qpMax &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010058 active == other.active);
59}
60
hta257dc392016-10-25 09:05:06 -070061VideoCodec::VideoCodec()
Kári Tristan Helgason84ccb2d2018-08-16 14:35:26 +020062 : codecType(kVideoCodecGeneric),
hta257dc392016-10-25 09:05:06 -070063 plType(0),
64 width(0),
65 height(0),
66 startBitrate(0),
67 maxBitrate(0),
68 minBitrate(0),
69 targetBitrate(0),
70 maxFramerate(0),
Seth Hampsonf6464c92018-01-17 13:55:14 -080071 active(true),
hta257dc392016-10-25 09:05:06 -070072 qpMax(0),
73 numberOfSimulcastStreams(0),
74 simulcastStream(),
75 spatialLayers(),
Niels Möllere3cf3d02018-06-13 11:52:16 +020076 mode(VideoCodecMode::kRealtimeVideo),
Erik Språng08127a92016-11-16 16:41:30 +010077 expect_encode_from_texture(false),
ilnik04f4d122017-06-19 07:18:55 -070078 timing_frame_thresholds({0, 0}),
hta527d3472016-11-16 23:23:04 -080079 codec_specific_() {}
hta257dc392016-10-25 09:05:06 -070080
81VideoCodecVP8* VideoCodec::VP8() {
82 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080083 return &codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070084}
85
86const VideoCodecVP8& VideoCodec::VP8() const {
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
91VideoCodecVP9* VideoCodec::VP9() {
92 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080093 return &codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -070094}
95
96const VideoCodecVP9& VideoCodec::VP9() const {
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
101VideoCodecH264* VideoCodec::H264() {
102 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800103 return &codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700104}
105
106const VideoCodecH264& VideoCodec::H264() const {
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
Erik Språng08127a92016-11-16 16:41:30 +0100111static const char* kPayloadNameVp8 = "VP8";
112static const char* kPayloadNameVp9 = "VP9";
113static const char* kPayloadNameH264 = "H264";
114static const char* kPayloadNameI420 = "I420";
Erik Språng08127a92016-11-16 16:41:30 +0100115static const char* kPayloadNameGeneric = "Generic";
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800116static const char* kPayloadNameMultiplex = "Multiplex";
Erik Språng08127a92016-11-16 16:41:30 +0100117
kthelgason1cdddc92017-08-24 03:52:48 -0700118const char* CodecTypeToPayloadString(VideoCodecType type) {
Erik Språng08127a92016-11-16 16:41:30 +0100119 switch (type) {
120 case kVideoCodecVP8:
kthelgason1cdddc92017-08-24 03:52:48 -0700121 return kPayloadNameVp8;
Erik Språng08127a92016-11-16 16:41:30 +0100122 case kVideoCodecVP9:
kthelgason1cdddc92017-08-24 03:52:48 -0700123 return kPayloadNameVp9;
Erik Språng08127a92016-11-16 16:41:30 +0100124 case kVideoCodecH264:
kthelgason1cdddc92017-08-24 03:52:48 -0700125 return kPayloadNameH264;
Erik Språng08127a92016-11-16 16:41:30 +0100126 case kVideoCodecI420:
kthelgason1cdddc92017-08-24 03:52:48 -0700127 return kPayloadNameI420;
Emircan Uysaler0a375472017-12-11 12:21:02 +0530128 // Other codecs default to generic.
Kári Tristan Helgason84ccb2d2018-08-16 14:35:26 +0200129 default:
kthelgason1cdddc92017-08-24 03:52:48 -0700130 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100131 }
132}
133
kthelgason1cdddc92017-08-24 03:52:48 -0700134VideoCodecType PayloadStringToCodecType(const std::string& name) {
Niels Möller039743e2018-10-23 10:07:25 +0200135 if (absl::EqualsIgnoreCase(name, kPayloadNameVp8))
kthelgason1cdddc92017-08-24 03:52:48 -0700136 return kVideoCodecVP8;
Niels Möller039743e2018-10-23 10:07:25 +0200137 if (absl::EqualsIgnoreCase(name, kPayloadNameVp9))
kthelgason1cdddc92017-08-24 03:52:48 -0700138 return kVideoCodecVP9;
Niels Möller039743e2018-10-23 10:07:25 +0200139 if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
kthelgason1cdddc92017-08-24 03:52:48 -0700140 return kVideoCodecH264;
Niels Möller039743e2018-10-23 10:07:25 +0200141 if (absl::EqualsIgnoreCase(name, kPayloadNameI420))
kthelgason1cdddc92017-08-24 03:52:48 -0700142 return kVideoCodecI420;
Niels Möller039743e2018-10-23 10:07:25 +0200143 if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800144 return kVideoCodecMultiplex;
kthelgason1cdddc92017-08-24 03:52:48 -0700145 return kVideoCodecGeneric;
146}
147
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000148} // namespace webrtc