Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef CALL_VIDEO_CONFIG_H_ |
| 12 | #define CALL_VIDEO_CONFIG_H_ |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/optional.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 18 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "rtc_base/basictypes.h" |
| 20 | #include "rtc_base/refcount.h" |
| 21 | #include "rtc_base/scoped_ref_ptr.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 22 | #include "typedefs.h" // NOLINT(build/include) |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | struct VideoStream { |
| 27 | VideoStream(); |
| 28 | ~VideoStream(); |
| 29 | std::string ToString() const; |
| 30 | |
| 31 | size_t width; |
| 32 | size_t height; |
| 33 | int max_framerate; |
| 34 | |
| 35 | int min_bitrate_bps; |
| 36 | int target_bitrate_bps; |
| 37 | int max_bitrate_bps; |
| 38 | |
| 39 | int max_qp; |
| 40 | |
| 41 | // Bitrate thresholds for enabling additional temporal layers. Since these are |
| 42 | // thresholds in between layers, we have one additional layer. One threshold |
| 43 | // gives two temporal layers, one below the threshold and one above, two give |
| 44 | // three, and so on. |
| 45 | // The VideoEncoder may redistribute bitrates over the temporal layers so a |
| 46 | // bitrate threshold of 100k and an estimate of 105k does not imply that we |
| 47 | // get 100k in one temporal layer and 5k in the other, just that the bitrate |
| 48 | // in the first temporal layer should not exceed 100k. |
| 49 | // TODO(kthelgason): Apart from a special case for two-layer screencast these |
| 50 | // thresholds are not propagated to the VideoEncoder. To be implemented. |
| 51 | std::vector<int> temporal_layer_thresholds_bps; |
| 52 | }; |
| 53 | |
| 54 | class VideoEncoderConfig { |
| 55 | public: |
| 56 | // These are reference counted to permit copying VideoEncoderConfig and be |
| 57 | // kept alive until all encoder_specific_settings go out of scope. |
| 58 | // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig |
| 59 | // and use rtc::Optional for encoder_specific_settings instead. |
| 60 | class EncoderSpecificSettings : public rtc::RefCountInterface { |
| 61 | public: |
| 62 | // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is |
| 63 | // not in use and encoder implementations ask for codec-specific structs |
| 64 | // directly. |
| 65 | void FillEncoderSpecificSettings(VideoCodec* codec_struct) const; |
| 66 | |
| 67 | virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const; |
| 68 | virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const; |
| 69 | virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const; |
| 70 | |
| 71 | private: |
| 72 | ~EncoderSpecificSettings() override {} |
| 73 | friend class VideoEncoderConfig; |
| 74 | }; |
| 75 | |
| 76 | class H264EncoderSpecificSettings : public EncoderSpecificSettings { |
| 77 | public: |
| 78 | explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics); |
| 79 | void FillVideoCodecH264(VideoCodecH264* h264_settings) const override; |
| 80 | |
| 81 | private: |
| 82 | VideoCodecH264 specifics_; |
| 83 | }; |
| 84 | |
| 85 | class Vp8EncoderSpecificSettings : public EncoderSpecificSettings { |
| 86 | public: |
| 87 | explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics); |
| 88 | void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override; |
| 89 | |
| 90 | private: |
| 91 | VideoCodecVP8 specifics_; |
| 92 | }; |
| 93 | |
| 94 | class Vp9EncoderSpecificSettings : public EncoderSpecificSettings { |
| 95 | public: |
| 96 | explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics); |
| 97 | void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override; |
| 98 | |
| 99 | private: |
| 100 | VideoCodecVP9 specifics_; |
| 101 | }; |
| 102 | |
| 103 | enum class ContentType { |
| 104 | kRealtimeVideo, |
| 105 | kScreen, |
| 106 | }; |
| 107 | |
| 108 | class VideoStreamFactoryInterface : public rtc::RefCountInterface { |
| 109 | public: |
| 110 | // An implementation should return a std::vector<VideoStream> with the |
| 111 | // wanted VideoStream settings for the given video resolution. |
| 112 | // The size of the vector may not be larger than |
| 113 | // |encoder_config.number_of_streams|. |
| 114 | virtual std::vector<VideoStream> CreateEncoderStreams( |
| 115 | int width, |
| 116 | int height, |
| 117 | const VideoEncoderConfig& encoder_config) = 0; |
| 118 | |
| 119 | protected: |
| 120 | ~VideoStreamFactoryInterface() override {} |
| 121 | }; |
| 122 | |
| 123 | VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default; |
| 124 | VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete; |
| 125 | |
| 126 | // Mostly used by tests. Avoid creating copies if you can. |
| 127 | VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); } |
| 128 | |
| 129 | VideoEncoderConfig(); |
| 130 | VideoEncoderConfig(VideoEncoderConfig&&); |
| 131 | ~VideoEncoderConfig(); |
| 132 | std::string ToString() const; |
| 133 | |
| 134 | rtc::scoped_refptr<VideoStreamFactoryInterface> video_stream_factory; |
| 135 | std::vector<SpatialLayer> spatial_layers; |
| 136 | ContentType content_type; |
| 137 | rtc::scoped_refptr<const EncoderSpecificSettings> encoder_specific_settings; |
| 138 | |
| 139 | // Padding will be used up to this bitrate regardless of the bitrate produced |
| 140 | // by the encoder. Padding above what's actually produced by the encoder helps |
| 141 | // maintaining a higher bitrate estimate. Padding will however not be sent |
| 142 | // unless the estimated bandwidth indicates that the link can handle it. |
| 143 | int min_transmit_bitrate_bps; |
| 144 | int max_bitrate_bps; |
| 145 | |
| 146 | // Max number of encoded VideoStreams to produce. |
| 147 | size_t number_of_streams; |
| 148 | |
| 149 | private: |
| 150 | // Access to the copy constructor is private to force use of the Copy() |
| 151 | // method for those exceptional cases where we do use it. |
| 152 | VideoEncoderConfig(const VideoEncoderConfig&); |
| 153 | }; |
| 154 | |
| 155 | } // namespace webrtc |
| 156 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 157 | #endif // CALL_VIDEO_CONFIG_H_ |