Ticket #80: roar_plugin.c

File roar_plugin.c, 4.1 KB (added by ph3-der-loewe, 13 years ago)

Start of a patch... See comment

Line 
1//roar_plugin.c:
2/*
3 * Copyright (C) 2003-2010 The Music Player Daemon Project
4 * copyright (c) 2010 Philipp 'ph3-der-loewe' Schafft
5 * copyright (c) 2010 Hans-Kristian 'maister' Arntzen
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22#include "config.h"
23#include "output_api.h"
24#include "mixer_list.h"
25#include <roaraudio.h>
26
27#include <glib.h>
28#include <sys/types.h>
29#include <sys/socket.h>
30#include <arpa/inet.h>
31#include <netdb.h>
32#include <stdint.h>
33#include <fcntl.h>
34#include <unistd.h>
35#include <stdlib.h>
36#include <string.h>
37#include <stdint.h>
38
39
40#undef G_LOG_DOMAIN
41#define G_LOG_DOMAIN "roaraudio"
42
43
44static const char *default_host = "localhost";
45static const char *default_port = "12345";
46
47struct roar {
48   struct roar_connection con;
49   roar_vs_t * vss;
50   int err;
51};
52
53static inline GQuark
54roar_output_quark(void)
55{
56   return g_quark_from_static_string("roar_output");
57}
58
59static void
60roar_configure(struct roar * self, const struct config_param *param)
61{
62   // XXX: ???
63/*
64   rsd_set_param(rd, RSD_HOST, config_dup_block_string(param, "host", default_host));
65   rsd_set_param(rd, RSD_PORT, config_dup_block_string(param, "port", default_port));
66*/
67}
68
69static void *
70roar_init(G_GNUC_UNUSED const struct audio_format *audio_format,
71     const struct config_param *param,
72     G_GNUC_UNUSED GError **error)
73{
74  struct roar * self = roar_mm_malloc(sizeof(struct roar));
75
76  if ( self == NULL ) {
77     return NULL;
78  }
79
80  memset(self, 0, sizeof(struct roar));
81
82  self->err = ROAR_ERROR_NONE;
83
84/*
85   if ( rsd_init(&rd) < 0 )
86   {
87      g_set_error(error, rsound_output_quark(), 0, "Failed to initialize");
88      return NULL;
89   }
90*/
91
92   roar_configure(self, param);
93
94   return self;
95}
96
97static void
98roar_finish(void *data)
99{
100   struct roar * self = data;
101
102   roar_close(data);
103
104   roar_disconnect(&(self->con));
105
106   roar_mm_free(self);
107}
108
109static bool
110roar_open(void *data, struct audio_format *audio_format, GError **error)
111{
112   struct roar * self = data;
113   struct roar_audio_info info;
114
115   self->vss = roar_vs_new_from_con(&(self->con), &(self->err));
116
117   if ( self->vss ) {
118      return false;
119   }
120
121   info.rate     = audio_format->sample_rate;
122   info.channels = audio_format->channels;
123
124   if ( roar_vs_stream(self->vss, &info, ROAR_DIR_PLAY, &(self->err)) == -1 ) {
125      roar_vs_close(self->vss, ROAR_VS_TRUE, NULL);
126      self->vss = NULL;
127      return false;
128   }
129/*
130   audio_format->format = SAMPLE_FORMAT_S16;
131   audio_format->reverse_endian = 0;
132
133   int format = RSD_S16_NE;
134   rsd_set_param(rd, RSD_FORMAT, &format);
135*/
136
137/*
138   if ( rsd_start(rd) < 0)
139   {
140      g_set_error(error, rsound_output_quark(), 0, "Failed to connect to server");
141      return false;
142   }
143   return true;
144*/
145}
146
147static void
148rsound_cancel(void *data)
149{
150   // XXX: ???
151}
152
153static void
154roar_close(void *data)
155{
156   struct roar * self = data;
157
158   if ( self->vss != NULL )
159      roar_vs_close(vss, ROAR_VS_FALSE, &(self->err));
160}
161
162static size_t
163roar_play(void *data, const void *chunk, size_t size, GError **error)
164{
165   struct roar * self = data;
166   ssize_t rc;
167   
168   rc = roar_vs_write(self->vss, chunk, size, &(self->err));
169   if ( rc <= 0 )
170   {
171      g_set_error(error, roar_output_quark(), 0, "Failed to play data");
172      return 0;
173   }
174
175   return rc;
176}
177
178const struct audio_output_plugin rsound_output_plugin = {
179   .name = "roar",
180   .init = roar_init,
181   .finish = roar_finish,
182   .open = rsound_open,
183   .play = roar_play,
184   .cancel = rsound_cancel,
185   .close = roar_close,
186};
187
188