Thanks to visit codestin.com
Credit goes to webrtc.googlesource.com

blob: a6cf7695235b331f16c086a99c84e540fc932b2b [file] [log] [blame]
Ying Wang3b790f32018-01-19 16:58:571/*
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 Hen28ce65c2024-09-04 11:55:2214#include <cstddef>
15#include <cstdint>
Ying Wang0dd1b0a2018-02-20 11:50:2716#include <memory>
Ying Wang3b790f32018-01-19 16:58:5717#include <vector>
18
Danil Chapovalov55a61892024-01-03 17:39:2719#include "api/environment/environment.h"
Niels Möller8f7ce222019-03-21 14:43:5820#include "api/video/video_frame_type.h"
Ying Wang0dd1b0a2018-02-20 11:50:2721#include "modules/include/module_fec_types.h"
Ying Wang3b790f32018-01-19 16:58:5722
23namespace 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.
29class 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 Wang2d598532023-06-01 05:55:3637 // '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 Tsirkin932e3612025-01-07 10:40:3740
Ying Wang3b790f32018-01-19 16:58:5741 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 Titov0e61fdd2021-07-25 19:50:1448// implementation of `VCMProtectionCallback` to set new FEC parameters and get
Ying Wang3b790f32018-01-19 16:58:5749// 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.
57class 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öller87e2d782019-03-07 09:18:2384 virtual void UpdateWithEncodedData(
85 size_t encoded_image_length,
86 VideoFrameType encoded_image_frametype) = 0;
Ying Wang8ed653d2018-01-23 15:37:2287
88 // Returns whether this FEC Controller needs Loss Vector Mask as input.
89 virtual bool UseLossVectorMask() = 0;
Ying Wang3b790f32018-01-19 16:58:5790};
91
Ying Wang0dd1b0a2018-02-20 11:50:2792class FecControllerFactoryInterface {
93 public:
Ying Wang0dd1b0a2018-02-20 11:50:2794 virtual ~FecControllerFactoryInterface() = default;
Danil Chapovalov55a61892024-01-03 17:39:2795
Danil Chapovalov55a61892024-01-03 17:39:2796 virtual std::unique_ptr<FecController> CreateFecController(
Danil Chapovalovc95ad5fe92024-01-08 17:05:5197 const Environment& env) = 0;
Ying Wang0dd1b0a2018-02-20 11:50:2798};
99
Ying Wang3b790f32018-01-19 16:58:57100} // namespace webrtc
101#endif // API_FEC_CONTROLLER_H_