jcs's openbsd hax
openbsd
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

libsndio: Move sio_sun_xrun() to sio.c and rename it to _sio_xrun()

ratchov f3a2e738 0fac0946

+109 -108
+106 -1
lib/libsndio/sio.c
··· 1 - /* $OpenBSD: sio.c,v 1.29 2026/03/10 06:23:44 ratchov Exp $ */ 1 + /* $OpenBSD: sio.c,v 1.30 2026/03/10 06:47:41 ratchov Exp $ */ 2 2 /* 3 3 * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> 4 4 * ··· 500 500 cpos, cdiff, wpos, wdiff, rpos, rdiff, hdl->cpending); 501 501 } 502 502 #endif 503 + 504 + /* 505 + * Restart the device restoring its state (i.e. hdl->cpos, hdl->wused, 506 + * hdl->rused), making the restart transparent to upper layers. 507 + */ 508 + int 509 + _sio_xrun(struct sio_hdl *hdl) 510 + { 511 + int cmove; 512 + 513 + #ifdef DEBUG 514 + if (_sndio_debug >= 1) 515 + _sio_printpos(hdl); 516 + #endif 517 + /* 518 + * The device restarts with empty buffers and block aligned. 519 + */ 520 + if (!hdl->ops->flush(hdl)) 521 + return 0; 522 + 523 + _sio_onxrun_cb(hdl); 524 + 525 + if (!hdl->ops->start(hdl)) 526 + return 0; 527 + 528 + DPRINTFN(1, "%s: rused = %d, wused = %d\n", __func__, 529 + hdl->rused, hdl->wused); 530 + 531 + /* 532 + * To restore the device state, we play silence, drop recorded data, 533 + * and advance the clock. We suppose that it takes N blocks to restore 534 + * the state (where N is any integer). 535 + * 536 + * After N blocks of operation cpos (the clock) must have advanced to 537 + * the next block boundary (the stream must remain block-aligned): 538 + * 539 + * cpos' = cpos + round - cpos % round 540 + * 541 + * on the other hand, cpos advances by N * par->round frames plus 542 + * hdl->delta (the advance we report immediately): 543 + * 544 + * cpos' = cpos + delta + N * round 545 + * 546 + * by combining above expressions, we obtain the advance to report: 547 + * 548 + * delta = - cpos % round - (N - 1) * round 549 + * 550 + * For playback, after N blocks, the buffer usage has decreased by 551 + * the elapsed time: 552 + * 553 + * wused' = wused - (cpos' - cpos) 554 + * 555 + * on the other hand it is equal to the amount of silence we have 556 + * inserted minus the N blocks that the device has consumed: 557 + * 558 + * wused' = wsil - N * par->round 559 + * 560 + * by combining both expressions, we obtain the amount of silence 561 + * we've to insert: 562 + * 563 + * wsil = wused + (N - 1) * par->round + cpos % round 564 + * 565 + * Similarly, for recording the buffer usage has increased by 566 + * the elapsed time: 567 + * 568 + * rused' = rused + (cpos' - cpos) 569 + * 570 + * it is also equal to the N blocks the device has produced minus 571 + * the amount of frames we drop: 572 + * 573 + * rused' = N * round - rdrop 574 + * 575 + * by combining both expressions, we obtain the amount of frames 576 + * to drop: 577 + * 578 + * rdrop = cpos % round + (N - 1) * round - rused; 579 + * 580 + * We're free to choose N. The smaller N (ideally 1) the sooner 581 + * performance will resume. But wsil and rdrop may not be negative. 582 + * 583 + */ 584 + 585 + cmove = hdl->cpos % hdl->par.round; 586 + 587 + if (hdl->mode & SIO_REC) { 588 + while (1) { 589 + hdl->rdrop = cmove * hdl->par.bps * hdl->par.rchan - hdl->rused; 590 + if (hdl->rdrop >= 0) 591 + break; 592 + /* 593 + * rdrop can't be negative, try a larger 'N' 594 + */ 595 + cmove += hdl->par.round; 596 + } 597 + } 598 + 599 + if (hdl->mode & SIO_PLAY) 600 + hdl->wsil = hdl->wused + cmove * hdl->par.bps * hdl->par.pchan; 601 + 602 + DPRINTFN(1, "%s: cmove = %d, wsil = %d, rdrop = %d\n", __func__, 603 + cmove, hdl->wsil, hdl->rdrop); 604 + 605 + _sio_onmove_cb(hdl, -cmove); 606 + return 1; 607 + } 503 608 504 609 void 505 610 _sio_onmove_cb(struct sio_hdl *hdl, int delta)
+2 -1
lib/libsndio/sio_priv.h
··· 1 - /* $OpenBSD: sio_priv.h,v 1.14 2026/03/10 06:23:44 ratchov Exp $ */ 1 + /* $OpenBSD: sio_priv.h,v 1.15 2026/03/10 06:47:41 ratchov Exp $ */ 2 2 /* 3 3 * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> 4 4 * ··· 73 73 struct sio_hdl *_sio_aucat_open(const char *, unsigned, int); 74 74 struct sio_hdl *_sio_sun_open(const char *, unsigned, int); 75 75 void _sio_create(struct sio_hdl *, struct sio_ops *, unsigned, int); 76 + int _sio_xrun(struct sio_hdl *); 76 77 void _sio_onmove_cb(struct sio_hdl *, int); 77 78 void _sio_onvol_cb(struct sio_hdl *, unsigned); 78 79 void _sio_onxrun_cb(struct sio_hdl *);
+1 -106
lib/libsndio/sio_sun.c
··· 1 - /* $OpenBSD: sio_sun.c,v 1.35 2026/03/10 06:41:10 ratchov Exp $ */ 1 + /* $OpenBSD: sio_sun.c,v 1.36 2026/03/10 06:47:41 ratchov Exp $ */ 2 2 /* 3 3 * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> 4 4 * ··· 522 522 } 523 523 524 524 return n; 525 - } 526 - 527 - /* 528 - * Restart the device restoring its state (i.e. hdl->cpos, hdl->wused, 529 - * hdl->rused), making the restart transparent to upper layers. 530 - */ 531 - static int 532 - _sio_xrun(struct sio_hdl *hdl) 533 - { 534 - int cmove; 535 - 536 - #ifdef DEBUG 537 - if (_sndio_debug >= 1) 538 - _sio_printpos(hdl); 539 - #endif 540 - /* 541 - * The device restarts with empty buffers and block aligned. 542 - */ 543 - if (!hdl->ops->flush(hdl)) 544 - return 0; 545 - 546 - _sio_onxrun_cb(hdl); 547 - 548 - if (!hdl->ops->start(hdl)) 549 - return 0; 550 - 551 - DPRINTFN(1, "%s: rused = %d, wused = %d\n", __func__, 552 - hdl->rused, hdl->wused); 553 - 554 - /* 555 - * To restore the device state, we play silence, drop recorded data, 556 - * and advance the clock. We suppose that it takes N blocks to restore 557 - * the state (where N is any integer). 558 - * 559 - * After N blocks of operation cpos (the clock) must have advanced to 560 - * the next block boundary (the stream must remain block-aligned): 561 - * 562 - * cpos' = cpos + round - cpos % round 563 - * 564 - * on the other hand, cpos advances by N * par->round frames plus 565 - * hdl->delta (the advance we report immediately): 566 - * 567 - * cpos' = cpos + delta + N * round 568 - * 569 - * by combining above expressions, we obtain the advance to report: 570 - * 571 - * delta = - cpos % round - (N - 1) * round 572 - * 573 - * For playback, after N blocks, the buffer usage has decreased by 574 - * the elapsed time: 575 - * 576 - * wused' = wused - (cpos' - cpos) 577 - * 578 - * on the other hand it is equal to the amount of silence we have 579 - * inserted minus the N blocks that the device has consumed: 580 - * 581 - * wused' = wsil - N * par->round 582 - * 583 - * by combining both expressions, we obtain the amount of silence 584 - * we've to insert: 585 - * 586 - * wsil = wused + (N - 1) * par->round + cpos % round 587 - * 588 - * Similarly, for recording the buffer usage has increased by 589 - * the elapsed time: 590 - * 591 - * rused' = rused + (cpos' - cpos) 592 - * 593 - * it is also equal to the N blocks the device has produced minus 594 - * the amount of frames we drop: 595 - * 596 - * rused' = N * round - rdrop 597 - * 598 - * by combining both expressions, we obtain the amount of frames 599 - * to drop: 600 - * 601 - * rdrop = cpos % round + (N - 1) * round - rused; 602 - * 603 - * We're free to choose N. The smaller N (ideally 1) the sooner 604 - * performance will resume. But wsil and rdrop may not be negative. 605 - * 606 - */ 607 - 608 - cmove = hdl->cpos % hdl->par.round; 609 - 610 - if (hdl->mode & SIO_REC) { 611 - while (1) { 612 - hdl->rdrop = cmove * hdl->par.bps * hdl->par.rchan - hdl->rused; 613 - if (hdl->rdrop >= 0) 614 - break; 615 - /* 616 - * rdrop can't be negative, try a larger 'N' 617 - */ 618 - cmove += hdl->par.round; 619 - } 620 - } 621 - 622 - if (hdl->mode & SIO_PLAY) 623 - hdl->wsil = hdl->wused + cmove * hdl->par.bps * hdl->par.pchan; 624 - 625 - DPRINTFN(1, "%s: cmove = %d, wsil = %d, rdrop = %d\n", __func__, 626 - cmove, hdl->wsil, hdl->rdrop); 627 - 628 - _sio_onmove_cb(hdl, -cmove); 629 - return 1; 630 525 } 631 526 632 527 static int