mixer.c (168264) | mixer.c (170161) |
---|---|
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 --- 14 unchanged lines hidden (view full) --- 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <dev/sound/pcm/sound.h> 28 29#include "mixer_if.h" 30 | 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 --- 14 unchanged lines hidden (view full) --- 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <dev/sound/pcm/sound.h> 28 29#include "mixer_if.h" 30 |
31SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/mixer.c 168264 2007-04-02 10:24:15Z ariff $"); | 31SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/mixer.c 170161 2007-05-31 18:43:33Z ariff $"); |
32 33MALLOC_DEFINE(M_MIXER, "mixer", "mixer"); 34 35#define MIXER_NAMELEN 16 36struct snd_mixer { 37 KOBJ_FIELDS; 38 const char *type; 39 void *devinfo; --- 54 unchanged lines hidden (view full) --- 94}; 95 96/** 97 * Keeps a count of mixer devices; used only by OSSv4 SNDCTL_SYSINFO ioctl. 98 */ 99int mixer_count = 0; 100 101#ifdef USING_DEVFS | 32 33MALLOC_DEFINE(M_MIXER, "mixer", "mixer"); 34 35#define MIXER_NAMELEN 16 36struct snd_mixer { 37 KOBJ_FIELDS; 38 const char *type; 39 void *devinfo; --- 54 unchanged lines hidden (view full) --- 94}; 95 96/** 97 * Keeps a count of mixer devices; used only by OSSv4 SNDCTL_SYSINFO ioctl. 98 */ 99int mixer_count = 0; 100 101#ifdef USING_DEVFS |
102static eventhandler_tag mixer_ehtag; | 102static eventhandler_tag mixer_ehtag = NULL; |
103#endif 104 105static struct cdev * 106mixer_get_devt(device_t dev) 107{ 108 struct snddev_info *snddev; 109 110 snddev = device_get_softc(dev); --- 14 unchanged lines hidden (view full) --- 125 return -1; 126} 127#endif 128 129static int 130mixer_set_softpcmvol(struct snd_mixer *mixer, struct snddev_info *d, 131 unsigned left, unsigned right) 132{ | 103#endif 104 105static struct cdev * 106mixer_get_devt(device_t dev) 107{ 108 struct snddev_info *snddev; 109 110 snddev = device_get_softc(dev); --- 14 unchanged lines hidden (view full) --- 125 return -1; 126} 127#endif 128 129static int 130mixer_set_softpcmvol(struct snd_mixer *mixer, struct snddev_info *d, 131 unsigned left, unsigned right) 132{ |
133 struct snddev_channel *sce; 134 struct pcm_channel *ch; 135#ifdef USING_MUTEX 136 int locked = (mixer->lock && mtx_owned((struct mtx *)(mixer->lock))) ? 1 : 0; | 133 struct pcm_channel *c; 134 int locked; |
137 | 135 |
136 locked = (mixer->lock != NULL && 137 mtx_owned((struct mtx *)(mixer->lock))) ? 1 : 0; |
|
138 if (locked) 139 snd_mtxunlock(mixer->lock); | 138 if (locked) 139 snd_mtxunlock(mixer->lock); |
140#endif 141 SLIST_FOREACH(sce, &d->channels, link) { 142 ch = sce->channel; 143 CHN_LOCK(ch); 144 if (ch->direction == PCMDIR_PLAY && 145 (ch->feederflags & (1 << FEEDER_VOLUME))) 146 chn_setvolume(ch, left, right); 147 CHN_UNLOCK(ch); | 140 141 if (CHN_EMPTY(d, channels.pcm.busy)) { 142 CHN_FOREACH(c, d, channels.pcm) { 143 CHN_LOCK(c); 144 if (c->direction == PCMDIR_PLAY && 145 (c->feederflags & (1 << FEEDER_VOLUME))) 146 chn_setvolume(c, left, right); 147 CHN_UNLOCK(c); 148 } 149 } else { 150 CHN_FOREACH(c, d, channels.pcm.busy) { 151 CHN_LOCK(c); 152 if (c->direction == PCMDIR_PLAY && 153 (c->feederflags & (1 << FEEDER_VOLUME))) 154 chn_setvolume(c, left, right); 155 CHN_UNLOCK(c); 156 } |
148 } | 157 } |
149#ifdef USING_MUTEX | 158 |
150 if (locked) 151 snd_mtxlock(mixer->lock); | 159 if (locked) 160 snd_mtxlock(mixer->lock); |
152#endif | 161 |
153 return 0; 154} 155 156static int 157mixer_set(struct snd_mixer *m, unsigned dev, unsigned lev) 158{ 159 struct snddev_info *d; 160 unsigned l, r, tl, tr; --- 314 unchanged lines hidden (view full) --- 475 476int 477mixer_init(device_t dev, kobj_class_t cls, void *devinfo) 478{ 479 struct snddev_info *snddev; 480 struct snd_mixer *m; 481 u_int16_t v; 482 struct cdev *pdev; | 162 return 0; 163} 164 165static int 166mixer_set(struct snd_mixer *m, unsigned dev, unsigned lev) 167{ 168 struct snddev_info *d; 169 unsigned l, r, tl, tr; --- 314 unchanged lines hidden (view full) --- 484 485int 486mixer_init(device_t dev, kobj_class_t cls, void *devinfo) 487{ 488 struct snddev_info *snddev; 489 struct snd_mixer *m; 490 u_int16_t v; 491 struct cdev *pdev; |
483 int i, unit, val; | 492 int i, unit, devunit, val; |
484 485 m = (struct snd_mixer *)kobj_create(cls, M_MIXER, M_WAITOK | M_ZERO); 486 snprintf(m->name, MIXER_NAMELEN, "%s:mixer", device_get_nameunit(dev)); 487 m->lock = snd_mtxcreate(m->name, "pcm mixer"); 488 m->type = cls->name; 489 m->devinfo = devinfo; 490 m->busy = 0; 491 m->dev = dev; --- 17 unchanged lines hidden (view full) --- 509 } 510 511 mixer_set(m, i, v | (v << 8)); 512 } 513 514 mixer_setrecsrc(m, SOUND_MASK_MIC); 515 516 unit = device_get_unit(dev); | 493 494 m = (struct snd_mixer *)kobj_create(cls, M_MIXER, M_WAITOK | M_ZERO); 495 snprintf(m->name, MIXER_NAMELEN, "%s:mixer", device_get_nameunit(dev)); 496 m->lock = snd_mtxcreate(m->name, "pcm mixer"); 497 m->type = cls->name; 498 m->devinfo = devinfo; 499 m->busy = 0; 500 m->dev = dev; --- 17 unchanged lines hidden (view full) --- 518 } 519 520 mixer_set(m, i, v | (v << 8)); 521 } 522 523 mixer_setrecsrc(m, SOUND_MASK_MIC); 524 525 unit = device_get_unit(dev); |
517 pdev = make_dev(&mixer_cdevsw, PCMMKMINOR(unit, SND_DEV_CTL, 0), | 526 devunit = snd_mkunit(unit, SND_DEV_CTL, 0); 527 pdev = make_dev(&mixer_cdevsw, unit2minor(devunit), |
518 UID_ROOT, GID_WHEEL, 0666, "mixer%d", unit); 519 pdev->si_drv1 = m; 520 snddev = device_get_softc(dev); 521 snddev->mixer_dev = pdev; 522 523 ++mixer_count; 524 525 if (bootverbose) { --- 314 unchanged lines hidden (view full) --- 840 } 841 842 snd_mtxunlock(m->lock); 843 return ret; 844} 845 846#ifdef USING_DEVFS 847static void | 528 UID_ROOT, GID_WHEEL, 0666, "mixer%d", unit); 529 pdev->si_drv1 = m; 530 snddev = device_get_softc(dev); 531 snddev->mixer_dev = pdev; 532 533 ++mixer_count; 534 535 if (bootverbose) { --- 314 unchanged lines hidden (view full) --- 850 } 851 852 snd_mtxunlock(m->lock); 853 return ret; 854} 855 856#ifdef USING_DEVFS 857static void |
848mixer_clone(void *arg, struct ucred *cred, char *name, int namelen, 849 struct cdev **dev) | 858mixer_clone(void *arg, 859#if __FreeBSD_version >= 600034 860 struct ucred *cred, 861#endif 862 char *name, int namelen, struct cdev **dev) |
850{ | 863{ |
851 struct snddev_info *sd; | 864 struct snddev_info *d; |
852 853 if (*dev != NULL) 854 return; 855 if (strcmp(name, "mixer") == 0) { | 865 866 if (*dev != NULL) 867 return; 868 if (strcmp(name, "mixer") == 0) { |
856 sd = devclass_get_softc(pcm_devclass, snd_unit); 857 if (sd != NULL && sd->mixer_dev != NULL) { 858 *dev = sd->mixer_dev; | 869 d = devclass_get_softc(pcm_devclass, snd_unit); 870 if (d != NULL && d->mixer_dev != NULL) { 871 *dev = d->mixer_dev; |
859 dev_ref(*dev); 860 } 861 } 862} 863 864static void 865mixer_sysinit(void *p) 866{ | 872 dev_ref(*dev); 873 } 874 } 875} 876 877static void 878mixer_sysinit(void *p) 879{ |
880 if (mixer_ehtag != NULL) 881 return; |
|
867 mixer_ehtag = EVENTHANDLER_REGISTER(dev_clone, mixer_clone, 0, 1000); 868} 869 870static void 871mixer_sysuninit(void *p) 872{ | 882 mixer_ehtag = EVENTHANDLER_REGISTER(dev_clone, mixer_clone, 0, 1000); 883} 884 885static void 886mixer_sysuninit(void *p) 887{ |
873 if (mixer_ehtag != NULL) 874 EVENTHANDLER_DEREGISTER(dev_clone, mixer_ehtag); | 888 if (mixer_ehtag == NULL) 889 return; 890 EVENTHANDLER_DEREGISTER(dev_clone, mixer_ehtag); 891 mixer_ehtag = NULL; |
875} 876 877SYSINIT(mixer_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, mixer_sysinit, NULL); 878SYSUNINIT(mixer_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, mixer_sysuninit, NULL); 879#endif 880 881/** 882 * @brief Handler for SNDCTL_MIXERINFO --- 150 unchanged lines hidden --- | 892} 893 894SYSINIT(mixer_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, mixer_sysinit, NULL); 895SYSUNINIT(mixer_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, mixer_sysuninit, NULL); 896#endif 897 898/** 899 * @brief Handler for SNDCTL_MIXERINFO --- 150 unchanged lines hidden --- |