blob: 47ff9254a1d398c8109603de2f43ebd09f30b756 [file] [log] [blame]
Niels Möller0a8f4352018-05-18 11:37:23 +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
11#ifndef API_VIDEO_CODECS_VIDEO_ENCODER_CONFIG_H_
12#define API_VIDEO_CODECS_VIDEO_ENCODER_CONFIG_H_
13
14#include <string>
15#include <vector>
16
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020017#include "absl/types/optional.h"
Niels Möller0a8f4352018-05-18 11:37:23 +020018#include "api/video_codecs/sdp_video_format.h"
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020019#include "api/video_codecs/video_codec.h"
Niels Möller0a8f4352018-05-18 11:37:23 +020020#include "rtc_base/refcount.h"
21#include "rtc_base/scoped_ref_ptr.h"
22
23namespace webrtc {
24
25struct VideoStream {
26 VideoStream();
27 ~VideoStream();
28 VideoStream(const VideoStream& other);
29 std::string ToString() const;
30
Danil Chapovalov350531e2018-06-08 11:04:04 +000031 size_t width;
32 size_t height;
Niels Möller0a8f4352018-05-18 11:37:23 +020033 int max_framerate;
34
35 int min_bitrate_bps;
36 int target_bitrate_bps;
37 int max_bitrate_bps;
38 int max_qp;
39
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020040 absl::optional<size_t> num_temporal_layers;
Niels Möller0a8f4352018-05-18 11:37:23 +020041
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020042 absl::optional<double> bitrate_priority;
Niels Möller0a8f4352018-05-18 11:37:23 +020043
44 // TODO(bugs.webrtc.org/8653): Support active per-simulcast layer.
45 bool active;
46};
47
48class VideoEncoderConfig {
49 public:
50 // These are reference counted to permit copying VideoEncoderConfig and be
51 // kept alive until all encoder_specific_settings go out of scope.
52 // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020053 // and use absl::optional for encoder_specific_settings instead.
Niels Möller0a8f4352018-05-18 11:37:23 +020054 class EncoderSpecificSettings : public rtc::RefCountInterface {
55 public:
56 // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is
57 // not in use and encoder implementations ask for codec-specific structs
58 // directly.
59 void FillEncoderSpecificSettings(VideoCodec* codec_struct) const;
60
61 virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const;
62 virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const;
63 virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const;
64
65 private:
66 ~EncoderSpecificSettings() override {}
67 friend class VideoEncoderConfig;
68 };
69
70 class H264EncoderSpecificSettings : public EncoderSpecificSettings {
71 public:
72 explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics);
73 void FillVideoCodecH264(VideoCodecH264* h264_settings) const override;
74
75 private:
76 VideoCodecH264 specifics_;
77 };
78
79 class Vp8EncoderSpecificSettings : public EncoderSpecificSettings {
80 public:
81 explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics);
82 void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override;
83
84 private:
85 VideoCodecVP8 specifics_;
86 };
87
88 class Vp9EncoderSpecificSettings : public EncoderSpecificSettings {
89 public:
90 explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics);
91 void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override;
92
93 private:
94 VideoCodecVP9 specifics_;
95 };
96
97 enum class ContentType {
98 kRealtimeVideo,
99 kScreen,
100 };
101
102 class VideoStreamFactoryInterface : public rtc::RefCountInterface {
103 public:
104 // An implementation should return a std::vector<VideoStream> with the
105 // wanted VideoStream settings for the given video resolution.
106 // The size of the vector may not be larger than
107 // |encoder_config.number_of_streams|.
108 virtual std::vector<VideoStream> CreateEncoderStreams(
109 int width,
110 int height,
111 const VideoEncoderConfig& encoder_config) = 0;
112
113 protected:
114 ~VideoStreamFactoryInterface() override {}
115 };
116
117 VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default;
118 VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete;
119
120 // Mostly used by tests. Avoid creating copies if you can.
121 VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); }
122
123 VideoEncoderConfig();
124 VideoEncoderConfig(VideoEncoderConfig&&);
125 ~VideoEncoderConfig();
126 std::string ToString() const;
127
128 // TODO(nisse): Consolidate on one of these.
129 VideoCodecType codec_type;
130 SdpVideoFormat video_format;
131
132 rtc::scoped_refptr<VideoStreamFactoryInterface> video_stream_factory;
133 std::vector<SpatialLayer> spatial_layers;
134 ContentType content_type;
135 rtc::scoped_refptr<const EncoderSpecificSettings> encoder_specific_settings;
136
137 // Padding will be used up to this bitrate regardless of the bitrate produced
138 // by the encoder. Padding above what's actually produced by the encoder helps
139 // maintaining a higher bitrate estimate. Padding will however not be sent
140 // unless the estimated bandwidth indicates that the link can handle it.
141 int min_transmit_bitrate_bps;
142 int max_bitrate_bps;
143 // The bitrate priority used for all VideoStreams.
144 double bitrate_priority;
145
146 // The simulcast layer's configurations set by the application for this video
147 // sender. These are modified by the video_stream_factory before being passed
148 // down to lower layers for the video encoding.
149 std::vector<VideoStream> simulcast_layers;
150
151 // Max number of encoded VideoStreams to produce.
152 size_t number_of_streams;
153
154 private:
155 // Access to the copy constructor is private to force use of the Copy()
156 // method for those exceptional cases where we do use it.
157 VideoEncoderConfig(const VideoEncoderConfig&);
158};
159
160} // namespace webrtc
161
162#endif // API_VIDEO_CODECS_VIDEO_ENCODER_CONFIG_H_