dsp.c (154826) | dsp.c (155008) |
---|---|
1/*- 2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/param.h> 28#include <sys/queue.h> 29 30#include <dev/sound/pcm/sound.h> 31 | 1/*- 2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/param.h> 28#include <sys/queue.h> 29 30#include <dev/sound/pcm/sound.h> 31 |
32SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/dsp.c 154826 2006-01-25 21:13:46Z joel $"); | 32SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/dsp.c 155008 2006-01-29 16:48:41Z netchild $"); |
33 34#define OLDPCM_IOCTL 35 36static d_open_t dsp_open; 37static d_close_t dsp_close; 38static d_read_t dsp_read; 39static d_write_t dsp_write; 40static d_ioctl_t dsp_ioctl; --- 424 unchanged lines hidden (view full) --- 465 rdch = NULL; 466 467 switch(cmd) { 468#ifdef OLDPCM_IOCTL 469 /* 470 * we start with the new ioctl interface. 471 */ 472 case AIONWRITE: /* how many bytes can write ? */ | 33 34#define OLDPCM_IOCTL 35 36static d_open_t dsp_open; 37static d_close_t dsp_close; 38static d_read_t dsp_read; 39static d_write_t dsp_write; 40static d_ioctl_t dsp_ioctl; --- 424 unchanged lines hidden (view full) --- 465 rdch = NULL; 466 467 switch(cmd) { 468#ifdef OLDPCM_IOCTL 469 /* 470 * we start with the new ioctl interface. 471 */ 472 case AIONWRITE: /* how many bytes can write ? */ |
473 CHN_LOCK(wrch); | 473 if (wrch) { 474 CHN_LOCK(wrch); |
474/* 475 if (wrch && wrch->bufhard.dl) 476 while (chn_wrfeed(wrch) == 0); 477*/ | 475/* 476 if (wrch && wrch->bufhard.dl) 477 while (chn_wrfeed(wrch) == 0); 478*/ |
478 *arg_i = wrch? sndbuf_getfree(wrch->bufsoft) : 0; 479 CHN_UNLOCK(wrch); | 479 *arg_i = sndbuf_getfree(wrch->bufsoft); 480 CHN_UNLOCK(wrch); 481 } else { 482 *arg_i = 0; 483 ret = EINVAL; 484 } |
480 break; 481 482 case AIOSSIZE: /* set the current blocksize */ 483 { 484 struct snd_size *p = (struct snd_size *)arg; 485 486 p->play_size = 0; 487 p->rec_size = 0; --- 130 unchanged lines hidden (view full) --- 618 case FIONREAD: /* get # bytes to read */ 619 if (rdch) { 620 CHN_LOCK(rdch); 621/* if (rdch && rdch->bufhard.dl) 622 while (chn_rdfeed(rdch) == 0); 623*/ 624 *arg_i = sndbuf_getready(rdch->bufsoft); 625 CHN_UNLOCK(rdch); | 485 break; 486 487 case AIOSSIZE: /* set the current blocksize */ 488 { 489 struct snd_size *p = (struct snd_size *)arg; 490 491 p->play_size = 0; 492 p->rec_size = 0; --- 130 unchanged lines hidden (view full) --- 623 case FIONREAD: /* get # bytes to read */ 624 if (rdch) { 625 CHN_LOCK(rdch); 626/* if (rdch && rdch->bufhard.dl) 627 while (chn_rdfeed(rdch) == 0); 628*/ 629 *arg_i = sndbuf_getready(rdch->bufsoft); 630 CHN_UNLOCK(rdch); |
626 } else | 631 } else { |
627 *arg_i = 0; | 632 *arg_i = 0; |
633 ret = EINVAL; 634 } |
|
628 break; 629 630 case FIOASYNC: /*set/clear async i/o */ 631 DEB( printf("FIOASYNC\n") ; ) 632 break; 633 634 case SNDCTL_DSP_NONBLOCK: 635 case FIONBIO: /* set/clear non-blocking i/o */ --- 17 unchanged lines hidden (view full) --- 653 654 /* 655 * Finally, here is the linux-compatible ioctl interface 656 */ 657#define THE_REAL_SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int) 658 case THE_REAL_SNDCTL_DSP_GETBLKSIZE: 659 case SNDCTL_DSP_GETBLKSIZE: 660 chn = wrch ? wrch : rdch; | 635 break; 636 637 case FIOASYNC: /*set/clear async i/o */ 638 DEB( printf("FIOASYNC\n") ; ) 639 break; 640 641 case SNDCTL_DSP_NONBLOCK: 642 case FIONBIO: /* set/clear non-blocking i/o */ --- 17 unchanged lines hidden (view full) --- 660 661 /* 662 * Finally, here is the linux-compatible ioctl interface 663 */ 664#define THE_REAL_SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int) 665 case THE_REAL_SNDCTL_DSP_GETBLKSIZE: 666 case SNDCTL_DSP_GETBLKSIZE: 667 chn = wrch ? wrch : rdch; |
661 CHN_LOCK(chn); 662 *arg_i = sndbuf_getblksz(chn->bufsoft); 663 CHN_UNLOCK(chn); | 668 if (chn) { 669 CHN_LOCK(chn); 670 *arg_i = sndbuf_getblksz(chn->bufsoft); 671 CHN_UNLOCK(chn); 672 } else { 673 *arg_i = 0; 674 ret = EINVAL; 675 } |
664 break ; 665 666 case SNDCTL_DSP_SETBLKSIZE: 667 RANGE(*arg_i, 16, 65536); 668 if (wrch) { 669 CHN_LOCK(wrch); 670 chn_setblocksize(wrch, 2, *arg_i); 671 CHN_UNLOCK(wrch); --- 47 unchanged lines hidden (view full) --- 719 tmp = rdch->speed; 720 CHN_UNLOCK(rdch); 721 } 722 *arg_i = tmp; 723 break; 724 725 case SOUND_PCM_READ_RATE: 726 chn = wrch ? wrch : rdch; | 676 break ; 677 678 case SNDCTL_DSP_SETBLKSIZE: 679 RANGE(*arg_i, 16, 65536); 680 if (wrch) { 681 CHN_LOCK(wrch); 682 chn_setblocksize(wrch, 2, *arg_i); 683 CHN_UNLOCK(wrch); --- 47 unchanged lines hidden (view full) --- 731 tmp = rdch->speed; 732 CHN_UNLOCK(rdch); 733 } 734 *arg_i = tmp; 735 break; 736 737 case SOUND_PCM_READ_RATE: 738 chn = wrch ? wrch : rdch; |
727 CHN_LOCK(chn); 728 *arg_i = chn->speed; 729 CHN_UNLOCK(chn); | 739 if (chn) { 740 CHN_LOCK(chn); 741 *arg_i = chn->speed; 742 CHN_UNLOCK(chn); 743 } else { 744 *arg_i = 0; 745 ret = EINVAL; 746 } |
730 break; 731 732 case SNDCTL_DSP_STEREO: 733 tmp = -1; 734 *arg_i = (*arg_i)? AFMT_STEREO : 0; 735 if (wrch) { 736 CHN_LOCK(wrch); 737 ret = chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | *arg_i); --- 34 unchanged lines hidden (view full) --- 772 CHN_LOCK(chn); 773 *arg_i = (chn->format & AFMT_STEREO) ? 2 : 1; 774 CHN_UNLOCK(chn); 775 } 776 break; 777 778 case SOUND_PCM_READ_CHANNELS: 779 chn = wrch ? wrch : rdch; | 747 break; 748 749 case SNDCTL_DSP_STEREO: 750 tmp = -1; 751 *arg_i = (*arg_i)? AFMT_STEREO : 0; 752 if (wrch) { 753 CHN_LOCK(wrch); 754 ret = chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | *arg_i); --- 34 unchanged lines hidden (view full) --- 789 CHN_LOCK(chn); 790 *arg_i = (chn->format & AFMT_STEREO) ? 2 : 1; 791 CHN_UNLOCK(chn); 792 } 793 break; 794 795 case SOUND_PCM_READ_CHANNELS: 796 chn = wrch ? wrch : rdch; |
780 CHN_LOCK(chn); 781 *arg_i = (chn->format & AFMT_STEREO) ? 2 : 1; 782 CHN_UNLOCK(chn); | 797 if (chn) { 798 CHN_LOCK(chn); 799 *arg_i = (chn->format & AFMT_STEREO) ? 2 : 1; 800 CHN_UNLOCK(chn); 801 } else { 802 *arg_i = 0; 803 ret = EINVAL; 804 } |
783 break; 784 785 case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */ 786 chn = wrch ? wrch : rdch; | 805 break; 806 807 case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */ 808 chn = wrch ? wrch : rdch; |
787 CHN_LOCK(chn); 788 *arg_i = chn_getformats(chn); 789 CHN_UNLOCK(chn); | 809 if (chn) { 810 CHN_LOCK(chn); 811 *arg_i = chn_getformats(chn); 812 CHN_UNLOCK(chn); 813 } else { 814 *arg_i = 0; 815 ret = EINVAL; 816 } |
790 break ; 791 792 case SNDCTL_DSP_SETFMT: /* sets _one_ format */ 793 if ((*arg_i != AFMT_QUERY)) { 794 tmp = 0; 795 if (wrch) { 796 CHN_LOCK(wrch); 797 ret = chn_setformat(wrch, (*arg_i) | (wrch->format & AFMT_STEREO)); --- 139 unchanged lines hidden (view full) --- 937 case SNDCTL_DSP_GETCAPS: 938 *arg_i = DSP_CAP_REALTIME | DSP_CAP_MMAP | DSP_CAP_TRIGGER; 939 if (rdch && wrch && !(dsp_get_flags(i_dev) & SD_F_SIMPLEX)) 940 *arg_i |= DSP_CAP_DUPLEX; 941 break; 942 943 case SOUND_PCM_READ_BITS: 944 chn = wrch ? wrch : rdch; | 817 break ; 818 819 case SNDCTL_DSP_SETFMT: /* sets _one_ format */ 820 if ((*arg_i != AFMT_QUERY)) { 821 tmp = 0; 822 if (wrch) { 823 CHN_LOCK(wrch); 824 ret = chn_setformat(wrch, (*arg_i) | (wrch->format & AFMT_STEREO)); --- 139 unchanged lines hidden (view full) --- 964 case SNDCTL_DSP_GETCAPS: 965 *arg_i = DSP_CAP_REALTIME | DSP_CAP_MMAP | DSP_CAP_TRIGGER; 966 if (rdch && wrch && !(dsp_get_flags(i_dev) & SD_F_SIMPLEX)) 967 *arg_i |= DSP_CAP_DUPLEX; 968 break; 969 970 case SOUND_PCM_READ_BITS: 971 chn = wrch ? wrch : rdch; |
945 CHN_LOCK(chn); 946 if (chn->format & AFMT_8BIT) 947 *arg_i = 8; 948 else if (chn->format & AFMT_16BIT) 949 *arg_i = 16; 950 else if (chn->format & AFMT_24BIT) 951 *arg_i = 24; 952 else if (chn->format & AFMT_32BIT) 953 *arg_i = 32; 954 else | 972 if (chn) { 973 CHN_LOCK(chn); 974 if (chn->format & AFMT_8BIT) 975 *arg_i = 8; 976 else if (chn->format & AFMT_16BIT) 977 *arg_i = 16; 978 else if (chn->format & AFMT_24BIT) 979 *arg_i = 24; 980 else if (chn->format & AFMT_32BIT) 981 *arg_i = 32; 982 else 983 ret = EINVAL; 984 CHN_UNLOCK(chn); 985 } else { 986 *arg_i = 0; |
955 ret = EINVAL; | 987 ret = EINVAL; |
956 CHN_UNLOCK(chn); | 988 } |
957 break; 958 959 case SNDCTL_DSP_SETTRIGGER: 960 if (rdch) { 961 CHN_LOCK(rdch); 962 rdch->flags &= ~(CHN_F_TRIGGERED | CHN_F_NOTRIGGER); 963 if (*arg_i & PCM_ENABLE_INPUT) 964 chn_start(rdch, 1); --- 237 unchanged lines hidden --- | 989 break; 990 991 case SNDCTL_DSP_SETTRIGGER: 992 if (rdch) { 993 CHN_LOCK(rdch); 994 rdch->flags &= ~(CHN_F_TRIGGERED | CHN_F_NOTRIGGER); 995 if (*arg_i & PCM_ENABLE_INPUT) 996 chn_start(rdch, 1); --- 237 unchanged lines hidden --- |