XMMS2
xform.c
Go to the documentation of this file.
1 /* XMMS2 - X Music Multiplexer System
2  * Copyright (C) 2003-2011 XMMS2 Team
3  *
4  * PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  */
16 
17 
18 /** @file
19  *
20  */
21 
22 #include "xmmspriv/xmms_xform.h"
23 #include "xmmspriv/xmms_output.h"
25 #include "xmms/xmms_log.h"
26 
27 #include <glib.h>
28 #include <stdio.h>
29 #include <limits.h>
30 
31 #include "common.h"
32 
33 static gboolean xmms_vis_init (xmms_xform_t *xform);
34 static void xmms_vis_destroy (xmms_xform_t *xform);
35 static gint xmms_vis_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len,
36  xmms_error_t *error);
37 static gint64 xmms_vis_seek (xmms_xform_t *xform, gint64 offset,
39 
40 static gboolean
41 xmms_vis_plugin_setup (xmms_xform_plugin_t *xform_plugin)
42 {
43  xmms_xform_methods_t methods;
44 
45  XMMS_XFORM_METHODS_INIT (methods);
46 
47  methods.init = xmms_vis_init;
48  methods.destroy = xmms_vis_destroy;
49  methods.read = xmms_vis_read;
50  methods.seek = xmms_vis_seek;
51 
52  xmms_xform_plugin_methods_set (xform_plugin, &methods);
53 
54  xmms_xform_plugin_indata_add (xform_plugin,
56  "audio/pcm",
60  44100,
62 
63  return TRUE;
64 }
65 
66 
67 static gboolean
68 xmms_vis_init (xmms_xform_t *xform)
69 {
70  gint srate;
71 
72  g_return_val_if_fail (xform, FALSE);
73 
75  /* yeah, baby! ask mr. output & calculate your stuff here */
76 
78 
79  XMMS_DBG ("Visualization hook initialized successfully!");
80 
81  return TRUE;
82 }
83 
84 static void
85 xmms_vis_destroy (xmms_xform_t *xform)
86 {
87  g_return_if_fail (xform);
88 }
89 
90 static gint
91 xmms_vis_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len,
92  xmms_error_t *error)
93 {
94  gint read, chan;
95 
96  g_return_val_if_fail (xform, -1);
97 
99 
100  /* perhaps rework this later */
101  if (len > XMMSC_VISUALIZATION_WINDOW_SIZE * chan * sizeof (short)) {
102  len = XMMSC_VISUALIZATION_WINDOW_SIZE * chan * sizeof (short);
103  }
104 
105  read = xmms_xform_read (xform, buf, len, error);
106  if (read > 0) {
107  send_data (chan, read / sizeof (short), buf);
108  }
109 
110  return read;
111 }
112 
113 static gint64
114 xmms_vis_seek (xmms_xform_t *xform, gint64 offset, xmms_xform_seek_mode_t whence, xmms_error_t *err)
115 {
116  return xmms_xform_seek (xform, offset, whence, err);
117 }
118 
119 
120 XMMS_XFORM_BUILTIN (visualization,
121  "visualization hook",
122  XMMS_VERSION,
123  "visualization hook",
124  xmms_vis_plugin_setup);
125 
126 /** @} */
struct xmms_xform_plugin_St xmms_xform_plugin_t
Xform plugin.
void xmms_xform_plugin_indata_add(xmms_xform_plugin_t *plugin,...)
Add a valid input type to the plugin.
Definition: xform_plugin.c:79
struct xmms_xform_St xmms_xform_t
gboolean(* init)(xmms_xform_t *)
Initialisation method.
XMMS_XFORM_BUILTIN(visualization, "visualization hook", XMMS_VERSION, "visualization hook", xmms_vis_plugin_setup)
void xmms_sample_t
Definition: xmms_sample.h:58
enum xmms_xform_seek_mode_E xmms_xform_seek_mode_t
Seek direction argument.
Methods provided by an xform plugin.
void xmms_xform_plugin_methods_set(xmms_xform_plugin_t *plugin, xmms_xform_methods_t *methods)
Should be called once from the plugin&#39;s setupfunc.
Definition: xform_plugin.c:53
gint64 xmms_xform_seek(xmms_xform_t *xform, gint64 offset, xmms_xform_seek_mode_t whence, xmms_error_t *err)
Change offset in stream.
Definition: xform.c:1120
#define XMMSC_VISUALIZATION_WINDOW_SIZE
void(* destroy)(xmms_xform_t *)
Destruction method.
void send_data(int channels, int size, int16_t *buf)
void xmms_xform_outdata_type_copy(xmms_xform_t *xform)
Definition: xform.c:452
gint xmms_xform_read(xmms_xform_t *xform, gpointer buf, gint siz, xmms_error_t *err)
Read data from previous xform.
Definition: xform.c:1113
gint(* read)(xmms_xform_t *, gpointer, gint, xmms_error_t *)
Read method.
#define XMMS_DBG(fmt,...)
Definition: xmms_log.h:32
gint xmms_xform_indata_get_int(xmms_xform_t *xform, xmms_stream_type_key_t key)
Definition: xform.c:478
G_BEGIN_DECLS struct xmms_error_St xmms_error_t
#define XMMS_XFORM_METHODS_INIT(m)
gint64(* seek)(xmms_xform_t *, gint64, xmms_xform_seek_mode_t, xmms_error_t *)
Seek method.