[950] | 1 | //driver_sout.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include "roard.h" |
---|
| 26 | #ifdef ROAR_HAVE_LIBSHOUT |
---|
| 27 | |
---|
| 28 | int _driver_shout_usage_counter = 0; |
---|
| 29 | |
---|
| 30 | int driver_shout_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh) { |
---|
| 31 | char * s_server = NULL; |
---|
| 32 | char * s_mount = NULL; |
---|
| 33 | char * s_pw = NULL; |
---|
| 34 | int s_port = -1; |
---|
| 35 | char * s_desc = NULL; |
---|
| 36 | char * s_genre = NULL; |
---|
| 37 | char * s_name = NULL; |
---|
| 38 | char * s_url = NULL; |
---|
| 39 | int s_public = 0; |
---|
| 40 | shout_t * shout; |
---|
| 41 | |
---|
| 42 | if ( info->codec == ROAR_CODEC_DEFAULT ) |
---|
| 43 | info->codec = ROAR_CODEC_OGG_VORBIS; |
---|
| 44 | |
---|
| 45 | if ( info->codec != ROAR_CODEC_OGG_VORBIS ) { |
---|
| 46 | ROAR_ERR("This driver only supports Ogg/Vorbis, current codec is %s", roar_codec2str(info->codec)); |
---|
| 47 | return -1; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | ROAR_WARN("try to connect..."); |
---|
| 51 | |
---|
| 52 | if ( s_server == NULL ) |
---|
| 53 | s_server = "localhost"; |
---|
| 54 | |
---|
| 55 | if ( s_mount == NULL ) |
---|
| 56 | s_mount = "/roar.ogg"; |
---|
| 57 | |
---|
| 58 | if ( s_pw == NULL ) |
---|
| 59 | s_pw = "hackme"; |
---|
| 60 | |
---|
| 61 | if ( s_port == -1 ) |
---|
| 62 | s_port = 8000; |
---|
| 63 | |
---|
| 64 | if ( _driver_shout_usage_counter++ == 0 ) |
---|
| 65 | shout_init(); |
---|
| 66 | |
---|
| 67 | if (!(shout = shout_new())) { |
---|
| 68 | ROAR_ERR("Can not clreate shout object"); |
---|
| 69 | return 1; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | if (shout_set_host(shout, s_server) != SHOUTERR_SUCCESS) { |
---|
| 73 | ROAR_ERR("Error setting hostname: %s", shout_get_error(shout)); |
---|
| 74 | return 1; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) { |
---|
| 78 | ROAR_ERR("Error setting protocol: %s", shout_get_error(shout)); |
---|
| 79 | return 1; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if (shout_set_port(shout, s_port) != SHOUTERR_SUCCESS) { |
---|
| 83 | ROAR_ERR("Error setting port: %s", shout_get_error(shout)); |
---|
| 84 | return 1; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | if (shout_set_password(shout, s_pw) != SHOUTERR_SUCCESS) { |
---|
| 88 | ROAR_ERR("Error setting password: %s", shout_get_error(shout)); |
---|
| 89 | return 1; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | if (shout_set_mount(shout, s_mount) != SHOUTERR_SUCCESS) { |
---|
| 93 | ROAR_ERR("Error setting mount: %s", shout_get_error(shout)); |
---|
| 94 | return 1; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) { |
---|
| 98 | ROAR_ERR("Error setting user: %s", shout_get_error(shout)); |
---|
| 99 | return 1; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) { |
---|
| 103 | ROAR_ERR("Error setting format: %s", shout_get_error(shout)); |
---|
| 104 | return 1; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | shout_set_public(shout, s_public); |
---|
| 108 | |
---|
| 109 | if (s_desc != NULL) |
---|
| 110 | shout_set_description(shout, s_desc); |
---|
| 111 | |
---|
| 112 | if (s_genre != NULL) |
---|
| 113 | shout_set_genre(shout, s_genre); |
---|
| 114 | |
---|
| 115 | if (s_name != NULL) |
---|
| 116 | shout_set_name(shout, s_name); |
---|
| 117 | |
---|
| 118 | if (s_url != NULL) |
---|
| 119 | shout_set_url(shout, s_url); |
---|
| 120 | |
---|
| 121 | if (shout_open(shout) != SHOUTERR_SUCCESS) { |
---|
| 122 | ROAR_ERR("Can not open connection via libshout!"); |
---|
| 123 | return -1; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | memset(inst, 0, sizeof(struct roar_vio_calls)); |
---|
| 127 | inst->inst = (void*)shout; |
---|
| 128 | inst->write = driver_shout_write; |
---|
| 129 | |
---|
| 130 | return 0; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | int driver_shout_close(DRIVER_USERDATA_T inst) { |
---|
| 134 | |
---|
| 135 | shout_close((shout_t *)((struct roar_vio_calls *)inst)->inst); |
---|
| 136 | |
---|
| 137 | if ( _driver_shout_usage_counter-- == 1 ) |
---|
| 138 | shout_shutdown(); |
---|
| 139 | |
---|
| 140 | return 0; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | ssize_t driver_shout_write(struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 144 | if (shout_send((shout_t *)vio->inst, (unsigned char*)buf, count) != SHOUTERR_SUCCESS) |
---|
| 145 | return -1; |
---|
| 146 | |
---|
| 147 | return count; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | #endif |
---|
| 151 | //ll |
---|