Mercurial > audlegacy-plugins
annotate src/demac/plugin.c @ 3047:4434b4c4a715
ported EsounD plugin
author | Andrew O. Shadoura <bugzilla@tut.by> |
---|---|
date | Fri, 17 Apr 2009 16:17:10 +0300 |
parents | b20622733f08 |
children |
rev | line source |
---|---|
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
1 /* |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
2 * Audacious Monkey's Audio plugin |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
3 * |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
4 * Copyright (C) Eugene Zagidullin 2007 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
5 * |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
6 * Used some code from libdemac and example application: |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
7 * Copyright (C) Dave Chapman 2007 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
8 * |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
9 * This program is free software; you can redistribute it and/or modify |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
11 * the Free Software Foundation; either version 2 of the License, or |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
12 * (at your option) any later version. |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
13 * |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
17 * GNU General Public License for more details. |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
18 * |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
19 * You should have received a copy of the GNU General Public License |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
20 * along with this program; if not, write to the Free Software |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
22 * |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
23 */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
24 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
25 #ifndef _XOPEN_SOURCE |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
26 #define _XOPEN_SOURCE |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
27 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
28 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
29 #include "config.h" |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
30 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
31 #include <ctype.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
32 #include <stdio.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
33 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
34 #include <stdlib.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
35 #include <errno.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
36 #include <string.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
37 #include <assert.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
38 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
39 #include <glib.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
40 #include <gtk/gtk.h> |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
41 #include <glib/gprintf.h> |
2196
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
42 #include <mowgli.h> |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
43 |
2971
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2666
diff
changeset
|
44 #include <audlegacy/i18n.h> |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
45 |
2971
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2666
diff
changeset
|
46 #include <audlegacy/plugin.h> |
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2666
diff
changeset
|
47 #include <audlegacy/output.h> |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
48 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
49 #include "ape.h" |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
50 #include "apev2.h" |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
51 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
52 #ifndef MIN |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
53 #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
54 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
55 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
56 #define MAX_BYTESPERSAMPLE 2 // currently only 16bps supported |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
57 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
58 static GThread *pb_thread; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
59 static gpointer demac_decode_loop(InputPlayback *pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
60 static Tuple *demac_get_tuple(char *filename); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
61 static Tuple *demac_probe_for_tuple (gchar *uri, VFSFile *vfd); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
62 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
63 static GMutex *demac_mutex; |
3028
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
64 static volatile int seek_to_msec = -1; |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
65 static volatile char pause_flag = 0; |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
66 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
67 static InputPlugin demac_ip; |
2191
329267b09658
get rid of talking with GDK directly
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2190
diff
changeset
|
68 static GtkWidget *about_window = NULL; |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
69 |
2516 | 70 #ifdef AUD_DEBUG |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
71 # include "crc.c" |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
72 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
73 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
74 static gboolean demac_probe_vfs(char *filename, VFSFile* input_file) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
75 APEContext *ctx; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
76 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
77 ctx = calloc(sizeof(APEContext), 1); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
78 if(ape_read_header(ctx, input_file, 1) < 0) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
79 free(ctx); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
80 aud_vfs_rewind(input_file); /* Do we really need it? */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
81 return FALSE; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
82 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
83 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
84 free(ctx); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
85 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
86 aud_vfs_rewind(input_file); /* Do we really need it? */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
87 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
88 return TRUE; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
89 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
90 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
91 static void demac_play(InputPlayback *pb) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
92 pb->playing = 1; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
93 pb->eof = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
94 pb->error = FALSE; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
95 pb_thread = g_thread_self(); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
96 pb->set_pb_ready(pb); |
3028
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
97 |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
98 demac_decode_loop(pb); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
99 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
100 |
3028
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
101 static void demac_do_mseek (APEContext * ctx, InputPlayback * playback) { |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
102 if(ctx->seektable) { |
3028
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
103 ctx->currentframe = (ctx->totalframes - 1) * (long long) seek_to_msec |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
104 / ctx->duration; |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
105 playback->output->flush (ctx->duration * (long long) ctx->currentframe |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
106 / (ctx->totalframes - 1)); |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
107 seek_to_msec = -1; |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
108 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
109 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
110 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
111 gpointer demac_decode_loop(InputPlayback *pb) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
112 VFSFile *vfd; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
113 uint8_t *frame_buf = NULL; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
114 guint8 *wav = NULL; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
115 int wav_buffer_size; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
116 gchar *title = NULL; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
117 int audio_opened = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
118 int playing; |
3028
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
119 char paused = 0; |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
120 APEContext *ctx = NULL; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
121 APEDecoderContext *dec = NULL; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
122 int decoded_bytes; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
123 int pkt_size, bytes_used; |
2516 | 124 #ifdef AUD_DEBUG |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
125 uint32_t frame_crc; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
126 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
127 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
128 if ((vfd = aud_vfs_fopen(pb->filename, "r")) == NULL) { |
2516 | 129 AUDDBG("** demac: plugin.c: Error opening URI: %s\n", pb->filename); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
130 pb->error = TRUE; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
131 goto cleanup; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
132 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
133 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
134 ctx = calloc(sizeof(APEContext), 1); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
135 if(ape_read_header(ctx, vfd, 0) < 0) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
136 pb->error = TRUE; |
2516 | 137 AUDDBG("** demac: plugin.c: Cannot parse APE header or unsupported format: %s\n", pb->filename); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
138 goto cleanup; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
139 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
140 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
141 dec = calloc(sizeof(APEDecoderContext), 1); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
142 if(ape_decode_init(dec, ctx) < 0) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
143 pb->error = TRUE; |
2516 | 144 AUDDBG("** demac: plugin.c: Error initializing decoder\n"); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
145 goto cleanup; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
146 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
147 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
148 frame_buf = malloc(ctx->max_packet_size); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
149 |
2516 | 150 AUDDBG("** demac: plugin.c: Duration: %u msec\n", ctx->duration); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
151 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
152 if(!pb->output->open_audio(FMT_S16_LE, ctx->samplerate, ctx->channels)) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
153 pb->error = TRUE; |
2516 | 154 AUDDBG("** demac: plugin.c: Cannot open audio.\n"); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
155 goto cleanup; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
156 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
157 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
158 audio_opened = 1; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
159 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
160 Tuple *tpl = demac_probe_for_tuple (pb->filename, vfd); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
161 title = aud_tuple_formatter_make_title_string(tpl, aud_get_gentitle_format()); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
162 pb->set_params(pb, title, ctx->duration, -1, ctx->samplerate, ctx->channels); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
163 aud_tuple_free(tpl); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
164 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
165 /* begin decoding */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
166 wav_buffer_size = ctx->blocksperframe * MAX_BYTESPERSAMPLE * ctx->channels; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
167 wav = malloc(wav_buffer_size); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
168 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
169 g_mutex_lock(demac_mutex); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
170 playing = pb->playing; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
171 g_mutex_unlock(demac_mutex); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
172 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
173 while (playing && (ctx->currentframe < ctx->totalframes)) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
174 { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
175 g_mutex_lock(demac_mutex); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
176 playing = pb->playing; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
177 g_mutex_unlock(demac_mutex); |
3028
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
178 if (seek_to_msec != -1) { |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
179 demac_do_mseek (ctx, pb); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
180 /* reset decoder */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
181 dec->samples = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
182 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
183 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
184 ape_read_packet(ctx, vfd, frame_buf, &pkt_size); |
2516 | 185 #ifdef AUD_DEBUG |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
186 assert(pkt_size <= ctx->max_packet_size); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
187 frame_crc = ape_initcrc(); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
188 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
189 bytes_used = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
190 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
191 /* Decode the frame a chunk at a time */ |
3028
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
192 while (playing && (bytes_used != pkt_size)) { |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
193 if (pause_flag) { |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
194 if (! paused) { |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
195 pb->output->pause (1); |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
196 paused = 1; |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
197 } |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
198 while (pause_flag && seek_to_msec == -1) |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
199 g_usleep (50000); |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
200 } |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
201 if (paused && ! pause_flag) { |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
202 pb->output->pause (0); |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
203 paused = 0; |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
204 } |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
205 if (seek_to_msec != -1) |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
206 break; |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
207 g_mutex_lock(demac_mutex); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
208 playing = pb->playing; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
209 g_mutex_unlock(demac_mutex); |
3028
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
210 |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
211 decoded_bytes = wav_buffer_size; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
212 bytes_used = ape_decode_frame(dec, wav, &decoded_bytes, frame_buf, pkt_size); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
213 if(bytes_used < 0) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
214 /* skip frame */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
215 dec->samples = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
216 break; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
217 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
218 /* Write audio data */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
219 pb->pass_audio(pb, FMT_S16_LE, ctx->channels, decoded_bytes, wav, &playing); |
2516 | 220 #ifdef AUD_DEBUG |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
221 frame_crc = ape_updatecrc(wav, decoded_bytes, frame_crc); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
222 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
223 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
224 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
225 |
2516 | 226 #ifdef AUD_DEBUG |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
227 frame_crc = ape_finishcrc(frame_crc); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
228 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
229 if (dec->CRC != frame_crc) { |
2516 | 230 AUDDBG("** demac: plugin.c: CRC error in frame %d\n", ctx->currentframe-1); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
231 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
232 #endif |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
233 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
234 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
235 cleanup: |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
236 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
237 pb->eof = TRUE; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
238 pb->playing = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
239 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
240 if(title) g_free(title); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
241 if(audio_opened) pb->output->close_audio(); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
242 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
243 if(dec) {ape_decode_close(dec); free(dec);} |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
244 if(wav) free(wav); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
245 if(frame_buf) free(frame_buf); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
246 if(ctx) {ape_read_close(ctx); free(ctx);} |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
247 if(vfd) aud_vfs_fclose(vfd); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
248 |
2516 | 249 AUDDBG("** demac: plugin.c: decoding loop finished\n"); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
250 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
251 return NULL; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
252 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
253 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
254 static void demac_stop(InputPlayback *pb) |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
255 { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
256 g_mutex_lock(demac_mutex); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
257 int playing = pb->playing; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
258 g_mutex_unlock(demac_mutex); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
259 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
260 if (playing) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
261 g_mutex_lock(demac_mutex); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
262 pb->playing = 0; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
263 g_mutex_unlock(demac_mutex); |
2516 | 264 AUDDBG("** demac: plugin.c: waiting for thread finished\n"); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
265 g_thread_join(pb_thread); |
2516 | 266 AUDDBG("** demac: plugin.c: thread finished\n"); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
267 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
268 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
269 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
270 static void demac_pause(InputPlayback *pb, short paused) { |
3028
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
271 pause_flag = paused; |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
272 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
273 |
2196
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
274 static void destroy_cb(mowgli_dictionary_elem_t *delem, void *privdata) { |
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
275 g_free(delem->data); |
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
276 } |
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
277 |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
278 Tuple *demac_probe_for_tuple (gchar *uri, VFSFile *vfd) { |
2516 | 279 AUDDBG("** demac: plugin.c: demac_probe_for_tuple()\n"); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
280 gchar codec_string[32]; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
281 |
2261
05c9bec29aaa
- Prevent APE plugin from freaking out non-seekable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
2199
diff
changeset
|
282 if (aud_vfs_is_streaming(vfd)) { |
05c9bec29aaa
- Prevent APE plugin from freaking out non-seekable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
2199
diff
changeset
|
283 /* This plugin does not support streams yet */ |
05c9bec29aaa
- Prevent APE plugin from freaking out non-seekable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
2199
diff
changeset
|
284 return NULL; |
05c9bec29aaa
- Prevent APE plugin from freaking out non-seekable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
2199
diff
changeset
|
285 } |
05c9bec29aaa
- Prevent APE plugin from freaking out non-seekable streams
Ralf Ertzinger <ralf@skytale.net>
parents:
2199
diff
changeset
|
286 |
2666
053341c248ef
"Fix" demac plugin not to arbitrarily determine that all files belong to it...
Matti Hamalainen <ccr@tnsp.org>
parents:
2576
diff
changeset
|
287 APEContext *ctx = calloc(sizeof(APEContext), 1); |
053341c248ef
"Fix" demac plugin not to arbitrarily determine that all files belong to it...
Matti Hamalainen <ccr@tnsp.org>
parents:
2576
diff
changeset
|
288 aud_vfs_rewind(vfd); |
053341c248ef
"Fix" demac plugin not to arbitrarily determine that all files belong to it...
Matti Hamalainen <ccr@tnsp.org>
parents:
2576
diff
changeset
|
289 if (ape_read_header(ctx, vfd, 1) < 0) { |
053341c248ef
"Fix" demac plugin not to arbitrarily determine that all files belong to it...
Matti Hamalainen <ccr@tnsp.org>
parents:
2576
diff
changeset
|
290 free(ctx); |
053341c248ef
"Fix" demac plugin not to arbitrarily determine that all files belong to it...
Matti Hamalainen <ccr@tnsp.org>
parents:
2576
diff
changeset
|
291 aud_vfs_rewind(vfd); |
053341c248ef
"Fix" demac plugin not to arbitrarily determine that all files belong to it...
Matti Hamalainen <ccr@tnsp.org>
parents:
2576
diff
changeset
|
292 return NULL; |
053341c248ef
"Fix" demac plugin not to arbitrarily determine that all files belong to it...
Matti Hamalainen <ccr@tnsp.org>
parents:
2576
diff
changeset
|
293 } |
053341c248ef
"Fix" demac plugin not to arbitrarily determine that all files belong to it...
Matti Hamalainen <ccr@tnsp.org>
parents:
2576
diff
changeset
|
294 |
053341c248ef
"Fix" demac plugin not to arbitrarily determine that all files belong to it...
Matti Hamalainen <ccr@tnsp.org>
parents:
2576
diff
changeset
|
295 Tuple *tpl = aud_tuple_new_from_filename(uri); |
2196
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
296 mowgli_dictionary_t *tag = NULL; |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
297 gchar *item; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
298 if ((tag = parse_apev2_tag(vfd)) != NULL) { |
2196
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
299 if((item = mowgli_dictionary_retrieve(tag, "Artist")) != NULL) aud_tuple_associate_string(tpl, FIELD_ARTIST, NULL, item); |
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
300 if((item = mowgli_dictionary_retrieve(tag, "Title")) != NULL) aud_tuple_associate_string(tpl, FIELD_TITLE, NULL, item); |
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
301 if((item = mowgli_dictionary_retrieve(tag, "Album")) != NULL) aud_tuple_associate_string(tpl, FIELD_ALBUM, NULL, item); |
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
302 if((item = mowgli_dictionary_retrieve(tag, "Comment")) != NULL) aud_tuple_associate_string(tpl, FIELD_COMMENT, NULL, item); |
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
303 if((item = mowgli_dictionary_retrieve(tag, "Genre")) != NULL) aud_tuple_associate_string(tpl, FIELD_GENRE, NULL, item); |
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
304 if((item = mowgli_dictionary_retrieve(tag, "Track")) != NULL) aud_tuple_associate_int(tpl, FIELD_TRACK_NUMBER, NULL, atoi(item)); |
dfa3c3aa2dc7
switched to mowgli_dictionary from GHashTable
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2191
diff
changeset
|
305 if((item = mowgli_dictionary_retrieve(tag, "Year")) != NULL) aud_tuple_associate_int(tpl, FIELD_YEAR, NULL, atoi(item)); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
306 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
307 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
308 aud_tuple_associate_int(tpl, FIELD_LENGTH, NULL, ctx->duration); |
2666
053341c248ef
"Fix" demac plugin not to arbitrarily determine that all files belong to it...
Matti Hamalainen <ccr@tnsp.org>
parents:
2576
diff
changeset
|
309 g_snprintf(codec_string, sizeof(codec_string), "Monkey's Audio v%4.2f", (float)ctx->fileversion/1000.0); |
2516 | 310 AUDDBG("** demac: plugin.c: Codec: %s\n", codec_string); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
311 aud_tuple_associate_string(tpl, FIELD_CODEC, NULL, codec_string); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
312 aud_tuple_associate_string(tpl, FIELD_QUALITY, NULL, "lossless"); |
2189
549009824758
demac: added MIME type (audio/x-ape) to provided tuple
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2182
diff
changeset
|
313 aud_tuple_associate_string(tpl, FIELD_MIMETYPE, NULL, "audio/x-ape"); |
2418
699b5e756bc4
fix for #135: do not read from already freed memory. patch by Jussi Judin. thanks Jussi!
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2261
diff
changeset
|
314 |
699b5e756bc4
fix for #135: do not read from already freed memory. patch by Jussi Judin. thanks Jussi!
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2261
diff
changeset
|
315 ape_read_close(ctx); |
699b5e756bc4
fix for #135: do not read from already freed memory. patch by Jussi Judin. thanks Jussi!
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2261
diff
changeset
|
316 free(ctx); |
699b5e756bc4
fix for #135: do not read from already freed memory. patch by Jussi Judin. thanks Jussi!
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2261
diff
changeset
|
317 |
699b5e756bc4
fix for #135: do not read from already freed memory. patch by Jussi Judin. thanks Jussi!
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2261
diff
changeset
|
318 if (tag) mowgli_dictionary_destroy(tag, destroy_cb, NULL); |
699b5e756bc4
fix for #135: do not read from already freed memory. patch by Jussi Judin. thanks Jussi!
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2261
diff
changeset
|
319 |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
320 return tpl; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
321 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
322 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
323 Tuple *demac_get_tuple(char *filename) { |
2516 | 324 AUDDBG("** demac: plugin.c: demac_get_tuple()\n"); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
325 VFSFile *vfd; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
326 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
327 if ((vfd = aud_vfs_fopen(filename, "r")) == NULL) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
328 return NULL; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
329 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
330 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
331 Tuple *tpl = demac_probe_for_tuple(filename, vfd); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
332 aud_vfs_fclose(vfd); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
333 return tpl; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
334 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
335 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
336 static void demac_mseek (InputPlayback *pb, gulong millisecond) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
337 seek_to_msec = millisecond; |
3028
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
338 while (seek_to_msec != -1) |
b20622733f08
Fix seeking when paused for .ape plugin (Debian bug #517692)
John Lindgren <john.lindgren@tds.net>
parents:
2971
diff
changeset
|
339 g_usleep (50000); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
340 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
341 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
342 static void demac_seek (InputPlayback *pb, gint time) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
343 demac_mseek(pb, (unsigned long)time*1000); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
344 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
345 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
346 static void demac_init() { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
347 /* Found in Freedesktop shared-mime-info */ |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
348 aud_mime_set_plugin("audio/x-ape", &demac_ip); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
349 demac_mutex = g_mutex_new(); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
350 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
351 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
352 static void demac_cleanup() { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
353 g_mutex_free(demac_mutex); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
354 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
355 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
356 static void demac_about(void) { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
357 |
2191
329267b09658
get rid of talking with GDK directly
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2190
diff
changeset
|
358 if (about_window) { |
329267b09658
get rid of talking with GDK directly
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2190
diff
changeset
|
359 gtk_window_present(GTK_WINDOW(about_window)); |
329267b09658
get rid of talking with GDK directly
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2190
diff
changeset
|
360 } else { |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
361 about_window = audacious_info_dialog(_("About Monkey's Audio Plugin"), |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
362 _("Copyright (C) 2007 Eugene Zagidullin <e.asphyx@gmail.com>\n" |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
363 "Based on ffape decoder, Copyright (C) 2007 Benjamin Zores\n" |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
364 "ffape itself based on libdemac by Dave Chapman\n\n" |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
365 "ffape is a part of FFmpeg project, http://ffmpeg.mplayerhq.hu/"), |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
366 _("Ok"), FALSE, NULL, NULL); |
2191
329267b09658
get rid of talking with GDK directly
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2190
diff
changeset
|
367 g_signal_connect(G_OBJECT(about_window), "destroy", G_CALLBACK(gtk_widget_destroyed), &about_window); |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
368 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
369 } |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
370 |
2199
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
371 static void insert_str_tuple_field_to_dictionary(Tuple *tuple, int fieldn, mowgli_dictionary_t *dict, char *key) { |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
372 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
373 if(mowgli_dictionary_find(dict, key) != NULL) g_free(mowgli_dictionary_delete(dict, key)); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
374 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
375 gchar *tmp = (gchar*)aud_tuple_get_string(tuple, fieldn, NULL); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
376 if(tmp != NULL && strlen(tmp) != 0) mowgli_dictionary_add(dict, key, g_strdup(tmp)); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
377 } |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
378 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
379 static void insert_int_tuple_field_to_dictionary(Tuple *tuple, int fieldn, mowgli_dictionary_t *dict, char *key) { |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
380 int val; |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
381 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
382 if(mowgli_dictionary_find(dict, key) != NULL) g_free(mowgli_dictionary_delete(dict, key)); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
383 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
384 if(aud_tuple_get_value_type(tuple, fieldn, NULL) == TUPLE_INT && (val = aud_tuple_get_int(tuple, fieldn, NULL)) >= 0) { |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
385 gchar *tmp = g_strdup_printf("%d", val); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
386 mowgli_dictionary_add(dict, key, tmp); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
387 } |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
388 } |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
389 |
2190
36b9f3e6cbcf
demac: added stub for update_song_tuple() for debugging purposes
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2189
diff
changeset
|
390 static gboolean demac_update_song_tuple(Tuple *tuple, VFSFile *vfd) { |
2199
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
391 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
392 mowgli_dictionary_t *tag = parse_apev2_tag(vfd); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
393 if (tag == NULL) tag = mowgli_dictionary_create(g_ascii_strcasecmp); |
2190
36b9f3e6cbcf
demac: added stub for update_song_tuple() for debugging purposes
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2189
diff
changeset
|
394 |
2199
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
395 insert_str_tuple_field_to_dictionary(tuple, FIELD_TITLE, tag, "Title"); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
396 insert_str_tuple_field_to_dictionary(tuple, FIELD_ARTIST, tag, "Artist"); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
397 insert_str_tuple_field_to_dictionary(tuple, FIELD_ALBUM, tag, "Album"); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
398 insert_str_tuple_field_to_dictionary(tuple, FIELD_COMMENT, tag, "Comment"); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
399 insert_str_tuple_field_to_dictionary(tuple, FIELD_GENRE, tag, "Genre"); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
400 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
401 insert_int_tuple_field_to_dictionary(tuple, FIELD_YEAR, tag, "Year"); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
402 insert_int_tuple_field_to_dictionary(tuple, FIELD_TRACK_NUMBER, tag, "Track"); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
403 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
404 gboolean ret = write_apev2_tag(vfd, tag); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
405 mowgli_dictionary_destroy(tag, destroy_cb, NULL); |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
406 |
8b3c2fe608c9
APEv2 writing implemented
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2196
diff
changeset
|
407 return ret; |
2190
36b9f3e6cbcf
demac: added stub for update_song_tuple() for debugging purposes
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2189
diff
changeset
|
408 } |
36b9f3e6cbcf
demac: added stub for update_song_tuple() for debugging purposes
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2189
diff
changeset
|
409 |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
410 static gchar *fmts[] = { "ape", NULL }; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
411 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
412 static InputPlugin demac_ip = { |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
413 .description = "Monkey's Audio Plugin", |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
414 .init = demac_init, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
415 .about = demac_about, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
416 .play_file = demac_play, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
417 .stop = demac_stop, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
418 .pause = demac_pause, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
419 .seek = demac_seek, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
420 .cleanup = demac_cleanup, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
421 .get_song_tuple = demac_get_tuple, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
422 .is_our_file_from_vfs = demac_probe_vfs, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
423 .vfs_extensions = fmts, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
424 .mseek = demac_mseek, |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
425 .probe_for_tuple = demac_probe_for_tuple, |
2190
36b9f3e6cbcf
demac: added stub for update_song_tuple() for debugging purposes
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
2189
diff
changeset
|
426 .update_song_tuple = demac_update_song_tuple, |
2182
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
427 }; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
428 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
429 InputPlugin *demac_iplist[] = { &demac_ip, NULL }; |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
430 DECLARE_PLUGIN(demac, NULL, NULL, demac_iplist, NULL, NULL, NULL, NULL, NULL); |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
431 |
cc5e9ec110a4
Added initial version of Monkey's Audio plugin
Eugene Zagidullin <e.asphyx@gmail.com>
parents:
diff
changeset
|
432 /* vim:foldmethod=syntax: */ |