video_stream_encoder_interface.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2018 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_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_
  11. #define API_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_
  12. #include <vector>
  13. #include "api/adaptation/resource.h"
  14. #include "api/fec_controller_override.h"
  15. #include "api/rtp_parameters.h" // For DegradationPreference.
  16. #include "api/scoped_refptr.h"
  17. #include "api/units/data_rate.h"
  18. #include "api/video/video_bitrate_allocator.h"
  19. #include "api/video/video_sink_interface.h"
  20. #include "api/video/video_source_interface.h"
  21. #include "api/video_codecs/video_encoder.h"
  22. #include "api/video_codecs/video_encoder_config.h"
  23. namespace webrtc {
  24. // This interface represents a class responsible for creating and driving the
  25. // encoder(s) for a single video stream. It is also responsible for adaptation
  26. // decisions related to video quality, requesting reduced frame rate or
  27. // resolution from the VideoSource when needed.
  28. // TODO(bugs.webrtc.org/8830): This interface is under development. Changes
  29. // under consideration include:
  30. //
  31. // 1. Taking out responsibility for adaptation decisions, instead only reporting
  32. // per-frame measurements to the decision maker.
  33. //
  34. // 2. Moving responsibility for simulcast and for software fallback into this
  35. // class.
  36. class VideoStreamEncoderInterface : public rtc::VideoSinkInterface<VideoFrame> {
  37. public:
  38. // Interface for receiving encoded video frames and notifications about
  39. // configuration changes.
  40. class EncoderSink : public EncodedImageCallback {
  41. public:
  42. virtual void OnEncoderConfigurationChanged(
  43. std::vector<VideoStream> streams,
  44. bool is_svc,
  45. VideoEncoderConfig::ContentType content_type,
  46. int min_transmit_bitrate_bps) = 0;
  47. };
  48. // If the resource is overusing, the VideoStreamEncoder will try to reduce
  49. // resolution or frame rate until no resource is overusing.
  50. // TODO(https://crbug.com/webrtc/11565): When the ResourceAdaptationProcessor
  51. // is moved to Call this method could be deleted altogether in favor of
  52. // Call-level APIs only.
  53. virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) = 0;
  54. virtual std::vector<rtc::scoped_refptr<Resource>>
  55. GetAdaptationResources() = 0;
  56. // Sets the source that will provide video frames to the VideoStreamEncoder's
  57. // OnFrame method. |degradation_preference| control whether or not resolution
  58. // or frame rate may be reduced. The VideoStreamEncoder registers itself with
  59. // |source|, and signals adaptation decisions to the source in the form of
  60. // VideoSinkWants.
  61. // TODO(nisse): When adaptation logic is extracted from this class,
  62. // it no longer needs to know the source.
  63. virtual void SetSource(
  64. rtc::VideoSourceInterface<VideoFrame>* source,
  65. const DegradationPreference& degradation_preference) = 0;
  66. // Sets the |sink| that gets the encoded frames. |rotation_applied| means
  67. // that the source must support rotation. Only set |rotation_applied| if the
  68. // remote side does not support the rotation extension.
  69. virtual void SetSink(EncoderSink* sink, bool rotation_applied) = 0;
  70. // Sets an initial bitrate, later overriden by OnBitrateUpdated. Mainly
  71. // affects the resolution of the initial key frame: If incoming frames are
  72. // larger than reasonable for the start bitrate, and scaling is enabled,
  73. // VideoStreamEncoder asks the source to scale down and drops a few initial
  74. // frames.
  75. // TODO(nisse): This is a poor interface, and mixes bandwidth estimation and
  76. // codec configuration in an undesired way. For the actual send bandwidth, we
  77. // should always be somewhat conservative, but we may nevertheless want to let
  78. // the application configure a more optimistic quality for the initial
  79. // resolution. Should be replaced by a construction time setting.
  80. virtual void SetStartBitrate(int start_bitrate_bps) = 0;
  81. // Request a key frame. Used for signalling from the remote receiver.
  82. virtual void SendKeyFrame() = 0;
  83. // Inform the encoder that a loss has occurred.
  84. virtual void OnLossNotification(
  85. const VideoEncoder::LossNotification& loss_notification) = 0;
  86. // Set the currently estimated network properties. A |target_bitrate|
  87. // of zero pauses the encoder.
  88. // |stable_target_bitrate| is a filtered version of |target_bitrate|. It is
  89. // always less or equal to it. It can be used to avoid rapid changes of
  90. // expensive encoding settings, such as resolution.
  91. // |link_allocation| is the bandwidth available for this video stream on the
  92. // network link. It is always at least |target_bitrate| but may be higher
  93. // if we are not network constrained.
  94. virtual void OnBitrateUpdated(DataRate target_bitrate,
  95. DataRate stable_target_bitrate,
  96. DataRate link_allocation,
  97. uint8_t fraction_lost,
  98. int64_t round_trip_time_ms,
  99. double cwnd_reduce_ratio) = 0;
  100. // Register observer for the bitrate allocation between the temporal
  101. // and spatial layers.
  102. virtual void SetBitrateAllocationObserver(
  103. VideoBitrateAllocationObserver* bitrate_observer) = 0;
  104. // Set a FecControllerOverride, through which the encoder may override
  105. // decisions made by FecController.
  106. virtual void SetFecControllerOverride(
  107. FecControllerOverride* fec_controller_override) = 0;
  108. // Creates and configures an encoder with the given |config|. The
  109. // |max_data_payload_length| is used to support single NAL unit
  110. // packetization for H.264.
  111. virtual void ConfigureEncoder(VideoEncoderConfig config,
  112. size_t max_data_payload_length) = 0;
  113. // Permanently stop encoding. After this method has returned, it is
  114. // guaranteed that no encoded frames will be delivered to the sink.
  115. virtual void Stop() = 0;
  116. };
  117. } // namespace webrtc
  118. #endif // API_VIDEO_VIDEO_STREAM_ENCODER_INTERFACE_H_