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(); |
Seth Hampson | 36193c3 | 2017-12-14 11:41:18 -0800 | [diff] [blame] | 29 | VideoStream(const VideoStream& other); |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 30 | std::string ToString() const; |
| 31 | |
| 32 | size_t width; |
| 33 | size_t height; |
| 34 | int max_framerate; |
| 35 | |
| 36 | int min_bitrate_bps; |
| 37 | int target_bitrate_bps; |
| 38 | int max_bitrate_bps; |
Philip Eliasson | e27e0ac | 2018-02-28 16:01:23 +0000 | [diff] [blame] | 39 | int max_qp; |
| 40 | |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 41 | rtc::Optional<size_t> num_temporal_layers; |
| 42 | |
| 43 | rtc::Optional<double> bitrate_priority; |
| 44 | |
Seth Hampson | 36193c3 | 2017-12-14 11:41:18 -0800 | [diff] [blame] | 45 | // TODO(bugs.webrtc.org/8653): Support active per-simulcast layer. |
| 46 | bool active; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | class VideoEncoderConfig { |
| 50 | public: |
| 51 | // These are reference counted to permit copying VideoEncoderConfig and be |
| 52 | // kept alive until all encoder_specific_settings go out of scope. |
| 53 | // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig |
| 54 | // and use rtc::Optional for encoder_specific_settings instead. |
| 55 | class EncoderSpecificSettings : public rtc::RefCountInterface { |
| 56 | public: |
| 57 | // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is |
| 58 | // not in use and encoder implementations ask for codec-specific structs |
| 59 | // directly. |
| 60 | void FillEncoderSpecificSettings(VideoCodec* codec_struct) const; |
| 61 | |
| 62 | virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const; |
| 63 | virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const; |
| 64 | virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const; |
| 65 | |
| 66 | private: |
| 67 | ~EncoderSpecificSettings() override {} |
| 68 | friend class VideoEncoderConfig; |
| 69 | }; |
| 70 | |
| 71 | class H264EncoderSpecificSettings : public EncoderSpecificSettings { |
| 72 | public: |
| 73 | explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics); |
| 74 | void FillVideoCodecH264(VideoCodecH264* h264_settings) const override; |
| 75 | |
| 76 | private: |
| 77 | VideoCodecH264 specifics_; |
| 78 | }; |
| 79 | |
| 80 | class Vp8EncoderSpecificSettings : public EncoderSpecificSettings { |
| 81 | public: |
| 82 | explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics); |
| 83 | void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override; |
| 84 | |
| 85 | private: |
| 86 | VideoCodecVP8 specifics_; |
| 87 | }; |
| 88 | |
| 89 | class Vp9EncoderSpecificSettings : public EncoderSpecificSettings { |
| 90 | public: |
| 91 | explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics); |
| 92 | void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override; |
| 93 | |
| 94 | private: |
| 95 | VideoCodecVP9 specifics_; |
| 96 | }; |
| 97 | |
| 98 | enum class ContentType { |
| 99 | kRealtimeVideo, |
| 100 | kScreen, |
| 101 | }; |
| 102 | |
| 103 | class VideoStreamFactoryInterface : public rtc::RefCountInterface { |
| 104 | public: |
| 105 | // An implementation should return a std::vector<VideoStream> with the |
| 106 | // wanted VideoStream settings for the given video resolution. |
| 107 | // The size of the vector may not be larger than |
| 108 | // |encoder_config.number_of_streams|. |
| 109 | virtual std::vector<VideoStream> CreateEncoderStreams( |
| 110 | int width, |
| 111 | int height, |
| 112 | const VideoEncoderConfig& encoder_config) = 0; |
| 113 | |
| 114 | protected: |
| 115 | ~VideoStreamFactoryInterface() override {} |
| 116 | }; |
| 117 | |
| 118 | VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default; |
| 119 | VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete; |
| 120 | |
| 121 | // Mostly used by tests. Avoid creating copies if you can. |
| 122 | VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); } |
| 123 | |
| 124 | VideoEncoderConfig(); |
| 125 | VideoEncoderConfig(VideoEncoderConfig&&); |
| 126 | ~VideoEncoderConfig(); |
| 127 | std::string ToString() const; |
| 128 | |
Niels Möller | 24a842a | 2018-03-22 08:52:50 +0100 | [diff] [blame^] | 129 | // TODO(nisse): This codec_type member is intended to be the new way |
| 130 | // to say which codec to use, when |
| 131 | // VideoSendStream::Config::EncoderSettings::payload_name is |
| 132 | // deleted. For the transition, both need to coexist. |
| 133 | VideoCodecType codec_type; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 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; |
Seth Hampson | f32795e | 2017-12-19 11:37:41 -0800 | [diff] [blame] | 145 | // The bitrate priority used for all VideoStreams. |
| 146 | double bitrate_priority; |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 147 | |
Seth Hampson | 36193c3 | 2017-12-14 11:41:18 -0800 | [diff] [blame] | 148 | // The simulcast layer's configurations set by the application for this video |
| 149 | // sender. These are modified by the video_stream_factory before being passed |
| 150 | // down to lower layers for the video encoding. |
| 151 | std::vector<VideoStream> simulcast_layers; |
| 152 | |
Stefan Holmer | 1acbd68 | 2017-09-01 15:29:28 +0200 | [diff] [blame] | 153 | // Max number of encoded VideoStreams to produce. |
| 154 | size_t number_of_streams; |
| 155 | |
| 156 | private: |
| 157 | // Access to the copy constructor is private to force use of the Copy() |
| 158 | // method for those exceptional cases where we do use it. |
| 159 | VideoEncoderConfig(const VideoEncoderConfig&); |
| 160 | }; |
| 161 | |
| 162 | } // namespace webrtc |
| 163 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 164 | #endif // CALL_VIDEO_CONFIG_H_ |