Changeset 94e46c9 in mainline for uspace/drv/audio/hdaudio/pcm_iface.c
- Timestamp:
- 2015-05-23T04:09:11Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b5143bd
- Parents:
- a25d893 (diff), 0683992 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/hdaudio/pcm_iface.c
ra25d893 r94e46c9 100 100 static unsigned hda_query_cap(ddf_fun_t *fun, audio_cap_t cap) 101 101 { 102 hda_t *hda = fun_to_hda(fun); 103 102 104 ddf_msg(LVL_NOTE, "hda_query_cap(%d)", cap); 103 105 switch (cap) { 104 106 case AUDIO_CAP_PLAYBACK: 105 107 case AUDIO_CAP_INTERRUPT: 108 /* XXX Only if we have an output converter */ 106 109 return 1; 110 case AUDIO_CAP_CAPTURE: 111 /* Yes if we have an input converter */ 112 return hda->ctl->codec->in_aw >= 0; 107 113 case AUDIO_CAP_BUFFER_POS: 108 case AUDIO_CAP_CAPTURE:109 114 return 0; 110 115 case AUDIO_CAP_MAX_BUFFER: … … 148 153 { 149 154 hda_t *hda = fun_to_hda(fun); 155 int rc; 150 156 151 157 hda_lock(hda); 152 158 153 159 ddf_msg(LVL_NOTE, "hda_get_buffer(): hda=%p", hda); 160 if (hda->pcm_buffers != NULL) { 161 hda_unlock(hda); 162 return EBUSY; 163 } 164 165 ddf_msg(LVL_NOTE, "hda_get_buffer() - allocate stream buffers"); 166 rc = hda_stream_buffers_alloc(hda, &hda->pcm_buffers); 167 if (rc != EOK) { 168 assert(rc == ENOMEM); 169 hda_unlock(hda); 170 return ENOMEM; 171 } 172 173 ddf_msg(LVL_NOTE, "hda_get_buffer() - fill info"); 174 /* XXX This is only one buffer */ 175 *buffer = hda->pcm_buffers->buf[0]; 176 *size = hda->pcm_buffers->bufsize * hda->pcm_buffers->nbuffers; 177 178 ddf_msg(LVL_NOTE, "hda_get_buffer() returing EOK, buffer=%p, size=%zu", 179 *buffer, *size); 180 181 hda_unlock(hda); 182 return EOK; 183 } 184 185 static int hda_get_buffer_position(ddf_fun_t *fun, size_t *pos) 186 { 187 ddf_msg(LVL_NOTE, "hda_get_buffer_position()"); 188 return ENOTSUP; 189 } 190 191 static int hda_set_event_session(ddf_fun_t *fun, async_sess_t *sess) 192 { 193 hda_t *hda = fun_to_hda(fun); 194 195 ddf_msg(LVL_NOTE, "hda_set_event_session()"); 196 hda_lock(hda); 197 hda->ev_sess = sess; 198 hda_unlock(hda); 199 200 return EOK; 201 } 202 203 static async_sess_t *hda_get_event_session(ddf_fun_t *fun) 204 { 205 hda_t *hda = fun_to_hda(fun); 206 async_sess_t *sess; 207 208 ddf_msg(LVL_NOTE, "hda_get_event_session()"); 209 210 hda_lock(hda); 211 sess = hda->ev_sess; 212 hda_unlock(hda); 213 214 return sess; 215 } 216 217 static int hda_release_buffer(ddf_fun_t *fun) 218 { 219 hda_t *hda = fun_to_hda(fun); 220 221 hda_lock(hda); 222 223 ddf_msg(LVL_NOTE, "hda_release_buffer()"); 224 if (hda->pcm_buffers == NULL) { 225 hda_unlock(hda); 226 return EINVAL; 227 } 228 229 hda_stream_buffers_free(hda->pcm_buffers); 230 hda->pcm_buffers = NULL; 231 232 hda_unlock(hda); 233 return EOK; 234 } 235 236 static int hda_start_playback(ddf_fun_t *fun, unsigned frames, 237 unsigned channels, unsigned rate, pcm_sample_format_t format) 238 { 239 hda_t *hda = fun_to_hda(fun); 240 int rc; 241 242 ddf_msg(LVL_NOTE, "hda_start_playback()"); 243 hda_lock(hda); 244 154 245 if (hda->pcm_stream != NULL) { 155 246 hda_unlock(hda); … … 162 253 fmt = (fmt_base_44khz << fmt_base) | (fmt_bits_16 << fmt_bits_l) | 1; 163 254 164 ddf_msg(LVL_NOTE, "hda_get_buffer() - create stream"); 165 hda->pcm_stream = hda_stream_create(hda, sdir_output, fmt); 255 ddf_msg(LVL_NOTE, "hda_start_playback() - create output stream"); 256 hda->pcm_stream = hda_stream_create(hda, sdir_output, hda->pcm_buffers, 257 fmt); 166 258 if (hda->pcm_stream == NULL) { 167 259 hda_unlock(hda); 168 260 return EIO; 169 261 } 170 171 ddf_msg(LVL_NOTE, "hda_get_buffer() - fill info");172 /* XXX This is only one buffer */173 *buffer = hda->pcm_stream->buf[0];174 *size = hda->pcm_stream->bufsize * hda->pcm_stream->nbuffers;175 176 ddf_msg(LVL_NOTE, "hda_get_buffer() retturing EOK, buffer=%p, size=%zu",177 *buffer, *size);178 179 hda_unlock(hda);180 return EOK;181 }182 183 static int hda_get_buffer_position(ddf_fun_t *fun, size_t *pos)184 {185 ddf_msg(LVL_NOTE, "hda_get_buffer_position()");186 return ENOTSUP;187 }188 189 static int hda_set_event_session(ddf_fun_t *fun, async_sess_t *sess)190 {191 hda_t *hda = fun_to_hda(fun);192 193 ddf_msg(LVL_NOTE, "hda_set_event_session()");194 hda_lock(hda);195 hda->ev_sess = sess;196 hda_unlock(hda);197 198 return EOK;199 }200 201 static async_sess_t *hda_get_event_session(ddf_fun_t *fun)202 {203 hda_t *hda = fun_to_hda(fun);204 async_sess_t *sess;205 206 ddf_msg(LVL_NOTE, "hda_get_event_session()");207 208 hda_lock(hda);209 sess = hda->ev_sess;210 hda_unlock(hda);211 212 return sess;213 }214 215 static int hda_release_buffer(ddf_fun_t *fun)216 {217 hda_t *hda = fun_to_hda(fun);218 219 hda_lock(hda);220 221 ddf_msg(LVL_NOTE, "hda_release_buffer()");222 if (hda->pcm_stream == NULL) {223 hda_unlock(hda);224 return EINVAL;225 }226 227 hda_stream_destroy(hda->pcm_stream);228 hda->pcm_stream = NULL;229 230 hda_unlock(hda);231 return EOK;232 }233 234 static int hda_start_playback(ddf_fun_t *fun, unsigned frames,235 unsigned channels, unsigned rate, pcm_sample_format_t format)236 {237 hda_t *hda = fun_to_hda(fun);238 int rc;239 240 ddf_msg(LVL_NOTE, "hda_start_playback()");241 hda_lock(hda);242 262 243 263 rc = hda_out_converter_setup(hda->ctl->codec, hda->pcm_stream); 244 264 if (rc != EOK) { 265 hda_stream_destroy(hda->pcm_stream); 266 hda->pcm_stream = NULL; 245 267 hda_unlock(hda); 246 268 return rc; 247 269 } 248 270 271 hda->playing = true; 249 272 hda_stream_start(hda->pcm_stream); 250 hda->playing = true;251 273 hda_unlock(hda); 252 274 return EOK; … … 262 284 hda_stream_reset(hda->pcm_stream); 263 285 hda->playing = false; 286 hda_stream_destroy(hda->pcm_stream); 287 hda->pcm_stream = NULL; 288 264 289 hda_unlock(hda); 265 290 … … 271 296 unsigned rate, pcm_sample_format_t format) 272 297 { 298 hda_t *hda = fun_to_hda(fun); 299 int rc; 300 273 301 ddf_msg(LVL_NOTE, "hda_start_capture()"); 274 return ENOTSUP; 302 hda_lock(hda); 303 304 if (hda->pcm_stream != NULL) { 305 hda_unlock(hda); 306 return EBUSY; 307 } 308 309 /* XXX Choose appropriate parameters */ 310 uint32_t fmt; 311 /* 48 kHz, 16-bits, 1 channel */ 312 fmt = (fmt_base_44khz << fmt_base) | (fmt_bits_16 << fmt_bits_l) | 1; 313 314 ddf_msg(LVL_NOTE, "hda_start_capture() - create input stream"); 315 hda->pcm_stream = hda_stream_create(hda, sdir_input, hda->pcm_buffers, 316 fmt); 317 if (hda->pcm_stream == NULL) { 318 hda_unlock(hda); 319 return EIO; 320 } 321 322 rc = hda_in_converter_setup(hda->ctl->codec, hda->pcm_stream); 323 if (rc != EOK) { 324 hda_stream_destroy(hda->pcm_stream); 325 hda->pcm_stream = NULL; 326 hda_unlock(hda); 327 return rc; 328 } 329 330 hda->capturing = true; 331 hda_stream_start(hda->pcm_stream); 332 hda_unlock(hda); 333 return EOK; 275 334 } 276 335 277 336 static int hda_stop_capture(ddf_fun_t *fun, bool immediate) 278 337 { 338 hda_t *hda = fun_to_hda(fun); 339 279 340 ddf_msg(LVL_NOTE, "hda_stop_capture()"); 280 return ENOTSUP; 341 hda_lock(hda); 342 hda_stream_stop(hda->pcm_stream); 343 hda_stream_reset(hda->pcm_stream); 344 hda->capturing = false; 345 hda_stream_destroy(hda->pcm_stream); 346 hda->pcm_stream = NULL; 347 hda_unlock(hda); 348 349 hda_pcm_event(hda, PCM_EVENT_CAPTURE_TERMINATED); 350 return EOK; 281 351 } 282 352
Note:
See TracChangeset
for help on using the changeset viewer.