Ticket #1848: mfdb_chanid_fix2.patch

File mfdb_chanid_fix2.patch, 5.1 KB (added by Anduin Withers, 19 years ago)
  • sourceutil.h

     
    1616                                        QString &passwd,  QString &lineupid);
    1717    static bool    IsAnalog(uint sourceid);
    1818    static bool    UpdateChannelsFromListings(uint sourceid);
     19    static QString GetLineupType(uint sourceid);
    1920};
    2021
    2122#endif //_SOURCEUTIL_H_
  • sourceutil.cpp

     
    33// Qt headers
    44#include <qregexp.h>
    55
     6#include <map>
     7
    68// MythTV headers
    79#include "sourceutil.h"
    810#include "mythdbcon.h"
    911#include "util.h"
     12#include "mythcontext.h"
    1013
    1114QString SourceUtil::GetChannelSeparator(uint sourceid)
    1215{
     
    118121                        "--sourceid %1").arg(sourceid));
    119122    return true;
    120123}
     124
     125/// Returns the lineup type given a source ID.
     126/// \param [in] sourceid The lineup source ID.
     127/// \returns A string with the TMSDataDirect lineup type or "Unknown"
     128/// \remarks This function relies on temporary tables which are only valid
     129///          when mythfilldatabase is processing a lineup.
     130QString SourceUtil::GetLineupType(uint sourceid)
     131{
     132    typedef std::map<uint, QString> smap;
     133    static smap sid_cache;
     134
     135    smap::iterator p = sid_cache.find(sourceid);
     136    if (p != sid_cache.end())
     137    {
     138        return p->second;
     139    }
     140
     141    MSqlQuery query(MSqlQuery::DDCon());
     142    query.prepare(
     143        "SELECT `type` FROM dd_lineup "
     144        "LEFT JOIN videosource ON dd_lineup.lineupid = videosource.lineupid "
     145        "WHERE sourceid = :SOURCEID;");
     146    query.bindValue(":SOURCEID", sourceid);
     147
     148    if (query.exec() && query.next())
     149    {
     150        QString type(query.value(0).toString());
     151        sid_cache.insert(smap::value_type(sourceid, type));
     152        return type;
     153    }
     154    else
     155    {
     156        VERBOSE(VB_IMPORTANT, QString("Error: Source ID has no lineup type."));
     157    }
     158
     159    return "Unknown";
     160}
  • datadirect.cpp

     
    3131static void    get_atsc_stuff(QString channum, int sourceid, int freqid,
    3232                              int &major, int &minor, long long &freq);
    3333static uint    create_atscsrcid(QString chan_major, QString chan_minor);
    34 static QString process_dd_station(uint sourceid,
     34static QString process_dd_station(uint sourceid, QString lineup_type,
    3535                                  QString  chan_major, QString  chan_minor,
    3636                                  QString &tvformat,   uint    &freqid,
    3737                                  uint    &atscsrcid);
     
    675675    if (dd_station_info.size() == 0)
    676676        return true;
    677677
     678    QString lineup_type = SourceUtil::GetLineupType(sourceid);
     679
    678680    MSqlQuery chan_update_q(MSqlQuery::DDCon());
    679681    chan_update_q.prepare(
    680682        "UPDATE channel "
     
    691693        QString chan_minor = dd_station_info.value(5).toString();
    692694        QString tvformat   = QString::null;
    693695        QString channum    = process_dd_station(
    694             sourceid, chan_major, chan_minor, tvformat, freqid, atscsrcid);
     696            sourceid, lineup_type, chan_major, chan_minor, tvformat, freqid,
     697            atscsrcid);
    695698
    696699        chan_update_q.bindValue(":CALLSIGN",  dd_station_info.value(0));
    697700        chan_update_q.bindValue(":NAME",      dd_station_info.value(1));
     
    17591762static uint create_atscsrcid(QString chan_major, QString chan_minor)
    17601763{
    17611764    bool ok;
    1762     uint major = chan_major.toUInt(&ok), atscsrcid = 0;
     1765    uint atscsrcid = chan_major.toUInt(&ok);
    17631766    if (!ok)
    1764         return atscsrcid;
     1767        return 0;
    17651768
    1766     atscsrcid = major << 8;
     1769    atscsrcid <<= 8;
    17671770    if (chan_minor.isEmpty())
    17681771        return atscsrcid;
    17691772
     
    17711774}
    17721775
    17731776static QString process_dd_station(
    1774     uint sourceid, QString chan_major, QString chan_minor,
     1777    uint sourceid, QString lineup_type, QString chan_major, QString chan_minor,
    17751778    QString &tvformat, uint &freqid, uint &atscsrcid)
    17761779{
    17771780    QString channum = chan_major;
     
    17811784    if (atscsrcid & 0xff)
    17821785    {
    17831786        tvformat = "atsc";
    1784         channum += SourceUtil::GetChannelSeparator(sourceid) + chan_minor;
     1787        channum += "_" + chan_minor;
    17851788    }
    17861789
    1787     if (!freqid && !(atscsrcid & 0xff))
    1788         freqid = chan_major.toInt();
     1790    if (lineup_type == "LocalBroadcast")
     1791    {
     1792        if (!freqid && !(atscsrcid & 0xff))
     1793            freqid = chan_major.toInt();
     1794    }
     1795    else
     1796    {
     1797        // lose the freqid lest someone be fool enough to use it
     1798        freqid = channum.toInt();
     1799    }
    17891800
    17901801    return channum;
    17911802}
     
    18001811    uint atscsrcid;
    18011812    QString tvformat;
    18021813    QString channum = process_dd_station(
    1803         sourceid, chan_major, chan_minor, tvformat, freqid, atscsrcid);
     1814        sourceid, SourceUtil::GetLineupType(sourceid), chan_major, chan_minor,
     1815        tvformat, freqid, atscsrcid);
    18041816
    18051817    // First check if channel already in DB, but without xmltvid
    18061818    MSqlQuery query(MSqlQuery::DDCon());