[xiph-cvs] cvs commit: vorbis-tools/ogg123 ogg123.c ogg123.h status.c

Stan Seibert volsung at xiph.org
Tue Dec 11 07:05:58 PST 2001



volsung     01/12/11 07:05:57

  Modified:    ogg123   Tag: volsung_kc_20011011 ogg123.c ogg123.h status.c
  Log:
  - Streamlined status updates by printing the entire line to the screen at
  once (including the characters used to erase the line).
  
  - Status updates now occur at a controllable frequency.  Updates should
  also be visible even when prebuffering.

Revision  Changes    Path
No                   revision

No                   revision

1.39.2.30.2.15 +36 -12    vorbis-tools/ogg123/ogg123.c

Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.39.2.30.2.14
retrieving revision 1.39.2.30.2.15
diff -u -r1.39.2.30.2.14 -r1.39.2.30.2.15
--- ogg123.c	2001/12/11 05:29:08	1.39.2.30.2.14
+++ ogg123.c	2001/12/11 15:05:56	1.39.2.30.2.15
@@ -14,7 +14,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.c,v 1.39.2.30.2.14 2001/12/11 05:29:08 volsung Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.30.2.15 2001/12/11 15:05:56 volsung Exp $
 
  ********************************************************************/
 
@@ -93,7 +93,8 @@
   switch (signo) {
   case SIGALRM:
     sig_request.ticks++;
-    alarm(1);
+    if (sig_request.ticks < options.delay)
+      alarm(1);
     break;
 
   case SIGINT:
@@ -142,6 +143,8 @@
   opts->prebuffer = 0.0f;
   opts->default_device = NULL;
   opts->devices = NULL;
+
+  opts->status_freq = 4;
 }
 
 /* ----------------------------- callbacks ------------------------------ */
@@ -251,7 +254,8 @@
   decoder_callbacks_t decoder_callbacks = { &decoder_error_callback,
                                             &decoder_metadata_callback };
   print_statistics_arg_t *pstats_arg;
-  
+  buffer_stats_t *buffer_stats;
+
   /* Preserve between calls so we only open the audio device when we 
      have to */
   static audio_format_t old_audio_fmt = { 0, 0, 0, 0, 0 };
@@ -260,7 +264,8 @@
 
   int eof = 0, eos = 0, ret;
   int nthc = 0, ntimesc = 0;
-  ogg_int64_t last_stats_tick = 0;
+  int next_status = 0;
+  int status_interval = 0;
 
   new_audio_fmt.big_endian = ao_is_big_endian();
   new_audio_fmt.signed_sample = 1;
@@ -347,7 +352,13 @@
       
       /* Check to see if the audio format has changed */
       if (!audio_format_equal(&new_audio_fmt, &old_audio_fmt)) {
-	audio_format_copy(&old_audio_fmt, &new_audio_fmt);
+	old_audio_fmt = new_audio_fmt;
+	
+	/* Update our status printing interval */
+	status_interval = new_audio_fmt.word_size * new_audio_fmt.channels * 
+	  new_audio_fmt.rate / options.status_freq;
+	next_status = 0;
+
         reopen_arg = new_audio_reopen_arg(options.devices, &new_audio_fmt);
 
         if (audio_buffer)	  
@@ -359,20 +370,33 @@
       
 
       /* Update statistics display if needed */
-      if (last_stats_tick < sig_request.ticks) {
-	last_stats_tick = sig_request.ticks;
-
+      if (next_status <= 0) {
+	
         pstats_arg = new_print_statistics_arg(stat_format,
                                               transport->statistics(source),
                                               format->statistics(decoder));
-	if (audio_buffer)
+	if (audio_buffer) {
+	  /* Place a status update into the buffer */
           buffer_append_action_at_end(audio_buffer,
                                       &print_statistics_callback,
                                       pstats_arg);
-	else
+
+	  /* And if we are not playing right now, do an immediate
+	     update just the output buffer */
+	  buffer_stats = buffer_statistics(audio_buffer);
+	  if (buffer_stats->paused || buffer_stats->prebuffering) {
+	    pstats_arg = new_print_statistics_arg(stat_format,
+						  NULL,
+						  NULL);
+	    print_statistics_callback(audio_buffer, pstats_arg);
+	  }
+
+	} else
           print_statistics_callback(NULL, pstats_arg);
-				      
-      }
+	
+	next_status = status_interval;
+      } else
+	next_status -= ret;
 
       /* Write audio data block to output, skipping or repeating chunks
          as needed */

1.7.2.12.2.6 +3 -2      vorbis-tools/ogg123/ogg123.h

Index: ogg123.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.h,v
retrieving revision 1.7.2.12.2.5
retrieving revision 1.7.2.12.2.6
diff -u -r1.7.2.12.2.5 -r1.7.2.12.2.6
--- ogg123.h	2001/12/08 23:59:25	1.7.2.12.2.5
+++ ogg123.h	2001/12/11 15:05:56	1.7.2.12.2.6
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.h,v 1.7.2.12.2.5 2001/12/08 23:59:25 volsung Exp $
+ last mod: $Id: ogg123.h,v 1.7.2.12.2.6 2001/12/11 15:05:56 volsung Exp $
 
  ********************************************************************/
 
@@ -54,7 +54,8 @@
   float prebuffer;            /* Percent of buffer to fill before playing */
   char *default_device;       /* Name of default driver to use */
   audio_device_t *devices;    /* Audio devices to playback to */
-  
+
+  double status_freq;         /* Number of status updates per second */
 } ogg123_options_t;
 
 typedef struct signal_request_t {

1.1.2.7.2.5 +44 -22    vorbis-tools/ogg123/Attic/status.c

Index: status.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/status.c,v
retrieving revision 1.1.2.7.2.4
retrieving revision 1.1.2.7.2.5
diff -u -r1.1.2.7.2.4 -r1.1.2.7.2.5
--- status.c	2001/12/11 05:29:08	1.1.2.7.2.4
+++ status.c	2001/12/11 15:05:56	1.1.2.7.2.5
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: status.c,v 1.1.2.7.2.4 2001/12/11 05:29:08 volsung Exp $
+ last mod: $Id: status.c,v 1.1.2.7.2.5 2001/12/11 15:05:56 volsung Exp $
 
  ********************************************************************/
 
@@ -22,7 +22,7 @@
 #include "buffer.h"
 #include "status.h"
 
-
+char temp_buffer[200];
 int last_line_len = 0;
 int max_verbosity = 0;
 
@@ -100,12 +100,8 @@
 #endif
 
 
-void clear_line ()
+void clear_line (int len)
 {
-  int len;
-
-  len = last_line_len;
-
   fputc('\r', stderr);
 
   while (len > 0) {
@@ -117,12 +113,38 @@
 }
 
 
+int sprintf_clear_line(int len, char *buf)
+{
+  int i = 0;
+
+  buf[i] = '\r';
+  i++;
+
+  while (len > 0) {
+    buf[i] = ' ';
+    len--;
+    i++;
+  }
+
+  buf[i] = '\r';
+  i++;
+
+  /* Null terminate just in case */
+  buf[i] = '\0';
+
+  return i;
+}
+
 int print_statistics_line (stat_format_t stats[])
 {
   int len = 0;
-  
-  clear_line(last_line_len);
-  
+  char *str = temp_buffer;
+
+  /* Put the clear line text into the same string buffer so that the
+     line is cleared and redrawn all at once.  This reduces
+     flickering.  Don't count characters used to clear line in len */
+  str += sprintf_clear_line(last_line_len, str); 
+
   while (stats->formatstr != NULL) {
     
     if (stats->verbosity > max_verbosity || !stats->enabled) {
@@ -131,30 +153,32 @@
     }
 
     if (len != 0)
-      len += fprintf(stderr, " ");
+      len += sprintf(str+len, " ");
 
     switch (stats->type) {
     case stat_noarg:
-      len += fprintf(stderr, stats->formatstr);
+      len += sprintf(str+len, stats->formatstr);
       break;
     case stat_intarg:
-      len += fprintf(stderr, stats->formatstr, stats->arg.intarg);
+      len += sprintf(str+len, stats->formatstr, stats->arg.intarg);
       break;
     case stat_stringarg:
-      len += fprintf(stderr, stats->formatstr, stats->arg.stringarg);
+      len += sprintf(str+len, stats->formatstr, stats->arg.stringarg);
       break;
     case stat_floatarg:
-      len += fprintf(stderr, stats->formatstr, stats->arg.floatarg);
+      len += sprintf(str+len, stats->formatstr, stats->arg.floatarg);
       break;
     case stat_doublearg:
-      len += fprintf(stderr, stats->formatstr, stats->arg.doublearg);
+      len += sprintf(str+len, stats->formatstr, stats->arg.doublearg);
       break;
     }
 
     stats++;
   }
+
+  len += sprintf(str+len, "\r");
 
-  fprintf(stderr, "\r");
+  fprintf(stderr, "%s", temp_buffer);
 
   return len;
 }
@@ -211,8 +235,8 @@
     
   cur = stats + 2; /* remaining playback time (preformatted) */
   cur->verbosity = 1;
-  cur->enabled = 0;
-  cur->formatstr = "%s";
+  cur->enabled = 1;
+  cur->formatstr = "[%s]";
   cur->type = stat_stringarg;
   cur->arg.stringarg = calloc(TIME_STR_SIZE, sizeof(char));
 
@@ -224,7 +248,7 @@
 
   cur = stats + 3; /* total playback time (preformatted) */
   cur->verbosity = 1;
-  cur->enabled = 0;
+  cur->enabled = 1;
   cur->formatstr = "of %s";
   cur->type = stat_stringarg;
   cur->arg.stringarg = calloc(TIME_STR_SIZE, sizeof(char));
@@ -319,7 +343,7 @@
 {
   pthread_mutex_lock(&output_lock);
 
-  clear_line();
+  clear_line(last_line_len);
 
   pthread_mutex_unlock(&output_lock);
 }
@@ -377,8 +401,6 @@
       write_buffer_state_string(stats[9].arg.stringarg, audio_statistics);
     }
     
-    clear_line();
-
     last_line_len = print_statistics_line(stats);
 
     pthread_mutex_unlock(&output_lock);

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list