diff options
Diffstat (limited to 'src/app/xineScope.c')
-rw-r--r-- | src/app/xineScope.c | 98 |
1 files changed, 75 insertions, 23 deletions
diff --git a/src/app/xineScope.c b/src/app/xineScope.c index 3e7cb69..55cf026 100644 --- a/src/app/xineScope.c +++ b/src/app/xineScope.c @@ -4,16 +4,38 @@ /* need access to port_ticket */ #define XINE_ENGINE_INTERNAL +#define LOG_MODULE "codine-scope" +#define LOG_LEVEL LOG_LEVEL_DEBUG +// #define LOG + #include "xineScope.h" #include <xine/post.h> #include <xine/xine_internal.h> +typedef struct scope_plugin_s { + post_plugin_t super; + int channels; + int64_t pts_per_smpls; + MyNode *list; +} scope_plugin_t; -static MyNode theList; -static int myChannels = 0; -static int64_t pts_per_smpls; +int scope_plugin_channels(void *post) +{ + scope_plugin_t *self = post; + return self->channels; +} -MyNode* const myList = &theList; +MyNode *scope_plugin_list(void *post) +{ + scope_plugin_t *self = post; + return self->list; +} + +int64_t scope_plugin_pts_per_smpls(void *post) +{ + scope_plugin_t *self = post; + return self->pts_per_smpls; +} /************************* * post plugin functions * @@ -22,7 +44,10 @@ MyNode* const myList = &theList; static int scope_port_open( xine_audio_port_t *port_gen, xine_stream_t *stream, uint32_t bits, uint32_t rate, int mode ) { + lprintf("scope_port_open()\n"); + post_audio_port_t *port = (post_audio_port_t *)port_gen; + scope_plugin_t *self = (scope_plugin_t *)port->post; _x_post_rewire( (post_plugin_t*)port->post ); _x_post_inc_usage( port ); @@ -32,14 +57,14 @@ scope_port_open( xine_audio_port_t *port_gen, xine_stream_t *stream, uint32_t bi port->rate = rate; port->mode = mode; - myChannels = _x_ao_mode2channels( mode ); + self->channels = _x_ao_mode2channels(mode); int ret = port->original_port->open( port->original_port, stream, bits, rate, mode ); #if XINE_MAJOR_VERSION > 1 || (XINE_MAJOR_VERSION == 1 && XINE_MINOR_VERSION > 2) || \ (XINE_MAJOR_VERSION == 1 && XINE_MINOR_VERSION == 2 && XINE_SUB_VERSION >= 10) - pts_per_smpls = ((uint32_t)90000 * (uint32_t)32768) / rate; + self->pts_per_smpls = ((uint32_t)90000 * (uint32_t)32768) / rate; #else - pts_per_smpls = stream->metronom->pts_per_smpls; + self->pts_per_smpls = stream->metronom->pts_per_smpls; #endif return ret; } @@ -47,7 +72,17 @@ scope_port_open( xine_audio_port_t *port_gen, xine_stream_t *stream, uint32_t bi static void scope_port_close( xine_audio_port_t *port_gen, xine_stream_t *stream ) { + lprintf("scope_port_close()\n"); + post_audio_port_t *port = (post_audio_port_t *)port_gen; + scope_plugin_t *self = (scope_plugin_t *)port->post; + + /* ensure the buffers are deleted during the next VideoWindow::timerEvent */ + MyNode *node; + for (node = self->list->next; node != self->list; node = node->next) + { + node->vpts = node->vpts_end - 1; + } port->stream = NULL; port->original_port->close( port->original_port, stream ); @@ -59,6 +94,7 @@ static void scope_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; + scope_plugin_t *self = (scope_plugin_t *)port->post; /* we are too simple to handle 8bit */ /* what does it mean when stream == NULL? */ @@ -66,7 +102,7 @@ scope_port_put_buffer( xine_audio_port_t *port_gen, audio_buffer_t *buf, xine_st port->original_port->put_buffer( port->original_port, buf, stream ); return; } MyNode *new_node; - const int num_samples = buf->num_frames * myChannels; + const int num_samples = buf->num_frames * self->channels; new_node = malloc( sizeof(MyNode) ); #ifdef METRONOM_VPTS @@ -80,7 +116,7 @@ scope_port_put_buffer( xine_audio_port_t *port_gen, audio_buffer_t *buf, xine_st { int64_t - K = pts_per_smpls; /*smpls = 1<<16 samples*/ + K = self->pts_per_smpls; /*smpls = 1<<16 samples*/ K *= num_samples; K /= (1<<16); K += new_node->vpts; @@ -93,14 +129,29 @@ scope_port_put_buffer( xine_audio_port_t *port_gen, audio_buffer_t *buf, xine_st /* finally we should append the current buffer to the list * NOTE this is thread-safe due to the way we handle the list in the GUI thread */ - new_node->next = myList->next; - myList->next = new_node; + new_node->next = self->list->next; + self->list->next = new_node; } static void scope_dispose( post_plugin_t *this ) { - free( this ); + MyNode *list = ((scope_plugin_t *)this)->list; + MyNode *prev; + MyNode *node = list; + + /* Free all elements of the list (a ring buffer) */ + do + { + prev = node->next; + + free(node->mem); + free(node); + + node = prev; + } while(node != list); + + free(this); } @@ -118,15 +169,15 @@ xine_post_t* scope_plugin_new( xine_t *xine, xine_audio_port_t *audio_target ) if( audio_target == NULL ) return NULL; - post_plugin_t *post_plugin = calloc( 1, sizeof(post_plugin_t) ); + scope_plugin_t *scope_plugin = calloc(1, sizeof(scope_plugin_t)); + post_plugin_t *post_plugin = (post_plugin_t *)scope_plugin; { - post_plugin_t *this = post_plugin; post_in_t *input; post_out_t *output; post_audio_port_t *port; - _x_post_init( this, 1, 0 ); + _x_post_init(post_plugin, 1, 0); #if XINE_MAJOR_VERSION > 1 || (XINE_MAJOR_VERSION == 1 && XINE_MINOR_VERSION > 2) || \ (XINE_MAJOR_VERSION == 1 && XINE_MINOR_VERSION == 2 && XINE_SUB_VERSION >= 10) @@ -138,10 +189,10 @@ xine_post_t* scope_plugin_new( xine_t *xine, xine_audio_port_t *audio_target ) port->new_port.close = scope_port_close; port->new_port.put_buffer = scope_port_put_buffer; - this->xine_post.audio_input[0] = &port->new_port; - this->xine_post.type = PLUGIN_POST; + post_plugin->xine_post.audio_input[0] = &port->new_port; + post_plugin->xine_post.type = PLUGIN_POST; - this->dispose = scope_dispose; + post_plugin->dispose = scope_dispose; } #if XINE_MAJOR_VERSION < 1 || (XINE_MAJOR_VERSION == 1 && XINE_MINOR_VERSION < 2) || \ @@ -153,6 +204,12 @@ xine_post_t* scope_plugin_new( xine_t *xine, xine_audio_port_t *audio_target ) post_plugin->xine = xine; #endif + /* scope_plugin_t init */ + scope_plugin->channels = 0; + scope_plugin->pts_per_smpls = 0; + scope_plugin->list = calloc(1, sizeof(MyNode)); + scope_plugin->list->next = scope_plugin->list; + #if XINE_MAJOR_VERSION > 1 || (XINE_MAJOR_VERSION == 1 && XINE_MINOR_VERSION > 2) || \ (XINE_MAJOR_VERSION == 1 && XINE_MINOR_VERSION == 2 && XINE_SUB_VERSION >= 10) return post_plugin; @@ -161,11 +218,6 @@ xine_post_t* scope_plugin_new( xine_t *xine, xine_audio_port_t *audio_target ) #endif } -int64_t scope_plugin_pts_per_smpls( void *post ) -{ - return pts_per_smpls; -} - #if XINE_MAJOR_VERSION > 1 || (XINE_MAJOR_VERSION == 1 && XINE_MINOR_VERSION > 2) || \ (XINE_MAJOR_VERSION == 1 && XINE_MINOR_VERSION == 2 && XINE_SUB_VERSION >= 10) static void *scope_init_plugin(xine_t *xine, const void *data) |