Mercurial > audlegacy-plugins
comparison src/pulse_audio/pulse_audio.c @ 2264:3e04aad140f9
Break large write operations into smaller fragments.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sun, 23 Dec 2007 20:24:16 -0600 |
parents | f51a47e53d4f |
children | 0962a6325b9b |
comparison
equal
deleted
inserted
replaced
2263:d3b950ee7e5f | 2264:3e04aad140f9 |
---|---|
444 | 444 |
445 pa_threaded_mainloop_unlock(mainloop); | 445 pa_threaded_mainloop_unlock(mainloop); |
446 } | 446 } |
447 | 447 |
448 static void pulse_write(void* ptr, int length) { | 448 static void pulse_write(void* ptr, int length) { |
449 gint writeoffs, remain, writable; | |
450 gint fragsize = 1024; /* TODO: make fragment size configurable */ | |
449 | 451 |
450 CHECK_CONNECTED(); | 452 CHECK_CONNECTED(); |
451 | 453 |
452 pa_threaded_mainloop_lock(mainloop); | 454 pa_threaded_mainloop_lock(mainloop); |
453 CHECK_DEAD_GOTO(fail, 1); | 455 CHECK_DEAD_GOTO(fail, 1); |
454 | 456 |
455 if (pa_stream_write(stream, ptr, length, NULL, PA_SEEK_RELATIVE, 0) < 0) { | 457 /* break large fragments into smaller fragments. --nenolod */ |
456 g_warning("pa_stream_write() failed: %s", pa_strerror(pa_context_errno(context))); | 458 for (writeoffs = 0, remain = length; |
457 goto fail; | 459 writeoffs < length; |
460 writeoffs += writable, remain -= writable) | |
461 { | |
462 gpointer pptr = ptr + writeoffs; | |
463 | |
464 writable = length - writeoffs; | |
465 | |
466 /* don't write any more than a fragment the size of fragsize at a time. */ | |
467 if (writable > fragsize) | |
468 writable = fragsize; | |
469 | |
470 if (pa_stream_write(stream, pptr, writable, NULL, PA_SEEK_RELATIVE, 0) < 0) { | |
471 g_warning("pa_stream_write() failed: %s", pa_strerror(pa_context_errno(context))); | |
472 goto fail; | |
473 } | |
458 } | 474 } |
459 | 475 |
460 do_trigger = 0; | 476 do_trigger = 0; |
461 written += length; | 477 written += length; |
462 | 478 |
463 fail: | 479 fail: |
464 | |
465 pa_threaded_mainloop_unlock(mainloop); | 480 pa_threaded_mainloop_unlock(mainloop); |
466 } | 481 } |
467 | 482 |
468 static void drain(void) { | 483 static void drain(void) { |
469 pa_operation *o = NULL; | 484 pa_operation *o = NULL; |
492 pa_operation_unref(o); | 507 pa_operation_unref(o); |
493 | 508 |
494 pa_threaded_mainloop_unlock(mainloop); | 509 pa_threaded_mainloop_unlock(mainloop); |
495 } | 510 } |
496 | 511 |
497 static void pulse_close(void) { | 512 static void pulse_close(void) |
498 | 513 { |
499 drain(); | 514 drain(); |
500 | 515 |
501 connected = 0; | 516 connected = 0; |
502 | 517 |
503 if (mainloop) | 518 if (mainloop) |