blob: 93f956201b547aeca524bd72d780ec9aa07450e1 [file] [log] [blame]
Stefan Holmer1acbd682017-09-01 15:29:28 +02001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef CALL_VIDEO_CONFIG_H_
12#define CALL_VIDEO_CONFIG_H_
Stefan Holmer1acbd682017-09-01 15:29:28 +020013
14#include <string>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/optional.h"
Niels Möller6dfc8d62018-04-17 12:51:59 +020018#include "api/video_codecs/sdp_video_format.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020019#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "rtc_base/basictypes.h"
21#include "rtc_base/refcount.h"
22#include "rtc_base/scoped_ref_ptr.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020023#include "typedefs.h" // NOLINT(build/include)
Stefan Holmer1acbd682017-09-01 15:29:28 +020024
25namespace webrtc {
26
27struct VideoStream {
28 VideoStream();
29 ~VideoStream();
Seth Hampson36193c32017-12-14 11:41:18 -080030 VideoStream(const VideoStream& other);
Stefan Holmer1acbd682017-09-01 15:29:28 +020031 std::string ToString() const;
32
33 size_t width;
34 size_t height;
35 int max_framerate;
36
37 int min_bitrate_bps;
38 int target_bitrate_bps;
39 int max_bitrate_bps;
Philip Eliassone27e0ac2018-02-28 16:01:23 +000040 int max_qp;
41
Sergey Silkina796a7e2018-03-01 15:11:29 +010042 rtc::Optional<size_t> num_temporal_layers;
43
44 rtc::Optional<double> bitrate_priority;
45
Seth Hampson36193c32017-12-14 11:41:18 -080046 // TODO(bugs.webrtc.org/8653): Support active per-simulcast layer.
47 bool active;
Stefan Holmer1acbd682017-09-01 15:29:28 +020048};
49
50class VideoEncoderConfig {
51 public:
52 // These are reference counted to permit copying VideoEncoderConfig and be
53 // kept alive until all encoder_specific_settings go out of scope.
54 // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig
55 // and use rtc::Optional for encoder_specific_settings instead.
56 class EncoderSpecificSettings : public rtc::RefCountInterface {
57 public:
58 // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is
59 // not in use and encoder implementations ask for codec-specific structs
60 // directly.
61 void FillEncoderSpecificSettings(VideoCodec* codec_struct) const;
62
63 virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const;
64 virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const;
65 virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const;
66
67 private:
68 ~EncoderSpecificSettings() override {}
69 friend class VideoEncoderConfig;
70 };
71
72 class H264EncoderSpecificSettings : public EncoderSpecificSettings {
73 public:
74 explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics);
75 void FillVideoCodecH264(VideoCodecH264* h264_settings) const override;
76
77 private:
78 VideoCodecH264 specifics_;
79 };
80
81 class Vp8EncoderSpecificSettings : public EncoderSpecificSettings {
82 public:
83 explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics);
84 void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override;
85
86 private:
87 VideoCodecVP8 specifics_;
88 };
89
90 class Vp9EncoderSpecificSettings : public EncoderSpecificSettings {
91 public:
92 explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics);
93 void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override;
94
95 private:
96 VideoCodecVP9 specifics_;
97 };
98
99 enum class ContentType {
100 kRealtimeVideo,
101 kScreen,
102 };
103
104 class VideoStreamFactoryInterface : public rtc::RefCountInterface {
105 public:
106 // An implementation should return a std::vector<VideoStream> with the
107 // wanted VideoStream settings for the given video resolution.
108 // The size of the vector may not be larger than
109 // |encoder_config.number_of_streams|.
110 virtual std::vector<VideoStream> CreateEncoderStreams(
111 int width,
112 int height,
113 const VideoEncoderConfig& encoder_config) = 0;
114
115 protected:
116 ~VideoStreamFactoryInterface() override {}
117 };
118
119 VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default;
120 VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete;
121
122 // Mostly used by tests. Avoid creating copies if you can.
123 VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); }
124
125 VideoEncoderConfig();
126 VideoEncoderConfig(VideoEncoderConfig&&);
127 ~VideoEncoderConfig();
128 std::string ToString() const;
129
Niels Möller6dfc8d62018-04-17 12:51:59 +0200130 // TODO(nisse): Consolidate on one of these.
Niels Möller24a842a2018-03-22 08:52:50 +0100131 VideoCodecType codec_type;
Niels Möller6dfc8d62018-04-17 12:51:59 +0200132 SdpVideoFormat video_format;
133
Stefan Holmer1acbd682017-09-01 15:29:28 +0200134 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 Hampsonf32795e2017-12-19 11:37:41 -0800145 // The bitrate priority used for all VideoStreams.
146 double bitrate_priority;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200147
Seth Hampson36193c32017-12-14 11:41:18 -0800148 // 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 Holmer1acbd682017-09-01 15:29:28 +0200153 // 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 Bonadei92ea95e2017-09-15 06:47:31 +0200164#endif // CALL_VIDEO_CONFIG_H_