Ticket #1970: 1970_silence_dvbrec_ff.diff

File 1970_silence_dvbrec_ff.diff, 6.6 KB (added by Janne <janne-mythtv@…>, 13 years ago)
  • mythtv/libs/libmythtv/dvbrecorder.cpp

     mythtv/libs/libmythtv/dvbrecorder.cpp |   93 ++++++++++++++++++---------------
     mythtv/libs/libmythtv/dvbrecorder.h   |   10 +++-
     2 files changed, 59 insertions(+), 44 deletions(-)
    
    diff --git a/mythtv/libs/libmythtv/dvbrecorder.cpp b/mythtv/libs/libmythtv/dvbrecorder.cpp
    index d348359..24e0f00 100644
    a b DVBRecorder::DVBRecorder(TVRec *rec, DVB 
    9393      dvbchannel(advbchannel),
    9494      _stream_data(NULL),
    9595      _reset_pid_filters(true),
     96      _open_pid_filters(0),
     97      _max_pid_filters(1<<13),
    9698      _pid_lock(true),
    9799      _input_pat(NULL),
    98100      _input_pmt(NULL),
    void DVBRecorder::CloseFilters(void) 
    314316    PIDInfoMap::iterator it;
    315317    for (it = _pid_infos.begin(); it != _pid_infos.end(); ++it)
    316318    {
    317         (*it)->Close();
     319        _open_pid_filters = (*it)->Close(_open_pid_filters);
    318320        delete *it;
    319321    }
    320322    _pid_infos.clear();
    321323    _eit_pids.clear();
     324    _open_pid_filters = 0;
     325    _max_pid_filters  = 1<<13;
    322326}
    323327
    324328int DVBRecorder::OpenFilterFd(uint pid, int pes_type, uint stream_type)
    325329{
     330    if (_open_pid_filters >= _max_pid_filters)
     331        return -1;
     332
    326333    // bits per millisecond
    327334    uint bpms = (StreamID::IsVideo(stream_type)) ? 19200 : 500;
    328335    // msec of buffering we want
    int DVBRecorder::OpenFilterFd(uint pid, 
    378385        close(fd_tmp);
    379386
    380387        VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to set demux filter." + ENO);
     388        _max_pid_filters = _open_pid_filters;
    381389        return -1;
    382390    }
    383391
     392    _open_pid_filters++;
    384393    return fd_tmp;
    385394}
    386395
    bool DVBRecorder::OpenFilter(uint pid, i 
    404413        if (info->pesType == pes_type)
    405414            fd_tmp = info->filter_fd;
    406415        else
    407             info->Close();
     416            _open_pid_filters = info->Close(_open_pid_filters);
     417
     418        _pid_infos.erase(it);
     419        delete info;
    408420    }
    409421
    410422    if (fd_tmp < 0)
     423    {
    411424        fd_tmp = OpenFilterFd(pid, pes_type, stream_type);
    412425
    413     // try to close a low priority filter
    414     if (fd_tmp < 0)
    415     {
    416         // no free filters available
    417         avail = false;
    418         PIDInfoMap::iterator lp_it = _pid_infos.begin();
    419         for (;lp_it != _pid_infos.end(); ++lp_it)
     426        if (fd_tmp < 0)
    420427        {
    421             if (lp_it != it && (*lp_it)->priority < kFilterPriorityHigh)
     428            // no free filters, try to close a low priority filter
     429            avail = false;
     430            int min_priority = kFilterPriorityHigh;
     431            PIDInfoMap::iterator min_it;
     432
     433            PIDInfoMap::iterator lp_it = _pid_infos.begin();
     434            for (;lp_it != _pid_infos.end(); ++lp_it)
     435                if ((*lp_it)->priority < kFilterPriorityHigh)
     436                {
     437                    (*lp_it)->priority--;
     438                    if ((*lp_it)->priority < min_priority)
     439                    {
     440                        min_priority = (*lp_it)->priority;
     441                        min_it = lp_it;
     442                    }
     443                }
     444
     445            if (min_priority < kFilterPriorityHigh)
    422446            {
    423                 (*lp_it)->Close();
    424                 break;
     447                _open_pid_filters = (*min_it)->Close(_open_pid_filters);
     448                VERBOSE(VB_RECORD, LOC + "Closing low priority PID filter "
     449                        + QString("on PID 0x%1.").arg(min_it.key(), 0, 16));
     450                // PMT PIDs are the only low priority pids
     451                _pmt_monitoring_pids.push_back(min_it.key());
     452                delete *min_it;
     453                _pid_infos.erase(min_it);
     454            }
     455            else
     456            {
     457                VERBOSE(VB_IMPORTANT, LOC_ERR + "Out of PID filters!");
     458                return false;
    425459            }
    426         }
    427         if (lp_it != _pid_infos.end())
    428         {
    429             // PMT PIDs are the only low priority pids
    430             uint lp_pid = lp_it.key();
    431 
    432             VERBOSE(VB_RECORD, LOC + "Closing low priority PID filter " +
    433                     QString("on PID 0x%1.").arg(lp_pid, 0, 16));
    434 
    435             _pmt_monitoring_pids.push_back(lp_pid);
    436             delete *lp_it;
    437             _pid_infos.erase(lp_it);
    438 
    439460            fd_tmp = OpenFilterFd(pid, pes_type, stream_type);
    440461        }
    441         else
    442         {
    443             VERBOSE(VB_RECORD, LOC_ERR + "Out of PID filters!");
    444         }
    445462    }
    446463
    447464    if (fd_tmp < 0)
    448     {
    449         if (info)
    450         {
    451             delete *it;
    452             _pid_infos.erase(it);
    453         }
    454         return avail;
    455     }
    456 
    457     if (!info)
    458         info = new PIDInfo();
     465        return false;
     466   
     467    info = new PIDInfo();
    459468
    460469    // Add the file descriptor to the filter list
    461470    info->filter_fd  = fd_tmp;
    bool DVBRecorder::AdjustFilters(void) 
    565574        // Delete pids we are no longer interested in
    566575        _stream_data->RemoveListeningPID(it.key());
    567576        _stream_data->RemoveWritingPID(it.key());
    568         (*it)->Close();
     577        _open_pid_filters = (*it)->Close(_open_pid_filters);
    569578        delete *it;
    570579        _pid_infos.erase(it);
    571580    }
    void DVBRecorder::AdjustMonitoringPMTPID 
    640649    if (VB_RECORD & print_verbose_messages)
    641650    {
    642651        QString tmp0 = "";
    643         QString tmp1 = QString("%1 PID filters open.").arg(_pid_infos.size());
     652        QString tmp1 = QString("%1 PID filters open.").arg(_open_pid_filters);
    644653
    645654        int sz = _pmt_monitoring_pids.size();
    646655        if (sz)
  • mythtv/libs/libmythtv/dvbrecorder.h

    diff --git a/mythtv/libs/libmythtv/dvbrecorder.h b/mythtv/libs/libmythtv/dvbrecorder.h
    index f2ab97a..fbbc309 100644
    a b class PIDInfo 
    4343    int    priority;          ///< filters with priority < 0 can be closed
    4444                              //   if a new filter can't be opened
    4545
    46     inline void Close(void);
     46    inline uint Close(uint open_filters);
    4747    inline bool CheckCC(uint cc);
    4848};
    4949typedef QMap<uint,PIDInfo*> PIDInfoMap;
    class DVBRecorder : public DTVRecorder, 
    134134    /// Set when we want to generate a new filter set
    135135    MPEGStreamData *_stream_data;
    136136    bool            _reset_pid_filters;
     137    uint            _open_pid_filters;
     138    uint            _max_pid_filters;
    137139    QMutex          _pid_lock;
    138140    PIDInfoMap      _pid_infos;
    139141    uint_vec_t      _eit_pids;
    class DVBRecorder : public DTVRecorder, 
    186188    static const int kFilterPriorityLow;
    187189};
    188190
    189 inline void PIDInfo::Close(void)
     191inline uint PIDInfo::Close(uint open_filters)
    190192{
    191193    if (filter_fd >= 0)
     194    {
    192195        close(filter_fd);
     196        return open_filters-1;
     197    }
     198    return open_filters;
    193199}
    194200
    195201inline bool PIDInfo::CheckCC(uint new_cnt)