Changeset 1df3018a in mainline for uspace/srv/audio/hound/audio_source.c
- Timestamp:
- 2012-07-13T03:24:17Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d93a5a6f
- Parents:
- d01e635
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/audio/hound/audio_source.c
rd01e635 r1df3018a 42 42 43 43 #include "audio_source.h" 44 #include "audio_sink.h" 44 45 #include "log.h" 45 46 46 47 47 int audio_source_init(audio_source_t *source, const char* name) 48 int audio_source_init(audio_source_t *source, const char *name, void *data, 49 int (*connection_change)(audio_source_t *), 50 int (*update_available_data)(audio_source_t *, size_t), 51 const audio_format_t *f) 48 52 { 49 53 assert(source); 50 if (!name ) {54 if (!name || !f) { 51 55 log_debug("Incorrect parameters."); 52 56 return EINVAL; … … 54 58 link_initialize(&source->link); 55 59 source->name = str_dup(name); 56 source-> connected_change.hook = NULL;57 source->connect ed_change.arg = NULL;58 source-> get_data.hook = NULL;59 source-> get_data.arg= NULL;60 source-> available.base = NULL;61 source->available .size = 0;62 log_verbose("Initialized source (%p) '%s' with ANY audio format",63 60 source->private_data = data; 61 source->connection_change = connection_change; 62 source->update_available_data = update_available_data; 63 source->connected_sink = NULL; 64 source->format = *f; 65 source->available_data.base = NULL; 66 source->available_data.size = 0; 67 log_verbose("Initialized source (%p) '%s'", source, source->name); 64 68 return EOK; 65 69 } 66 70 67 int audio_source_connected(audio_source_t *source, const audio_format_t *f) 71 void audio_source_fini(audio_source_t *source) 72 { 73 if (!source) 74 return; 75 assert(source->connected_sink == NULL); 76 free(source->name); 77 free(source); 78 } 79 80 int audio_source_connected(audio_source_t *source, struct audio_sink *sink) 68 81 { 69 82 assert(source); 70 if (!f) { 71 log_debug("Incorrect parameters."); 72 return EINVAL; 83 audio_sink_t *old_sink = source->connected_sink; 84 const audio_format_t old_format = source->format; 85 86 source->connected_sink = sink; 87 if (audio_format_is_any(&source->format)) { 88 assert(sink); 89 assert(!audio_format_is_any(&sink->format)); 90 source->format = sink->format; 73 91 } 74 if (source->connected_change.hook) 75 source->connected_change.hook(source->connected_change.arg, f); 92 if (source->connection_change) { 93 const int ret = source->connection_change(source); 94 if (ret != EOK) { 95 source->format = old_format; 96 source->connected_sink = old_sink; 97 return ret; 98 } 99 } 76 100 return EOK; 77 101 } … … 96 120 return ENOTSUP; 97 121 } 98 99 if (source->available.size == 0) { 100 log_debug("No data to add"); 101 return EOVERFLOW; /* In fact this is underflow... */ 122 if (source->available_data.base == NULL || 123 source->available_data.size == 0) { 124 int ret = EOVERFLOW; /* In fact this is underflow... */ 125 if (source->update_available_data) 126 ret = source->update_available_data(source, size); 127 if (ret != EOK) { 128 log_debug("No data to add"); 129 return ret; 130 } 102 131 } 103 132 104 const size_t real_size = min(size, source->available .size);133 const size_t real_size = min(size, source->available_data.size); 105 134 const int ret = 106 audio_format_mix(buffer, source->available .base, real_size, f);135 audio_format_mix(buffer, source->available_data.base, real_size, f); 107 136 if (ret != EOK) { 108 137 log_debug("Mixing failed"); 109 138 return ret; 110 139 } 111 source->available.base += real_size; 112 source->available.size -= real_size; 140 source->available_data.base += real_size; 141 source->available_data.size -= real_size; 142 buffer += real_size; 143 size -= real_size; 144 145 //TODO update data again 146 if (size) 147 log_warning("not enough data"); 148 113 149 return EOK; 114 150 }
Note:
See TracChangeset
for help on using the changeset viewer.