]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
timeshift: include support for total buffer size.
authorAdam Sutton <dev@adamsutton.me.uk>
Mon, 14 Jan 2013 22:37:57 +0000 (22:37 +0000)
committerAdam Sutton <dev@adamsutton.me.uk>
Mon, 14 Jan 2013 22:37:57 +0000 (22:37 +0000)
docs/html/config_timeshift.html
src/timeshift.h
src/timeshift/timeshift_filemgr.c
src/timeshift/timeshift_writer.c
src/webui/static/app/timeshift.js

index 3265118baec7db462ed20ce544f7030b89a8e1ac..bf1e6052c8b927676ac301a8901a7e4d6e52806d 100644 (file)
@@ -29,7 +29,6 @@
   <dd>If checked, this allows the timeshift buffer to grow unbounded until
       your storage media runs out of space (WARNING: this could be dangerous!).
 
-  <!--
   <dt>Max. Size (MegaBytes)
   <dd>Specifies the maximum combined size of all timeshift buffers. If you
       specify an unlimited period its highly recommended you specifying a value
@@ -39,7 +38,6 @@
   <dd>If checked, this allows the combined size of all timeshift buffers to
       potentially grow unbounded until your storage media runs out of space
       (WARNING: this could be dangerous!).
-  -->
 
  </dl>
  Changes to any of these settings must be confirmed by pressing the
index 5281e8b5582dda9925476d97325ed337ec81bb49..342c7c6638541faa55798929ab66bed2a6e781ae 100644 (file)
@@ -27,6 +27,9 @@ extern uint32_t  timeshift_max_period;
 extern int       timeshift_unlimited_size;
 extern size_t    timeshift_max_size;
 
+extern size_t          timeshift_total_size;
+extern pthread_mutex_t timeshift_size_lock;
+
 void timeshift_init ( void );
 void timeshift_term ( void );
 void timeshift_save ( void );
index 2e2661bd318633ecc8a30b2bda250a1810b72732..fc097bc4fa759058486d8a2ed96353aef37bc929 100644 (file)
@@ -38,6 +38,9 @@ static pthread_t             timeshift_reaper_thread;
 static pthread_mutex_t       timeshift_reaper_lock;
 static pthread_cond_t        timeshift_reaper_cond;
 
+pthread_mutex_t              timeshift_size_lock;
+size_t                       timeshift_total_size;
+
 /* **************************************************************************
  * File reaper thread
  * *************************************************************************/
@@ -72,6 +75,10 @@ static void* timeshift_reaper_callback ( void *p )
       if (errno != ENOTEMPTY)
         tvhlog(LOG_ERR, "timeshift", "failed to remove %s [e=%s]",
                dpath, strerror(errno));
+    pthread_mutex_lock(&timeshift_size_lock);
+    assert(tsf->size >= timeshift_total_size);
+    timeshift_total_size -= tsf->size;
+    pthread_mutex_unlock(&timeshift_size_lock);
 
     /* Free memory */
     while ((ti = TAILQ_FIRST(&tsf->iframes))) {
@@ -218,8 +225,13 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create )
     }
 
     /* Check size */
-    // TODO: need to implement this
-
+    pthread_mutex_lock(&timeshift_size_lock);
+    if (!timeshift_unlimited_size && timeshift_total_size >= timeshift_max_size) {
+      tvhlog(LOG_DEBUG, "timshift", "ts %d buffer full", ts->id);
+      ts->full = 1;
+    }
+    pthread_mutex_unlock(&timeshift_size_lock);
+      
     /* Create new file */
     tsf_tmp = NULL;
     if (!ts->full) {
@@ -304,6 +316,10 @@ void timeshift_filemgr_init ( void )
   timeshift_filemgr_get_root(path, sizeof(path));
   rmtree(path);
 
+  /* Size processing */
+  timeshift_total_size = 0;
+  pthread_mutex_init(&timeshift_size_lock, NULL);
+
   /* Start the reaper thread */
   timeshift_reaper_run = 1;
   pthread_mutex_init(&timeshift_reaper_lock, NULL);
index 0fb3129f8a7799fb2814b801951d31abf632df19..8bf6be03e6a30288d0caa08703ecc0bea428d876 100644 (file)
@@ -224,6 +224,9 @@ static inline ssize_t _process_msg0
   if (err > 0) {
     tsf->last  = sm->sm_time;
     tsf->size += err;
+    pthread_mutex_lock(&timeshift_size_lock);
+    timeshift_total_size += err;
+    pthread_mutex_unlock(&timeshift_size_lock);
   }
   return err;
 }
index 059aae78b44f16f5b4f985ca94736f90815299e6..02335006044fe80ba57a0a87c28a8ed38fa24906 100644 (file)
@@ -56,15 +56,13 @@ tvheadend.timeshift = function() {
     fieldLabel: 'Max. Size (MB)',
     name: 'timeshift_max_size',
     allowBlank: false,
-    width: 300,
-    hidden : true
+    width: 300
   });
 
   var timeshiftUnlSize = new Ext.form.Checkbox({
     fieldLabel: '&nbsp;&nbsp;&nbsp;(unlimited)',
     name: 'timeshift_unlimited_size',
-    Width: 300,
-    hidden : true
+    Width: 300
   });
 
   /* ****************************************************************