aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-02-26 01:34:08 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-02-26 01:34:08 +0100
commit84254c10d2898fbe7f45934bcaad94a217cc22ab (patch)
tree4a2d468800a3318e38c95983d5c390c8e1f4b9cc /src
parent7af7b3dd5f1a4bdef4748079dfee86c81d00bee9 (diff)
downloadODR-AudioEnc-84254c10d2898fbe7f45934bcaad94a217cc22ab.tar.gz
ODR-AudioEnc-84254c10d2898fbe7f45934bcaad94a217cc22ab.tar.bz2
ODR-AudioEnc-84254c10d2898fbe7f45934bcaad94a217cc22ab.zip
Make ALSA input conditional
Diffstat (limited to 'src')
-rw-r--r--src/AlsaInput.cpp9
-rw-r--r--src/AlsaInput.h17
-rw-r--r--src/VLCInput.h4
-rw-r--r--src/common.h29
-rw-r--r--src/dabplus-enc.cpp23
5 files changed, 68 insertions, 14 deletions
diff --git a/src/AlsaInput.cpp b/src/AlsaInput.cpp
index 492ff62..e5fd420 100644
--- a/src/AlsaInput.cpp
+++ b/src/AlsaInput.cpp
@@ -17,12 +17,13 @@
* -------------------------------------------------------------------
*/
+#include "config.h"
+#if HAVE_ALSA
+
+#include "AlsaInput.h"
#include <cstdio>
#include <string>
-
#include <alsa/asoundlib.h>
-
-#include "AlsaInput.h"
#include <sys/time.h>
using namespace std;
@@ -159,3 +160,5 @@ ssize_t AlsaInputDirect::read(uint8_t* buf, size_t length)
return (read > 0) ? read * bytes_per_frame : read;
}
+#endif // HAVE_ALSA
+
diff --git a/src/AlsaInput.h b/src/AlsaInput.h
index 4f63ab5..34886df 100644
--- a/src/AlsaInput.h
+++ b/src/AlsaInput.h
@@ -19,6 +19,11 @@
#ifndef __ALSA_H_
#define __ALSA_H_
+
+#include "config.h"
+
+#if HAVE_ALSA
+
#include <cstdio>
#include <string>
#include <thread>
@@ -27,12 +32,7 @@
#include <alsa/asoundlib.h>
#include "SampleQueue.h"
-
-// 16 bits per sample is fine for now
-#define BYTES_PER_SAMPLE 2
-
-// How many samples we insert into the queue each call
-#define NUM_SAMPLES_PER_CALL 10 // 10 samples @ 32kHz = 3.125ms
+#include "common.h"
/* Common functionality for the direct alsa input and the
* threaded alsa input
@@ -132,5 +132,8 @@ class AlsaInputThreaded : public AlsaInput
};
-#endif
+#endif // HAVE_ALSA
+
+#endif // __ALSA_H_
+
diff --git a/src/VLCInput.h b/src/VLCInput.h
index 27d6237..5139b89 100644
--- a/src/VLCInput.h
+++ b/src/VLCInput.h
@@ -34,9 +34,7 @@
#include <vlc/vlc.h>
#include "SampleQueue.h"
-
-// 16 bits per sample is fine for now
-#define BYTES_PER_SAMPLE 2
+#include "common.h"
/* Common functionality for the direct libvlc input and the
* threaded libvlc input
diff --git a/src/common.h b/src/common.h
new file mode 100644
index 0000000..cd856f4
--- /dev/null
+++ b/src/common.h
@@ -0,0 +1,29 @@
+/* ------------------------------------------------------------------
+ * Copyright (C) 2016 Matthias P. Braendli
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+ * express or implied.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ * -------------------------------------------------------------------
+ */
+
+#ifndef __COMMON_H_
+#define __COMMON_H_
+
+// 16 bits per sample is fine for now
+#define BYTES_PER_SAMPLE 2
+
+// How many samples we insert into the queue each call
+#define NUM_SAMPLES_PER_CALL 10 // 10 samples @ 32kHz = 3.125ms
+
+#endif // __COMMON_H_
+
diff --git a/src/dabplus-enc.cpp b/src/dabplus-enc.cpp
index b865a61..42a58f9 100644
--- a/src/dabplus-enc.cpp
+++ b/src/dabplus-enc.cpp
@@ -24,6 +24,7 @@
#include "VLCInput.h"
#include "SampleQueue.h"
#include "zmq.hpp"
+#include "common.h"
extern "C" {
#include "encryption.h"
@@ -41,6 +42,7 @@ extern "C" {
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+#include <fcntl.h>
#include "libAACenc/include/aacenc_lib.h"
@@ -49,6 +51,8 @@ extern "C" {
#include "libtoolame-dab/toolame.h"
}
+
+
// Enumerate which encoder we can use
enum class encoder_selection_t {
fdk_dabplus,
@@ -83,7 +87,7 @@ void usage(const char* name) {
"This encoder includes PAD (DLS and MOT Slideshow) support by\n"
"http://rd.csp.it to be used with mot-encoder\n"
"\nUsage:\n"
- "%s (-i file|-d alsa_device) [OPTION...]\n",
+ "%s [INPUT SELECTION] [OPTION...]\n",
#if defined(GITVERSION)
GITVERSION
#else
@@ -92,7 +96,11 @@ void usage(const char* name) {
, name);
fprintf(stderr,
" For the alsa input:\n"
+#if HAVE_ALSA
" -d, --device=alsa_device Set ALSA input device (default: \"default\").\n"
+#else
+ " The Alsa input was disabled at compile time\n"
+#endif
" For the file input:\n"
" -i, --input=FILENAME Input filename (default: stdin).\n"
" -f, --format={ wav, raw } Set input file format (default: wav).\n"
@@ -694,8 +702,10 @@ int main(int argc, char *argv[])
}
// We'll use one of the tree possible inputs
+#if HAVE_ALSA
AlsaInputThreaded alsa_in_threaded(alsa_device, channels, sample_rate, queue);
AlsaInputDirect alsa_in_direct(alsa_device, channels, sample_rate);
+#endif
FileInput file_in(infile, raw_input, sample_rate);
#if HAVE_JACK
JackInput jack_in(jack_name, channels, sample_rate, queue);
@@ -738,6 +748,7 @@ int main(int argc, char *argv[])
}
}
#endif
+#if HAVE_ALSA
else if (drift_compensation) {
if (alsa_in_threaded.prepare() != 0) {
fprintf(stderr, "Alsa with drift compensation: preparation failed\n");
@@ -753,6 +764,12 @@ int main(int argc, char *argv[])
return 1;
}
}
+#else
+ else {
+ fprintf(stderr, "No input defined\n");
+ return 1;
+ }
+#endif
int outbuf_size;
std::vector<uint8_t> zmqframebuf;
@@ -912,11 +929,13 @@ int main(int argc, char *argv[])
}
#endif
else if (drift_compensation || jack_name) {
+#if HAVE_ALSA
if (drift_compensation && alsa_in_threaded.fault_detected()) {
fprintf(stderr, "Detected fault in alsa input!\n");
retval = 5;
break;
}
+#endif
size_t overruns;
read_bytes = queue.pop(&input_buf[0], input_buf.size(), &overruns); // returns bytes
@@ -930,6 +949,7 @@ int main(int argc, char *argv[])
}
}
else {
+#if HAVE_ALSA
read_bytes = alsa_in_direct.read(&input_buf[0], input_buf.size());
if (read_bytes < 0) {
break;
@@ -937,6 +957,7 @@ int main(int argc, char *argv[])
else if (read_bytes != input_buf.size()) {
fprintf(stderr, "Short alsa read !\n");
}
+#endif
}
for (int i = 0; i < read_bytes; i+=4) {