diff options
Diffstat (limited to 'src/post/visualizations')
-rw-r--r-- | src/post/visualizations/fftgraph.c | 171 | ||||
-rw-r--r-- | src/post/visualizations/fftscope.c | 183 | ||||
-rw-r--r-- | src/post/visualizations/fooviz.c | 162 | ||||
-rw-r--r-- | src/post/visualizations/oscope.c | 165 | ||||
-rw-r--r-- | src/post/visualizations/visualizations.c | 8 |
5 files changed, 242 insertions, 447 deletions
diff --git a/src/post/visualizations/fftgraph.c b/src/post/visualizations/fftgraph.c index 40a667621..2105b646b 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.8 2003/12/03 10:52:41 andruil Exp $ + * $Id: fftgraph.c,v 1.9 2004/01/07 19:52:42 mroi Exp $ * */ @@ -61,7 +61,7 @@ struct post_plugin_fftgraph_s { /* private data */ xine_video_port_t *vo_port; - xine_stream_t *stream; + post_out_t video_output; /* private metronom for syncing the video */ metronom_t *metronom; @@ -72,10 +72,7 @@ struct post_plugin_fftgraph_s { complex_t wave[MAXCHANNELS][NUMSAMPLES]; audio_buffer_t buf; /* dummy buffer just to hold a copy of audio data */ - int bits; - int mode; int channels; - int sample_rate; int sample_counter; int samples_per_frame; @@ -189,47 +186,20 @@ static void draw_fftgraph(post_plugin_fftgraph_t *this, vo_frame_t *frame) { * xine video post plugin functions *************************************************************************/ -typedef struct post_fftgraph_out_s post_fftgraph_out_t; -struct post_fftgraph_out_s { - xine_post_out_t out; - post_plugin_fftgraph_t *post; -}; - -static int fftgraph_rewire_audio(xine_post_out_t *output_gen, void *data) -{ - post_fftgraph_out_t *output = (post_fftgraph_out_t *)output_gen; - xine_audio_port_t *old_port = *(xine_audio_port_t **)output_gen->data; - xine_audio_port_t *new_port = (xine_audio_port_t *)data; - post_plugin_fftgraph_t *this = (post_plugin_fftgraph_t *)output->post; - - if (!data) - return 0; - if (this->stream) { - /* register our stream at the new output port */ - old_port->close(old_port, this->stream); - new_port->open(new_port, this->stream, this->bits, this->sample_rate, this->mode); - } - /* reconnect ourselves */ - *(xine_audio_port_t **)output_gen->data = new_port; - return 1; -} - static int fftgraph_rewire_video(xine_post_out_t *output_gen, void *data) { - post_fftgraph_out_t *output = (post_fftgraph_out_t *)output_gen; + post_out_t *output = (post_out_t *)output_gen; xine_video_port_t *old_port = *(xine_video_port_t **)output_gen->data; xine_video_port_t *new_port = (xine_video_port_t *)data; post_plugin_fftgraph_t *this = (post_plugin_fftgraph_t *)output->post; if (!data) return 0; - if (this->stream) { - /* register our stream at the new output port */ - old_port->close(old_port, this->stream); - new_port->open(new_port, this->stream); - } + /* register our stream at the new output port */ + old_port->close(old_port, NULL); + new_port->open(new_port, NULL); /* reconnect ourselves */ - *(xine_video_port_t **)output_gen->data = new_port; + this->vo_port = new_port; return 1; } @@ -244,19 +214,27 @@ static int fftgraph_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream /* printf("fftgraph_port_open, port_gen=%p, stream=%p, this=%p\n", port_gen, stream, this); */ + _x_post_rewire_audio(port); + _x_post_inc_usage(port); + + if (stream) + port->stream = stream; + else + port->stream = POST_NULL_STREAM; + port->bits = bits; + port->rate = rate; + port->mode = mode; + this->ratio = (double)FFTGRAPH_WIDTH / (double)FFTGRAPH_HEIGHT; - this->bits = bits; - this->mode = mode; this->channels = _x_ao_mode2channels(mode); if( this->channels > MAXCHANNELS ) this->channels = MAXCHANNELS; this->lines_per_channel = FFTGRAPH_HEIGHT / this->channels; this->samples_per_frame = rate / FPS; - this->sample_rate = rate; - this->stream = stream; this->data_idx = 0; + this->vo_port->open(this->vo_port, NULL); this->metronom->set_master(this->metronom, stream->metronom); this->fft = fft_new(FFT_BITS); @@ -316,13 +294,17 @@ static void fftgraph_port_close(xine_audio_port_t *port_gen, xine_stream_t *stre post_audio_port_t *port = (post_audio_port_t *)port_gen; post_plugin_fftgraph_t *this = (post_plugin_fftgraph_t *)port->post; - this->stream = NULL; + port->stream = NULL; + fft_dispose(this->fft); this->fft = NULL; + this->vo_port->close(this->vo_port, NULL); this->metronom->set_master(this->metronom, NULL); port->original_port->close(port->original_port, stream ); + + _x_post_dec_usage(port); } static void fftgraph_port_put_buffer (xine_audio_port_t *port_gen, @@ -343,7 +325,7 @@ static void fftgraph_port_put_buffer (xine_audio_port_t *port_gen, this->buf.mem_size = buf->mem_size; } memcpy(this->buf.mem, buf->mem, - buf->num_frames*this->channels*((this->bits == 8)?1:2)); + buf->num_frames*this->channels*((port->bits == 8)?1:2)); this->buf.num_frames = buf->num_frames; /* pass data to original port */ @@ -358,7 +340,7 @@ static void fftgraph_port_put_buffer (xine_audio_port_t *port_gen, do { - if( this->bits == 8 ) { + if( port->bits == 8 ) { data8 = (int8_t *)buf->mem; data8 += samples_used * this->channels; @@ -394,7 +376,7 @@ static void fftgraph_port_put_buffer (xine_audio_port_t *port_gen, VO_BOTH_FIELDS); frame->extra_info->invalid = 1; frame->bad_frame = 0; - frame->duration = 90000 * this->samples_per_frame / this->sample_rate; + frame->duration = 90000 * this->samples_per_frame / port->rate; frame->pts = pts; this->metronom->got_video_frame(this->metronom, frame); @@ -411,23 +393,15 @@ static void fftgraph_port_put_buffer (xine_audio_port_t *port_gen, static void fftgraph_dispose(post_plugin_t *this_gen) { post_plugin_fftgraph_t *this = (post_plugin_fftgraph_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); - - free(this->post.xine_post.audio_input); - free(this->post.xine_post.video_input); - free(xine_list_first_content(this->post.input)); - free(xine_list_first_content(this->post.output)); - xine_list_free(this->post.input); - xine_list_free(this->post.output); - if(this->buf.mem) - free(this->buf.mem); - free(this); + + if (_x_post_dispose(this_gen)) { + + this->metronom->exit(this->metronom); + + if(this->buf.mem) + free(this->buf.mem); + free(this); + } } /* plugin class functions */ @@ -435,64 +409,39 @@ 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)); - post_fftgraph_out_t *outputv = (post_fftgraph_out_t *)malloc(sizeof(post_fftgraph_out_t)); - post_audio_port_t *port; - - if (!this || !input || !output || !outputv || !video_target || !video_target[0] || - !audio_target || !audio_target[0] ) { + post_class_fftgraph_t *class = (post_class_fftgraph_t *)class_gen; + post_plugin_fftgraph_t *this = (post_plugin_fftgraph_t *)xine_xmalloc(sizeof(post_plugin_fftgraph_t)); + post_in_t *input; + post_out_t *output; + post_out_t *outputv; + post_audio_port_t *port; + + if (!this || !video_target || !video_target[0] || !audio_target || !audio_target[0] ) { free(this); - free(input); - free(output); - free(outputv); return NULL; } + _x_post_init(&this->post, 1, 0); + this->metronom = _x_metronom_init(1, 0, class->xine); - this->sample_counter = 0; - this->stream = NULL; this->vo_port = video_target[0]; - this->buf.mem = NULL; - this->buf.mem_size = 0; - - port = _x_post_intercept_audio_port(&this->post, audio_target[0]); - port->port.open = fftgraph_port_open; - port->port.close = fftgraph_port_close; - port->port.put_buffer = fftgraph_port_put_buffer; - - input->name = "audio in"; - input->type = XINE_POST_DATA_AUDIO; - input->data = (xine_audio_port_t *)&port->port; - - output->out.name = "audio out"; - output->out.type = XINE_POST_DATA_AUDIO; - output->out.data = (xine_audio_port_t **)&port->original_port; - output->out.rewire = fftgraph_rewire_audio; - output->post = this; - - outputv->out.name = "generated video"; - outputv->out.type = XINE_POST_DATA_VIDEO; - outputv->out.data = (xine_video_port_t **)&this->vo_port; - outputv->out.rewire = fftgraph_rewire_video; - outputv->post = this; - - this->post.xine_post.audio_input = (xine_audio_port_t **)malloc(sizeof(xine_audio_port_t *) * 2); - this->post.xine_post.audio_input[0] = &port->port; - this->post.xine_post.audio_input[1] = NULL; - this->post.xine_post.video_input = (xine_video_port_t **)malloc(sizeof(xine_video_port_t *) * 1); - this->post.xine_post.video_input[0] = NULL; - - this->post.input = xine_list_new(); - this->post.output = xine_list_new(); - - xine_list_append_content(this->post.input, input); - xine_list_append_content(this->post.output, output); + + port = _x_post_intercept_audio_port(&this->post, audio_target[0], &input, &output); + port->new_port.open = fftgraph_port_open; + port->new_port.close = fftgraph_port_close; + port->new_port.put_buffer = fftgraph_port_put_buffer; + + outputv = &this->video_output; + outputv->xine_out.name = "generated video"; + outputv->xine_out.type = XINE_POST_DATA_VIDEO; + outputv->xine_out.data = (xine_video_port_t **)&this->vo_port; + outputv->xine_out.rewire = fftgraph_rewire_video; + outputv->post = &this->post; xine_list_append_content(this->post.output, outputv); + this->post.xine_post.audio_input[0] = &port->new_port; + this->post.dispose = fftgraph_dispose; return &this->post; diff --git a/src/post/visualizations/fftscope.c b/src/post/visualizations/fftscope.c index 4113d4d7d..b2d4e4770 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.23 2003/12/13 23:01:45 tmmm Exp $ + * $Id: fftscope.c,v 1.24 2004/01/07 19:52:42 mroi Exp $ * */ @@ -51,9 +51,9 @@ 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; + post_class_t post_class; + + xine_t *xine; }; struct post_plugin_fftscope_s { @@ -61,8 +61,8 @@ struct post_plugin_fftscope_s { /* private data */ xine_video_port_t *vo_port; - xine_stream_t *stream; - + post_out_t video_output; + /* private metronom for syncing the video */ metronom_t *metronom; @@ -77,10 +77,7 @@ struct post_plugin_fftscope_s { int amp_age[MAXCHANNELS][NUMSAMPLES / 2]; audio_buffer_t buf; /* dummy buffer just to hold a copy of audio data */ - int bits; - int mode; int channels; - int sample_rate; int sample_counter; int samples_per_frame; @@ -253,47 +250,20 @@ static void draw_fftscope(post_plugin_fftscope_t *this, vo_frame_t *frame) { * xine video post plugin functions *************************************************************************/ -typedef struct post_fftscope_out_s post_fftscope_out_t; -struct post_fftscope_out_s { - xine_post_out_t out; - post_plugin_fftscope_t *post; -}; - -static int fftscope_rewire_audio(xine_post_out_t *output_gen, void *data) -{ - post_fftscope_out_t *output = (post_fftscope_out_t *)output_gen; - xine_audio_port_t *old_port = *(xine_audio_port_t **)output_gen->data; - xine_audio_port_t *new_port = (xine_audio_port_t *)data; - post_plugin_fftscope_t *this = (post_plugin_fftscope_t *)output->post; - - if (!data) - return 0; - if (this->stream) { - /* register our stream at the new output port */ - old_port->close(old_port, this->stream); - new_port->open(new_port, this->stream, this->bits, this->sample_rate, this->mode); - } - /* reconnect ourselves */ - *(xine_audio_port_t **)output_gen->data = new_port; - return 1; -} - static int fftscope_rewire_video(xine_post_out_t *output_gen, void *data) { - post_fftscope_out_t *output = (post_fftscope_out_t *)output_gen; + post_out_t *output = (post_out_t *)output_gen; xine_video_port_t *old_port = *(xine_video_port_t **)output_gen->data; xine_video_port_t *new_port = (xine_video_port_t *)data; post_plugin_fftscope_t *this = (post_plugin_fftscope_t *)output->post; if (!data) return 0; - if (this->stream) { - /* register our stream at the new output port */ - old_port->close(old_port, this->stream); - new_port->open(new_port, this->stream); - } + /* register our stream at the new output port */ + old_port->close(old_port, NULL); + new_port->open(new_port, NULL); /* reconnect ourselves */ - *(xine_video_port_t **)output_gen->data = new_port; + this->vo_port = new_port; return 1; } @@ -304,19 +274,27 @@ static int fftscope_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream post_plugin_fftscope_t *this = (post_plugin_fftscope_t *)port->post; int c, i; + _x_post_rewire_audio(port); + _x_post_inc_usage(port); + + if (stream) + port->stream = stream; + else + port->stream = POST_NULL_STREAM; + port->bits = bits; + port->rate = rate; + port->mode = mode; + this->ratio = (double)FFT_WIDTH/(double)FFT_HEIGHT; - this->bits = bits; - this->mode = mode; this->channels = _x_ao_mode2channels(mode); if( this->channels > MAXCHANNELS ) this->channels = MAXCHANNELS; this->samples_per_frame = rate / FPS; - this->sample_rate = rate; - this->stream = stream; this->data_idx = 0; this->fft = fft_new(FFT_BITS); + this->vo_port->open(this->vo_port, NULL); this->metronom->set_master(this->metronom, stream->metronom); for (c = 0; c < this->channels; c++) { @@ -337,21 +315,25 @@ static void fftscope_port_close(xine_audio_port_t *port_gen, xine_stream_t *stre post_audio_port_t *port = (post_audio_port_t *)port_gen; post_plugin_fftscope_t *this = (post_plugin_fftscope_t *)port->post; - this->stream = NULL; + port->stream = NULL; + fft_dispose(this->fft); this->fft = NULL; + this->vo_port->close(this->vo_port, NULL); this->metronom->set_master(this->metronom, NULL); port->original_port->close(port->original_port, stream ); + + _x_post_dec_usage(port); } static void fftscope_port_put_buffer (xine_audio_port_t *port_gen, audio_buffer_t *buf, xine_stream_t *stream) { - post_audio_port_t *port = (post_audio_port_t *)port_gen; + post_audio_port_t *port = (post_audio_port_t *)port_gen; post_plugin_fftscope_t *this = (post_plugin_fftscope_t *)port->post; - vo_frame_t *frame; + vo_frame_t *frame; int16_t *data; int8_t *data8; int samples_used = 0; @@ -364,7 +346,7 @@ static void fftscope_port_put_buffer (xine_audio_port_t *port_gen, this->buf.mem_size = buf->mem_size; } memcpy(this->buf.mem, buf->mem, - buf->num_frames*this->channels*((this->bits == 8)?1:2)); + buf->num_frames*this->channels*((port->bits == 8)?1:2)); this->buf.num_frames = buf->num_frames; /* pass data to original port */ @@ -379,7 +361,7 @@ static void fftscope_port_put_buffer (xine_audio_port_t *port_gen, do { - if( this->bits == 8 ) { + if( port->bits == 8 ) { data8 = (int8_t *)buf->mem; data8 += samples_used * this->channels; @@ -415,7 +397,7 @@ static void fftscope_port_put_buffer (xine_audio_port_t *port_gen, VO_BOTH_FIELDS); frame->extra_info->invalid = 1; frame->bad_frame = 0; - frame->duration = 90000 * this->samples_per_frame / this->sample_rate; + frame->duration = 90000 * this->samples_per_frame / port->rate; frame->pts = pts; this->metronom->got_video_frame(this->metronom, frame); @@ -432,23 +414,15 @@ static void fftscope_port_put_buffer (xine_audio_port_t *port_gen, static void fftscope_dispose(post_plugin_t *this_gen) { post_plugin_fftscope_t *this = (post_plugin_fftscope_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); - - free(this->post.xine_post.audio_input); - free(this->post.xine_post.video_input); - free(xine_list_first_content(this->post.input)); - free(xine_list_first_content(this->post.output)); - xine_list_free(this->post.input); - xine_list_free(this->post.output); - if(this->buf.mem) - free(this->buf.mem); - free(this); + + if (_x_post_dispose(this_gen)) { + + this->metronom->exit(this->metronom); + + if(this->buf.mem) + free(this->buf.mem); + free(this); + } } /* plugin class functions */ @@ -456,64 +430,39 @@ 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)); - post_fftscope_out_t *outputv = (post_fftscope_out_t *)malloc(sizeof(post_fftscope_out_t)); - post_audio_port_t *port; - - if (!this || !input || !output || !outputv || !video_target || !video_target[0] || - !audio_target || !audio_target[0] ) { + post_plugin_fftscope_t *this = (post_plugin_fftscope_t *)xine_xmalloc(sizeof(post_plugin_fftscope_t)); + post_class_fftscope_t *class = (post_class_fftscope_t *)class_gen; + post_in_t *input; + post_out_t *output; + post_out_t *outputv; + post_audio_port_t *port; + + if (!this || !video_target || !video_target[0] || !audio_target || !audio_target[0] ) { free(this); - free(input); - free(output); - free(outputv); return NULL; } + + _x_post_init(&this->post, 1, 0); this->metronom = _x_metronom_init(1, 0, class->xine); - this->sample_counter = 0; - this->stream = NULL; this->vo_port = video_target[0]; - this->buf.mem = NULL; - this->buf.mem_size = 0; - - port = _x_post_intercept_audio_port(&this->post, audio_target[0]); - port->port.open = fftscope_port_open; - port->port.close = fftscope_port_close; - port->port.put_buffer = fftscope_port_put_buffer; - - input->name = "audio in"; - input->type = XINE_POST_DATA_AUDIO; - input->data = (xine_audio_port_t *)&port->port; - - output->out.name = "audio out"; - output->out.type = XINE_POST_DATA_AUDIO; - output->out.data = (xine_audio_port_t **)&port->original_port; - output->out.rewire = fftscope_rewire_audio; - output->post = this; - - outputv->out.name = "generated video"; - outputv->out.type = XINE_POST_DATA_VIDEO; - outputv->out.data = (xine_video_port_t **)&this->vo_port; - outputv->out.rewire = fftscope_rewire_video; - outputv->post = this; - - this->post.xine_post.audio_input = (xine_audio_port_t **)malloc(sizeof(xine_audio_port_t *) * 2); - this->post.xine_post.audio_input[0] = &port->port; - this->post.xine_post.audio_input[1] = NULL; - this->post.xine_post.video_input = (xine_video_port_t **)malloc(sizeof(xine_video_port_t *) * 1); - this->post.xine_post.video_input[0] = NULL; - - this->post.input = xine_list_new(); - this->post.output = xine_list_new(); - - xine_list_append_content(this->post.input, input); - xine_list_append_content(this->post.output, output); + + port = _x_post_intercept_audio_port(&this->post, audio_target[0], &input, &output); + port->new_port.open = fftscope_port_open; + port->new_port.close = fftscope_port_close; + port->new_port.put_buffer = fftscope_port_put_buffer; + + outputv = &this->video_output; + outputv->xine_out.name = "generated video"; + outputv->xine_out.type = XINE_POST_DATA_VIDEO; + outputv->xine_out.data = (xine_video_port_t **)&this->vo_port; + outputv->xine_out.rewire = fftscope_rewire_video; + outputv->post = &this->post; xine_list_append_content(this->post.output, outputv); + this->post.xine_post.audio_input[0] = &port->new_port; + this->post.dispose = fftscope_dispose; return &this->post; diff --git a/src/post/visualizations/fooviz.c b/src/post/visualizations/fooviz.c index bf5326a39..d72ee4354 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.18 2003/12/14 22:13:25 siggi Exp $ + * $Id: fooviz.c,v 1.19 2004/01/07 19:52:42 mroi Exp $ * */ @@ -55,7 +55,7 @@ struct post_plugin_fooviz_s { /* private data */ xine_video_port_t *vo_port; - xine_stream_t *stream; + post_out_t video_output; /* private metronom for syncing the video */ metronom_t *metronom; @@ -66,10 +66,7 @@ struct post_plugin_fooviz_s { short data [2][NUMSAMPLES]; audio_buffer_t buf; /* dummy buffer just to hold a copy of audio data */ - int bits; - int mode; int channels; - int sample_rate; int sample_counter; int samples_per_frame; @@ -86,47 +83,20 @@ struct post_plugin_fooviz_s { * xine video post plugin functions *************************************************************************/ -typedef struct post_fooviz_out_s post_fooviz_out_t; -struct post_fooviz_out_s { - xine_post_out_t out; - post_plugin_fooviz_t *post; -}; - -static int fooviz_rewire_audio(xine_post_out_t *output_gen, void *data) -{ - post_fooviz_out_t *output = (post_fooviz_out_t *)output_gen; - xine_audio_port_t *old_port = *(xine_audio_port_t **)output_gen->data; - xine_audio_port_t *new_port = (xine_audio_port_t *)data; - post_plugin_fooviz_t *this = (post_plugin_fooviz_t *)output->post; - - if (!data) - return 0; - if (this->stream) { - /* register our stream at the new output port */ - old_port->close(old_port, this->stream); - new_port->open(new_port, this->stream, this->bits, this->sample_rate, this->mode); - } - /* reconnect ourselves */ - *(xine_audio_port_t **)output_gen->data = new_port; - return 1; -} - static int fooviz_rewire_video(xine_post_out_t *output_gen, void *data) { - post_fooviz_out_t *output = (post_fooviz_out_t *)output_gen; + post_out_t *output = (post_out_t *)output_gen; xine_video_port_t *old_port = *(xine_video_port_t **)output_gen->data; xine_video_port_t *new_port = (xine_video_port_t *)data; post_plugin_fooviz_t *this = (post_plugin_fooviz_t *)output->post; if (!data) return 0; - if (this->stream) { - /* register our stream at the new output port */ - old_port->close(old_port, this->stream); - new_port->open(new_port, this->stream); - } + /* register our stream at the new output port */ + old_port->close(old_port, NULL); + new_port->open(new_port, NULL); /* reconnect ourselves */ - *(xine_video_port_t **)output_gen->data = new_port; + this->vo_port = new_port; return 1; } @@ -136,15 +106,23 @@ static int fooviz_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream, post_audio_port_t *port = (post_audio_port_t *)port_gen; post_plugin_fooviz_t *this = (post_plugin_fooviz_t *)port->post; + _x_post_rewire_audio(port); + _x_post_inc_usage(port); + + if (stream) + port->stream = stream; + else + port->stream = POST_NULL_STREAM; + port->bits = bits; + port->rate = rate; + port->mode = mode; + this->ratio = (double)FOO_WIDTH/(double)FOO_HEIGHT; - this->bits = bits; - this->mode = mode; this->channels = _x_ao_mode2channels(mode); this->samples_per_frame = rate / FPS; - this->sample_rate = rate; - this->stream = stream; this->data_idx = 0; + this->vo_port->open(this->vo_port, NULL); this->metronom->set_master(this->metronom, stream->metronom); return port->original_port->open(port->original_port, stream, bits, rate, mode ); @@ -155,11 +133,14 @@ static void fooviz_port_close(xine_audio_port_t *port_gen, xine_stream_t *stream post_audio_port_t *port = (post_audio_port_t *)port_gen; post_plugin_fooviz_t *this = (post_plugin_fooviz_t *)port->post; - this->stream = NULL; + port->stream = NULL; + this->vo_port->close(this->vo_port, NULL); this->metronom->set_master(this->metronom, NULL); port->original_port->close(port->original_port, stream ); + + _x_post_dec_usage(port); } static void fooviz_port_put_buffer (xine_audio_port_t *port_gen, @@ -180,7 +161,7 @@ static void fooviz_port_put_buffer (xine_audio_port_t *port_gen, this->buf.mem_size = buf->mem_size; } memcpy(this->buf.mem, buf->mem, - buf->num_frames*this->channels*((this->bits == 8)?1:2)); + buf->num_frames*this->channels*((port->bits == 8)?1:2)); this->buf.num_frames = buf->num_frames; /* pass data to original port */ @@ -197,7 +178,7 @@ static void fooviz_port_put_buffer (xine_audio_port_t *port_gen, do { - if( this->bits == 8 ) { + if( port->bits == 8 ) { data8 = (int8_t *)buf->mem; data8 += samples_used * this->channels; @@ -229,7 +210,7 @@ static void fooviz_port_put_buffer (xine_audio_port_t *port_gen, VO_BOTH_FIELDS); frame->extra_info->invalid = 1; frame->bad_frame = 0; - frame->duration = 90000 * this->samples_per_frame / this->sample_rate; + frame->duration = 90000 * this->samples_per_frame / port->rate; frame->pts = pts; this->metronom->got_video_frame(this->metronom, frame); @@ -247,23 +228,15 @@ static void fooviz_port_put_buffer (xine_audio_port_t *port_gen, static void fooviz_dispose(post_plugin_t *this_gen) { post_plugin_fooviz_t *this = (post_plugin_fooviz_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 (_x_post_dispose(this_gen)) { - if (this->stream) - port->close(port, this->stream); - - free(this->post.xine_post.audio_input); - free(this->post.xine_post.video_input); - free(xine_list_first_content(this->post.input)); - free(xine_list_first_content(this->post.output)); - xine_list_free(this->post.input); - xine_list_free(this->post.output); - if(this->buf.mem) - free(this->buf.mem); - free(this); + this->metronom->exit(this->metronom); + + if(this->buf.mem) + free(this->buf.mem); + free(this); + } } /* plugin class functions */ @@ -271,64 +244,39 @@ 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)); - post_fooviz_out_t *outputv = (post_fooviz_out_t *)malloc(sizeof(post_fooviz_out_t)); - post_audio_port_t *port; + post_class_fooviz_t *class = (post_class_fooviz_t *)class_gen; + post_plugin_fooviz_t *this = (post_plugin_fooviz_t *)xine_xmalloc(sizeof(post_plugin_fooviz_t)); + post_in_t *input; + post_out_t *output; + post_out_t *outputv; + post_audio_port_t *port; - if (!this || !input || !output || !outputv || !video_target || !video_target[0] || - !audio_target || !audio_target[0] ) { + if (!this || !video_target || !video_target[0] || !audio_target || !audio_target[0] ) { free(this); - free(input); - free(output); - free(outputv); return NULL; } + _x_post_init(&this->post, 1, 0); + this->metronom = _x_metronom_init(1, 0, class->xine); - this->sample_counter = 0; - this->stream = NULL; this->vo_port = video_target[0]; - this->buf.mem = NULL; - this->buf.mem_size = 0; - port = _x_post_intercept_audio_port(&this->post, audio_target[0]); - port->port.open = fooviz_port_open; - port->port.close = fooviz_port_close; - port->port.put_buffer = fooviz_port_put_buffer; - - input->name = "audio in"; - input->type = XINE_POST_DATA_AUDIO; - input->data = (xine_audio_port_t *)&port->port; - - output->out.name = "audio out"; - output->out.type = XINE_POST_DATA_AUDIO; - output->out.data = (xine_audio_port_t **)&port->original_port; - output->out.rewire = fooviz_rewire_audio; - output->post = this; - - outputv->out.name = "generated video"; - outputv->out.type = XINE_POST_DATA_VIDEO; - outputv->out.data = (xine_video_port_t **)&this->vo_port; - outputv->out.rewire = fooviz_rewire_video; - outputv->post = this; + port = _x_post_intercept_audio_port(&this->post, audio_target[0], &input, &output); + port->new_port.open = fooviz_port_open; + port->new_port.close = fooviz_port_close; + port->new_port.put_buffer = fooviz_port_put_buffer; - this->post.xine_post.audio_input = (xine_audio_port_t **)malloc(sizeof(xine_audio_port_t *) * 2); - this->post.xine_post.audio_input[0] = &port->port; - this->post.xine_post.audio_input[1] = NULL; - this->post.xine_post.video_input = (xine_video_port_t **)malloc(sizeof(xine_video_port_t *) * 1); - this->post.xine_post.video_input[0] = NULL; - - this->post.input = xine_list_new(); - this->post.output = xine_list_new(); - - xine_list_append_content(this->post.input, input); - xine_list_append_content(this->post.output, output); + outputv = &this->video_output; + outputv->xine_out.name = "generated video"; + outputv->xine_out.type = XINE_POST_DATA_VIDEO; + outputv->xine_out.data = (xine_video_port_t **)&this->vo_port; + outputv->xine_out.rewire = fooviz_rewire_video; + outputv->post = &this->post; xine_list_append_content(this->post.output, outputv); + this->post.xine_post.audio_input[0] = &port->new_port; + this->post.dispose = fooviz_dispose; return &this->post; @@ -372,6 +320,6 @@ post_info_t fooviz_special_info = { XINE_POST_TYPE_AUDIO_VISUALIZATION }; plugin_info_t xine_plugin_info[] = { /* type, API, "name", version, special_info, init_function */ - { PLUGIN_POST, 7, "fooviz", XINE_VERSION_CODE, &fooviz_special_info, &fooviz_init_plugin }, + { PLUGIN_POST, 8, "fooviz", XINE_VERSION_CODE, &fooviz_special_info, &fooviz_init_plugin }, { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; diff --git a/src/post/visualizations/oscope.c b/src/post/visualizations/oscope.c index 7b2427b83..658a56d28 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.15 2003/12/03 10:52:41 andruil Exp $ + * $Id: oscope.c,v 1.16 2004/01/07 19:52:42 mroi Exp $ * */ @@ -54,7 +54,7 @@ struct post_plugin_oscope_s { /* private data */ xine_video_port_t *vo_port; - xine_stream_t *stream; + post_out_t video_output; /* private metronom for syncing the video */ metronom_t *metronom; @@ -65,10 +65,7 @@ struct post_plugin_oscope_s { short data [MAXCHANNELS][NUMSAMPLES]; audio_buffer_t buf; /* dummy buffer just to hold a copy of audio data */ - int bits; - int mode; int channels; - int sample_rate; int sample_counter; int samples_per_frame; @@ -157,47 +154,19 @@ static void draw_oscope_dots(post_plugin_oscope_t *this) { * xine video post plugin functions *************************************************************************/ -typedef struct post_oscope_out_s post_oscope_out_t; -struct post_oscope_out_s { - xine_post_out_t out; - post_plugin_oscope_t *post; -}; - -static int oscope_rewire_audio(xine_post_out_t *output_gen, void *data) -{ - post_oscope_out_t *output = (post_oscope_out_t *)output_gen; - xine_audio_port_t *old_port = *(xine_audio_port_t **)output_gen->data; - xine_audio_port_t *new_port = (xine_audio_port_t *)data; - post_plugin_oscope_t *this = (post_plugin_oscope_t *)output->post; - - if (!data) - return 0; - if (this->stream) { - /* register our stream at the new output port */ - old_port->close(old_port, this->stream); - new_port->open(new_port, this->stream, this->bits, this->sample_rate, this->mode); - } - /* reconnect ourselves */ - *(xine_audio_port_t **)output_gen->data = new_port; - return 1; -} - static int oscope_rewire_video(xine_post_out_t *output_gen, void *data) { - post_oscope_out_t *output = (post_oscope_out_t *)output_gen; + post_out_t *output = (post_out_t *)output_gen; xine_video_port_t *old_port = *(xine_video_port_t **)output_gen->data; xine_video_port_t *new_port = (xine_video_port_t *)data; post_plugin_oscope_t *this = (post_plugin_oscope_t *)output->post; if (!data) return 0; - if (this->stream) { - /* register our stream at the new output port */ - old_port->close(old_port, this->stream); - new_port->open(new_port, this->stream); - } + old_port->close(old_port, NULL); + new_port->open(new_port, NULL); /* reconnect ourselves */ - *(xine_video_port_t **)output_gen->data = new_port; + this->vo_port = new_port; return 1; } @@ -207,17 +176,27 @@ static int oscope_port_open(xine_audio_port_t *port_gen, xine_stream_t *stream, post_audio_port_t *port = (post_audio_port_t *)port_gen; post_plugin_oscope_t *this = (post_plugin_oscope_t *)port->post; + _x_post_rewire_audio(port); + _x_post_inc_usage(port); + + if (stream) + port->stream = stream; + else + port->stream = POST_NULL_STREAM; + port->bits = bits; + port->rate = rate; + port->mode = mode; + this->ratio = (double)OSCOPE_WIDTH/(double)OSCOPE_HEIGHT; - this->bits = bits; - this->mode = mode; this->channels = _x_ao_mode2channels(mode); + if( this->channels > MAXCHANNELS ) + this->channels = MAXCHANNELS; this->samples_per_frame = rate / FPS; - this->sample_rate = rate; - this->stream = stream; this->data_idx = 0; init_yuv_planes(&this->yuv, OSCOPE_WIDTH, OSCOPE_HEIGHT); + this->vo_port->open(this->vo_port, NULL); this->metronom->set_master(this->metronom, stream->metronom); return port->original_port->open(port->original_port, stream, bits, rate, mode ); @@ -228,19 +207,22 @@ static void oscope_port_close(xine_audio_port_t *port_gen, xine_stream_t *stream post_audio_port_t *port = (post_audio_port_t *)port_gen; post_plugin_oscope_t *this = (post_plugin_oscope_t *)port->post; - this->stream = NULL; + port->stream = NULL; + this->vo_port->close(this->vo_port, NULL); this->metronom->set_master(this->metronom, NULL); port->original_port->close(port->original_port, stream ); + + _x_post_dec_usage(port); } static void oscope_port_put_buffer (xine_audio_port_t *port_gen, audio_buffer_t *buf, xine_stream_t *stream) { - post_audio_port_t *port = (post_audio_port_t *)port_gen; + post_audio_port_t *port = (post_audio_port_t *)port_gen; post_plugin_oscope_t *this = (post_plugin_oscope_t *)port->post; - vo_frame_t *frame; + vo_frame_t *frame; int16_t *data; int8_t *data8; int samples_used = 0; @@ -253,7 +235,7 @@ static void oscope_port_put_buffer (xine_audio_port_t *port_gen, this->buf.mem_size = buf->mem_size; } memcpy(this->buf.mem, buf->mem, - buf->num_frames*this->channels*((this->bits == 8)?1:2)); + buf->num_frames*this->channels*((port->bits == 8)?1:2)); this->buf.num_frames = buf->num_frames; /* pass data to original port */ @@ -268,7 +250,7 @@ static void oscope_port_put_buffer (xine_audio_port_t *port_gen, do { - if( this->bits == 8 ) { + if( port->bits == 8 ) { data8 = (int8_t *)buf->mem; data8 += samples_used * this->channels; @@ -298,7 +280,7 @@ static void oscope_port_put_buffer (xine_audio_port_t *port_gen, VO_BOTH_FIELDS); frame->extra_info->invalid = 1; frame->bad_frame = 0; - frame->duration = 90000 * this->samples_per_frame / this->sample_rate; + frame->duration = 90000 * this->samples_per_frame / port->rate; frame->pts = pts; this->metronom->got_video_frame(this->metronom, frame); @@ -317,23 +299,15 @@ static void oscope_port_put_buffer (xine_audio_port_t *port_gen, static void oscope_dispose(post_plugin_t *this_gen) { post_plugin_oscope_t *this = (post_plugin_oscope_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 (_x_post_dispose(this_gen)) { + + this->metronom->exit(this->metronom); - if (this->stream) - port->close(port, this->stream); - - free(this->post.xine_post.audio_input); - free(this->post.xine_post.video_input); - free(xine_list_first_content(this->post.input)); - free(xine_list_first_content(this->post.output)); - xine_list_free(this->post.input); - xine_list_free(this->post.output); - if(this->buf.mem) - free(this->buf.mem); - free(this); + if(this->buf.mem) + free(this->buf.mem); + free(this); + } } /* plugin class functions */ @@ -341,64 +315,39 @@ 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)); - post_oscope_out_t *outputv = (post_oscope_out_t *)malloc(sizeof(post_oscope_out_t)); - post_audio_port_t *port; + post_class_oscope_t *class = (post_class_oscope_t *)class_gen; + post_plugin_oscope_t *this = (post_plugin_oscope_t *)xine_xmalloc(sizeof(post_plugin_oscope_t)); + post_in_t *input; + post_out_t *output; + post_out_t *outputv; + post_audio_port_t *port; - if (!this || !input || !output || !outputv || !video_target || !video_target[0] || - !audio_target || !audio_target[0] ) { + if (!this || !video_target || !video_target[0] || !audio_target || !audio_target[0] ) { free(this); - free(input); - free(output); - free(outputv); return NULL; } + _x_post_init(&this->post, 1, 0); + this->metronom = _x_metronom_init(1, 0, class->xine); - this->sample_counter = 0; - this->stream = NULL; this->vo_port = video_target[0]; - this->buf.mem = NULL; - this->buf.mem_size = 0; - port = _x_post_intercept_audio_port(&this->post, audio_target[0]); - port->port.open = oscope_port_open; - port->port.close = oscope_port_close; - port->port.put_buffer = oscope_port_put_buffer; - - input->name = "audio in"; - input->type = XINE_POST_DATA_AUDIO; - input->data = (xine_audio_port_t *)&port->port; - - output->out.name = "audio out"; - output->out.type = XINE_POST_DATA_AUDIO; - output->out.data = (xine_audio_port_t **)&port->original_port; - output->out.rewire = oscope_rewire_audio; - output->post = this; - - outputv->out.name = "generated video"; - outputv->out.type = XINE_POST_DATA_VIDEO; - outputv->out.data = (xine_video_port_t **)&this->vo_port; - outputv->out.rewire = oscope_rewire_video; - outputv->post = this; + port = _x_post_intercept_audio_port(&this->post, audio_target[0], &input, &output); + port->new_port.open = oscope_port_open; + port->new_port.close = oscope_port_close; + port->new_port.put_buffer = oscope_port_put_buffer; - this->post.xine_post.audio_input = (xine_audio_port_t **)malloc(sizeof(xine_audio_port_t *) * 2); - this->post.xine_post.audio_input[0] = &port->port; - this->post.xine_post.audio_input[1] = NULL; - this->post.xine_post.video_input = (xine_video_port_t **)malloc(sizeof(xine_video_port_t *) * 1); - this->post.xine_post.video_input[0] = NULL; - - this->post.input = xine_list_new(); - this->post.output = xine_list_new(); - - xine_list_append_content(this->post.input, input); - xine_list_append_content(this->post.output, output); + outputv = &this->video_output; + outputv->xine_out.name = "generated video"; + outputv->xine_out.type = XINE_POST_DATA_VIDEO; + outputv->xine_out.data = (xine_video_port_t **)&this->vo_port; + outputv->xine_out.rewire = oscope_rewire_video; + outputv->post = &this->post; xine_list_append_content(this->post.output, outputv); + this->post.xine_post.audio_input[0] = &port->new_port; + this->post.dispose = oscope_dispose; return &this->post; diff --git a/src/post/visualizations/visualizations.c b/src/post/visualizations/visualizations.c index 64f17c570..92a5df1fa 100644 --- a/src/post/visualizations/visualizations.c +++ b/src/post/visualizations/visualizations.c @@ -19,7 +19,7 @@ * * This file contains plugin entries for several visualization post plugins. * - * $Id: visualizations.c,v 1.9 2003/12/14 22:13:25 siggi Exp $ + * $Id: visualizations.c,v 1.10 2004/01/07 19:52:42 mroi Exp $ */ #ifdef HAVE_CONFIG_H @@ -48,8 +48,8 @@ post_info_t fftgraph_special_info = { XINE_POST_TYPE_AUDIO_VISUALIZATION }; plugin_info_t xine_plugin_info[] = { /* type, API, "name", version, special_info, init_function */ - { PLUGIN_POST, 7, "oscope", XINE_VERSION_CODE, &oscope_special_info, &oscope_init_plugin }, - { PLUGIN_POST, 7, "fftscope", XINE_VERSION_CODE, &fftscope_special_info, &fftscope_init_plugin }, - { PLUGIN_POST, 7, "fftgraph", XINE_VERSION_CODE, &fftgraph_special_info, &fftgraph_init_plugin }, + { PLUGIN_POST, 8, "oscope", XINE_VERSION_CODE, &oscope_special_info, &oscope_init_plugin }, + { PLUGIN_POST, 8, "fftscope", XINE_VERSION_CODE, &fftscope_special_info, &fftscope_init_plugin }, + { PLUGIN_POST, 8, "fftgraph", XINE_VERSION_CODE, &fftgraph_special_info, &fftgraph_init_plugin }, { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; |