blob: 9c573ae000db80e43074c304a135d722c81f9d1d [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 Chapovalov355b8d22021-08-13 16:50:37 +020038 const VideoDecoder::Settings& settings);
Niels Möllerf9063782018-02-20 16:09:48 +010039 bool DeregisterReceiveCodec(uint8_t payload_type);
40
Åsa Persson6cb74fd2018-06-01 15:13:42 +020041 // Returns a decoder specified by frame.PayloadType. The decoded frame
Artem Titovdcd7fc72021-08-09 13:02:57 +020042 // callback of the decoder is set to `decoded_frame_callback`. If no such
Åsa Persson6cb74fd2018-06-01 15:13:42 +020043 // decoder already exists an instance will be created and initialized.
44 // nullptr is returned if no decoder with the specified payload type was found
Niels Möllerf9063782018-02-20 16:09:48 +010045 // and the function failed to create one.
46 VCMGenericDecoder* GetDecoder(
47 const VCMEncodedFrame& frame,
48 VCMDecodedFrameCallback* decoded_frame_callback);
49
Niels Möllerf9063782018-02-20 16:09:48 +010050 private:
Danil Chapovalov7b78a312021-08-06 12:30:02 +020051 void CreateAndInitDecoder(const VCMEncodedFrame& frame);
Niels Möllerf9063782018-02-20 16:09:48 +010052
Danil Chapovalov7b78a312021-08-06 12:30:02 +020053 absl::optional<uint8_t> current_payload_type_;
54 absl::optional<VCMGenericDecoder> current_decoder_;
55 // Initialization paramaters for decoders keyed by payload type.
Danil Chapovalov355b8d22021-08-13 16:50:37 +020056 std::map<uint8_t, VideoDecoder::Settings> decoder_settings_;
Danil Chapovalov7b78a312021-08-06 12:30:02 +020057 // Decoders keyed by payload type.
58 std::map<uint8_t, VideoDecoder*> decoders_;
Niels Möllerf9063782018-02-20 16:09:48 +010059};
60
61} // namespace webrtc
62
63#endif // MODULES_VIDEO_CODING_DECODER_DATABASE_H_