xref: /aosp_15_r20/external/webrtc/video/config/encoder_stream_factory.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2022 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 #ifndef VIDEO_CONFIG_ENCODER_STREAM_FACTORY_H_
11 #define VIDEO_CONFIG_ENCODER_STREAM_FACTORY_H_
12 
13 #include <string>
14 #include <vector>
15 
16 #include "api/transport/field_trial_based_config.h"
17 #include "api/units/data_rate.h"
18 #include "api/video_codecs/video_encoder.h"
19 #include "call/adaptation/video_source_restrictions.h"
20 #include "video/config/video_encoder_config.h"
21 
22 namespace cricket {
23 
24 class EncoderStreamFactory
25     : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface {
26  public:
27   // Note: this constructor is used by testcase in downstream.
28   EncoderStreamFactory(std::string codec_name,
29                        int max_qp,
30                        bool is_screenshare,
31                        bool conference_mode);
32 
33   EncoderStreamFactory(std::string codec_name,
34                        int max_qp,
35                        bool is_screenshare,
36                        bool conference_mode,
37                        const webrtc::VideoEncoder::EncoderInfo& encoder_info,
38                        absl::optional<webrtc::VideoSourceRestrictions>
39                            restrictions = absl::nullopt,
40                        const webrtc::FieldTrialsView* trials = nullptr);
41 
42   std::vector<webrtc::VideoStream> CreateEncoderStreams(
43       int width,
44       int height,
45       const webrtc::VideoEncoderConfig& encoder_config) override;
46 
47  private:
48   std::vector<webrtc::VideoStream> CreateDefaultVideoStreams(
49       int width,
50       int height,
51       const webrtc::VideoEncoderConfig& encoder_config,
52       const absl::optional<webrtc::DataRate>& experimental_min_bitrate) const;
53 
54   std::vector<webrtc::VideoStream>
55   CreateSimulcastOrConferenceModeScreenshareStreams(
56       int width,
57       int height,
58       const webrtc::VideoEncoderConfig& encoder_config,
59       const absl::optional<webrtc::DataRate>& experimental_min_bitrate) const;
60 
61   webrtc::Resolution GetLayerResolutionFromRequestedResolution(
62       int in_frame_width,
63       int in_frame_height,
64       webrtc::Resolution requested_resolution) const;
65 
66   const std::string codec_name_;
67   const int max_qp_;
68   const bool is_screenshare_;
69   // Allows a screenshare specific configuration, which enables temporal
70   // layering and various settings.
71   const bool conference_mode_;
72   const webrtc::FieldTrialBasedConfig fallback_trials_;
73   const webrtc::FieldTrialsView& trials_;
74   const int encoder_info_requested_resolution_alignment_;
75   const absl::optional<webrtc::VideoSourceRestrictions> restrictions_;
76 };
77 
78 }  // namespace cricket
79 
80 #endif  // VIDEO_CONFIG_ENCODER_STREAM_FACTORY_H_
81