int CStreamInfo2::update_rate () { int ret = 0; int timeout = 100; int b_len; if(!dmx && !mp) return 0; if (mp) { usleep(timeout * 1000); b_len = mp->GetReadCount(); } else { b_len = dmx->Read(dmxbuf, TS_BUF_SIZE, timeout); } //printf("ts: read %d\n", b_len); long b = b_len; if (b <= 0) return 0; gettimeofday (&tv, NULL); b_total += b; long d_tim_ms; d_tim_ms = delta_time_ms (&tv, &last_tv); if (d_tim_ms <= 0) d_tim_ms = 1; // ignore usecs bit_s = (((uint64_t) b * 8000ULL) + ((uint64_t) d_tim_ms / 2ULL)) / (uint64_t) d_tim_ms; d_tim_ms = delta_time_ms (&tv, &first_tv); if (d_tim_ms <= 0) d_tim_ms = 1; // ignore usecs abit_s = ((b_total * 8000ULL) + ((uint64_t) d_tim_ms / 2ULL)) / (uint64_t) d_tim_ms; last_tv.tv_sec = tv.tv_sec; last_tv.tv_usec = tv.tv_usec; ret = 1; return ret; }
void out_receive_time (int verbose, OPTION *opt) { struct timeval tv; time_t t; long ms; char tstr[128]; switch (opt->time_mode) { case FULL_TIME: t = time (&t); strftime (tstr,sizeof(tstr)-1,"%a %Y-%m-%d %H:%M:%S", localtime(&t)); gettimeofday (&tv, NULL); out (verbose,"Time received: %s.%03ld\n", tstr, tv.tv_usec/1000 ); break; case DELTA_TIME: gettimeofday (&tv, NULL); ms = delta_time_ms(&tv, &last_tv); out (verbose,"Time (delta) received: %0ld.%03ld (sec)\n", ms / 1000, ms % 1000); last_tv.tv_sec = tv.tv_sec; last_tv.tv_usec = tv.tv_usec; break; case NO_TIME: default: break; } return; }
int do_SignalStrength (OPTION *opt) { int fd_fe = 0; struct timeval tv,last_tv, first_tv; u_long count; FE_SIGNAL s; FE_SIG_CAP has; if (opt->inpPidFile) { fprintf (stderr,"Error: FileMode not supported...\n"); return -1; } if((fd_fe = open(opt->devFE,O_RDONLY)) < 0){ IO_error(opt->devFE); return -1; } // -- check capabilities has.ber = capability_Check (fd_fe, FE_READ_BER); has.snr = capability_Check (fd_fe, FE_READ_SNR); has.strength = capability_Check (fd_fe, FE_READ_SIGNAL_STRENGTH); has.status = capability_Check (fd_fe, FE_READ_STATUS); has.ublocks = capability_Check (fd_fe, FE_READ_UNCORRECTED_BLOCKS); indent (0); out_NL (2); out_nl (2,"---------------------------------------------------------"); out_nl (2,"Transponder/Frequency signal strength statistics..."); if (opt->rd_packet_count > 0) { out_nl (2,"max cycle count: %ld ", opt->rd_packet_count); } out_nl (9,"Capabilities: BER: %d SNR: %d SIG: %d STAT: %d UBLK: %d", has.ber, has.snr, has.strength, has.status, has.ublocks); out_nl (2,"---------------------------------------------------------"); gettimeofday (&first_tv, NULL); last_tv.tv_sec = first_tv.tv_sec; last_tv.tv_usec = first_tv.tv_usec; count = 0; while ( !isSigAbort() ) { int err; int d_tim_ms; count++; out (6, "cycle: %lu ",count); gettimeofday (&tv, NULL); d_tim_ms = delta_time_ms (&tv, &last_tv); if (d_tim_ms <= 0) d_tim_ms = 1; // ignore usecs last_tv.tv_sec = tv.tv_sec; last_tv.tv_usec = tv.tv_usec; out (6, "d_time: %ld.%03ld s ", d_tim_ms / 1000UL, d_tim_ms % 1000UL); err = read_Signal (fd_fe, &s, &has); if (err == -1) return -1; // if (err == -2) { // out_nl (1," No signal..."); // continue; // } // & 0xFFFF necessary, due to interface transformations?? if (has.strength) out (1,"Sig: %u ", s.strength & 0xFFFFL); if (has.snr) out (2,"SNR: %u ", s.snr & 0xFFFFL); if (has.ber) out (3,"BER: %lu ",s.ber); if (has.ublocks) out (4,"UBLK: %ld ",s.ublocks); if (has.status) { out (4,"Stat: 0x%02x ",s.status); out_status_detail (5,s.status); } out_NL(1); if (opt->timeout_ms) usleep (opt->timeout_ms * 1000); if (d_tim_ms == 0) usleep (1000); // don't kill the system // count cycles? ? if (opt->rd_packet_count && (opt->rd_packet_count <= count)) break; } // while close(fd_fe); return 0; }
int ts_pidbandwidth (OPTION *opt) { u_char buf[TS_BUF_SIZE]; struct pollfd pfd; struct dmx_pes_filter_params flt; int dmxfd; struct timeval tv,last_tv, first_tv; int pid; unsigned long long b_total; long b; long packets_bad; long packets_total; struct { // simple struct for storing last average bandwidth unsigned long kb_sec; unsigned long b_sec; } last_avg; if (opt->ts_raw_mode) { pid = PID_FULL_TS; } else { pid = opt->pid; } indent (0); out_nl (2,""); out_nl (2,"---------------------------------------------------------"); out_nl (2,"PID bandwidth statistics..."); if (opt->ts_raw_mode) { out (2,"Full Transponder"); } else { out (2,"PID: %u (0x%04x)", pid, pid); } if (opt->rd_packet_count != 0) { out (2," - max packet count: %ld ", opt->rd_packet_count); } out_nl (2,""); out_nl (2,"---------------------------------------------------------"); // -- open DVR device for reading pfd.events = POLLIN | POLLPRI; if((pfd.fd = open(opt->devDvr,O_RDONLY|O_NONBLOCK)) < 0){ IO_error(opt->devDvr); return -1; } if ((dmxfd=open(opt->devDemux,O_RDWR)) < 0) { IO_error(opt->devDemux); close(pfd.fd); return -1; } ioctl (dmxfd,DMX_SET_BUFFER_SIZE, sizeof(buf)); flt.pid = pid; flt.input = DMX_IN_FRONTEND; flt.output = DMX_OUT_TS_TAP; flt.pes_type = DMX_PES_OTHER; flt.flags = DMX_IMMEDIATE_START; if (ioctl(dmxfd, DMX_SET_PES_FILTER, &flt) < 0) { IO_error("DMX_SET_PES_FILTER"); close(pfd.fd); close(dmxfd); return -1; } gettimeofday (&first_tv, NULL); last_tv.tv_sec = first_tv.tv_sec; last_tv.tv_usec = first_tv.tv_usec; b_total = 0; packets_total = 0; packets_bad = 0; while ( !isSigAbort() ) { int b_len, b_start; // -- we will poll the PID in 2 secs intervall int timeout = 2000; b_len = 0; b_start = 0; if (poll(&pfd, 1, timeout) > 0) { if (pfd.revents & POLLIN) { b_len = read(pfd.fd, buf, sizeof(buf)); gettimeofday (&tv, NULL); if (b_len >= TS_LEN) { b_start = sync_ts (buf, b_len); } else { b_len = 0; } b = b_len - b_start; if (b == 0) continue; if (b < 0) { IO_error("read"); continue; } b_total += b; // -- calc bandwidth { unsigned long long bit_s; long d_tim_ms; int packets; packets = b/TS_LEN; packets_total += packets; // output on different verbosity levels // -- current bandwidth d_tim_ms = delta_time_ms (&tv, &last_tv); if (d_tim_ms <= 0) d_tim_ms = 1; // ignore usecs out (3, "packets read: %3d/(%ld) d_time: %2ld.%03ld s = ", packets, packets_total, d_tim_ms / 1000UL, d_tim_ms % 1000UL); // -- current bandwidth in kbit/sec // --- cast to unsigned long long so it doesn't overflow as // --- early, add time / 2 before division for correct rounding bit_s = (((unsigned long long)b * 8000ULL) + ((unsigned long long)d_tim_ms / 2ULL)) / (unsigned long long)d_tim_ms; out (1, "%5llu.%03llu kbit/s", bit_s / 1000ULL, bit_s % 1000ULL); // -- average bandwidth d_tim_ms = delta_time_ms (&tv,&first_tv); if (d_tim_ms <= 0) d_tim_ms = 1; // ignore usecs bit_s = ((b_total * 8000ULL) + ((unsigned long long)d_tim_ms / 2ULL)) / (unsigned long long)d_tim_ms; last_avg.kb_sec = (unsigned long) (bit_s / 1000ULL); last_avg.b_sec = (unsigned long) (bit_s % 1000ULL); out (2, " (Avrg: %5lu.%03lu kbit/s)", last_avg.kb_sec, last_avg.b_sec); // -- bad packet(s) check in buffer { int bp; bp = ts_error_count (buf+b_start, b); packets_bad += bp; out (4, " [bad: %d]", bp); } out_NL (1); } last_tv.tv_sec = tv.tv_sec; last_tv.tv_usec = tv.tv_usec; // count packets ? if (opt->rd_packet_count > 0) { opt->rd_packet_count -= b/TS_LEN; if (opt->rd_packet_count <= 0) break; } } } } // -- packets stats out (4, "## "); if (opt->ts_raw_mode) { out (2,"PID: <ALL>"); } else { out (2,"PID: %u (0x%04x)", pid, pid); } out (4, " bad/total packets: %ld/%ld (= %1.1Lf%%)", packets_bad, packets_total, (((long double) packets_bad)*100)/packets_total ); out (4, " Avrg: %5lu.%03lu kbit/s", last_avg.kb_sec, last_avg.b_sec); out_NL(4); if (ioctl(dmxfd, DMX_STOP) < 0) { IO_error("DMX_STOP"); } close(dmxfd); close(pfd.fd); return 0; }