blob: f429996737b58947203c9b3c42d7fb07de2efd4e [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>
eladalond0244c22017-06-08 04:19:13 -070014#include <algorithm>
danilchapef8d7732017-04-19 02:59:48 -070015#include <limits>
Niels Möllera46bd4b2018-06-08 14:03:44 +020016#include <string>
danilchapef8d7732017-04-19 02:59:48 -070017#include <type_traits>
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000018
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/checks.h"
Erik Språngbb60a3a2018-03-19 18:25:10 +010020#include "rtc_base/strings/string_builder.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/stringutils.h"
magjed10165ab2016-11-22 10:16:57 -080022
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000023namespace webrtc {
24
Niels Möllerdef1ef52018-03-19 13:48:44 +010025bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
Niels Möllerdef1ef52018-03-19 13:48:44 +010026 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010027 numberOfTemporalLayers == other.numberOfTemporalLayers &&
28 denoisingOn == other.denoisingOn &&
29 automaticResizeOn == other.automaticResizeOn &&
30 frameDroppingOn == other.frameDroppingOn &&
31 keyFrameInterval == other.keyFrameInterval);
32}
33
34bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
35 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010036 numberOfTemporalLayers == other.numberOfTemporalLayers &&
37 denoisingOn == other.denoisingOn &&
38 frameDroppingOn == other.frameDroppingOn &&
39 keyFrameInterval == other.keyFrameInterval &&
40 adaptiveQpMode == other.adaptiveQpMode &&
41 automaticResizeOn == other.automaticResizeOn &&
42 numberOfSpatialLayers == other.numberOfSpatialLayers &&
43 flexibleMode == other.flexibleMode);
44}
45
46bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
47 return (frameDroppingOn == other.frameDroppingOn &&
48 keyFrameInterval == other.keyFrameInterval &&
49 spsLen == other.spsLen &&
50 ppsLen == other.ppsLen &&
51 profile == other.profile &&
52 (spsLen == 0 || memcmp(spsData, other.spsData, spsLen) == 0) &&
53 (ppsLen == 0 || memcmp(ppsData, other.ppsData, ppsLen) == 0));
54}
55
56bool SpatialLayer::operator==(const SpatialLayer& other) const {
57 return (width == other.width &&
58 height == other.height &&
59 numberOfTemporalLayers == other.numberOfTemporalLayers &&
60 maxBitrate == other.maxBitrate &&
61 targetBitrate == other.targetBitrate &&
62 minBitrate == other.minBitrate &&
63 qpMax == other.qpMax &&
64 active == other.active);
65}
66
hta257dc392016-10-25 09:05:06 -070067VideoCodec::VideoCodec()
68 : codecType(kVideoCodecUnknown),
hta257dc392016-10-25 09:05:06 -070069 plType(0),
70 width(0),
71 height(0),
72 startBitrate(0),
73 maxBitrate(0),
74 minBitrate(0),
75 targetBitrate(0),
76 maxFramerate(0),
Seth Hampsonf6464c92018-01-17 13:55:14 -080077 active(true),
hta257dc392016-10-25 09:05:06 -070078 qpMax(0),
79 numberOfSimulcastStreams(0),
80 simulcastStream(),
81 spatialLayers(),
82 mode(kRealtimeVideo),
Erik Språng08127a92016-11-16 16:41:30 +010083 expect_encode_from_texture(false),
ilnik04f4d122017-06-19 07:18:55 -070084 timing_frame_thresholds({0, 0}),
hta527d3472016-11-16 23:23:04 -080085 codec_specific_() {}
hta257dc392016-10-25 09:05:06 -070086
87VideoCodecVP8* VideoCodec::VP8() {
88 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080089 return &codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070090}
91
92const VideoCodecVP8& VideoCodec::VP8() const {
93 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080094 return codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070095}
96
97VideoCodecVP9* VideoCodec::VP9() {
98 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080099 return &codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -0700100}
101
102const VideoCodecVP9& VideoCodec::VP9() const {
103 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -0800104 return codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -0700105}
106
107VideoCodecH264* VideoCodec::H264() {
108 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800109 return &codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700110}
111
112const VideoCodecH264& VideoCodec::H264() const {
113 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -0800114 return codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -0700115}
116
Erik Språng08127a92016-11-16 16:41:30 +0100117static const char* kPayloadNameVp8 = "VP8";
118static const char* kPayloadNameVp9 = "VP9";
119static const char* kPayloadNameH264 = "H264";
120static const char* kPayloadNameI420 = "I420";
Erik Språng08127a92016-11-16 16:41:30 +0100121static const char* kPayloadNameGeneric = "Generic";
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800122static const char* kPayloadNameMultiplex = "Multiplex";
Erik Språng08127a92016-11-16 16:41:30 +0100123
magjed10165ab2016-11-22 10:16:57 -0800124static bool CodecNamesEq(const char* name1, const char* name2) {
125 return _stricmp(name1, name2) == 0;
126}
127
kthelgason1cdddc92017-08-24 03:52:48 -0700128const char* CodecTypeToPayloadString(VideoCodecType type) {
Erik Språng08127a92016-11-16 16:41:30 +0100129 switch (type) {
130 case kVideoCodecVP8:
kthelgason1cdddc92017-08-24 03:52:48 -0700131 return kPayloadNameVp8;
Erik Språng08127a92016-11-16 16:41:30 +0100132 case kVideoCodecVP9:
kthelgason1cdddc92017-08-24 03:52:48 -0700133 return kPayloadNameVp9;
Erik Språng08127a92016-11-16 16:41:30 +0100134 case kVideoCodecH264:
kthelgason1cdddc92017-08-24 03:52:48 -0700135 return kPayloadNameH264;
Erik Språng08127a92016-11-16 16:41:30 +0100136 case kVideoCodecI420:
kthelgason1cdddc92017-08-24 03:52:48 -0700137 return kPayloadNameI420;
Emircan Uysaler0a375472017-12-11 12:21:02 +0530138 // Other codecs default to generic.
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800139 case kVideoCodecMultiplex:
Emircan Uysaler0a375472017-12-11 12:21:02 +0530140 case kVideoCodecGeneric:
141 case kVideoCodecUnknown:
kthelgason1cdddc92017-08-24 03:52:48 -0700142 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100143 }
Emircan Uysaler0a375472017-12-11 12:21:02 +0530144 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100145}
146
kthelgason1cdddc92017-08-24 03:52:48 -0700147VideoCodecType PayloadStringToCodecType(const std::string& name) {
magjed10165ab2016-11-22 10:16:57 -0800148 if (CodecNamesEq(name.c_str(), kPayloadNameVp8))
kthelgason1cdddc92017-08-24 03:52:48 -0700149 return kVideoCodecVP8;
magjed10165ab2016-11-22 10:16:57 -0800150 if (CodecNamesEq(name.c_str(), kPayloadNameVp9))
kthelgason1cdddc92017-08-24 03:52:48 -0700151 return kVideoCodecVP9;
magjed10165ab2016-11-22 10:16:57 -0800152 if (CodecNamesEq(name.c_str(), kPayloadNameH264))
kthelgason1cdddc92017-08-24 03:52:48 -0700153 return kVideoCodecH264;
magjed10165ab2016-11-22 10:16:57 -0800154 if (CodecNamesEq(name.c_str(), kPayloadNameI420))
kthelgason1cdddc92017-08-24 03:52:48 -0700155 return kVideoCodecI420;
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800156 if (CodecNamesEq(name.c_str(), kPayloadNameMultiplex))
157 return kVideoCodecMultiplex;
kthelgason1cdddc92017-08-24 03:52:48 -0700158 return kVideoCodecGeneric;
159}
160
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000161} // namespace webrtc