blob: 2753c7bd2e428d3377cefd547810746cd49b3ddd [file] [log] [blame]
Niels Möllerf9063782018-02-20 16:09:48 +01001/*
2 * Copyright (c) 2018 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 MODULES_VIDEO_CODING_ENCODER_DATABASE_H_
12#define MODULES_VIDEO_CODING_ENCODER_DATABASE_H_
13
14#include <memory>
15
16#include "modules/video_coding/generic_encoder.h"
17
18namespace webrtc {
19
20class VCMEncoderDataBase {
21 public:
22 explicit VCMEncoderDataBase(VCMEncodedFrameCallback* encoded_frame_callback);
23 ~VCMEncoderDataBase();
24
25 // Sets the sender side codec and initiates the desired codec given the
26 // VideoCodec struct.
27 // Returns true if the codec was successfully registered, false otherwise.
28 bool SetSendCodec(const VideoCodec* send_codec,
29 int number_of_cores,
30 size_t max_payload_size);
31
32 // Registers and initializes an external encoder object.
33 // |internal_source| should be set to true if the codec has an internal
34 // video source and doesn't need the user to provide it with frames via
35 // the Encode() method.
36 void RegisterExternalEncoder(VideoEncoder* external_encoder,
37 uint8_t payload_type,
38 bool internal_source);
39
40 // Deregisters an external encoder. Returns true if the encoder was
41 // found and deregistered, false otherwise. |was_send_codec| is set to true
42 // if the external encoder was the send codec before being deregistered.
43 bool DeregisterExternalEncoder(uint8_t payload_type, bool* was_send_codec);
44
45 VCMGenericEncoder* GetEncoder();
46
47 bool SetPeriodicKeyFrames(bool enable);
48
Niels Möllerf9063782018-02-20 16:09:48 +010049 bool MatchesCurrentResolution(int width, int height) const;
50
51 private:
52 // Determines whether a new codec has to be created or not.
53 // Checks every setting apart from maxFramerate and startBitrate.
54 bool RequiresEncoderReset(const VideoCodec& send_codec);
55
56 void DeleteEncoder();
57
58 int number_of_cores_;
59 size_t max_payload_size_;
60 bool periodic_key_frames_;
61 bool pending_encoder_reset_;
62 VideoCodec send_codec_;
63 uint8_t encoder_payload_type_;
64 VideoEncoder* external_encoder_;
65 bool internal_source_;
66 VCMEncodedFrameCallback* const encoded_frame_callback_;
67 std::unique_ptr<VCMGenericEncoder> ptr_encoder_;
68};
69
70} // namespace webrtc
71
72#endif // MODULES_VIDEO_CODING_ENCODER_DATABASE_H_