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