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