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