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