Changeset 5221:aa6530a03260 in roaraudio for libroar
- Timestamp:
- 11/12/11 12:25:21 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/file.c
r5148 r5221 198 198 199 199 200 ssize_t roar_file_play (struct roar_connection * con, char * file, int exec) {201 return roar_file_play_full(con, file, exec, 0, NULL);202 }203 204 ssize_t roar_file_play_full (struct roar_connection * con, char * file, int exec, int passfh, struct roar_stream * s) {205 #ifdef _CAN_OPERATE206 int codec = -1;207 int in, out = -1;208 ssize_t r = 0;209 int seek;210 int len;211 char buf[BUFFERSIZE];212 int rate = ROAR_RATE_DEFAULT, channels = ROAR_CHANNELS_DEFAULT, bits = ROAR_BITS_DEFAULT;213 struct roar_stream localstream[1];214 215 // FIXME: check error cases216 217 ROAR_DBG("roar_file_play_full(*) = ?");218 219 if ( s == NULL )220 s = localstream;221 222 if ( con == NULL ) {223 roar_err_set(ROAR_ERROR_FAULT);224 return -1;225 }226 227 if ( file == NULL ) {228 roar_err_set(ROAR_ERROR_FAULT);229 return -1;230 }231 232 if ( exec && passfh ) {233 roar_err_set(ROAR_ERROR_INVAL);234 return -1;235 }236 237 #ifdef ROAR_TARGET_WIN32238 if ( (in = open(file, O_RDONLY|O_BINARY, 0644)) == -1 ) {239 #else240 if ( (in = open(file, O_RDONLY, 0644)) == -1 ) {241 #endif242 roar_err_from_errno();243 return -1;244 }245 246 if ((len = read(in, buf, BUFFERSIZE)) < 1) {247 roar_err_from_errno();248 close(in);249 return -1;250 }251 252 codec = roar_file_codecdetect(buf, len);253 254 ROAR_DBG("roar_file_play_full(*): codec=%i(%s)", codec, roar_codec2str(codec));255 256 seek = lseek(in, 0, SEEK_SET) == (off_t) -1 ? 0 : 1;257 258 if ( codec == -1 ) {259 ROAR_WARN("roar_file_play_full(*): Unknown codec of file: %s", file);260 close(in);261 roar_err_set(ROAR_ERROR_BADMAGIC);262 return -1;263 }264 265 if ( passfh && !seek ) {266 ROAR_WARN("roar_file_play_full(*): passfh on non seekable file: this may produce incorrect playback");267 }268 269 if ( exec ) {270 if ( roar_stream_new(s, rate, channels, bits, codec) == -1 ) {271 ROAR_DBG("roar_file_play_full(*): Can not create new stream. This is realy BAD!");272 close(in);273 return -1;274 }275 276 if ( roar_stream_connect2(con, s, ROAR_DIR_PLAY, -1) == -1 ) {277 ROAR_DBG("roar_file_play_full(*): Can not connect new stream to server.");278 close(in);279 return -1;280 }281 282 if ( roar_stream_exec(con, s) == -1 ) {283 ROAR_DBG("roar_file_play_full(*): Can not exec new stream on server.");284 close(in);285 return -1;286 }287 288 roar_libroar_nowarn();289 if ( (out = roar_get_connection_fh(con)) == -1 ) {290 ROAR_DBG("roar_file_play_full(*): Can not get socket of server connection for exec data transmition.");291 close(in);292 roar_libroar_warn();293 return -1;294 }295 roar_libroar_warn();296 297 ROAR_SHUTDOWN(out, SHUT_RD);298 } else {299 if ( !(passfh && seek) ) {300 if ( (out = roar_simple_new_stream_obj(con, s, rate, channels, bits, codec, ROAR_DIR_PLAY)) == -1 ) {301 close(in);302 return -1;303 }304 } else {305 if ( roar_stream_new(s, rate, channels, bits, codec) == -1 ) {306 close(in);307 return -1;308 }309 310 if ( roar_stream_connect2(con, s, ROAR_DIR_PLAY, -1) == -1 ) {311 close(in);312 return -1;313 }314 }315 }316 317 if ( !seek )318 ROAR_NETWORK_WRITE(out, buf, len);319 320 if ( !passfh ) {321 #ifndef ROAR_TARGET_WIN32322 r = roar_file_send_raw(out, in);323 324 close(out);325 #else326 while ((len = read(in, buf, BUFFERSIZE)) > 0)327 if ( send(out, buf, len, 0) != len )328 break;329 330 closesocket(out);331 #endif332 333 if ( exec ) {334 // TODO: FIXME: this ma cause a memory leak in future335 // OLD: con->fh = -1;336 roar_connect_fh(con, -2);337 }338 339 close(in);340 } else {341 if ( roar_stream_passfh(con, s, in) == -1 ) {342 return -1;343 }344 close(out);345 close(in);346 return 0;347 }348 349 return r;350 #else351 roar_err_set(ROAR_ERROR_NOSYS);352 return -1;353 #endif354 }355 356 200 char * roar_cdromdevice (void) { 357 201 char * k;
Note: See TracChangeset
for help on using the changeset viewer.