blob: 3e5f7bb2168e916f65c1f0d507a4a77637ab54d8 [file] [log] [blame]
Ying Wang3b790f32018-01-19 17:58:57 +01001/*
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
Ying Wang0dd1b0a2018-02-20 12:50:27 +010014#include <memory>
Ying Wang3b790f32018-01-19 17:58:57 +010015#include <vector>
16
Niels Möller8f7ce222019-03-21 15:43:58 +010017#include "api/video/video_frame_type.h"
Ying Wang0dd1b0a2018-02-20 12:50:27 +010018#include "modules/include/module_fec_types.h"
Ying Wang3b790f32018-01-19 17:58:57 +010019
20namespace 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.
26class 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:
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.
50class FecController {
51 public:
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.
Niels Möller87e2d782019-03-07 10:18:23 +010077 virtual void UpdateWithEncodedData(
78 size_t encoded_image_length,
79 VideoFrameType encoded_image_frametype) = 0;
Ying Wang8ed653d2018-01-23 16:37:22 +010080
81 // Returns whether this FEC Controller needs Loss Vector Mask as input.
82 virtual bool UseLossVectorMask() = 0;
Ying Wang3b790f32018-01-19 17:58:57 +010083};
84
Ying Wang0dd1b0a2018-02-20 12:50:27 +010085class FecControllerFactoryInterface {
86 public:
87 virtual std::unique_ptr<FecController> CreateFecController() = 0;
88 virtual ~FecControllerFactoryInterface() = default;
89};
90
Ying Wang3b790f32018-01-19 17:58:57 +010091} // namespace webrtc
92#endif // API_FEC_CONTROLLER_H_