blob: 09baff01e59987eb86eaca6fa1e3aeb8576571c7 [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
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
Niels Möllerf9063782018-02-20 16:09:48 +010015#include <memory>
16
Yves Gerey3e707812018-11-28 16:47:49 +010017#include "api/video_codecs/video_codec.h"
18#include "api/video_codecs/video_encoder.h"
Niels Möllerf9063782018-02-20 16:09:48 +010019#include "modules/video_coding/generic_encoder.h"
20
21namespace webrtc {
22
23class VCMEncoderDataBase {
24 public:
25 explicit VCMEncoderDataBase(VCMEncodedFrameCallback* encoded_frame_callback);
26 ~VCMEncoderDataBase();
27
28 // Sets the sender side codec and initiates the desired codec given the
29 // VideoCodec struct.
30 // Returns true if the codec was successfully registered, false otherwise.
31 bool SetSendCodec(const VideoCodec* send_codec,
32 int number_of_cores,
33 size_t max_payload_size);
34
35 // Registers and initializes an external encoder object.
36 // |internal_source| should be set to true if the codec has an internal
37 // video source and doesn't need the user to provide it with frames via
38 // the Encode() method.
39 void RegisterExternalEncoder(VideoEncoder* external_encoder,
Niels Möllerf9063782018-02-20 16:09:48 +010040 bool internal_source);
41
Niels Möllerbf3dbb42018-03-16 13:38:46 +010042 // Deregisters any external encoder.
43 void DeregisterExternalEncoder();
Niels Möllerf9063782018-02-20 16:09:48 +010044
45 VCMGenericEncoder* GetEncoder();
46
Niels Möllerf9063782018-02-20 16:09:48 +010047 bool MatchesCurrentResolution(int width, int height) const;
48
49 private:
50 // Determines whether a new codec has to be created or not.
51 // Checks every setting apart from maxFramerate and startBitrate.
52 bool RequiresEncoderReset(const VideoCodec& send_codec);
53
54 void DeleteEncoder();
55
56 int number_of_cores_;
57 size_t max_payload_size_;
Niels Möllerf9063782018-02-20 16:09:48 +010058 bool pending_encoder_reset_;
59 VideoCodec send_codec_;
Niels Möllerf9063782018-02-20 16:09:48 +010060 VideoEncoder* external_encoder_;
61 bool internal_source_;
62 VCMEncodedFrameCallback* const encoded_frame_callback_;
63 std::unique_ptr<VCMGenericEncoder> ptr_encoder_;
64};
65
66} // namespace webrtc
67
68#endif // MODULES_VIDEO_CODING_ENCODER_DATABASE_H_