TSDuck v3.40-3963
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TunerEmulator Class Reference

Digital TV tuner emulator. More...

#include <tsTunerEmulator.h>

Inheritance diagram for ts::TunerEmulator:
Collaboration diagram for ts::TunerEmulator:

Public Member Functions

 TunerEmulator (DuckContext &duck)
 Constructor.
 
virtual ~TunerEmulator () override
 Destructor.
 
virtual void abort (bool silent=false)
 Abort any pending or blocked reception.
 
virtual bool close (bool silent=false) override
 Close the tuner.
 
virtual const DeliverySystemSetdeliverySystems () const override
 Set of delivery systems which are supported by the tuner.
 
virtual UString deviceInfo () const override
 Device-specific information.
 
virtual UString deviceName () const override
 Get the device name of the tuner.
 
virtual UString devicePath () const override
 System-specific device path (for information only).
 
virtual std::ostream & displayStatus (std::ostream &strm, const UString &margin=UString(), bool extended=false) override
 Display the characteristics and status of the tuner.
 
virtual bool getCurrentTuning (ModulationArgs &params, bool reset_unknown) override
 Get the current tuning parameters.
 
virtual bool getSignalState (SignalState &state) override
 Check if a signal is present and get the signal state.
 
virtual bool infoOnly () const override
 Get the open mode.
 
virtual bool isOpen () const override
 Check if the tuner is open.
 
virtual bool open (const UString &device_name, bool info_only) override
 Open the tuner.
 
virtual size_t receive (TSPacket *buffer, size_t max_packets, const AbortInterface *abort=nullptr) override
 Receive packets.
 
virtual cn::milliseconds receiveTimeout () const
 Get the timeout for receive operation.
 
Reportreport () const
 Get a reference to the error report.
 
virtual void setDemuxBufferSize (size_t s)
 Set the demux buffer size in bytes (Linux-specific).
 
virtual void setReceiverFilterName (const UString &name)
 Specify a receiver filter name (Windows-specific).
 
virtual bool setReceiveTimeout (cn::milliseconds t)
 Set the timeout for receive operations.
 
virtual void setSignalPoll (cn::milliseconds t)
 Set the poll interval for signal timeout (Linux-specific).
 
virtual void setSignalTimeout (cn::milliseconds t)
 Set the timeout before getting a signal on start.
 
virtual void setSignalTimeoutSilent (bool silent)
 Set if an error should be reported on timeout before getting a signal on start.
 
virtual void setSinkQueueSize (size_t s)
 Set the max number of queued media samples (Windows-specific).
 
virtual bool start () override
 Start receiving packets.
 
virtual bool stop (bool silent=false) override
 Stop receiving packets.
 
virtual bool tune (ModulationArgs &params) override
 Tune to the specified parameters.
 

Static Public Member Functions

static bool GetAllTuners (DuckContext &duck, TunerPtrVector &tuners)
 Get the list of all existing physical tuners.
 

Static Public Attributes

static constexpr size_t DEFAULT_DEMUX_BUFFER_SIZE = 1024 * 1024
 Default demux buffer size in bytes (Linux-specific).
 
static constexpr cn::milliseconds DEFAULT_SIGNAL_POLL = cn::milliseconds(100)
 Default poll interval for signal timeout (Linux-specific).
 
static constexpr cn::milliseconds DEFAULT_SIGNAL_TIMEOUT = cn::seconds(5)
 Default timeout before getting a signal on start.
 
static constexpr size_t DEFAULT_SINK_QUEUE_SIZE = 1000
 Default max number of queued media samples (Windows-specific).
 

Protected Member Functions

bool checkTuneParameters (ModulationArgs &params) const
 Check the consistency of tune() parameters.
 
bool unimplemented () const
 Helper for unimplemented methods.
 

Protected Attributes

DuckContext_duck
 TSDuck execution context for subclasses.
 

Detailed Description

Digital TV tuner emulator.

A tuner emulator implements the TunerBase interface without physical tuner. The "device name" is the name of an XML file which describes the tuner configuration.

A tuner configuration contains a list of frequencies. The "tuner" can tune around each of these frequencies (center frequency with a given bandwidth). Each frequency is associated with a TS file. When the emulated tuner is tuned to a valid frequency, the reception is emulated by reading packets from the associated TS file again and again.

Sample XML tuner emulator configuration:

<?xml version="1.0" encoding="UTF-8"?>
<tsduck>
<defaults delivery="DVB-T" bandwidth="4,000,000" directory="/home/user/streams"/>
<channel frequency="474,000,000" file="mux1.ts"/>
<channel frequency="482,000,000" file="mux2.ts"/>
<channel frequency="490,000,000" file="mux3.ts"/>
<channel frequency="498,000,000" file="mux4.ts"/>
<channel frequency="506,000,000" file="mux5.ts"/>
<channel frequency="514,000,000" file="mux6.ts"/>
<channel frequency="522,000,000" file="mux7.ts"/>
<channel frequency="530,000,000" file="mux8.ts" delivery="DVB-T2" bandwidth="6,000,000"/>
</tsduck>
version()
TSDuck version as a string.
Definition tsduck.py:227

Sample tuning test using this tuner emulator. The various TS files are read as if they were actual muxes:

tsscan -d etuner.xml --uhf-band --first-channel 21 --last-channel 28 --service-list

Constructor & Destructor Documentation

◆ TunerEmulator()

ts::TunerEmulator::TunerEmulator ( DuckContext duck)

Constructor.

Parameters
[in,out]duckTSDuck execution context.

Member Function Documentation

◆ open()

virtual bool ts::TunerEmulator::open ( const UString device_name,
bool  info_only 
)
overridevirtual

Open the tuner.

Parameters
[in]device_nameTuner device name. If name is empty, use "first" or "default" tuner.
[in]info_onlyIf true, we will only fetch the properties of the tuner, we won't use it to receive streams. Thus, it is possible to open tuners which are already used to actually receive a stream.
Returns
True on success, false on error.

Reimplemented from ts::TunerBase.

◆ close()

virtual bool ts::TunerEmulator::close ( bool  silent = false)
overridevirtual

Close the tuner.

Parameters
[in]silentWhen true, do not report close errors.
Returns
True on success, false on error.

Reimplemented from ts::TunerBase.

◆ isOpen()

virtual bool ts::TunerEmulator::isOpen ( ) const
overridevirtual

Check if the tuner is open.

Returns
True if the tuner is open.

Reimplemented from ts::TunerBase.

◆ infoOnly()

virtual bool ts::TunerEmulator::infoOnly ( ) const
overridevirtual

Get the open mode.

Returns
True if the tuner is open to fetch information only. In that case, the tuner cannot receive streams.

Reimplemented from ts::TunerBase.

◆ deliverySystems()

virtual const DeliverySystemSet & ts::TunerEmulator::deliverySystems ( ) const
overridevirtual

Set of delivery systems which are supported by the tuner.

Returns
A constant reference to the set of delivery systems which are supported by the tuner.

Reimplemented from ts::TunerBase.

◆ deviceName()

virtual UString ts::TunerEmulator::deviceName ( ) const
overridevirtual

Get the device name of the tuner.

Returns
The device name of the tuner.

Reimplemented from ts::TunerBase.

◆ deviceInfo()

virtual UString ts::TunerEmulator::deviceInfo ( ) const
overridevirtual

Device-specific information.

Returns
A string with device-specific information. Can be empty.

Reimplemented from ts::TunerBase.

◆ devicePath()

virtual UString ts::TunerEmulator::devicePath ( ) const
overridevirtual

System-specific device path (for information only).

Returns
A string with system-specific device path. Can be empty.

Reimplemented from ts::TunerBase.

◆ getSignalState()

virtual bool ts::TunerEmulator::getSignalState ( SignalState state)
overridevirtual

Check if a signal is present and get the signal state.

Parameters
[out]stateReturned state of the tuner. Some fields may be unset if unavailable with that tuner.
Returns
True in case of success (even if no signal was detected), false on error.

Reimplemented from ts::TunerBase.

◆ tune()

virtual bool ts::TunerEmulator::tune ( ModulationArgs params)
overridevirtual

Tune to the specified parameters.

Parameters
[in,out]paramsTuning parameters. Updated with missing default values.
Returns
True on success, false on error.

Reimplemented from ts::TunerBase.

◆ start()

virtual bool ts::TunerEmulator::start ( )
overridevirtual

Start receiving packets.

Returns
True on success, false on error.

Reimplemented from ts::TunerBase.

◆ stop()

virtual bool ts::TunerEmulator::stop ( bool  silent = false)
overridevirtual

Stop receiving packets.

Parameters
[in]silentWhen true, do not report close errors.
Returns
True on success, false on error.

Reimplemented from ts::TunerBase.

◆ receive()

virtual size_t ts::TunerEmulator::receive ( TSPacket buffer,
size_t  max_packets,
const AbortInterface abort = nullptr 
)
overridevirtual

Receive packets.

Parameters
[out]bufferAddress of TS packet receive buffer. Read only complete 188-byte TS packets.
[in]max_packetsMaximum number of packets to read in buffer.
[in]abortIf non-zero, invoked when I/O is interrupted (in case of user-interrupt, return, otherwise retry).
Returns
The number of actually received packets (in the range 1 to max_packets). Returning zero means error or end of input.

Reimplemented from ts::TunerBase.

◆ getCurrentTuning()

virtual bool ts::TunerEmulator::getCurrentTuning ( ModulationArgs params,
bool  reset_unknown 
)
overridevirtual

Get the current tuning parameters.

Parameters
[in,out]paramsReturned tuning parameters. Modify only the properties which can be reported by the tuner.
[in]reset_unknownIf true, the unknown values (those which are not reported by the tuner) are reset to unknown/zero/auto values. Otherwise, they are left unmodified.
Returns
True on success, false on error.

Reimplemented from ts::TunerBase.

◆ displayStatus()

virtual std::ostream & ts::TunerEmulator::displayStatus ( std::ostream &  strm,
const UString margin = UString(),
bool  extended = false 
)
overridevirtual

Display the characteristics and status of the tuner.

Parameters
[in,out]strmOutput text stream.
[in]marginLeft margin to display.
[in]extendedDisplay "extended" information. Can be very verbose.
Returns
A reference to strm.

Reimplemented from ts::TunerBase.

◆ GetAllTuners()

static bool ts::TunerBase::GetAllTuners ( DuckContext duck,
TunerPtrVector tuners 
)
staticinherited

Get the list of all existing physical tuners.

Parameters
[in,out]duckTSDuck execution context.
[out]tunersReturned list of physical tuners on the system.
Returns
True on success, false on error.

◆ abort()

virtual void ts::TunerBase::abort ( bool  silent = false)
virtualinherited

Abort any pending or blocked reception.

This unblocks a blocked reader but leaves the tuner in an undefined state. The only safe option after this is a close().

Parameters
[in]silentWhen true, do not report close errors.

Reimplemented in ts::Tuner, ts::TunerDevice, and ts::TunerDevice.

◆ setSignalTimeout()

virtual void ts::TunerBase::setSignalTimeout ( cn::milliseconds  t)
virtualinherited

Set the timeout before getting a signal on start.

If zero, do not wait for signal on start. Must be set before start().

Parameters
[in]tNumber of milliseconds to wait after start() before receiving a signal.

Reimplemented in ts::Tuner, ts::TunerDevice, and ts::TunerDevice.

◆ setSignalTimeoutSilent()

virtual void ts::TunerBase::setSignalTimeoutSilent ( bool  silent)
virtualinherited

Set if an error should be reported on timeout before getting a signal on start.

Must be set before start().

Parameters
[in]silentIf true, no error message will be reported if no signal is received after the timeout on start.

Reimplemented in ts::Tuner, ts::TunerDevice, and ts::TunerDevice.

◆ setReceiveTimeout()

virtual bool ts::TunerBase::setReceiveTimeout ( cn::milliseconds  t)
virtualinherited

Set the timeout for receive operations.

Parameters
[in]tNumber of milliseconds to wait before receiving packets in a receive() operation. If zero (the default), no timeout is applied.
Returns
True on success, false on error.

Reimplemented in ts::Tuner, ts::TunerDevice, and ts::TunerDevice.

◆ receiveTimeout()

virtual cn::milliseconds ts::TunerBase::receiveTimeout ( ) const
virtualinherited

Get the timeout for receive operation.

Returns
The timeout for receive operation.
See also
setReceiveTimeout()

Reimplemented in ts::Tuner, ts::TunerDevice, and ts::TunerDevice.

◆ setSignalPoll()

virtual void ts::TunerBase::setSignalPoll ( cn::milliseconds  t)
virtualinherited

Set the poll interval for signal timeout (Linux-specific).

Must be set before start(). This is a Linux-specific method which does nothing on other systems.

Parameters
[in]tPoll interval in milliseconds.

Reimplemented in ts::Tuner, and ts::TunerDevice.

◆ setDemuxBufferSize()

virtual void ts::TunerBase::setDemuxBufferSize ( size_t  s)
virtualinherited

Set the demux buffer size in bytes (Linux-specific).

Must be set before start(). This is a Linux-specific method which does nothing on other systems.

Parameters
[in]sThe demux buffer size in bytes.

Reimplemented in ts::Tuner, and ts::TunerDevice.

◆ setSinkQueueSize()

virtual void ts::TunerBase::setSinkQueueSize ( size_t  s)
virtualinherited

Set the max number of queued media samples (Windows-specific).

Must be set before start(). This is a Windows-specific method which does nothing on other systems.

Parameters
[in]sMax number of media samples in the queue between the graph thread and the application thread.

Reimplemented in ts::Tuner, and ts::TunerDevice.

◆ setReceiverFilterName()

virtual void ts::TunerBase::setReceiverFilterName ( const UString name)
virtualinherited

Specify a receiver filter name (Windows-specific).

Must be set before open(). This is a Windows-specific method which does nothing on other systems.

Parameters
[in]nameName of the receiver filter to use. The DirectShow graph will use the specified receiver filter instead of the standard search algorithm.

Reimplemented in ts::Tuner, and ts::TunerDevice.

◆ report()

Report & ts::TunerBase::report ( ) const
inlineinherited

Get a reference to the error report.

Returns
A reference to the error report.

◆ checkTuneParameters()

bool ts::TunerBase::checkTuneParameters ( ModulationArgs params) const
protectedinherited

Check the consistency of tune() parameters.

Parameters
[in,out]paramsModulation parameters. Updated with default values.
Returns
True on success, false on error.

◆ unimplemented()

bool ts::TunerBase::unimplemented ( ) const
protectedinherited

Helper for unimplemented methods.

Display a standard error message.

Returns
False.

Member Data Documentation

◆ DEFAULT_SINK_QUEUE_SIZE

constexpr size_t ts::TunerBase::DEFAULT_SINK_QUEUE_SIZE = 1000
staticconstexprinherited

Default max number of queued media samples (Windows-specific).

See also
setSinkQueueSize().

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