video_codec.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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_CODECS_VIDEO_CODEC_H_
  11. #define API_VIDEO_CODECS_VIDEO_CODEC_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <string>
  15. #include "absl/types/optional.h"
  16. #include "api/video/video_bitrate_allocation.h"
  17. #include "api/video/video_codec_type.h"
  18. #include "api/video_codecs/spatial_layer.h"
  19. #include "rtc_base/system/rtc_export.h"
  20. namespace webrtc {
  21. // The VideoCodec class represents an old defacto-apis, which we're migrating
  22. // away from slowly.
  23. // Video codec
  24. enum class VideoCodecComplexity {
  25. kComplexityNormal = 0,
  26. kComplexityHigh = 1,
  27. kComplexityHigher = 2,
  28. kComplexityMax = 3
  29. };
  30. // VP8 specific
  31. struct VideoCodecVP8 {
  32. bool operator==(const VideoCodecVP8& other) const;
  33. bool operator!=(const VideoCodecVP8& other) const {
  34. return !(*this == other);
  35. }
  36. VideoCodecComplexity complexity;
  37. unsigned char numberOfTemporalLayers;
  38. bool denoisingOn;
  39. bool automaticResizeOn;
  40. bool frameDroppingOn;
  41. int keyFrameInterval;
  42. };
  43. enum class InterLayerPredMode : int {
  44. kOff = 0, // Inter-layer prediction is disabled.
  45. kOn = 1, // Inter-layer prediction is enabled.
  46. kOnKeyPic = 2 // Inter-layer prediction is enabled but limited to key frames.
  47. };
  48. // VP9 specific.
  49. struct VideoCodecVP9 {
  50. bool operator==(const VideoCodecVP9& other) const;
  51. bool operator!=(const VideoCodecVP9& other) const {
  52. return !(*this == other);
  53. }
  54. VideoCodecComplexity complexity;
  55. unsigned char numberOfTemporalLayers;
  56. bool denoisingOn;
  57. bool frameDroppingOn;
  58. int keyFrameInterval;
  59. bool adaptiveQpMode;
  60. bool automaticResizeOn;
  61. unsigned char numberOfSpatialLayers;
  62. bool flexibleMode;
  63. InterLayerPredMode interLayerPred;
  64. };
  65. // H264 specific.
  66. struct VideoCodecH264 {
  67. bool operator==(const VideoCodecH264& other) const;
  68. bool operator!=(const VideoCodecH264& other) const {
  69. return !(*this == other);
  70. }
  71. bool frameDroppingOn;
  72. int keyFrameInterval;
  73. uint8_t numberOfTemporalLayers;
  74. };
  75. // Translates from name of codec to codec type and vice versa.
  76. RTC_EXPORT const char* CodecTypeToPayloadString(VideoCodecType type);
  77. RTC_EXPORT VideoCodecType PayloadStringToCodecType(const std::string& name);
  78. union VideoCodecUnion {
  79. VideoCodecVP8 VP8;
  80. VideoCodecVP9 VP9;
  81. VideoCodecH264 H264;
  82. };
  83. enum class VideoCodecMode { kRealtimeVideo, kScreensharing };
  84. // Common video codec properties
  85. class RTC_EXPORT VideoCodec {
  86. public:
  87. VideoCodec();
  88. // Public variables. TODO(hta): Make them private with accessors.
  89. VideoCodecType codecType;
  90. // TODO(nisse): Change to int, for consistency.
  91. uint16_t width;
  92. uint16_t height;
  93. unsigned int startBitrate; // kilobits/sec.
  94. unsigned int maxBitrate; // kilobits/sec.
  95. unsigned int minBitrate; // kilobits/sec.
  96. uint32_t maxFramerate;
  97. // This enables/disables encoding and sending when there aren't multiple
  98. // simulcast streams,by allocating 0 bitrate if inactive.
  99. bool active;
  100. unsigned int qpMax;
  101. unsigned char numberOfSimulcastStreams;
  102. SpatialLayer simulcastStream[kMaxSimulcastStreams];
  103. SpatialLayer spatialLayers[kMaxSpatialLayers];
  104. VideoCodecMode mode;
  105. bool expect_encode_from_texture;
  106. // The size of pool which is used to store video frame buffers inside decoder.
  107. // If value isn't present some codec-default value will be used.
  108. // If value is present and decoder doesn't have buffer pool the
  109. // value will be ignored.
  110. absl::optional<int> buffer_pool_size;
  111. // Timing frames configuration. There is delay of delay_ms between two
  112. // consequent timing frames, excluding outliers. Frame is always made a
  113. // timing frame if it's at least outlier_ratio in percent of "ideal" average
  114. // frame given bitrate and framerate, i.e. if it's bigger than
  115. // |outlier_ratio / 100.0 * bitrate_bps / fps| in bits. This way, timing
  116. // frames will not be sent too often usually. Yet large frames will always
  117. // have timing information for debug purposes because they are more likely to
  118. // cause extra delays.
  119. struct TimingFrameTriggerThresholds {
  120. int64_t delay_ms;
  121. uint16_t outlier_ratio_percent;
  122. } timing_frame_thresholds;
  123. // Legacy Google conference mode flag for simulcast screenshare
  124. bool legacy_conference_mode;
  125. bool operator==(const VideoCodec& other) const = delete;
  126. bool operator!=(const VideoCodec& other) const = delete;
  127. // Accessors for codec specific information.
  128. // There is a const version of each that returns a reference,
  129. // and a non-const version that returns a pointer, in order
  130. // to allow modification of the parameters.
  131. VideoCodecVP8* VP8();
  132. const VideoCodecVP8& VP8() const;
  133. VideoCodecVP9* VP9();
  134. const VideoCodecVP9& VP9() const;
  135. VideoCodecH264* H264();
  136. const VideoCodecH264& H264() const;
  137. private:
  138. // TODO(hta): Consider replacing the union with a pointer type.
  139. // This will allow removing the VideoCodec* types from this file.
  140. VideoCodecUnion codec_specific_;
  141. };
  142. } // namespace webrtc
  143. #endif // API_VIDEO_CODECS_VIDEO_CODEC_H_