ifm3d
decoder_manager.h
1 /*
2  * Copyright (C) 2026-present ifm electronic, gmbh
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #ifndef IFM3D_RTSP_DECODER_MANAGER_H
7 #define IFM3D_RTSP_DECODER_MANAGER_H
8 
9 #include <memory>
10 #include <optional>
11 #include <string>
12 #include <unordered_map>
13 #include <vector>
14 
15 #include <ifm3d/rtsp/video_decoder.h>
16 
17 namespace ifm3d
18 {
19 
41  {
42  public:
47  explicit DecoderManager(std::optional<std::string> preferred_decoder = {});
48 
49  ~DecoderManager();
50 
55  struct DecoderInfo
56  {
57  /* Stable decoder name (e.g. "ffmpeg", "null"). */
58  std::string name;
59  /* True when the decoder can be used on the current system (e.g. the
60  * ffmpeg decoder found a usable libavcodec). */
61  bool available{false};
62  /* True when the decoder advertises H.264 decode support. */
63  bool supports_h264{false};
64  /* Human-readable reason when available is false; empty otherwise. */
65  std::string error;
66  };
67 
75  static std::vector<DecoderInfo> DiscoverDecoders();
76 
77  /* Non-copyable, non-movable. */
78  DecoderManager(const DecoderManager&) = delete;
79  DecoderManager& operator=(const DecoderManager&) = delete;
80  DecoderManager(DecoderManager&&) = delete;
81  DecoderManager& operator=(DecoderManager&&) = delete;
82 
88  void LoadDecoders();
89 
95  std::unique_ptr<ifm3d::rtsp::VideoDecoder> CreateDecoder(
96  ifm3d::rtsp::VideoCodec codec);
97 
102  [[nodiscard]] std::string SelectedDecoderName(
103  ifm3d::rtsp::VideoCodec codec) const;
104 
105  private:
106  void select_decoders();
107 
108  std::optional<std::string> _preferred_decoder;
109 
110  /* Registered decoder implementations, in preference order (real decoders
111  * first, the null decoder last). */
112  std::vector<std::unique_ptr<ifm3d::rtsp::VideoDecoderFactory>> _factories;
113 
114  /* Decoder selected for each codec (may be the null decoder). Empty until
115  * LoadDecoders() runs. */
116  std::unordered_map<ifm3d::rtsp::VideoCodec,
118  _selected;
119  };
120 
121 } // namespace ifm3d
122 
123 #endif /* IFM3D_RTSP_DECODER_MANAGER_H */
Lists and selects the video decoder implementations that are compiled into the RTSP module.
Definition: decoder_manager.h:41
static std::vector< DecoderInfo > DiscoverDecoders()
List the decoder implementations and report whether each is usable on the current system.
DecoderManager(std::optional< std::string > preferred_decoder={})
void LoadDecoders()
Resolve which decoder serves each codec, honouring preferred_decoder and falling back to the null dec...
std::string SelectedDecoderName(ifm3d::rtsp::VideoCodec codec) const
std::unique_ptr< ifm3d::rtsp::VideoDecoder > CreateDecoder(ifm3d::rtsp::VideoCodec codec)
Create a decoder for the given codec using the selected implementation.
Abstract decoder implementation (factory).
Definition: video_decoder.h:121
Describes a registered decoder implementation and whether it can be used on the current system.
Definition: decoder_manager.h:56