fec_controller.h 3.8 KB

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