libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
videoencoder.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/ancformat.h>
25#include <promeki/ancpacket.h>
26#include <promeki/uniqueptr.h>
27
28PROMEKI_NAMESPACE_BEGIN
29
30class MediaConfig;
31class Frame;
32
119class VideoEncoder {
120 public:
122 using UPtr = UniquePtr<VideoEncoder>;
123
125 using Factory = Function<VideoEncoder *()>;
126
134 struct BackendRecord {
135 VideoCodec::ID codecId;
136 VideoCodec::Backend
137 backend;
138 int weight = BackendWeight::
139 Vendored;
148 List<int> supportedInputs;
149 Factory factory;
150 };
151
153 virtual ~VideoEncoder();
154
165 VideoCodec codec() const { return _codec; }
166
177 void configure(const MediaConfig &config);
178
202 virtual Error submitFrame(const Frame &frame) = 0;
203
215 virtual Frame receiveFrame() = 0;
216
218 virtual Error flush() = 0;
219
221 virtual Error reset() = 0;
222
233 virtual void requestKeyframe();
234
236 Error lastError() const { return _lastError; }
237
239 const String &lastErrorMessage() const { return _lastErrorMessage; }
240
241 // ---- Frame-shaped helpers (public so nested pImpls in concrete backends can use them) ----
242
259 static UncompressedVideoPayload::Ptr selectInputPayload(const Frame &frame, int streamIndex = -1);
260
277 static AncPacket::List selectAncForSei(const Frame &frame, int pairedVideoStreamIndex,
278 const AncFormat::IDList &allowedFormats);
279
296 static Frame buildOutputFrame(const Frame &source, CompressedVideoPayload::Ptr emitted);
297
298 // ---- Backend registry ----
299
316 static Error registerBackend(BackendRecord record);
317
318 // ---- Internal bridge from VideoCodec ----
319 //
320 // These are the lookup surfaces VideoCodec::canEncode /
321 // createEncoder / encoderSupportedInputs / availableEncoderBackends
322 // call into. Public only so the VideoCodec wrapper (which
323 // lives in a different TU) can reach them without a friend
324 // declaration; application code should not use them directly.
325
327 static VideoCodec::BackendList availableBackends(VideoCodec::ID codecId);
328
336 static List<int> supportedInputsFor(VideoCodec::ID codecId, VideoCodec::Backend backend);
337
348 static Result<VideoEncoder *> create(VideoCodec::ID codecId, VideoCodec::Backend pinned,
349 const MediaConfig *config);
350
351 protected:
352 VideoEncoder() = default;
353
364 void setCodec(VideoCodec codec) { _codec = codec; }
365
374 virtual void onConfigure(const MediaConfig &config);
375
386 const MediaConfig &config() const;
387
388 Error _lastError;
389 String _lastErrorMessage;
390
392 void setError(Error err, const String &msg = String());
393
395 void clearError();
396
397 private:
398 UniquePtr<MediaConfig> _stashedConfig;
399 VideoCodec _codec;
400};
401
402PROMEKI_NAMESPACE_END
403
404#endif // PROMEKI_ENABLE_PROAV