TTranscoderT

primo::avblocks::modern::TTranscoderT

template<typename CharT = char>
class TTranscoderT

Fluent wrapper for primo::avblocks::Transcoder, which encodes, decodes and transforms audio and video.

Add input and output sockets, then either run the whole job with transcode() (file to file), or drive it step by step: open(), run() or push() / pull() / flush(), then close(). Failures are reported with TAVBlocksException; the try* variants return false instead. Progress and status are received through lambdas (see onProgress()).

TTranscoder()
    .allowDemoMode(true)
    .addInput(TMediaSocket(mediaInfo))
    .addOutput(TMediaSocket("out.mp4"))
    .transcode();

Template Parameters:

CharT – char or wchar_t, matching the sockets used. Use the aliases TTranscoder and TTranscoderW. Owns the raw object through a primo::ref. Not copyable, movable.

Unnamed Group

TTranscoderT(TTranscoderT&&) = default
TTranscoderT &operator=(TTranscoderT&&) = default

Move construction/assignment transfers ownership of the underlying object. The moved-from object no longer wraps anything.

Unnamed Group

inline TTranscoderT &allowDemoMode(bool allow = true) &
inline TTranscoderT &&allowDemoMode(bool allow = true) &&

Sets whether demo mode (unlicensed transcoding) is allowed.

When allowed, a demo overlay is applied if a required codec is not licensed; otherwise the transcoder fails with AVBlocksError::UnlicensedFeature. Demo mode is on by default in the Demo release and off in the OEM release.

Parameters:

allow – true to allow demo mode.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Unnamed Group

inline TTranscoderT &onProgress(std::function<void(double, double)> f) &
inline TTranscoderT &&onProgress(std::function<void(double, double)> f) &&

Sets a function called periodically during run() to report progress.

Parameters:

f – Function taking the current and total time in seconds.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Unnamed Group

inline TTranscoderT &onStatus(std::function<void(primo::avblocks::TranscoderStatus::Enum)> f) &
inline TTranscoderT &&onStatus(std::function<void(primo::avblocks::TranscoderStatus::Enum)> f) &&

Sets a function called during run() to report the status of the current operation.

Parameters:

f – Function taking the TranscoderStatus.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Unnamed Group

inline TTranscoderT &onContinue(std::function<bool(double)> f) &
inline TTranscoderT &&onContinue(std::function<bool(double)> f) &&

Sets a function that controls whether run() continues.

It is called with the current time in seconds. Return true to continue or false to stop gracefully, leaving valid output.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Unnamed Group

inline TTranscoderT &onInputChange(std::function<void(int32_t)> f) &
inline TTranscoderT &&onInputChange(std::function<void(int32_t)> f) &&

Sets a function called when an input format is detected or changes in push mode, with the index of the input socket.

It can inspect the detected inputs and reconfigure outputs.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Unnamed Group

inline TTranscoderT &addInput(const TMediaSocketT<CharT> &socket) &
inline TTranscoderT &&addInput(const TMediaSocketT<CharT> &socket) &&

Adds an input socket.

The transcoder retains the socket.

Parameters:

socket – The input socket.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Unnamed Group

inline TTranscoderT &removeInput(int32_t index) &
inline TTranscoderT &&removeInput(int32_t index) &&

Removes the input socket at index.

Parameters:

index – Zero-based index of the socket.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Unnamed Group

inline TTranscoderT &addOutput(const TMediaSocketT<CharT> &socket) &
inline TTranscoderT &&addOutput(const TMediaSocketT<CharT> &socket) &&

Adds an output socket.

The transcoder retains the socket.

Parameters:

socket – The output socket.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Unnamed Group

inline TTranscoderT &removeOutput(int32_t index) &
inline TTranscoderT &&removeOutput(int32_t index) &&

Removes the output socket at index.

Parameters:

index – Zero-based index of the socket.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Unnamed Group

inline TTranscoderT &open() &
inline TTranscoderT &&open() &&

Initializes the transcoder from the configured inputs and outputs.

When it succeeds the transcoder is ready to process data with run(), or with push() and pull().

Throws:

TAVBlocksException – if the transcoder cannot be opened.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Unnamed Group

inline TTranscoderT &run() &
inline TTranscoderT &&run() &&

Runs an automatic transcoding.

It returns when the transcoding is finished. All inputs and outputs must be associated with files or user streams.

Throws:

TAVBlocksException – if the transcoding fails or run mode cannot be used with these inputs and outputs.

Returns:

This object, for chaining. On a temporary the rvalue overload returns the object by rvalue reference, so the chain can be returned or moved.

Public Functions

inline TTranscoderT()

Creates a transcoder with no inputs and outputs.

TTranscoderT(const TTranscoderT&) = delete
TTranscoderT &operator=(const TTranscoderT&) = delete
inline TTranscoderCallback &ensureCallback()

Returns the callback adapter, creating it and installing it in the transcoder on first use.

inline TMediaSocketList inputs() const

Returns a non-owning view of the input socket list.

inline TMediaSocketT<CharT> inputs(int32_t index) const

Returns the input socket at index, wrapping the existing (non-owned) pointer.

inline TMediaSocketList outputs() const

Returns a non-owning view of the output socket list.

inline TMediaSocketT<CharT> outputs(int32_t index) const

Returns the output socket at index, wrapping the existing (non-owned) pointer.

inline bool tryOpen()

Opens the transcoder without throwing. Returns true on success.

inline bool pull(int32_t &outputIndex, TMediaSample &sample)

Pulls output data from the transcoder.

Parameters:
  • outputIndex – [out] Receives the index of the output socket the data belongs to.

  • sample – [out] Receives the output data.

Returns:

true on success.

inline bool push(int32_t inputIndex, TMediaSample &sample)

Pushes input data to the transcoder.

The sample is used only within this call and is not retained. The transcoder may consume only part of it: on return the buffer’s data offset and size show what is left, which matters when more data is appended for the next push.

Parameters:
  • inputIndex – Index of the input socket the data is for.

  • sample – The input data.

Returns:

true on success.

inline bool pushEos(int32_t inputIndex)

Signals end-of-stream on the input socket at inputIndex.

Equivalent to pushing a null (empty) sample.

inline void close()

Closes the transcoder. When closed it neither accepts nor delivers data. The inputs and outputs are not modified.

inline void transcode()

Opens, runs and closes the transcoder (file to file mode): the whole open().run().close() sequence in one call.

The transcoder is closed even if run() throws; TAVBlocksException is thrown if it cannot be opened or fails to run.

TTranscoder().allowDemoMode(true).addInput(in).addOutput(out).transcode();

inline bool flush()

Flushes the data buffered in the transcoder to the output and marks the end of the stream for all inputs.

Push mode only. Do not push data after flushing.

Returns:

true on success.

inline TErrorInfo error() const

Returns the error information for the last operation.

inline primo::avblocks::Transcoder *get() const

Returns the raw underlying pointer. For interop with the core API only.