comparison src/http.c @ 127:5a380559a61e

modify calclate bitrate mechanism.
author Naoya OYAMA <naoya.oyama@gmail.com>
date Tue, 05 Oct 2010 01:42:59 +0900
parents 5dcaf3785ebe
children cc3e3f370aec
comparison
equal deleted inserted replaced
126:5dcaf3785ebe 127:5a380559a61e
607 { 607 {
608 off_t length = 0; 608 off_t length = 0;
609 extern thread_data *gp_tdata; 609 extern thread_data *gp_tdata;
610 thread_data *tdata = gp_tdata; 610 thread_data *tdata = gp_tdata;
611 time_t cur_time; 611 time_t cur_time;
612 struct timespec cur;
613 struct timespec diff;
614 clock_gettime(CLOCK_REALTIME, &cur);
615 off_t bitrate = 0;
616
617 if ( cur.tv_nsec < tdata->streamer->start.tv_nsec ) {
618 diff.tv_nsec = cur.tv_nsec - tdata->streamer->start.tv_nsec +1e9;
619 diff.tv_sec = cur.tv_sec - tdata->streamer->start.tv_sec -1;
620 } else {
621 diff.tv_nsec = cur.tv_nsec - tdata->streamer->start.tv_nsec;
622 diff.tv_sec = cur.tv_sec - tdata->streamer->start.tv_sec;
623 }
624
625 if ( diff.tv_sec < 1 ) {
626 bitrate = TS_BITRATE;
627 } else {
628 bitrate = (((off_t)tdata->streamer->total_byte)*1e9) /
629 ( (((off_t)diff.tv_sec)*1e9) + (diff.tv_sec/1e9));
630 bitrate = bitrate;
631 }
612 632
613 time(&cur_time); 633 time(&cur_time);
614 length = ((tdata->start_time+tdata->recsec) -cur_time) * (off_t)TS_BITRATE; 634 length = (tdata->start_time +tdata->recsec -cur_time) * bitrate;
615 if ( length < 0 ) { 635 if ( length < 0 ) {
616 length = 0; 636 length = 0;
617 } 637 }
618 length = length - (length % LENGTH_PACKET); 638 length = length - (length % LENGTH_PACKET);
619 return length; 639 return length;