--- a/mpd2src/mpd2sc.cpp
+++ b/mpd2src/mpd2sc.cpp
@@ -330,51 +330,88 @@
delete (iDriver);
}
-int main(int aArgc, char* aArgv[])
-{
- OptionParser parser;
-
- OptionString optionAudioParams("-A", "--audio", Brn(""), "[44100:16:2:0/1] audio params only if they can't be obtained from file. Conflicting values will cause error");
- parser.AddOption(&optionAudioParams);
-
- OptionUint optionAdapter("-a", "--adapter", 0, "[adapter] index of network adapter to use");
- parser.AddOption(&optionAdapter);
-
- OptionUint optionChannel("-c", "--channel", 0, "[0..65535] sender channel");
- parser.AddOption(&optionChannel);
-
- OptionBool optionDisabled("-d", "--disabled", "[disabled] start up disabled");
- parser.AddOption(&optionDisabled);
-
- OptionString optionFile("-f", "--file", Brn(""), "[file] file name to read and send. "
- "Use xx.wav for an actual wav,\n"
- " xx or xx.fifo for a fifo, stdin for stdin");
- parser.AddOption(&optionFile);
-
- OptionUint optionLatency("-l", "--latency", 100, "[latency] latency in ms");
- parser.AddOption(&optionLatency);
-
- OptionBool optionMulticast("-m", "--multicast", "[multicast] use multicast instead of unicast");
- parser.AddOption(&optionMulticast);
-
- OptionBool optionNeedPace("-p", "--pace", "Use internal timer to pace source. Implicit for regular files.");
- parser.AddOption(&optionNeedPace);
-
- OptionString optionName("-n", "--name", Brn("Openhome WavSender"), "[name] name of the sender");
- parser.AddOption(&optionName);
-
- OptionUint optionTtl("-t", "--ttl", 1, "[ttl] ttl");
- parser.AddOption(&optionTtl);
-
- OptionString optionUdn("-u", "--udn", Brn("12345678"), "[udn] udn for the upnp device");
- parser.AddOption(&optionUdn);
-
-// OptionBool optionPacketLogging("-z", "--logging", "[logging] toggle packet logging");
-// parser.AddOption(&optionPacketLogging);
-
- if (!parser.Parse(aArgc, aArgv)) {
- return (1);
- }
+static char *thisprog;
+static char usage [] =
+" -h, --help, show this help message and exit.\n"
+" -A, --audio, [44100:16:2:0/1] audio params only if they can't be obtained\n"
+" from the file. Conflicting values will cause error."
+" -a, --adapter, [adapter] index of network adapter to use.\n"
+" -c, --channel, [0..65535] sender channel.\n"
+" -d, --disabled, [disabled] start up disabled.\n"
+" -f, --file, [file] file name to read and send.\n"
+" Use xx.wav for an actual wav,\n"
+" xx or xx.fifo for a fifo, stdin for stdin.\n"
+" -l, --latency, [latency] latency in ms.\n"
+" -m, --multicast, [multicast] use multicast instead of unicast.\n"
+" -p, --pace, Use internal timer to pace source. Implicit for regular files.\n"
+" -n, --name, [name] name of the sender.\n"
+" -t, --ttl, [ttl] ttl.\n"
+" -u, --udn, [udn] udn for the upnp device.\n"
+ ;
+static void
+Usage(FILE *fp = stderr)
+{
+ fprintf(fp, "%s: usage:\n%s", thisprog, usage);
+ exit(1);
+}
+
+#include <getopt.h>
+static int op_flags;
+#define OPT_A 0x1
+#define OPT_a 0x2
+#define OPT_c 0x4
+#define OPT_d 0x8
+#define OPT_f 0x10
+#define OPT_l 0x20
+#define OPT_m 0x40
+#define OPT_n 0x80
+#define OPT_p 0x100
+#define OPT_t 0x200
+#define OPT_u 0x400
+
+static struct option long_options[] = {
+ {"audio", required_argument, 0, 'A'},
+ {"adapter", required_argument, 0, 'a'},
+ {"channel", required_argument, 0, 'c'},
+ {"disabled", 0, 0, 'd'},
+ {"file", required_argument, 0, 'f'},
+ {"latency", required_argument, 0, 'l'},
+ {"multicast", 0, 0, 'm'},
+ {"name", required_argument, 0, 'n'},
+ {"pace", 0, 0, 'p'},
+ {"ttl", required_argument, 0, 't'},
+ {"udn", required_argument, 0, 'u'},
+ {0, 0, 0, 0}
+};
+
+int main(int argc, char **argv)
+{
+ thisprog = argv[0];
+ int ret;
+ (void)op_flags;
+ string audioparams, sfile, sname("Openhome WavSender"), sudn("12345678");
+ unsigned int adaptidx(0), channel(0), ttl(1), latency(100);
+ while ((ret = getopt_long(argc, argv, "A:a:c:df:l:mn:pt:u:",
+ long_options, NULL)) != -1) {
+ switch (ret) {
+ case 'A': audioparams = optarg;op_flags |= OPT_A; break;
+ case 'a': adaptidx = atoi(optarg);op_flags |= OPT_a; break;
+ case 'c': channel = atoi(optarg);op_flags |= OPT_c; break;
+ case 'd': op_flags |= OPT_d; break;
+ case 'f': sfile = optarg;op_flags |= OPT_f; break;
+ case 'h': Usage(stdout);break;
+ case 'l': latency = atoi(optarg); op_flags |= OPT_l; break;
+ case 'm': op_flags |= OPT_m; break;
+ case 'n': sname = optarg;op_flags |= OPT_n; break;
+ case 'p': op_flags |= OPT_p; break;
+ case 't': ttl = atoi(optarg);op_flags |= OPT_t; break;
+ case 'u': sudn = optarg;op_flags |= OPT_u; break;
+ default:
+ Usage();
+ }
+ }
+ if (optind != argc )
+ Usage();
InitialisationParams* initParams = InitialisationParams::Create();
@@ -388,39 +425,32 @@
((addr>>8)&0xff) << "." << ((addr>>16)&0xff) << "." <<
((addr>>24)&0xff) << endl);
}
- if (subnetList->size() <= optionAdapter.Value()) {
- LOGERR("ERROR: adapter " << optionAdapter.Value() << "doesn't exist\n");
+ if (subnetList->size() <= adaptidx) {
+ LOGERR("ERROR: adapter " << adaptidx << "doesn't exist\n");
return (1);
}
- TIpAddress subnet = (*subnetList)[optionAdapter.Value()]->Subnet();
- TIpAddress adapter = (*subnetList)[optionAdapter.Value()]->Address();
+ TIpAddress subnet = (*subnetList)[adaptidx]->Subnet();
+ TIpAddress adapter = (*subnetList)[adaptidx]->Address();
Library::DestroySubnetList(subnetList);
lib->SetCurrentSubnet(subnet);
LOGDEB("using subnet " << (subnet&0xff) << "." << ((subnet>>8)&0xff) << "."
<< ((subnet>>16)&0xff) << "." << ((subnet>>24)&0xff) << endl);
- Brhz file(optionFile.Value());
-
- if (file.Bytes() == 0) {
+ if (sfile.empty()) {
LOGERR("No input file specified\n");
return (1);
}
-
- Brhz udn(optionUdn.Value());
- Brhz name(optionName.Value());
- Brhz audioparams(optionAudioParams.Value());
- TUint channel = optionChannel.Value();
- TUint ttl = optionTtl.Value();
- TUint latency = optionLatency.Value();
- TBool multicast = optionMulticast.Value();
- TBool disabled = optionDisabled.Value();
- //TBool logging = optionPacketLogging.Value();
- TBool needpace = optionNeedPace.Value();
-
- AudioReader *audio = openAudio(file.CString(), audioparams.CString(),
- !needpace);
+ Brhz file(sfile.c_str());
+
+ Brhz udn(sudn.c_str());
+ Brhz name(sname.c_str());
+ TBool multicast = op_flags & OPT_m;
+ TBool disabled = op_flags & OPT_d;
+ TBool needpace = op_flags & OPT_p;
+
+ AudioReader *audio = openAudio(sfile, audioparams, !needpace);
if (!audio || !audio->open()) {
cerr << "Audio file open failed" << endl;
return 1;