blob: 34734ad5556305cbb16505410c932b470203c547 [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
49 // Deregisters an external decoder object specified by |payload_type|.
50 bool DeregisterExternalDecoder(uint8_t payload_type);
51
52 // Registers an external decoder object to the payload type |payload_type|.
53 void RegisterExternalDecoder(VideoDecoder* external_decoder,
54 uint8_t payload_type);
55
56 bool MatchesCurrentResolution(int width, int height) const;
57
58 private:
59 // Determines whether a new codec has to be created or not.
60 // Checks every setting apart from maxFramerate and startBitrate.
61 bool RequiresEncoderReset(const VideoCodec& send_codec);
62
63 void DeleteEncoder();
64
65 int number_of_cores_;
66 size_t max_payload_size_;
67 bool periodic_key_frames_;
68 bool pending_encoder_reset_;
69 VideoCodec send_codec_;
70 uint8_t encoder_payload_type_;
71 VideoEncoder* external_encoder_;
72 bool internal_source_;
73 VCMEncodedFrameCallback* const encoded_frame_callback_;
74 std::unique_ptr<VCMGenericEncoder> ptr_encoder_;
75};
76
77} // namespace webrtc
78
79#endif // MODULES_VIDEO_CODING_ENCODER_DATABASE_H_