diff 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
line wrap: on
line diff
--- a/src/http.c	Sun Oct 03 21:55:37 2010 +0900
+++ b/src/http.c	Tue Oct 05 01:42:59 2010 +0900
@@ -609,9 +609,29 @@
     extern thread_data *gp_tdata;
     thread_data *tdata = gp_tdata;
     time_t cur_time;
+    struct timespec cur;
+    struct timespec diff;
+    clock_gettime(CLOCK_REALTIME, &cur);
+    off_t bitrate = 0;
+
+    if ( cur.tv_nsec < tdata->streamer->start.tv_nsec ) {
+        diff.tv_nsec = cur.tv_nsec - tdata->streamer->start.tv_nsec +1e9;
+        diff.tv_sec = cur.tv_sec - tdata->streamer->start.tv_sec -1;
+    } else {
+        diff.tv_nsec = cur.tv_nsec - tdata->streamer->start.tv_nsec;
+        diff.tv_sec = cur.tv_sec - tdata->streamer->start.tv_sec;
+    }
+
+    if ( diff.tv_sec < 1 ) {
+        bitrate = TS_BITRATE;
+    } else {
+        bitrate = (((off_t)tdata->streamer->total_byte)*1e9) /
+            ( (((off_t)diff.tv_sec)*1e9) + (diff.tv_sec/1e9));
+        bitrate = bitrate;
+    }
 
     time(&cur_time);
-    length = ((tdata->start_time+tdata->recsec) -cur_time) * (off_t)TS_BITRATE;
+    length = (tdata->start_time +tdata->recsec -cur_time) * bitrate;
     if ( length < 0 ) {
         length = 0;
     }