[xiph-cvs] cvs commit: vorbis-tools/ogg123 audio.c audio.h buffer.c buffer.h file_transport.c format.c format.h ogg123.c oggvorbis_format.c status.c status.h transport.c transport.h

Stan Seibert volsung at xiph.org
Mon Dec 10 21:29:12 PST 2001



volsung     01/12/10 21:29:11

  Modified:    ogg123   Tag: volsung_kc_20011011 audio.c audio.h buffer.c
                        buffer.h file_transport.c format.c format.h
                        ogg123.c oggvorbis_format.c status.c status.h
                        transport.c transport.h
  Log:
  Mostly working statistics code and status printing.  Printing is chunky,
  so I'll have to go back to the string buffer method Ken used.

Revision  Changes    Path
No                   revision

No                   revision

1.1.2.3   +4 -6      vorbis-tools/ogg123/Attic/audio.c

Index: audio.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/audio.c,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- audio.c	2001/12/09 03:45:26	1.1.2.2
+++ audio.c	2001/12/11 05:29:08	1.1.2.3
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: audio.c,v 1.1.2.2 2001/12/09 03:45:26 volsung Exp $
+ last mod: $Id: audio.c,v 1.1.2.3 2001/12/11 05:29:08 volsung Exp $
 
  ********************************************************************/
 
@@ -127,8 +127,6 @@
 
   ret = audio_devices_write(play_arg->devices, ptr, nbytes);
 
-  status_print_statistics(play_arg->stats);
-
   return ret ? nbytes : 0;
 }
 
@@ -157,9 +155,9 @@
   while (current != NULL) {
     ao_info *info = ao_driver_info(current->driver_id);
     
-    status_message(1, "\nDevice:   %s", info->name);
-    status_message(1, "Author:   %s", info->author);
-    status_message(1, "Comments: %s\n", info->comment);
+    status_message(2, "\nDevice:   %s", info->name);
+    status_message(2, "Author:   %s", info->author);
+    status_message(2, "Comments: %s\n", info->comment);
     
     if (current->filename == NULL)
       current->device = ao_open_live(current->driver_id, &format,

1.1.2.2   +2 -2      vorbis-tools/ogg123/Attic/audio.h

Index: audio.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/audio.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- audio.h	2001/12/08 23:59:24	1.1.2.1
+++ audio.h	2001/12/11 05:29:08	1.1.2.2
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
  
- last mod: $Id: audio.h,v 1.1.2.1 2001/12/08 23:59:24 volsung Exp $
+ last mod: $Id: audio.h,v 1.1.2.2 2001/12/11 05:29:08 volsung Exp $
  
 ********************************************************************/
 
@@ -39,7 +39,7 @@
 /* Structures used by callbacks */
 
 typedef struct audio_play_arg_t {
-  stat_t *stats;
+  stat_format_t *stat_format;
   audio_device_t *devices;
 } audio_play_arg_t;
 

1.7.2.23.2.7 +91 -9     vorbis-tools/ogg123/buffer.c

Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.7.2.23.2.6
retrieving revision 1.7.2.23.2.7
diff -u -r1.7.2.23.2.6 -r1.7.2.23.2.7
--- buffer.c	2001/12/08 23:59:24	1.7.2.23.2.6
+++ buffer.c	2001/12/11 05:29:08	1.7.2.23.2.7
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: buffer.c,v 1.7.2.23.2.6 2001/12/08 23:59:24 volsung Exp $
+ last mod: $Id: buffer.c,v 1.7.2.23.2.7 2001/12/11 05:29:08 volsung Exp $
 
  ********************************************************************/
 
@@ -121,9 +121,17 @@
 }
 
 
-void in_order_append_action (action_t **action_list, action_t *action)
+/* insert = 1:  Make this action the first action associated with this position
+   insert = 0:  Make this action the last action associated with this position
+*/
+#define INSERT 1
+#define APPEND 0
+void in_order_add_action (action_t **action_list, action_t *action, int insert)
 {
-  while (*action_list != NULL && (*action_list)->position <= action->position)
+  insert = insert > 0 ? 1 : 0;  /* Clamp in case caller messed up */
+
+  while (*action_list != NULL && 
+	 (*action_list)->position <= (action->position + insert))
     action_list = &((*action_list)->next);
 
   action->next = *action_list;
@@ -246,6 +254,8 @@
   
   pthread_cleanup_pop(1);
   DEBUG("exiting buffer_thread_func");
+
+  return 0;
 }
 
 
@@ -308,6 +318,21 @@
 }
 
 
+buffer_stats_t *malloc_buffer_stats ()
+{
+  buffer_stats_t *new_stats;
+
+  new_stats = malloc(sizeof(buffer_stats_t));
+
+  if (new_stats == NULL) {
+    fprintf(stderr, "Error: Could not allocate memory in malloc_buffer_stats()\n");
+    exit(1);
+  }
+
+  return new_stats;
+}
+
+
 /* ------------------ Begin public interface ------------------ */
 
 /* --- Buffer allocation --- */
@@ -542,8 +567,8 @@
 }
 
 
-void buffer_action_at_end (buf_t *buf, action_func_t action_func, 
-			   void *action_arg)
+void buffer_insert_action_at_end (buf_t *buf, action_func_t action_func, 
+				  void *action_arg)
 {
   action_t *action;
 
@@ -554,29 +579,64 @@
   /* Stick after the last item in the buffer */
   action->position = buf->position;
 
-  in_order_append_action(&buf->actions, action);
+  in_order_add_action(&buf->actions, action, INSERT);
 
   UNLOCK_MUTEX(buf->mutex);
 }
 
 
-void buffer_action_at (buf_t *buf, action_func_t action_func, 
-		       void *action_arg, ogg_int64_t position)
+void buffer_append_action_at_end (buf_t *buf, action_func_t action_func, 
+				  void *action_arg)
 {
   action_t *action;
 
   action = malloc_action(action_func, action_arg);
 
   LOCK_MUTEX(buf->mutex);
+
+  /* Stick after the last item in the buffer */
+  action->position = buf->position;
+
+  in_order_add_action(&buf->actions, action, APPEND);
+
+  UNLOCK_MUTEX(buf->mutex);
+}
+
+
+void buffer_insert_action_at (buf_t *buf, action_func_t action_func, 
+			      void *action_arg, ogg_int64_t position)
+{
+  action_t *action;
+
+  action = malloc_action(action_func, action_arg);
+
+  LOCK_MUTEX(buf->mutex);
   
   action->position = position;
 
-  in_order_append_action(&buf->actions, action);
+  in_order_add_action(&buf->actions, action, INSERT);
 
   UNLOCK_MUTEX(buf->mutex);  
 }
 
 
+void buffer_append_action_at (buf_t *buf, action_func_t action_func, 
+			      void *action_arg, ogg_int64_t position)
+{
+  action_t *action;
+
+  action = malloc_action(action_func, action_arg);
+
+  LOCK_MUTEX(buf->mutex);
+  
+  action->position = position;
+
+  in_order_add_action(&buf->actions, action, APPEND);
+
+  UNLOCK_MUTEX(buf->mutex);  
+}
+
+
 /* --- Buffer status functions --- */
 
 void buffer_wait_for_empty (buf_t *buf)
@@ -604,3 +664,25 @@
 {
   return buf->curfill;
 }
+
+
+buffer_stats_t *buffer_statistics (buf_t *buf)
+{
+  buffer_stats_t *stats;
+  
+  LOCK_MUTEX(buf->mutex);
+
+  stats = malloc_buffer_stats();
+
+  stats->size = buf->size;
+  stats->fill = (double) buf->curfill / (double) buf->size;
+  stats->prebuffering = buf->prebuffering;
+  stats->paused = buf->paused;
+  stats->eos = buf->eos;
+
+  UNLOCK_MUTEX(buf->mutex);
+
+  return stats;
+}
+
+    

1.2.2.16.2.5 +19 -5     vorbis-tools/ogg123/buffer.h

Index: buffer.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.h,v
retrieving revision 1.2.2.16.2.4
retrieving revision 1.2.2.16.2.5
diff -u -r1.2.2.16.2.4 -r1.2.2.16.2.5
--- buffer.h	2001/12/08 23:59:24	1.2.2.16.2.4
+++ buffer.h	2001/12/11 05:29:08	1.2.2.16.2.5
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
  
- last mod: $Id: buffer.h,v 1.2.2.16.2.4 2001/12/08 23:59:24 volsung Exp $
+ last mod: $Id: buffer.h,v 1.2.2.16.2.5 2001/12/11 05:29:08 volsung Exp $
  
 ********************************************************************/
 
@@ -81,6 +81,15 @@
 } action_t;
 
 
+typedef struct buffer_stats_t {
+  long size;
+  double fill;
+  int prebuffering;
+  int paused;
+  int eos;
+} buffer_stats_t;
+
+
 /* --- Buffer allocation --- */
 
 buf_t *buffer_create (long size, long prebuffer,
@@ -105,13 +114,18 @@
 /* --- Action buffering functions --- */
 void buffer_action_now (buf_t *buf, action_func_t action_func, 
                         void *action_arg);
-void buffer_action_at_end (buf_t *buf, action_func_t action_func, 
-			   void *action_arg);
-void buffer_action_at (buf_t *buf, action_func_t action_func, 
-		       void *action_arg, ogg_int64_t position);
+void buffer_insert_action_at_end (buf_t *buf, action_func_t action_func, 
+				  void *action_arg);
+void buffer_append_action_at_end (buf_t *buf, action_func_t action_func, 
+				  void *action_arg);
+void buffer_insert_action_at (buf_t *buf, action_func_t action_func, 
+			      void *action_arg, ogg_int64_t position);
+void buffer_append_action_at (buf_t *buf, action_func_t action_func, 
+			      void *action_arg, ogg_int64_t position);
 
 /* --- Buffer status functions --- */
 void buffer_wait_for_empty (buf_t *buf);
 long buffer_full (buf_t *buf);
+buffer_stats_t *buffer_statistics (buf_t *buf);
 
 #endif /* __BUFFER_H__ */

1.1.2.2   +22 -2     vorbis-tools/ogg123/Attic/file_transport.c

Index: file_transport.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/file_transport.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- file_transport.c	2001/12/08 23:59:25	1.1.2.1
+++ file_transport.c	2001/12/11 05:29:08	1.1.2.2
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: file_transport.c,v 1.1.2.1 2001/12/08 23:59:25 volsung Exp $
+ last mod: $Id: file_transport.c,v 1.1.2.2 2001/12/11 05:29:08 volsung Exp $
 
  ********************************************************************/
 
@@ -23,6 +23,7 @@
 
 typedef struct file_private_t {
   FILE *fp;
+  data_source_stats_t stats;
 } file_private_t;
 
 
@@ -47,6 +48,10 @@
     source->source_string = strdup(source_string);
     source->transport = &file_transport;
     source->private = private;
+    
+    private->stats.transfer_rate = 0;
+    private->stats.bytes_read = 0;
+    private->stats.input_buffer_used = 0;
   } else {
     fprintf(stderr, "Error: Out of memory.\n");
     exit(1);
@@ -92,8 +97,14 @@
 {
   file_private_t *private = source->private;
   FILE *fp = private->fp;
+  int bytes_read;
+
+  bytes_read = fread(ptr, size, nmemb, fp);
+
+  if (bytes_read > 0)
+    private->stats.bytes_read += bytes_read;
 
-  return fread(ptr, size, nmemb, fp);
+  return bytes_read;
 }
 
 
@@ -106,6 +117,14 @@
 }
 
 
+data_source_stats_t * file_statistics (data_source_t *source)
+{
+  file_private_t *private = source->private;
+
+  return malloc_data_source_stats(&private->stats);
+}
+
+
 long file_tell (data_source_t *source)
 {
   file_private_t *private = source->private;
@@ -135,6 +154,7 @@
   &file_peek,
   &file_read,
   &file_seek,
+  &file_statistics,
   &file_tell,
   &file_close
 };

1.1.2.2   +21 -2     vorbis-tools/ogg123/Attic/format.c

Index: format.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/format.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- format.c	2001/12/08 23:59:25	1.1.2.1
+++ format.c	2001/12/11 05:29:08	1.1.2.2
@@ -11,13 +11,15 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: format.c,v 1.1.2.1 2001/12/08 23:59:25 volsung Exp $
+ last mod: $Id: format.c,v 1.1.2.2 2001/12/11 05:29:08 volsung Exp $
 
  ********************************************************************/
 
+#include <stdio.h>
+#include <string.h>
+
 #include "transport.h"
 #include "format.h"
-#include "string.h"
 
 extern format_t oggvorbis_format;
 
@@ -65,3 +67,20 @@
   dest->rate          = source->rate;  
   dest->channels      = source->channels;
 }  
+
+
+decoder_stats_t *malloc_decoder_stats (decoder_stats_t *to_copy)
+{
+  decoder_stats_t *new_stats;
+
+  new_stats = malloc(sizeof(decoder_stats_t));
+
+  if (new_stats == NULL) {
+    fprintf(stderr, "Error: Could not allocate memory in malloc_decoder_stats()\n");
+    exit(1);
+  }
+
+  *new_stats = *to_copy;  /* Copy the data */
+
+  return new_stats;
+}

1.1.2.2   +13 -2     vorbis-tools/ogg123/Attic/format.h

Index: format.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/format.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- format.h	2001/12/08 23:59:25	1.1.2.1
+++ format.h	2001/12/11 05:29:08	1.1.2.2
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: format.h,v 1.1.2.1 2001/12/08 23:59:25 volsung Exp $
+ last mod: $Id: format.h,v 1.1.2.2 2001/12/11 05:29:08 volsung Exp $
 
  ********************************************************************/
 
@@ -30,6 +30,15 @@
 } audio_format_t;
 
 
+typedef struct decoder_stats_t {
+  double total_time;  /* seconds */
+  double current_time;   /* seconds */
+  long   instant_bitrate;
+  long   avg_bitrate;
+} decoder_stats_t;
+
+
+/* Severity constants */
 enum { ERROR, WARNING, INFO };
 
 typedef struct decoder_callbacks_t {
@@ -58,7 +67,7 @@
                        decoder_callbacks_t *callbacks, void *callback_arg);
   int (* read) (decoder_t *decoder, void *ptr, int nbytes, int *eos, 
                 audio_format_t *audio_fmt);
-  long (* instant_bitrate) (decoder_t *decoder);
+  decoder_stats_t* (* statistics) (decoder_t *decoder);
   void (* cleanup) (decoder_t *decoder);
 } format_t;
 
@@ -66,5 +75,7 @@
 format_t *select_format (data_source_t *source);
 int audio_format_equal (audio_format_t *a, audio_format_t *b);
 void audio_format_copy  (audio_format_t *source, audio_format_t *dest);
+
+decoder_stats_t *malloc_decoder_stats (decoder_stats_t *to_copy);
 
 #endif /* __FORMAT_H__ */

1.39.2.30.2.14 +27 -17    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.13
retrieving revision 1.39.2.30.2.14
diff -u -r1.39.2.30.2.13 -r1.39.2.30.2.14
--- ogg123.c	2001/12/09 03:45:26	1.39.2.30.2.13
+++ ogg123.c	2001/12/11 05:29:08	1.39.2.30.2.14
@@ -14,7 +14,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: ogg123.c,v 1.39.2.30.2.13 2001/12/09 03:45:26 volsung Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.30.2.14 2001/12/11 05:29:08 volsung Exp $
 
  ********************************************************************/
 
@@ -47,7 +47,7 @@
 int convsize = AUDIO_CHUNK_SIZE;
 
 ogg123_options_t options;
-stat_t *stats;
+stat_format_t *stat_format;
 buf_t *audio_buffer;
 
 audio_play_arg_t audio_play_arg;
@@ -174,7 +174,7 @@
   int optind;
 
   ao_initialize();
-  stats = stats_create();
+  stat_format = stat_format_create();
   options_init(&options);
   file_options_init(file_opts);
 
@@ -182,7 +182,7 @@
   optind = parse_cmdline_options(argc, argv, &options, file_opts);
 
   audio_play_arg.devices = options.devices;
-  audio_play_arg.stats = stats;
+  audio_play_arg.stat_format = stat_format;
 
 
   status_set_verbosity(options.verbosity);
@@ -250,6 +250,7 @@
   decoder_t *decoder;
   decoder_callbacks_t decoder_callbacks = { &decoder_error_callback,
                                             &decoder_metadata_callback };
+  print_statistics_arg_t *pstats_arg;
   
   /* Preserve between calls so we only open the audio device when we 
      have to */
@@ -258,9 +259,8 @@
   audio_reopen_arg_t *reopen_arg;
 
   int eof = 0, eos = 0, ret;
-  long bitrate;
-
   int nthc = 0, ntimesc = 0;
+  ogg_int64_t last_stats_tick = 0;
 
   new_audio_fmt.big_endian = ao_is_big_endian();
   new_audio_fmt.signed_sample = 1;
@@ -351,22 +351,37 @@
         reopen_arg = new_audio_reopen_arg(options.devices, &new_audio_fmt);
 
         if (audio_buffer)	  
-	  buffer_action_at_end(audio_buffer, &audio_reopen_callback,
-			       reopen_arg);
+	  buffer_insert_action_at_end(audio_buffer, &audio_reopen_callback,
+				      reopen_arg);
         else
           audio_reopen_callback(NULL, reopen_arg);
       }
       
 
+      /* Update statistics display if needed */
+      if (last_stats_tick < sig_request.ticks) {
+	last_stats_tick = sig_request.ticks;
+
+	pstats_arg = new_print_statistics_arg(stat_format,
+					      transport->statistics(source),
+					      format->statistics(decoder));
+	if (audio_buffer)
+	  buffer_append_action_at_end(audio_buffer,
+				      &print_statistics_callback,
+				      pstats_arg);
+	else
+	  print_statistics_callback(NULL, pstats_arg);
+				      
+      }
+
       /* Write audio data block to output, skipping or repeating chunks
          as needed */
       do {
         
         if (nthc-- == 0) {
-	  if (audio_buffer) {
+	  if (audio_buffer)
             buffer_submit_data(audio_buffer, convbuffer, ret);
-	    status_print_statistics(stats);
-	  } else
+	  else
             audio_play_callback(convbuffer, ret, eos, &audio_play_arg);
           
           nthc = options.nth - 1;
@@ -375,12 +390,7 @@
       } while (++ntimesc < options.ntimes);
 
       ntimesc = 0;
-      
-      /* Update bitrate display */
-      bitrate = format->instant_bitrate (decoder);
-      if (bitrate > 0)
-	stats[4].arg.doublearg = (double) bitrate  / 1000.0f;
-      
+            
     } /* End of data loop */
     
   

1.1.2.3   +27 -4     vorbis-tools/ogg123/Attic/oggvorbis_format.c

Index: oggvorbis_format.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/oggvorbis_format.c,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- oggvorbis_format.c	2001/12/09 03:45:26	1.1.2.2
+++ oggvorbis_format.c	2001/12/11 05:29:08	1.1.2.3
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: oggvorbis_format.c,v 1.1.2.2 2001/12/09 03:45:26 volsung Exp $
+ last mod: $Id: oggvorbis_format.c,v 1.1.2.3 2001/12/11 05:29:08 volsung Exp $
 
  ********************************************************************/
 
@@ -31,6 +31,8 @@
   int current_section;
 
   int bos; /* At beginning of logical bitstream */
+
+  decoder_stats_t stats;
 } ovf_private_t;
 
 /* Forward declarations */
@@ -95,6 +97,11 @@
 
     private->bos = 1;
     private->current_section = -1;
+
+    private->stats.total_time = 0.0;
+    private->stats.current_time = 0.0;
+    private->stats.instant_bitrate = 0;
+    private->stats.avg_bitrate = 0;
   } else {
     fprintf(stderr, "Error: Out of memory.\n");
     exit(1);
@@ -185,11 +192,27 @@
   return bytes_read;
 }
 
-long ovf_instant_bitrate (decoder_t *decoder)
+
+decoder_stats_t *ovf_statistics (decoder_t *decoder)
 {
   ovf_private_t *priv = decoder->private;
+  long instant_bitrate;
+  long avg_bitrate;
+
+  priv->stats.total_time = ov_time_total(&priv->vf, -1);
+  priv->stats.current_time = ov_time_tell(&priv->vf);
+
+  /* vorbisfile returns 0 when no bitrate change has occurred */
+  instant_bitrate = ov_bitrate_instant(&priv->vf);
+  if (instant_bitrate > 0)
+    priv->stats.instant_bitrate = instant_bitrate;
+
+  avg_bitrate = ov_bitrate(&priv->vf, priv->current_section);
+  /* Catch error case caused by non-seekable stream */
+  priv->stats.avg_bitrate = avg_bitrate > 0 ? avg_bitrate : 0;
+
 
-  return ov_bitrate_instant(&priv->vf);
+  return malloc_decoder_stats(&priv->stats);
 }
 
 
@@ -209,7 +232,7 @@
   &ovf_can_decode,
   &ovf_init,
   &ovf_read,
-  &ovf_instant_bitrate,
+  &ovf_statistics,
   &ovf_cleanup,
 };
 

1.1.2.7.2.4 +113 -35   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.3
retrieving revision 1.1.2.7.2.4
diff -u -r1.1.2.7.2.3 -r1.1.2.7.2.4
--- status.c	2001/12/09 03:45:26	1.1.2.7.2.3
+++ status.c	2001/12/11 05:29:08	1.1.2.7.2.4
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: status.c,v 1.1.2.7.2.3 2001/12/09 03:45:26 volsung Exp $
+ last mod: $Id: status.c,v 1.1.2.7.2.4 2001/12/11 05:29:08 volsung Exp $
 
  ********************************************************************/
 
@@ -31,33 +31,44 @@
 
 /* ------------------- Private functions ------------------ */
 
-void set_buffer_state_string (buf_t *buf, char *strbuf)
+void write_buffer_state_string (char *dest, buffer_stats_t *buf_stats)
 {
-  char *cur = strbuf;
+  char *cur = dest;
   char *comma = ", ";
   char *sep = "(";
 
-  if (buf->prebuffering) {
+  if (buf_stats->prebuffering) {
     cur += sprintf (cur, "%sPrebuf", sep);
     sep = comma;
   }
-  if (buf->paused) {
+  if (buf_stats->paused) {
     cur += sprintf (cur, "%sPaused", sep);
     sep = comma;
   }
-  if (buf->eos) {
+  if (buf_stats->eos) {
     cur += sprintf (cur, "%sEOS", sep);
     sep = comma;
   }
-  if (cur != strbuf)
+  if (cur != dest)
     cur += sprintf (cur, ")");
   else
     *cur = '\0';
 }
 
 
+/* Write a min:sec.msec style string to dest corresponding to time.
+   The time parameter is in seconds.  Returns the number of characters
+   written */
+int write_time_string (char *dest, double time)
+{
+  long min = (long) time / (long) 60;
+  double sec = time - 60.0f * min;
+
+  return sprintf (dest, "%02li:%05.2f", min, sec);
+}
+
 #if 0
-void SetTime (stat_t stats[], ogg_int64_t sample)
+void SetTime (stat_format_t stats[], ogg_int64_t sample)
 {
   double CurTime = (double) sample / (double) Options.outputOpts.rate;
   long c_min = (long) CurTime / (long) 60;
@@ -106,11 +117,11 @@
 }
 
 
-void print_statistics_line (stat_t stats[])
+int print_statistics_line (stat_format_t stats[])
 {
   int len = 0;
   
-  status_clear_line(last_line_len);
+  clear_line(last_line_len);
   
   while (stats->formatstr != NULL) {
     
@@ -142,8 +153,10 @@
 
     stats++;
   }
+
+  fprintf(stderr, "\r");
 
-  last_line_len = len;
+  return len;
 }
 
 
@@ -166,12 +179,12 @@
 #define STATE_STR_SIZE 25
 #define NUM_STATS 10
 
-stat_t *stats_create ()
+stat_format_t *stat_format_create ()
 {
-  stat_t *stats;
-  stat_t *cur;
+  stat_format_t *stats;
+  stat_format_t *cur;
 
-  stats = calloc(NUM_STATS + 1, sizeof(stat_t));  /* One extra for end flag */
+  stats = calloc(NUM_STATS + 1, sizeof(stat_format_t));  /* One extra for end flag */
   if (stats == NULL) {
     fprintf(stderr, "Memory allocation error in stats_init()\n");
     exit(1);
@@ -279,7 +292,7 @@
 }
 
 
-void stats_cleanup (stat_t *stats)
+void stat_format_cleanup (stat_format_t *stats)
 {
   free(stats[1].arg.stringarg);
   free(stats[2].arg.stringarg);
@@ -311,38 +324,63 @@
   pthread_mutex_unlock(&output_lock);
 }
 
-void status_print_statistics (stat_t *stats)
+void status_print_statistics (stat_format_t *stats,
+			      buffer_stats_t *audio_statistics,
+			      data_source_stats_t *transport_statistics,
+			      decoder_stats_t *decoder_statistics)
 {
 
   /* Updating statistics is not critical.  If another thread is
      already doing output, we skip it. */
   if (pthread_mutex_trylock(&output_lock) == 0) {
 
-#if 0
-    if () {
-      set_buffer_state_string(Options.inputOpts.data->buf,
-			      stats[7].arg.stringarg);
-      stats[6].arg.doublearg = 
-	(double) buffer_full(Options.inputOpts.data->buf)
-	/ (double) Options.inputOpts.data->buf->size * 100.0f;
+    if (decoder_statistics) {
+      /* Current playback time */
+      write_time_string(stats[1].arg.stringarg,
+			decoder_statistics->current_time);
+	
+      /* Remaining playback time */
+      write_time_string(stats[2].arg.stringarg,
+			decoder_statistics->total_time - 
+			decoder_statistics->current_time);
+      
+      /* Total playback time */
+      write_time_string(stats[3].arg.stringarg,
+			decoder_statistics->total_time);
+
+      /* Instantaneous bitrate */
+      stats[4].arg.doublearg = decoder_statistics->instant_bitrate / 1000.0f;
+
+      /* Instantaneous bitrate */
+      stats[5].arg.doublearg = decoder_statistics->avg_bitrate / 1000.0f;
     }
 
-    if (Options.outputOpts.buffer) {
-      set_buffer_state_string(Options.inputOpts.data->buf,
-			      stats[9].arg.stringarg);
+
+    if (transport_statistics != NULL && 
+	transport_statistics->input_buffer_used) {
       
-      stats[8].arg.doublearg =
-	(double) buffer_full(Options.outputOpts.buffer) 
-	/ (double) Options.outputOpts.buffer->size * 100.0f;
+      /* Input buffer fill % */
+      stats[6].arg.doublearg = transport_statistics->input_buffer.fill;
+
+      /* Input buffer state */
+      write_buffer_state_string(stats[7].arg.stringarg,
+				&transport_statistics->input_buffer);
     }
 
-    
-    print_statistics_line(stats);
-#endif
 
-    clear_line();
-    last_line_len = fprintf(stderr, "Boing!");
+    if (audio_statistics != NULL) {
+      
+      /* Output buffer fill % */
+      stats[8].arg.doublearg = audio_statistics->fill;
+      
+      /* Output buffer state */
+      write_buffer_state_string(stats[9].arg.stringarg, audio_statistics);
+    }
     
+    clear_line();
+
+    last_line_len = print_statistics_line(stats);
+
     pthread_mutex_unlock(&output_lock);
   }
 }
@@ -401,3 +439,43 @@
   pthread_mutex_unlock(&output_lock);
 }
 
+
+void print_statistics_callback (buf_t *buf, void *arg)
+{
+  print_statistics_arg_t *stats_arg = (print_statistics_arg_t *) arg;
+  buffer_stats_t *buffer_stats;
+
+  if (buf != NULL)
+    buffer_stats = buffer_statistics(buf);
+  else
+    buffer_stats = NULL;
+
+  status_print_statistics(stats_arg->stat_format,
+			  buffer_stats,
+			  stats_arg->transport_statistics,
+			  stats_arg->decoder_statistics);
+
+  free(stats_arg->transport_statistics);
+  free(stats_arg->decoder_statistics);
+  free(stats_arg);
+}
+
+
+print_statistics_arg_t *new_print_statistics_arg (
+			       stat_format_t *stat_format,
+			       data_source_stats_t *transport_statistics,
+			       decoder_stats_t *decoder_statistics)
+{
+  print_statistics_arg_t *arg;
+
+  if ( (arg = malloc(sizeof(print_statistics_arg_t))) == NULL ) {
+    status_error("Error: Out of memory in new_print_statistics_arg().\n");
+    exit(1);
+  }  
+  
+  arg->stat_format = stat_format;
+  arg->transport_statistics = transport_statistics;
+  arg->decoder_statistics = decoder_statistics;
+
+  return arg;
+}

1.1.2.4.2.4 +25 -8     vorbis-tools/ogg123/Attic/status.h

Index: status.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/status.h,v
retrieving revision 1.1.2.4.2.3
retrieving revision 1.1.2.4.2.4
diff -u -r1.1.2.4.2.3 -r1.1.2.4.2.4
--- status.h	2001/12/09 03:45:26	1.1.2.4.2.3
+++ status.h	2001/12/11 05:29:09	1.1.2.4.2.4
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: status.h,v 1.1.2.4.2.3 2001/12/09 03:45:26 volsung Exp $
+ last mod: $Id: status.h,v 1.1.2.4.2.4 2001/12/11 05:29:09 volsung Exp $
 
  ********************************************************************/
 
@@ -19,6 +19,9 @@
 #define __STATUS_H__
 
 #include <stdarg.h>
+#include "buffer.h"
+#include "transport.h"
+#include "format.h"
 
 typedef struct {
   int verbosity;
@@ -37,9 +40,16 @@
     float floatarg;
     double doublearg;
   } arg;
-} stat_t;
+} stat_format_t;
 
 
+typedef struct print_statistics_arg_t {
+  stat_format_t *stat_format;
+  data_source_stats_t *transport_statistics;
+  decoder_stats_t *decoder_statistics;
+} print_statistics_arg_t;
+
+
 /* Status options:
  * stats[0] - currently playing file / stream
  * stats[1] - current playback time
@@ -48,22 +58,29 @@
  * stats[4] - instantaneous bitrate
  * stats[5] - average bitrate (not yet implemented)
  * stats[6] - input buffer fill %
- * stats[7] - input buffer status
+ * stats[7] - input buffer state
  * stats[8] - output buffer fill %
- * stats[9] - output buffer status
+ * stats[9] - output buffer state
  * stats[10] - Null format string to mark end of array
  */
-
-stat_t *stats_create ();
-void stats_cleanup (stat_t *stats);
+stat_format_t *stat_format_create ();
+void stat_format_cleanup (stat_format_t *stats);
 
 void status_set_verbosity (int verbosity);
 void status_reset_output_lock ();
 void status_clear_line ();
-void status_print_statistics (stat_t *stats);
+void status_print_statistics (stat_format_t *stats,
+			      buffer_stats_t *audio_statistics,
+			      data_source_stats_t *transport_statistics,
+			      decoder_stats_t *decoder_statistics);
 void status_message (int verbosity, const char *fmt, ...);
 void vstatus_message (int verbosity, const char *fmt, va_list ap);
 void status_error (const char *fmt, ...);
 void vstatus_error (const char *fmt, va_list);
 
+void print_statistics_callback (buf_t *buf, void *arg);
+print_statistics_arg_t *new_print_statistics_arg (
+			       stat_format_t *stat_format,
+			       data_source_stats_t *transport_statistics,
+			       decoder_stats_t *decoder_statistics);
 #endif /* __STATUS_H__ */

1.1.2.2   +20 -2     vorbis-tools/ogg123/Attic/transport.c

Index: transport.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/transport.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- transport.c	2001/12/08 23:59:25	1.1.2.1
+++ transport.c	2001/12/11 05:29:09	1.1.2.2
@@ -11,12 +11,14 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: transport.c,v 1.1.2.1 2001/12/08 23:59:25 volsung Exp $
+ last mod: $Id: transport.c,v 1.1.2.2 2001/12/11 05:29:09 volsung Exp $
 
  ********************************************************************/
 
+#include <stdio.h>
+#include <string.h>
+
 #include "transport.h"
-#include "string.h"
 
 extern transport_t file_transport;
 
@@ -44,3 +46,19 @@
   return transports[i];
 }
 
+
+data_source_stats_t *malloc_data_source_stats (data_source_stats_t *to_copy)
+{
+  data_source_stats_t *new_stats;
+
+  new_stats = malloc(sizeof(data_source_stats_t));
+
+  if (new_stats == NULL) {
+    fprintf(stderr, "Error: Could not allocate memory in malloc_data_source_stats()\n");
+    exit(1);
+  }
+
+  *new_stats = *to_copy;  /* Copy the data */
+
+  return new_stats;
+}

1.1.2.2   +17 -1     vorbis-tools/ogg123/Attic/transport.h

Index: transport.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/Attic/transport.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- transport.h	2001/12/08 23:59:25	1.1.2.1
+++ transport.h	2001/12/11 05:29:09	1.1.2.2
@@ -11,7 +11,7 @@
  *                                                                  *
  ********************************************************************
 
- last mod: $Id: transport.h,v 1.1.2.1 2001/12/08 23:59:25 volsung Exp $
+ last mod: $Id: transport.h,v 1.1.2.2 2001/12/11 05:29:09 volsung Exp $
 
  ********************************************************************/
 
@@ -20,7 +20,20 @@
 
 #include <sys/types.h>
 #include <unistd.h>
+#include "ogg/os_types.h"
+#include "buffer.h"
 
+
+typedef struct data_source_stats_t {
+  ogg_int64_t bytes_read;
+  int input_buffer_used;  /* flag to show if this data_source uses an
+                             input buffer.  Ignore the contents of
+                             input_buffer and transfer rate if it is
+                             false. */
+  long transfer_rate;
+  buffer_stats_t input_buffer;
+} data_source_stats_t;
+
 struct transport_t;
 
 typedef struct data_source_t {
@@ -36,11 +49,14 @@
   int (* peek) (data_source_t *source, void *ptr, size_t size, size_t nmemb);
   int (* read) (data_source_t *source, void *ptr, size_t size, size_t nmemb);
   int (* seek) (data_source_t *source, long offset, int whence);
+  data_source_stats_t * (* statistics) (data_source_t *source);
   long (* tell) (data_source_t *source);
   void (* close) (data_source_t *source);
 } transport_t;
 
 transport_t *get_transport_by_name (char *name);
 transport_t *select_transport (char *source);
+
+data_source_stats_t *malloc_data_source_stats (data_source_stats_t *to_copy);
 
 #endif /* __TRANSPORT_H__ */

--- >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