Changeset 60e5696d in mainline
- Timestamp:
- 2013-04-05T16:02:33Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f465461
- Parents:
- 4389076
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/wavplay/main.c
r4389076 r60e5696d 51 51 static int hplay(const char *filename) 52 52 { 53 printf("H PLAY: %s\n", filename);53 printf("Hound playback: %s\n", filename); 54 54 FILE *source = fopen(filename, "rb"); 55 55 if (!source) { … … 103 103 } 104 104 105 typedef struct {106 FILE *source;107 volatile bool playing;108 fibril_mutex_t mutex;109 fibril_condvar_t cv;110 hound_sess_t *server;111 } playback_t;112 113 static void playback_initialize(playback_t *pb, hound_sess_t *sess)114 {115 assert(pb);116 pb->playing = false;117 pb->source = NULL;118 pb->server = sess;119 fibril_mutex_initialize(&pb->mutex);120 fibril_condvar_initialize(&pb->cv);121 }122 123 static void data_callback(void* arg, void *buffer, ssize_t size)124 {125 playback_t *pb = arg;126 assert(pb);127 128 if (size > 0) {129 const ssize_t bytes =130 fread(buffer, sizeof(uint8_t), size, pb->source);131 printf("%zu bytes ready\n", bytes);132 if (bytes < size) {133 printf(" requested: %zd ready: %zd zero: %zd\n",134 size, bytes, size - bytes);135 bzero(buffer + bytes, size - bytes);136 }137 if (bytes == 0) {138 pb->playing = false;139 printf("The end, nothing more to play.\n");140 fibril_condvar_signal(&pb->cv);141 }142 } else {143 printf("Got error %s.\n", str_error(size));144 pb->playing = false;145 fibril_condvar_signal(&pb->cv);146 }147 }148 149 static int play_hound(const char *filename)150 {151 hound_sess_t *sess = hound_get_session();152 if (!sess) {153 printf("Failed to connect to hound service\n");154 return 1;155 }156 playback_t pb;157 playback_initialize(&pb, sess);158 pb.source = fopen(filename, "rb");159 if (pb.source == NULL) {160 printf("Failed to open %s.\n", filename);161 hound_release_session(sess);162 return 1;163 }164 wave_header_t header;165 fread(&header, sizeof(header), 1, pb.source);166 unsigned rate, channels;167 pcm_sample_format_t format;168 const char *error;169 int ret = wav_parse_header(&header, NULL, NULL, &channels, &rate,170 &format, &error);171 if (ret != EOK) {172 printf("Error parsing wav header: %s.\n", error);173 fclose(pb.source);174 hound_release_session(sess);175 return 1;176 }177 178 /* Create playback client */179 ret = hound_register_playback(pb.server, filename, channels, rate,180 format, data_callback, &pb);181 if (ret != EOK) {182 printf("Failed to register playback: %s\n", str_error(ret));183 fclose(pb.source);184 hound_release_session(sess);185 return 1;186 }187 188 /* Connect */189 ret = hound_create_connection(pb.server, filename, DEFAULT_SINK);190 if (ret == EOK) {191 fibril_mutex_lock(&pb.mutex);192 for (pb.playing = true; pb.playing;193 fibril_condvar_wait(&pb.cv, &pb.mutex));194 fibril_mutex_unlock(&pb.mutex);195 196 hound_destroy_connection(pb.server, filename, DEFAULT_SINK);197 } else198 printf("Failed to connect: %s\n", str_error(ret));199 200 printf("Unregistering playback\n");201 hound_unregister_playback(pb.server, filename);202 printf("Releasing session\n");203 hound_release_session(sess);204 fclose(pb.source);205 return 0;206 }207 208 105 static const struct option opts[] = { 209 106 {"device", required_argument, 0, 'd'}, … … 218 115 printf("supported options:\n"); 219 116 printf("\t -h, --help\t Print this help.\n"); 220 printf("\t -r, --record\t Start recording instead of playback.\n"); 221 printf("\t -d, --device\t Use specified device instead of sound " 222 "service. Use location path or special device `default'\n"); 117 printf("\t -r, --record\t Start recording instead of playback. " 118 "(Not implemented)\n"); 119 printf("\t -d, --device\t Use specified device instead of the sound " 120 "service. Use location path or a special device `default'\n"); 223 121 } 224 122 … … 262 160 } else { 263 161 return hplay(file); 264 return play_hound(file);265 162 } 266 163 }
Note:
See TracChangeset
for help on using the changeset viewer.