blob: d014e7c3a94b1bcebb38a5c06e5132238b294a02 [file] [log] [blame]
Niels Möller802506c2018-05-31 10:44:51 +02001/*
2 * Copyright (c) 2018 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
11#ifndef API_VIDEO_CODECS_VIDEO_CODEC_H_
12#define API_VIDEO_CODECS_VIDEO_CODEC_H_
13
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15#include <stdint.h>
Niels Möllera46bd4b2018-06-08 14:03:44 +020016#include <string>
Niels Möller802506c2018-05-31 10:44:51 +020017
Yves Gerey988cc082018-10-23 12:03:01 +020018#include "api/video/video_bitrate_allocation.h"
Niels Möller22b70ff2018-11-20 11:06:58 +010019#include "api/video/video_codec_type.h"
Niels Möller802506c2018-05-31 10:44:51 +020020#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei276827c2018-10-16 14:13:50 +020021#include "rtc_base/system/rtc_export.h"
Niels Möller802506c2018-05-31 10:44:51 +020022
Niels Möllera46bd4b2018-06-08 14:03:44 +020023namespace webrtc {
24
25// The VideoCodec class represents an old defacto-apis, which we're migrating
Niels Möller802506c2018-05-31 10:44:51 +020026// away from slowly.
27
Niels Möllera46bd4b2018-06-08 14:03:44 +020028// Video codec
Niels Möllere3cf3d02018-06-13 11:52:16 +020029enum class VideoCodecComplexity {
Niels Möllera46bd4b2018-06-08 14:03:44 +020030 kComplexityNormal = 0,
31 kComplexityHigh = 1,
32 kComplexityHigher = 2,
33 kComplexityMax = 3
34};
35
36// VP8 specific
37struct VideoCodecVP8 {
38 bool operator==(const VideoCodecVP8& other) const;
39 bool operator!=(const VideoCodecVP8& other) const {
40 return !(*this == other);
41 }
42 VideoCodecComplexity complexity;
43 unsigned char numberOfTemporalLayers;
44 bool denoisingOn;
45 bool automaticResizeOn;
46 bool frameDroppingOn;
47 int keyFrameInterval;
48};
49
Sergey Silkincf267052019-04-09 11:40:09 +020050enum class InterLayerPredMode : int {
51 kOff = 0, // Inter-layer prediction is disabled.
52 kOn = 1, // Inter-layer prediction is enabled.
53 kOnKeyPic = 2 // Inter-layer prediction is enabled but limited to key frames.
Niels Möllera46bd4b2018-06-08 14:03:44 +020054};
55
56// VP9 specific.
57struct VideoCodecVP9 {
58 bool operator==(const VideoCodecVP9& other) const;
59 bool operator!=(const VideoCodecVP9& other) const {
60 return !(*this == other);
61 }
62 VideoCodecComplexity complexity;
63 unsigned char numberOfTemporalLayers;
64 bool denoisingOn;
65 bool frameDroppingOn;
66 int keyFrameInterval;
67 bool adaptiveQpMode;
68 bool automaticResizeOn;
69 unsigned char numberOfSpatialLayers;
70 bool flexibleMode;
71 InterLayerPredMode interLayerPred;
72};
73
74// H264 specific.
75struct VideoCodecH264 {
76 bool operator==(const VideoCodecH264& other) const;
77 bool operator!=(const VideoCodecH264& other) const {
78 return !(*this == other);
79 }
80 bool frameDroppingOn;
81 int keyFrameInterval;
Johnny Lee1a1c52b2019-02-08 14:25:40 -050082 uint8_t numberOfTemporalLayers;
Niels Möllera46bd4b2018-06-08 14:03:44 +020083};
84
85// Translates from name of codec to codec type and vice versa.
Mirko Bonadeiac194142018-10-22 17:08:37 +020086RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type);
87RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name);
Niels Möllera46bd4b2018-06-08 14:03:44 +020088
89union VideoCodecUnion {
90 VideoCodecVP8 VP8;
91 VideoCodecVP9 VP9;
92 VideoCodecH264 H264;
93};
94
Niels Möllere3cf3d02018-06-13 11:52:16 +020095enum class VideoCodecMode { kRealtimeVideo, kScreensharing };
Niels Möllera46bd4b2018-06-08 14:03:44 +020096
97// Common video codec properties
Mirko Bonadei276827c2018-10-16 14:13:50 +020098class RTC_EXPORT VideoCodec {
Niels Möllera46bd4b2018-06-08 14:03:44 +020099 public:
100 VideoCodec();
101
102 // Public variables. TODO(hta): Make them private with accessors.
103 VideoCodecType codecType;
104 unsigned char plType;
105
106 // TODO(nisse): Change to int, for consistency.
107 uint16_t width;
108 uint16_t height;
109
110 unsigned int startBitrate; // kilobits/sec.
111 unsigned int maxBitrate; // kilobits/sec.
112 unsigned int minBitrate; // kilobits/sec.
Niels Möllera46bd4b2018-06-08 14:03:44 +0200113
114 uint32_t maxFramerate;
115
116 // This enables/disables encoding and sending when there aren't multiple
117 // simulcast streams,by allocating 0 bitrate if inactive.
118 bool active;
119
120 unsigned int qpMax;
121 unsigned char numberOfSimulcastStreams;
122 SimulcastStream simulcastStream[kMaxSimulcastStreams];
123 SpatialLayer spatialLayers[kMaxSpatialLayers];
124
125 VideoCodecMode mode;
126 bool expect_encode_from_texture;
127
128 // Timing frames configuration. There is delay of delay_ms between two
129 // consequent timing frames, excluding outliers. Frame is always made a
130 // timing frame if it's at least outlier_ratio in percent of "ideal" average
131 // frame given bitrate and framerate, i.e. if it's bigger than
132 // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
133 // frames will not be sent too often usually. Yet large frames will always
134 // have timing information for debug purposes because they are more likely to
135 // cause extra delays.
136 struct TimingFrameTriggerThresholds {
137 int64_t delay_ms;
138 uint16_t outlier_ratio_percent;
139 } timing_frame_thresholds;
140
141 bool operator==(const VideoCodec& other) const = delete;
142 bool operator!=(const VideoCodec& other) const = delete;
143
144 // Accessors for codec specific information.
145 // There is a const version of each that returns a reference,
146 // and a non-const version that returns a pointer, in order
147 // to allow modification of the parameters.
148 VideoCodecVP8* VP8();
149 const VideoCodecVP8& VP8() const;
150 VideoCodecVP9* VP9();
151 const VideoCodecVP9& VP9() const;
152 VideoCodecH264* H264();
153 const VideoCodecH264& H264() const;
154
155 private:
156 // TODO(hta): Consider replacing the union with a pointer type.
157 // This will allow removing the VideoCodec* types from this file.
158 VideoCodecUnion codec_specific_;
159};
160
161} // namespace webrtc
Niels Möller802506c2018-05-31 10:44:51 +0200162#endif // API_VIDEO_CODECS_VIDEO_CODEC_H_