summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGoran Mekić <meka@tilda.center>2017-04-17 02:19:43 +0200
committerGoran Mekić <meka@tilda.center>2017-04-17 14:24:22 +0200
commitd091b7db11fc0fa3e19912d03c11d511218608e3 (patch)
tree317b132246bed7aa8ae430b78fc814f2d872e168
parent20c62f8cc12c86734d63c654d2fceb80d762e010 (diff)
CLI diskstreaming options
-rw-r--r--drumgizmo/drumgizmoc.cc113
-rw-r--r--man/drumgizmo.115
-rw-r--r--src/bytesizeparser.cc17
3 files changed, 104 insertions, 41 deletions
diff --git a/drumgizmo/drumgizmoc.cc b/drumgizmo/drumgizmoc.cc
index 4ad2550..a8a94d1 100644
--- a/drumgizmo/drumgizmoc.cc
+++ b/drumgizmo/drumgizmoc.cc
@@ -33,6 +33,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sstream>
#include <hugin.hpp>
@@ -66,11 +67,12 @@ static const char usage_str[] =
"output engine.\n"
" -O, --outputparms parmlist Set output engine parameters.\n"
" -e, --endpos Number of samples to process, -1: infinite.\n"
- " -m, --diskstreamsize Size of buffer for disk streaming, eg. 5{k,M,G}.\n"
#ifndef DISABLE_HUGIN
" -D, --debug ddd Enable debug messages on 'ddd'; see hugin "
"documentation for details\n"
#endif /*DISABLE_HUGIN*/
+ " -s, --streaming Enable streaming.\n"
+ " -S, --streamingparms Streaming options.\n"
" -v, --version Print version information and exit.\n"
" -h, --help Print this message and exit.\n"
"\n"
@@ -95,6 +97,10 @@ static const char usage_str[] =
"(default 44100)\n"
" jackaudio:\n"
" dummy:\n"
+ "\n"
+ "Streaming parameters:\n"
+ " limit: maximum size in k,M,G\n"
+ " chunk_size: chunk size in k,M,G\n"
"\n";
@@ -113,30 +119,32 @@ int main(int argc, char* argv[])
std::string inputengine;
std::string iparms;
std::string oparms;
+ std::string sparms;
bool async = false;
int endpos = -1;
EngineFactory factory;
int option_index = 0;
- while(1)
- {
- static struct option long_options[] = {
- {"async-load", no_argument, 0, 'a'},
- {"inputengine", required_argument, 0, 'i'},
- {"inputparms", required_argument, 0, 'I'},
- {"outputengine", required_argument, 0, 'o'},
- {"outputparms", required_argument, 0, 'O'},
- {"endpos", required_argument, 0, 'e'},
- {"diskstreamsize", required_argument, 0, 'm'},
+ static struct option long_options[] = {
+ {"async-load", no_argument, 0, 'a'},
+ {"inputengine", required_argument, 0, 'i'},
+ {"inputparms", required_argument, 0, 'I'},
+ {"outputengine", required_argument, 0, 'o'},
+ {"outputparms", required_argument, 0, 'O'},
+ {"endpos", required_argument, 0, 'e'},
#ifndef DISABLE_HUGIN
- {"debug", required_argument, 0, 'D'},
+ {"debug", required_argument, 0, 'D'},
#endif /*DISABLE_HUGIN*/
- {"version", no_argument, 0, 'v'},
- {"help", no_argument, 0, 'h'},
- {0, 0, 0, 0}};
-
- c = getopt_long(argc, argv, "hvpo:O:i:I:e:am:"
+ {"streaming", no_argument, 0, 's'},
+ {"streamingparams", required_argument, 0, 'S'},
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+ while(1)
+ {
+ c = getopt_long(argc, argv, "hvpo:O:i:I:e:asS:"
#ifndef DISABLE_HUGIN
"D:"
#endif /*DISABLE_HUGIN*/
@@ -211,18 +219,13 @@ int main(int argc, char* argv[])
printf("%s", copyright_str);
return 0;
- case 'm':
- settings.disk_cache_upper_limit = byteSizeParser(optarg);
- if(!settings.disk_cache_upper_limit)
- {
- printf("%s", version_str);
- printf(usage_str, argv[0]);
- std::cerr << "Stream size should be in <number>[suffix] format ";
- std::cerr << "where [suffix] is k, M, or G." << std::endl;
- std::cerr << "Example: 10M which is 10 * 1024 * 1024 bytes" << std::endl;
- return 1;
- }
+ case 's':
settings.disk_cache_enable = true;
+ break;
+
+ case 'S':
+ sparms = optarg;
+ break;
default:
break;
@@ -257,7 +260,7 @@ int main(int argc, char* argv[])
std::string parm;
std::string val;
bool inval = false;
- for(size_t i = 0; i < iparms.size(); i++)
+ for(size_t i = 0; i < iparms.size(); ++i)
{
if(iparms[i] == ',')
{
@@ -289,6 +292,56 @@ int main(int argc, char* argv[])
}
}
+ {
+ if(sparms.size() != 0)
+ {
+ if(sparms[0] == ',' || sparms[sparms.size()-1] == ',')
+ {
+ std::cerr << "Invalid streamparms" << std::endl;
+ return 1;
+ }
+ std::string token;
+ std::istringstream tokenstream(sparms);
+ while(getline(tokenstream, token, ','))
+ {
+ std::size_t index = token.find('=');
+ if(index == std::string::npos || index == token.size()-1 || index == 0)
+ {
+ std::cerr << "Invalid streamparms" << std::endl;
+ return 1;
+ }
+
+ std::string parm = token.substr(0, index);
+ std::string value = token.substr(index+1);
+
+ if(parm == "limit")
+ {
+ settings.disk_cache_upper_limit = byteSizeParser(value);
+ if(settings.disk_cache_upper_limit == 0)
+ {
+ std::cerr << "Invalid argument for streamparms limit: " << value << std::endl;
+ return 1;
+ }
+ }
+ else if(parm == "chunk_size")
+ {
+ settings.disk_cache_chunk_size = byteSizeParser(value);
+ if(settings.disk_cache_chunk_size == 0)
+ {
+ std::cerr << "Invalid argument for streamparms chunk_size: " << value << std::endl;
+ return 1;
+ }
+ }
+ else
+ {
+ std::cerr << "Unknown streamingparms argument " << parm << std::endl;
+ return 1;
+ }
+ }
+ }
+ return 0;
+ }
+
if(outputengine == "")
{
printf("Missing output engine\n");
@@ -307,7 +360,7 @@ int main(int argc, char* argv[])
std::string parm;
std::string val;
bool inval = false;
- for(size_t i = 0; i < oparms.size(); i++)
+ for(size_t i = 0; i < oparms.size(); ++i)
{
if(oparms[i] == ',')
{
diff --git a/man/drumgizmo.1 b/man/drumgizmo.1
index 281d162..3d36299 100644
--- a/man/drumgizmo.1
+++ b/man/drumgizmo.1
@@ -99,6 +99,21 @@ http://manuals.opensound.com/developer/SNDCTL_DSP_SETFRAGMENT.html
Number of samples to process, (default -1: infinite)
.RE
+\fB-s, --streaming\fR
+.RS 7
+Enable diskstreaming
+
+.RE
+\fB-S, --strimingparms parmlist\fR
+.RS 7
+Parameters for controling the streaming buffers.
+
+.P
+\fBlimit\fR=<size> (maximum size in k,M,G)
+.P
+\fBchunk_size\fR=<size> (chunk size in k,M,G)
+
+.RE
\fB-v, --version\fR
.RS 7
Print drumgizmo version and exit.
diff --git a/src/bytesizeparser.cc b/src/bytesizeparser.cc
index 329407d..ef63f7d 100644
--- a/src/bytesizeparser.cc
+++ b/src/bytesizeparser.cc
@@ -54,7 +54,7 @@ static std::size_t suffixToSize(const char& suffix)
std::size_t byteSizeParser(const std::string& argument)
{
std::string::size_type suffix_index;
- std::size_t stream_size;
+ std::size_t size;
std::string suffix;
bool error = false;
@@ -65,7 +65,7 @@ std::size_t byteSizeParser(const std::string& argument)
try
{
- stream_size = std::stoi(argument, &suffix_index);
+ size = std::stoi(argument, &suffix_index);
}
catch(std::invalid_argument)
{
@@ -85,19 +85,14 @@ std::size_t byteSizeParser(const std::string& argument)
error = true;
}
}
- if(!error)
+ if(!error && suffix.size() > 0)
{
- std::size_t suffix_size = 1;
- if(suffix_index <= suffix.length())
- {
- suffix_size = suffixToSize(suffix[0]);
-
- }
- stream_size *= suffix_size;
+ std::size_t suffix_size = suffixToSize(suffix[0]);
+ size *= suffix_size;
}
if(error)
{
return 0;
}
- return stream_size;
+ return size;
}