~ubuntu-branches/ubuntu/quantal/mythtv/quantal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* -*- Mode: c++ -*-
 *  DTVChannel
 *  Copyright (c) 2005,2006 by Daniel Kristjansson
 *  Contains base class for digital channels.
 */

#ifndef _DTVCHANNEL_H_
#define _DTVCHANNEL_H_

// POSIX headers
#include <stdint.h>

// C++ headers
#include <vector>
using namespace std;

// Qt headers
#include <QReadWriteLock>
#include <QString>
#include <QMutex>

// MythTV headers
#include "dtvconfparserhelpers.h" // for DTVTunerType
#include "channelbase.h"
#include "channelutil.h" // for pid_cache_t

class ProgramAssociationTable;
class ProgramMapTable;
class TVRec;

/** \class DTVChannel
 *  \brief Class providing a generic interface to digital tuning hardware.
 */
class DTVChannel : public ChannelBase
{
  public:
    DTVChannel(TVRec *parent);
    virtual ~DTVChannel();

    // Commands
    virtual bool SetChannelByString(const QString &chan);

    /// \brief To be used by the channel scanner and possibly the EIT scanner.
    virtual bool TuneMultiplex(uint mplexid, QString inputname);
    /// \brief This performs the actual frequency tuning and in some cases
    ///        input switching.
    ///
    /// In rare cases such as ASI this does nothing since all the channels
    /// are in the same MPTS stream on the same input. But generally you
    /// will need to implement this when adding support for new hardware.
    virtual bool Tune(const DTVMultiplex &tuning, QString inputname) = 0;
    /// \brief Enters power saving mode if the card supports it
    virtual bool EnterPowerSavingMode(void)
    {
        return true;
    }
    /// \brief This tunes on the frequency Identification parameter for
    ///        hardware that supports it.
    ///
    /// This is only called when there is no frequency set. This is used
    /// to implement "Channel Numbers" in analog tuning scenarios and to
    /// implement "Virtual Channels" in the OCUR and Firewire tuners.
    virtual bool Tune(const QString &freqid, int finetune)
    {
        (void) freqid; (void) finetune;
        return false;
    }

    virtual bool Tune(uint64_t frequency, QString inputname)
    {
        (void) frequency; (void) inputname;
        return false;
    }

    // Gets

    /// \brief Returns program number in PAT, -1 if unknown.
    int GetProgramNumber(void) const
        { return currentProgramNum; };

    /// \brief Returns major channel, 0 if unknown.
    uint GetMajorChannel(void) const
        { return currentATSCMajorChannel; };

    /// \brief Returns minor channel, 0 if unknown.
    uint GetMinorChannel(void) const
        { return currentATSCMinorChannel; };

    /// \brief Returns DVB original_network_id, 0 if unknown.
    uint GetOriginalNetworkID(void) const
        { return currentOriginalNetworkID; };

    /// \brief Returns DVB transport_stream_id, 0 if unknown.
    uint GetTransportID(void) const
        { return currentTransportID; };

    /// \brief Returns PSIP table standard: MPEG, DVB, ATSC, or OpenCable
    QString GetSIStandard(void) const;

    /// \brief Returns suggested tuning mode: "mpeg", "dvb", or "atsc"
    QString GetSuggestedTuningMode(bool is_live_tv) const;

    /// \brief Returns tuning mode last set by SetTuningMode().
    QString GetTuningMode(void) const;

    /// \brief Returns a vector of supported tuning types.
    virtual vector<DTVTunerType> GetTunerTypes(void) const;

    void GetCachedPids(pid_cache_t &pid_cache) const;

    void RegisterForMaster(const QString &key);
    void DeregisterForMaster(const QString &key);
    static DTVChannel *GetMasterLock(const QString &key);
    typedef DTVChannel* DTVChannelP;
    static void ReturnMasterLock(DTVChannelP&);

    /// \brief Returns true if this is the first of a number of multi-rec devs
    virtual bool IsMaster(void) const { return false; }

    virtual bool IsPIDTuningSupported(void) const { return false; }

    bool HasGeneratedPAT(void) const { return genPAT != NULL; }
    bool HasGeneratedPMT(void) const { return genPMT != NULL; }
    const ProgramAssociationTable *GetGeneratedPAT(void) const {return genPAT;}
    const ProgramMapTable         *GetGeneratedPMT(void) const {return genPMT;}

    // Sets

    /// \brief Sets tuning mode: "mpeg", "dvb", "atsc", etc.
    void SetTuningMode(const QString &tuningmode);

    void SaveCachedPids(const pid_cache_t &pid_cache) const;

  protected:
    /// \brief Sets PSIP table standard: MPEG, DVB, ATSC, or OpenCable
    void SetSIStandard(const QString&);
    void SetDTVInfo(uint atsc_major, uint atsc_minor,
                    uint dvb_orig_netid,
                    uint mpeg_tsid, int mpeg_pnum);
    void ClearDTVInfo(void) { SetDTVInfo(0, 0, 0, 0, -1); }
    /// \brief Checks tuning for problems, and tries to fix them.
    virtual void CheckOptions(DTVMultiplex &tuning) const {}
    virtual void HandleScriptEnd(bool ok);

  protected:
    mutable QMutex dtvinfo_lock;

    DTVTunerType tunerType;
    QString sistandard; ///< PSIP table standard: MPEG, DVB, ATSC, OpenCable
    QString tuningMode;
    int     currentProgramNum;
    uint    currentATSCMajorChannel;
    uint    currentATSCMinorChannel;
    uint    currentTransportID;
    uint    currentOriginalNetworkID;

    /// This is a generated PAT for RAW pid tuning
    ProgramAssociationTable *genPAT;
    /// This is a generated PMT for RAW pid tuning
    ProgramMapTable         *genPMT;

    typedef QMap<QString,QList<DTVChannel*> > MasterMap;
    static QReadWriteLock    master_map_lock;
    static MasterMap         master_map;
};

#endif // _DTVCHANNEL_H_