blob: 0a3c1aee66aca081f443987bcf9c61d8c81eac43 [file] [log] [blame]
Magnus Jedvertd4b0c052017-09-14 10:24:54 +02001/*
2 * Copyright (c) 2017 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 API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_
12#define API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020013
14#include <memory>
15#include <vector>
16
philipel9b058032020-02-10 11:30:00 +010017#include "absl/types/optional.h"
18#include "api/units/data_rate.h"
philipel0bb08812019-07-11 13:23:16 +020019#include "api/video_codecs/sdp_video_format.h"
20
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020021namespace webrtc {
22
23class VideoEncoder;
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020024
25// A factory that creates VideoEncoders.
26// NOTE: This class is still under development and may change without notice.
27class VideoEncoderFactory {
28 public:
29 // TODO(magjed): Try to get rid of this struct.
30 struct CodecInfo {
Niels Möller2b781bf2020-07-16 14:19:41 +020031 // TODO(nisse): Unused in webrtc, delete as soon as downstream use is fixed.
Niels Möller35928392020-07-16 12:08:44 +020032 bool is_hardware_accelerated = false;
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020033 // |has_internal_source| is true if encoders created by this factory of the
34 // given codec will use internal camera sources, meaning that they don't
35 // require/expect frames to be delivered via webrtc::VideoEncoder::Encode.
36 // This flag is used as the internal_source parameter to
37 // webrtc::ViEExternalCodec::RegisterExternalSendCodec.
Niels Möller35928392020-07-16 12:08:44 +020038 bool has_internal_source = false;
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020039 };
40
philipel9b058032020-02-10 11:30:00 +010041 // An injectable class that is continuously updated with encoding conditions
42 // and selects the best encoder given those conditions.
43 class EncoderSelectorInterface {
44 public:
45 virtual ~EncoderSelectorInterface() {}
46
47 // Informs the encoder selector about which encoder that is currently being
48 // used.
49 virtual void OnCurrentEncoder(const SdpVideoFormat& format) = 0;
50
Mirta Dvornicic4f34d782020-02-26 13:01:19 +010051 // Called every time the available bitrate is updated. Should return a
philipel9b058032020-02-10 11:30:00 +010052 // non-empty if an encoder switch should be performed.
Mirta Dvornicic4f34d782020-02-26 13:01:19 +010053 virtual absl::optional<SdpVideoFormat> OnAvailableBitrate(
philipel9b058032020-02-10 11:30:00 +010054 const DataRate& rate) = 0;
55
56 // Called if the currently used encoder reports itself as broken. Should
57 // return a non-empty if an encoder switch should be performed.
58 virtual absl::optional<SdpVideoFormat> OnEncoderBroken() = 0;
59 };
60
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020061 // Returns a list of supported video formats in order of preference, to use
62 // for signaling etc.
63 virtual std::vector<SdpVideoFormat> GetSupportedFormats() const = 0;
64
philipel0bb08812019-07-11 13:23:16 +020065 // Returns a list of supported video formats in order of preference, that can
66 // also be tagged with additional information to allow the VideoEncoderFactory
67 // to separate between different implementations when CreateVideoEncoder is
68 // called.
69 virtual std::vector<SdpVideoFormat> GetImplementations() const {
70 return GetSupportedFormats();
71 }
72
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020073 // Returns information about how this format will be encoded. The specified
74 // format must be one of the supported formats by this factory.
Niels Möller2b781bf2020-07-16 14:19:41 +020075
76 // TODO(magjed): Try to get rid of this method. Since is_hardware_accelerated
77 // is unused, only factories producing internal source encoders (in itself a
78 // deprecated feature) needs to override this method.
79 virtual CodecInfo QueryVideoEncoder(const SdpVideoFormat& format) const {
80 return CodecInfo();
81 }
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020082
83 // Creates a VideoEncoder for the specified format.
84 virtual std::unique_ptr<VideoEncoder> CreateVideoEncoder(
85 const SdpVideoFormat& format) = 0;
86
philipel9b058032020-02-10 11:30:00 +010087 virtual std::unique_ptr<EncoderSelectorInterface> GetEncoderSelector() const {
88 return nullptr;
89 }
90
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020091 virtual ~VideoEncoderFactory() {}
92};
93
94} // namespace webrtc
95
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020096#endif // API_VIDEO_CODECS_VIDEO_ENCODER_FACTORY_H_