• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sched.h>
5 #include <errno.h>
6 #include <getopt.h>
7 #include "../include/mixer_ordinary.h"
8 #include <sys/time.h>
9 #include <math.h>
10 
help(void)11 static void help(void)
12 {
13 	printf(
14 "Usage: omixer [OPTION]...\n\n"
15 "-h,--help      help\n"
16 "-P,--pname     playback PCM device\n"
17 "-C,--cname     capture PCM device\n"
18 );
19 }
20 
main(int argc,char * argv[])21 int main(int argc, char *argv[])
22 {
23 	struct option long_option[] =
24 	{
25 		{"help", 0, NULL, 'h'},
26 		{"pname", 1, NULL, 'P'},
27 		{"cname", 1, NULL, 'C'},
28 		{NULL, 0, NULL, 0},
29 	};
30 	int err, morehelp, result = EXIT_SUCCESS;
31 	char *pname = "default", *cname = "default";
32 	snd_pcm_t *phandle = NULL, *chandle = NULL;
33 	sndo_mixer_t *handle;
34 
35 	morehelp = 0;
36 	while (1) {
37 		int c;
38 		if ((c = getopt_long(argc, argv, "hP:C:", long_option, NULL)) < 0)
39 			break;
40 		switch (c) {
41 		case 'h':
42 			morehelp++;
43 			break;
44 		case 'P':
45 			pname = strdup(optarg);
46 			break;
47 		case 'C':
48 			cname = strdup(optarg);
49 			break;
50 		}
51 	}
52 
53 	if (morehelp) {
54 		help();
55 		return 0;
56 	}
57 
58 	if (strcmp(pname, "-")) {
59 		err = snd_pcm_open(&phandle, pname, SND_PCM_STREAM_PLAYBACK, 0);
60 		if (err < 0) {
61 			fprintf(stderr, "Playback PCM open error: %s\n", snd_strerror(err));
62 			result = EXIT_FAILURE;
63 			goto __end;
64 		}
65 	}
66 
67 	if (strcmp(cname, "-")) {
68 		err = snd_pcm_open(&chandle, cname, SND_PCM_STREAM_CAPTURE, 0);
69 		if (err < 0) {
70 			if (phandle)
71 				snd_pcm_close(phandle);
72 			fprintf(stderr, "Capture PCM open error: %s\n", snd_strerror(err));
73 			result = EXIT_FAILURE;
74 			goto __end;
75 		}
76 	}
77 
78 	err = sndo_mixer_open_pcm(&handle, phandle, chandle, NULL);
79 	if (err < 0) {
80 		fprintf(stderr, "mixer open error: %s\n", snd_strerror(err));
81 		result = EXIT_FAILURE;
82 	} else {
83 		sndo_mixer_close(handle);
84 	}
85       __end:
86 	if (chandle)
87 		snd_pcm_close(chandle);
88 	if (phandle)
89 		snd_pcm_close(phandle);
90 	snd_config_update_free_global(); /* to keep valgrind happy */
91 	return result;
92 }
93