aboutsummaryrefslogtreecommitdiffstats
path: root/src/odr-audioenc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/odr-audioenc.cpp')
-rw-r--r--src/odr-audioenc.cpp68
1 files changed, 25 insertions, 43 deletions
diff --git a/src/odr-audioenc.cpp b/src/odr-audioenc.cpp
index c6887da..5b0facf 100644
--- a/src/odr-audioenc.cpp
+++ b/src/odr-audioenc.cpp
@@ -50,6 +50,7 @@
*/
#include "config.h"
+#include "PadInterface.h"
#include "AlsaInput.h"
#include "FileInput.h"
#include "JackInput.h"
@@ -121,7 +122,7 @@ static void usage(const char* name)
"artifacts.\n"
"\n"
"This encoder is able to insert PAD (DLS and MOT Slideshow)\n"
- "generated by ODR-PadEnc.\n"
+ "generated by ODR-PadEnc, and communicates using a UNIX socket.\n"
"\nUsage:\n"
"%s [INPUT SELECTION] [OPTION...]\n",
#if defined(GITVERSION)
@@ -200,16 +201,13 @@ static void usage(const char* name)
" add a delay (in milliseconds) to the timestamps carried in EDI\n"
" -k, --secret-key=FILE Enable ZMQ encryption with the given secret key.\n"
" -p, --pad=BYTES Enable PAD insertion and set PAD size in bytes.\n"
- " -P, --pad-fifo=FILENAME Set PAD data input fifo name"
- " (default: /tmp/pad.fifo).\n"
+ " -P, --pad-socket=IDENTIFIER Use the given identifier to communicate with ODR-PadEnc."
" -l, --level Show peak audio level indication.\n"
" -S, --stats=SOCKET_NAME Connect to the specified UNIX Datagram socket and send statistics.\n"
" This allows external tools to collect audio and drift compensation stats.\n"
" -s, --silence=TIMEOUT Abort encoding after TIMEOUT seconds of silence.\n"
" --version Show version and quit.\n"
"\n"
- "Only the tcp:// zeromq transport has been tested until now,\n"
- " but epgm://, pgm:// and ipc:// are also accepted\n"
);
}
@@ -469,8 +467,8 @@ public:
int measured_silence_ms = 0;
/* For MOT Slideshow and DLS insertion */
- const char* pad_fifo = "/tmp/pad.fifo";
- int pad_fd = -1;
+ string pad_ident = "";
+ PadInterface pad_intf;
int padlen = 0;
/* Encoder status, see the above STATUS macros */
@@ -557,7 +555,7 @@ int AudioEnc::run()
}
}
- if (padlen < 0) {
+ if (padlen < 0 or padlen > 255) {
fprintf(stderr, "Invalid PAD length specified\n");
return 1;
}
@@ -637,27 +635,11 @@ int AudioEnc::run()
edi_output.set_odr_version_tag(ss.str());
}
- if (padlen != 0) {
- int flags;
- if (mkfifo(pad_fifo, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH) != 0) {
- if (errno != EEXIST) {
- fprintf(stderr, "Can't create pad file: %d!\n", errno);
- return 1;
- }
- }
- pad_fd = open(pad_fifo, O_RDONLY | O_NONBLOCK);
- if (pad_fd == -1) {
- fprintf(stderr, "Can't open pad file!\n");
- return 1;
- }
- flags = fcntl(pad_fd, F_GETFL, 0);
- if (fcntl(pad_fd, F_SETFL, flags | O_NONBLOCK)) {
- fprintf(stderr, "Can't set non-blocking mode in pad file!\n");
- return 1;
- }
+ if (padlen != 0 and not pad_ident.empty()) {
+ pad_intf.open(pad_ident);
+ fprintf(stderr, "PAD socket opened\n");
}
-
vec_u8 input_buf;
if (selected_encoder == encoder_selection_t::fdk_dabplus) {
@@ -806,7 +788,7 @@ int AudioEnc::run()
break;
}
- unsigned char pad_buf[padlen + 1];
+ vector<uint8_t> pad_buf(padlen + 1);
if (restart_on_fault) {
fprintf(stderr, "Autorestart has been deprecated and will be removed in the future!\n");
@@ -822,18 +804,17 @@ int AudioEnc::run()
int calls = 0; // for checking
ssize_t read_bytes = 0;
do {
- // --------------- Read data from the PAD fifo
+ // --------------- Read data from the PAD socket
int calculated_padlen = 0;
if (padlen != 0) {
- ssize_t pad_ret = read(pad_fd, pad_buf, padlen + 1);
+ vector<uint8_t> pad_data = pad_intf.request(padlen);
- if ((pad_ret < 0 && errno == EAGAIN) || pad_ret == 0) {
- // If this condition passes, there is no data to be read
+ if (pad_data.empty()) {
+ /* no PAD available */
}
- else if (pad_ret == padlen + 1) {
- // Otherwise, you're good to go and buffer should contain "count" bytes.
- calculated_padlen = pad_buf[padlen];
+ else if (pad_data.size() == pad_buf.size()) {
+ calculated_padlen = pad_data[padlen];
if (calculated_padlen < 2) {
throw runtime_error("Invalid X-PAD length " + to_string(calculated_padlen));
@@ -844,14 +825,15 @@ int AudioEnc::run()
*/
if ( selected_encoder == encoder_selection_t::fdk_dabplus &&
calculated_padlen == 2 &&
- pad_buf[padlen - 2] == 0x00 &&
- pad_buf[padlen - 1] == 0x00 ) {
+ pad_data[padlen - 2] == 0x00 &&
+ pad_data[padlen - 1] == 0x00 ) {
calculated_padlen = 0;
}
+
+ copy(pad_data.begin(), pad_data.end(), pad_buf.begin());
}
else {
- // Some other error occurred during read.
- fprintf(stderr, "Unable to read from PAD!\n");
+ fprintf(stderr, "Incorrect PAD length received: %zu expected %d\n", pad_data.size(), padlen + 1);
break;
}
}
@@ -1072,7 +1054,7 @@ int AudioEnc::run()
int out_size, out_elem_size;
in_ptr[0] = input_buf.data();
- in_ptr[1] = pad_buf + (padlen - calculated_padlen); // offset due to unused PAD bytes
+ in_ptr[1] = pad_buf.data() + (padlen - calculated_padlen); // offset due to unused PAD bytes
in_size[0] = read_bytes;
in_size[1] = calculated_padlen;
in_elem_size[0] = BYTES_PER_SAMPLE;
@@ -1133,7 +1115,7 @@ int AudioEnc::run()
}
if (read_bytes) {
- numOutBytes = toolame_encode_frame(input_buffers, pad_buf, calculated_padlen, outbuf.data(), outbuf.size());
+ numOutBytes = toolame_encode_frame(input_buffers, pad_buf.data(), calculated_padlen, outbuf.data(), outbuf.size());
}
else {
numOutBytes = toolame_finish(outbuf.data(), outbuf.size());
@@ -1375,7 +1357,7 @@ int main(int argc, char *argv[])
{"jack", required_argument, 0, 'j'},
{"output", required_argument, 0, 'o'},
{"pad", required_argument, 0, 'p'},
- {"pad-fifo", required_argument, 0, 'P'},
+ {"pad-socket", required_argument, 0, 'P'},
{"rate", required_argument, 0, 'r'},
{"secret-key", required_argument, 0, 'k'},
{"silence", required_argument, 0, 's'},
@@ -1543,7 +1525,7 @@ int main(int argc, char *argv[])
audio_enc.padlen = std::stoi(optarg);
break;
case 'P':
- audio_enc.pad_fifo = optarg;
+ audio_enc.pad_ident = optarg;
break;
case 'r':
audio_enc.sample_rate = std::stoi(optarg);