Changeset ec49085 in mainline for uspace/srv/audio/hound/audio_source.c
- Timestamp:
- 2012-07-12T17:21:08Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 992ef56
- Parents:
- 737b4c0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/audio/hound/audio_source.c
r737b4c0 rec49085 36 36 #include <assert.h> 37 37 #include <errno.h> 38 #include <macros.h> 38 39 #include <stdlib.h> 39 40 #include <str.h> … … 76 77 } 77 78 78 int audio_source_get_buffer(audio_source_t *source, const void **buffer, size_t *size) 79 int audio_source_add_self(audio_source_t *source, void *buffer, size_t size, 80 const audio_format_t *f) 79 81 { 80 82 assert(source); 81 if (!buffer || !size) { 82 log_debug("Incorrect parameters."); 83 if (!buffer) { 84 log_debug("Non-existent buffer"); 85 return EBADMEM; 86 } 87 if (!f || size == 0) { 88 log_debug("No format or zero size"); 89 } 90 if (size % (pcm_sample_format_size(f->sample_format) * f->channels)) { 91 log_debug("Buffer does not fit integer number of frames"); 83 92 return EINVAL; 84 93 } 85 if ( source->get_data.hook)86 source->get_data.hook(source->get_data.arg);87 if (!source->available.base || !source->available.size)88 return EOVERFLOW; /* In fact it's underflow */94 if (!audio_format_same(&source->format, f)) { 95 log_debug("Format conversion is not supported yet"); 96 return ENOTSUP; 97 } 89 98 90 const size_t requested_size = 91 (*size == 0) || (*size > source->available.size) 92 ? source->available.size : *size; 93 *buffer = source->available.base; 94 *size = requested_size; 95 source->available.size -= requested_size; 96 source->available.base += requested_size; 99 if (source->available.size == 0) { 100 log_debug("No data to add"); 101 return EOVERFLOW; /* In fact this is underflow... */ 102 } 103 104 const size_t real_size = min(size, source->available.size); 105 const int ret = 106 audio_format_mix(buffer, source->available.base, real_size, f); 107 if (ret != EOK) { 108 log_debug("Mixing failed"); 109 return ret; 110 } 111 source->available.base += real_size; 112 source->available.size -= real_size; 97 113 return EOK; 98 114 } 115 99 116 /** 100 117 * @}
Note:
See TracChangeset
for help on using the changeset viewer.