libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
videodecoder.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_PROAV
13#include <functional>
14#include <promeki/function.h>
15#include <promeki/namespace.h>
16#include <promeki/string.h>
17#include <promeki/error.h>
18#include <promeki/list.h>
19#include <promeki/result.h>
20#include <promeki/videocodec.h>
24#include <promeki/ancpacket.h>
26#include <promeki/uniqueptr.h>
27
28PROMEKI_NAMESPACE_BEGIN
29
30class MediaConfig;
31class Frame;
32
80class VideoDecoder {
81 public:
83 using UPtr = UniquePtr<VideoDecoder>;
84
86 using Factory = Function<VideoDecoder *()>;
87
93 struct BackendRecord {
94 VideoCodec::ID codecId;
95 VideoCodec::Backend backend;
96 int weight = BackendWeight::Vendored;
103 List<int> supportedOutputs;
104 Factory factory;
105 };
106
108 virtual ~VideoDecoder();
109
111 VideoCodec codec() const { return _codec; }
112
121 void configure(const MediaConfig &config);
122
141 virtual Error submitFrame(const Frame &frame) = 0;
142
153 virtual Frame receiveFrame() = 0;
154
156 virtual Error flush() = 0;
157
159 virtual Error reset() = 0;
160
162 Error lastError() const { return _lastError; }
163
165 const String &lastErrorMessage() const { return _lastErrorMessage; }
166
190 MediaIOAllocator::Ptr allocator() const;
191
209 virtual void setAllocator(MediaIOAllocator::Ptr a);
210
211 // ---- Backend registry ----
212
217 static Error registerBackend(BackendRecord record);
218
219 // ---- Internal bridge from VideoCodec (see VideoEncoder's equivalents) ----
220
221 static VideoCodec::BackendList availableBackends(VideoCodec::ID codecId);
222 static List<int> supportedOutputsFor(VideoCodec::ID codecId, VideoCodec::Backend backend);
223 static Result<VideoDecoder *> create(VideoCodec::ID codecId, VideoCodec::Backend pinned,
224 const MediaConfig *config);
225
226 protected:
227 VideoDecoder() = default;
228
230 void setCodec(VideoCodec codec) { _codec = codec; }
231
238 virtual void onConfigure(const MediaConfig &config);
239
246 const MediaConfig &config() const;
247
248 Error _lastError;
249 String _lastErrorMessage;
250
252 void setError(Error err, const String &msg = String());
253
255 void clearError();
256
266 MediaIOAllocator::Ptr _allocator;
267
268 public:
269 // ---- Frame-shaped helpers (public so nested pImpls in concrete backends can use them) ----
270
287 static CompressedVideoPayload::Ptr selectInputPayload(const Frame &frame, int streamIndex = -1);
288
301 static void attachExtractedAnc(Frame &frame, AncPacket pkt, int pairedVideoStreamIndex);
302
318 static Frame buildOutputFrame(const Frame &source, UncompressedVideoPayload::Ptr emitted);
319
320 private:
321 UniquePtr<MediaConfig> _stashedConfig;
322 VideoCodec _codec;
323};
324
325PROMEKI_NAMESPACE_END
326
327#endif // PROMEKI_ENABLE_PROAV