| Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 API_FEC_CONTROLLER_H_ |
| 12 | #define API_FEC_CONTROLLER_H_ |
| 13 | |
| Dor Hen | 28ce65c | 2024-09-04 11:55:22 | [diff] [blame] | 14 | #include <cstddef> |
| 15 | #include <cstdint> |
| Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 16 | #include <memory> |
| Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
| Danil Chapovalov | 55a6189 | 2024-01-03 17:39:27 | [diff] [blame] | 19 | #include "api/environment/environment.h" |
| Niels Möller | 8f7ce22 | 2019-03-21 14:43:58 | [diff] [blame] | 20 | #include "api/video/video_frame_type.h" |
| Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 21 | #include "modules/include/module_fec_types.h" |
| Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | // TODO(yinwa): work in progress. API in class FecController should not be |
| 25 | // used by other users until this comment is removed. |
| 26 | |
| 27 | // Callback class used for telling the user about how to configure the FEC, |
| 28 | // and the rates sent the last second is returned to the VCM. |
| 29 | class VCMProtectionCallback { |
| 30 | public: |
| 31 | virtual int ProtectionRequest(const FecProtectionParams* delta_params, |
| 32 | const FecProtectionParams* key_params, |
| 33 | uint32_t* sent_video_rate_bps, |
| 34 | uint32_t* sent_nack_rate_bps, |
| 35 | uint32_t* sent_fec_rate_bps) = 0; |
| 36 | |
| Ying Wang | 2d59853 | 2023-06-01 05:55:36 | [diff] [blame] | 37 | // 'retransmission_mode' is either a value of enum RetransmissionMode, or |
| 38 | // computed with bitwise operators on values of enum RetransmissionMode. |
| 39 | virtual void SetRetransmissionMode(int retransmission_mode) = 0; |
| Boris Tsirkin | 932e361 | 2025-01-07 10:40:37 | [diff] [blame] | 40 | |
| Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 41 | protected: |
| 42 | virtual ~VCMProtectionCallback() {} |
| 43 | }; |
| 44 | |
| 45 | // FecController calculates how much of the allocated network |
| 46 | // capacity that can be used by an encoder and how much that |
| 47 | // is needed for redundant packets such as FEC and NACK. It uses an |
| Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 48 | // implementation of `VCMProtectionCallback` to set new FEC parameters and get |
| Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 49 | // the bitrate currently used for FEC and NACK. |
| 50 | // Usage: |
| 51 | // Setup by calling SetProtectionMethod and SetEncodingData. |
| 52 | // For each encoded image, call UpdateWithEncodedData. |
| 53 | // Each time the bandwidth estimate change, call UpdateFecRates. UpdateFecRates |
| 54 | // will return the bitrate that can be used by an encoder. |
| 55 | // A lock is used to protect internal states, so methods can be called on an |
| 56 | // arbitrary thread. |
| 57 | class FecController { |
| 58 | public: |
| 59 | virtual ~FecController() {} |
| 60 | |
| 61 | virtual void SetProtectionCallback( |
| 62 | VCMProtectionCallback* protection_callback) = 0; |
| 63 | virtual void SetProtectionMethod(bool enable_fec, bool enable_nack) = 0; |
| 64 | |
| 65 | // Informs loss protectoin logic of initial encoding state. |
| 66 | virtual void SetEncodingData(size_t width, |
| 67 | size_t height, |
| 68 | size_t num_temporal_layers, |
| 69 | size_t max_payload_size) = 0; |
| 70 | |
| 71 | // Returns target rate for the encoder given the channel parameters. |
| 72 | // Inputs: estimated_bitrate_bps - the estimated network bitrate in bits/s. |
| 73 | // actual_framerate - encoder frame rate. |
| 74 | // fraction_lost - packet loss rate in % in the network. |
| 75 | // loss_mask_vector - packet loss mask since last time this method |
| 76 | // was called. round_trip_time_ms - round trip time in milliseconds. |
| 77 | virtual uint32_t UpdateFecRates(uint32_t estimated_bitrate_bps, |
| 78 | int actual_framerate, |
| 79 | uint8_t fraction_lost, |
| 80 | std::vector<bool> loss_mask_vector, |
| 81 | int64_t round_trip_time_ms) = 0; |
| 82 | |
| 83 | // Informs of encoded output. |
| Niels Möller | 87e2d78 | 2019-03-07 09:18:23 | [diff] [blame] | 84 | virtual void UpdateWithEncodedData( |
| 85 | size_t encoded_image_length, |
| 86 | VideoFrameType encoded_image_frametype) = 0; |
| Ying Wang | 8ed653d | 2018-01-23 15:37:22 | [diff] [blame] | 87 | |
| 88 | // Returns whether this FEC Controller needs Loss Vector Mask as input. |
| 89 | virtual bool UseLossVectorMask() = 0; |
| Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 90 | }; |
| 91 | |
| Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 92 | class FecControllerFactoryInterface { |
| 93 | public: |
| Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 94 | virtual ~FecControllerFactoryInterface() = default; |
| Danil Chapovalov | 55a6189 | 2024-01-03 17:39:27 | [diff] [blame] | 95 | |
| Danil Chapovalov | 55a6189 | 2024-01-03 17:39:27 | [diff] [blame] | 96 | virtual std::unique_ptr<FecController> CreateFecController( |
| Danil Chapovalov | c95ad5fe9 | 2024-01-08 17:05:51 | [diff] [blame] | 97 | const Environment& env) = 0; |
| Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 98 | }; |
| 99 | |
| Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 100 | } // namespace webrtc |
| 101 | #endif // API_FEC_CONTROLLER_H_ |