changeset 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 3a7d8d2f0585
files src/http.c src/recpt1.c src/recpt1.h
diffstat 3 files changed, 26 insertions(+), 1 deletions(-) [+]
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;
     }
--- a/src/recpt1.c	Sun Oct 03 21:55:37 2010 +0900
+++ b/src/recpt1.c	Tue Oct 05 01:42:59 2010 +0900
@@ -671,6 +671,8 @@
     ARIB_STD_B25_BUFFER *qbuf = NULL;
     ARIB_STD_B25_BUFFER *buf;
     int i;
+    clock_gettime(CLOCK_REALTIME, &data->streamer->start);
+    data->streamer->total_byte = 0;
     //fprintf (stderr, "stream_func(): start.\n");
 
     while(1) {
@@ -684,6 +686,7 @@
             //fprintf (stderr, "stream_func(): dequeue() return NULL pointer. streaming abort.\n");
             continue;
         }
+        data->streamer->total_byte += qbuf->size;
         // $B%/%j%F%#%+%k%;%/%7%g%sD9$$$N$J$s$H$+$7$?$$$J$!!D(B
         // ToDo: memcpy $B$H$+%/%j%F%#%+%k%;%/%7%g%s$N30$K=P$9(B
         // 3.2 tdata->streamer->mutex $B$r(B lock
--- a/src/recpt1.h	Sun Oct 03 21:55:37 2010 +0900
+++ b/src/recpt1.h	Tue Oct 05 01:42:59 2010 +0900
@@ -74,6 +74,8 @@
 typedef struct _streamer {
     pthread_mutex_t mutex;   //open、close、(recpt1からの)write
     int stream_nr;
+    size_t total_byte; // 送信BYTE数
+    struct timespec start; // 開始時刻
     session *stream_session[STREAM_MAX]; //NULL止めの配列
 } streamer;