blob: 041b7792707287d66c41b44ab57ced72e5512d64 [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"
Mirko Bonadei71207422017-09-15 13:58:09 +020018#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "rtc_base/basictypes.h"
20#include "rtc_base/refcount.h"
21#include "rtc_base/scoped_ref_ptr.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020022#include "typedefs.h" // NOLINT(build/include)
Stefan Holmer1acbd682017-09-01 15:29:28 +020023
24namespace webrtc {
25
26struct VideoStream {
27 VideoStream();
28 ~VideoStream();
Seth Hampson36193c32017-12-14 11:41:18 -080029 VideoStream(const VideoStream& other);
Stefan Holmer1acbd682017-09-01 15:29:28 +020030 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 Eliassone27e0ac2018-02-28 16:01:23 +000039 int max_qp;
40
Sergey Silkina796a7e2018-03-01 15:11:29 +010041 rtc::Optional<size_t> num_temporal_layers;
42
43 rtc::Optional<double> bitrate_priority;
44
Seth Hampson36193c32017-12-14 11:41:18 -080045 // TODO(bugs.webrtc.org/8653): Support active per-simulcast layer.
46 bool active;
Stefan Holmer1acbd682017-09-01 15:29:28 +020047};
48
49class 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öller24a842a2018-03-22 08:52:50 +0100129 // 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 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_