From e4f25307b11599e0495aa4743123984287be3650 Mon Sep 17 00:00:00 2001 From: Michael Roitzsch Date: Sun, 16 Nov 2003 12:18:59 +0000 Subject: audio visualization post plugins now use a private metronom to sync their video CVS patchset: 5743 CVS date: 2003/11/16 12:18:59 --- src/post/goom/xine_goom.c | 53 +++++++++++++------------------------- src/post/visualizations/fftgraph.c | 49 ++++++++++++++++++++++------------- src/post/visualizations/fftscope.c | 51 ++++++++++++++++++++++-------------- src/post/visualizations/fooviz.c | 49 ++++++++++++++++++++++------------- src/post/visualizations/oscope.c | 51 ++++++++++++++++++++++-------------- 5 files changed, 144 insertions(+), 109 deletions(-) diff --git a/src/post/goom/xine_goom.c b/src/post/goom/xine_goom.c index 184f7665f..a1b99afa1 100644 --- a/src/post/goom/xine_goom.c +++ b/src/post/goom/xine_goom.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_goom.c,v 1.40 2003/11/11 18:44:58 f1rmb Exp $ + * $Id: xine_goom.c,v 1.41 2003/11/16 12:18:59 mroi Exp $ * * GOOM post plugin. * @@ -47,9 +47,6 @@ #define GOOM_WIDTH 320 #define GOOM_HEIGHT 240 -/* skip frames if there is less than LOW_MARK pts in the audio_out fifo */ -#define LOW_MARK 90000 / 5 - /* colorspace conversion methods */ const char * goom_csc_methods[]={ "Fast but not photorealistic", @@ -75,7 +72,10 @@ struct post_plugin_goom_s { xine_video_port_t *vo_port; xine_stream_t *stream; - post_class_goom_t *class; + post_class_goom_t *class; + + /* private metronom for syncing the video */ + metronom_t *metronom; int data_idx; gint16 data [2][512]; @@ -258,6 +258,8 @@ static post_plugin_t *goom_open_plugin(post_class_t *class_gen, int inputs, */ this->class = class; class->ip = this; + + this->metronom = _x_metronom_init(0, class->xine); lprintf("goom: goom_open_plugin\n"); @@ -359,6 +361,8 @@ static void goom_dispose(post_plugin_t *this_gen) this->class->ip = NULL; goom_close(); + + this->metronom->exit(this->metronom); if (this->stream) port->close(port, this->stream); @@ -444,6 +448,8 @@ static int goom_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream, this->data_idx = 0; init_yuv_planes(&this->yuv, this->width, this->height); this->skip_frame = 0; + + this->metronom->set_master(this->metronom, stream->metronom); return port->original_port->open(port->original_port, stream, bits, rate, mode ); } @@ -456,6 +462,8 @@ static void goom_port_close(xine_audio_port_t *port_gen, xine_stream_t *stream ) free_yuv_planes(&this->yuv); this->stream = NULL; + + this->metronom->set_master(this->metronom, NULL); port->original_port->close(port->original_port, stream ); } @@ -472,7 +480,6 @@ static void goom_port_put_buffer (xine_audio_port_t *port_gen, int8_t *data8; int samples_used = 0; int64_t pts = buf->vpts; - int64_t vpts = 0; int i, j; uint8_t *dest_ptr; int width, height; @@ -533,36 +540,11 @@ static void goom_port_put_buffer (xine_audio_port_t *port_gen, frame->extra_info->invalid = 1; frame->bad_frame = 0; frame->duration = 90000 * this->samples_per_frame / this->sample_rate; - if (!vpts) { - vpts = this->stream->metronom->audio_vpts; - frame->pts = pts; - frame->vpts = vpts; - pts = 0; - vpts += frame->duration; - } else { - frame->pts = 0; - frame->vpts = vpts; - vpts += frame->duration; - } + frame->pts = pts; + this->metronom->got_video_frame(this->metronom, frame); + this->sample_counter -= this->samples_per_frame; - /* skip frames if there is less than LOW_MARK in audio output fifo */ - { - metronom_t *metronom = this->stream->metronom; - int64_t cur_vpts, diff; - cur_vpts = metronom->clock->get_current_time(metronom->clock); - pthread_mutex_lock(&metronom->lock); - diff = metronom->audio_vpts - cur_vpts; - pthread_mutex_unlock(&metronom->lock); - if (diff < LOW_MARK) { - lprintf("skip frame: diff = %lld, spf=%d, nf=%d, sr=%d\n", - diff, this->samples_per_frame, buf->num_frames, this->sample_rate); - this->skip_frame = 1; - } else { - this->skip_frame = 0; - } - } - if (!this->skip_frame) { /* Try to be fast */ goom_frame = (uint8_t *)goom_update (this->data, 0, 0, NULL, NULL); @@ -624,10 +606,11 @@ static void goom_port_put_buffer (xine_audio_port_t *port_gen, } } - frame->draw(frame, NULL); + this->skip_frame = frame->draw(frame, NULL); } else { frame->bad_frame = 1; frame->draw(frame, NULL); + this->skip_frame--; } frame->free(frame); diff --git a/src/post/visualizations/fftgraph.c b/src/post/visualizations/fftgraph.c index 3d3089642..11cd0c180 100644 --- a/src/post/visualizations/fftgraph.c +++ b/src/post/visualizations/fftgraph.c @@ -20,7 +20,7 @@ * FftGraph Visualization Post Plugin For xine * by Thibaut Mattern (tmattern@noos.fr) * - * $Id: fftgraph.c,v 1.4 2003/11/11 18:44:59 f1rmb Exp $ + * $Id: fftgraph.c,v 1.5 2003/11/16 12:18:59 mroi Exp $ * */ @@ -48,6 +48,14 @@ typedef struct post_plugin_fftgraph_s post_plugin_fftgraph_t; +typedef struct post_class_fftgraph_s post_class_fftgraph_t; + +struct post_class_fftgraph_s { + post_class_t post_class; + + xine_t *xine; +}; + struct post_plugin_fftgraph_s { post_plugin_t post; @@ -55,6 +63,9 @@ struct post_plugin_fftgraph_s { xine_video_port_t *vo_port; xine_stream_t *stream; + /* private metronom for syncing the video */ + metronom_t *metronom; + double ratio; int data_idx; @@ -262,6 +273,8 @@ static int fftgraph_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream this->stream = stream; this->data_idx = 0; + this->metronom->set_master(this->metronom, stream->metronom); + this->fft = fft_new(FFT_BITS); this->cur_line = 0; @@ -323,6 +336,8 @@ static void fftgraph_port_close(xine_audio_port_t *port_gen, xine_stream_t *stre fft_dispose(this->fft); this->fft = NULL; + this->metronom->set_master(this->metronom, NULL); + port->original_port->close(port->original_port, stream ); } @@ -336,7 +351,6 @@ static void fftgraph_port_put_buffer (xine_audio_port_t *port_gen, int8_t *data8; int samples_used = 0; int64_t pts = buf->vpts; - int64_t vpts = 0; int i, c; /* make a copy of buf data for private use */ @@ -397,17 +411,9 @@ static void fftgraph_port_put_buffer (xine_audio_port_t *port_gen, frame->extra_info->invalid = 1; frame->bad_frame = 0; frame->duration = 90000 * this->samples_per_frame / this->sample_rate; - if (!vpts) { - vpts = this->stream->metronom->audio_vpts; - frame->pts = pts; - frame->vpts = vpts; - pts = 0; - vpts += frame->duration; - } else { - frame->pts = 0; - frame->vpts = vpts; - vpts += frame->duration; - } + frame->pts = pts; + this->metronom->got_video_frame(this->metronom, frame); + this->sample_counter -= this->samples_per_frame; draw_fftgraph(this, frame); @@ -424,6 +430,8 @@ static void fftgraph_dispose(post_plugin_t *this_gen) xine_post_out_t *output = (xine_post_out_t *)xine_list_last_content(this_gen->output); xine_video_port_t *port = *(xine_video_port_t **)output->data; + this->metronom->exit(this->metronom); + if (this->stream) port->close(port, this->stream); @@ -443,6 +451,7 @@ static post_plugin_t *fftgraph_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target) { + post_class_fftgraph_t *class = (post_class_fftgraph_t *)class_gen; post_plugin_fftgraph_t *this = (post_plugin_fftgraph_t *)malloc(sizeof(post_plugin_fftgraph_t)); xine_post_in_t *input = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); post_fftgraph_out_t *output = (post_fftgraph_out_t *)malloc(sizeof(post_fftgraph_out_t)); @@ -458,6 +467,8 @@ static post_plugin_t *fftgraph_open_plugin(post_class_t *class_gen, int inputs, return NULL; } + this->metronom = _x_metronom_init(0, class->xine); + this->sample_counter = 0; this->stream = NULL; this->vo_port = video_target[0]; @@ -521,15 +532,17 @@ static void fftgraph_class_dispose(post_class_t *class_gen) /* plugin class initialization function */ void *fftgraph_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_fftgraph_t *class = (post_class_fftgraph_t *)malloc(sizeof(post_class_fftgraph_t)); if (!class) return NULL; - class->open_plugin = fftgraph_open_plugin; - class->get_identifier = fftgraph_get_identifier; - class->get_description = fftgraph_get_description; - class->dispose = fftgraph_class_dispose; + class->post_class.open_plugin = fftgraph_open_plugin; + class->post_class.get_identifier = fftgraph_get_identifier; + class->post_class.get_description = fftgraph_get_description; + class->post_class.dispose = fftgraph_class_dispose; + + class->xine = xine; return class; } diff --git a/src/post/visualizations/fftscope.c b/src/post/visualizations/fftscope.c index 6277be7c9..607f70a29 100644 --- a/src/post/visualizations/fftscope.c +++ b/src/post/visualizations/fftscope.c @@ -22,7 +22,7 @@ * * FFT code by Steve Haehnichen, originally licensed under GPL v1 * - * $Id: fftscope.c,v 1.18 2003/11/11 18:44:59 f1rmb Exp $ + * $Id: fftscope.c,v 1.19 2003/11/16 12:18:59 mroi Exp $ * */ @@ -48,6 +48,14 @@ typedef struct post_plugin_fftscope_s post_plugin_fftscope_t; +typedef struct post_class_fftscope_s post_class_fftscope_t; + +struct post_class_fftscope_s { + post_class_t post_class; + + xine_t *xine; +}; + struct post_plugin_fftscope_s { post_plugin_t post; @@ -55,6 +63,9 @@ struct post_plugin_fftscope_s { xine_video_port_t *vo_port; xine_stream_t *stream; + /* private metronom for syncing the video */ + metronom_t *metronom; + double ratio; int data_idx; @@ -340,6 +351,8 @@ static int fftscope_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream this->data_idx = 0; this->fft = fft_new(FFT_BITS); + this->metronom->set_master(this->metronom, stream->metronom); + for (c = 0; c < this->channels; c++) { for (i = 0; i < (NUMSAMPLES / 2); i++) { this->amp_max[c][i] = 0; @@ -362,6 +375,8 @@ static void fftscope_port_close(xine_audio_port_t *port_gen, xine_stream_t *stre fft_dispose(this->fft); this->fft = NULL; + this->metronom->set_master(this->metronom, NULL); + port->original_port->close(port->original_port, stream ); } @@ -375,7 +390,6 @@ static void fftscope_port_put_buffer (xine_audio_port_t *port_gen, int8_t *data8; int samples_used = 0; int64_t pts = buf->vpts; - int64_t vpts = 0; int i, c; /* make a copy of buf data for private use */ @@ -436,17 +450,9 @@ static void fftscope_port_put_buffer (xine_audio_port_t *port_gen, frame->extra_info->invalid = 1; frame->bad_frame = 0; frame->duration = 90000 * this->samples_per_frame / this->sample_rate; - if (!vpts) { - vpts = this->stream->metronom->audio_vpts; - frame->pts = pts; - frame->vpts = vpts; - pts = 0; - vpts += frame->duration; - } else { - frame->pts = 0; - frame->vpts = vpts; - vpts += frame->duration; - } + frame->pts = pts; + this->metronom->got_video_frame(this->metronom, frame); + this->sample_counter -= this->samples_per_frame; draw_fftscope(this, frame); @@ -463,6 +469,8 @@ static void fftscope_dispose(post_plugin_t *this_gen) xine_post_out_t *output = (xine_post_out_t *)xine_list_last_content(this_gen->output); xine_video_port_t *port = *(xine_video_port_t **)output->data; + this->metronom->exit(this->metronom); + if (this->stream) port->close(port, this->stream); @@ -482,6 +490,7 @@ static post_plugin_t *fftscope_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target) { + post_class_fftscope_t *class = (post_class_fftscope_t *)class_gen; post_plugin_fftscope_t *this = (post_plugin_fftscope_t *)malloc(sizeof(post_plugin_fftscope_t)); xine_post_in_t *input = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); post_fftscope_out_t *output = (post_fftscope_out_t *)malloc(sizeof(post_fftscope_out_t)); @@ -497,6 +506,8 @@ static post_plugin_t *fftscope_open_plugin(post_class_t *class_gen, int inputs, return NULL; } + this->metronom = _x_metronom_init(0, class->xine); + this->sample_counter = 0; this->stream = NULL; this->vo_port = video_target[0]; @@ -560,15 +571,17 @@ static void fftscope_class_dispose(post_class_t *class_gen) /* plugin class initialization function */ void *fftscope_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_fftscope_t *class = (post_class_fftscope_t *)malloc(sizeof(post_class_fftscope_t)); if (!class) return NULL; - class->open_plugin = fftscope_open_plugin; - class->get_identifier = fftscope_get_identifier; - class->get_description = fftscope_get_description; - class->dispose = fftscope_class_dispose; + class->post_class.open_plugin = fftscope_open_plugin; + class->post_class.get_identifier = fftscope_get_identifier; + class->post_class.get_description = fftscope_get_description; + class->post_class.dispose = fftscope_class_dispose; + + class->xine = xine; - return class; + return &class->post_class; } diff --git a/src/post/visualizations/fooviz.c b/src/post/visualizations/fooviz.c index 4f70de432..fccb6d72f 100644 --- a/src/post/visualizations/fooviz.c +++ b/src/post/visualizations/fooviz.c @@ -23,7 +23,7 @@ * process. It simply paints the screen a solid color and rotates through * colors on each iteration. * - * $Id: fooviz.c,v 1.13 2003/11/11 18:45:00 f1rmb Exp $ + * $Id: fooviz.c,v 1.14 2003/11/16 12:18:59 mroi Exp $ * */ @@ -42,6 +42,14 @@ typedef struct post_plugin_fooviz_s post_plugin_fooviz_t; +typedef struct post_class_fooviz_s post_class_fooviz_t; + +struct post_class_fooviz_s { + post_class_t post_class; + + xine_t *xine; +}; + struct post_plugin_fooviz_s { post_plugin_t post; @@ -49,6 +57,9 @@ struct post_plugin_fooviz_s { xine_video_port_t *vo_port; xine_stream_t *stream; + /* private metronom for syncing the video */ + metronom_t *metronom; + double ratio; int data_idx; @@ -150,6 +161,8 @@ static int fooviz_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream, this->stream = stream; this->data_idx = 0; + this->metronom->set_master(this->metronom, stream->metronom); + return port->original_port->open(port->original_port, stream, bits, rate, mode ); } @@ -160,6 +173,8 @@ static void fooviz_port_close(xine_audio_port_t *port_gen, xine_stream_t *stream this->stream = NULL; + this->metronom->set_master(this->metronom, NULL); + port->original_port->close(port->original_port, stream ); } @@ -173,7 +188,6 @@ static void fooviz_port_put_buffer (xine_audio_port_t *port_gen, int8_t *data8; int samples_used = 0; int64_t pts = buf->vpts; - int64_t vpts = 0; int i, j; /* make a copy of buf data for private use */ @@ -232,17 +246,9 @@ static void fooviz_port_put_buffer (xine_audio_port_t *port_gen, frame->extra_info->invalid = 1; frame->bad_frame = 0; frame->duration = 90000 * this->samples_per_frame / this->sample_rate; - if (!vpts) { - vpts = this->stream->metronom->audio_vpts; - frame->pts = pts; - frame->vpts = vpts; - pts = 0; - vpts += frame->duration; - } else { - frame->pts = 0; - frame->vpts = vpts; - vpts += frame->duration; - } + frame->pts = pts; + this->metronom->got_video_frame(this->metronom, frame); + this->sample_counter -= this->samples_per_frame; memset(frame->base[0], this->current_yuv_byte, FOO_WIDTH * FOO_HEIGHT * 2); @@ -260,6 +266,8 @@ static void fooviz_dispose(post_plugin_t *this_gen) xine_post_out_t *output = (xine_post_out_t *)xine_list_last_content(this_gen->output); xine_video_port_t *port = *(xine_video_port_t **)output->data; + this->metronom->exit(this->metronom); + if (this->stream) port->close(port, this->stream); @@ -279,6 +287,7 @@ static post_plugin_t *fooviz_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target) { + post_class_fooviz_t *class = (post_class_fooviz_t *)class_gen; post_plugin_fooviz_t *this = (post_plugin_fooviz_t *)malloc(sizeof(post_plugin_fooviz_t)); xine_post_in_t *input = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); post_fooviz_out_t *output = (post_fooviz_out_t *)malloc(sizeof(post_fooviz_out_t)); @@ -294,6 +303,8 @@ static post_plugin_t *fooviz_open_plugin(post_class_t *class_gen, int inputs, return NULL; } + this->metronom = _x_metronom_init(0, class->xine); + this->sample_counter = 0; this->stream = NULL; this->vo_port = video_target[0]; @@ -357,15 +368,17 @@ static void fooviz_class_dispose(post_class_t *class_gen) /* plugin class initialization function */ static void *fooviz_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_fooviz_t *class = (post_class_fooviz_t *)malloc(sizeof(post_class_fooviz_t)); if (!class) return NULL; - class->open_plugin = fooviz_open_plugin; - class->get_identifier = fooviz_get_identifier; - class->get_description = fooviz_get_description; - class->dispose = fooviz_class_dispose; + class->post_class.open_plugin = fooviz_open_plugin; + class->post_class.get_identifier = fooviz_get_identifier; + class->post_class.get_description = fooviz_get_description; + class->post_class.dispose = fooviz_class_dispose; + + class->xine = xine; return class; } diff --git a/src/post/visualizations/oscope.c b/src/post/visualizations/oscope.c index 71fe3933a..553ea5519 100644 --- a/src/post/visualizations/oscope.c +++ b/src/post/visualizations/oscope.c @@ -20,7 +20,7 @@ * Basic Oscilloscope Visualization Post Plugin For xine * by Mike Melanson (melanson@pcisys.net) * - * $Id: oscope.c,v 1.11 2003/11/11 18:45:00 f1rmb Exp $ + * $Id: oscope.c,v 1.12 2003/11/16 12:18:59 mroi Exp $ * */ @@ -41,6 +41,14 @@ typedef struct post_plugin_oscope_s post_plugin_oscope_t; +typedef struct post_class_oscope_s post_class_oscope_t; + +struct post_class_oscope_s { + post_class_t post_class; + + xine_t *xine; +}; + struct post_plugin_oscope_s { post_plugin_t post; @@ -48,6 +56,9 @@ struct post_plugin_oscope_s { xine_video_port_t *vo_port; xine_stream_t *stream; + /* private metronom for syncing the video */ + metronom_t *metronom; + double ratio; int data_idx; @@ -223,6 +234,8 @@ static int oscope_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream, this->data_idx = 0; init_yuv_planes(&this->yuv, OSCOPE_WIDTH, OSCOPE_HEIGHT); + this->metronom->set_master(this->metronom, stream->metronom); + return port->original_port->open(port->original_port, stream, bits, rate, mode ); } @@ -233,6 +246,8 @@ static void oscope_port_close(xine_audio_port_t *port_gen, xine_stream_t *stream this->stream = NULL; + this->metronom->set_master(this->metronom, NULL); + port->original_port->close(port->original_port, stream ); } @@ -246,7 +261,6 @@ static void oscope_port_put_buffer (xine_audio_port_t *port_gen, int8_t *data8; int samples_used = 0; int64_t pts = buf->vpts; - int64_t vpts = 0; int i, c; /* make a copy of buf data for private use */ @@ -301,17 +315,9 @@ static void oscope_port_put_buffer (xine_audio_port_t *port_gen, frame->extra_info->invalid = 1; frame->bad_frame = 0; frame->duration = 90000 * this->samples_per_frame / this->sample_rate; - if (!vpts) { - vpts = this->stream->metronom->audio_vpts; - frame->pts = pts; - frame->vpts = vpts; - pts = 0; - vpts += frame->duration; - } else { - frame->pts = 0; - frame->vpts = vpts; - vpts += frame->duration; - } + frame->pts = pts; + this->metronom->got_video_frame(this->metronom, frame); + this->sample_counter -= this->samples_per_frame; draw_oscope_dots(this); @@ -330,6 +336,8 @@ static void oscope_dispose(post_plugin_t *this_gen) xine_post_out_t *output = (xine_post_out_t *)xine_list_last_content(this_gen->output); xine_video_port_t *port = *(xine_video_port_t **)output->data; + this->metronom->exit(this->metronom); + if (this->stream) port->close(port, this->stream); @@ -349,6 +357,7 @@ static post_plugin_t *oscope_open_plugin(post_class_t *class_gen, int inputs, xine_audio_port_t **audio_target, xine_video_port_t **video_target) { + post_class_oscope_t *class = (post_class_oscope_t *)class_gen; post_plugin_oscope_t *this = (post_plugin_oscope_t *)malloc(sizeof(post_plugin_oscope_t)); xine_post_in_t *input = (xine_post_in_t *)malloc(sizeof(xine_post_in_t)); post_oscope_out_t *output = (post_oscope_out_t *)malloc(sizeof(post_oscope_out_t)); @@ -364,6 +373,8 @@ static post_plugin_t *oscope_open_plugin(post_class_t *class_gen, int inputs, return NULL; } + this->metronom = _x_metronom_init(0, class->xine); + this->sample_counter = 0; this->stream = NULL; this->vo_port = video_target[0]; @@ -427,15 +438,17 @@ static void oscope_class_dispose(post_class_t *class_gen) /* plugin class initialization function */ void *oscope_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof(post_class_t)); + post_class_oscope_t *class = (post_class_oscope_t *)malloc(sizeof(post_class_oscope_t)); if (!class) return NULL; - class->open_plugin = oscope_open_plugin; - class->get_identifier = oscope_get_identifier; - class->get_description = oscope_get_description; - class->dispose = oscope_class_dispose; + class->post_class.open_plugin = oscope_open_plugin; + class->post_class.get_identifier = oscope_get_identifier; + class->post_class.get_description = oscope_get_description; + class->post_class.dispose = oscope_class_dispose; + + class->xine = xine; - return class; + return &class->post_class; } -- cgit v1.2.3