From e47580ccf15a9951ba5f928f3817a02695279a97 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Mon, 1 Feb 2021 16:14:03 +0000 Subject: add functional argv --device --- parecord/parecord.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'parecord') diff --git a/parecord/parecord.c b/parecord/parecord.c index e14cea9..5e8e94e 100644 --- a/parecord/parecord.c +++ b/parecord/parecord.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "audio_types.h" @@ -56,11 +57,12 @@ int main(int argc, char *argv[]) pa_simple *connection; pa_sample_spec specification; - int fd_output = STDOUT_FILENO, result; + int fd_output = STDOUT_FILENO, result, error; int file_type = AUDIO_TYPE_NONE; int record_format = STD_REC_FORMAT; uint32_t record_rate = STD_REC_RATE; uint8_t record_channels = STD_REC_CHANNELS; + char *device = NULL; off_t offset; const struct option long_options[] = { {"help", no_argument, NULL, 'h'}, @@ -85,7 +87,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "\t\tPrint this text.\n"); fprintf(stderr, "\t-d, --device\n"); - fprintf(stderr, "\t\tIn development...\n"); + fprintf(stderr, "\t\tName of the audio devices to record stream.\n"); fprintf(stderr, "\t-D, --list-devices\n"); fprintf(stderr, "\t\tPrint all recorder audio devices\n"); @@ -110,7 +112,8 @@ int main(int argc, char *argv[]) return 0; } case 'd': { - // ... + device = malloc((strlen(optarg)+1) * sizeof(char)); + strcpy(device, optarg); break; } case 'D': { @@ -201,14 +204,14 @@ int main(int argc, char *argv[]) connection = pa_simple_new(NULL, argv[0], PA_STREAM_RECORD, - NULL, + device, "record", &specification, NULL, NULL, - NULL); + &error); if(!connection) { - fprintf(stderr, "[Error] pa_simple_new() failed\n"); + fprintf(stderr, "[Error] pa_simple_new(): %s failed\n", pa_strerror(error)); return 1; } @@ -281,5 +284,8 @@ int main(int argc, char *argv[]) close(fd_output); } + if(!device) + free(device); + return 0; } -- cgit v1.2.3-18-g5258