Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_ |
| 12 | #define MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_ |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 13 | |
Ying Wang | 3b790f3 | 2018-01-19 17:58:57 +0100 | [diff] [blame] | 14 | #include "api/fec_controller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "api/video/video_frame.h" |
Niels Möller | a46bd4b | 2018-06-08 14:03:44 +0200 | [diff] [blame] | 16 | #include "api/video_codecs/video_codec.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #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öller | 689983f | 2018-11-07 16:36:22 +0100 | [diff] [blame] | 20 | #include "rtc_base/deprecation.h" |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 21 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 22 | namespace webrtc { |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 23 | |
| 24 | class Clock; |
| 25 | class EncodedImageCallback; |
Anders Carlsson | 7eb8e9f | 2018-05-18 10:33:04 +0200 | [diff] [blame] | 26 | class VideoDecoder; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 27 | class VideoEncoder; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 28 | struct CodecSpecificInfo; |
| 29 | |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 30 | // Used to indicate which decode with errors mode should be used. |
| 31 | enum VCMDecodeErrorMode { |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 32 | 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 Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 41 | }; |
| 42 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 43 | class VideoCodingModule : public Module { |
| 44 | public: |
| 45 | enum SenderNackMode { kNackNone, kNackAll, kNackSelective }; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 46 | |
tommi | a5c18d7 | 2017-03-20 10:43:23 -0700 | [diff] [blame] | 47 | // DEPRECATED. |
Niels Möller | 689983f | 2018-11-07 16:36:22 +0100 | [diff] [blame] | 48 | static VideoCodingModule* Create(Clock* clock); |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 49 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 50 | /* |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 51 | * Receiver |
| 52 | */ |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 53 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 54 | // Register possible receive codecs, can be called multiple times for |
| 55 | // different codecs. |
| 56 | // The module will automatically switch between registered codecs depending on |
| 57 | // the |
| 58 | // payload type of incoming frames. The actual decoder will be created when |
| 59 | // needed. |
| 60 | // |
| 61 | // Input: |
| 62 | // - receiveCodec : Settings for the codec to be registered. |
| 63 | // - numberOfCores : Number of CPU cores that the decoder is allowed |
| 64 | // to use. |
| 65 | // - requireKeyFrame : Set this to true if you don't want any delta |
| 66 | // frames |
| 67 | // to be decoded until the first key frame has been |
| 68 | // decoded. |
| 69 | // |
| 70 | // Return value : VCM_OK, on success. |
| 71 | // < 0, on error. |
| 72 | virtual int32_t RegisterReceiveCodec(const VideoCodec* receiveCodec, |
| 73 | int32_t numberOfCores, |
| 74 | bool requireKeyFrame = false) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 75 | |
Anders Carlsson | 7eb8e9f | 2018-05-18 10:33:04 +0200 | [diff] [blame] | 76 | // Register an external decoder object. |
| 77 | // |
| 78 | // Input: |
| 79 | // - externalDecoder : Decoder object to be used for decoding frames. |
| 80 | // - payloadType : The payload type which this decoder is bound to. |
| 81 | virtual void RegisterExternalDecoder(VideoDecoder* externalDecoder, |
| 82 | uint8_t payloadType) = 0; |
| 83 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 84 | // Register a receive callback. Will be called whenever there is a new frame |
| 85 | // ready |
| 86 | // for rendering. |
| 87 | // |
| 88 | // Input: |
| 89 | // - receiveCallback : The callback object to be used by the |
| 90 | // module when a |
| 91 | // frame is ready for rendering. |
| 92 | // De-register with a NULL pointer. |
| 93 | // |
| 94 | // Return value : VCM_OK, on success. |
| 95 | // < 0, on error. |
| 96 | virtual int32_t RegisterReceiveCallback( |
| 97 | VCMReceiveCallback* receiveCallback) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 98 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 99 | // Register a frame type request callback. This callback will be called when |
| 100 | // the |
| 101 | // module needs to request specific frame types from the send side. |
| 102 | // |
| 103 | // Input: |
| 104 | // - frameTypeCallback : The callback object to be used by the |
| 105 | // module when |
| 106 | // requesting a specific type of frame from |
| 107 | // the send side. |
| 108 | // De-register with a NULL pointer. |
| 109 | // |
| 110 | // Return value : VCM_OK, on success. |
| 111 | // < 0, on error. |
| 112 | virtual int32_t RegisterFrameTypeCallback( |
| 113 | VCMFrameTypeCallback* frameTypeCallback) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 114 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 115 | // Registers a callback which is called whenever the receive side of the VCM |
| 116 | // encounters holes in the packet sequence and needs packets to be |
| 117 | // retransmitted. |
| 118 | // |
| 119 | // Input: |
| 120 | // - callback : The callback to be registered in the VCM. |
| 121 | // |
| 122 | // Return value : VCM_OK, on success. |
| 123 | // <0, on error. |
| 124 | virtual int32_t RegisterPacketRequestCallback( |
| 125 | VCMPacketRequestCallback* callback) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 126 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 127 | // Waits for the next frame in the jitter buffer to become complete |
| 128 | // (waits no longer than maxWaitTimeMs), then passes it to the decoder for |
| 129 | // decoding. |
| 130 | // Should be called as often as possible to get the most out of the decoder. |
| 131 | // |
| 132 | // Return value : VCM_OK, on success. |
| 133 | // < 0, on error. |
| 134 | virtual int32_t Decode(uint16_t maxWaitTimeMs = 200) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 135 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 136 | // Insert a parsed packet into the receiver side of the module. Will be placed |
| 137 | // in the |
| 138 | // jitter buffer waiting for the frame to become complete. Returns as soon as |
| 139 | // the packet |
| 140 | // has been placed in the jitter buffer. |
| 141 | // |
| 142 | // Input: |
| 143 | // - incomingPayload : Payload of the packet. |
| 144 | // - payloadLength : Length of the payload. |
| 145 | // - rtpInfo : The parsed header. |
| 146 | // |
| 147 | // Return value : VCM_OK, on success. |
| 148 | // < 0, on error. |
| 149 | virtual int32_t IncomingPacket(const uint8_t* incomingPayload, |
| 150 | size_t payloadLength, |
| 151 | const WebRtcRTPHeader& rtpInfo) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 152 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 153 | // Robustness APIs |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 154 | |
tommi | a5c18d7 | 2017-03-20 10:43:23 -0700 | [diff] [blame] | 155 | // DEPRECATED. |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 156 | // Set the receiver robustness mode. The mode decides how the receiver |
tommi | a5c18d7 | 2017-03-20 10:43:23 -0700 | [diff] [blame] | 157 | // responds to losses in the stream. The type of counter-measure is selected |
| 158 | // through the robustnessMode parameter. The errorMode parameter decides if it |
| 159 | // is allowed to display frames corrupted by losses. Note that not all |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 160 | // combinations of the two parameters are feasible. An error will be |
| 161 | // returned for invalid combinations. |
| 162 | // Input: |
| 163 | // - robustnessMode : selected robustness mode. |
| 164 | // - errorMode : selected error mode. |
| 165 | // |
| 166 | // Return value : VCM_OK, on success; |
| 167 | // < 0, on error. |
tommi | a5c18d7 | 2017-03-20 10:43:23 -0700 | [diff] [blame] | 168 | enum ReceiverRobustness { kNone, kHardNack }; |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 169 | virtual int SetReceiverRobustnessMode(ReceiverRobustness robustnessMode, |
| 170 | VCMDecodeErrorMode errorMode) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 171 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 172 | // Sets the maximum number of sequence numbers that we are allowed to NACK |
| 173 | // and the oldest sequence number that we will consider to NACK. If a |
| 174 | // sequence number older than |max_packet_age_to_nack| is missing |
| 175 | // a key frame will be requested. A key frame will also be requested if the |
| 176 | // time of incomplete or non-continuous frames in the jitter buffer is above |
| 177 | // |max_incomplete_time_ms|. |
| 178 | virtual void SetNackSettings(size_t max_nack_list_size, |
| 179 | int max_packet_age_to_nack, |
| 180 | int max_incomplete_time_ms) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | } // namespace webrtc |
| 184 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 185 | #endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_ |