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