Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/virtual_oss/virtual_oss/main.c
| Show All 25 Lines | |||||
| #include <sys/queue.h> | #include <sys/queue.h> | ||||
| #include <sys/types.h> | #include <sys/types.h> | ||||
| #include <sys/filio.h> | #include <sys/filio.h> | ||||
| #include <sys/linker.h> | #include <sys/linker.h> | ||||
| #include <sys/rtprio.h> | #include <sys/rtprio.h> | ||||
| #include <sys/nv.h> | #include <sys/nv.h> | ||||
| #include <sys/sndstat.h> | #include <sys/sndstat.h> | ||||
| #include <sys/soundcard.h> | #include <sys/soundcard.h> | ||||
| #include <sys/sysctl.h> | |||||
| #include <dlfcn.h> | #include <dlfcn.h> | ||||
| #include <errno.h> | #include <errno.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <stdint.h> | #include <stdint.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include <unistd.h> | #include <unistd.h> | ||||
| #include <err.h> | #include <err.h> | ||||
| #include <sysexits.h> | #include <sysexits.h> | ||||
| #include <signal.h> | #include <signal.h> | ||||
| #include <fcntl.h> | #include <fcntl.h> | ||||
| #include <paths.h> | #include <paths.h> | ||||
| #include <cuse.h> | #include <cuse.h> | ||||
| #include <pthread.h> | #include <pthread.h> | ||||
| #include "backend.h" | #include "backend.h" | ||||
| #include "int.h" | #include "int.h" | ||||
| #include "virtual_oss.h" | #include "virtual_oss.h" | ||||
| #define SYSCTL_BASECLONE "hw.snd.basename_clone" | |||||
| pthread_mutex_t atomic_mtx; | pthread_mutex_t atomic_mtx; | ||||
| pthread_cond_t atomic_cv; | pthread_cond_t atomic_cv; | ||||
| static void | static void | ||||
| atomic_init(void) | atomic_init(void) | ||||
| { | { | ||||
| if (pthread_mutex_init(&atomic_mtx, NULL) != 0) | if (pthread_mutex_init(&atomic_mtx, NULL) != 0) | ||||
| err(1, "pthread_mutex_init"); | err(1, "pthread_mutex_init"); | ||||
| ▲ Show 20 Lines • Show All 1,549 Lines • ▼ Show 20 Lines | |||||
| uint8_t voss_libsamplerate_enable; | uint8_t voss_libsamplerate_enable; | ||||
| uint8_t voss_libsamplerate_quality = SRC_SINC_FASTEST; | uint8_t voss_libsamplerate_quality = SRC_SINC_FASTEST; | ||||
| int voss_is_recording = 1; | int voss_is_recording = 1; | ||||
| int voss_has_synchronization; | int voss_has_synchronization; | ||||
| volatile sig_atomic_t voss_exit = 0; | volatile sig_atomic_t voss_exit = 0; | ||||
| static int voss_dsp_perm = 0666; | static int voss_dsp_perm = 0666; | ||||
| static int voss_do_background; | static int voss_do_background; | ||||
| static int voss_baseclone = 0; | |||||
| static const char *voss_pid_path; | static const char *voss_pid_path; | ||||
| uint32_t voss_dsp_rx_refresh; | uint32_t voss_dsp_rx_refresh; | ||||
| uint32_t voss_dsp_tx_refresh; | uint32_t voss_dsp_tx_refresh; | ||||
| char voss_dsp_rx_device[VMAX_STRING]; | char voss_dsp_rx_device[VMAX_STRING]; | ||||
| char voss_dsp_tx_device[VMAX_STRING]; | char voss_dsp_tx_device[VMAX_STRING]; | ||||
| char voss_ctl_device[VMAX_STRING]; | char voss_ctl_device[VMAX_STRING]; | ||||
| ▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | fprintf(stderr, "Usage: virtual_oss [options...] [device] \\\n" | ||||
| "\t" "-t vdsp.ctl \n" | "\t" "-t vdsp.ctl \n" | ||||
| "\t" "Left channel = 0\n" | "\t" "Left channel = 0\n" | ||||
| "\t" "Right channel = 1\n" | "\t" "Right channel = 1\n" | ||||
| "\t" "Max channels = %d\n", VMAX_CHAN); | "\t" "Max channels = %d\n", VMAX_CHAN); | ||||
| exit(EX_USAGE); | exit(EX_USAGE); | ||||
| } | } | ||||
| /* | |||||
| * Restore hw.snd.basename_clone if it was disabled by us. | |||||
| */ | |||||
| static void | static void | ||||
| restore_baseclone(void) | |||||
| { | |||||
| if (voss_baseclone) { | |||||
| if (sysctlbyname(SYSCTL_BASECLONE, NULL, NULL, &voss_baseclone, | |||||
| sizeof(int)) < 0) | |||||
| warn("Could not enable " SYSCTL_BASECLONE); | |||||
markj: atexit() handlers shouldn't call exit(). | |||||
| printf(SYSCTL_BASECLONE ": 0 -> %d\n", voss_baseclone); | |||||
| } | |||||
| } | |||||
| static void | |||||
| init_compressor(struct virtual_profile *pvp) | init_compressor(struct virtual_profile *pvp) | ||||
| { | { | ||||
| int x; | int x; | ||||
| memset(&pvp->rx_compressor_param, 0, sizeof(pvp->rx_compressor_param)); | memset(&pvp->rx_compressor_param, 0, sizeof(pvp->rx_compressor_param)); | ||||
| pvp->rx_compressor_param.knee = 85; | pvp->rx_compressor_param.knee = 85; | ||||
| pvp->rx_compressor_param.attack = 3; | pvp->rx_compressor_param.attack = 3; | ||||
| ▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | dup_profile(vprofile_t *pvp, int *pamp, int pol, int rx_mute, | ||||
| } | } | ||||
| /* create DSP device */ | /* create DSP device */ | ||||
| if (ptr->oss_name[0] != 0) { | if (ptr->oss_name[0] != 0) { | ||||
| /* | /* | ||||
| * Detect /dev/dsp creation and try to disable system | * Detect /dev/dsp creation and try to disable system | ||||
| * basename cloning automatically: | * basename cloning automatically: | ||||
| */ | */ | ||||
| if (strcmp(ptr->oss_name, "dsp") == 0) | if (strcmp(ptr->oss_name, "dsp") == 0) { | ||||
| system("sysctl hw.snd.basename_clone=0"); | size_t size; | ||||
| x = 0; | |||||
| size = sizeof(int); | |||||
| if (sysctlbyname(SYSCTL_BASECLONE, &voss_baseclone, | |||||
| &size, &x, size) < 0) | |||||
| return ("Could not disable " SYSCTL_BASECLONE); | |||||
| printf(SYSCTL_BASECLONE ": %d -> 0\n", voss_baseclone); | |||||
| if (atexit(restore_baseclone) < 0) | |||||
| return ("Could not set atexit callback"); | |||||
Done Inline ActionsWhy do you call err() when the error path above returns an error string? markj: Why do you call err() when the error path above returns an error string? | |||||
| } | |||||
Done Inline ActionsYou can read and write the sysctl with a single call. markj: You can read and write the sysctl with a single call. | |||||
Done Inline ActionsExtra newline here. markj: Extra newline here. | |||||
| /* create DSP character device */ | /* create DSP character device */ | ||||
| pdev = cuse_dev_create(&vclient_oss_methods, ptr, NULL, | pdev = cuse_dev_create(&vclient_oss_methods, ptr, NULL, | ||||
| 0, 0, voss_dsp_perm, ptr->oss_name); | 0, 0, voss_dsp_perm, ptr->oss_name); | ||||
| if (pdev == NULL) { | if (pdev == NULL) { | ||||
| free(ptr); | free(ptr); | ||||
| return ("Could not create CUSE DSP device"); | return ("Could not create CUSE DSP device"); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 656 Lines • ▼ Show 20 Lines | main(int argc, char **argv) | ||||
| memset(&sa, 0, sizeof(sa)); | memset(&sa, 0, sizeof(sa)); | ||||
| sigfillset(&sa.sa_mask); | sigfillset(&sa.sa_mask); | ||||
| sa.sa_handler = virtual_sig_exit; | sa.sa_handler = virtual_sig_exit; | ||||
| if (sigaction(SIGINT, &sa, NULL) < 0) | if (sigaction(SIGINT, &sa, NULL) < 0) | ||||
| err(1, "sigaction(SIGINT)"); | err(1, "sigaction(SIGINT)"); | ||||
| if (sigaction(SIGTERM, &sa, NULL) < 0) | if (sigaction(SIGTERM, &sa, NULL) < 0) | ||||
| err(1, "sigaction(SIGTERM)"); | err(1, "sigaction(SIGTERM)"); | ||||
| ptrerr = parse_options(argc, argv, 1); | ptrerr = parse_options(argc, argv, 1); | ||||
Done Inline ActionsWhy not set the atexit handler in the same place where you set the sysctl to begin with? markj: Why not set the atexit handler in the same place where you set the sysctl to begin with? | |||||
Done Inline ActionsI thought it makes more sense to put it here along with some other callback settings (signal callback). I can move do it after the sysctl setting, no objection. christos: I thought it makes more sense to put it here along with some other callback settings (signal… | |||||
| if (ptrerr != NULL) | if (ptrerr != NULL) | ||||
| errx(EX_USAGE, "%s", ptrerr); | errx(EX_USAGE, "%s", ptrerr); | ||||
| if (voss_dsp_rx_device[0] == 0 || voss_dsp_tx_device[0] == 0) | if (voss_dsp_rx_device[0] == 0 || voss_dsp_tx_device[0] == 0) | ||||
| errx(EX_USAGE, "Missing -f argument"); | errx(EX_USAGE, "Missing -f argument"); | ||||
| /* use DSP channels as default */ | /* use DSP channels as default */ | ||||
| if (voss_mix_channels == 0) | if (voss_mix_channels == 0) | ||||
| ▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines | |||||
atexit() handlers shouldn't call exit().