annotate src/daap/xmms2-daap/daap_util.c @ 3163:26a2c237ef53

alsa-ng: Destroy the ringbuffer when the plugin closes.
author William Pitcock <nenolod@atheme.org>
date Thu, 14 May 2009 21:08:03 -0500
parents 776dd8fc2b38
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1407
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
1 /** @file daap_util.c
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
2 * Miscellaneous utility functions.
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
3 *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
4 * Copyright (C) 2006-2007 XMMS2 Team
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
5 *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
8 * as published by the Free Software Foundation; either version 2
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
9 * of the License, or (at your option) any later version.
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
10 *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
14 * GNU General Public License for more details.
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
15 */
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
16
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
17 #include <glib.h>
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
18 #include <glib/gprintf.h>
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
19
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
20 #include "daap_util.h"
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
21
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
22 void
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
23 write_buffer_to_channel (GIOChannel *chan, gchar *buf, gint bufsize)
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
24 {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
25 guint total_sent_bytes = 0;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
26 gsize sent_bytes;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
27 GIOStatus io_stat;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
28 GError *err = NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
29
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
30 do {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
31 io_stat = g_io_channel_write_chars (chan,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
32 buf + total_sent_bytes,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
33 bufsize - total_sent_bytes,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
34 &sent_bytes,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
35 &err);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
36 if (io_stat == G_IO_STATUS_ERROR) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
37 if (NULL != err) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
38 g_print ("Error writing to channel: %s\n", err->message);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
39 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
40 break;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
41 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
42
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
43 bufsize -= sent_bytes;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
44 total_sent_bytes += sent_bytes;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
45 } while (bufsize > 0);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
46
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
47 g_io_channel_flush (chan, &err);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
48 if (NULL != err) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
49 g_print ("warning: error flushing channel: %s\n", err->message);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
50 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
51 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
52
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
53 gint
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
54 read_buffer_from_channel (GIOChannel *chan, gchar *buf, gint bufsize)
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
55 {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
56 guint n_total_bytes_read = 0;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
57 gsize read_bytes;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
58 GIOStatus io_stat;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
59 GError *err = NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
60
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
61 do {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
62 io_stat = g_io_channel_read_chars (chan,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
63 buf + n_total_bytes_read,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
64 bufsize - n_total_bytes_read,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
65 &read_bytes,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
66 &err);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
67 if (io_stat == G_IO_STATUS_ERROR) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
68 g_print ("warning: error reading from channel: %s\n", err->message);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
69 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
70 n_total_bytes_read += read_bytes;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
71
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
72 if (io_stat == G_IO_STATUS_EOF) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
73 break;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
74 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
75 } while (bufsize > n_total_bytes_read);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
76
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
77 return n_total_bytes_read;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
78 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
79