TMediaSocketT

primo::avblocks::modern::TMediaSocketT

template<typename CharT = char>
class TMediaSocketT : public primo::avblocks::modern::TParamsMixin<TMediaSocketT<char>>

Fluent wrapper for primo::avblocks::MediaSocket, an input or output point of a transcoder.

A socket describes either a container (WAV, AVI, MP4, etc.) with one or more streams, or a single elementary stream (MP3, M2V, etc.). Its pins (see pins()) describe the contained streams. Socket parameters, such as muxer options, are added with addParam(). The setters can be chained and return the object by rvalue reference on a temporary, so a whole socket can be built in one expression:

TMediaSocket("out.mp4").addPin(TMediaPin().streamInfo(video));

Template Parameters:

CharT – char for UTF-8 std::string paths, wchar_t for std::wstring paths. Use the aliases TMediaSocket and TMediaSocketW. Owns the raw object through a primo::ref. Not copyable, movable.

Unnamed Group

TMediaSocketT(TMediaSocketT&&) = default
TMediaSocketT &operator=(TMediaSocketT&&) = default

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

Unnamed Group

inline TMediaSocketT &&file(const string_type &path) &&
inline TMediaSocketT &file(const string_type &path) &

Sets the file associated with the socket.

Parameters:

path – File name.

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 TMediaSocketT &&file(std::nullptr_t) &&
inline TMediaSocketT &file(std::nullptr_t) &

Clears the file associated with 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 TMediaSocketT &&streamType(primo::codecs::StreamType::Enum type) &&
inline TMediaSocketT &streamType(primo::codecs::StreamType::Enum type) &

Sets explicitly the format of the associated file or stream, e.g.

AVI, WAV or MP4. If the socket has a file and no type, the type is deduced from the file name extension.

Parameters:

type – Stream type.

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 TMediaSocketT &&stream(primo::Stream *s) &&
inline TMediaSocketT &stream(primo::Stream *s) &

Sets the user stream, an alternative to a file, that is the source or sink of the socket.

The socket retains the stream. When both a file and a stream are set, the transcoder uses the stream.

Parameters:

s – The stream. Pass nullptr to clear a previously set stream.

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 TMediaSocketT &&streamSubType(primo::codecs::StreamSubType::Enum subType) &&
inline TMediaSocketT &streamSubType(primo::codecs::StreamSubType::Enum subType) &

Sets explicitly the stream subtype of the associated file or stream.

Parameters:

subType – Stream subtype.

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 TMediaSocketT &&addPin(TMediaPin &&pin) &&
inline TMediaSocketT &addPin(TMediaPin &&pin) &

Adds a pin (elementary stream) to the socket.

The pin list retains the pin.

Parameters:

pin – The pin to add.

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 TMediaSocketT &&timePosition(double time) &&
inline TMediaSocketT &timePosition(double time) &

Sets the time position of the socket.

On an input socket the transcoder seeks to this position before the transcoding starts. It cannot be changed while the transcoder is open. Has no effect if the socket is immutable.

Parameters:

time – Time position 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

template<typename Fn>
inline TMediaSocketT &&pinRef(int32_t index, Fn &&fn) &&
template<typename Fn>
inline TMediaSocketT &pinRef(int32_t index, Fn &&fn) &

Gives you a reference to the pin at index, so you can do something with it (read it or change it) without leaving a fluent chain.

fn is called once, immediately, with a TMediaPin& that refers to the pin inside this socket (it is not a copy), so changes made through it apply to the socket. The socket itself is returned, so chaining continues.

Use this instead of pins(index): that returns the pin and ends the chain, so the socket is no longer available to pass on, e.g. to TTranscoder::addOutput().

TTranscoder()
    .addInput(TMediaSocket(mediaInfo))
    .addOutput(
TMediaSocket(mediaInfo)
            .file("out.mp4")
            .pinRef(0, [](TMediaPin& pin) {
                pin.videoStreamInfo().frameRate(30.0);
            }))
    .open().run().close();

Parameters:
  • index – Zero-based index of the pin.

  • fn – Callable taking TMediaPin&.

Unnamed Group

template<typename Fn>
inline TMediaSocketT &&videoInfoRef(int32_t index, Fn &&fn) &&
template<typename Fn>
inline TMediaSocketT &videoInfoRef(int32_t index, Fn &&fn) &

Gives you a reference to the video stream info of the pin at index, so you can do something with it (read it or change it) without leaving a fluent chain. Shorter than pinRef() when only the stream info is needed.

fn is called once, immediately, with a TVideoStreamInfo& that refers to the stream info inside the pin (it is not a copy), so changes made through it apply to the socket. The socket is returned, so chaining continues. The pin must be a video pin.

TMediaSocket(mediaInfo).file("out.mp4")
    .videoInfoRef(0, [](TVideoStreamInfo& video) { video.frameRate(30.0); })

Unnamed Group

template<typename Fn>
inline TMediaSocketT &&audioInfoRef(int32_t index, Fn &&fn) &&
template<typename Fn>
inline TMediaSocketT &audioInfoRef(int32_t index, Fn &&fn) &

Gives you a reference to the audio stream info of the pin at index, so you can do something with it (read it or change it) without leaving a fluent chain. Same as videoInfoRef() for an audio pin.

TMediaSocket(mediaInfo).file("out.mp3")
    .audioInfoRef(0, [](TAudioStreamInfo& audio) { audio.sampleRate(48000); })

Public Types

using string_type = typename string_traits<CharT>::string_type

The string type for paths: std::string for char, std::wstring for wchar_t.

Public Functions

inline TMediaSocketT()

Creates an empty media socket.

inline explicit TMediaSocketT(primo::ref<primo::avblocks::MediaSocket> socket)

Takes ownership of an existing MediaSocket reference.

inline explicit TMediaSocketT(primo::avblocks::MediaSocket *socket)

Wraps a non-owned MediaSocket pointer, retaining it. Used by TMediaInfo::inputs() / outputs().

template<typename TMediaInfoArg>
inline explicit TMediaSocketT(const TMediaInfoArg &info)

Creates a socket from a TMediaInfo, wrapping Library::createMediaSocket(MediaInfo*).

The created socket contains the file path and pins from the media info, ready to be added as a transcoder input. Member template so the body is instantiation-checked, allowing TMediaInfo to be defined after TMediaSocketT without a circular dependency.

inline explicit TMediaSocketT(const char *preset)

Creates a socket pre-configured with the named AVBlocks preset (e.g.

Preset::Video::Generic::MP4::Base_H264_AAC).

TMediaSocketT(const TMediaSocketT&) = delete
TMediaSocketT &operator=(const TMediaSocketT&) = delete
inline string_type file() const

Returns the file path as a string_type (UTF-8 std::string for char, std::wstring for wchar_t), or empty string if not set.

inline primo::codecs::StreamType::Enum streamType() const

Returns the stream type of this socket (read from the underlying MediaSocket).

inline primo::codecs::StreamSubType::Enum streamSubType() const

Returns the stream sub-type of this socket (read from the underlying MediaSocket).

inline TMediaPinList pins() const

Returns a non-owning view of the pin list.

inline TMediaPin pins(int32_t index) const

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

inline TMetadata metadata() const

Returns the metadata associated with this socket as a TMetadata wrapper.

The returned object is invalid (valid() == false) if the socket has no metadata.

inline TMediaSocketT clone() const

Creates an independent deep copy of this socket (file, stream types and pins).

Typical use is to start the output from the input: input.clone().file(“out.mp4”).

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

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