Changeset 5221:aa6530a03260 in roaraudio for libroaryiff
- Timestamp:
- 11/12/11 12:25:21 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroaryiff/playback.c
r4708 r5221 36 36 #include <libroaryiff.h> 37 37 38 #define BUFFERSIZE 8192 39 40 #ifdef ROAR_HAVE_IO_POSIX 41 #define _CAN_OPERATE 42 #endif 43 38 44 YID YStartPlaySoundObjectSimple (YConnection *con, const char *path) { 39 45 return YStartPlaySoundObject(con, path, NULL); 46 } 47 48 static inline ssize_t _file_play (struct roar_connection * con, const char * file, struct roar_stream * s) { 49 #ifdef _CAN_OPERATE 50 int codec = -1; 51 int in, out = -1; 52 ssize_t r = 0; 53 int seek; 54 int len; 55 char buf[BUFFERSIZE]; 56 int rate = ROAR_RATE_DEFAULT, channels = ROAR_CHANNELS_DEFAULT, bits = ROAR_BITS_DEFAULT; 57 58 // FIXME: check error cases 59 60 ROAR_DBG("roar_file_play_full(*) = ?"); 61 62 #ifdef ROAR_TARGET_WIN32 63 if ( (in = open(file, O_RDONLY|O_BINARY, 0644)) == -1 ) { 64 #else 65 if ( (in = open(file, O_RDONLY, 0644)) == -1 ) { 66 #endif 67 roar_err_from_errno(); 68 return -1; 69 } 70 71 if ((len = read(in, buf, BUFFERSIZE)) < 1) { 72 roar_err_from_errno(); 73 close(in); 74 return -1; 75 } 76 77 codec = roar_file_codecdetect(buf, len); 78 79 ROAR_DBG("roar_file_play_full(*): codec=%i(%s)", codec, roar_codec2str(codec)); 80 81 seek = lseek(in, 0, SEEK_SET) == (off_t) -1 ? 0 : 1; 82 83 if ( codec == -1 ) { 84 ROAR_WARN("roar_file_play_full(*): Unknown codec of file: %s", file); 85 close(in); 86 roar_err_set(ROAR_ERROR_BADMAGIC); 87 return -1; 88 } 89 90 if ( !seek ) { 91 ROAR_WARN("roar_file_play_full(*): passfh on non seekable file: this may produce incorrect playback"); 92 close(in); 93 roar_err_set(ROAR_ERROR_NOSEEK); 94 return -1; 95 } 96 97 if ( roar_stream_new(s, rate, channels, bits, codec) == -1 ) { 98 close(in); 99 return -1; 100 } 101 102 if ( roar_stream_connect2(con, s, ROAR_DIR_PLAY, -1) == -1 ) { 103 close(in); 104 return -1; 105 } 106 107 if ( roar_stream_passfh(con, s, in) == -1 ) { 108 close(in); 109 roar_kick(con, ROAR_OT_STREAM, roar_stream_get_id(s)); 110 return -1; 111 } 112 113 close(out); 114 close(in); 115 return 0; 116 117 return r; 118 #else 119 roar_err_set(ROAR_ERROR_NOSYS); 120 return -1; 121 #endif 40 122 } 41 123 … … 44 126 struct roar_stream stream[1]; 45 127 46 if ( !con)128 if ( con == NULL ) 47 129 return YIDNULL; 48 130 49 if ( !path)131 if ( path == NULL ) 50 132 return YIDNULL; 51 133 … … 56 138 // in background 57 139 58 if ( roar_file_play_full(&rcon, (char*)path, 0, 1, stream) == -1 ) {140 if ( _file_play(&rcon, path, stream) == -1 ) { 59 141 ROAR_ERR("Can not start playback"); 60 142 return YIDNULL;
Note: See TracChangeset
for help on using the changeset viewer.