arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | List of all members
IMediaSource Class Referenceabstract

Media Source Interface - Contract for Media Data Providers. More...

#include <IMediaSource.h>

Inheritance diagram for IMediaSource:
RTSPMediaCallbackSource RTSPMediaSource RTSPVideoEncoder H264RtpEncoder JPEGRtpEncoder

Public Member Functions

virtual RTSPFormatgetFormat ()=0
 Get the media format configuration.
 
virtual int packetSize ()
 Size of the next queued, ready-to-send fragment, for sources that provide already RTP-payload-ready, self-delimited fragments (e.g. RFC 2435 JPEG) instead of a continuous byte stream. For these sources, readBytes() must always be called with exactly packetSize() as maxBytes, so each call retrieves exactly one complete fragment instead of the transport having to guess where one RTP payload ends and the next begins.
 
virtual int readBytes (void *dest, int maxSamples)=0
 Read media data into provided buffer.
 
virtual void start ()
 Initialize media source for streaming.
 
virtual void stop ()
 Cleanup media source after streaming.
 

Detailed Description

Media Source Interface - Contract for Media Data Providers.

Member Function Documentation

◆ getFormat()

virtual RTSPFormat & getFormat ( )
pure virtual

Get the media format configuration.

Returns the RTSPFormat object that describes the media data characteristics including sample rate, bit depth, number of channels, and RTP packaging parameters. If no format has been explicitly set, creates a default 16-bit PCM format at 16kHz mono.

Returns
Pointer to RTSPFormat describing the media characteristics
Note
Default format: 16-bit PCM, 16000 Hz, 1 channel
See also
setFormat(), RTSPFormatPCM

Implemented in H264RtpEncoder, JPEGRtpEncoder, RTSPMediaCallbackSource, and RTSPMediaSource.

◆ packetSize()

virtual int packetSize ( )
inlinevirtual

Size of the next queued, ready-to-send fragment, for sources that provide already RTP-payload-ready, self-delimited fragments (e.g. RFC 2435 JPEG) instead of a continuous byte stream. For these sources, readBytes() must always be called with exactly packetSize() as maxBytes, so each call retrieves exactly one complete fragment instead of the transport having to guess where one RTP payload ends and the next begins.

Call it once before each readBytes() to size that call, and again right after to tell whether the fragment just read was the last one currently available - a 0 result means the caller should set the RTP marker bit on the fragment it just sent (and may advance the timestamp for the next frame).

Returns
-1 if this source is not packetized (use the plain readBytes() stream instead), 0 if packetized but nothing is queued right now, otherwise the size in bytes of the next fragment

Reimplemented in H264RtpEncoder, JPEGRtpEncoder, and RTSPMediaCallbackSource.

◆ readBytes()

virtual int readBytes ( void *  dest,
int  maxSamples 
)
pure virtual

Read media data into provided buffer.

This is the core method that provides media data to the streaming system. Implementation should fill the destination buffer with media samples in the format specified by getFormat(). The method should be non-blocking and return available data immediately.

Parameters
destPointer to buffer where media data should be written
maxBytesMaximum number of bytes that can be written to dest buffer
Returns
Actual number of bytes written to the buffer (0 if no data available)
Note
Data format must match the RTSPFormat returned by getFormat()
Should return 0 when no media data is available (not block)
Called periodically by the streaming system at the rate specified by format

Implemented in RTSPMediaSource, H264RtpEncoder, JPEGRtpEncoder, and RTSPMediaCallbackSource.

◆ start()

virtual void start ( )
inlinevirtual

Initialize media source for streaming.

Called when streaming is about to begin. Implementations should use this to initialize hardware, allocate buffers, start media capture, or perform any other setup required for media data generation.

Note
Called by RTSPMediaStreamer.start()
Default implementation does nothing (suitable for sources that need no setup)

Reimplemented in H264RtpEncoder, JPEGRtpEncoder, RTSPMediaCallbackSource, and RTSPMediaSource.

◆ stop()

virtual void stop ( )
inlinevirtual

Cleanup media source after streaming.

Called when streaming has ended. Implementations should use this to release hardware resources, deallocate buffers, stop media capture, or perform cleanup operations.

Note
Called by RTSPMediaStreamer.stop()
Default implementation does nothing (suitable for sources that need no cleanup)

Reimplemented in H264RtpEncoder, JPEGRtpEncoder, RTSPMediaCallbackSource, and RTSPMediaSource.


The documentation for this class was generated from the following file: