OLD | NEW |
| (Empty) |
1 /* | |
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 | |
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_ | |
12 #define WEBRTC_MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_ | |
13 | |
14 #pragma message("WARNING: video_coding/main/interface is DEPRECATED; use video_c
oding/include") | |
15 | |
16 #if defined(WEBRTC_WIN) | |
17 // This is a workaround on Windows due to the fact that some Windows | |
18 // headers define CreateEvent as a macro to either CreateEventW or CreateEventA. | |
19 // This can cause problems since we use that name as well and could | |
20 // declare them as one thing here whereas in another place a windows header | |
21 // may have been included and then implementing CreateEvent() causes compilation | |
22 // errors. So for consistency, we include the main windows header here. | |
23 #include <windows.h> | |
24 #endif | |
25 | |
26 #include "webrtc/modules/include/module.h" | |
27 #include "webrtc/modules/include/module_common_types.h" | |
28 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | |
29 #include "webrtc/system_wrappers/include/event_wrapper.h" | |
30 #include "webrtc/video_frame.h" | |
31 | |
32 namespace webrtc | |
33 { | |
34 | |
35 class Clock; | |
36 class EncodedImageCallback; | |
37 class VideoEncoder; | |
38 class VideoDecoder; | |
39 struct CodecSpecificInfo; | |
40 | |
41 class EventFactory { | |
42 public: | |
43 virtual ~EventFactory() {} | |
44 | |
45 virtual EventWrapper* CreateEvent() = 0; | |
46 }; | |
47 | |
48 class EventFactoryImpl : public EventFactory { | |
49 public: | |
50 virtual ~EventFactoryImpl() {} | |
51 | |
52 virtual EventWrapper* CreateEvent() { | |
53 return EventWrapper::Create(); | |
54 } | |
55 }; | |
56 | |
57 // Used to indicate which decode with errors mode should be used. | |
58 enum VCMDecodeErrorMode { | |
59 kNoErrors, // Never decode with errors. Video will freeze | |
60 // if nack is disabled. | |
61 kSelectiveErrors, // Frames that are determined decodable in | |
62 // VCMSessionInfo may be decoded with missing | |
63 // packets. As not all incomplete frames will be | |
64 // decodable, video will freeze if nack is disabled. | |
65 kWithErrors // Release frames as needed. Errors may be | |
66 // introduced as some encoded frames may not be | |
67 // complete. | |
68 }; | |
69 | |
70 class VideoCodingModule : public Module | |
71 { | |
72 public: | |
73 enum SenderNackMode { | |
74 kNackNone, | |
75 kNackAll, | |
76 kNackSelective | |
77 }; | |
78 | |
79 enum ReceiverRobustness { | |
80 kNone, | |
81 kHardNack, | |
82 kSoftNack, | |
83 kReferenceSelection | |
84 }; | |
85 | |
86 static VideoCodingModule* Create( | |
87 Clock* clock, | |
88 VideoEncoderRateObserver* encoder_rate_observer, | |
89 VCMQMSettingsCallback* qm_settings_callback); | |
90 | |
91 static VideoCodingModule* Create(Clock* clock, EventFactory* event_factory); | |
92 | |
93 static void Destroy(VideoCodingModule* module); | |
94 | |
95 // Get number of supported codecs | |
96 // | |
97 // Return value : Number of supported codecs | |
98 static uint8_t NumberOfCodecs(); | |
99 | |
100 // Get supported codec settings with using id | |
101 // | |
102 // Input: | |
103 // - listId : Id or index of the codec to look up | |
104 // - codec : Memory where the codec settings will be stored | |
105 // | |
106 // Return value : VCM_OK, on success | |
107 // VCM_PARAMETER_ERROR if codec not supported or id too
high | |
108 static int32_t Codec(const uint8_t listId, VideoCodec* codec); | |
109 | |
110 // Get supported codec settings using codec type | |
111 // | |
112 // Input: | |
113 // - codecType : The codec type to get settings for | |
114 // - codec : Memory where the codec settings will be stored | |
115 // | |
116 // Return value : VCM_OK, on success | |
117 // VCM_PARAMETER_ERROR if codec not supported | |
118 static int32_t Codec(VideoCodecType codecType, VideoCodec* codec); | |
119 | |
120 /* | |
121 * Sender | |
122 */ | |
123 | |
124 // Registers a codec to be used for encoding. Calling this | |
125 // API multiple times overwrites any previously registered codecs. | |
126 // | |
127 // NOTE: Must be called on the thread that constructed the VCM instance. | |
128 // | |
129 // Input: | |
130 // - sendCodec : Settings for the codec to be registered. | |
131 // - numberOfCores : The number of cores the codec is allowed | |
132 // to use. | |
133 // - maxPayloadSize : The maximum size each payload is allowed | |
134 // to have. Usually MTU - overhead. | |
135 // | |
136 // Return value : VCM_OK, on success. | |
137 // < 0, on error. | |
138 virtual int32_t RegisterSendCodec(const VideoCodec* sendCodec, | |
139 uint32_t numberOfCores, | |
140 uint32_t maxPayloadSize) = 0; | |
141 | |
142 // Get the current send codec in use. | |
143 // | |
144 // If a codec has not been set yet, the |id| property of the return value | |
145 // will be 0 and |name| empty. | |
146 // | |
147 // NOTE: This method intentionally does not hold locks and minimizes data | |
148 // copying. It must be called on the thread where the VCM was constructed. | |
149 virtual const VideoCodec& GetSendCodec() const = 0; | |
150 | |
151 // DEPRECATED: Use GetSendCodec() instead. | |
152 // | |
153 // API to get the current send codec in use. | |
154 // | |
155 // Input: | |
156 // - currentSendCodec : Address where the sendCodec will be written. | |
157 // | |
158 // Return value : VCM_OK, on success. | |
159 // < 0, on error. | |
160 // | |
161 // NOTE: The returned codec information is not guaranteed to be current when | |
162 // the call returns. This method acquires a lock that is aligned with | |
163 // video encoding, so it should be assumed to be allowed to block for | |
164 // several milliseconds. | |
165 virtual int32_t SendCodec(VideoCodec* currentSendCodec) const = 0; | |
166 | |
167 // DEPRECATED: Use GetSendCodec() instead. | |
168 // | |
169 // API to get the current send codec type | |
170 // | |
171 // Return value : Codec type, on success. | |
172 // kVideoCodecUnknown, on error or if no send codec is s
et | |
173 // NOTE: Same notes apply as for SendCodec() above. | |
174 virtual VideoCodecType SendCodec() const = 0; | |
175 | |
176 // Register an external encoder object. This can not be used together with | |
177 // external decoder callbacks. | |
178 // | |
179 // Input: | |
180 // - externalEncoder : Encoder object to be used for encoding frames in
serted | |
181 // with the AddVideoFrame API. | |
182 // - payloadType : The payload type bound which this encoder is bou
nd to. | |
183 // | |
184 // Return value : VCM_OK, on success. | |
185 // < 0, on error. | |
186 virtual int32_t RegisterExternalEncoder(VideoEncoder* externalEncoder, | |
187 uint8_t payloadType, | |
188 bool internalSource = false) = 0; | |
189 | |
190 // API to get currently configured encoder target bitrate in bits/s. | |
191 // | |
192 // Return value : 0, on success. | |
193 // < 0, on error. | |
194 virtual int Bitrate(unsigned int* bitrate) const = 0; | |
195 | |
196 // API to get currently configured encoder target frame rate. | |
197 // | |
198 // Return value : 0, on success. | |
199 // < 0, on error. | |
200 virtual int FrameRate(unsigned int* framerate) const = 0; | |
201 | |
202 // Sets the parameters describing the send channel. These parameters are inp
uts to the | |
203 // Media Optimization inside the VCM and also specifies the target bit rate
for the | |
204 // encoder. Bit rate used by NACK should already be compensated for by the u
ser. | |
205 // | |
206 // Input: | |
207 // - target_bitrate : The target bitrate for VCM in bits/s. | |
208 // - lossRate : Fractions of lost packets the past second. | |
209 // (loss rate in percent = 100 * packetLoss /
255) | |
210 // - rtt : Current round-trip time in ms. | |
211 // | |
212 // Return value : VCM_OK, on success. | |
213 // < 0, on error. | |
214 virtual int32_t SetChannelParameters(uint32_t target_bitrate, | |
215 uint8_t lossRate, | |
216 int64_t rtt) = 0; | |
217 | |
218 // Sets the parameters describing the receive channel. These parameters are
inputs to the | |
219 // Media Optimization inside the VCM. | |
220 // | |
221 // Input: | |
222 // - rtt : Current round-trip time in ms. | |
223 // with the most amount available bandwidth i
n a conference | |
224 // scenario | |
225 // | |
226 // Return value : VCM_OK, on success. | |
227 // < 0, on error. | |
228 virtual int32_t SetReceiveChannelParameters(int64_t rtt) = 0; | |
229 | |
230 // Register a transport callback which will be called to deliver the encoded
data and | |
231 // side information. | |
232 // | |
233 // Input: | |
234 // - transport : The callback object to register. | |
235 // | |
236 // Return value : VCM_OK, on success. | |
237 // < 0, on error. | |
238 virtual int32_t RegisterTransportCallback(VCMPacketizationCallback* transpor
t) = 0; | |
239 | |
240 // Register video output information callback which will be called to delive
r information | |
241 // about the video stream produced by the encoder, for instance the average
frame rate and | |
242 // bit rate. | |
243 // | |
244 // Input: | |
245 // - outputInformation : The callback object to register. | |
246 // | |
247 // Return value : VCM_OK, on success. | |
248 // < 0, on error. | |
249 virtual int32_t RegisterSendStatisticsCallback( | |
250 VCMSendStatisticsCallback* sendStats) = 0; | |
251 | |
252 // Register a video protection callback which will be called to deliver | |
253 // the requested FEC rate and NACK status (on/off). | |
254 // | |
255 // Input: | |
256 // - protection : The callback object to register. | |
257 // | |
258 // Return value : VCM_OK, on success. | |
259 // < 0, on error. | |
260 virtual int32_t RegisterProtectionCallback(VCMProtectionCallback* protection
) = 0; | |
261 | |
262 // Enable or disable a video protection method. | |
263 // | |
264 // Input: | |
265 // - videoProtection : The method to enable or disable. | |
266 // - enable : True if the method should be enabled, false if | |
267 // it should be disabled. | |
268 // | |
269 // Return value : VCM_OK, on success. | |
270 // < 0, on error. | |
271 virtual int32_t SetVideoProtection(VCMVideoProtection videoProtection, | |
272 bool enable) = 0; | |
273 | |
274 // Add one raw video frame to the encoder. This function does all the necess
ary | |
275 // processing, then decides what frame type to encode, or if the frame shoul
d be | |
276 // dropped. If the frame should be encoded it passes the frame to the encode
r | |
277 // before it returns. | |
278 // | |
279 // Input: | |
280 // - videoFrame : Video frame to encode. | |
281 // - codecSpecificInfo : Extra codec information, e.g., pre-parsed in-b
and signaling. | |
282 // | |
283 // Return value : VCM_OK, on success. | |
284 // < 0, on error. | |
285 virtual int32_t AddVideoFrame( | |
286 const VideoFrame& videoFrame, | |
287 const VideoContentMetrics* contentMetrics = NULL, | |
288 const CodecSpecificInfo* codecSpecificInfo = NULL) = 0; | |
289 | |
290 // Next frame encoded should be an intra frame (keyframe). | |
291 // | |
292 // Return value : VCM_OK, on success. | |
293 // < 0, on error. | |
294 virtual int32_t IntraFrameRequest(int stream_index) = 0; | |
295 | |
296 // Frame Dropper enable. Can be used to disable the frame dropping when the
encoder | |
297 // over-uses its bit rate. This API is designed to be used when the encoded
frames | |
298 // are supposed to be stored to an AVI file, or when the I420 codec is used
and the | |
299 // target bit rate shouldn't affect the frame rate. | |
300 // | |
301 // Input: | |
302 // - enable : True to enable the setting, false to disable i
t. | |
303 // | |
304 // Return value : VCM_OK, on success. | |
305 // < 0, on error. | |
306 virtual int32_t EnableFrameDropper(bool enable) = 0; | |
307 | |
308 | |
309 /* | |
310 * Receiver | |
311 */ | |
312 | |
313 // Register possible receive codecs, can be called multiple times for differ
ent codecs. | |
314 // The module will automatically switch between registered codecs depending
on the | |
315 // payload type of incoming frames. The actual decoder will be created when
needed. | |
316 // | |
317 // Input: | |
318 // - receiveCodec : Settings for the codec to be registered. | |
319 // - numberOfCores : Number of CPU cores that the decoder is allowe
d to use. | |
320 // - requireKeyFrame : Set this to true if you don't want any delta f
rames | |
321 // to be decoded until the first key frame has be
en decoded. | |
322 // | |
323 // Return value : VCM_OK, on success. | |
324 // < 0, on error. | |
325 virtual int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec, | |
326 int32_t numberOfCores, | |
327 bool requireKeyFrame = false) = 0; | |
328 | |
329 // Register an externally defined decoder/renderer object. Can be a decoder
only or a | |
330 // decoder coupled with a renderer. Note that RegisterReceiveCodec must be c
alled to | |
331 // be used for decoding incoming streams. | |
332 // | |
333 // Input: | |
334 // - externalDecoder : The external decoder/renderer object. | |
335 // - payloadType : The payload type which this decoder shoul
d be | |
336 // registered to. | |
337 // - internalRenderTiming : True if the internal renderer (if any) of
the decoder | |
338 // object can make sure to render at a given
time in ms. | |
339 // | |
340 // Return value : VCM_OK, on success. | |
341 // < 0, on error. | |
342 virtual int32_t RegisterExternalDecoder(VideoDecoder* externalDecoder, | |
343 uint8_t payloadType, | |
344 bool internalRenderTiming) = 0; | |
345 | |
346 // Register a receive callback. Will be called whenever there is a new frame
ready | |
347 // for rendering. | |
348 // | |
349 // Input: | |
350 // - receiveCallback : The callback object to be used by the mod
ule when a | |
351 // frame is ready for rendering. | |
352 // De-register with a NULL pointer. | |
353 // | |
354 // Return value : VCM_OK, on success. | |
355 // < 0, on error. | |
356 virtual int32_t RegisterReceiveCallback(VCMReceiveCallback* receiveCallback)
= 0; | |
357 | |
358 // Register a receive statistics callback which will be called to deliver in
formation | |
359 // about the video stream received by the receiving side of the VCM, for ins
tance the | |
360 // average frame rate and bit rate. | |
361 // | |
362 // Input: | |
363 // - receiveStats : The callback object to register. | |
364 // | |
365 // Return value : VCM_OK, on success. | |
366 // < 0, on error. | |
367 virtual int32_t RegisterReceiveStatisticsCallback( | |
368 VCMReceiveStatisticsCallback* receiveStats) = 0; | |
369 | |
370 // Register a decoder timing callback which will be called to deliver | |
371 // information about the timing of the decoder in the receiving side of the | |
372 // VCM, for instance the current and maximum frame decode latency. | |
373 // | |
374 // Input: | |
375 // - decoderTiming : The callback object to register. | |
376 // | |
377 // Return value : VCM_OK, on success. | |
378 // < 0, on error. | |
379 virtual int32_t RegisterDecoderTimingCallback( | |
380 VCMDecoderTimingCallback* decoderTiming) = 0; | |
381 | |
382 // Register a frame type request callback. This callback will be called when
the | |
383 // module needs to request specific frame types from the send side. | |
384 // | |
385 // Input: | |
386 // - frameTypeCallback : The callback object to be used by the mod
ule when | |
387 // requesting a specific type of frame from
the send side. | |
388 // De-register with a NULL pointer. | |
389 // | |
390 // Return value : VCM_OK, on success. | |
391 // < 0, on error. | |
392 virtual int32_t RegisterFrameTypeCallback( | |
393 VCMFrameTypeCallback* frameTypeCallback) = 0; | |
394 | |
395 // Registers a callback which is called whenever the receive side of the VCM | |
396 // encounters holes in the packet sequence and needs packets to be retransmi
tted. | |
397 // | |
398 // Input: | |
399 // - callback : The callback to be registered in the VCM. | |
400 // | |
401 // Return value : VCM_OK, on success. | |
402 // <0, on error. | |
403 virtual int32_t RegisterPacketRequestCallback( | |
404 VCMPacketRequestCallback* callback) = 0; | |
405 | |
406 // Waits for the next frame in the jitter buffer to become complete | |
407 // (waits no longer than maxWaitTimeMs), then passes it to the decoder for d
ecoding. | |
408 // Should be called as often as possible to get the most out of the decoder. | |
409 // | |
410 // Return value : VCM_OK, on success. | |
411 // < 0, on error. | |
412 virtual int32_t Decode(uint16_t maxWaitTimeMs = 200) = 0; | |
413 | |
414 // Registers a callback which conveys the size of the render buffer. | |
415 virtual int RegisterRenderBufferSizeCallback( | |
416 VCMRenderBufferSizeCallback* callback) = 0; | |
417 | |
418 // Reset the decoder state to the initial state. | |
419 // | |
420 // Return value : VCM_OK, on success. | |
421 // < 0, on error. | |
422 virtual int32_t ResetDecoder() = 0; | |
423 | |
424 // API to get the codec which is currently used for decoding by the module. | |
425 // | |
426 // Input: | |
427 // - currentReceiveCodec : Settings for the codec to be registered
. | |
428 // | |
429 // Return value : VCM_OK, on success. | |
430 // < 0, on error. | |
431 virtual int32_t ReceiveCodec(VideoCodec* currentReceiveCodec) const = 0; | |
432 | |
433 // API to get the codec type currently used for decoding by the module. | |
434 // | |
435 // Return value : codecy type, on success. | |
436 // kVideoCodecUnknown, on error or if no receive codec i
s registered | |
437 virtual VideoCodecType ReceiveCodec() const = 0; | |
438 | |
439 // Insert a parsed packet into the receiver side of the module. Will be plac
ed in the | |
440 // jitter buffer waiting for the frame to become complete. Returns as soon a
s the packet | |
441 // has been placed in the jitter buffer. | |
442 // | |
443 // Input: | |
444 // - incomingPayload : Payload of the packet. | |
445 // - payloadLength : Length of the payload. | |
446 // - rtpInfo : The parsed header. | |
447 // | |
448 // Return value : VCM_OK, on success. | |
449 // < 0, on error. | |
450 virtual int32_t IncomingPacket(const uint8_t* incomingPayload, | |
451 size_t payloadLength, | |
452 const WebRtcRTPHeader& rtpInfo) = 0; | |
453 | |
454 // Minimum playout delay (Used for lip-sync). This is the minimum delay requ
ired | |
455 // to sync with audio. Not included in VideoCodingModule::Delay() | |
456 // Defaults to 0 ms. | |
457 // | |
458 // Input: | |
459 // - minPlayoutDelayMs : Additional delay in ms. | |
460 // | |
461 // Return value : VCM_OK, on success. | |
462 // < 0, on error. | |
463 virtual int32_t SetMinimumPlayoutDelay(uint32_t minPlayoutDelayMs) = 0; | |
464 | |
465 // Set the time required by the renderer to render a frame. | |
466 // | |
467 // Input: | |
468 // - timeMS : The time in ms required by the renderer to render
a frame. | |
469 // | |
470 // Return value : VCM_OK, on success. | |
471 // < 0, on error. | |
472 virtual int32_t SetRenderDelay(uint32_t timeMS) = 0; | |
473 | |
474 // The total delay desired by the VCM. Can be less than the minimum | |
475 // delay set with SetMinimumPlayoutDelay. | |
476 // | |
477 // Return value : Total delay in ms, on success. | |
478 // < 0, on error. | |
479 virtual int32_t Delay() const = 0; | |
480 | |
481 // Returns the number of packets discarded by the jitter buffer due to being | |
482 // too late. This can include duplicated packets which arrived after the | |
483 // frame was sent to the decoder. Therefore packets which were prematurely | |
484 // NACKed will be counted. | |
485 virtual uint32_t DiscardedPackets() const = 0; | |
486 | |
487 | |
488 // Robustness APIs | |
489 | |
490 // Set the receiver robustness mode. The mode decides how the receiver | |
491 // responds to losses in the stream. The type of counter-measure (soft or | |
492 // hard NACK, dual decoder, RPS, etc.) is selected through the | |
493 // robustnessMode parameter. The errorMode parameter decides if it is | |
494 // allowed to display frames corrupted by losses. Note that not all | |
495 // combinations of the two parameters are feasible. An error will be | |
496 // returned for invalid combinations. | |
497 // Input: | |
498 // - robustnessMode : selected robustness mode. | |
499 // - errorMode : selected error mode. | |
500 // | |
501 // Return value : VCM_OK, on success; | |
502 // < 0, on error. | |
503 virtual int SetReceiverRobustnessMode(ReceiverRobustness robustnessMode, | |
504 VCMDecodeErrorMode errorMode) = 0; | |
505 | |
506 // Set the decode error mode. The mode decides which errors (if any) are | |
507 // allowed in decodable frames. Note that setting decode_error_mode to | |
508 // anything other than kWithErrors without enabling nack will cause | |
509 // long-term freezes (resulting from frequent key frame requests) if | |
510 // packet loss occurs. | |
511 virtual void SetDecodeErrorMode(VCMDecodeErrorMode decode_error_mode) = 0; | |
512 | |
513 // Sets the maximum number of sequence numbers that we are allowed to NACK | |
514 // and the oldest sequence number that we will consider to NACK. If a | |
515 // sequence number older than |max_packet_age_to_nack| is missing | |
516 // a key frame will be requested. A key frame will also be requested if the | |
517 // time of incomplete or non-continuous frames in the jitter buffer is above | |
518 // |max_incomplete_time_ms|. | |
519 virtual void SetNackSettings(size_t max_nack_list_size, | |
520 int max_packet_age_to_nack, | |
521 int max_incomplete_time_ms) = 0; | |
522 | |
523 // Setting a desired delay to the VCM receiver. Video rendering will be | |
524 // delayed by at least desired_delay_ms. | |
525 virtual int SetMinReceiverDelay(int desired_delay_ms) = 0; | |
526 | |
527 // Lets the sender suspend video when the rate drops below | |
528 // |threshold_bps|, and turns back on when the rate goes back up above | |
529 // |threshold_bps| + |window_bps|. | |
530 virtual void SuspendBelowMinBitrate() = 0; | |
531 | |
532 // Returns true if SuspendBelowMinBitrate is engaged and the video has been | |
533 // suspended due to bandwidth limitations; otherwise false. | |
534 virtual bool VideoSuspended() const = 0; | |
535 | |
536 virtual void RegisterPreDecodeImageCallback( | |
537 EncodedImageCallback* observer) = 0; | |
538 virtual void RegisterPostEncodeImageCallback( | |
539 EncodedImageCallback* post_encode_callback) = 0; | |
540 // Releases pending decode calls, permitting faster thread shutdown. | |
541 virtual void TriggerDecoderShutdown() = 0; | |
542 }; | |
543 | |
544 } // namespace webrtc | |
545 | |
546 #endif // WEBRTC_MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_ | |
OLD | NEW |