Changeset 4960:60cdebcb83ef in roaraudio for libroarpulse
- Timestamp:
- 05/14/11 04:46:29 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- libroarpulse
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libroarpulse/error.c
r4708 r4960 43 43 static const struct { 44 44 int error; 45 int ra_error; 45 46 const char * name; 46 47 } _roar_pa_errors[] = { 47 {PA_OK, "OK" }, 48 {PA_ERR_ACCESS, "Access denied" }, 49 {PA_ERR_COMMAND, "Unknown command" }, 50 {PA_ERR_INVALID, "Invalid argument" }, 51 {PA_ERR_EXIST, "Entity exists" }, 52 {PA_ERR_NOENTITY, "No such entity" }, 53 {PA_ERR_CONNECTIONREFUSED, "Connection refused" }, 54 {PA_ERR_PROTOCOL, "Protocol error" }, 55 {PA_ERR_TIMEOUT, "Timeout" }, 56 {PA_ERR_AUTHKEY, "No authorization key" }, 57 {PA_ERR_INTERNAL, "Internal error" }, 58 {PA_ERR_CONNECTIONTERMINATED, "Connection terminated" }, 59 {PA_ERR_KILLED, "Entity killed" }, 60 {PA_ERR_INVALIDSERVER, "Invalid server" }, 61 {PA_ERR_MODINITFAILED, "Module initalization failed" }, 62 {PA_ERR_BADSTATE, "Bad state" }, 63 {PA_ERR_NODATA, "No data" }, 64 {PA_ERR_VERSION, "Incompatible protocol version" }, 65 {PA_ERR_TOOLARGE, "Too large" }, 66 {PA_ERR_MAX, "MAX" }, 67 {-1, NULL} 48 {PA_OK, ROAR_ERROR_NONE, "OK" }, 49 {PA_ERR_ACCESS, ROAR_ERROR_PERM, "Access denied" }, 50 {PA_ERR_COMMAND, ROAR_ERROR_BADRQC, "Unknown command" }, 51 {PA_ERR_INVALID, ROAR_ERROR_INVAL, "Invalid argument" }, 52 {PA_ERR_EXIST, ROAR_ERROR_EXIST, "Entity exists" }, 53 {PA_ERR_NOENTITY, ROAR_ERROR_NOENT, "No such entity" }, 54 {PA_ERR_CONNECTIONREFUSED, ROAR_ERROR_CONNREFUSED, "Connection refused" }, 55 {PA_ERR_PROTOCOL, ROAR_ERROR_PROTO, "Protocol error" }, 56 {PA_ERR_TIMEOUT, ROAR_ERROR_TIMEDOUT, "Timeout" }, 57 {PA_ERR_AUTHKEY, ROAR_ERROR_PERM, "No authorization key" }, 58 {PA_ERR_INTERNAL, ROAR_ERROR_UNKNOWN, "Internal error" }, 59 {PA_ERR_CONNECTIONTERMINATED, ROAR_ERROR_IO, "Connection terminated" }, 60 {PA_ERR_KILLED, ROAR_ERROR_IO, "Entity killed" }, 61 {PA_ERR_INVALIDSERVER, ROAR_ERROR_INVAL, "Invalid server" }, 62 {PA_ERR_MODINITFAILED, ROAR_ERROR_BADLIB, "Module initalization failed" }, 63 {PA_ERR_BADSTATE, ROAR_ERROR_INVAL, "Bad state" }, 64 {PA_ERR_NODATA, ROAR_ERROR_NODATA, "No data" }, 65 {PA_ERR_VERSION, ROAR_ERROR_NSVERSION, "Incompatible protocol version" }, 66 {PA_ERR_TOOLARGE, ROAR_ERROR_RANGE, "Too large" }, 67 #ifdef PA_ERR_NOTSUPPORTED 68 {PA_ERR_NOTSUPPORTED, ROAR_ERROR_NOTSUP, "Not supported"}, 69 #endif 70 #ifdef PA_ERR_UNKNOWN 71 {PA_ERR_UNKNOWN, ROAR_ERROR_UNKNOWN, "Unknown error code"}, 72 #endif 73 #ifdef PA_ERR_NOEXTENSION 74 {PA_ERR_UNKNOWN, ROAR_ERROR_NOENT, "No such extension"}, 75 #endif 76 #ifdef PA_ERR_OBSOLETE 77 {PA_ERR_OBSOLETE, ROAR_ERROR_NOSYS, "Obsolete functionality"}, 78 #endif 79 #ifdef PA_ERR_NOTIMPLEMENTED 80 {PA_ERR_NOTIMPLEMENTED, ROAR_ERROR_NOSYS, "Missing implementation"}, 81 #endif 82 #ifdef PA_ERR_FORKED 83 {PA_ERR_FORKED, ROAR_ERROR_INVAL, "Client forked"}, 84 #endif 85 #ifdef PA_ERR_IO 86 {PA_ERR_IO, ROAR_ERROR_IO, "Input/Output error"}, 87 #endif 88 #ifdef PA_ERR_BUSY 89 {PA_ERR_BUSY, ROAR_ERROR_BUSY, "Device or resource busy"}, 90 #endif 91 {PA_ERR_MAX, ROAR_ERROR_UNKNOWN, "MAX" }, 92 {-1, ROAR_ERROR_UNKNOWN, NULL} 68 93 }; 69 94 … … 78 103 } 79 104 105 int roar_pa_raerror2paerror(int error) { 106 int i; 107 108 for (i = 0; _roar_pa_errors[i].name != NULL; i++) 109 if ( _roar_pa_errors[i].ra_error == error ) 110 return _roar_pa_errors[i].error; 111 112 return PA_ERR_INVALID; 113 } 114 80 115 //ll -
libroarpulse/sample.c
r4708 r4960 41 41 42 42 /** Return the amount of bytes playback of a second of audio with the specified sample type takes */ 43 size_t pa_bytes_per_second(const pa_sample_spec *spec); 43 size_t pa_bytes_per_second(const pa_sample_spec *spec) { 44 return pa_sample_size(spec) * spec->channels * spec->rate; 45 } 44 46 45 47 /** Return the size of a frame with the specific sample type */ … … 66 68 return 2; 67 69 break; 70 #ifdef PA_SAMPLE_S24LE 71 case PA_SAMPLE_S24LE: 72 case PA_SAMPLE_S24BE: 73 return 3; 74 break; 75 #endif 76 #ifdef PA_SAMPLE_S32LE 77 case PA_SAMPLE_S32LE: 78 case PA_SAMPLE_S32BE: 79 case PA_SAMPLE_S24_32LE: 80 case PA_SAMPLE_S24_32BE: 81 return 4; 82 break; 83 #endif 68 84 default: 69 85 return 0; -
libroarpulse/simple.c
r4708 r4960 40 40 #include <libroarpulse/libroarpulse.h> 41 41 42 #define _seterr() if ( error != NULL ) { *error = roar_pa_raerror2paerror(err); } 43 42 44 /** Create a new connection to the server */ 43 45 pa_simple* pa_simple_new( … … 52 54 int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */ 53 55 ) { 54 struct roarpulse_simple * s; 56 struct roar_keyval kv[1]; 57 roar_vs_t * vss = NULL; 55 58 struct roar_audio_info info; 56 59 int roar_dir; 57 struct roar_meta meta;60 int err = ROAR_ERROR_NONE; 58 61 59 62 if ( dir == PA_STREAM_PLAYBACK ) { … … 69 72 } 70 73 71 if ( (s = roar_mm_malloc(sizeof(struct roarpulse_simple))) == NULL )72 return NULL;73 74 74 server = roar_pa_find_server((char*)server); 75 75 76 if ( roar_simple_connect(&(s->con), (char*)server, (char*)name) == -1 ) { 77 roar_mm_free(s); 76 vss = roar_vs_new(server, name, &err); 77 if ( vss == NULL ) { 78 _seterr(); 78 79 return NULL; 79 80 } 80 81 81 if ( roar_vio_simple_new_stream_obj(&(s->vio), &(s->con), &(s->stream), 82 info.rate, info.channels, 83 info.bits, info.codec, roar_dir) == -1 ) { 84 roar_disconnect(&(s->con)); 85 roar_mm_free(s); 82 if ( roar_vs_stream(vss, &info, roar_dir, &err) == -1 ) { 83 roar_vs_close(vss, ROAR_VS_TRUE, NULL); 84 _seterr(); 86 85 return NULL; 87 86 } 88 87 89 88 if ( stream_name != NULL && stream_name[0] != 0 ) { 90 meta.value = (char*)stream_name; 91 meta.key[0] = 0; 92 meta.type = ROAR_META_TYPE_DESCRIPTION; 89 kv[0].key = "DESCRIPTION"; 90 kv[1].value = (char*)stream_name; 93 91 94 roar_ stream_meta_set(&(s->con), &(s->stream), ROAR_META_MODE_SET, &meta);92 roar_vs_meta(vss, kv, 1, NULL); 95 93 } 96 94 97 return (pa_simple*) s;95 return (pa_simple*) vss; 98 96 } 99 97 100 98 /** Close and free the connection to the server. The connection objects becomes invalid when this is called. */ 101 99 void pa_simple_free(pa_simple *s) { 102 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;103 104 100 if ( s == NULL ) 105 101 return; 106 102 107 roar_vio_close(&(ss->vio)); 108 roar_disconnect(&(ss->con)); 109 110 roar_mm_free(s); 103 roar_vs_close((roar_vs_t*)s, ROAR_VS_FALSE, NULL); 111 104 } 112 105 113 106 /** Write some data to the server */ 114 107 int pa_simple_write(pa_simple *s, const void*data, size_t length, int *error) { 115 struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 108 int ret; 109 int err = ROAR_ERROR_NONE; 116 110 117 111 if ( s == NULL ) 118 112 return -1; 119 113 120 return roar_vio_write(&(ss->vio), (char*) data, length); 114 ret = roar_vs_write((roar_vs_t*)s, data, length, &err); 115 116 _seterr(); 117 118 return ret; 121 119 } 122 120 123 121 /** Wait until all data already written is played by the daemon */ 124 122 int pa_simple_drain(pa_simple *s, int *error) { 125 // struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 123 int ret; 124 int err = ROAR_ERROR_NONE; 126 125 127 126 if ( s == NULL ) 128 127 return -1; 129 128 130 pa_simple_flush(s, error);129 ret = roar_vs_sync((roar_vs_t*)s, ROAR_VS_WAIT, &err); 131 130 132 return -1; 131 _seterr(); 132 133 return ret; 133 134 } 134 135 135 136 /** Read some data from the server */ 136 137 int pa_simple_read(pa_simple *s, void*data, size_t length, int *error) { 137 struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 138 int ret; 139 int err = ROAR_ERROR_NONE; 138 140 139 141 if ( s == NULL ) 140 142 return -1; 141 143 142 return roar_vio_read(&(ss->vio), data, length); 144 ret = roar_vs_read((roar_vs_t*)s, data, length, &err); 145 146 _seterr(); 147 148 return ret; 143 149 } 144 150 145 151 /** Return the playback latency. \since 0.5 */ 146 152 pa_usec_t pa_simple_get_latency(pa_simple *s, int *error) { 147 struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 153 roar_mus_t ret; 154 int err = ROAR_ERROR_NONE; 148 155 149 156 if ( s == NULL ) 150 157 return -1; 151 158 152 return -1; 159 ret = roar_vs_latency((roar_vs_t*)s, ROAR_VS_BACKEND_DEFAULT, &err); 160 161 if ( ret < 0 ) 162 ret *= -1; 163 164 if ( ret == 0 && err != ROAR_ERROR_NONE ) { 165 _seterr(); 166 return -1; 167 } 168 169 return ret; 153 170 } 154 171 155 172 /** Flush the playback buffer. \since 0.5 */ 156 173 int pa_simple_flush(pa_simple *s, int *error) { 157 struct roarpulse_simple * ss = (struct roarpulse_simple*) s; 174 int ret; 175 int err = ROAR_ERROR_NONE; 158 176 159 177 if ( s == NULL ) 160 178 return -1; 161 179 162 return roar_vio_sync(&(ss->vio)); 180 ret = roar_vs_sync((roar_vs_t*)s, ROAR_VS_NOWAIT, &err); 181 182 _seterr(); 183 184 return ret; 163 185 } 164 186 -
libroarpulse/util.c
r4896 r4960 72 72 73 73 /** Return the current username in the specified string buffer. */ 74 char *pa_get_user_name(char *s, size_t l); 74 char *pa_get_user_name(char *s, size_t l) { 75 char * user = NULL; 76 77 if ( s == NULL ) { 78 roar_err_set(ROAR_ERROR_FAULT); 79 roar_err_to_errno(); 80 return NULL; 81 } 82 83 if ( user == NULL ) 84 user = getenv("USER"); 85 if ( user == NULL ) 86 user = getenv("LOGNAME"); 87 if ( user == NULL ) 88 user = getenv("USERNAME"); 89 90 #ifdef ROAR_HAVE_GETUID 91 if ( user == NULL ) 92 if ( getuid() == 0 ) 93 user = "root"; 94 #endif 95 96 if ( user == NULL ) { 97 roar_err_set(ROAR_ERROR_NOENT); 98 roar_err_to_errno(); 99 return NULL; 100 } 101 102 strncpy(s, user, l); 103 s[l-1] = 0; 104 105 return s; 106 } 75 107 76 108 /** Return the current hostname in the specified buffer. */ 77 char *pa_get_host_name(char *s, size_t l); 109 char *pa_get_host_name(char *s, size_t l) { 110 #ifdef ROAR_HAVE_GETHOSTNAME 111 if (gethostname(s, l) == -1) 112 return NULL; 113 114 s[l-1] = 0; 115 return s; 116 #else 117 roar_err_set(ROAR_ERROR_NOSYS); 118 roar_err_to_errno(); 119 return NULL; 120 #endif 121 } 78 122 79 123 /** Return the fully qualified domain name in s */
Note: See TracChangeset
for help on using the changeset viewer.