XMMS2
|
00001 /* XMMS2 - X Music Multiplexer System 00002 * Copyright (C) 2003-2009 XMMS2 Team 00003 * 00004 * PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!! 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 */ 00016 00017 /** @defgroup Visualization Common 00018 * @brief Common structs for the visualization client and server 00019 * @{ 00020 */ 00021 00022 #ifndef __XMMS_VIS_COMMON_H__ 00023 #define __XMMS_VIS_COMMON_H__ 00024 00025 /* 512 is what libvisual wants for pcm data. 00026 we won't deliver more than 512 samples at once. */ 00027 #define XMMSC_VISUALIZATION_WINDOW_SIZE 512 00028 00029 #ifdef __cplusplus 00030 extern "C" { 00031 #endif 00032 00033 #include <sys/time.h> 00034 00035 #include "xmmsc/xmmsc_stdint.h" 00036 #include "xmmsc/xmmsc_sockets.h" 00037 00038 double tv2ts (struct timeval *t); 00039 double net2ts (int32_t* s); 00040 void ts2net (int32_t* d, double t); 00041 void tv2net (int32_t* d, struct timeval *t); 00042 00043 /* Note that features should only be added to the packet data, _not_ 00044 removed. The packet's format should stay downwardly compatible. 00045 The client only tests if the server's version is equal or greater 00046 than the client's version! */ 00047 #define XMMS_VISPACKET_VERSION 1 00048 00049 /* How many packages are in the shm queue? 00050 * one package the server can operate on 00051 * one packate the client can operate on 00052 * to avoid needing to be in sync, one spare packet 00053 * XXX packets to compensate the latency (TODO: find a good value) */ 00054 #define XMMS_VISPACKET_SHMCOUNT 500 00055 00056 /** 00057 * Package format for vis data, encapsulated by unixshm or udp transport 00058 */ 00059 00060 typedef struct { 00061 int32_t timestamp[2]; 00062 uint16_t format; 00063 uint16_t size; 00064 int16_t data[2 * XMMSC_VISUALIZATION_WINDOW_SIZE]; 00065 } xmmsc_vischunk_t; 00066 00067 /** 00068 * UDP package _descriptor_ to deliver a vis chunk 00069 */ 00070 00071 typedef struct { 00072 char *__unaligned_type; /* = 'V' */; 00073 uint16_t *__unaligned_grace; 00074 xmmsc_vischunk_t *__unaligned_data; 00075 int size; 00076 } xmmsc_vis_udp_data_t; 00077 00078 #define XMMSC_VIS_UNALIGNED_WRITE(dst, src, typ) do { \ 00079 typ *__d = (dst); \ 00080 typ __s = (src); \ 00081 memcpy (__d, &__s, sizeof (typ)); \ 00082 } while (0) 00083 00084 #define XMMSC_VIS_UNALIGNED_READ(dst, src, typ) do { \ 00085 typ *__s = (src); \ 00086 memcpy (&(dst), __s, sizeof (typ)); \ 00087 } while (0) 00088 00089 00090 00091 #define XMMS_VISPACKET_UDP_OFFSET (1 + sizeof (uint16_t)) 00092 00093 /** 00094 * UDP package _descriptor_ to synchronize time 00095 */ 00096 00097 typedef struct { 00098 char *__unaligned_type; /* = 'T' */ 00099 int32_t *__unaligned_id; 00100 int32_t *__unaligned_clientstamp; 00101 int32_t *__unaligned_serverstamp; 00102 int size; 00103 } xmmsc_vis_udp_timing_t; 00104 00105 char* packet_init_data (xmmsc_vis_udp_data_t *p); 00106 char* packet_init_timing (xmmsc_vis_udp_timing_t *p); 00107 00108 /** 00109 * Possible data modes 00110 */ 00111 00112 typedef enum { 00113 VIS_PCM, 00114 VIS_SPECTRUM, 00115 VIS_PEAK 00116 } xmmsc_vis_data_t; 00117 00118 /** 00119 * Properties of the delivered vis data. The client doesn't use this struct 00120 * to date, but perhaps could in future 00121 */ 00122 00123 typedef struct { 00124 /* type of data */ 00125 xmmsc_vis_data_t type; 00126 /* wether to send both channels seperate, or mixed */ 00127 int stereo; 00128 /* wether the stereo signal should go 00001111 (false) or 01010101 (true) */ 00129 int pcm_hardwire; 00130 00131 /* TODO: implement following.. */ 00132 double freq; 00133 double timeframe; 00134 /* pcm amount of data wanted */ 00135 int pcm_samplecount; 00136 /* pcm bitsize wanted */ 00137 /* TODO xmms_sample_format_t pcm_sampleformat;*/ 00138 } xmmsc_vis_properties_t; 00139 00140 /** 00141 * Possible vis transports 00142 */ 00143 00144 typedef enum { 00145 VIS_UNIXSHM, 00146 VIS_UDP, 00147 VIS_NONE 00148 } xmmsc_vis_transport_t; 00149 00150 typedef enum { 00151 VIS_NEW, 00152 VIS_TRYING_UNIXSHM, 00153 VIS_TO_TRY_UDP, 00154 VIS_TRYING_UDP, 00155 VIS_ERRORED, 00156 VIS_WORKING, 00157 } xmmsc_vis_state_t; 00158 00159 /** 00160 * data describing a unixshm transport 00161 */ 00162 00163 typedef struct { 00164 int semid; 00165 int shmid; 00166 xmmsc_vischunk_t *buffer; 00167 int pos, size; 00168 } xmmsc_vis_unixshm_t; 00169 00170 /** 00171 * data describing a udp transport 00172 */ 00173 00174 typedef struct { 00175 // client address, used by server 00176 struct sockaddr_storage addr; 00177 // file descriptors, used by the client 00178 xmms_socket_t socket[2]; 00179 // watch adjustment, used by the client 00180 double timediff; 00181 // grace value (lifetime of the client without pong) 00182 int grace; 00183 } xmmsc_vis_udp_t; 00184 00185 #ifdef __cplusplus 00186 } 00187 #endif 00188 00189 #endif 00190 00191 /** @} */