blob: 1eb60d4bb2327b723ccdf6532f752562e54626d5 [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
Ying Wang3b790f32018-01-19 17:58:57 +010014#include "api/fec_controller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "api/video/video_frame.h"
Niels Möllera46bd4b2018-06-08 14:03:44 +020016#include "api/video_codecs/video_codec.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/include/module.h"
18#include "modules/include/module_common_types.h"
19#include "modules/video_coding/include/video_coding_defines.h"
Niels Möller689983f2018-11-07 16:36:22 +010020#include "rtc_base/deprecation.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010021
philipel9d3ab612015-12-21 04:12:39 -080022namespace webrtc {
Henrik Kjellander2557b862015-11-18 22:00:21 +010023
24class Clock;
25class EncodedImageCallback;
Anders Carlsson7eb8e9f2018-05-18 10:33:04 +020026class VideoDecoder;
Henrik Kjellander2557b862015-11-18 22:00:21 +010027class VideoEncoder;
Henrik Kjellander2557b862015-11-18 22:00:21 +010028struct CodecSpecificInfo;
29
Henrik Kjellander2557b862015-11-18 22:00:21 +010030// Used to indicate which decode with errors mode should be used.
31enum VCMDecodeErrorMode {
philipel9d3ab612015-12-21 04:12:39 -080032 kNoErrors, // Never decode with errors. Video will freeze
33 // if nack is disabled.
34 kSelectiveErrors, // Frames that are determined decodable in
35 // VCMSessionInfo may be decoded with missing
36 // packets. As not all incomplete frames will be
37 // decodable, video will freeze if nack is disabled.
38 kWithErrors // Release frames as needed. Errors may be
39 // introduced as some encoded frames may not be
40 // complete.
Henrik Kjellander2557b862015-11-18 22:00:21 +010041};
42
philipel9d3ab612015-12-21 04:12:39 -080043class VideoCodingModule : public Module {
44 public:
45 enum SenderNackMode { kNackNone, kNackAll, kNackSelective };
Henrik Kjellander2557b862015-11-18 22:00:21 +010046
tommia5c18d72017-03-20 10:43:23 -070047 // DEPRECATED.
Niels Möller689983f2018-11-07 16:36:22 +010048 static VideoCodingModule* Create(Clock* clock);
Henrik Kjellander2557b862015-11-18 22:00:21 +010049
philipel9d3ab612015-12-21 04:12:39 -080050 // Enable or disable a video protection method.
51 //
52 // Input:
53 // - videoProtection : The method to enable or disable.
54 // - enable : True if the method should be enabled, false if
55 // it should be disabled.
56 //
57 // Return value : VCM_OK, on success.
58 // < 0, on error.
59 virtual int32_t SetVideoProtection(VCMVideoProtection videoProtection,
60 bool enable) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +010061
philipel9d3ab612015-12-21 04:12:39 -080062 /*
Yves Gerey665174f2018-06-19 15:03:05 +020063 * Receiver
64 */
Henrik Kjellander2557b862015-11-18 22:00:21 +010065
philipel9d3ab612015-12-21 04:12:39 -080066 // Register possible receive codecs, can be called multiple times for
67 // different codecs.
68 // The module will automatically switch between registered codecs depending on
69 // the
70 // payload type of incoming frames. The actual decoder will be created when
71 // needed.
72 //
73 // Input:
74 // - receiveCodec : Settings for the codec to be registered.
75 // - numberOfCores : Number of CPU cores that the decoder is allowed
76 // to use.
77 // - requireKeyFrame : Set this to true if you don't want any delta
78 // frames
79 // to be decoded until the first key frame has been
80 // decoded.
81 //
82 // Return value : VCM_OK, on success.
83 // < 0, on error.
84 virtual int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec,
85 int32_t numberOfCores,
86 bool requireKeyFrame = false) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +010087
Anders Carlsson7eb8e9f2018-05-18 10:33:04 +020088 // Register an external decoder object.
89 //
90 // Input:
91 // - externalDecoder : Decoder object to be used for decoding frames.
92 // - payloadType : The payload type which this decoder is bound to.
93 virtual void RegisterExternalDecoder(VideoDecoder* externalDecoder,
94 uint8_t payloadType) = 0;
95
philipel9d3ab612015-12-21 04:12:39 -080096 // Register a receive callback. Will be called whenever there is a new frame
97 // ready
98 // for rendering.
99 //
100 // Input:
101 // - receiveCallback : The callback object to be used by the
102 // module when a
103 // frame is ready for rendering.
104 // De-register with a NULL pointer.
105 //
106 // Return value : VCM_OK, on success.
107 // < 0, on error.
108 virtual int32_t RegisterReceiveCallback(
109 VCMReceiveCallback* receiveCallback) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100110
philipel9d3ab612015-12-21 04:12:39 -0800111 // Register a frame type request callback. This callback will be called when
112 // the
113 // module needs to request specific frame types from the send side.
114 //
115 // Input:
116 // - frameTypeCallback : The callback object to be used by the
117 // module when
118 // requesting a specific type of frame from
119 // the send side.
120 // De-register with a NULL pointer.
121 //
122 // Return value : VCM_OK, on success.
123 // < 0, on error.
124 virtual int32_t RegisterFrameTypeCallback(
125 VCMFrameTypeCallback* frameTypeCallback) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100126
philipel9d3ab612015-12-21 04:12:39 -0800127 // Registers a callback which is called whenever the receive side of the VCM
128 // encounters holes in the packet sequence and needs packets to be
129 // retransmitted.
130 //
131 // Input:
132 // - callback : The callback to be registered in the VCM.
133 //
134 // Return value : VCM_OK, on success.
135 // <0, on error.
136 virtual int32_t RegisterPacketRequestCallback(
137 VCMPacketRequestCallback* callback) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100138
philipel9d3ab612015-12-21 04:12:39 -0800139 // Waits for the next frame in the jitter buffer to become complete
140 // (waits no longer than maxWaitTimeMs), then passes it to the decoder for
141 // decoding.
142 // Should be called as often as possible to get the most out of the decoder.
143 //
144 // Return value : VCM_OK, on success.
145 // < 0, on error.
146 virtual int32_t Decode(uint16_t maxWaitTimeMs = 200) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100147
philipel9d3ab612015-12-21 04:12:39 -0800148 // Insert a parsed packet into the receiver side of the module. Will be placed
149 // in the
150 // jitter buffer waiting for the frame to become complete. Returns as soon as
151 // the packet
152 // has been placed in the jitter buffer.
153 //
154 // Input:
155 // - incomingPayload : Payload of the packet.
156 // - payloadLength : Length of the payload.
157 // - rtpInfo : The parsed header.
158 //
159 // Return value : VCM_OK, on success.
160 // < 0, on error.
161 virtual int32_t IncomingPacket(const uint8_t* incomingPayload,
162 size_t payloadLength,
163 const WebRtcRTPHeader& rtpInfo) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100164
philipel9d3ab612015-12-21 04:12:39 -0800165 // Robustness APIs
Henrik Kjellander2557b862015-11-18 22:00:21 +0100166
tommia5c18d72017-03-20 10:43:23 -0700167 // DEPRECATED.
philipel9d3ab612015-12-21 04:12:39 -0800168 // Set the receiver robustness mode. The mode decides how the receiver
tommia5c18d72017-03-20 10:43:23 -0700169 // responds to losses in the stream. The type of counter-measure is selected
170 // through the robustnessMode parameter. The errorMode parameter decides if it
171 // is allowed to display frames corrupted by losses. Note that not all
philipel9d3ab612015-12-21 04:12:39 -0800172 // combinations of the two parameters are feasible. An error will be
173 // returned for invalid combinations.
174 // Input:
175 // - robustnessMode : selected robustness mode.
176 // - errorMode : selected error mode.
177 //
178 // Return value : VCM_OK, on success;
179 // < 0, on error.
tommia5c18d72017-03-20 10:43:23 -0700180 enum ReceiverRobustness { kNone, kHardNack };
philipel9d3ab612015-12-21 04:12:39 -0800181 virtual int SetReceiverRobustnessMode(ReceiverRobustness robustnessMode,
182 VCMDecodeErrorMode errorMode) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100183
philipel9d3ab612015-12-21 04:12:39 -0800184 // Sets the maximum number of sequence numbers that we are allowed to NACK
185 // and the oldest sequence number that we will consider to NACK. If a
186 // sequence number older than |max_packet_age_to_nack| is missing
187 // a key frame will be requested. A key frame will also be requested if the
188 // time of incomplete or non-continuous frames in the jitter buffer is above
189 // |max_incomplete_time_ms|.
190 virtual void SetNackSettings(size_t max_nack_list_size,
191 int max_packet_age_to_nack,
192 int max_incomplete_time_ms) = 0;
Henrik Kjellander2557b862015-11-18 22:00:21 +0100193};
194
195} // namespace webrtc
196
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200197#endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_