annotate Plugins/Output/arts/audio.c @ 1083:9414f79e856f trunk

[svn] - disable expand/fill
author nenolod
date Fri, 19 May 2006 13:09:35 -0700
parents 03712a532f1c
children 14e6dd38e108
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
810
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
1 /*
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
2 * aRts ouput plugin for xmms
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
3 *
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
4 * Copyright (C) 2000,2003 Haavard Kvaalen <havardk@xmms.org>
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
5 *
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
6 * Licenced under GNU GPL version 2.
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
7 *
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
8 * Audacious port by Giacomo Lozito from develia.org
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
9 *
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
10 */
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
11
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
12 #include "arts.h"
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
13 #include "arts_helper/arts_helper.h"
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
14 #include <errno.h>
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
15 #include <signal.h>
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
16 #include <pthread.h>
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
17
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
18 #include <sys/types.h>
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
19 #include <sys/socket.h>
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
20 #include <sys/wait.h>
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
21 #include <unistd.h>
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
22
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
23 static gboolean going, paused, helper_failed;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
24 static guint64 written;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
25 static struct params_info input_params, output_params;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
26 static int helperfd;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
27 static pid_t helper_pid;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
28
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
29 static int (*arts_convert_func)(void **data, int length);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
30 struct arts_config artsxmms_cfg;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
31
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
32 struct {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
33 int left, right;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
34 } volume = {100, 100};
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
35
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
36
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
37 typedef struct format_info {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
38 AFormat format;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
39 long frequency;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
40 int channels;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
41 long bps;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
42 } format_info_t;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
43
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
44 static format_info_t input;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
45 static format_info_t effect;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
46 static format_info_t output;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
47
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
48
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
49 void artsxmms_tell_audio(AFormat * fmt, gint * srate, gint * nch)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
50 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
51 (*fmt) = input.format;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
52 (*srate) = input.frequency;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
53 (*nch) = input.channels;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
54 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
55
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
56
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
57 void artsxmms_init(void)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
58 {
1034
03712a532f1c [svn] Convert from deprecated configfile interace to configdb, closes bug #494.
chainsaw
parents: 810
diff changeset
59 ConfigDb *db;
810
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
60
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
61 memset(&artsxmms_cfg, 0, sizeof (artsxmms_cfg));
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
62
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
63 artsxmms_cfg.buffer_size = 400;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
64
1034
03712a532f1c [svn] Convert from deprecated configfile interace to configdb, closes bug #494.
chainsaw
parents: 810
diff changeset
65 db = bmp_cfg_db_open();
03712a532f1c [svn] Convert from deprecated configfile interace to configdb, closes bug #494.
chainsaw
parents: 810
diff changeset
66 bmp_cfg_db_get_int(db, "arts", "buffer_size",
810
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
67 &artsxmms_cfg.buffer_size);
1034
03712a532f1c [svn] Convert from deprecated configfile interace to configdb, closes bug #494.
chainsaw
parents: 810
diff changeset
68 bmp_cfg_db_close(db);
810
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
69 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
70
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
71
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
72 static int read_all(int fd, void *buf, size_t count)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
73 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
74 size_t left = count;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
75 int r;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
76 do {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
77 r = read(fd, buf, left);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
78 if (r < 0)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
79 return -1;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
80 left -= r;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
81 buf = (char *)buf + r;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
82 } while (left > 0 && r > 0);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
83 return count - left;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
84 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
85
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
86 static int write_all(int fd, const void *buf, size_t count)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
87 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
88 size_t left = count;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
89 int w;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
90 do {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
91 w = write(fd, buf, left);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
92 if (w < 0)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
93 return -1;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
94 left -= w;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
95 buf = (char *)buf + w;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
96 } while (left > 0 && w > 0);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
97 /* g_message("wrote: %d", count - left); */
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
98 return count - left;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
99 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
100
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
101 static int wait_for_helper(int fd)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
102 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
103 struct timeval timeout;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
104 fd_set rdfs;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
105 int sr;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
106
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
107 FD_ZERO(&rdfs);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
108 FD_SET(fd, &rdfs);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
109
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
110 timeout.tv_sec = 10;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
111 timeout.tv_usec = 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
112
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
113 sr = select(fd + 1, &rdfs, NULL, NULL, &timeout);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
114 if (sr < 0) {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
115 g_message("wait_for_helper(): select failed: %s",
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
116 strerror(errno));
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
117 return -1;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
118 } else if (!sr) {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
119 g_message("wait_for_helper(): Timed out waiting for helper");
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
120 return -1;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
121 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
122 return 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
123 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
124
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
125 static int xx;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
126
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
127 static int helper_cmd_data(int cmd, int idata, void* ptr, int data_length)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
128 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
129 static pthread_mutex_t artsm = PTHREAD_MUTEX_INITIALIZER;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
130 struct command out;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
131 struct response in;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
132 int status;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
133
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
134 out.cmd = cmd;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
135 out.data = idata;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
136 out.data_length = data_length;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
137 xx++;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
138
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
139 if (helper_failed)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
140 goto failed;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
141
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
142 pthread_mutex_lock(&artsm);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
143 /* fprintf(stderr, "Sending %d; ", out.cmd); */
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
144 if (write_all(helperfd, &out, sizeof (out)) != sizeof (out))
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
145 goto failed;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
146 if (data_length > 0)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
147 if (write_all(helperfd, ptr, data_length) != data_length)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
148 goto failed;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
149
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
150 if (wait_for_helper(helperfd)) {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
151 g_message("waiting failed: %d", cmd);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
152 goto failed;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
153 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
154
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
155 if (read_all(helperfd, &in, sizeof (in)) != sizeof (in))
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
156 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
157 g_message("read failed: %d", cmd);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
158 goto failed;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
159 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
160
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
161 /* fprintf(stderr, "%d complete\n", out.cmd); */
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
162 pthread_mutex_unlock(&artsm);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
163
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
164 if (in.status)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
165 return -in.status;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
166 return in.data;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
167
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
168 failed:
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
169 g_message("helper_cmd_data(): failed");
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
170 helper_failed = TRUE;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
171 if (helper_pid && waitpid(helper_pid, &status, WNOHANG)) {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
172 if (status)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
173 g_message("helper terminated abnormally: %d", status);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
174 else
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
175 g_message("helper terminated normally");
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
176 helper_pid = 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
177 } else if (helper_pid)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
178 g_message("helper has not terminated");
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
179 pthread_mutex_unlock(&artsm);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
180 return -STATUS_FAILED;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
181 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
182
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
183 static int helper_cmd(int cmd, int idata)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
184 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
185 return helper_cmd_data(cmd, idata, NULL, 0);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
186 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
187
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
188 static int artsxmms_helper_init(struct params_info *params)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
189 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
190 int ret;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
191 struct init_data id;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
192
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
193 id.version = HELPER_VERSION;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
194 id.resolution = params->resolution;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
195 id.rate= params->frequency;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
196 id.nchannels = params->channels;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
197 id.buffer_time = artsxmms_cfg.buffer_size;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
198
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
199 ret = helper_cmd_data(CMD_INIT, 0, &id, sizeof (id));
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
200 if (ret) {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
201 g_message("Init failed: %d", -ret);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
202 return -1;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
203 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
204
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
205 return 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
206 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
207
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
208 static void artsxmms_set_params(struct params_info *params, AFormat fmt, int rate, int nch)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
209 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
210 params->format = fmt;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
211 params->frequency = rate;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
212 params->channels = nch;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
213
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
214 params->bps = rate * nch;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
215 params->resolution = 8;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
216 if (!(fmt == FMT_U8 || fmt == FMT_S8))
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
217 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
218 params->bps *= 2;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
219 params->resolution = 16;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
220 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
221 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
222
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
223 int artsxmms_get_written_time(void)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
224 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
225 if (!going)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
226 return 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
227
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
228 return (written * 1000) / output_params.bps;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
229 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
230
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
231 int artsxmms_get_output_time(void)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
232 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
233 int time;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
234
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
235 if (!going)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
236 return 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
237 if (helper_failed)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
238 return -2;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
239
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
240 time = artsxmms_get_written_time();
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
241 time -= helper_cmd(CMD_GET_OUTPUT_LATENCY, 0);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
242
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
243 if (time < 0)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
244 return 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
245 return time;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
246 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
247
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
248 int artsxmms_playing(void)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
249 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
250 if (!going)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
251 return FALSE;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
252
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
253 if (!paused)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
254 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
255 if (helper_cmd(CMD_QUERY_PLAYING, 0) <= 0)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
256 return FALSE;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
257 return TRUE;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
258 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
259
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
260 return TRUE;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
261 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
262
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
263 int artsxmms_free(void)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
264 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
265 int space;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
266
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
267 if (!going)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
268 return 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
269
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
270 space = helper_cmd(CMD_FREE, 0);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
271 if (space < 0)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
272 return 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
273
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
274 return space;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
275 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
276
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
277 void artsxmms_write(gpointer ptr, int length)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
278 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
279 AFormat new_format;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
280 int new_frequency, new_channels;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
281 EffectPlugin *ep;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
282
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
283 new_format = input_params.format;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
284 new_frequency = input_params.frequency;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
285 new_channels = input_params.channels;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
286
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
287 ep = get_current_effect_plugin();
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
288 if (effects_enabled() && ep && ep->query_format)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
289 ep->query_format(&new_format, &new_frequency, &new_channels);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
290
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
291 if (new_format != output_params.format ||
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
292 new_frequency != output_params.frequency ||
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
293 new_channels != output_params.channels)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
294 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
295 /*
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
296 * The effect plugins has changed the format of the stream.
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
297 */
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
298
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
299 guint64 offset = (written * 1000) / output_params.bps;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
300 artsxmms_set_params(&output_params, new_format,
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
301 new_frequency, new_channels);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
302 arts_convert_func = arts_get_convert_func(output_params.format);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
303
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
304 written = (offset * output_params.bps) / 1000;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
305
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
306 artsxmms_helper_init(&output_params);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
307 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
308
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
309 /*
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
310 * Doing the effect plugin processing here adds some latency,
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
311 * but the alternative is just too frigging hairy.
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
312 */
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
313
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
314 if (effects_enabled() && ep && ep->mod_samples)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
315 length = ep->mod_samples(&ptr, length, input_params.format,
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
316 input_params.frequency,
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
317 input_params.channels);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
318
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
319 if (arts_convert_func)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
320 arts_convert_func(ptr, length);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
321
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
322 helper_cmd_data(CMD_WRITE, 0, ptr, length);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
323 written += length;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
324 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
325
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
326 void artsxmms_close(void)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
327 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
328 int status;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
329 going = 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
330 /* g_message("sending quit cmd"); */
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
331 if (!helper_cmd(CMD_QUIT, 0)) {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
332 waitpid(helper_pid, &status, 0);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
333 if (status)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
334 g_message("artsxmms_close(): Child exited abnormally: %d",
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
335 status);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
336 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
337 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
338
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
339 void artsxmms_flush(int time)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
340 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
341 /*
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
342 * Argh, no way to flush the stream from the C api.
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
343 */
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
344 written = (time / 10) * (output_params.bps / 100);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
345
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
346 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
347
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
348 void artsxmms_pause(short p)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
349 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
350 paused = p;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
351 helper_cmd(CMD_PAUSE, p);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
352 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
353
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
354 static int artsxmms_start_helper()
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
355 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
356 int sockets[2];
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
357
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
358 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) < 0)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
359 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
360 g_message("artsxmms_start_helper(): "
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
361 "Failed to create socketpair: %s", strerror(errno));
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
362 return -1;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
363 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
364
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
365 if ((helper_pid = fork()) == 0)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
366 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
367 /* Child */
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
368 char sockfdstr[10];
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
369 close(sockets[1]);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
370 sprintf(sockfdstr, "%d", sockets[0]);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
371 execlp("audacious-arts-helper", "audacious-arts-helper",
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
372 sockfdstr, NULL);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
373 g_warning("artsxmms_start_helper(): "
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
374 "Failed to start audacious-arts-helper: %s", strerror(errno));
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
375 close(sockets[0]);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
376 _exit(1);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
377 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
378 close(sockets[0]);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
379 helperfd = sockets[1];
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
380
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
381 if (helper_pid < 0)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
382 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
383 g_message("artsxmms_start_helper(): "
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
384 "Failed to fork() helper process: %s", strerror(errno));
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
385 close(sockets[1]);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
386 return -1;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
387 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
388
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
389 return 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
390 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
391
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
392 int artsxmms_open(AFormat fmt, int rate, int nch)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
393 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
394 if (artsxmms_start_helper() < 0)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
395 return 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
396
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
397 artsxmms_set_params(&input_params, fmt, rate, nch);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
398 artsxmms_set_params(&output_params, fmt, rate, nch);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
399
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
400 arts_convert_func = arts_get_convert_func(output_params.format);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
401
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
402 written = 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
403 paused = 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
404 helper_failed = FALSE;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
405
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
406 if (artsxmms_helper_init(&output_params)) {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
407 artsxmms_close();
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
408 return 0;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
409 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
410 artsxmms_set_volume(volume.left, volume.right);
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
411
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
412 going = 1;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
413 return 1;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
414 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
415
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
416 void artsxmms_get_volume(int *l, int *r)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
417 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
418 *l = volume.left;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
419 *r = volume.right;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
420 }
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
421
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
422 void artsxmms_set_volume(int l, int r)
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
423 {
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
424 int vol[2];
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
425 volume.left = l;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
426 volume.right = r;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
427 vol[0] = l;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
428 vol[1] = r;
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
429 helper_cmd_data(CMD_SET_VOLUME, 0, vol, sizeof(vol));
e9509e909193 [svn] ported xmms-arts 0.7.1 to audacious and integrated it in the build process
giacomo
parents:
diff changeset
430 }