Update of /cvsroot/xine/xine-lib/src/post/visualizations
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv22404/visualizations

Modified Files:
        fftgraph.c fftscope.c fooviz.c oscope.c 
Log Message:
two fixes to viz glue code:
- avoid overrunning the provided input audio buffer.
- generate a bad frame if time is due but we don't have enough data
for updating the viz plugin. this could happen in some rare situations
but the result was pretty catastrophic: xine froze with 100% cpu usage.


Index: fftgraph.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/post/visualizations/fftgraph.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- fftgraph.c  27 Jan 2006 07:46:14 -0000      1.14
+++ fftgraph.c  2 Dec 2006 22:35:18 -0000       1.15
@@ -230,6 +230,7 @@
   this->lines_per_channel = FFTGRAPH_HEIGHT / this->channels;
   this->samples_per_frame = rate / FPS;
   this->data_idx = 0;
+  this->sample_counter = 0;
 
   this->vo_port->open(this->vo_port, XINE_ANON_STREAM);
   this->metronom->set_master(this->metronom, stream->metronom);
@@ -342,7 +343,7 @@
       data8 += samples_used * this->channels;
 
       /* scale 8 bit data to 16 bits and convert to signed as well */
-      for( i = 0; i < buf->num_frames && this->data_idx < NUMSAMPLES;
+      for( i = samples_used; i < buf->num_frames && this->data_idx < 
NUMSAMPLES;
            i++, this->data_idx++, data8 += this->channels ) {
         for( c = 0; c < this->channels; c++){
           this->wave[c][this->data_idx].re = (double)(data8[c] << 8) - 0x8000;
@@ -353,7 +354,7 @@
       data = buf->mem;
       data += samples_used * this->channels;
 
-      for( i = 0; i < buf->num_frames && this->data_idx < NUMSAMPLES;
+      for( i = samples_used; i < buf->num_frames && this->data_idx < 
NUMSAMPLES;
            i++, this->data_idx++, data += this->channels ) {
         for( c = 0; c < this->channels; c++){
           this->wave[c][this->data_idx].re = (double)data[c];
@@ -362,17 +363,24 @@
       }
     }
 
-    if( this->sample_counter >= this->samples_per_frame &&
-        this->data_idx == NUMSAMPLES ) {
+    if( this->sample_counter >= this->samples_per_frame ) {
 
-      this->data_idx = 0;
       samples_used += this->samples_per_frame;
 
       frame = this->vo_port->get_frame (this->vo_port, FFTGRAPH_WIDTH, 
FFTGRAPH_HEIGHT,
                                         this->ratio, XINE_IMGFMT_YUY2,
                                         VO_BOTH_FIELDS);
       frame->extra_info->invalid = 1;
-      frame->bad_frame = 0;
+      
+      /* frame is marked as bad if we don't have enough samples for 
+       * updating the viz plugin (calculations may be skipped).
+       * we must keep the framerate though. */
+      if( this->data_idx == NUMSAMPLES ) {
+        frame->bad_frame = 0;
+        this->data_idx = 0;
+      } else {
+        frame->bad_frame = 1;
+      }
       frame->duration = 90000 * this->samples_per_frame / port->rate;
       frame->pts = pts;
       this->metronom->got_video_frame(this->metronom, frame);

Index: fftscope.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/post/visualizations/fftscope.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- fftscope.c  27 Jan 2006 07:46:14 -0000      1.29
+++ fftscope.c  2 Dec 2006 22:35:18 -0000       1.30
@@ -289,6 +289,7 @@
     this->channels = MAXCHANNELS;
   this->samples_per_frame = rate / FPS;
   this->data_idx = 0;
+  this->sample_counter = 0;
   this->fft = fft_new(FFT_BITS);
 
   this->vo_port->open(this->vo_port, XINE_ANON_STREAM);
@@ -363,7 +364,7 @@
       data8 += samples_used * this->channels;
 
       /* scale 8 bit data to 16 bits and convert to signed as well */
-      for( i = 0; i < buf->num_frames && this->data_idx < NUMSAMPLES;
+      for( i = samples_used; i < buf->num_frames && this->data_idx < 
NUMSAMPLES;
            i++, this->data_idx++, data8 += this->channels ) {
         for( c = 0; c < this->channels; c++){
           this->wave[c][this->data_idx].re = (double)(data8[c] << 8) - 0x8000;
@@ -374,7 +375,7 @@
       data = buf->mem;
       data += samples_used * this->channels;
 
-      for( i = 0; i < buf->num_frames && this->data_idx < NUMSAMPLES;
+      for( i = samples_used; i < buf->num_frames && this->data_idx < 
NUMSAMPLES;
            i++, this->data_idx++, data += this->channels ) {
         for( c = 0; c < this->channels; c++){
           this->wave[c][this->data_idx].re = (double)data[c];
@@ -383,17 +384,24 @@
       }
     }
 
-    if( this->sample_counter >= this->samples_per_frame &&
-        this->data_idx == NUMSAMPLES ) {
+    if( this->sample_counter >= this->samples_per_frame ) {
 
-      this->data_idx = 0;
       samples_used += this->samples_per_frame;
 
       frame = this->vo_port->get_frame (this->vo_port, FFT_WIDTH, FFT_HEIGHT,
                                         this->ratio, XINE_IMGFMT_YUY2,
                                         VO_BOTH_FIELDS);
       frame->extra_info->invalid = 1;
-      frame->bad_frame = 0;
+      
+      /* frame is marked as bad if we don't have enough samples for 
+       * updating the viz plugin (calculations may be skipped).
+       * we must keep the framerate though. */
+      if( this->data_idx == NUMSAMPLES ) {
+        frame->bad_frame = 0;
+        this->data_idx = 0;
+      } else {
+        frame->bad_frame = 1;
+      }
       frame->duration = 90000 * this->samples_per_frame / port->rate;
       frame->pts = pts;
       this->metronom->got_video_frame(this->metronom, frame);

Index: fooviz.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/post/visualizations/fooviz.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- fooviz.c    10 Jul 2006 22:08:44 -0000      1.27
+++ fooviz.c    2 Dec 2006 22:35:18 -0000       1.28
@@ -118,6 +118,7 @@
   this->channels = _x_ao_mode2channels(mode);
   this->samples_per_frame = rate / FPS;
   this->data_idx = 0;
+  this->sample_counter = 0;
 
   this->vo_port->open(this->vo_port, XINE_ANON_STREAM);
   this->metronom->set_master(this->metronom, stream->metronom);
@@ -180,7 +181,7 @@
       data8 += samples_used * this->channels;
   
       /* scale 8 bit data to 16 bits and convert to signed as well */
-      for( i = 0; i < buf->num_frames && this->data_idx < NUMSAMPLES;
+      for( i = samples_used; i < buf->num_frames && this->data_idx < 
NUMSAMPLES;
            i++, this->data_idx++, data8 += this->channels ) {
         this->data[0][this->data_idx] = ((int16_t)data8[0] << 8) - 0x8000;
         this->data[1][this->data_idx] = ((int16_t)data8[j] << 8) - 0x8000;
@@ -189,24 +190,31 @@
       data = buf->mem;
       data += samples_used * this->channels;
   
-      for( i = 0; i < buf->num_frames && this->data_idx < NUMSAMPLES;
+      for( i = samples_used; i < buf->num_frames && this->data_idx < 
NUMSAMPLES;
            i++, this->data_idx++, data += this->channels ) {
         this->data[0][this->data_idx] = data[0];
         this->data[1][this->data_idx] = data[j];
       }
     }
   
-    if( this->sample_counter >= this->samples_per_frame &&
-        this->data_idx == NUMSAMPLES ) {
+    if( this->sample_counter >= this->samples_per_frame ) {
   
-      this->data_idx = 0;
       samples_used += this->samples_per_frame;
   
       frame = this->vo_port->get_frame (this->vo_port, FOO_WIDTH, FOO_HEIGHT,
                                         this->ratio, XINE_IMGFMT_YUY2,
                                         VO_BOTH_FIELDS);
       frame->extra_info->invalid = 1;
-      frame->bad_frame = 0;
+      
+      /* frame is marked as bad if we don't have enough samples for 
+       * updating the viz plugin (calculations may be skipped).
+       * we must keep the framerate though. */
+      if( this->data_idx == NUMSAMPLES ) {
+        frame->bad_frame = 0;
+        this->data_idx = 0;
+      } else {
+        frame->bad_frame = 1;
+      }
       frame->duration = 90000 * this->samples_per_frame / port->rate;
       frame->pts = pts;
       this->metronom->got_video_frame(this->metronom, frame);

Index: oscope.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/post/visualizations/oscope.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- oscope.c    27 Jan 2006 07:46:14 -0000      1.20
+++ oscope.c    2 Dec 2006 22:35:18 -0000       1.21
@@ -191,6 +191,7 @@
     this->channels = MAXCHANNELS;
   this->samples_per_frame = rate / FPS;
   this->data_idx = 0;
+  this->sample_counter = 0;
   init_yuv_planes(&this->yuv, OSCOPE_WIDTH, OSCOPE_HEIGHT);
 
   this->vo_port->open(this->vo_port, XINE_ANON_STREAM);
@@ -252,7 +253,7 @@
       data8 += samples_used * this->channels;
   
       /* scale 8 bit data to 16 bits and convert to signed as well */
-      for( i = 0; i < buf->num_frames && this->data_idx < NUMSAMPLES;
+      for( i = samples_used; i < buf->num_frames && this->data_idx < 
NUMSAMPLES;
            i++, this->data_idx++, data8 += this->channels )
         for( c = 0; c < this->channels; c++)
           this->data[c][this->data_idx] = ((int16_t)data8[c] << 8) - 0x8000;
@@ -260,23 +261,30 @@
       data = buf->mem;
       data += samples_used * this->channels;
   
-      for( i = 0; i < buf->num_frames && this->data_idx < NUMSAMPLES;
+      for( i = samples_used; i < buf->num_frames && this->data_idx < 
NUMSAMPLES;
            i++, this->data_idx++, data += this->channels )
         for( c = 0; c < this->channels; c++)
           this->data[c][this->data_idx] = data[c];
     }
   
-    if( this->sample_counter >= this->samples_per_frame &&
-        this->data_idx == NUMSAMPLES ) {
+    if( this->sample_counter >= this->samples_per_frame ) {
   
-      this->data_idx = 0;
       samples_used += this->samples_per_frame;
   
       frame = this->vo_port->get_frame (this->vo_port, OSCOPE_WIDTH, 
OSCOPE_HEIGHT,
                                         this->ratio, XINE_IMGFMT_YUY2,
                                         VO_BOTH_FIELDS);
       frame->extra_info->invalid = 1;
-      frame->bad_frame = 0;
+      
+      /* frame is marked as bad if we don't have enough samples for 
+       * updating the viz plugin (calculations may be skipped).
+       * we must keep the framerate though. */
+      if( this->data_idx == NUMSAMPLES ) {
+        frame->bad_frame = 0;
+        this->data_idx = 0;
+      } else {
+        frame->bad_frame = 1;
+      }
       frame->duration = 90000 * this->samples_per_frame / port->rate;
       frame->pts = pts;
       this->metronom->got_video_frame(this->metronom, frame);


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Xine-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xine-cvslog

Reply via email to