summaryrefslogtreecommitdiff
path: root/audio/gqmpeg/patches/patch-ac
blob: edf3a78f27c079548dbd1c377cbe671257a46ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
$NetBSD: patch-ac,v 1.9 2002/03/25 06:25:01 lukem Exp $

--- src/io_ogg123.c.orig	Sat Feb 23 04:39:13 2002
+++ src/io_ogg123.c	Mon Mar 25 17:16:37 2002
@@ -47,6 +47,62 @@ static gint ogg123_child_pid = -1;
 static int ogg123_pipe[2];
 
 /*
+ *-----------------------------------------------------------------------------
+ * pipe functions
+ *-----------------------------------------------------------------------------
+ */
+
+static gint ogg123_pipe_open(char *ogg_argv[], gint *ogg_child,
+    int ogg_pipe[2])
+{
+	pid_t frk_pid;
+
+	/* Create the pipe. */
+	if (pipe(ogg_pipe))
+                {
+                fprintf (stderr, _("Pipe failed.\n"));
+                return FALSE;
+                }
+
+        if (debug_mode) printf("ogg123_pipe_open: %s\n", ogg_argv[0]);
+
+	/* Create the child process. */
+	frk_pid = fork ();
+	if (frk_pid == (pid_t) 0)
+		{
+		/* This is the child process. */
+		dup2(ogg_pipe[1], 1);
+		dup2(ogg_pipe[1], 2);
+		close(ogg_pipe[0]);
+
+		execvp(ogg_argv[0], ogg_argv);
+		printf(_("unable to run %s (in the path?)\n"), ogg_argv);
+		_exit(1);
+		}
+	else if (frk_pid < (pid_t) 0)
+		{
+		/* The fork failed. */
+		fprintf (stderr, _("Fork failed.\n"));
+		close(ogg_pipe[0]);
+		close(ogg_pipe[1]);
+		*ogg_child = -1;
+		return FALSE;
+		}
+	else
+		{
+		/* This is the parent process. */
+		*ogg_child = (int) frk_pid;
+
+		close(ogg_pipe[1]);
+		ogg_pipe[1] = -1;
+		}
+
+	if (debug_mode) printf("ogg123_pipe_open pid = %d\n", *ogg_child);
+
+	return TRUE;
+}
+
+/*
  *----------------------------------------------------------------------------
  * title/description utils
  *----------------------------------------------------------------------------
@@ -100,21 +156,22 @@ OGGInfo *ogg123_info_get(const gchar *pa
 {
 	OGGInfo *info = NULL;
 	FILE *f;
-	gchar *command;
+	char *command[3];
+	gint child_pid;
+	int child_pipe[2];
 	char buf[128];
 
 	if (!ogg123_info_found) return NULL;
+	command[0] = OGG123_BINARY_INFO;
+	command[1] = (char *)path;
+	command[2] = NULL;
 
-	command = g_strdup_printf("%s \"%s\"", OGG123_BINARY_INFO, path);
-	f = popen(command, "r");
-	if (!f)
+	if (ogg123_pipe_open(command, &child_pid, child_pipe) == FALSE
+	    || (f = fdopen(child_pipe[0], "r")) == NULL)
 		{
-		printf("Failed to run \"%s\n\"", command);
-		g_free(command);
+		printf("Failed to run \"%s\n\"", command[0]);
 		return NULL;
 		}
-	g_free(command);
-
 	info = g_new0(OGGInfo, 1);
 
 	while (fgets(buf, sizeof(buf), f) != NULL)
@@ -163,7 +220,7 @@ OGGInfo *ogg123_info_get(const gchar *pa
 			}
 		}
 
-	pclose(f);
+	close(child_pipe[0]);
 
 	info->bytes = filesize(path);
 
@@ -178,20 +235,23 @@ GList *ogg123_comment_get(const gchar *p
 {
 	GList *list = NULL;
 	FILE *f;
-	gchar *command;
+	char *command[4];
+	gint child_pid;
+	int child_pipe[2];
 	char buf[128];
 
 	if (!ogg123_comment_found) return NULL;
+	command[0] = OGG123_BINARY_COMMENT;
+	command[1] = "-l";
+	command[2] = (char *)path;
+	command[3] = NULL;
 
-	command = g_strdup_printf("%s -l \"%s\"", OGG123_BINARY_COMMENT, path);
-	f = popen(command, "r");
-	if (!f)
+	if (ogg123_pipe_open(command, &child_pid, child_pipe) == FALSE
+	    || (f = fdopen(child_pipe[0], "r")) == NULL)
 		{
-		printf("Failed to run \"%s\n\"", command);
-		g_free(command);
+		printf("Failed to run \"%s\n\"", command[0]);
 		return NULL;
 		}
-	g_free(command);
 
 	while (fgets(buf, sizeof(buf), f) != NULL)
 		{
@@ -214,7 +274,7 @@ GList *ogg123_comment_get(const gchar *p
 		g_free(key);
 		}
 
-	pclose(f);
+	close(child_pipe[0]);
 
 	return g_list_reverse(list);
 }
@@ -250,16 +310,36 @@ const gchar *ogg123_comment_value(GList 
 gint ogg123_comment_set(const gchar *path, GList *comments)
 {
 	FILE *f;
-	gchar *command;
 	GList *errlist;
 	GList *work;
 	char buf[128];
-	gchar *tmp;
+	int argc, i;
+	char **argv;
+	gint child_pid;
+	int child_pipe[2];
 	
 	if (!ogg123_comment_found) return TRUE;
 	if (!path) return FALSE;
 
-	command = g_strdup_printf("%s -w \"%s\"", OGG123_BINARY_COMMENT, path);
+	argc = 4;
+	work = comments;
+	while (work && work->next) {
+		if (work->data)
+			argc += 2;
+		work = work->next;
+		work = work->next;
+	}
+	if ((argv = g_malloc(argc * sizeof(argv[0]))) == NULL)
+		{
+		printf("Failed to allocate memory to run %s\n",
+		    OGG123_BINARY_COMMENT);
+		return FALSE;
+		}
+
+	argc = 0;
+	argv[argc++] = OGG123_BINARY_COMMENT;
+	argv[argc++] = "-w";
+	argv[argc++] = (char *)path;
 
 	work = comments;
 	while (work && work->next)
@@ -272,26 +352,21 @@ gint ogg123_comment_set(const gchar *pat
 
 		if (key && strlen(key) > 0 && value && strlen(value) > 0)
 			{
-			tmp = g_strdup_printf("%s -t \"%s=%s\"", command, key, value);
-			g_free(command);
-			command = tmp;
+			argv[argc++] = "-t";
+			argv[argc++] = g_strdup_printf("%s=%s", key, value);
 			}
 
 		work = work->next;
 		work = work->next;
 		}
-	tmp = g_strdup_printf("%s 2>&1", command);
-	g_free(command);
-	command = tmp;
+	argv[argc++] = NULL;
 
-	f = popen(command, "r");
-	if (!f)
+	if (ogg123_pipe_open(argv, &child_pid, child_pipe) == FALSE
+	    || (f = fdopen(child_pipe[0], "r")) == NULL)
 		{
-		printf("Failed to run \"%s\"\n", command);
-		g_free(command);
+		printf("Failed to run \"%s\"\n", argv[0]);
 		return FALSE;
 		}
-	g_free(command);
 
 	errlist = NULL;
 	while (fgets(buf, sizeof(buf), f) != NULL)
@@ -302,7 +377,10 @@ gint ogg123_comment_set(const gchar *pat
 			}
 		}
 
-	pclose(f);
+	close(child_pipe[0]);
+	for (i = 4; i < argc; i += 2)
+		g_free(argv[i]);
+	g_free(argv);
 
 	if (errlist)
 		{
@@ -472,30 +550,24 @@ static gint parse_time(const gchar *text
 	return (m * 60 + s);
 }
 
-static void parse_bitrate(const gchar *text)
+static gint parse_bitrate(const gchar *text)
 {
 	static time_t old_t = 0;
 	time_t new_t;
-	const gchar *ptr;
 	gint force = FALSE;
+	int new_rate;
 
-	ptr = strstr(text, "Bitrate: ");
-	if (ptr)
+	if (sscanf(text, "(%d.%*d kbps)", &new_rate) != 1)
+		return FALSE;
+	if (input_bitrate != 0)
 		{
-		gint new_rate;
-
-		ptr += 9;
-		new_rate = (gint)strtol(ptr, NULL, 10);
-		if (input_bitrate != 0)
-			{
-			/* show a trend, ugly but it makes the rate change more smoothly */
-			input_bitrate = ((input_bitrate * 4) + new_rate) / 5;
-			}
-		else
-			{
-			input_bitrate = new_rate;
-			force = TRUE;
-			}
+		/* show a trend, ugly but it makes the rate change more smoothly */
+		input_bitrate = ((input_bitrate * 4) + (gint)new_rate) / 5;
+		}
+	else
+		{
+		input_bitrate = (gint)new_rate;
+		force = TRUE;
 		}
 
 	/* we only update once per second */
@@ -505,12 +577,14 @@ static void parse_bitrate(const gchar *t
 		module_playback_data_changed();
 		old_t = new_t;
 		}
+	return TRUE;
 }
 
 static gint ogg123_input_parse(const gchar *buffer)
 {
 	if (debug_mode > 1) printf("ogg123 output:\"%s\"\n", buffer);
 
+/* Time: 00:03.92 [04:48.17] of 04:52.09  (140.9 kbps)  Output Buffer 75.0%  */
 	if (strncmp(buffer, "Time: ", 6) == 0)
 		{
 		const gchar *ptr;
@@ -527,7 +601,9 @@ static gint ogg123_input_parse(const gch
 		if (strlen(ptr) < 8) return FALSE;
 		seconds_remaining = parse_time(ptr);
 		frames_remaining = seconds_remaining;
-		parse_bitrate(ptr);
+		ptr = strchr(ptr, '(');
+		if (!ptr) return FALSE;
+		if (parse_bitrate(ptr) == FALSE) return FALSE;
 		}
 	else if (strncmp(buffer, "Bitstream is", 12) == 0)
 		{
@@ -648,7 +724,6 @@ static void ogg123_input_read_reset(void
 
 static gint ogg123_child_run(SongData *sd, gint position)
 {
-	pid_t frk_pid;
 	char cmd_arguments[OGG123_MAX_COMMANDS][512];
 	char *cmd_ptr[OGG123_MAX_COMMANDS];
 	int cmd_cnt = 0;
@@ -720,48 +795,11 @@ static gint ogg123_child_run(SongData *s
 	cmd_ptr[cmd_cnt] = NULL;
 	cmd_cnt++;
 
-	/* Create the pipe. */
-	if (pipe(ogg123_pipe))
-                {
-                fprintf (stderr, _("Pipe failed.\n"));
-                return FALSE;
-                }
-
-        if (debug_mode) printf("opening: %s\n", sd->path);
-
-	/* Create the child process. */
-	frk_pid = fork ();
-	if (frk_pid == (pid_t) 0)
-		{
-		/* This is the child process. */
-		dup2(ogg123_pipe[1], 2);
-		close(ogg123_pipe[0]);
-
-		execvp(exec_bin, cmd_ptr);
-		printf(_("unable to run %s (in the path?)\n"), exec_bin);
-		_exit(1);
-		}
-	else if (frk_pid < (pid_t) 0)
-		{
-		/* The fork failed. */
-		fprintf (stderr, _("Fork failed.\n"));
-		close(ogg123_pipe[0]);
-		close(ogg123_pipe[1]);
-		pid = 0;
-		ogg123_child_pid = -1;
+	pid = 0;
+	if (ogg123_pipe_open(cmd_ptr, &ogg123_child_pid, ogg123_pipe) == FALSE)
 		return FALSE;
-		}
-	else
-		{
-		/* This is the parent process. */
-		ogg123_child_pid = (int) frk_pid;
-		pid = ogg123_child_pid;
 
-		close(ogg123_pipe[1]);
-		ogg123_pipe[1] = -1;
-		}
-
-	if (debug_mode) printf("ogg123 pid = %d\n", ogg123_child_pid);
+	pid = ogg123_child_pid;
 
 	ogg123_input_read_reset();
 	ogg123_control_read_id = gdk_input_add (ogg123_pipe[0], GDK_INPUT_READ, ogg123_input_read_cb, NULL);
@@ -769,6 +807,7 @@ static gint ogg123_child_run(SongData *s
 	return TRUE;
 }
 
+
 /*
  *----------------------------------------------------------------------------
  * module callback funcs
@@ -793,7 +832,7 @@ static gint ogg123_data_set(SongData *sd
 		if (info)
 			{
 			sd->length = info->length;
-			sd->bit_rate = info->bitrate_nominal;
+			sd->bit_rate = info->bitrate_average / 1000;
 			sd->channels = info->channels;
 			sd->bit_depth = 16;	/* these two correct ? */
 			sd->khz_rate = 44;