XMMS2

src/xmms/visualization/xform.c

Go to the documentation of this file.
00001 /*  XMMS2 - X Music Multiplexer System
00002  *  Copyright (C) 2003-2009 XMMS2 Team
00003  *
00004  *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Lesser General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2.1 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Lesser General Public License for more details.
00015  */
00016 
00017 
00018 /** @file
00019  *
00020  */
00021 
00022 #include "xmmspriv/xmms_xform.h"
00023 #include "xmmspriv/xmms_output.h"
00024 #include "xmmspriv/xmms_visualization.h"
00025 #include "xmms/xmms_log.h"
00026 
00027 #include <glib.h>
00028 #include <stdio.h>
00029 #include <limits.h>
00030 
00031 #include "common.h"
00032 
00033 static gboolean xmms_vis_init (xmms_xform_t *xform);
00034 static void xmms_vis_destroy (xmms_xform_t *xform);
00035 static gint xmms_vis_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len,
00036                           xmms_error_t *error);
00037 static gint64 xmms_vis_seek (xmms_xform_t *xform, gint64 offset,
00038                             xmms_xform_seek_mode_t whence, xmms_error_t *err);
00039 
00040 static gboolean
00041 xmms_vis_plugin_setup (xmms_xform_plugin_t *xform_plugin)
00042 {
00043     xmms_xform_methods_t methods;
00044 
00045     XMMS_XFORM_METHODS_INIT (methods);
00046 
00047     methods.init = xmms_vis_init;
00048     methods.destroy = xmms_vis_destroy;
00049     methods.read = xmms_vis_read;
00050     methods.seek = xmms_vis_seek;
00051 
00052     xmms_xform_plugin_methods_set (xform_plugin, &methods);
00053 
00054     xmms_xform_plugin_indata_add (xform_plugin,
00055                                   XMMS_STREAM_TYPE_MIMETYPE,
00056                                   "audio/pcm",
00057                                   XMMS_STREAM_TYPE_FMT_FORMAT,
00058                                   XMMS_SAMPLE_FORMAT_S16,
00059                                   XMMS_STREAM_TYPE_FMT_SAMPLERATE,
00060                                   44100,
00061                                   XMMS_STREAM_TYPE_END);
00062 
00063     return TRUE;
00064 }
00065 
00066 
00067 static gboolean
00068 xmms_vis_init (xmms_xform_t *xform)
00069 {
00070     gint srate;
00071 
00072     g_return_val_if_fail (xform, FALSE);
00073 
00074     srate = xmms_xform_indata_get_int (xform, XMMS_STREAM_TYPE_FMT_SAMPLERATE);
00075     /* yeah, baby! ask mr. output & calculate your stuff here */
00076 
00077     xmms_xform_outdata_type_copy (xform);
00078 
00079     XMMS_DBG ("Visualization hook initialized successfully!");
00080 
00081     return TRUE;
00082 }
00083 
00084 static void
00085 xmms_vis_destroy (xmms_xform_t *xform)
00086 {
00087     g_return_if_fail (xform);
00088 }
00089 
00090 static gint
00091 xmms_vis_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len,
00092               xmms_error_t *error)
00093 {
00094     gint read, chan;
00095 
00096     g_return_val_if_fail (xform, -1);
00097 
00098     chan = xmms_xform_indata_get_int (xform, XMMS_STREAM_TYPE_FMT_CHANNELS);
00099 
00100     /* perhaps rework this later */
00101     if (len > XMMSC_VISUALIZATION_WINDOW_SIZE * chan * sizeof (short)) {
00102         len = XMMSC_VISUALIZATION_WINDOW_SIZE * chan * sizeof (short);
00103     }
00104 
00105     read = xmms_xform_read (xform, buf, len, error);
00106     if (read > 0) {
00107         send_data (chan, read / sizeof (short), buf);
00108     }
00109 
00110     return read;
00111 }
00112 
00113 static gint64
00114 xmms_vis_seek (xmms_xform_t *xform, gint64 offset, xmms_xform_seek_mode_t whence, xmms_error_t *err)
00115 {
00116     return xmms_xform_seek (xform, offset, whence, err);
00117 }
00118 
00119 
00120 XMMS_XFORM_BUILTIN (visualization,
00121                     "visualization hook",
00122                     XMMS_VERSION,
00123                     "visualization hook",
00124                     xmms_vis_plugin_setup);
00125 
00126 /** @} */