fec_controller.h (4079B)
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 14 #include <cstddef> 15 #include <cstdint> 16 #include <memory> 17 #include <vector> 18 19 #include "api/environment/environment.h" 20 #include "api/video/video_frame_type.h" 21 #include "modules/include/module_fec_types.h" 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 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; 40 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 48 // implementation of `VCMProtectionCallback` to set new FEC parameters and get 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. 84 virtual void UpdateWithEncodedData( 85 size_t encoded_image_length, 86 VideoFrameType encoded_image_frametype) = 0; 87 88 // Returns whether this FEC Controller needs Loss Vector Mask as input. 89 virtual bool UseLossVectorMask() = 0; 90 }; 91 92 class FecControllerFactoryInterface { 93 public: 94 virtual ~FecControllerFactoryInterface() = default; 95 96 virtual std::unique_ptr<FecController> CreateFecController( 97 const Environment& env) = 0; 98 }; 99 100 } // namespace webrtc 101 #endif // API_FEC_CONTROLLER_H_