| file:
src/plugin_main.c |
| #include
<xmms/plugin.h> VisPlugin part2_vp = { NULL,NULL,0, "Autotools example 2", 0,0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; VisPlugin *get_vplugin_info(void) { return &part2_vp; } |
| typedef
struct _VisPlugin { /* Filled in by xmms */ void *handle; /* Filled in by xmms */ char *filename; /* The session ID for attaching to the control socket */ int xmms_session; /* The description that is shown in the preferences box */ char *description; /* Numbers of PCM channels wanted in the call to render_pcm */ int num_pcm_chs_wanted; /* Numbers of freq channels wanted in the call to render_freq */ int num_freq_chs_wanted; /* Called when the plugin is enabled */ void (*init)(void); /* Called when the plugin is disabled */ void (*cleanup)(void); /* Callback to show the about box */ void (*about)(void); /* Callback to show the configure box */ void (*configure)(void); /* Call this with a pointer to your plugin to disable the plugin */ void (*disable_plugin)(struct _VisPlugin *); /* Called when playback starts */ void (*playback_start)(void); /* Called when playback stops */ void (*playback_stop)(void); /* Render the PCM data (don't do anything time consuming in here) */ void (*render_pcm)(gint16 pcm_data[2][512]); /* Render the freq data (don't do anything time consuming in here) */ void (*render_freq)(gint16 freq_data[2][256]); } VisPlugin; |
| file:
configure.in |
| AC_PREREQ(2.58) AC_INIT(Tutorial part 3,1.0.0,[email@hotmail.com],example3) AC_CANONICAL_TARGET([]) AM_INIT_AUTOMAKE([example3],[1.0.0]) AC_CONFIG_SRCDIR([src/plugin_main.c]) AM_CONFIG_HEADER([config.h]) AM_DISABLE_STATIC AC_PROG_CC AC_PROG_INSTALL AC_PROG_LIBTOOL AM_PATH_XMMS(1.2.9,,AC_MSG_ERROR([XMMS >= 1.2.9 not installed])) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT |
| file:
src/Makefile.am |
| lib_LTLIBRARIES = libexample3.la AM_CFLAGS = -Wall @XMMS_CFLAGS@ @CFLAGS@ libexample3_la_LDFLAGS = -module -avoid-version libexample3_la_SOURCES = plugin_main.c |
| file:
src/plugin_main.c |
| #include <xmms/plugin.h> #include <stdio.h> static void example_init(void) { printf("Init\n"); } static void example_cleanup(void) { printf("Cleanup\n"); } static void example_disable(void) { printf("Disable\n"); } static void example_play(void) { printf("Start\n"); } static void example_stop(void) { printf("Stop\n"); } VisPlugin example_vp = { NULL,NULL,0, "Autotools example 3", 0,0, example_init, example_cleanup, NULL, NULL, example_disable, example_play, example_stop, NULL, NULL }; VisPlugin *get_vplugin_info(void) { return &example_vp; } |
| aclocal libtoolize --force --copy autoheader autoconf automake -a -c |
| file:
configure.in |
| AC_PREREQ(2.58) AC_INIT(Tutorial part 4,1.0.0,[email@hotmail.com],example4) AC_CANONICAL_TARGET([]) AM_INIT_AUTOMAKE([example4],[1.0.0]) AC_CONFIG_SRCDIR([src/plugin_main.c]) AM_CONFIG_HEADER([config.h]) AM_DISABLE_STATIC AC_PROG_CC AC_PROG_INSTALL AC_PROG_LIBTOOL AM_PATH_XMMS(1.2.9,,AC_MSG_ERROR([XMMS >= 1.2.9 not installed])) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT |
| file:
src/Makefile.am |
| lib_LTLIBRARIES = libexample4.la AM_CFLAGS = -Wall @XMMS_CFLAGS@ @CFLAGS@ libexample4_la_LDFLAGS = -module -avoid-version libexample4_la_SOURCES = plugin_main.c |
| file:
src/plugin_main.c |
| #include <xmms/plugin.h> #include <pthread.h> #include <string.h> #include <stdio.h> #include <unistd.h> // Functions predefined here static void example_pcm_callback(gint16 data[2][512]); static void example_init(void); static void example_cleanup(void); static void example_play(void); static void example_stop(void); void *example_worker(void *); // Define global variables gint16 databuffer[2][512]; static pthread_t worker_thread; static pthread_attr_t worker_attr; int worker_running,worker_status,xmms_status; // Visualization plugin structure VisPlugin example_vp = { NULL,NULL,0, "Autotools example 4", 2, // 2 pcm channels 0, // 0 freq channels example_init, example_cleanup, NULL, NULL, NULL, example_play, example_stop, example_pcm_callback, NULL }; // ----------------------- // PCM callback routine // ----------------------- static void example_pcm_callback(gint16 data[2][512]) { // Make a copy of pcm data for worker function if(worker_status==0) { memcpy(databuffer[0],data[0],512); memcpy(databuffer[1],data[1],512); worker_status=1; } else { // If for some reason we have new datapacket to // process, but our worker is not ready, then // print out a warning printf("!"); } } // ----------------------- // Worker routine // ----------------------- void *example_worker(void *arg) { int i; double left_val,right_val; // Thread mainloop while(worker_running==1) { // do work only if xmms is in playback state, // and we have something new to process if(xmms_status==1 && worker_status!=0) { // Calculate avarage value left_val=0; right_val=0; for(i=0; i<512; i++) { left_val+=(double)databuffer[0][i]; right_val+=(double)databuffer[0][i]; } left_val/=512.0; right_val/=512.0; printf("(%.2f , %.2f)\n",left_val,right_val); // acknowledge datapacket worker_status=0; } // Wait about 4ms, and check loop status every 1ms // [ note: usleep gives cpu time to multitasking, so // if machine is heavily loaded, this loop might // take longer than 10ms ] for(i=0; i<4; i++) { usleep(1000); if(worker_running==0) pthread_exit(0); } } // Exit thread pthread_exit(0); } // ----------------------- // START / STOP / INIT / CLEANUP // ----------------------- static void example_init(void) { worker_running=1; // enable worker loop worker_status=0; // no new datapackets xmms_status=0; // playback stopped // Create worker thread pthread_attr_init(&worker_attr); pthread_attr_setdetachstate(&worker_attr, PTHREAD_CREATE_JOINABLE); pthread_create(&worker_thread, &worker_attr, example_worker, NULL); pthread_attr_destroy(&worker_attr); } static void example_cleanup(void) { // Disable worker loop worker_running=0; // Wait a second, for worker to quit sleep(1); } static void example_play(void) { xmms_status=1; } static void example_stop(void) { xmms_status=0; } // ----------------------- // Function required by xmms // ----------------------- VisPlugin *get_vplugin_info(void) { return &example_vp; } |