blob: 3566aefec63599bb61fd6298272b4d05d2de2601 [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"
magjed10165ab2016-11-22 10:16:57 -080018
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +000019namespace webrtc {
20
Niels Möllerdef1ef52018-03-19 13:48:44 +010021bool VideoCodecVP8::operator==(const VideoCodecVP8& other) const {
Niels Möllerdef1ef52018-03-19 13:48:44 +010022 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010023 numberOfTemporalLayers == other.numberOfTemporalLayers &&
24 denoisingOn == other.denoisingOn &&
25 automaticResizeOn == other.automaticResizeOn &&
26 frameDroppingOn == other.frameDroppingOn &&
27 keyFrameInterval == other.keyFrameInterval);
28}
29
30bool VideoCodecVP9::operator==(const VideoCodecVP9& other) const {
31 return (complexity == other.complexity &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010032 numberOfTemporalLayers == other.numberOfTemporalLayers &&
33 denoisingOn == other.denoisingOn &&
34 frameDroppingOn == other.frameDroppingOn &&
35 keyFrameInterval == other.keyFrameInterval &&
36 adaptiveQpMode == other.adaptiveQpMode &&
37 automaticResizeOn == other.automaticResizeOn &&
38 numberOfSpatialLayers == other.numberOfSpatialLayers &&
39 flexibleMode == other.flexibleMode);
40}
41
42bool VideoCodecH264::operator==(const VideoCodecH264& other) const {
43 return (frameDroppingOn == other.frameDroppingOn &&
44 keyFrameInterval == other.keyFrameInterval &&
Rasmus Brandt70c961f2019-04-11 13:26:25 +020045 numberOfTemporalLayers == other.numberOfTemporalLayers);
Niels Möllerdef1ef52018-03-19 13:48:44 +010046}
47
48bool SpatialLayer::operator==(const SpatialLayer& other) const {
Yves Gerey665174f2018-06-19 15:03:05 +020049 return (width == other.width && height == other.height &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010050 numberOfTemporalLayers == other.numberOfTemporalLayers &&
51 maxBitrate == other.maxBitrate &&
52 targetBitrate == other.targetBitrate &&
Yves Gerey665174f2018-06-19 15:03:05 +020053 minBitrate == other.minBitrate && qpMax == other.qpMax &&
Niels Möllerdef1ef52018-03-19 13:48:44 +010054 active == other.active);
55}
56
hta257dc392016-10-25 09:05:06 -070057VideoCodec::VideoCodec()
Kári Tristan Helgason84ccb2d2018-08-16 14:35:26 +020058 : codecType(kVideoCodecGeneric),
hta257dc392016-10-25 09:05:06 -070059 plType(0),
60 width(0),
61 height(0),
62 startBitrate(0),
63 maxBitrate(0),
64 minBitrate(0),
hta257dc392016-10-25 09:05:06 -070065 maxFramerate(0),
Seth Hampsonf6464c92018-01-17 13:55:14 -080066 active(true),
hta257dc392016-10-25 09:05:06 -070067 qpMax(0),
68 numberOfSimulcastStreams(0),
69 simulcastStream(),
70 spatialLayers(),
Niels Möllere3cf3d02018-06-13 11:52:16 +020071 mode(VideoCodecMode::kRealtimeVideo),
Erik Språng08127a92016-11-16 16:41:30 +010072 expect_encode_from_texture(false),
ilnik04f4d122017-06-19 07:18:55 -070073 timing_frame_thresholds({0, 0}),
hta527d3472016-11-16 23:23:04 -080074 codec_specific_() {}
hta257dc392016-10-25 09:05:06 -070075
76VideoCodecVP8* VideoCodec::VP8() {
77 RTC_DCHECK_EQ(codecType, kVideoCodecVP8);
hta527d3472016-11-16 23:23:04 -080078 return &codec_specific_.VP8;
hta257dc392016-10-25 09:05:06 -070079}
80
81const VideoCodecVP8& VideoCodec::VP8() const {
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
86VideoCodecVP9* VideoCodec::VP9() {
87 RTC_DCHECK_EQ(codecType, kVideoCodecVP9);
hta527d3472016-11-16 23:23:04 -080088 return &codec_specific_.VP9;
hta257dc392016-10-25 09:05:06 -070089}
90
91const VideoCodecVP9& VideoCodec::VP9() const {
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
96VideoCodecH264* VideoCodec::H264() {
97 RTC_DCHECK_EQ(codecType, kVideoCodecH264);
hta527d3472016-11-16 23:23:04 -080098 return &codec_specific_.H264;
hta257dc392016-10-25 09:05:06 -070099}
100
101const VideoCodecH264& VideoCodec::H264() const {
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
Erik Språng08127a92016-11-16 16:41:30 +0100106static const char* kPayloadNameVp8 = "VP8";
107static const char* kPayloadNameVp9 = "VP9";
108static const char* kPayloadNameH264 = "H264";
Erik Språng08127a92016-11-16 16:41:30 +0100109static const char* kPayloadNameGeneric = "Generic";
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800110static const char* kPayloadNameMultiplex = "Multiplex";
Erik Språng08127a92016-11-16 16:41:30 +0100111
kthelgason1cdddc92017-08-24 03:52:48 -0700112const char* CodecTypeToPayloadString(VideoCodecType type) {
Erik Språng08127a92016-11-16 16:41:30 +0100113 switch (type) {
114 case kVideoCodecVP8:
kthelgason1cdddc92017-08-24 03:52:48 -0700115 return kPayloadNameVp8;
Erik Språng08127a92016-11-16 16:41:30 +0100116 case kVideoCodecVP9:
kthelgason1cdddc92017-08-24 03:52:48 -0700117 return kPayloadNameVp9;
Erik Språng08127a92016-11-16 16:41:30 +0100118 case kVideoCodecH264:
kthelgason1cdddc92017-08-24 03:52:48 -0700119 return kPayloadNameH264;
Emircan Uysaler0a375472017-12-11 12:21:02 +0530120 // Other codecs default to generic.
Kári Tristan Helgason84ccb2d2018-08-16 14:35:26 +0200121 default:
kthelgason1cdddc92017-08-24 03:52:48 -0700122 return kPayloadNameGeneric;
Erik Språng08127a92016-11-16 16:41:30 +0100123 }
124}
125
kthelgason1cdddc92017-08-24 03:52:48 -0700126VideoCodecType PayloadStringToCodecType(const std::string& name) {
Niels Möller039743e2018-10-23 10:07:25 +0200127 if (absl::EqualsIgnoreCase(name, kPayloadNameVp8))
kthelgason1cdddc92017-08-24 03:52:48 -0700128 return kVideoCodecVP8;
Niels Möller039743e2018-10-23 10:07:25 +0200129 if (absl::EqualsIgnoreCase(name, kPayloadNameVp9))
kthelgason1cdddc92017-08-24 03:52:48 -0700130 return kVideoCodecVP9;
Niels Möller039743e2018-10-23 10:07:25 +0200131 if (absl::EqualsIgnoreCase(name, kPayloadNameH264))
kthelgason1cdddc92017-08-24 03:52:48 -0700132 return kVideoCodecH264;
Niels Möller039743e2018-10-23 10:07:25 +0200133 if (absl::EqualsIgnoreCase(name, kPayloadNameMultiplex))
Emircan Uysalerd7ae3c32018-01-25 13:01:09 -0800134 return kVideoCodecMultiplex;
kthelgason1cdddc92017-08-24 03:52:48 -0700135 return kVideoCodecGeneric;
136}
137
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000138} // namespace webrtc