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