Changeset f1438e5 in mainline
- Timestamp:
- 2013-04-05T12:20:18Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 50179b63
- Parents:
- d988ef2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/audio/hound/hound_ctx.c
rd988ef2 rf1438e5 101 101 typedef struct hound_ctx_stream { 102 102 link_t link; 103 list_t fifo;103 audio_pipe_t fifo; 104 104 hound_ctx_t *ctx; 105 105 pcm_format_t format; 106 106 int flags; 107 107 size_t allowed_size; 108 size_t current_size;109 108 } hound_ctx_stream_t; 110 109 … … 120 119 hound_ctx_stream_t *stream = malloc(sizeof(hound_ctx_stream_t)); 121 120 if (stream) { 122 list_initialize(&stream->fifo);121 audio_pipe_init(&stream->fifo); 123 122 link_initialize(&stream->link); 124 123 stream->ctx = ctx; … … 126 125 stream->format = format; 127 126 stream->allowed_size = buffer_size; 128 stream->current_size = 0;129 127 list_append(&stream->link, &ctx->streams); 130 128 log_verbose("CTX: %p added stream; flags:%#x ch: %u r:%u f:%s", … … 140 138 //TODO consider DRAIN FLAG 141 139 list_remove(&stream->link); 142 if ( !list_empty(&stream->fifo))140 if (audio_pipe_bytes(&stream->fifo)) 143 141 log_warning("Destroying stream with non empty buffer"); 144 while (!list_empty(&stream->fifo)) { 145 link_t *l = list_first(&stream->fifo); 146 audio_data_link_t *data = 147 audio_data_link_list_instance(l); 148 list_remove(l); 149 audio_data_link_destroy(data); 150 } 142 audio_pipe_fini(&stream->fifo); 151 143 log_verbose("CTX: %p remove stream (%zu/%zu); " 152 144 "flags:%#x ch: %u r:%u f:%s", 153 stream->ctx, stream->current_size, stream->allowed_size,154 stream-> flags, stream->format.channels,155 stream->format. sampling_rate,145 stream->ctx, audio_pipe_bytes(&stream->fifo), 146 stream->allowed_size, stream->flags, 147 stream->format.channels, stream->format.sampling_rate, 156 148 pcm_sample_format_str(stream->format.sample_format)); 157 149 free(stream); … … 170 162 171 163 if (stream->allowed_size && 172 ( stream->current_size+ size > stream->allowed_size))164 (audio_pipe_bytes(&stream->fifo) + size > stream->allowed_size)) 173 165 return EBUSY; 174 166 175 audio_data_link_t *adatalink = 176 audio_data_link_create_data(data, size, stream->format); 177 if (adatalink) { 178 list_append(&adatalink->link, &stream->fifo); 179 stream->current_size += size; 180 return EOK; 181 } 182 log_warning("Failed to enqueue %zu bytes of data.", size); 183 return ENOMEM; 167 return audio_pipe_push_data(&stream->fifo, data, size, stream->format); 184 168 } 185 169 … … 194 178 { 195 179 assert(stream); 196 const size_t src_frame_size = pcm_format_frame_size(&stream->format); 197 const size_t dst_frame_size = pcm_format_frame_size(f); 198 //TODO consider sample rate 199 size_t needed_frames = size / dst_frame_size; 200 while (needed_frames > 0 && !list_empty(&stream->fifo)) { 201 link_t *l = list_first(&stream->fifo); 202 audio_data_link_t *alink = audio_data_link_list_instance(l); 203 /* Get actual audio data chunk */ 204 const size_t available_frames = 205 audio_data_link_available_frames(alink); 206 const size_t copy_frames = min(available_frames, needed_frames); 207 const size_t copy_size = copy_frames * dst_frame_size; 208 209 /* Copy audio data */ 210 pcm_format_convert_and_mix(data, copy_size, 211 audio_data_link_start(alink), 212 audio_data_link_remain_size(alink), 213 &alink->adata->format, f); 214 215 /* Update values */ 216 needed_frames -= copy_frames; 217 data += copy_size; 218 alink->position += (copy_frames * src_frame_size); 219 if (audio_data_link_remain_size(alink) == 0) { 220 list_remove(&alink->link); 221 audio_data_link_destroy(alink); 222 } else { 223 assert(needed_frames == 0); 224 } 225 } 226 return ENOTSUP; 180 const ssize_t copied_size = 181 audio_pipe_mix_data(&stream->fifo, data, size, f); 182 if (copied_size != (ssize_t)size) 183 log_warning("Not enough data in stream buffer"); 184 return copied_size > 0 ? EOK : copied_size; 227 185 } 228 186 … … 230 188 { 231 189 assert(stream); 232 while ( !list_empty(&stream->fifo))190 while (audio_pipe_bytes(&stream->fifo)) 233 191 async_usleep(10000); 234 192 }
Note:
See TracChangeset
for help on using the changeset viewer.