Changeset 6b0cfa1 in mainline
- Timestamp:
- 2013-03-16T23:19:45Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 89d3946f
- Parents:
- 5c1b3cd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/wavplay/main.c
r5c1b3cd r6b0cfa1 46 46 #include "wave.h" 47 47 48 #define NAME_MAX 3249 char name[NAME_MAX + 1];50 51 48 typedef struct { 52 49 FILE* source; … … 93 90 } 94 91 95 static void play(playback_t *pb, unsigned channels, unsigned rate, pcm_sample_format_t format) 96 { 97 assert(pb); 92 static int play_hound(const char *filename) 93 { 94 hound_sess_t *sess = hound_get_session(); 95 if (!sess) { 96 printf("Failed to connect to hound service\n"); 97 return 1; 98 } 99 playback_t pb; 100 playback_initialize(&pb, sess); 101 pb.source = fopen(filename, "rb"); 102 if (pb.source == NULL) { 103 printf("Failed to open %s.\n", filename); 104 hound_release_session(sess); 105 return 1; 106 } 107 wave_header_t header; 108 fread(&header, sizeof(header), 1, pb.source); 109 unsigned rate, channels; 110 pcm_sample_format_t format; 111 const char *error; 112 int ret = wav_parse_header(&header, NULL, NULL, &channels, &rate, 113 &format, &error); 114 if (ret != EOK) { 115 printf("Error parsing wav header: %s.\n", error); 116 fclose(pb.source); 117 hound_release_session(sess); 118 return 1; 119 } 120 98 121 /* Create playback client */ 99 int ret = hound_register_playback(pb->server,name, channels, rate,100 format, data_callback, pb);122 ret = hound_register_playback(pb.server, filename, channels, rate, 123 format, data_callback, &pb); 101 124 if (ret != EOK) { 102 125 printf("Failed to register playback: %s\n", str_error(ret)); 103 return; 126 fclose(pb.source); 127 hound_release_session(sess); 128 return 1; 104 129 } 105 130 106 131 /* Connect */ 107 ret = hound_create_connection(pb ->server,name, DEFAULT_SINK);132 ret = hound_create_connection(pb.server, filename, DEFAULT_SINK); 108 133 if (ret == EOK) { 109 fibril_mutex_lock(&pb ->mutex);110 for (pb ->playing = true; pb->playing;111 fibril_condvar_wait(&pb ->cv, &pb->mutex));112 fibril_mutex_unlock(&pb ->mutex);113 114 hound_destroy_connection(pb ->server,name, DEFAULT_SINK);134 fibril_mutex_lock(&pb.mutex); 135 for (pb.playing = true; pb.playing; 136 fibril_condvar_wait(&pb.cv, &pb.mutex)); 137 fibril_mutex_unlock(&pb.mutex); 138 139 hound_destroy_connection(pb.server, filename, DEFAULT_SINK); 115 140 } else 116 141 printf("Failed to connect: %s\n", str_error(ret)); 117 142 118 143 printf("Unregistering playback\n"); 119 hound_unregister_playback(pb->server, name); 144 hound_unregister_playback(pb.server, filename); 145 printf("Releasing session\n"); 146 hound_release_session(sess); 147 fclose(pb.source); 148 return 0; 120 149 } 121 150 … … 174 203 if (direct) 175 204 return dplay(device, file); 176 177 task_id_t tid = task_get_id(); 178 snprintf(name, NAME_MAX, "%s%" PRIu64 ":%s", argv[0], tid, file); 179 180 printf("Client name: %s\n", name); 181 182 hound_sess_t *sess = hound_get_session(); 183 if (!sess) { 184 printf("Failed to connect to hound service\n"); 185 return 1; 186 } 187 188 playback_t pb; 189 playback_initialize(&pb, sess); 190 pb.source = fopen(file, "rb"); 191 if (pb.source == NULL) { 192 printf("Failed to open %s.\n", file); 193 hound_release_session(sess); 194 return 1; 195 } 196 wave_header_t header; 197 fread(&header, sizeof(header), 1, pb.source); 198 unsigned rate, channels; 199 pcm_sample_format_t format; 200 const char *error; 201 ret = wav_parse_header(&header, NULL, NULL, &channels, &rate, 202 &format, &error); 203 if (ret != EOK) { 204 printf("Error parsing wav header: %s.\n", error); 205 fclose(pb.source); 206 hound_release_session(sess); 207 return 1; 208 } 209 210 play(&pb, channels, rate, format); 211 212 printf("Releasing session\n"); 213 hound_release_session(sess); 214 return 0; 205 else 206 return play_hound(file); 215 207 } 216 208 /**
Note:
See TracChangeset
for help on using the changeset viewer.