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"
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
33static gboolean xmms_vis_init (xmms_xform_t *xform);
34static void xmms_vis_destroy (xmms_xform_t *xform);
35static gint xmms_vis_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len,
36 xmms_error_t *error);
37static gint64 xmms_vis_seek (xmms_xform_t *xform, gint64 offset,
39
40static gboolean
41xmms_vis_plugin_setup (xmms_xform_plugin_t *xform_plugin)
42{
44
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
67static gboolean
68xmms_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
84static void
85xmms_vis_destroy (xmms_xform_t *xform)
86{
87 g_return_if_fail (xform);
88}
89
90static gint
91xmms_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
113static gint64
114xmms_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
120XMMS_XFORM_BUILTIN (visualization,
121 "visualization hook",
122 XMMS_VERSION,
123 "visualization hook",
124 xmms_vis_plugin_setup);
125
126/** @} */
void send_data(int channels, int size, int16_t *buf)
#define XMMSC_VISUALIZATION_WINDOW_SIZE
struct xmms_xform_plugin_St xmms_xform_plugin_t
Xform plugin.
struct xmms_xform_St xmms_xform_t
void xmms_xform_plugin_indata_add(xmms_xform_plugin_t *plugin,...)
Add a valid input type to the plugin.
Definition: xform_plugin.c:79
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
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
void xmms_xform_plugin_methods_set(xmms_xform_plugin_t *plugin, xmms_xform_methods_t *methods)
Should be called once from the plugin's setupfunc.
Definition: xform_plugin.c:53
void xmms_xform_outdata_type_copy(xmms_xform_t *xform)
Definition: xform.c:452
enum xmms_xform_seek_mode_E xmms_xform_seek_mode_t
Seek direction argument.
gint xmms_xform_indata_get_int(xmms_xform_t *xform, xmms_stream_type_key_t key)
Definition: xform.c:478
#define XMMS_XFORM_METHODS_INIT(m)
Methods provided by an xform plugin.
gboolean(* init)(xmms_xform_t *)
Initialisation method.
gint64(* seek)(xmms_xform_t *, gint64, xmms_xform_seek_mode_t, xmms_error_t *)
Seek method.
void(* destroy)(xmms_xform_t *)
Destruction method.
gint(* read)(xmms_xform_t *, gpointer, gint, xmms_error_t *)
Read method.
#define XMMS_DBG(fmt,...)
Definition: xmms_log.h:32
void xmms_sample_t
Definition: xmms_sample.h:58
@ XMMS_SAMPLE_FORMAT_S16
Definition: xmms_sample.h:29
@ XMMS_STREAM_TYPE_MIMETYPE
@ XMMS_STREAM_TYPE_FMT_FORMAT
@ XMMS_STREAM_TYPE_FMT_SAMPLERATE
@ XMMS_STREAM_TYPE_FMT_CHANNELS
@ XMMS_STREAM_TYPE_END
G_BEGIN_DECLS struct xmms_error_St xmms_error_t
#define XMMS_XFORM_BUILTIN(shname, name, ver, desc, setupfunc)
Definition: xmms_xform.h:53