blob: e726669db2cfff5f47e1d4f0b5f623f48079fdb5 [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_DECODER_DATABASE_H_
12#define MODULES_VIDEO_CODING_DECODER_DATABASE_H_
13
Danil Chapovalov7b78a312021-08-06 12:30:02 +020014#include <stdint.h>
Niels Möllerf9063782018-02-20 16:09:48 +010015
Danil Chapovalov7b78a312021-08-06 12:30:02 +020016#include <map>
17
18#include "absl/types/optional.h"
19#include "api/video_codecs/video_decoder.h"
20#include "modules/video_coding/encoded_frame.h"
Niels Möllerf9063782018-02-20 16:09:48 +010021#include "modules/video_coding/generic_decoder.h"
22
23namespace webrtc {
24
Niels Möllerf9063782018-02-20 16:09:48 +010025class VCMDecoderDataBase {
26 public:
Danil Chapovalov7b78a312021-08-06 12:30:02 +020027 VCMDecoderDataBase() = default;
28 VCMDecoderDataBase(const VCMDecoderDataBase&) = delete;
29 VCMDecoderDataBase& operator=(const VCMDecoderDataBase&) = delete;
30 ~VCMDecoderDataBase() = default;
Niels Möllerf9063782018-02-20 16:09:48 +010031
32 bool DeregisterExternalDecoder(uint8_t payload_type);
Danil Chapovalov7b78a312021-08-06 12:30:02 +020033 void RegisterExternalDecoder(uint8_t payload_type,
34 VideoDecoder* external_decoder);
Johannes Kron16359f62021-02-18 23:37:22 +010035 bool IsExternalDecoderRegistered(uint8_t payload_type) const;
Niels Möllerf9063782018-02-20 16:09:48 +010036
Niels Möller582102c2020-08-07 16:19:56 +020037 bool RegisterReceiveCodec(uint8_t payload_type,
Danil Chapovalov7b78a312021-08-06 12:30:02 +020038 const VideoCodec& receive_codec,
Niels Möller18c83d32020-08-07 14:14:49 +020039 int number_of_cores);
Niels Möllerf9063782018-02-20 16:09:48 +010040 bool DeregisterReceiveCodec(uint8_t payload_type);
41
Åsa Persson6cb74fd2018-06-01 15:13:42 +020042 // Returns a decoder specified by frame.PayloadType. The decoded frame
Artem Titovdcd7fc72021-08-09 13:02:57 +020043 // callback of the decoder is set to `decoded_frame_callback`. If no such
Åsa Persson6cb74fd2018-06-01 15:13:42 +020044 // decoder already exists an instance will be created and initialized.
45 // nullptr is returned if no decoder with the specified payload type was found
Niels Möllerf9063782018-02-20 16:09:48 +010046 // and the function failed to create one.
47 VCMGenericDecoder* GetDecoder(
48 const VCMEncodedFrame& frame,
49 VCMDecodedFrameCallback* decoded_frame_callback);
50
Niels Möllerf9063782018-02-20 16:09:48 +010051 private:
Danil Chapovalov7b78a312021-08-06 12:30:02 +020052 struct DecoderSettings {
53 VideoCodec settings;
54 int number_of_cores;
55 };
Niels Möllerf9063782018-02-20 16:09:48 +010056
Danil Chapovalov7b78a312021-08-06 12:30:02 +020057 void CreateAndInitDecoder(const VCMEncodedFrame& frame);
Niels Möllerf9063782018-02-20 16:09:48 +010058
Danil Chapovalov7b78a312021-08-06 12:30:02 +020059 absl::optional<uint8_t> current_payload_type_;
60 absl::optional<VCMGenericDecoder> current_decoder_;
61 // Initialization paramaters for decoders keyed by payload type.
62 std::map<uint8_t, DecoderSettings> decoder_settings_;
63 // Decoders keyed by payload type.
64 std::map<uint8_t, VideoDecoder*> decoders_;
Niels Möllerf9063782018-02-20 16:09:48 +010065};
66
67} // namespace webrtc
68
69#endif // MODULES_VIDEO_CODING_DECODER_DATABASE_H_