diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/odr-padenc.cpp | 28 | ||||
| -rw-r--r-- | src/odr-padenc.h | 1 | ||||
| -rw-r--r-- | src/pad_common.cpp | 12 | ||||
| -rw-r--r-- | src/pad_interface.cpp | 24 | ||||
| -rw-r--r-- | src/pad_interface.h | 6 |
5 files changed, 57 insertions, 14 deletions
diff --git a/src/odr-padenc.cpp b/src/odr-padenc.cpp index 3d610bd..5862d17 100644 --- a/src/odr-padenc.cpp +++ b/src/odr-padenc.cpp @@ -61,7 +61,9 @@ static void usage(const char* name) { " -s, --sleep=DUR Wait DUR seconds between each slide. If set to 0, the next slide is inserted just after the previous one\n" " has been transmitted. This is useful e.g. for stations that transmit just a logo slide.\n" " Default: %d\n" - " -o, --output=IDENTIFIER Socket to communicate with audio encoder\n" + " -o, --output=IDENTIFIER Socket to communicate with audio encoder.\n" + " If IDENTIFIER contains '/', it's used as a full path.\n" + " Otherwise, /tmp/ is prepended for backward compatibility\n" " --dump-current-slide=F1 Write the slide currently being transmitted to the file F1\n" " --dump-completed-slide=F2 Once the slide is transmitted, move the file from F1 to F2\n" " -t, --dls=FILENAME FIFO or file to read DLS text from.\n" @@ -455,15 +457,22 @@ int PadEncoder::EncodeSlide() { } int PadEncoder::EncodeLabel() { - // skip insertion, if previous one not yet finished + // delay insertion, if previous one not yet finished if (pad_packetizer.QueueContainsDG(DLSEncoder::APPTYPE_START)) { - fprintf(stderr, "ODR-PadEnc Warning: skipping label insertion, as previous one still in transmission!\n"); + if(!label_warn_shown) { + fprintf(stderr, "ODR-PadEnc Warning: there is a label already in transmission, delaying until the previous one ends.\n"); + label_warn_shown = true; + } + return 0; } else { + if(label_warn_shown) { + fprintf(stderr, "ODR-PadEnc Previous label ended transmission, sending the new one.\n"); + label_warn_shown = false; + } dls_encoder.encodeLabel(options.dls_files[curr_dls_file], options.item_state_file, options.dl_params); + return 1; } - - return 0; } @@ -534,12 +543,13 @@ int PadEncoder::Encode(PadInterface& intf) { if (pad_timeline >= next_label_insertion) { // encode label - result = EncodeLabel(); - next_label_insertion += std::chrono::milliseconds(options.label_insertion); + int label_encode_result = 0; + label_encode_result = EncodeLabel(); + if(label_encode_result > 0) { + next_label_insertion += std::chrono::milliseconds(options.label_insertion); + } } } - if (result) - return result; // flush one PAD (considering X-PAD output interval) auto pad = pad_packetizer.GetNextPAD(xpad_interval_counter == 0); diff --git a/src/odr-padenc.h b/src/odr-padenc.h index c493d95..6a48516 100644 --- a/src/odr-padenc.h +++ b/src/odr-padenc.h @@ -82,6 +82,7 @@ protected: SLSEncoder sls_encoder; SlideStore slides; bool slides_success; + bool label_warn_shown; int curr_dls_file; steady_clock::time_point next_slide; steady_clock::time_point next_label; diff --git a/src/pad_common.cpp b/src/pad_common.cpp index 8ee2cd8..f8e769a 100644 --- a/src/pad_common.cpp +++ b/src/pad_common.cpp @@ -143,7 +143,9 @@ std::vector<uint8_t> PADPacketizer::GetNextPAD(bool output_xpad) { pad_t* pad = output_xpad ? GetPAD() : FlushPAD(); if (verbose >= 2) { - fprintf(stderr, "ODR-PadEnc writing PAD (%zu bytes):", pad->size()); + fprintf(stderr, "ODR-PadEnc writing %cPAD (%zu bytes):", + output_xpad ? 'X' : 'F', + pad->size()); for (size_t j = 0; j < pad->size(); j++) { const char sep = (j == (pad->size() - 1) || j == (pad->size() - 1 - FPAD_LEN)) ? '|' : ' '; fprintf(stderr, "%c%02X", sep , (*pad)[j]); @@ -227,6 +229,14 @@ bool PADPacketizer::AppendDG(DATA_GROUP* dg) { } else { AppendDGWithCI(dg); + /* + fprintf(stderr, "flush? %d %zu == %zu or %d: %zu + %zu > (%zu - %zu)\n", + used_cis == max_cis, + used_cis, max_cis, + SUBFIELD_LENS[0] + AddCINeededBytes() > (xpad_size_max - xpad_size), + SUBFIELD_LENS[0], AddCINeededBytes(), xpad_size_max, xpad_size); + */ + // if no further sub-fields could be added, PAD must be flushed if (used_cis == max_cis || SUBFIELD_LENS[0] + AddCINeededBytes() > (xpad_size_max - xpad_size)) return true; diff --git a/src/pad_interface.cpp b/src/pad_interface.cpp index 3db5308..26a04ab 100644 --- a/src/pad_interface.cpp +++ b/src/pad_interface.cpp @@ -47,7 +47,17 @@ void PadInterface::open(const std::string &pad_ident) struct sockaddr_un claddr; memset(&claddr, 0, sizeof(struct sockaddr_un)); claddr.sun_family = AF_UNIX; - snprintf(claddr.sun_path, sizeof(claddr.sun_path), "/tmp/%s.padenc", m_pad_ident.c_str()); + + size_t last_slash = m_pad_ident.find_last_of('/'); + if (last_slash != std::string::npos) { + // Full path provided, use as-is with .padenc suffix + std::string socket_dir = m_pad_ident.substr(0, last_slash); + std::string socket_base = m_pad_ident.substr(last_slash + 1); + snprintf(claddr.sun_path, sizeof(claddr.sun_path), "%s/%s.padenc", socket_dir.c_str(), socket_base.c_str()); + } else { + // Identifier only, use /tmp/ for backward compatibility + snprintf(claddr.sun_path, sizeof(claddr.sun_path), "/tmp/%s.padenc", m_pad_ident.c_str()); + } if (unlink(claddr.sun_path) == -1 and errno != ENOENT) { fprintf(stderr, "Unlinking of socket %s failed: %s\n", claddr.sun_path, strerror(errno)); } @@ -110,7 +120,17 @@ void PadInterface::send_pad_data(const uint8_t *data, size_t len) struct sockaddr_un claddr; memset(&claddr, 0, sizeof(struct sockaddr_un)); claddr.sun_family = AF_UNIX; - snprintf(claddr.sun_path, sizeof(claddr.sun_path), "/tmp/%s.audioenc", m_pad_ident.c_str()); + + size_t last_slash = m_pad_ident.find_last_of('/'); + if (last_slash != std::string::npos) { + // Full path provided, use as-is with .audioenc suffix + std::string socket_dir = m_pad_ident.substr(0, last_slash); + std::string socket_base = m_pad_ident.substr(last_slash + 1); + snprintf(claddr.sun_path, sizeof(claddr.sun_path), "%s/%s.audioenc", socket_dir.c_str(), socket_base.c_str()); + } else { + // Identifier only, use /tmp/ for backward compatibility + snprintf(claddr.sun_path, sizeof(claddr.sun_path), "/tmp/%s.audioenc", m_pad_ident.c_str()); + } vector<uint8_t> message(len + 1); message[0] = MESSAGE_PAD_DATA; diff --git a/src/pad_interface.h b/src/pad_interface.h index f0307bd..2803b5e 100644 --- a/src/pad_interface.h +++ b/src/pad_interface.h @@ -33,8 +33,10 @@ class PadInterface { public: - /*! Create a new PAD data interface that binds to /tmp/pad_ident.padenc and - * communicates with ODR-AudioEnc at /tmp/pad_ident.audioenc + /*! Create a new PAD data interface that binds to a socket and + * communicates with ODR-AudioEnc. If pad_ident contains '/', it's used as a full path. + * Otherwise, /tmp/ is prepended for backward compatibility. + * Sockets: pad_ident.padenc (this) and pad_ident.audioenc (ODR-AudioEnc) */ void open(const std::string &pad_ident); |
