blob: 9fba60c4e872710fcc8579ef24094febdbb47541 [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
50enum class InterLayerPredMode {
51 kOn, // Allow inter-layer prediction for all frames.
52 // Frame of low spatial layer can be used for
53 // prediction of next spatial layer frame.
54 kOff, // Encoder produces independent spatial layers.
55 kOnKeyPic // Allow inter-layer prediction only for frames
56 // within key picture.
57};
58
59// VP9 specific.
60struct VideoCodecVP9 {
61 bool operator==(const VideoCodecVP9& other) const;
62 bool operator!=(const VideoCodecVP9& other) const {
63 return !(*this == other);
64 }
65 VideoCodecComplexity complexity;
66 unsigned char numberOfTemporalLayers;
67 bool denoisingOn;
68 bool frameDroppingOn;
69 int keyFrameInterval;
70 bool adaptiveQpMode;
71 bool automaticResizeOn;
72 unsigned char numberOfSpatialLayers;
73 bool flexibleMode;
74 InterLayerPredMode interLayerPred;
75};
76
77// H264 specific.
78struct VideoCodecH264 {
79 bool operator==(const VideoCodecH264& other) const;
80 bool operator!=(const VideoCodecH264& other) const {
81 return !(*this == other);
82 }
83 bool frameDroppingOn;
84 int keyFrameInterval;
85 // These are NULL/0 if not externally negotiated.
86 const uint8_t* spsData;
87 size_t spsLen;
88 const uint8_t* ppsData;
89 size_t ppsLen;
90 H264::Profile profile;
91};
92
93// Translates from name of codec to codec type and vice versa.
Mirko Bonadeiac194142018-10-22 17:08:37 +020094RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type);
95RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name);
Niels Möllera46bd4b2018-06-08 14:03:44 +020096
97union VideoCodecUnion {
98 VideoCodecVP8 VP8;
99 VideoCodecVP9 VP9;
100 VideoCodecH264 H264;
101};
102
Niels Möllere3cf3d02018-06-13 11:52:16 +0200103enum class VideoCodecMode { kRealtimeVideo, kScreensharing };
Niels Möllera46bd4b2018-06-08 14:03:44 +0200104
105// Common video codec properties
Mirko Bonadei276827c2018-10-16 14:13:50 +0200106class RTC_EXPORT VideoCodec {
Niels Möllera46bd4b2018-06-08 14:03:44 +0200107 public:
108 VideoCodec();
109
110 // Public variables. TODO(hta): Make them private with accessors.
111 VideoCodecType codecType;
112 unsigned char plType;
113
114 // TODO(nisse): Change to int, for consistency.
115 uint16_t width;
116 uint16_t height;
117
118 unsigned int startBitrate; // kilobits/sec.
119 unsigned int maxBitrate; // kilobits/sec.
120 unsigned int minBitrate; // kilobits/sec.
121 unsigned int targetBitrate; // kilobits/sec.
122
123 uint32_t maxFramerate;
124
125 // This enables/disables encoding and sending when there aren't multiple
126 // simulcast streams,by allocating 0 bitrate if inactive.
127 bool active;
128
129 unsigned int qpMax;
130 unsigned char numberOfSimulcastStreams;
131 SimulcastStream simulcastStream[kMaxSimulcastStreams];
132 SpatialLayer spatialLayers[kMaxSpatialLayers];
133
134 VideoCodecMode mode;
135 bool expect_encode_from_texture;
136
137 // Timing frames configuration. There is delay of delay_ms between two
138 // consequent timing frames, excluding outliers. Frame is always made a
139 // timing frame if it's at least outlier_ratio in percent of "ideal" average
140 // frame given bitrate and framerate, i.e. if it's bigger than
141 // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
142 // frames will not be sent too often usually. Yet large frames will always
143 // have timing information for debug purposes because they are more likely to
144 // cause extra delays.
145 struct TimingFrameTriggerThresholds {
146 int64_t delay_ms;
147 uint16_t outlier_ratio_percent;
148 } timing_frame_thresholds;
149
150 bool operator==(const VideoCodec& other) const = delete;
151 bool operator!=(const VideoCodec& other) const = delete;
152
153 // Accessors for codec specific information.
154 // There is a const version of each that returns a reference,
155 // and a non-const version that returns a pointer, in order
156 // to allow modification of the parameters.
157 VideoCodecVP8* VP8();
158 const VideoCodecVP8& VP8() const;
159 VideoCodecVP9* VP9();
160 const VideoCodecVP9& VP9() const;
161 VideoCodecH264* H264();
162 const VideoCodecH264& H264() const;
163
164 private:
165 // TODO(hta): Consider replacing the union with a pointer type.
166 // This will allow removing the VideoCodec* types from this file.
167 VideoCodecUnion codec_specific_;
168};
169
170} // namespace webrtc
Niels Möller802506c2018-05-31 10:44:51 +0200171#endif // API_VIDEO_CODECS_VIDEO_CODEC_H_