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 withaddParam(). 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 –
charfor UTF-8std::stringpaths,wchar_tforstd::wstringpaths. Use the aliasesTMediaSocketandTMediaSocketW. Owns the raw object through aprimo::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
nullptrto 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.fnis called once, immediately, with aTMediaPin&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. toTTranscoder::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 thanpinRef()when only the stream info is needed.fnis called once, immediately, with aTVideoStreamInfo&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 asvideoInfoRef()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::stringforchar,std::wstringforwchar_t.
Public Functions
-
inline TMediaSocketT()¶
Creates an empty media socket.
-
inline explicit TMediaSocketT(primo::ref<primo::avblocks::MediaSocket> socket)¶
Takes ownership of an existing
MediaSocketreference.
-
inline explicit TMediaSocketT(primo::avblocks::MediaSocket *socket)¶
Wraps a non-owned
MediaSocketpointer, retaining it. Used byTMediaInfo::inputs()/outputs().
-
template<typename TMediaInfoArg>
inline explicit TMediaSocketT(const TMediaInfoArg &info)¶ Creates a socket from a
TMediaInfo, wrappingLibrary::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
TMediaInfoto be defined afterTMediaSocketTwithout 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-8std::stringforchar,std::wstringforwchar_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
TMetadatawrapper.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.