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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "api/video/video_frame.h" |
Niels Möller | a46bd4b | 2018-06-08 14:03:44 +0200 | [diff] [blame] | 15 | #include "api/video_codecs/video_codec.h" |
Danil Chapovalov | 355b8d2 | 2021-08-13 16:50:37 +0200 | [diff] [blame^] | 16 | #include "api/video_codecs/video_decoder.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/include/module.h" |
Niels Möller | 834a554 | 2019-09-23 10:31:16 +0200 | [diff] [blame] | 18 | #include "modules/rtp_rtcp/source/rtp_video_header.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "modules/video_coding/include/video_coding_defines.h" |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 20 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 21 | namespace webrtc { |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 22 | |
| 23 | class Clock; |
| 24 | class EncodedImageCallback; |
Anders Carlsson | 7eb8e9f | 2018-05-18 10:33:04 +0200 | [diff] [blame] | 25 | class VideoDecoder; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 26 | class VideoEncoder; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 27 | struct CodecSpecificInfo; |
| 28 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 29 | class VideoCodingModule : public Module { |
| 30 | public: |
tommi | a5c18d7 | 2017-03-20 10:43:23 -0700 | [diff] [blame] | 31 | // DEPRECATED. |
Niels Möller | 689983f | 2018-11-07 16:36:22 +0100 | [diff] [blame] | 32 | static VideoCodingModule* Create(Clock* clock); |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 33 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 34 | /* |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 35 | * Receiver |
| 36 | */ |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 37 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 38 | // Register possible receive codecs, can be called multiple times for |
| 39 | // different codecs. |
| 40 | // The module will automatically switch between registered codecs depending on |
| 41 | // the |
| 42 | // payload type of incoming frames. The actual decoder will be created when |
| 43 | // needed. |
| 44 | // |
| 45 | // Input: |
Niels Möller | 582102c | 2020-08-07 16:19:56 +0200 | [diff] [blame] | 46 | // - payload_type : RTP payload type |
Danil Chapovalov | 355b8d2 | 2021-08-13 16:50:37 +0200 | [diff] [blame^] | 47 | // - settings : Settings for the decoder to be registered. |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 48 | // |
Danil Chapovalov | 355b8d2 | 2021-08-13 16:50:37 +0200 | [diff] [blame^] | 49 | // Return value : true, on success. |
| 50 | // false, on error. |
| 51 | virtual bool RegisterReceiveCodec(uint8_t payload_type, |
| 52 | const VideoDecoder::Settings& settings) = 0; |
| 53 | ABSL_DEPRECATED("Use RegisterReceiveCodec above") |
Niels Möller | 582102c | 2020-08-07 16:19:56 +0200 | [diff] [blame] | 54 | virtual int32_t RegisterReceiveCodec(uint8_t payload_type, |
| 55 | const VideoCodec* receiveCodec, |
| 56 | int32_t numberOfCores) = 0; |
| 57 | |
Anders Carlsson | 7eb8e9f | 2018-05-18 10:33:04 +0200 | [diff] [blame] | 58 | // Register an external decoder object. |
| 59 | // |
| 60 | // Input: |
| 61 | // - externalDecoder : Decoder object to be used for decoding frames. |
| 62 | // - payloadType : The payload type which this decoder is bound to. |
| 63 | virtual void RegisterExternalDecoder(VideoDecoder* externalDecoder, |
| 64 | uint8_t payloadType) = 0; |
| 65 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 66 | // Register a receive callback. Will be called whenever there is a new frame |
| 67 | // ready |
| 68 | // for rendering. |
| 69 | // |
| 70 | // Input: |
| 71 | // - receiveCallback : The callback object to be used by the |
| 72 | // module when a |
| 73 | // frame is ready for rendering. |
| 74 | // De-register with a NULL pointer. |
| 75 | // |
| 76 | // Return value : VCM_OK, on success. |
| 77 | // < 0, on error. |
| 78 | virtual int32_t RegisterReceiveCallback( |
| 79 | VCMReceiveCallback* receiveCallback) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 80 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 81 | // Register a frame type request callback. This callback will be called when |
| 82 | // the |
| 83 | // module needs to request specific frame types from the send side. |
| 84 | // |
| 85 | // Input: |
| 86 | // - frameTypeCallback : The callback object to be used by the |
| 87 | // module when |
| 88 | // requesting a specific type of frame from |
| 89 | // the send side. |
| 90 | // De-register with a NULL pointer. |
| 91 | // |
| 92 | // Return value : VCM_OK, on success. |
| 93 | // < 0, on error. |
| 94 | virtual int32_t RegisterFrameTypeCallback( |
| 95 | VCMFrameTypeCallback* frameTypeCallback) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 96 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 97 | // Registers a callback which is called whenever the receive side of the VCM |
| 98 | // encounters holes in the packet sequence and needs packets to be |
| 99 | // retransmitted. |
| 100 | // |
| 101 | // Input: |
| 102 | // - callback : The callback to be registered in the VCM. |
| 103 | // |
| 104 | // Return value : VCM_OK, on success. |
| 105 | // <0, on error. |
| 106 | virtual int32_t RegisterPacketRequestCallback( |
| 107 | VCMPacketRequestCallback* callback) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 108 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 109 | // Waits for the next frame in the jitter buffer to become complete |
| 110 | // (waits no longer than maxWaitTimeMs), then passes it to the decoder for |
| 111 | // decoding. |
| 112 | // Should be called as often as possible to get the most out of the decoder. |
| 113 | // |
| 114 | // Return value : VCM_OK, on success. |
| 115 | // < 0, on error. |
| 116 | virtual int32_t Decode(uint16_t maxWaitTimeMs = 200) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 117 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 118 | // Insert a parsed packet into the receiver side of the module. Will be placed |
| 119 | // in the |
| 120 | // jitter buffer waiting for the frame to become complete. Returns as soon as |
| 121 | // the packet |
| 122 | // has been placed in the jitter buffer. |
| 123 | // |
| 124 | // Input: |
| 125 | // - incomingPayload : Payload of the packet. |
| 126 | // - payloadLength : Length of the payload. |
Niels Möller | be7a0ec | 2019-04-25 10:02:52 +0200 | [diff] [blame] | 127 | // - rtp_header : The parsed RTP header. |
| 128 | // - video_header : The relevant extensions and payload header. |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 129 | // |
| 130 | // Return value : VCM_OK, on success. |
| 131 | // < 0, on error. |
| 132 | virtual int32_t IncomingPacket(const uint8_t* incomingPayload, |
| 133 | size_t payloadLength, |
Niels Möller | be7a0ec | 2019-04-25 10:02:52 +0200 | [diff] [blame] | 134 | const RTPHeader& rtp_header, |
| 135 | const RTPVideoHeader& video_header) = 0; |
| 136 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 137 | // Sets the maximum number of sequence numbers that we are allowed to NACK |
| 138 | // and the oldest sequence number that we will consider to NACK. If a |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 139 | // sequence number older than `max_packet_age_to_nack` is missing |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 140 | // a key frame will be requested. A key frame will also be requested if the |
| 141 | // time of incomplete or non-continuous frames in the jitter buffer is above |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 142 | // `max_incomplete_time_ms`. |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 143 | virtual void SetNackSettings(size_t max_nack_list_size, |
| 144 | int max_packet_age_to_nack, |
| 145 | int max_incomplete_time_ms) = 0; |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | } // namespace webrtc |
| 149 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 150 | #endif // MODULES_VIDEO_CODING_INCLUDE_VIDEO_CODING_H_ |