diff options
-rw-r--r-- | .travis.yml | 15 | ||||
-rw-r--r-- | Makefile.am | 11 | ||||
-rw-r--r-- | configure.ac | 18 | ||||
-rw-r--r-- | src/AlsaInput.cpp | 9 | ||||
-rw-r--r-- | src/AlsaInput.h | 17 | ||||
-rw-r--r-- | src/VLCInput.h | 4 | ||||
-rw-r--r-- | src/common.h | 29 | ||||
-rw-r--r-- | src/dabplus-enc.cpp | 23 |
8 files changed, 104 insertions, 22 deletions
diff --git a/.travis.yml b/.travis.yml index 289b8fd..5b48aa6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,18 @@ script: sudo make install popd - | - ./bootstrap - ./configure --enable-jack --enable-vlc + ./configure + make + - | + ./configure --enable-vlc + make + - | + ./configure --enable-alsa + make + - | + ./configure --enable-jack + make + - | + ./configure --enable-alsa --enable-jack --enable-vlc make diff --git a/Makefile.am b/Makefile.am index 31289bc..388adbb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -88,11 +88,17 @@ else dabplus_enc_LDADD_JACK = endif +if HAVE_ALSA +dabplus_enc_LDADD_ALSA = -lasound +else +dabplus_enc_LDADD_ALSA = +endif dabplus_enc_LDFLAGS = -no-install dabplus_enc_LDADD = libfdk-dabplus.la libtoolame-dab.la \ - -lfec -lzmq -lasound \ + -lfec -lzmq \ -lrt $(dabplus_enc_LDADD_JACK) \ + $(dabplus_enc_LDADD_ALSA) \ $(LIBVLC_LIBS) dabplus_enc_CPPFLAGS = $(AM_CPPFLAGS) $(GITVERSION_FLAGS) -ggdb -O2 dabplus_enc_SOURCES = src/dabplus-enc.cpp \ @@ -115,7 +121,8 @@ dabplus_enc_SOURCES = src/dabplus-enc.cpp \ src/utf8.h \ src/utf8/checked.h \ src/utf8/unchecked.h \ - src/utf8/core.h + src/utf8/core.h \ + src/common.h mot_encoder_CXXFLAGS = $(GITVERSION_FLAGS) @MAGICKWAND_CFLAGS@ -Icontrib mot_encoder_LDADD = @MAGICKWAND_LDADD@ diff --git a/configure.ac b/configure.ac index 16f570d..3796ab0 100644 --- a/configure.ac +++ b/configure.ac @@ -27,21 +27,30 @@ AC_SEARCH_LIBS([init_rs_char], [fec], [], [ AC_CHECK_LIB([rt], [clock_gettime], [], [AC_MSG_ERROR([library rt is missing])]) -AM_PATH_ALSA(1.0.25) +# Check for options +AC_ARG_ENABLE([alsa], + AS_HELP_STRING([--enable-alsa], [Enable ALSA input])) -# Check for JACK AC_ARG_ENABLE([jack], AS_HELP_STRING([--enable-jack], [Enable JACK input])) AC_ARG_ENABLE([vlc], AS_HELP_STRING([--enable-vlc], [Enable libvlc input])) + +AS_IF([test "x$enable_alsa" = "xyes"], + [AM_PATH_ALSA(1.0.25)]) +AS_IF([test "x$enable_alsa" = "xyes"], + AC_DEFINE(HAVE_ALSA, [1], [Define if ALSA input is enabled])) + + AS_IF([test "x$enable_jack" = "xyes"], AC_CHECK_LIB(jack, jack_client_open, [], [AC_MSG_ERROR([JACK is required])])) AS_IF([test "x$enable_jack" = "xyes"], AC_DEFINE(HAVE_JACK, [1], [Define if JACK input is enabled])) + AS_IF([test "x$enable_vlc" = "xyes"], [ PKG_CHECK_MODULES([LIBVLC], [libvlc]) AC_SUBST([LIBVLC_CFLAGS]) @@ -51,8 +60,9 @@ AS_IF([test "x$enable_vlc" = "xyes"], AC_DEFINE(HAVE_VLC, [1], [Define if VLC input is enabled])) -# Link against jack +# Link against jack and alsa conditionally AM_CONDITIONAL([HAVE_JACK], [ test "x$enable_jack" = "xyes" ]) +AM_CONDITIONAL([HAVE_ALSA], [ test "x$enable_alsa" = "xyes" ]) # fdk-aac-dabplus-zmq needs ZeroMQ AC_CHECK_LIB(zmq, zmq_init, , AC_MSG_ERROR(ZeroMQ libzmq is required)) @@ -94,7 +104,7 @@ echo echo "Features enabled:" enabled="" disabled="" -for feature in jack vlc +for feature in jack vlc alsa do eval var=\$enable_$feature AS_IF([test "x$var" = "xyes"], 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) { |