Ticket #80: roar-mpd.patch

File roar-mpd.patch, 11.0 KB (added by themaister, 13 years ago)

MPD patch. Needs fixes.

  • Makefile.am

    diff --git a/Makefile.am b/Makefile.am
    index 0966a2a..0e8f004 100644
    a b mpd_headers = \ 
    138138        src/output/httpd_client.h \ 
    139139        src/output/httpd_internal.h \ 
    140140        src/output/pulse_output_plugin.h \ 
     141        src/output/roar_output_plugin.h \ 
    141142        src/output/winmm_output_plugin.h \ 
    142143        src/page.h \ 
    143144        src/pcm_buffer.h \ 
    OUTPUT_LIBS = \ 
    654655        $(LIBWRAP_LDFLAGS) \ 
    655656        $(AO_LIBS) \ 
    656657        $(ALSA_LIBS) \ 
     658        $(ROAR_LIBS) \ 
    657659        $(FFADO_LIBS) \ 
    658660        $(JACK_LIBS) \ 
    659661        $(OPENAL_LIBS) \ 
    OUTPUT_SRC += src/output/alsa_plugin.c 
    687689MIXER_SRC += src/mixer/alsa_mixer_plugin.c 
    688690endif 
    689691 
     692if HAVE_ROAR 
     693OUTPUT_SRC += src/output/roar_plugin.c 
     694MIXER_SRC += src/mixer/roar_mixer_plugin.c 
     695endif 
     696 
    690697if ENABLE_FFADO_OUTPUT 
    691698OUTPUT_SRC += src/output/ffado_output_plugin.c 
    692699endif 
  • configure.ac

    diff --git a/configure.ac b/configure.ac
    index ab1410d..e16670d 100644
    a b AC_ARG_ENABLE(alsa, 
    120120        AS_HELP_STRING([--enable-alsa], [enable ALSA support]),, 
    121121        [enable_alsa=auto]) 
    122122 
     123AC_ARG_ENABLE(roar, 
     124  AS_HELP_STRING([--enable-roar], 
     125     [enable support for RoarAudio]),, 
     126        [enable_roar=auto]) 
     127 
    123128AC_ARG_ENABLE(ao, 
    124129        AS_HELP_STRING([--enable-ao], 
    125130                [enable support for libao]),, 
    fi 
    12091214 
    12101215AM_CONDITIONAL(HAVE_ALSA, test x$enable_alsa = xyes) 
    12111216 
     1217dnl ----------------------------------- ROAR ---------------------------------- 
     1218MPD_AUTO_PKG(roar, ROAR, [libroar >= 0.4.0], 
     1219             [ROAR output plugin], [libroar not found]) 
     1220 
     1221if test x$enable_roar = xyes; then 
     1222   AC_DEFINE(HAVE_ROAR, 1, [Define to enable ROAR support]) 
     1223fi 
     1224 
     1225AM_CONDITIONAL(HAVE_ROAR, test x$enable_roar = xyes) 
     1226 
    12121227dnl ----------------------------------- FFADO --------------------------------- 
    12131228 
    12141229MPD_AUTO_PKG(ffado, FFADO, [libffado], 
    AM_CONDITIONAL(ENABLE_WINMM_OUTPUT, test x$enable_winmm_output = xyes) 
    14091424dnl --------------------- Post Audio Output Plugins Tests --------------------- 
    14101425if 
    14111426        test x$enable_alsa = xno && 
     1427   test x$enable_roar = xno && 
    14121428        test x$enable_ao = xno && 
    14131429        test x$enable_ffado = xno && 
    14141430        test x$enable_fifo = xno && 
    results(id3,[ID3]) 
    15451561 
    15461562echo -en '\nPlayback support:\n\t' 
    15471563results(alsa,ALSA) 
     1564results(roar,ROAR) 
    15481565results(ffado,FFADO) 
    15491566results(fifo,FIFO) 
    15501567results(recorder_output,[File Recorder]) 
  • new file src/mixer/roar_mixer_plugin.c

    diff --git a/src/mixer/roar_mixer_plugin.c b/src/mixer/roar_mixer_plugin.c
    new file mode 100644
    index 0000000..70015ba
    - +  
     1/* 
     2 * Copyright (C) 2003-2010 The Music Player Daemon Project 
     3 * http://www.musicpd.org 
     4 * 
     5 * This program is free software; you can redistribute it and/or modify 
     6 * it under the terms of the GNU General Public License as published by 
     7 * the Free Software Foundation; either version 2 of the License, or 
     8 * (at your option) any later version. 
     9 * 
     10 * This program is distributed in the hope that it will be useful, 
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     13 * GNU General Public License for more details. 
     14 * 
     15 * You should have received a copy of the GNU General Public License along 
     16 * with this program; if not, write to the Free Software Foundation, Inc., 
     17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
     18 */ 
     19 
     20#include "config.h" 
     21#include "mixer_api.h" 
     22#include "output_api.h" 
     23#include "output/roar_output_plugin.h" 
     24 
     25#include <glib.h> 
     26 
     27#include <assert.h> 
     28#include <sys/stat.h> 
     29#include <sys/ioctl.h> 
     30#include <fcntl.h> 
     31#include <errno.h> 
     32#include <stdlib.h> 
     33#include <unistd.h> 
     34 
     35typedef struct roar_mpd_mixer  
     36{ 
     37        /** the base mixer class */ 
     38        struct mixer base; 
     39   roar_vs_t *vss; 
     40} roar_mixer_t; 
     41 
     42/** 
     43 * The quark used for GError.domain. 
     44 */ 
     45static inline GQuark 
     46roar_mixer_quark(void) 
     47{ 
     48        return g_quark_from_static_string("oss_mixer"); 
     49} 
     50 
     51static struct mixer * 
     52roar_mixer_init(void *ao, G_GNUC_UNUSED const struct config_param *param, 
     53               G_GNUC_UNUSED GError **error_r) 
     54{ 
     55        roar_mixer_t *self = g_new(roar_mixer_t, 1); 
     56   self->vss = ao; 
     57 
     58        mixer_init(&self->base, &roar_mixer_plugin); 
     59 
     60        return &self->base; 
     61} 
     62 
     63static void 
     64roar_mixer_finish(struct mixer *data) 
     65{ 
     66        roar_mixer_t *self = (roar_mixer_t *) data; 
     67 
     68        g_free(self); 
     69} 
     70 
     71static void 
     72roar_mixer_close(G_GNUC_UNUSED struct mixer *data) 
     73{ 
     74} 
     75 
     76static bool 
     77roar_mixer_open(G_GNUC_UNUSED struct mixer *data, G_GNUC_UNUSED GError **error_r) 
     78{ 
     79        return true; 
     80} 
     81 
     82static int 
     83roar_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r) 
     84{ 
     85        roar_mixer_t *self = (roar_mixer_t *)mixer; 
     86        assert(self->vss); 
     87 
     88   float l, r; 
     89   int error; 
     90   int rc = roar_vs_volume_get(self->vss, &l, &r, &error); 
     91   fprintf(stderr, "Volume GET: %.2f %.2f\n", l, r); 
     92   fprintf(stderr, "rc = %d\n", rc); 
     93   fprintf(stderr, "Error: %d\n", error); 
     94        return (l + r) * 50; 
     95} 
     96 
     97static bool 
     98roar_mixer_set_volume(struct mixer *mixer, unsigned volume, G_GNUC_UNUSED GError **error_r) 
     99{ 
     100        roar_mixer_t *self = (roar_mixer_t *)mixer; 
     101        assert(self->vss); 
     102        assert(volume <= 100); 
     103 
     104   int error; 
     105   float level = volume / 100.0; 
     106   fprintf(stderr, "Volume SET: %.2f\n", level); 
     107 
     108   int rc = roar_vs_volume_mono(self->vss, level, &error); 
     109   fprintf(stderr, "rc = %d\n", rc); 
     110   fprintf(stderr, "error = %d\n", error); 
     111        return true; 
     112} 
     113 
     114const struct mixer_plugin roar_mixer_plugin = { 
     115        .init = roar_mixer_init, 
     116        .finish = roar_mixer_finish, 
     117        .open = roar_mixer_open, 
     118        .close = roar_mixer_close, 
     119        .get_volume = roar_mixer_get_volume, 
     120        .set_volume = roar_mixer_set_volume, 
     121        .global = true, 
     122}; 
  • src/mixer_list.h

    diff --git a/src/mixer_list.h b/src/mixer_list.h
    index a472c88..9bb2d9a 100644
    a b  
    2828extern const struct mixer_plugin software_mixer_plugin; 
    2929extern const struct mixer_plugin alsa_mixer_plugin; 
    3030extern const struct mixer_plugin oss_mixer_plugin; 
     31extern const struct mixer_plugin roar_mixer_plugin; 
    3132extern const struct mixer_plugin pulse_mixer_plugin; 
    3233extern const struct mixer_plugin winmm_mixer_plugin; 
    3334 
  • new file src/output/roar_output_plugin.h

    diff --git a/src/output/roar_output_plugin.h b/src/output/roar_output_plugin.h
    new file mode 100644
    index 0000000..9f4b480
    - +  
     1#ifndef __ROAR_OUTPUT_H 
     2#define __ROAR_OUTPUT_H 
     3 
     4#include <roaraudio.h> 
     5 
     6typedef struct roar  
     7{ 
     8   roar_vs_t * vss; 
     9   int err; 
     10   char *host; 
     11   char *name; 
     12} roar_t; 
     13 
     14#endif 
  • new file src/output/roar_plugin.c

    diff --git a/src/output/roar_plugin.c b/src/output/roar_plugin.c
    new file mode 100644
    index 0000000..aeda5e3
    - +  
     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 "roar_output_plugin.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 
     43static inline GQuark 
     44roar_output_quark(void) 
     45{ 
     46   return g_quark_from_static_string("roar_output"); 
     47} 
     48 
     49static void 
     50roar_configure(struct roar * self, const struct config_param *param) 
     51{ 
     52   self->host = config_dup_block_string(param, "server", NULL); 
     53   self->name = config_dup_block_string(param, "name", "MPD"); 
     54} 
     55 
     56static void * 
     57roar_init(G_GNUC_UNUSED const struct audio_format *audio_format, 
     58     const struct config_param *param, 
     59     G_GNUC_UNUSED GError **error) 
     60{ 
     61  roar_t * self = roar_mm_calloc(1, sizeof(*self)); 
     62 
     63  if (self == NULL)  
     64     return NULL; 
     65 
     66  self->err = ROAR_ERROR_NONE; 
     67  roar_configure(self, param); 
     68  return self; 
     69} 
     70 
     71static void 
     72roar_close(void *data) 
     73{ 
     74   roar_t * self = data; 
     75 
     76   if (self->vss != NULL) 
     77   { 
     78      roar_vs_close(self->vss, ROAR_VS_FALSE, &(self->err)); 
     79      self->vss = NULL; 
     80   } 
     81} 
     82 
     83static void 
     84roar_finish(void *data) 
     85{ 
     86   roar_t * self = data; 
     87 
     88   roar_close(data); 
     89 
     90   if (self->host != NULL) 
     91      g_free(self->host); 
     92   if (self->name != NULL) 
     93      g_free(self->name); 
     94 
     95   roar_mm_free(data); 
     96} 
     97 
     98static bool 
     99roar_open(void *data, struct audio_format *audio_format, GError **error) 
     100{ 
     101   roar_t * self = data; 
     102 
     103   self->vss = roar_vs_new_simple(self->host, self->name, audio_format->sample_rate, audio_format->channels, ROAR_CODEC_DEFAULT, 16, ROAR_DIR_PLAY, &(self->err)); 
     104 
     105   if (self->vss == NULL || self->err != ROAR_ERROR_NONE) 
     106   { 
     107      g_set_error(error, roar_output_quark(), 0, "Failed to connect to server"); 
     108      return false; 
     109   } 
     110 
     111   audio_format->format = SAMPLE_FORMAT_S16; 
     112   audio_format->reverse_endian = 0; 
     113 
     114   return true; 
     115} 
     116 
     117// Here we should reopen stream properly. 
     118static void 
     119roar_cancel(G_GNUC_UNUSED void *data) 
     120{ 
     121} 
     122 
     123static size_t 
     124roar_play(void *data, const void *chunk, size_t size, GError **error) 
     125{ 
     126   struct roar * self = data; 
     127   ssize_t rc; 
     128    
     129   rc = roar_vs_write(self->vss, chunk, size, &(self->err)); 
     130   if ( rc <= 0 ) 
     131   { 
     132      g_set_error(error, roar_output_quark(), 0, "Failed to play data"); 
     133      return 0; 
     134   } 
     135 
     136   return rc; 
     137} 
     138 
     139const struct audio_output_plugin roar_output_plugin = { 
     140   .name = "roar", 
     141   .init = roar_init, 
     142   .finish = roar_finish, 
     143   .open = roar_open, 
     144   .play = roar_play, 
     145   .cancel = roar_cancel, 
     146   .close = roar_close, 
     147 
     148   .mixer_plugin = &roar_mixer_plugin 
     149}; 
     150 
     151 
  • src/output_list.c

    diff --git a/src/output_list.c b/src/output_list.c
    index 8238f58..ef8847d 100644
    a b extern const struct audio_output_plugin null_output_plugin; 
    2626extern const struct audio_output_plugin fifo_output_plugin; 
    2727extern const struct audio_output_plugin pipe_output_plugin; 
    2828extern const struct audio_output_plugin alsaPlugin; 
     29extern const struct audio_output_plugin roar_output_plugin; 
    2930extern const struct audio_output_plugin ao_output_plugin; 
    3031extern const struct audio_output_plugin oss_output_plugin; 
    3132extern const struct audio_output_plugin openal_output_plugin; 
    const struct audio_output_plugin *audio_output_plugins[] = { 
    5354#ifdef HAVE_ALSA 
    5455        &alsaPlugin, 
    5556#endif 
     57#ifdef HAVE_ROAR 
     58   &roar_output_plugin, 
     59#endif 
    5660#ifdef HAVE_AO 
    5761        &ao_output_plugin, 
    5862#endif