TSDuck v3.38-3675
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::Tuner Class Reference

General-purpose implementation of a digital TV tuner. More...

#include <tsTuner.h>

Inheritance diagram for ts::Tuner:
Collaboration diagram for ts::Tuner:

Public Member Functions

 Tuner (DuckContext &duck)
 Constructor.
 
 Tuner (DuckContext &duck, const UString &device_name, bool info_only)
 Constructor and open device name.
 
virtual ~Tuner () override
 Destructor.
 
virtual void abort (bool silent=false) override
 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 override
 Get the timeout for receive operation.
 
Reportreport () const
 Get a reference to the error report.
 
virtual void setDemuxBufferSize (size_t s) override
 Set the demux buffer size in bytes (Linux-specific).
 
virtual void setReceiverFilterName (const UString &name) override
 Specify a receiver filter name (Windows-specific).
 
virtual bool setReceiveTimeout (cn::milliseconds t) override
 Set the timeout for receive operations.
 
virtual void setSignalPoll (cn::milliseconds t) override
 Set the poll interval for signal timeout (Linux-specific).
 
virtual void setSignalTimeout (cn::milliseconds t) override
 Set the timeout before getting a signal on start.
 
virtual void setSignalTimeoutSilent (bool silent) override
 Set if an error should be reported on timeout before getting a signal on start.
 
virtual void setSinkQueueSize (size_t s) override
 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

General-purpose implementation of a digital TV tuner.

This class encapsulates physical tuners and file-based tuner emulators. When a "tuner name" is an XML file (a file path ending in ".xml"), the tuner emulator is used. Otherwise, a physical tuner is used.

The syntax of a physical tuner "device name" depends on the operating system.

Linux:

  • Syntax: /dev/dvb/adapterA[:F[:M[:V]]]
  • A = adapter number
  • F = frontend number (default: 0)
  • M = demux number (default: 0)
  • V = dvr number (default: 0)

Windows:

  • DirectShow/BDA tuner filter name

Constructor & Destructor Documentation

◆ Tuner() [1/2]

ts::Tuner::Tuner ( DuckContext duck)

Constructor.

Parameters
[in,out]duckTSDuck execution context.

◆ Tuner() [2/2]

ts::Tuner::Tuner ( DuckContext duck,
const UString device_name,
bool  info_only 
)

Constructor and open device name.

Parameters
[in,out]duckTSDuck execution context.
[in]device_nameTuner device name. If the name is empty, use the "first" or "default" tuner. If the name is a file path ending in ".xml", a tuner emulator is used.
[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.

Member Function Documentation

◆ open()

virtual bool ts::Tuner::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::Tuner::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::Tuner::isOpen ( ) const
overridevirtual

Check if the tuner is open.

Returns
True if the tuner is open.

Reimplemented from ts::TunerBase.

◆ infoOnly()

virtual bool ts::Tuner::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::Tuner::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::Tuner::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::Tuner::deviceInfo ( ) const
overridevirtual

Device-specific information.

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

Reimplemented from ts::TunerBase.

◆ devicePath()

virtual UString ts::Tuner::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::Tuner::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::Tuner::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::Tuner::start ( )
overridevirtual

Start receiving packets.

Returns
True on success, false on error.

Reimplemented from ts::TunerBase.

◆ stop()

virtual bool ts::Tuner::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.

◆ abort()

virtual void ts::Tuner::abort ( bool  silent = false)
overridevirtual

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 from ts::TunerBase.

◆ receive()

virtual size_t ts::Tuner::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::Tuner::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.

◆ setSignalTimeout()

virtual void ts::Tuner::setSignalTimeout ( cn::milliseconds  t)
overridevirtual

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 from ts::TunerBase.

◆ setSignalTimeoutSilent()

virtual void ts::Tuner::setSignalTimeoutSilent ( bool  silent)
overridevirtual

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 from ts::TunerBase.

◆ setReceiveTimeout()

virtual bool ts::Tuner::setReceiveTimeout ( cn::milliseconds  t)
overridevirtual

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 from ts::TunerBase.

◆ receiveTimeout()

virtual cn::milliseconds ts::Tuner::receiveTimeout ( ) const
overridevirtual

Get the timeout for receive operation.

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

Reimplemented from ts::TunerBase.

◆ setSignalPoll()

virtual void ts::Tuner::setSignalPoll ( cn::milliseconds  t)
overridevirtual

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 from ts::TunerBase.

◆ setDemuxBufferSize()

virtual void ts::Tuner::setDemuxBufferSize ( size_t  s)
overridevirtual

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 from ts::TunerBase.

◆ setSinkQueueSize()

virtual void ts::Tuner::setSinkQueueSize ( size_t  s)
overridevirtual

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 from ts::TunerBase.

◆ setReceiverFilterName()

virtual void ts::Tuner::setReceiverFilterName ( const UString name)
overridevirtual

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 from ts::TunerBase.

◆ displayStatus()

virtual std::ostream & ts::Tuner::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.

◆ 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: