Ticket #361: mpegscan.diff

File mpegscan.diff, 16.6 KB (added by Paul Milazzo <pgm0203@…>, 21 years ago)

Oops; forgot to attach the patch file.

  • libs/libmythtv/channelutil.cpp

     
    442442    return query.value(0).toInt();
    443443}
    444444
    445 QString ChannelUtil::GetChanNum(int chan_id)
     445QString ChannelUtil::GetChannelStringField(int chan_id, const QString &field)
    446446{
    447447    if (chan_id < 0)
    448448        return QString::null;
    449449
    450450    MSqlQuery query(MSqlQuery::InitCon());
    451     query.prepare(QString("SELECT channum FROM channel "
    452                           "WHERE chanid=%1").arg(chan_id));
     451    query.prepare(QString("SELECT %1 FROM channel "
     452            "WHERE chanid=%2").arg(field).arg(chan_id));
    453453    if (!query.exec() || !query.isActive())
    454454    {
    455455        MythContext::DBError("Selecting channel/dtv_multiplex 1", query);
     
    462462    return query.value(0).toString();
    463463}
    464464
     465QString ChannelUtil::GetChanNum(int chan_id)
     466{
     467    return GetChannelStringField(chan_id, QString("channum"));
     468}
     469
     470QString ChannelUtil::GetCallsign(int chan_id)
     471{
     472    return GetChannelStringField(chan_id, QString("callsign"));
     473}
     474
     475QString ChannelUtil::GetServiceName(int chan_id)
     476{
     477    return GetChannelStringField(chan_id, QString("name"));
     478}
     479
    465480int ChannelUtil::GetSourceID(int db_mplexid)
    466481{
    467482    MSqlQuery query(MSqlQuery::InitCon());
     
    666681    query.bindValue(":CHANID",    new_channel_id);
    667682    query.bindValue(":CHANNUM",   chan_num);
    668683    query.bindValue(":SOURCEID",  db_sourceid);
    669     query.bindValue(":CALLSIGN",  callsign);
    670     query.bindValue(":NAME",      service_name);
     684    query.bindValue(":CALLSIGN",  callsign.utf8());
     685    query.bindValue(":NAME",      service_name.utf8());
    671686    query.bindValue(":XMLTVID",   xmltvid);
    672687    query.bindValue(":FREQID",    freqid);
    673688    query.bindValue(":TVFORMAT",  tvformat);
     
    684699bool ChannelUtil::CreateChannel(uint db_mplexid,
    685700                                uint db_sourceid,
    686701                                uint new_channel_id,
     702                                const QString &callsign,
    687703                                const QString &service_name,
    688704                                const QString &chan_num,
    689705                                uint service_id,
     
    714730    query.bindValue(":CHANID",    new_channel_id);
    715731    query.bindValue(":CHANNUM",   chanNum);
    716732    query.bindValue(":SOURCEID",  db_sourceid);
    717     query.bindValue(":CALLSIGN",  service_name.utf8());
     733    query.bindValue(":CALLSIGN",  callsign.utf8());
    718734    query.bindValue(":NAME",      service_name.utf8());
    719735
    720736    query.bindValue(":MPLEXID",   db_mplexid);
     
    739755bool ChannelUtil::UpdateChannel(uint db_mplexid,
    740756                                uint source_id,
    741757                                uint channel_id,
     758                                const QString &callsign,
    742759                                const QString &service_name,
    743760                                const QString &chan_num,
    744761                                uint service_id,
     
    761778    query.bindValue(":MPLEXID",   db_mplexid);
    762779    query.bindValue(":SERVICEID", service_id);
    763780    query.bindValue(":ATSCSRCID", atsc_src_id);
    764     query.bindValue(":CALLSIGN",  service_name.utf8());
     781    query.bindValue(":CALLSIGN",  callsign.utf8());
    765782    query.bindValue(":NAME",      service_name.utf8());
    766783    query.bindValue(":SOURCEID",  source_id);
    767784    query.bindValue(":CHANID",    channel_id);
  • libs/libmythtv/mpeg/mpegstreamdata.cpp

     
    593593    _cache_lock.lock();
    594594    DeleteCachedTable(_cached_pat);
    595595    _cached_pat = pat;
     596    for (uint i = 0; i < pat->ProgramCount(); i++)
     597        AddListeningPID(pat->ProgramPID(i));
    596598    _cache_lock.unlock();
    597599}
    598600
  • libs/libmythtv/mpeg/atscdescriptors.cpp

     
    225225    return QString("TODO huffman 2");
    226226}
    227227
     228ExtendedChannelNameDescriptor::ExtendedChannelNameDescriptor(
     229        const unsigned char *data) :
     230    MPEGDescriptor(data)
     231{
     232    assert(DescriptorTag() == DescriptorID::extended_channel_name);
     233}
     234
     235MultipleStringStructure ExtendedChannelNameDescriptor::LongChannelName() const
     236{
     237    return MultipleStringStructure(_data + 2);
     238}
     239
     240QString ExtendedChannelNameDescriptor::LongChannelNameString() const
     241{
     242    QString str;
     243    MultipleStringStructure mstr = LongChannelName();
     244
     245    for (int i = 0; i < mstr.StringCount(); i++)
     246    {
     247        for (uint j = 0; j < mstr.SegmentCount(i); j++)
     248            str.append(mstr.CompressedString(i,j));
     249    }
     250   
     251    return str;
     252}
  • libs/libmythtv/mpeg/atscdescriptors.h

     
    285285    //   content_identifier                  v   4.0
    286286};
    287287
     288/**
     289 * \brief Provides the long channel name for the virtual channel containing
     290 *  this descriptor.
     291 *
     292 * See ATSC A/65B section 6.9.5.
     293 * When used, this descriptor must be in the Virtual Channel Table.
     294 */
     295class ExtendedChannelNameDescriptor : public MPEGDescriptor
     296{
     297public:
     298    /**
     299     * \brief Creates a new ExtendedChannelNameDescriptor.
     300     *
     301     * \param data the raw data representing this descriptor
     302     */
     303    ExtendedChannelNameDescriptor(const unsigned char *data);
     304
     305    /**
     306     * \brief Returns a MultipleStringStructure representing the
     307     *  long name of the associated channel.
     308     */
     309    MultipleStringStructure LongChannelName() const;
     310
     311    /**
     312     * \brief Convenience function that returns a QString comprising a
     313     *  concatenation of all the segments in the LongChannelName() value.
     314     */
     315    QString LongChannelNameString() const;
     316};
     317
    288318#endif
  • libs/libmythtv/mpeg/mpegtables.cpp

     
    157157#endif
    158158}
    159159
     160bool ProgramMapTable::IsStillPicture(void) const
     161{
     162    static const unsigned char STILL_PICTURE_FLAG = 0x01;
     163   
     164    for (uint i = 0; i < StreamCount(); i++)
     165    {
     166        if (IsVideo(i))
     167            return StreamInfoLength(i) > 2 &&
     168                   (StreamInfo(i)[2] & STILL_PICTURE_FLAG);
     169    }
     170    return false;
     171}
     172
     173
    160174/** \fn ProgramMapTable::FindPIDs(uint type, vector<uint>& pids) const
    161175 *  \brief Finds all pids matching type.
    162176 *  \param pids vector pids will be added to
  • libs/libmythtv/mpeg/mpegtables.h

     
    440440    bool IsAudio(uint i) const;
    441441    /// Returns true iff PMT contains CA descriptor.
    442442    bool IsEncrypted(void) const;
     443    /**
     444     * Returns true iff PMT contains a video stream with the
     445     * still-picture flag.
     446     */
     447    bool IsStillPicture(void) const;
    443448    /// Returns a string representation of type at stream index i
    444449    const QString StreamTypeString(uint i) const;
    445450    uint FindPIDs(uint type, vector<uint>& pids) const;
  • libs/libmythtv/channelutil.h

     
    5555    static bool    CreateChannel(uint db_mplexid,
    5656                                 uint db_sourceid,
    5757                                 uint new_channel_id,
     58                                 const QString &callsign,
    5859                                 const QString &service_name,
    5960                                 const QString &chan_num,
    6061                                 uint service_id,
     
    6768    static bool    UpdateChannel(uint db_mplexid,
    6869                                 uint source_id,
    6970                                 uint channel_id,
     71                                 const QString &callsign,
    7072                                 const QString &service_name,
    7173                                 const QString &chan_num,
    7274                                 uint service_id,
     
    8183    static int     GetServiceVersion(int mplexid);
    8284
    8385    // Misc
     86    /**
     87     * \brief Returns the channel-number string of the given channel.
     88     * \param chanid primary key for channel record
     89     */
    8490    static QString GetChanNum(int chanid);
     91    /**
     92     * \brief Returns the callsign of the given channel.
     93     * \param chanid primary key for channel record
     94     */
     95    static QString GetCallsign(int chanid);
     96    /**
     97     * \brief Returns the service name of the given channel.
     98     * \param chanid primary key for channel record
     99     */
     100    static QString GetServiceName(int chanid);
    85101    static int     GetSourceID(int mplexid);
    86102    static QString GetInputName(int sourceid);
    87103    static QString GetDTVPrivateType(uint networkid, const QString &key,
    88104                                     const QString sitype = "dvb");
     105
     106  private:
     107      static QString GetChannelStringField(int chanid, const QString &field);
    89108};
    90109
    91110#endif // CHANUTIL_H
  • libs/libmythtv/siscan.h

     
    3838class DTVSignalMonitor;
    3939class DVBSignalMonitor;
    4040class ProgramAssociationTable;
     41class ProgramMapTable;
    4142class ServiceDescriptionTable;
    4243class NetworkInformationTable;
    4344class VirtualChannelTable;
     
    5253    TRANSPORT_LIST, ///< Actively scan for channels
    5354} SCANMODE;
    5455
     56/// PMTs by PID
     57typedef QMap<uint, const ProgramMapTable *> QMap_PMTs;
     58
    5559class SIScan : public QObject
    5660{
    5761    Q_OBJECT
     
    126130    void HandleMPEGDBInsertion(const ScanStreamData *sd, bool wait);
    127131    void UpdatePATinDB(int mplexid,
    128132                       const ProgramAssociationTable*,
     133                       const QMap_PMTs &,
    129134                       bool force_update);
    130135
    131136    void HandleATSCDBInsertion(const ScanStreamData *sd, bool wait);
  • libs/libmythtv/siscan.cpp

     
    345345    const ProgramAssociationTable *pat = sd->GetCachedPAT();
    346346    if (pat)
    347347    {
    348         UpdatePATinDB((*current).mplexid, pat, true);
     348        QMap_PMTs pmt_map;
     349        pmt_vec_t pmt_vector = sd->GetCachedPMTs();
     350        for (pmt_vec_t::iterator mi = pmt_vector.begin(); mi != pmt_vector.end(); mi++)
     351            pmt_map[(*mi)->tsheader()->PID()] = *mi;
     352        UpdatePATinDB((*current).mplexid, pat, pmt_map, true);
     353        sd->ReturnCachedTables(pmt_vector);
    349354        sd->ReturnCachedTable(pat);
    350355    }
    351356
     
    936941// ///////////////////// DB STUFF /////////////////////
    937942// ///////////////////// DB STUFF /////////////////////
    938943
    939 /** \fn UpdatePATinDB(int, const ProgramAssociationTable*, bool)
     944/** \fn UpdatePATinDB(int, const ProgramAssociationTable*, const QMap_PMTs &, bool)
    940945 */
    941946void SIScan::UpdatePATinDB(int tid_db,
    942947                           const ProgramAssociationTable *pat,
     948                           const QMap_PMTs &pmt_map,
    943949                           bool)
    944950{
    945951    SISCAN(QString("UpdatePATinDB(): mplex: %1:%2")
     
    959965
    960966    for (uint i = 0; i < pat->ProgramCount(); i++)
    961967    {
     968        const ProgramMapTable *pmt = pmt_map[pat->ProgramPID(i)];
     969        VERBOSE(VB_SIPARSER,
     970                tr("UpdatePATinDB(): Prog %1 PID %2: PMT @ %3")
     971                    .arg(pat->ProgramNumber(i))
     972                    .arg(pat->ProgramPID(i))
     973                    .arg((long long unsigned int)pmt));
     974        //TODO: user preference for still picture?
     975        // For now we just ignore still-picture services such as
     976        // music channels; Myth can't play them properly anyway.
     977        // Eventually we might want to add a preference flag
     978        // to the UI.
     979        if (! pmt || // adding undefined services is rarely a good idea
     980            ignoreEncryptedServices && pmt->IsEncrypted() ||
     981            pmt->IsStillPicture())
     982        {
     983            continue;
     984        }
     985       
    962986        // See if service already in database based on program number
    963987        int chanid = ChannelUtil::GetChanID(
    964988            db_mplexid, -1, 0, 0, pat->ProgramNumber(i));
     
    969993            chan_num = QString("%1#%2")
    970994                .arg((freqid) ? freqid : db_mplexid).arg(i);
    971995        }
     996       
     997        QString callsign = ChannelUtil::GetCallsign(chanid);
     998        if (callsign == QString::null || callsign == "")
     999            callsign = tr("C%1", "Synthesized callsign").arg(chan_num);
    9721000
    973         QString service_name = QString("Unknown %1").arg(chan_num);
     1001        QString service_name = ChannelUtil::GetServiceName(chanid);
     1002        if (service_name == QString::null || service_name == "")
     1003            service_name = callsign;
    9741004
    9751005        QString common_status_info = tr("%1 %2-%3 as %4 on %5 (%6)")
    9761006            .arg(service_name)
     
    9851015            chanid = ChannelUtil::CreateChanID(db_source_id, chan_num);
    9861016            ChannelUtil::CreateChannel(
    9871017                db_mplexid, db_source_id, chanid,
     1018                callsign,
    9881019                service_name,
    9891020                chan_num,
    9901021                pat->ProgramNumber(i),
     
    9991030                db_mplexid,
    10001031                db_source_id,
    10011032                chanid,
     1033                callsign,
    10021034                service_name,
    10031035                chan_num,
    10041036                pat->ProgramNumber(i),
     
    10781110                .arg(vct->MinorChannel(i));
    10791111        }
    10801112
     1113        // try to find an extended channel name
     1114        QString extendedChannelName = vct->ShortChannelName(i); // fallback
     1115        if (vct->DescriptorsLength(i) > 0)
     1116        {
     1117            vector<const unsigned char*> descVec =
     1118                MPEGDescriptor::Parse(vct->Descriptors(i), vct->DescriptorsLength(i));
     1119            for (uint j = 0; j < descVec.size(); j++)
     1120            {
     1121                if (MPEGDescriptor(descVec[j]).DescriptorTag() ==
     1122                    DescriptorID::extended_channel_name)
     1123                {
     1124                    QString longName =
     1125                        ExtendedChannelNameDescriptor(descVec[j]).LongChannelNameString();
     1126                    SISCAN(QString("UpdateVCTinDB(): chan index %1 has long name \"%2\"")
     1127                            .arg(i).arg(longName));
     1128                    if (! longName.isEmpty())
     1129                        extendedChannelName = longName;
     1130                    break;
     1131                }
     1132            }
     1133        }
     1134
    10811135        QString common_status_info = tr("%1 %2-%3 as %4 on %5 (%6)")
    10821136            .arg(vct->ShortChannelName(i))
    10831137            .arg(vct->MajorChannel(i)).arg(vct->MinorChannel(i))
     
    10961150                    db_source_id,
    10971151                    chanid,
    10981152                    vct->ShortChannelName(i),
     1153                    extendedChannelName,
    10991154                    chan_num,
    11001155                    vct->ProgramNumber(i),
    11011156                    vct->MajorChannel(i), vct->MinorChannel(i),
     
    11131168                db_source_id,
    11141169                chanid,
    11151170                vct->ShortChannelName(i),
     1171                extendedChannelName,
    11161172                chan_num,
    11171173                vct->ProgramNumber(i),
    11181174                vct->MajorChannel(i), vct->MinorChannel(i),
     
    12321288                ChannelUtil::CreateChannel(
    12331289                    db_mplexid, db_source_id, chanid,
    12341290                    service_name,
     1291                    service_name,
    12351292                    chan_num,
    12361293                    sdt->ServiceID(i),
    12371294                    0, 0,
     
    12481305                db_source_id,
    12491306                chanid,
    12501307                service_name,
     1308                service_name,
    12511309                chan_num,
    12521310                sdt->ServiceID(i),
    12531311                0, 0,
     
    14361494                db_source_id,
    14371495                chanid,
    14381496                (*s).ServiceName,
     1497                (*s).ServiceName,
    14391498                chan_num,
    14401499                (*s).ServiceID,
    14411500                atsc_major, atsc_minor,
     
    14521511                db_source_id,
    14531512                chanid,
    14541513                (*s).ServiceName,
     1514                (*s).ServiceName,
    14551515                chan_num,
    14561516                (*s).ServiceID,
    14571517                (*s).ChanNum / 10, (*s).ChanNum % 10,