blob: 5f21ca39088c1c20ae6dbdf557ee0cff59ec9c4f [file] [log] [blame]
Henrik Kjellander2557b862015-11-18 22:00:21 +01001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_
12#define MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_
Henrik Kjellander2557b862015-11-18 22:00:21 +010013
14#if defined(WEBRTC_WIN)
15// This is a workaround on Windows due to the fact that some Windows
16// headers define CreateEvent as a macro to either CreateEventW or CreateEventA.
17// This can cause problems since we use that name as well and could
18// declare them as one thing here whereas in another place a windows header
19// may have been included and then implementing CreateEvent() causes compilation
20// errors. So for consistency, we include the main windows header here.
21#include <windows.h>
22#endif
23
Ying Wang3b790f32018-01-19 17:58:57 +010024#include "api/fec_controller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "api/video/video_frame.h"
Niels Möllera46bd4b2018-06-08 14:03:44 +020026#include "api/video_codecs/video_codec.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "modules/include/module.h"
28#include "modules/include/module_common_types.h"
29#include "modules/video_coding/include/video_coding_defines.h"
Niels Möller689983f2018-11-07 16:36:22 +010030#include "rtc_base/deprecation.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "system_wrappers/include/event_wrapper.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010032
philipel9d3ab612015-12-21 04:12:39 -080033namespace webrtc {
Henrik Kjellander2557b862015-11-18 22:00:21 +010034
35class Clock;
36class EncodedImageCallback;
Anders Carlsson7eb8e9f2018-05-18 10:33:04 +020037class VideoDecoder;
Henrik Kjellander2557b862015-11-18 22:00:21 +010038class VideoEncoder;
Henrik Kjellander2557b862015-11-18 22:00:21 +010039struct CodecSpecificInfo;
40
Niels Möller689983f2018-11-07 16:36:22 +010041// DEPRECATED
Henrik Kjellander2557b862015-11-18 22:00:21 +010042class EventFactory {
43 public:
44 virtual ~EventFactory() {}
45
46 virtual EventWrapper* CreateEvent() = 0;
47};
48
Niels Möller689983f2018-11-07 16:36:22 +010049class RTC_DEPRECATED EventFactoryImpl : public EventFactory {
Henrik Kjellander2557b862015-11-18 22:00:21 +010050 public:
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020051 ~EventFactoryImpl() override {}
Henrik Kjellander2557b862015-11-18 22:00:21 +010052
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020053 EventWrapper* CreateEvent() override;
Henrik Kjellander2557b862015-11-18 22:00:21 +010054};
55
56// Used to indicate which decode with errors mode should be used.
57enum VCMDecodeErrorMode {
philipel9d3ab612015-12-21 04:12:39 -080058 kNoErrors, // Never decode with errors. Video will freeze
59 // if nack is disabled.
60 kSelectiveErrors, // Frames that are determined decodable in
61 // VCMSessionInfo may be decoded with missing
62 // packets. As not all incomplete frames will be
63 // decodable, video will freeze if nack is disabled.
64 kWithErrors // Release frames as needed. Errors may be
65 // introduced as some encoded frames may not be
66 // complete.
Henrik Kjellander2557b862015-11-18 22:00:21 +010067};
68
philipel9d3ab612015-12-21 04:12:39 -080069class VideoCodingModule : public Module {
70 public:
71 enum SenderNackMode { kNackNone, kNackAll, kNackSelective };
Henrik Kjellander2557b862015-11-18 22:00:21 +010072
Niels Möller689983f2018-11-07 16:36:22 +010073 RTC_DEPRECATED
74 static VideoCodingModule* Create(Clock* clock,
75 EventFactory* /* event_factory*/) {
76 return Create(clock);
77 }
tommia5c18d72017-03-20 10:43:23 -070078 // DEPRECATED.
Niels Möller689983f2018-11-07 16:36:22 +010079 static VideoCodingModule* Create(Clock* clock);
Henrik Kjellander2557b862015-11-18 22:00:21 +010080
philipel9d3ab612015-12-21 04:12:39 -080081 /*
Yves Gerey665174f2018-06-19 15:03:05 +020082 * Sender
83 */
Henrik Kjellander2557b862015-11-18 22:00:21 +010084
philipel9d3ab612015-12-21 04:12:39 -080085 // Registers a codec to be used for encoding. Calling this
86 // API multiple times overwrites any previously registered codecs.
87 //
88 // NOTE: Must be called on the thread that constructed the VCM instance.
89 //
90 // Input:
91 // - sendCodec : Settings for the codec to be registered.
92 // - numberOfCores : The number of cores the codec is allowed
93 // to use.
94 // - maxPayloadSize : The maximum size each payload is allowed
95 // to have. Usually MTU - overhead.
96 //
97 // Return value : VCM_OK, on success.
98 // < 0, on error.
99 virtual int32_t RegisterSendCodec(const VideoCodec* sendCodec,
100 uint32_t numberOfCores,
101 uint32_t maxPayloadSize) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100102
philipel9d3ab612015-12-21 04:12:39 -0800103 // Register an external encoder object. This can not be used together with
104 // external decoder callbacks.
105 //
106 // Input:
107 // - externalEncoder : Encoder object to be used for encoding frames
108 // inserted
109 // with the AddVideoFrame API.
110 // - payloadType : The payload type bound which this encoder is bound
111 // to.
112 //
113 // Return value : VCM_OK, on success.
114 // < 0, on error.
115 // TODO(pbos): Remove return type when unused elsewhere.
116 virtual int32_t RegisterExternalEncoder(VideoEncoder* externalEncoder,
117 uint8_t payloadType,
118 bool internalSource = false) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100119
philipel9d3ab612015-12-21 04:12:39 -0800120 // Sets the parameters describing the send channel. These parameters are
121 // inputs to the
122 // Media Optimization inside the VCM and also specifies the target bit rate
123 // for the
124 // encoder. Bit rate used by NACK should already be compensated for by the
125 // user.
126 //
127 // Input:
128 // - target_bitrate : The target bitrate for VCM in bits/s.
129 // - lossRate : Fractions of lost packets the past second.
130 // (loss rate in percent = 100 * packetLoss /
131 // 255)
132 // - rtt : Current round-trip time in ms.
133 //
134 // Return value : VCM_OK, on success.
135 // < 0, on error.
136 virtual int32_t SetChannelParameters(uint32_t target_bitrate,
137 uint8_t lossRate,
138 int64_t rtt) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100139
philipel9d3ab612015-12-21 04:12:39 -0800140 // Enable or disable a video protection method.
141 //
142 // Input:
143 // - videoProtection : The method to enable or disable.
144 // - enable : True if the method should be enabled, false if
145 // it should be disabled.
146 //
147 // Return value : VCM_OK, on success.
148 // < 0, on error.
149 virtual int32_t SetVideoProtection(VCMVideoProtection videoProtection,
150 bool enable) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100151
philipel9d3ab612015-12-21 04:12:39 -0800152 // Add one raw video frame to the encoder. This function does all the
153 // necessary
154 // processing, then decides what frame type to encode, or if the frame should
155 // be
156 // dropped. If the frame should be encoded it passes the frame to the encoder
157 // before it returns.
158 //
159 // Input:
160 // - videoFrame : Video frame to encode.
161 // - codecSpecificInfo : Extra codec information, e.g., pre-parsed
162 // in-band signaling.
163 //
164 // Return value : VCM_OK, on success.
165 // < 0, on error.
166 virtual int32_t AddVideoFrame(
167 const VideoFrame& videoFrame,
philipel9d3ab612015-12-21 04:12:39 -0800168 const CodecSpecificInfo* codecSpecificInfo = NULL) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100169
philipel9d3ab612015-12-21 04:12:39 -0800170 // Next frame encoded should be an intra frame (keyframe).
171 //
172 // Return value : VCM_OK, on success.
173 // < 0, on error.
perkj600246e2016-05-04 11:26:51 -0700174 virtual int32_t IntraFrameRequest(size_t stream_index) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100175
philipel9d3ab612015-12-21 04:12:39 -0800176 // Frame Dropper enable. Can be used to disable the frame dropping when the
177 // encoder
178 // over-uses its bit rate. This API is designed to be used when the encoded
179 // frames
180 // are supposed to be stored to an AVI file, or when the I420 codec is used
181 // and the
182 // target bit rate shouldn't affect the frame rate.
183 //
184 // Input:
185 // - enable : True to enable the setting, false to disable it.
186 //
187 // Return value : VCM_OK, on success.
188 // < 0, on error.
189 virtual int32_t EnableFrameDropper(bool enable) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100190
philipel9d3ab612015-12-21 04:12:39 -0800191 /*
Yves Gerey665174f2018-06-19 15:03:05 +0200192 * Receiver
193 */
Henrik Kjellander2557b862015-11-18 22:00:21 +0100194
philipel9d3ab612015-12-21 04:12:39 -0800195 // Register possible receive codecs, can be called multiple times for
196 // different codecs.
197 // The module will automatically switch between registered codecs depending on
198 // the
199 // payload type of incoming frames. The actual decoder will be created when
200 // needed.
201 //
202 // Input:
203 // - receiveCodec : Settings for the codec to be registered.
204 // - numberOfCores : Number of CPU cores that the decoder is allowed
205 // to use.
206 // - requireKeyFrame : Set this to true if you don't want any delta
207 // frames
208 // to be decoded until the first key frame has been
209 // decoded.
210 //
211 // Return value : VCM_OK, on success.
212 // < 0, on error.
213 virtual int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
214 int32_t numberOfCores,
215 bool requireKeyFrame = false) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100216
Anders Carlsson7eb8e9f2018-05-18 10:33:04 +0200217 // Register an external decoder object.
218 //
219 // Input:
220 // - externalDecoder : Decoder object to be used for decoding frames.
221 // - payloadType : The payload type which this decoder is bound to.
222 virtual void RegisterExternalDecoder(VideoDecoder* externalDecoder,
223 uint8_t payloadType) = 0;
224
philipel9d3ab612015-12-21 04:12:39 -0800225 // Register a receive callback. Will be called whenever there is a new frame
226 // ready
227 // for rendering.
228 //
229 // Input:
230 // - receiveCallback : The callback object to be used by the
231 // module when a
232 // frame is ready for rendering.
233 // De-register with a NULL pointer.
234 //
235 // Return value : VCM_OK, on success.
236 // < 0, on error.
237 virtual int32_t RegisterReceiveCallback(
238 VCMReceiveCallback* receiveCallback) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100239
philipel9d3ab612015-12-21 04:12:39 -0800240 // Register a frame type request callback. This callback will be called when
241 // the
242 // module needs to request specific frame types from the send side.
243 //
244 // Input:
245 // - frameTypeCallback : The callback object to be used by the
246 // module when
247 // requesting a specific type of frame from
248 // the send side.
249 // De-register with a NULL pointer.
250 //
251 // Return value : VCM_OK, on success.
252 // < 0, on error.
253 virtual int32_t RegisterFrameTypeCallback(
254 VCMFrameTypeCallback* frameTypeCallback) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100255
philipel9d3ab612015-12-21 04:12:39 -0800256 // Registers a callback which is called whenever the receive side of the VCM
257 // encounters holes in the packet sequence and needs packets to be
258 // retransmitted.
259 //
260 // Input:
261 // - callback : The callback to be registered in the VCM.
262 //
263 // Return value : VCM_OK, on success.
264 // <0, on error.
265 virtual int32_t RegisterPacketRequestCallback(
266 VCMPacketRequestCallback* callback) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100267
philipel9d3ab612015-12-21 04:12:39 -0800268 // Waits for the next frame in the jitter buffer to become complete
269 // (waits no longer than maxWaitTimeMs), then passes it to the decoder for
270 // decoding.
271 // Should be called as often as possible to get the most out of the decoder.
272 //
273 // Return value : VCM_OK, on success.
274 // < 0, on error.
275 virtual int32_t Decode(uint16_t maxWaitTimeMs = 200) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100276
philipel9d3ab612015-12-21 04:12:39 -0800277 // Insert a parsed packet into the receiver side of the module. Will be placed
278 // in the
279 // jitter buffer waiting for the frame to become complete. Returns as soon as
280 // the packet
281 // has been placed in the jitter buffer.
282 //
283 // Input:
284 // - incomingPayload : Payload of the packet.
285 // - payloadLength : Length of the payload.
286 // - rtpInfo : The parsed header.
287 //
288 // Return value : VCM_OK, on success.
289 // < 0, on error.
290 virtual int32_t IncomingPacket(const uint8_t* incomingPayload,
291 size_t payloadLength,
292 const WebRtcRTPHeader& rtpInfo) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100293
philipel9d3ab612015-12-21 04:12:39 -0800294 // Robustness APIs
Henrik Kjellander2557b862015-11-18 22:00:21 +0100295
tommia5c18d72017-03-20 10:43:23 -0700296 // DEPRECATED.
philipel9d3ab612015-12-21 04:12:39 -0800297 // Set the receiver robustness mode. The mode decides how the receiver
tommia5c18d72017-03-20 10:43:23 -0700298 // responds to losses in the stream. The type of counter-measure is selected
299 // through the robustnessMode parameter. The errorMode parameter decides if it
300 // is allowed to display frames corrupted by losses. Note that not all
philipel9d3ab612015-12-21 04:12:39 -0800301 // combinations of the two parameters are feasible. An error will be
302 // returned for invalid combinations.
303 // Input:
304 // - robustnessMode : selected robustness mode.
305 // - errorMode : selected error mode.
306 //
307 // Return value : VCM_OK, on success;
308 // < 0, on error.
tommia5c18d72017-03-20 10:43:23 -0700309 enum ReceiverRobustness { kNone, kHardNack };
philipel9d3ab612015-12-21 04:12:39 -0800310 virtual int SetReceiverRobustnessMode(ReceiverRobustness robustnessMode,
311 VCMDecodeErrorMode errorMode) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100312
philipel9d3ab612015-12-21 04:12:39 -0800313 // Sets the maximum number of sequence numbers that we are allowed to NACK
314 // and the oldest sequence number that we will consider to NACK. If a
315 // sequence number older than |max_packet_age_to_nack| is missing
316 // a key frame will be requested. A key frame will also be requested if the
317 // time of incomplete or non-continuous frames in the jitter buffer is above
318 // |max_incomplete_time_ms|.
319 virtual void SetNackSettings(size_t max_nack_list_size,
320 int max_packet_age_to_nack,
321 int max_incomplete_time_ms) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100322
philipel9d3ab612015-12-21 04:12:39 -0800323 virtual void RegisterPostEncodeImageCallback(
324 EncodedImageCallback* post_encode_callback) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100325};
326
327} // namespace webrtc
328
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200329#endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_