Ticket #6138: 134-hdhr.recstats.trunk.7.patch

File 134-hdhr.recstats.trunk.7.patch, 15.7 KB (added by anonymous, 12 years ago)
  • mythtv/libs/libmythhdhomerun/hdhomerun_video.c

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythhdhomerun/hdhomerun_video.c myth.20207.0313b/mythtv/libs/libmythhdhomerun/hdhomerun_video.c
     
    4949        volatile uint32_t network_error_count;
    5050        volatile uint32_t sequence_error_count;
    5151        volatile uint32_t overflow_error_count;
     52        volatile uint32_t buffer_highwater_mark;
    5253        volatile uint8_t sequence[0x2000];
    5354};
    5455
     
    286287                        head -= vs->buffer_size;
    287288                }
    288289
     290                /* update buffer_highwater_mark */
     291                /* head - where things will be inserted */
     292                /* tail - where things will be removed */
     293                size_t tail = vs->tail;
     294                uint32_t space_used;
     295                if (head > tail) {
     296                        space_used = head - tail;
     297                } else {
     298                        /* head < tail */
     299                        space_used = (head + vs->buffer_size) - tail;
     300                }
     301
     302                if (space_used > vs->buffer_highwater_mark) {
     303                        vs->buffer_highwater_mark = space_used;
     304                }
     305
    289306                /* Check for buffer overflow. */
    290307                if (head == vs->tail) {
    291308                        vs->overflow_error_count++;
     
    367384        vs->network_error_count = 0;
    368385        vs->sequence_error_count = 0;
    369386        vs->overflow_error_count = 0;
     387        vs->buffer_highwater_mark = 0;
    370388
    371389        pthread_mutex_unlock(&vs->lock);
    372390}
     
    376394        struct hdhomerun_video_stats_t stats;
    377395        hdhomerun_video_get_stats(vs, &stats);
    378396
    379         hdhomerun_debug_printf(vs->dbg, "video sock: pkt=%ld net=%ld te=%ld miss=%ld drop=%ld\n",
     397        hdhomerun_debug_printf(vs->dbg, "video sock: pkt=%ld net=%ld te=%ld miss=%ld drop=%ld hwm=%ld\n",
    380398                stats.packet_count, stats.network_error_count,
    381399                stats.transport_error_count, stats.sequence_error_count,
    382                 stats.overflow_error_count
     400                stats.overflow_error_count, stats.buffer_highwater_mark
    383401        );
    384402}
    385403
     
    394412        stats->transport_error_count = vs->transport_error_count;
    395413        stats->sequence_error_count = vs->sequence_error_count;
    396414        stats->overflow_error_count = vs->overflow_error_count;
     415        stats->buffer_highwater_mark = vs->buffer_highwater_mark;
    397416
    398417        pthread_mutex_unlock(&vs->lock);
    399418}
  • mythtv/libs/libmythhdhomerun/hdhomerun_video.h

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythhdhomerun/hdhomerun_video.h myth.20207.0313b/mythtv/libs/libmythhdhomerun/hdhomerun_video.h
     
    4141        uint32_t transport_error_count;
    4242        uint32_t sequence_error_count;
    4343        uint32_t overflow_error_count;
     44        uint32_t buffer_highwater_mark;
    4445};
    4546
    4647#define TS_PACKET_SIZE 188
  • mythtv/libs/libmythtv/DeviceReadBuffer.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/DeviceReadBuffer.cpp myth.20207.0313b/mythtv/libs/libmythtv/DeviceReadBuffer.cpp
     
    214214    used     += len;
    215215    writePtr += len;
    216216    writePtr  = (writePtr == endPtr) ? buffer : writePtr;
    217 #if REPORT_RING_STATS
    218217    max_used = max(used, max_used);
     218#if REPORT_RING_STATS
    219219    avg_used = ((avg_used * avg_cnt) + used) / ++avg_cnt;
    220220#endif
    221221}
  • mythtv/libs/libmythtv/DeviceReadBuffer.h

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/DeviceReadBuffer.h myth.20207.0313b/mythtv/libs/libmythtv/DeviceReadBuffer.h
     
    4040    void Reset(const QString &streamName, int streamfd);
    4141    void Stop(void);
    4242
     43    size_t GetMaxUsed() const { return max_used; };
     44
    4345    void SetRequestPause(bool request);
    4446    bool IsPaused(void) const;
    4547    bool WaitForUnpause(unsigned long timeout);
  • mythtv/libs/libmythtv/ThreadedFileWriter.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/ThreadedFileWriter.cpp myth.20207.0313b/mythtv/libs/libmythtv/ThreadedFileWriter.cpp
     
    134134    rpos(0),                             wpos(0),
    135135    written(0),
    136136    // buffer
    137     buf(NULL),                           tfw_buf_size(0)
     137    buf(NULL),                           tfw_buf_size(0),
     138    tfw_highwater_mark(0)
    138139{
    139140    filename.detach();
    140141}
     
    168169
    169170        tfw_buf_size = TFW_DEF_BUF_SIZE;
    170171        tfw_min_write_size = TFW_MIN_WRITE_SIZE;
     172        tfw_highwater_mark = 0;
    171173        pthread_create(&writer, NULL, boot_writer, this);
    172174        pthread_create(&syncer, NULL, boot_syncer, this);
    173175        return true;
     
    200202        delete [] buf;
    201203        buf = NULL;
    202204    }
     205
     206    VERBOSE(VB_GENERAL, LOC + QString("Buffer size = %1 KB hwm = %2 KB")
     207        .arg(tfw_buf_size / 1024).arg(tfw_highwater_mark/1024));
    203208}
    204209
    205210/** \fn ThreadedFileWriter::Write(const void*, uint)
     
    511516/** \fn ThreadedFileWriter::BufUsed(void) const
    512517 *  \brief Number of bytes queued for write by the write thread. With locking.
    513518 */
    514 uint ThreadedFileWriter::BufUsed(void) const
     519uint ThreadedFileWriter::BufUsed(void)
    515520{
    516521    QMutexLocker locker(&buflock);
    517     return (wpos >= rpos) ? wpos - rpos : tfw_buf_size - rpos + wpos;
     522    uint result = (wpos >= rpos) ? wpos - rpos : tfw_buf_size - rpos + wpos;
     523    if (result > tfw_highwater_mark)
     524        tfw_highwater_mark=result;
     525    return result;
    518526}
    519527
    520528/**
  • mythtv/libs/libmythtv/ThreadedFileWriter.h

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/ThreadedFileWriter.h myth.20207.0313b/mythtv/libs/libmythtv/ThreadedFileWriter.h
     
    2121    void SetWriteBufferSize(uint newSize = TFW_DEF_BUF_SIZE);
    2222    void SetWriteBufferMinWriteSize(uint newMinSize = TFW_MIN_WRITE_SIZE);
    2323
    24     uint BufUsed(void) const;
     24    uint BufUsed(void);
    2525    uint BufFree(void) const;
    2626
    2727    void Sync(void);
     
    6161    // buffer
    6262    char           *buf;
    6363    unsigned long   tfw_buf_size;
     64    unsigned long   tfw_highwater_mark;
    6465
    6566    // threads
    6667    pthread_t       writer;
  • mythtv/libs/libmythtv/dvbrecorder.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/dvbrecorder.cpp myth.20207.0313b/mythtv/libs/libmythtv/dvbrecorder.cpp
     
    330330{
    331331    VERBOSE(VB_RECORD, LOC + "Close() fd("<<_stream_fd<<") -- begin");
    332332
     333    uint hwm = _stream_handler->GetMaxUsed();
     334    VERBOSE(VB_GENERAL,QString( LOC + "DVB Stats: pkts=%1 hwm=%2 KB Errors: trnsprt=%3 seq=%4")
     335            .arg(_total_packet_count)
     336            .arg(hwm/1024)
     337            .arg(_transport_error_count)
     338            .arg(_continuity_error_count));
     339
    333340    DVBStreamHandler::Return(_stream_handler);
    334341
    335342    VERBOSE(VB_RECORD, LOC + "Close() fd("<<_stream_fd<<") -- end");
     
    374381
    375382    _continuity_error_count = 0;
    376383    _stream_overflow_count = 0;
     384    _transport_error_count = 0;
     385    _bad_packet_count = 0;
     386    _total_packet_count = 0;
    377387
    378388    _request_recording = true;
    379389    _recording = true;
     
    519529                QString("PID 0x%1 discontinuity detected").arg(pid,0,16));
    520530        _continuity_error_count++;
    521531    }
     532    if (tspacket.TransportError())
     533    {
     534        _transport_error_count++;
     535    }
     536    _total_packet_count++;
    522537
    523538    // Sync recording start to first keyframe
    524539    if (_wait_for_keyframe_option && _first_keyframe < 0)
     
    553568                QString("PID 0x%1 discontinuity detected").arg(pid,0,16));
    554569        _continuity_error_count++;
    555570    }
     571    if (tspacket.TransportError())
     572    {
     573        _transport_error_count++;
     574    }
     575
     576    _total_packet_count++;
    556577
    557578    // Only create fake keyframe[s] if there are no audio/video streams
    558579    if (_input_pmt && _has_no_av)
  • mythtv/libs/libmythtv/dvbrecorder.h

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/dvbrecorder.h myth.20207.0313b/mythtv/libs/libmythtv/dvbrecorder.h
     
    125125    mutable uint        _continuity_error_count;
    126126    mutable uint        _stream_overflow_count;
    127127    mutable uint        _bad_packet_count;
     128    mutable uint        _transport_error_count;
     129    mutable uint        _total_packet_count;
    128130
    129131    // Constants
    130132    static const int TSPACKETS_BETWEEN_PSIP_SYNC;
  • mythtv/libs/libmythtv/dvbstreamhandler.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/dvbstreamhandler.cpp myth.20207.0313b/mythtv/libs/libmythtv/dvbstreamhandler.cpp
     
    9898
    9999    _pid_lock(QMutex::Recursive),
    100100    _open_pid_filters(0),
    101     _listener_lock(QMutex::Recursive)
     101    _listener_lock(QMutex::Recursive),
     102    _max_used(0)
    102103{
    103104}
    104105
     
    208209    }
    209210}
    210211
     212uint DVBStreamHandler::GetMaxUsed(void)
     213{
     214    QMutexLocker locker(&_start_stop_lock);
     215    if (_device_read_buffer)
     216    {
     217       _max_used = _device_read_buffer->GetMaxUsed();
     218    }
     219    return _max_used;
     220}
     221
    211222void DVBStreamHandler::Stop(void)
    212223{
    213224    QMutexLocker locker(&_start_stop_lock);
     
    215226    if (IsRunning())
    216227    {
    217228        if (_device_read_buffer)
     229        {
    218230            _device_read_buffer->Stop();
     231            _max_used = _device_read_buffer->GetMaxUsed();
     232        }
    219233        SetRunning(false);
    220234        pthread_join(_reader_thread, NULL);
    221235    }
     
    255269        return;
    256270    bzero(buffer, buffer_size);
    257271
     272    VERBOSE(VB_GENERAL, QString(LOC + "HD Ringbuffer size = %1 KB").arg(buffer_size / 1024));
     273
    258274    QByteArray dvr_dev_path = _dvr_dev_path.toAscii();
    259275    int dvr_fd = open(dvr_dev_path.constData(), O_RDONLY | O_NONBLOCK);
    260276    if (dvr_fd < 0)
     
    369385        if (_device_read_buffer->IsRunning())
    370386            _device_read_buffer->Stop();
    371387
     388        _max_used=_device_read_buffer->GetMaxUsed();
     389
    372390        delete _device_read_buffer;
    373391        _device_read_buffer = NULL;
    374392    }
  • mythtv/libs/libmythtv/dvbstreamhandler.h

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/dvbstreamhandler.h myth.20207.0313b/mythtv/libs/libmythtv/dvbstreamhandler.h
     
    7070    // ReaderPausedCB
    7171    virtual void ReaderPaused(int fd) { (void) fd; }
    7272
     73    uint GetMaxUsed();
     74
    7375  private:
    7476    DVBStreamHandler(const QString &);
    7577    ~DVBStreamHandler();
     
    118120    mutable QMutex          _listener_lock;
    119121    vector<MPEGStreamData*> _stream_data_list;
    120122
     123    uint _max_used;
     124
    121125    // for caching TS monitoring supported value.
    122126    static QMutex             _rec_supports_ts_monitoring_lock;
    123127    static QMap<QString,bool> _rec_supports_ts_monitoring;
  • mythtv/libs/libmythtv/hdhrrecorder.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/hdhrrecorder.cpp myth.20207.0313b/mythtv/libs/libmythtv/hdhrrecorder.cpp
     
    117117    memset(_continuity_counter, 0xff, sizeof(_continuity_counter));
    118118
    119119    _stream_handler = HDHRStreamHandler::Get(_channel->GetDevice());
     120    _stream_handler->GetStats(&_start_stats, false);
    120121
    121122    VERBOSE(VB_RECORD, LOC + "HDHR opened successfully");
    122123
     
    129130
    130131    if (IsOpen())
    131132    {
     133        hdhomerun_video_stats_t end_stats;
     134        _stream_handler->GetStats(&end_stats, true);
     135
     136        VERBOSE(VB_GENERAL,QString( LOC + "HDHR Stats: pkts=%1 hwm=%6 KB Errors: net=%2 trnsprt=%3 seq=%4 ovflow=%5")
     137               .arg(end_stats.packet_count          - _start_stats.packet_count)
     138               .arg(end_stats.network_error_count   - _start_stats.network_error_count)
     139               .arg(end_stats.transport_error_count - _start_stats.transport_error_count)
     140               .arg(end_stats.sequence_error_count  - _start_stats.sequence_error_count)
     141               .arg(end_stats.overflow_error_count  - _start_stats.overflow_error_count)
     142               .arg(end_stats.buffer_highwater_mark / 1024)); /* buffer_highwater_mark is absolute */
     143
    132144        HDHRStreamHandler::Return(_stream_handler);
    133145    }
    134146
  • mythtv/libs/libmythtv/hdhrrecorder.h

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/hdhrrecorder.h myth.20207.0313b/mythtv/libs/libmythtv/hdhrrecorder.h
     
    9595    ProgramMapTable               *_input_pmt;
    9696    bool                           _has_no_av;
    9797
     98    hdhomerun_video_stats_t       _start_stats;
     99
    98100    unsigned char   _stream_id[0x1fff];
    99101    unsigned char   _pid_status[0x1fff];
    100102    unsigned char   _continuity_counter[0x1fff];
  • mythtv/libs/libmythtv/hdhrstreamhandler.cpp

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/hdhrstreamhandler.cpp myth.20207.0313b/mythtv/libs/libmythtv/hdhrstreamhandler.cpp
     
    112112    _listener_lock(QMutex::Recursive),
    113113    _hdhr_lock(QMutex::Recursive)
    114114{
     115    memset(&_last_stats, 0, sizeof(_last_stats));
    115116}
    116117
    117118HDHRStreamHandler::~HDHRStreamHandler()
     
    294295    return (QString::null != TunerSet("target", "0.0.0.0:0"));
    295296}
    296297
     298void HDHRStreamHandler::GetStats(hdhomerun_video_stats_t* stats, bool use_cache) {
     299    QMutexLocker locker(&_hdhr_lock);
     300    if (_video_socket) {
     301        hdhomerun_video_get_stats(_video_socket, &_last_stats);
     302        memcpy(stats, &_last_stats, sizeof(hdhomerun_video_stats_t));
     303    } else if (use_cache) {
     304        memcpy(stats, &_last_stats, sizeof(hdhomerun_video_stats_t));
     305    } else {
     306        memset(stats, 0, sizeof(hdhomerun_video_stats_t));
     307    }
     308}
     309
    297310QString HDHRStreamHandler::GetTunerStatus() {
    298311    return TunerGet("status");
    299312}
     
    511524    hdhomerun_video_sock_t* tmp_video_socket;
    512525    {
    513526        QMutexLocker locker(&_hdhr_lock);
     527        hdhomerun_video_get_stats(_video_socket, &_last_stats);
    514528        tmp_video_socket = _video_socket;
    515529        _video_socket=NULL;
    516530    }
  • mythtv/libs/libmythtv/hdhrstreamhandler.h

    diff -r -u -N -X diff.exclude -x myth.20207.0313a -x myth.20207.0313b myth.20207.0313a/mythtv/libs/libmythtv/hdhrstreamhandler.h myth.20207.0313b/mythtv/libs/libmythtv/hdhrstreamhandler.h
     
    5050                          DTVSignalMonitor *sigmon,
    5151                          HDHRChannel       *dvbchan);
    5252
     53    void GetStats(hdhomerun_video_stats_t* stats, bool use_cache);
     54
    5355    // ReaderPausedCB
    5456    virtual void ReaderPaused(int fd) { (void) fd; }
    5557
     
    106108  private:
    107109    hdhomerun_control_sock_t  *_control_socket;
    108110    hdhomerun_video_sock_t    *_video_socket;
     111    hdhomerun_video_stats_t    _last_stats;
    109112    uint                       _device_id;
    110113    uint                       _device_ip;
    111114    uint                       _tuner;