Ticket #927: tuning_patch.diff

File tuning_patch.diff, 11.4 KB (added by Mark.Buechler@…, 20 years ago)

Much better patch

  • dvbchannel.cpp

    diff -rup libmythtv.no_hack/dvbchannel.cpp libmythtv/dvbchannel.cpp
    old new DVBChannel::DVBChannel(int aCardNum, TVR  
    8282    dvbcam = new DVBCam(cardnum);
    8383    bzero(&info, sizeof(info));
    8484    has_crc_bug = CardUtil::HasDVBCRCBug(aCardNum);
     85    frequency_incr = -10;
    8586}
    8687
    8788DVBChannel::~DVBChannel()
    bool DVBChannel::Tune(const dvb_channel_  
    642643    bool has_diseq = (FE_QPSK == info.type) && diseqc;
    643644    struct dvb_frontend_parameters params = channel.tuning.params;
    644645
     646    prev_channel.tuning = channel.tuning;
     647
    645648// (begin)softcam-0.4
    646649    GENERAL(QString("invalidating DeCSA for card %1").arg(cardnum));
    647650    //DVBRecorder::UpdateDeCSAKeys(cardnum, 'I', 0, NULL, 0);
    bool DVBChannel::Tune(const dvb_channel_  
    674677        // Adjust for Satelite recievers which offset the frequency.
    675678        params.frequency = tuned_frequency(channel.tuning, info.type, NULL);
    676679
     680        frequency_incr = 0 - frequency_incr;
     681        params.frequency = params.frequency + frequency_incr;
     682
    677683        if (ioctl(fd_frontend, FE_SET_FRONTEND, &params) < 0)
    678684        {
    679685            ERRNO("DVBChannel::Tune: "
    bool DVBChannel::Tune(const dvb_channel_  
    691697    return true;
    692698}
    693699
     700bool DVBChannel::Tune_again(void)
     701{
     702    return Tune(prev_channel, true);
     703}
     704
    694705/** \fn DVBChannel::GetTuningParams(DVBTuning& tuning) const
    695706 *  \brief Fetches DVBTuning params from driver
    696707 *  \return true on success, false on failure
  • dvbchannel.h

    diff -rup libmythtv.no_hack/dvbchannel.h libmythtv/dvbchannel.h
    old new class DVBChannel : public QObject, publi  
    6565    bool SwitchToInput(const QString &inputname, const QString &chan);
    6666    bool SwitchToInput(int newcapchannel, bool setstarting);
    6767    bool Tune(const dvb_channel_t& channel, bool force_reset=false);
     68    bool Tune_again(void);
    6869
    6970    // Set/Get/Command just for SIScan/ScanWizardScanner
    7071    void SetMultiplexID(int mplexid)          { currentTID = mplexid; };
    class DVBChannel : public QObject, publi  
    105106    dvb_frontend_info info;        ///< Contains info on tuning hardware
    106107    dvb_channel_t     chan_opts;   ///< Tuning options sent to tuning hardware
    107108    DVBTuning         prev_tuning; ///< Last tuning options sent to hardware
     109    dvb_channel_t     prev_channel;
    108110
    109111    volatile int      fd_frontend; ///< File descriptor for tuning hardware
    110112    int               cardnum;     ///< DVB Card number
    class DVBChannel : public QObject, publi  
    114116    bool              first_tune;  ///< Used to force hardware reset
    115117
    116118    int               nextcapchannel; ///< Signal an input change
     119    int               frequency_incr;
    117120};
    118121
    119122#endif
  • dvbdiseqc.cpp

    diff -rup libmythtv.no_hack/dvbdiseqc.cpp libmythtv/dvbdiseqc.cpp
    old new DVBDiSEqC::DVBDiSEqC(int _cardnum, int _  
    5252{
    5353
    5454    // Number of repeats for DiSEqC 1.1 devices
    55     repeat = 1;
     55    repeat = 2;
    5656}
    5757
    5858DVBDiSEqC::~DVBDiSEqC()
  • dvbrecorder.cpp

    Only in libmythtv: dvbdiseqc.cpp.rej
    diff -rup libmythtv.no_hack/dvbrecorder.cpp libmythtv/dvbrecorder.cpp
    old new DVBRecorder::DVBRecorder(TVRec *rec, DVB  
    127127    initDeCSA();
    128128// (end)softcsa-0.5.pre3
    129129
     130    _has_payload = false;
    130131}
    131132
    132133DVBRecorder::~DVBRecorder()
    bool DVBRecorder::ProcessTSPacket(const  
    880881    if (!info->payloadStartSeen)
    881882    {
    882883        if (!tspacket.PayloadStart())
     884        {
     885            _has_payload = false;
    883886            return true; // not payload start - drop packet
     887        }
    884888
    885889        VERBOSE(VB_RECORD,
    886890                QString("PID 0x%1 Found Payload Start").arg(pid,0,16));
    887891        info->payloadStartSeen = true;
     892        _has_payload = true;
    888893    }
    889894
    890895    // Write PAT & PMT tables occasionally
  • dvbrecorder.h

    diff -rup libmythtv.no_hack/dvbrecorder.h libmythtv/dvbrecorder.h
    old new class DVBRecorder: public DTVRecorder, p  
    9494    bool IsOpen(void) const { return _stream_fd >= 0; }
    9595    void Close(void);
    9696
     97    bool HasPayload(void) const
     98        { return _has_payload; }
     99
    97100    bool RecordsTransportStream(void) const
    98101        { return _record_transport_stream_option; }
    99102
    class DVBRecorder: public DTVRecorder, p  
    165168    ProgramMapTable         *_pmt;
    166169    uint            _next_pmt_version;
    167170    int             _ts_packets_until_psip_sync;
     171    bool            _has_payload;
    168172
    169173    // Input Misc
    170174    /// PMT on input side
  • tv_rec.cpp

    Only in libmythtv: siparser.cpp.orig
    Only in libmythtv: siparser.h.orig
    Only in libmythtv: siparser.h.rej
    diff -rup libmythtv.no_hack/tv_rec.cpp libmythtv/tv_rec.cpp
    old new TVRec::TVRec(int capturecardnum)  
    130130      // RingBuffer info
    131131      ringBuffer(NULL), rbFilePrefix(""), rbFileExt("mpg")
    132132{
     133      // Retune stuff
     134      retune_timer = new TuningTimer();
     135      retune_timer->setTimeout(10000);
     136      retune_timer->start();
     137      retune_requests = 0;
    133138}
    134139
    135140/** \fn TVRec::Init()
    void TVRec::RingBufferChanged(RingBuffer  
    31883193 */
    31893194void TVRec::HandleTuning(void)
    31903195{
     3196    bool handle_done = false;
     3197
    31913198    if (tuningRequests.size())
    31923199    {
    31933200        const TuningRequest *request = &tuningRequests.front();
    void TVRec::HandleTuning(void)  
    31993206                              kFlagEITScan|kFlagAntennaAdjust))
    32003207        {
    32013208            if (!recorder)
     3209            {
    32023210                TuningFrequency(*request);
     3211                retune_timer->restart();
     3212                retune_timer->addMSecs(1);
     3213                retune_requests = 0;
     3214            }
    32033215            else
    32043216                SetFlags(kFlagWaitingForRecPause);
    32053217        }
    void TVRec::HandleTuning(void)  
    32213233            GetDVBRecorder()->Close();
    32223234            GetDVBRecorder()->SetRingBuffer(NULL);
    32233235        }
     3236
     3237        retune_timer->restart();
     3238        retune_timer->addMSecs(1);
     3239        retune_requests = 0;
    32243240#endif // USING_DVB
    32253241        TuningFrequency(lastTuningRequest);
    32263242    }
    3227 
     3243   
    32283244    if (HasFlags(kFlagWaitingForSignal))
    32293245    {
    32303246        if (!TuningSignalCheck())
    3231             return;
     3247            handle_done = true;
    32323248    }
    32333249
    32343250    if (HasFlags(kFlagWaitingForSIParser))
    32353251    {
    32363252        if (!TuningPMTCheck())
    3237             return;
     3253            handle_done = true;
    32383254    }
    32393255
     3256#ifdef USING_DVB
     3257    if (HasFlags(kFlagWaitingForSignal) ||  // Just because we have signal, we
     3258        HasFlags(kFlagWaitingForSIParser))  // may not have the right transponder
     3259        if (!retune_timer->elapsed() && (retune_requests < 30))
     3260        {
     3261            RetuneChannel();
     3262            retune_requests++;
     3263        }
     3264#endif // USING_DVB
     3265
     3266    if (handle_done)
     3267        return;
     3268
    32403269    if (HasFlags(kFlagNeedToStartRecorder))
    32413270    {
    32423271        if (recorder)
    void TVRec::HandleTuning(void)  
    32443273        else
    32453274            TuningNewRecorder();
    32463275
    3247         // If we got this far it is safe to set a new starting channel...
    3248         if (channel)
    3249             channel->StoreInputChannels();
     3276        SetFlags(kFlagWaitingForPayload);
     3277    }
     3278
     3279    if (HasFlags(kFlagWaitingForPayload))
     3280    {
     3281#ifdef USING_DVB
     3282        if (GetDVBRecorder())
     3283        {
     3284            // Check to see if we have a Payload Start
     3285            if (GetDVBRecorder()->HasPayload())
     3286            {
     3287                ClearFlags(kFlagWaitingForPayload);
     3288
     3289                // If we got this far it is safe to set a new starting channel...
     3290                if (channel)
     3291                    channel->StoreInputChannels();
     3292            }
     3293        }
     3294        else
     3295        {
     3296#endif // USING_DVB
     3297
     3298            ClearFlags(kFlagWaitingForPayload);
     3299
     3300            if (channel)
     3301                channel->StoreInputChannels();
     3302#if USING_DVB
     3303        }
     3304#endif // USING_DVB
    32503305    }
    32513306}
    32523307
    void TVRec::TuningShutdowns(const Tuning  
    33213376    ClearFlags(kFlagPendingActions);
    33223377}
    33233378
     3379/** \fn TVRec::RetuneChannel(void)
     3380 *  \brief Retunes a DVB channel
     3381 */
     3382bool TVRec::RetuneChannel(void)
     3383{
     3384#ifdef USING_DVB
     3385    if (GetDVBChannel())
     3386        return GetDVBChannel()->Tune_again();
     3387#endif // USING_DVB
     3388    return false;
     3389}
     3390
    33243391/** \fn TVRec::TuningFrequency(const TuningRequest&)
    33253392 *  \brief Performs initial tuning required for any tuning event.
    33263393 *
    QString TVRec::FlagToString(uint f)  
    38803947            msg += "WaitingForSignal,";
    38813948        if (kFlagWaitingForSIParser & f)
    38823949            msg += "WaitingForSIParser,";
     3950        if (kFlagWaitingForPayload & f)
     3951            msg += "kFlagWaitingForPayload,";
    38833952        if (kFlagNeedToStartRecorder & f)
    38843953            msg += "NeedToStartRecorder,";
    38853954        if (kFlagKillRingBuffer & f)
  • tv_rec.h

    diff -rup libmythtv.no_hack/tv_rec.h libmythtv/tv_rec.h
    old new  
    1313#include "mythdeque.h"
    1414#include "programinfo.h"
    1515#include "tv.h"
     16#include "util.h"
    1617
    1718class QSocket;
    1819class NuppelVideoRecorder;
    class Channel;  
    3738
    3839class PMTObject;
    3940
     41class TuningTimer
     42{
     43  public:
     44    TuningTimer() {}
     45
     46    void setTimeout(long t) { _timeout = t; }
     47    long timeout(void) { return _timeout; }
     48    void start() { t_timer.start(); }
     49    int restart() { int ret = elapsed();
     50                    t_timer.restart();
     51                    return ret;
     52                  }
     53    int elapsed() { int ret = t_timer.elapsed();
     54                    if (ret > _timeout) { ret = 0;  t_timer.restart(); }
     55                    return ret;
     56                  }
     57
     58    void addMSecs(int ms) { t_timer.addMSecs(ms); }
     59
     60  private:
     61    QTime t_timer;
     62    long _timeout;
     63};
     64
    4065/// Used to request ProgramInfo for channel browsing.
    4166typedef enum
    4267{
    class TVRec : public QObject  
    276301    void TuningNewRecorder(void);
    277302    void TuningRestartRecorder(void);
    278303
     304    bool RetuneChannel(void);
     305
    279306    void HandleStateChange(void);
    280307    void ChangeState(TVState nextState);
    281308    bool StateIsRecording(TVState state);
    class TVRec : public QObject  
    362389    QString      rbFilePrefix;
    363390    QString      rbFileExt;
    364391
     392    // Retune stuff
     393    TuningTimer *retune_timer;
     394    int retune_requests;
     395
    365396  public:
    366397    static const uint kEITScanStartTimeout;
    367398    static const uint kSignalMonitoringRate;
    class TVRec : public QObject  
    394425
    395426    static const uint kFlagNoRec                = 0x0000F000;
    396427    static const uint kFlagKillRingBuffer       = 0x00010000;
     428    static const uint kFlagWaitingForPayload    = 0x00020000;
    397429
    398430    // Waiting stuff
    399431    static const uint kFlagWaitingForRecPause   = 0x00100000;