vdr/device.h
Klaus Schmidinger da948a50d2 Version 1.3.38
- Fixed handling second audio and Dolby Digital PIDs for encrypted channels
  (was broken in version 1.3.37).
- Improved TS/PES conversion to better handle lost TS packets (thanks to
  Reinhard Nissl).
- Limited the frequency of log messages from the cRepackers.
- Now using the gettid() syscall to get a thread's pid, so that we get a
  useful value on NPTL systems (suggested by Johannes Stezenbach).
- Fixed the RCU remote control handling to avoid problems with NPTL (thanks
  to Andreas Share for reporting a lockup with the RCU on NPTL systems).
- When displaying the amount of free disk space, the space consumed by
  recordings that have been "deleted" but not yet actually "removed" is now
  taken into account (suggested by Christian Vogt).
- Now avoiding unnecessary disk access when checking if there are deleted
  recordings that need to be removed (reported by Carsten Koch).
- Fixed handling the DELETEDLIFETIME when removing deleted recordings. Now
  a deleted recording is retained at least DELETEDLIFETIME seconds before
  actually removing it.
  The value of DELETEDLIFETIME has been changed to 300. So after (possibly
  inadvertently) deleting a recording, there will be at least 5 minutes
  in which it can be recovered (unless a new recording immediately requires
  the disk space). The count starts again at 0 every time VDR is started.
- Fixed a possible crash when displaying the "Low disk space!" message from
  a background thread (thanks to Christof Steininger).
- Fixed handling OSD areas that have invalid sizes (thanks to Marco Schlüßler).
- Added a mutex to AssertFreeDiskSpace() to make sure calls from foreground
  and background threads won't interfere.
- The main menu now dynamically updates its contents in case an instant
  recording or replay stops, etc.
- The version number of EPG events is now also stored in the epg.data file
  (thanks to Kendy Kutzner).
- EPG events that are no longer in the currently broadcasted data stream are
  now automatically deleted.
- Removed an invalid access to Event->schedule in cSchedule::DelEvent().
- Modified cSchedule::Cleanup() (events are always sorted by time).
- Schedules are now cleaned up once every hour (not only at 05:00).
- The "Schedule" and "What's on now/next?" menus are now updated if a timer
  is set or modified.
- cTimer no longer has its own 'schedule' member, it rather uses that of the
  event it has been set to.
- The "Red" button in the "Schedule", "What's on now/next?" and "Event" menus
  now immediately creates a timer for the selected event and marks it with 'T'.
  If the event is already marked with 'T', the "Red" button opens the "Edit
  timer" menu for that timer.
- Removing deleted recordings is now done in a separate thread.
- Dropped the unused "stop recording on primary interface" stuff.
- Converting a grabbed image to JPEG is now done with the new function
  RgbToJpeg() (see tools.h).
- The SVDRP command GRAB now determines the image type (JPEG or PNM) from the
  extension (".jpg", ".jpeg" or ".pnm") of the given file name. The explicit
  'jpeg' or 'pnm' parameter is still accepted for backward compatibility, but
  has no meaning any more.
- The function cDevice::GrabImage() no longer writes the grabbed image to a
  file, but rather returns a pointer to the image in memory. The wrapper
  function cDevice::GrabImageFile() can be used to write the grabbed image
  directly to a file. Plugins that used the old version of cDevice::GrabImage()
  need to be adapted to the new interface.
- The new class cBase64Encoder (see tools.h) can be used to encode data in
  base64 (thanks to Bob Withers for publishing his Base64 class).
- The SVDRP command GRAB now writes the image data to the SVDRP connection
  (encoded in base64) if the given file name consists of only the file
  extension (".jpg", ".jpeg" or ".pnm"), or if only "-" is given as file
  name (based on a suggestion from Darren Salt).
  A simple way of viewing a grabbed image on a remote host is:

  svdrpsend.pl -d <hostname> 'grab -' | sed -n -e 's/^216-//p' -e '1ibegin-base64 644 -' -e '$a====' | uudecode | display -

- The new command line option '-g' must be given if the SVDRP command GRAB
  shall be allowed to write image files to disk. The parameter to this option
  must be the full path name of an existing directory, without any "..", double
  '/' or symlinks. By default, or if "-g- is given, grabbing to files is
  not allowed any more because of potential security risks.
- Modified the way the SVDRP command GRAB writes the grabbed image to a file
  to avoid a security hole (CAN-2005-0071, reported by Javier Fernández-Sanguino
  Peña):
  + The file handle is now opened in a way that it won't follow symbolic links
    (suggested by Darren Salt).
  + The given file name is now canonicalized, so that it won't contain any
    ".." or symlinks (suggested by Darren Salt).
  + Grabbing to files is limited to the directory given in the the command
    line option '-g'. By default grabbing to files is not allowed any more.
- Updated the Greek OSD texts (thanks to Dimitrios Dimitrakos).
- Changed all "illegal" to "invalid" in error messages (there's nothing "illegal"
  in VDR ;-).
- When started as user 'root' VDR now switches to a lesser privileged user id,
  keeping the capability to set the system time (based on a patch from Ludwig
  Nussel). By default the user id 'vdr' is used, which can be changed through
  the new command line option '-u'. Note that for security reasons VDR will no
  longer run as user 'root' (unless you explicitly start it with '-u root',
  but this is not recommended!). The 'runvdr' script has been changed to
  use the '-u' option.
- Changed the API of the functions cStatus::Recording() and cStatus::Replaying(),
  so that they can provide the full file name of the recording. Plugins that use
  these (or the related cStatus::Msg...() functions) need to be adapted
  (suggested by Andreas Brugger).
- The DVB devices now retune (and, if applicable, resend the DiSEqC data) if
  the lock is lost (based on a patch from Reinhard Nissl).
- Fixed handling multi byte key sequences in cKbdRemote (based on a patch from
  Jürgen Schneider).
- Removed unused variables in skinclassic.c and skinsttng.c (thanks to Marco
  Schlüßler).
- Made the static cControl functions thread safe (thanks to Patrick Fischer).
- Fixed initializing pthread_mutexattr_t and pthread_rwlockattr_t to avoid
  warnings with g++ 4.1.0 (thanks to Ville Skyttä).
- Fixed incrementing the 'state' variables in the repacker classes in remux.c
  to avoid warnings with g++ 4.1.0 (reported by Ville Skyttä).
- The Makefile now reports a summary of failed plugins (thanks to Udo Richter).
- The cTimer constructor can now take an optional cChannel (suggested by
  Patrick Fischer).
- Fixed setting the main thread id if VDR is running as a daemon.
- Fixed handling TS packets in cTS2PES (thanks to Reinhard Nissl).
- Added cTimer::SetPriority() to set a timer's priority (suggested by Kendy Kutzner).
- Added cMenuEditStrItem::InEditMode() (suggested by Christian Wieninger).
- Now using FE_READ_STATUS to read the current frontend status (suggested by
  Holger Wächtler).
- The "Menu" key now behaves consistently. If there is anything on the OSD, it
  is closed when the "Menu" key is pressed, and if there is nothing on the OSD,
  the "Menu" key opens the main menu (suggested by Luca Olivetti).
- The new option "Setup/OSD/Timeout requested channel info" can be used to turn
  off the automatic timeout of the channel display in case it was invoked by
  a press of the "Ok" key (suggested by Thiemo Gehrke).
- A message is now given when an instant recording is started (suggested by
  Helmut Auer). Actually the code was already there, just commented out - don't
  remember why it wasn't active...
- Removed an obsolete "Summary" text from i18n.c and preceded all key definition
  texts with "Key$" to avoid duplicates (reported by Lucian Muresan).
- Preceded all button texts with "Button$".
- Removed obsolete "Eject", "Language" and "scanning recordings..." texts.
- Added missing #include "thread.h" to dvbspu.c (reported by Gavin Hamill).
- Disabled the use of "fadvise" in cUnbufferedFile because there have been
  several reports that it causes more problems than it solves (suggested by
  Petri Hintukainen). If you want to use "fadvise", you can activate the line
  //#define USE_FADVISE
  in tools.c.
- Removed unused 'offset' member from cOsdItem.
- In the "Channels" menu the numeric keys now position the cursor to the channel
  with the given number (see MANUAL, section "Remote Control Keys", note (3) for
  details).
- The "Mark/Move" function in the "Channels" menu now also works in the non-numeric
  sort modes.
- The default cOsdObject::Show() now automatically calls cOsdMenu::Display() if
  this is a menu.
- The new "Info" key brings up information on the currently viewed programme
  or recording. For a live programme this is the same as "Schedule/Ok", i.e. the
  description of the current EPG event. For a recording this is the same as shown
  by the "Info" button in the "Recordings" menu. Plugins that implement players
  can overwrite their cControl::GetInfo() function to show their own info (see
  PLUGINS.html for details). Pressing the "Info" key again while the info is
  displayed will close the OSD. In order to assign this new key to an existing
  remote control setup, the remote.conf file needs to be deleted and VDR has
  to be restarted to go through the process of learning the remote control keys.
- Any cReceivers still attached to a cDevice when that device switches to a
  different transponder are now automatically detached (suggested by Patrick
  Fischer).
- The "flags" of a timer are now handled as an unsigned integer value. In order
  to do this, the interface of cMenuEditBitItem also had to be changed.
- In string entry fields (like, e.g., the file name of a recording) the characters
  can now be entered by pressing the numeric keys, the same way as on a
  telephone keypad (based on the "Easy Input" patch from Marcel Schaeben).
- Fixed the "Day" field of the "Edit timer" menu when pressing '0' to switch
  from "single shot" to "weekly", followed by the "Right" key (reported by
  Andreas Böttger).
- The file 'ca.conf' is obsolete and has been removed.
- Revised all descriptions regarding CICAM.
- Adapted c(Dvb)Device::ProvidesCa() to the dynamic CA handling.
- Added a mutex to synchronize cDevice::PlayPesPacket() and SetCurrentAudioTrack()
  (thanks to Reinhard Nissl).
- Added a SleepMs() in cRecorder::Action() to avoid a busy loop (thanks to Ingo
  Schneider).
- Cleaned up some trailing white space.
2006-01-08 18:00:00 +01:00

552 lines
26 KiB
C++

/*
* device.h: The basic device interface
*
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: device.h 1.70 2006/01/08 10:10:26 kls Exp $
*/
#ifndef __DEVICE_H
#define __DEVICE_H
#include "channels.h"
#include "ci.h"
#include "eit.h"
#include "filter.h"
#include "nit.h"
#include "pat.h"
#include "ringbuffer.h"
#include "sdt.h"
#include "sections.h"
#include "spu.h"
#include "thread.h"
#include "tools.h"
#define MAXDEVICES 16 // the maximum number of devices in the system
#define MAXPIDHANDLES 64 // the maximum number of different PIDs per device
#define MAXRECEIVERS 16 // the maximum number of receivers per device
#define MAXVOLUME 255
#define VOLUMEDELTA 5 // used to increase/decrease the volume
#define TS_SIZE 188
#define TS_SYNC_BYTE 0x47
#define PID_MASK_HI 0x1F
enum eSetChannelResult { scrOk, scrNotAvailable, scrNoTransfer, scrFailed };
enum ePlayMode { pmNone, // audio/video from decoder
pmAudioVideo, // audio/video from player
pmAudioOnly, // audio only from player, video from decoder
pmAudioOnlyBlack, // audio only from player, no video (black screen)
pmVideoOnly, // video only from player, audio from decoder
pmExtern_THIS_SHOULD_BE_AVOIDED
// external player (e.g. MPlayer), release the device
// WARNING: USE THIS MODE ONLY AS A LAST RESORT, IF YOU
// ABSOLUTELY, POSITIVELY CAN'T IMPLEMENT YOUR PLAYER
// THE WAY IT IS SUPPOSED TO WORK. FORCING THE DEVICE
// TO RELEASE ITS FILES HANDLES (OR WHATEVER RESOURCES
// IT MAY USE) TO ALLOW AN EXTERNAL PLAYER TO ACCESS
// THEM MEANS THAT SUCH A PLAYER WILL NEED TO HAVE
// DETAILED KNOWLEDGE ABOUT THE INTERNALS OF THE DEVICE
// IN USE. AS A CONSEQUENCE, YOUR PLAYER MAY NOT WORK
// IF A PARTICULAR VDR INSTALLATION USES A DEVICE NOT
// KNOWN TO YOUR PLAYER.
};
enum eVideoSystem { vsPAL,
vsNTSC
};
enum eVideoDisplayFormat { vdfPanAndScan,
vdfLetterBox,
vdfCenterCutOut
};
enum eTrackType { ttNone,
ttAudio,
ttAudioFirst = ttAudio,
ttAudioLast = ttAudioFirst + 31, // MAXAPIDS - 1
ttDolby,
ttDolbyFirst = ttDolby,
ttDolbyLast = ttDolbyFirst + 15, // MAXDPIDS - 1
/* future...
ttSubtitle,
ttSubtitleFirst = ttSubtitle,
ttSubtitleLast = ttSubtitleFirst + 7, // MAXSPIDS - 1
*/
ttMaxTrackTypes
};
#define IS_AUDIO_TRACK(t) (ttAudioFirst <= (t) && (t) <= ttAudioLast)
#define IS_DOLBY_TRACK(t) (ttDolbyFirst <= (t) && (t) <= ttDolbyLast)
struct tTrackId {
uint16_t id; // The PES packet id or the PID.
char language[MAXLANGCODE2]; // something like either "eng" or "deu+eng"
char description[32]; // something like "Dolby Digital 5.1"
};
class cPlayer;
class cReceiver;
class cPesAssembler;
/// The cDevice class is the base from which actual devices can be derived.
class cDevice : public cThread {
private:
static int numDevices;
static int useDevice;
static cDevice *device[MAXDEVICES];
static cDevice *primaryDevice;
public:
static int NumDevices(void) { return numDevices; }
///< Returns the total number of devices.
static bool WaitForAllDevicesReady(int Timeout = 0);
///< Waits until all devices have become ready, or the given Timeout
///< (seconds) has expired. While waiting, the Ready() function of each
///< device is called in turn, until they all return true.
///< \return True if all devices have become ready within the given
///< timeout.
static void SetUseDevice(int n);
///< Sets the 'useDevice' flag of the given device.
///< If this function is not called before initializing, all devices
///< will be used.
static bool UseDevice(int n) { return useDevice == 0 || (useDevice & (1 << n)) != 0; }
///< Tells whether the device with the given card index shall be used in
///< this instance of VDR.
static bool SetPrimaryDevice(int n);
///< Sets the primary device to 'n'.
///< \param n must be in the range 1...numDevices.
///< \return true if this was possible.
static cDevice *PrimaryDevice(void) { return primaryDevice; }
///< Returns the primary device.
static cDevice *ActualDevice(void);
///< Returns the actual receiving device in case of Transfer Mode, or the
///< primary device otherwise.
static cDevice *GetDevice(int Index);
///< Gets the device with the given Index.
///< \param Index must be in the range 0..numDevices-1.
///< \return A pointer to the device, or NULL if the Index was invalid.
static cDevice *GetDevice(const cChannel *Channel, int Priority = -1, bool *NeedsDetachReceivers = NULL);
///< Returns a device that is able to receive the given Channel at the
///< given Priority.
///< See ProvidesChannel() for more information on how
///< priorities are handled, and the meaning of NeedsDetachReceivers.
static void Shutdown(void);
///< Closes down all devices.
///< Must be called at the end of the program.
private:
static int nextCardIndex;
int cardIndex;
protected:
cDevice(void);
virtual ~cDevice();
virtual bool Ready(void);
///< Returns true if this device is ready. Devices with conditional
///< access hardware may need some time until they are up and running.
///< This function is called in a loop at startup until all devices
///< are ready (see WaitForAllDevicesReady()).
static int NextCardIndex(int n = 0);
///< Calculates the next card index.
///< Each device in a given machine must have a unique card index, which
///< will be used to identify the device for assigning Ca parameters and
///< deciding whether to actually use that device in this particular
///< instance of VDR. Every time a new cDevice is created, it will be
///< given the current nextCardIndex, and then nextCardIndex will be
///< automatically incremented by 1. A derived class can determine whether
///< a given device shall be used by checking UseDevice(NextCardIndex()).
///< If a device is skipped, or if there are possible device indexes left
///< after a derived class has set up all its devices, NextCardIndex(n)
///< must be called, where n is the number of card indexes to skip.
virtual void MakePrimaryDevice(bool On);
///< Informs a device that it will be the primary device. If there is
///< anything the device needs to set up when it becomes the primary
///< device (On = true) or to shut down when it no longer is the primary
///< device (On = false), it should do so in this function.
public:
bool IsPrimaryDevice(void) const { return this == primaryDevice; }
int CardIndex(void) const { return cardIndex; }
///< Returns the card index of this device (0 ... MAXDEVICES - 1).
int DeviceNumber(void) const;
///< Returns the number of this device (0 ... MAXDEVICES - 1).
virtual int ProvidesCa(const cChannel *Channel) const;
///< Checks whether this device provides the conditional access
///< facilities to decrypt the given Channel.
///< Returns 0 if the Channel can't be decrypted, 1 if this is a
///< Free To Air channel or only exactly this device can decrypt it,
///< and > 1 if this device can decrypt the Channel.
///< If the result is greater than 1 and the device has more than one
///< CAM, the value will be increased by the number of CAMs, which
///< allows to select the device with the smallest number of CAMs
///< in order to preserve resources for other recordings.
virtual bool HasDecoder(void) const;
///< Tells whether this device has an MPEG decoder.
// SPU facilities
public:
virtual cSpuDecoder *GetSpuDecoder(void);
///< Returns a pointer to the device's SPU decoder (or NULL, if this
///< device doesn't have an SPU decoder).
// Channel facilities
protected:
static int currentChannel;
public:
virtual bool ProvidesSource(int Source) const;
///< Returns true if this device can provide the given source.
virtual bool ProvidesTransponder(const cChannel *Channel) const;
///< XXX -> PLUGINS.html!
virtual bool ProvidesTransponderExclusively(const cChannel *Channel) const;
///< Returns true if this is the only device that is able to provide
///< the given channel's transponder.
virtual bool ProvidesChannel(const cChannel *Channel, int Priority = -1, bool *NeedsDetachReceivers = NULL) const;
///< Returns true if this device can provide the given channel.
///< In case the device has cReceivers attached to it or it is the primary
///< device, Priority is used to decide whether the caller's request can
///< be honored.
///< The special Priority value -1 will tell the caller whether this device
///< is principally able to provide the given Channel, regardless of any
///< attached cReceivers.
///< If NeedsDetachReceivers is given, the resulting value in it will tell the
///< caller whether or not it will have to detach any currently attached
///< receivers from this device before calling SwitchChannel. Note
///< that the return value in NeedsDetachReceivers is only meaningful if the
///< function itself actually returns true.
///< The default implementation always returns false, so a derived cDevice
///< class that can provide channels must implement this function.
virtual bool MaySwitchTransponder(void);
///< Returns true if it is ok to switch the transponder on this device,
///< without disturbing any other activities.
bool SwitchChannel(const cChannel *Channel, bool LiveView);
///< Switches the device to the given Channel, initiating transfer mode
///< if necessary.
static bool SwitchChannel(int Direction);
///< Switches the primary device to the next available channel in the given
///< Direction (only the sign of Direction is evaluated, positive values
///< switch to higher channel numbers).
private:
eSetChannelResult SetChannel(const cChannel *Channel, bool LiveView);
///< Sets the device to the given channel (general setup).
protected:
virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView);
///< Sets the device to the given channel (actual physical setup).
public:
static int CurrentChannel(void) { return primaryDevice ? currentChannel : 0; }
///< Returns the number of the current channel on the primary device.
virtual bool HasLock(int TimeoutMs = 0);//XXX PLUGINS.html
///< Returns true if the device has a lock on the requested transponder.
///< Default is true, a specific device implementation may return false
///< to indicate that it is not ready yet.
///< If TimeoutMs is not zero, waits for the given number of milliseconds
///< before returning false.
virtual bool HasProgramme(void);
///< Returns true if the device is currently showing any programme to
///< the user, either through replaying or live.
// PID handle facilities
private:
virtual void Action(void);
protected:
enum ePidType { ptAudio, ptVideo, ptPcr, ptTeletext, ptDolby, ptOther };
class cPidHandle {
public:
int pid;
int handle;
int used;
cPidHandle(void) { pid = used = 0; handle = -1; }
};
cPidHandle pidHandles[MAXPIDHANDLES];
bool HasPid(int Pid) const;
///< Returns true if this device is currently receiving the given PID.
bool AddPid(int Pid, ePidType PidType = ptOther);
///< Adds a PID to the set of PIDs this device shall receive.
void DelPid(int Pid, ePidType PidType = ptOther);
///< Deletes a PID from the set of PIDs this device shall receive.
virtual bool SetPid(cPidHandle *Handle, int Type, bool On);
///< Does the actual PID setting on this device.
///< On indicates whether the PID shall be added or deleted.
///< Handle->handle can be used by the device to store information it
///< needs to receive this PID (for instance a file handle).
///< Handle->used indicates how many receivers are using this PID.
///< Type indicates some special types of PIDs, which the device may
///< need to set in a specific way.
// Section filter facilities
private:
cSectionHandler *sectionHandler;
cEitFilter *eitFilter;
cPatFilter *patFilter;
cSdtFilter *sdtFilter;
cNitFilter *nitFilter;
protected:
void StartSectionHandler(void);
///< A derived device that provides section data must call
///< this function to actually set up the section handler.
public:
virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask);
///< Opens a file handle for the given filter data.
///< A derived device that provides section data must
///< implement this function.
void AttachFilter(cFilter *Filter);
///< Attaches the given filter to this device.
void Detach(cFilter *Filter);
///< Detaches the given filter from this device.
// Common Interface facilities:
protected:
cCiHandler *ciHandler;
public:
cCiHandler *CiHandler(void) { return ciHandler; }
// Image Grab facilities
public:
virtual uchar *GrabImage(int &Size, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
///< Grabs the currently visible screen image.
///< \param Size The size of the returned data block.
///< \param Jpeg If true will write a JPEG file. Otherwise a PNM file will be written.
///< \param Quality The compression factor for JPEG. 1 will create a very blocky
///< and small image, 70..80 will yield reasonable quality images while keeping the
///< image file size around 50 KB for a full frame. The default will create a big
///< but very high quality image.
///< \param SizeX The number of horizontal pixels in the frame (default is the current screen width).
///< \param SizeY The number of vertical pixels in the frame (default is the current screen height).
///< \return A pointer to the grabbed image data, or NULL in case of an error.
///< The caller takes ownership of the returned memory and must free() it once it isn't needed any more.
bool GrabImageFile(const char *FileName, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
///< Calls GrabImage() and stores the resulting image in a file with the given name.
///< \return True if all went well.
///< The caller is responsible for making sure that the given file name
///< doesn't lead to overwriting any important other file.
// Video format facilities
public:
virtual void SetVideoDisplayFormat(eVideoDisplayFormat VideoDisplayFormat);
///< Sets the video display format to the given one (only useful
///< if this device has an MPEG decoder).
///< A derived class must first call the base class function!
virtual void SetVideoFormat(bool VideoFormat16_9);
///< Sets the output video format to either 16:9 or 4:3 (only useful
///< if this device has an MPEG decoder).
virtual eVideoSystem GetVideoSystem(void);
///< Returns the video system of the currently displayed material
///< (default is PAL).
// Track facilities
private:
tTrackId availableTracks[ttMaxTrackTypes];
eTrackType currentAudioTrack;
cMutex mutexCurrentAudioTrack;
int currentAudioTrackMissingCount;
bool pre_1_3_19_PrivateStream;
protected:
virtual void SetAudioTrackDevice(eTrackType Type);
///< Sets the current audio track to the given value.
public:
void ClrAvailableTracks(bool DescriptionsOnly = false);
bool SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const char *Language = NULL, const char *Description = NULL);
///< Sets the track of the given Type and Index to the given values.
///< Type must be one of the basic eTrackType values, like ttAudio or ttDolby.
///< Index tells which track of the given basic type is meant.
///< If Id is 0 any existing id will be left untouched and only the
///< given Language and Description will be set.
///< \return Returns true if the track was set correctly, false otherwise.
const tTrackId *GetTrack(eTrackType Type);
///< Returns a pointer to the given track id, or NULL if Type is not
///< less than ttMaxTrackTypes.
int NumAudioTracks(void) const;
///< Returns the number of audio tracks that are currently available.
///< This is just for information, to quickly find out whether there
///< is more than one audio track.
eTrackType GetCurrentAudioTrack(void) { return currentAudioTrack; }
bool SetCurrentAudioTrack(eTrackType Type);
///< Sets the current audio track to the given Type.
///< \return Returns true if Type is a valid audio track, false otherwise.
void EnsureAudioTrack(bool Force = false);
///< Makes sure an audio track is selected that is actually available.
///< If Force is true, the language and Dolby Digital settings will
///< be verified even if the current audio track is available.
// Audio facilities
private:
bool mute;
int volume;
protected:
virtual int GetAudioChannelDevice(void);
///< Gets the current audio channel, which is stereo (0), mono left (1) or
///< mono right (2).
virtual void SetAudioChannelDevice(int AudioChannel);
///< Sets the audio channel to stereo (0), mono left (1) or mono right (2).
virtual void SetVolumeDevice(int Volume);
///< Sets the audio volume on this device (Volume = 0...255).
virtual void SetDigitalAudioDevice(bool On);
///< Tells the actual device that digital audio output shall be switched
///< on or off.
public:
bool IsMute(void) const { return mute; }
bool ToggleMute(void);
///< Turns the volume off or on and returns the new mute state.
int GetAudioChannel(void);
///< Gets the current audio channel, which is stereo (0), mono left (1) or
///< mono right (2).
void SetAudioChannel(int AudioChannel);
///< Sets the audio channel to stereo (0), mono left (1) or mono right (2).
///< Any other values will be silently ignored.
void SetVolume(int Volume, bool Absolute = false);
///< Sets the volume to the given value, either absolutely or relative to
///< the current volume.
static int CurrentVolume(void) { return primaryDevice ? primaryDevice->volume : 0; }//XXX???
// Player facilities
private:
cPlayer *player;
cPesAssembler *pesAssembler;
protected:
virtual bool CanReplay(void) const;
///< Returns true if this device can currently start a replay session.
virtual bool SetPlayMode(ePlayMode PlayMode);
///< Sets the device into the given play mode.
///< \return true if the operation was successful.
virtual int PlayVideo(const uchar *Data, int Length);
///< Plays the given data block as video.
///< Data points to exactly one complete PES packet of the given Length.
///< PlayVideo() shall process the packet either as a whole (returning
///< Length) or not at all (returning 0 or -1 and setting 'errno' to EAGAIN).
///< \return Returns the number of bytes actually taken from Data, or -1
///< in case of an error.
virtual int PlayAudio(const uchar *Data, int Length);
///< Plays the given data block as audio.
///< Data points to exactly one complete PES packet of the given Length.
///< PlayAudio() shall process the packet either as a whole (returning
///< Length) or not at all (returning 0 or -1 and setting 'errno' to EAGAIN).
///< \return Returns the number of bytes actually taken from Data, or -1
///< in case of an error.
virtual int PlayPesPacket(const uchar *Data, int Length, bool VideoOnly = false);
///< Plays the single PES packet in Data with the given Length.
///< If VideoOnly is true, only the video will be displayed,
///< which is necessary for trick modes like 'fast forward'.
///< Data must point to one single, complete PES packet.
public:
virtual int64_t GetSTC(void);
///< Gets the current System Time Counter, which can be used to
///< synchronize audio and video. If this device is unable to
///< provide the STC, -1 will be returned.
virtual void TrickSpeed(int Speed);
///< Sets the device into a mode where replay is done slower.
///< Every single frame shall then be displayed the given number of
///< times.
virtual void Clear(void);
///< Clears all video and audio data from the device.
///< A derived class must call the base class function to make sure
///< all registered cAudio objects are notified.
virtual void Play(void);
///< Sets the device into play mode (after a previous trick
///< mode).
virtual void Freeze(void);
///< Puts the device into "freeze frame" mode.
virtual void Mute(void);
///< Turns off audio while replaying.
///< A derived class must call the base class function to make sure
///< all registered cAudio objects are notified.
virtual void StillPicture(const uchar *Data, int Length);
///< Displays the given I-frame as a still picture.
virtual bool Poll(cPoller &Poller, int TimeoutMs = 0);
///< Returns true if the device itself or any of the file handles in
///< Poller is ready for further action.
///< If TimeoutMs is not zero, the device will wait up to the given number
///< of milleseconds before returning in case it can't accept any data.
virtual bool Flush(int TimeoutMs = 0);
///< Returns true if the device's output buffers are empty, i. e. any
///< data which was bufferd so far has been processed.
///< If TimeoutMs is not zero, the device will wait up to the given
///< number of milliseconds before returning in case there is still
///< data in the buffers..
virtual int PlayPes(const uchar *Data, int Length, bool VideoOnly = false);
///< Plays all valid PES packets in Data with the given Length.
///< If Data is NULL any leftover data from a previous call will be
///< discarded. If VideoOnly is true, only the video will be displayed,
///< which is necessary for trick modes like 'fast forward'.
///< Data should point to a sequence of complete PES packets. If the
///< last packet in Data is not complete, it will be copied and combined
///< to a complete packet with data from the next call to PlayPes().
///< That way any functions called from within PlayPes() will be
///< guaranteed to always receive complete PES packets.
bool Replaying(void) const;
///< Returns true if we are currently replaying.
void StopReplay(void);
///< Stops the current replay session (if any).
bool AttachPlayer(cPlayer *Player);
///< Attaches the given player to this device.
void Detach(cPlayer *Player);
///< Detaches the given player from this device.
// Receiver facilities
private:
cMutex mutexReceiver;
cReceiver *receiver[MAXRECEIVERS];
protected:
int Priority(void) const;
///< Returns the priority of the current receiving session (0..MAXPRIORITY),
///< or -1 if no receiver is currently active. The primary device will
///< always return at least Setup.PrimaryLimit-1.
virtual bool OpenDvr(void);
///< Opens the DVR of this device and prepares it to deliver a Transport
///< Stream for use in a cReceiver.
virtual void CloseDvr(void);
///< Shuts down the DVR.
virtual bool GetTSPacket(uchar *&Data);
///< Gets exactly one TS packet from the DVR of this device and returns
///< a pointer to it in Data. Only the first 188 bytes (TS_SIZE) Data
///< points to are valid and may be accessed. If there is currently no
///< new data available, Data will be set to NULL. The function returns
///< false in case of a non recoverable error, otherwise it returns true,
///< even if Data is NULL.
public:
int Ca(void) const;
///< Returns the ca of the current receiving session(s).
bool Receiving(bool CheckAny = false) const;
///< Returns true if we are currently receiving.
bool AttachReceiver(cReceiver *Receiver);
///< Attaches the given receiver to this device.
void Detach(cReceiver *Receiver);
///< Detaches the given receiver from this device.
void DetachAll(int Pid);
///< Detaches all receivers from this device for this pid.
void DetachAllReceivers(void);
///< Detaches all receivers from this device.
};
/// Derived cDevice classes that can receive channels will have to provide
/// Transport Stream (TS) packets one at a time. cTSBuffer implements a
/// simple buffer that allows the device to read a larger amount of data
/// from the driver with each call to Read(), thus avoiding the overhead
/// of getting each TS packet separately from the driver. It also makes
/// sure the returned data points to a TS packet and automatically
/// re-synchronizes after broken packets.
class cTSBuffer : public cThread {
private:
int f;
int cardIndex;
bool delivered;
cRingBufferLinear *ringBuffer;
virtual void Action(void);
public:
cTSBuffer(int File, int Size, int CardIndex);
~cTSBuffer();
uchar *Get(void);
};
#endif //__DEVICE_H