History

Add extended command line options

Tom Kistner committed 7 years ago

Commit 4e489371 parent 5cc918c2 files · +53 −22Browse files

Unified · Split

2 files
  1. Receivers/alsa/scream-alsa.c +52 −22
  2. Receivers/pulseaudio/scream-pulse.c +1 −0
Receivers/alsa/scream-alsa.c+52−22
@@ -10,10 +10,8 @@ · 9 unmodified lines
1010 #include <netinet/in.h>
1111 #include <arpa/inet.h>
1212
13−#define MULTICAST_TARGET "239.255.77.77"
14−#define MULTICAST_PORT 4010
15−
16−#define BYTES_PER_SAMPLE 2
13+#define DEFAULT_MULTICAST_GROUP "239.255.77.77"
14+#define DEFAULT_PORT 4010
1715
1816 #define MAX_SO_PACKETSIZE 1154
1917 #define CHANNELS 2
@@ -32,8 +30,23 @@ static void alsa_error(const char *msg, int r) · 12 unmodified lines
3230
3331 static void show_usage(const char *arg0)
3432 {
35− fprintf(stderr, "Usage: %s [-v] [-i interface_name_or_address] [-t target_latency_ms]\n",
36− arg0);
33+ fprintf(stderr, "\n");
34+ fprintf(stderr, "Usage: %s [-u] [-v] [-p <port>] [-i <iface>] [-g <group>] [-t <target_latency_ms>]\n", arg0);
35+ fprintf(stderr, "\n");
36+ fprintf(stderr, " All command line options are optional. Default is to use\n");
37+ fprintf(stderr, " multicast with group address 239.255.77.77, port 4010.\n");
38+ fprintf(stderr, "\n");
39+ fprintf(stderr, " -u : Use unicast instead of multicast.\n");
40+ fprintf(stderr, " -v : Verbose operation.\n");
41+ fprintf(stderr, " -p <port> : Use <port> instead of default port 4010.\n");
42+ fprintf(stderr, " Applies to both multicast and unicast.\n");
43+ fprintf(stderr, " -i <iface> : Use local interface <iface>. Either the IP\n");
44+ fprintf(stderr, " or the interface name can be specified. In\n");
45+ fprintf(stderr, " multicast mode, uses this interface for IGMP.\n");
46+ fprintf(stderr, " In unicast, binds to this interface only.\n");
47+ fprintf(stderr, " -g <group> : Multicast group address. Multicast mode only.\n");
48+ fprintf(stderr, " -t <latency>: Target latency in milliseconds. Defaults to 50ms.\n");
49+ fprintf(stderr, "\n");
3750 exit(1);
3851 }
3952
@@ -149,22 +162,38 @@ int main(int argc, char *argv[]) · 109 unmodified lines
149162 struct ip_mreq imreq;
150163 snd_pcm_t *snd;
151164 unsigned char buf[MAX_SO_PACKETSIZE];
152− in_addr_t interface = INADDR_ANY;
153165 int opt;
154166 int verbosity = 0;
155167 int samples;
156168 snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE;
157169 unsigned int bytes_per_sample = 2;
158170 unsigned int rate = 44100;
159− int target_latency_ms = 50;
160171 unsigned char cur_server_rate = 0;
161172 unsigned char cur_server_size = 0;
162173
163− while ((opt = getopt(argc, argv, "i:t:v")) != -1) {
174+ // Command line options
175+ int use_unicast = 0;
176+ char *multicast_group = NULL;
177+ in_addr_t interface = INADDR_ANY;
178+ uint16_t port = DEFAULT_PORT;
179+ int target_latency_ms = 50;
180+
181+
182+ while ((opt = getopt(argc, argv, "i:g:p:t:vuh")) != -1) {
164183 switch (opt) {
165184 case 'i':
166185 interface = get_interface(optarg);
167186 break;
187+ case 'p':
188+ port = atoi(optarg);
189+ if (!port) show_usage(argv[0]);
190+ break;
191+ case 'u':
192+ use_unicast = 1;
193+ break;
194+ case 'g':
195+ multicast_group = strdup(optarg);
196+ break;
168197 case 't':
169198 target_latency_ms = atoi(optarg);
170199 break;
@@ -180,23 +209,21 @@ int main(int argc, char *argv[]) · 9 unmodified lines
180209 show_usage(argv[0]);
181210 }
182211
183− // const char *device = "default";
184− // ret = snd_pcm_open(&snd, device, SND_PCM_STREAM_PLAYBACK, 0);
185− // SNDCHK("snd_pcm_open", ret);
186−
187212 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
188213
189214 memset((void *)&servaddr, 0, sizeof(servaddr));
190215 servaddr.sin_family = AF_INET;
191− servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
192− servaddr.sin_port = htons(MULTICAST_PORT);
216+ servaddr.sin_addr.s_addr = use_unicast ? interface : htonl(INADDR_ANY);
217+ servaddr.sin_port = htons(port);
193218 bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
194219
195− imreq.imr_multiaddr.s_addr = inet_addr(MULTICAST_TARGET);
196− imreq.imr_interface.s_addr = interface;
220+ if (!use_unicast) {
221+ imreq.imr_multiaddr.s_addr = inet_addr(multicast_group ? multicast_group : DEFAULT_MULTICAST_GROUP);
222+ imreq.imr_interface.s_addr = interface;
197223
198− setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
199− (const void *)&imreq, sizeof(struct ip_mreq));
224+ setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
225+ (const void *)&imreq, sizeof(struct ip_mreq));
226+ }
200227
201228 if (setup_alsa(&snd, format, rate, verbosity, target_latency_ms) == -1) {
202229 return -1;
@@ -217,19 +244,22 @@ int main(int argc, char *argv[]) · 14 unmodified lines
217244 case 24: format = SND_PCM_FORMAT_S24_3LE; bytes_per_sample = 3; break;
218245 case 32: format = SND_PCM_FORMAT_S32_LE; bytes_per_sample = 4; break;
219246 default:
220− printf("Unsupported sample size %hhu, not playing until next format switch.\n", cur_server_size);
247+ if (verbosity > 0)
248+ printf("Unsupported sample size %hhu, not playing until next format switch.\n", cur_server_size);
221249 rate = 0;
222250 }
223251
224252 if (rate) {
225253 close_alsa(snd);
226254 if (setup_alsa(&snd, format, rate, verbosity, target_latency_ms) == -1) {
227− printf("Unable to set up ALSA with sample rate %u and sample size %hhu, not playing until next format switch.\n", rate, cur_server_size);
255+ if (verbosity > 0)
256+ printf("Unable to set up ALSA with sample rate %u and sample size %hhu, not playing until next format switch.\n", rate, cur_server_size);
228257 snd = NULL;
229258 rate = 0;
230259 }
231260 else {
232− printf("Switched format to sample rate %u and sample size %hhu.\n", rate, cur_server_size);
261+ if (verbosity > 0)
262+ printf("Switched format to sample rate %u and sample size %hhu.\n", rate, cur_server_size);
233263 }
234264 }
235265 }
Receivers/pulseaudio/scream-pulse.c+1−0
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313
1414 #define DEFAULT_MULTICAST_GROUP "239.255.77.77"
1515 #define DEFAULT_PORT 4010
16+
1617 #define MAX_SO_PACKETSIZE 1154
1718
1819 static void show_usage(const char *arg0)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t