aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorrmens <r.mens@me.com>2025-08-23 00:58:45 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2025-08-30 12:48:37 +0200
commitc4f0ba1c9c909f7c1ac697068197b681cd567beb (patch)
treed70e88d0592a4d702669f29a18b307d32e8645a6 /src
parent12ca282e72c4680be3bf7e92ac984be01b4821b9 (diff)
downloadODR-AudioEnc-c4f0ba1c9c909f7c1ac697068197b681cd567beb.tar.gz
ODR-AudioEnc-c4f0ba1c9c909f7c1ac697068197b681cd567beb.tar.bz2
ODR-AudioEnc-c4f0ba1c9c909f7c1ac697068197b681cd567beb.zip
feat: make pad path more flexible
Diffstat (limited to 'src')
-rw-r--r--src/PadInterface.cpp26
-rw-r--r--src/PadInterface.h6
-rw-r--r--src/odr-audioenc.cpp4
3 files changed, 31 insertions, 5 deletions
diff --git a/src/PadInterface.cpp b/src/PadInterface.cpp
index a8a129c..8269004 100644
--- a/src/PadInterface.cpp
+++ b/src/PadInterface.cpp
@@ -56,7 +56,18 @@ 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.audioenc", m_pad_ident.c_str());
+
+ // Check if pad_ident contains path separators - if so, treat as full path
+ size_t last_slash = m_pad_ident.find_last_of('/');
+ if (last_slash != std::string::npos) {
+ // It's a path - use directory and basename
+ 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 {
+ // It's just an identifier - use /tmp/ as before for backward compatibility
+ snprintf(claddr.sun_path, sizeof(claddr.sun_path), "/tmp/%s.audioenc", 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));
}
@@ -84,7 +95,18 @@ vector<uint8_t> PadInterface::request(uint8_t padlen)
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());
+
+ // Check if pad_ident contains path separators - if so, treat as full path
+ size_t last_slash = m_pad_ident.find_last_of('/');
+ if (last_slash != std::string::npos) {
+ // It's a path - use directory and basename
+ 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 {
+ // It's just an identifier - use /tmp/ as before for backward compatibility
+ snprintf(claddr.sun_path, sizeof(claddr.sun_path), "/tmp/%s.padenc", m_pad_ident.c_str());
+ }
ssize_t ret = ::sendto(m_sock, packet, sizeof(packet), 0, (struct sockaddr*)&claddr, sizeof(struct sockaddr_un));
if (ret == -1) {
diff --git a/src/PadInterface.h b/src/PadInterface.h
index 9787d06..8b8f68f 100644
--- a/src/PadInterface.h
+++ b/src/PadInterface.h
@@ -30,8 +30,10 @@
class PadInterface {
public:
- /*! Create a new PAD data interface that binds to /tmp/pad_ident.audioenc and
- * communicates with ODR-PadEnc at /tmp/pad_ident.padenc
+ /*! Create a new PAD data interface. If pad_ident contains path separators,
+ * it is treated as a full path (creates pad_ident.audioenc and communicates
+ * with pad_ident.padenc). Otherwise, it is treated as an identifier and
+ * binds to /tmp/pad_ident.audioenc and communicates with /tmp/pad_ident.padenc
*/
void open(const std::string &pad_ident);
diff --git a/src/odr-audioenc.cpp b/src/odr-audioenc.cpp
index 44fc694..de3843c 100644
--- a/src/odr-audioenc.cpp
+++ b/src/odr-audioenc.cpp
@@ -208,7 +208,9 @@ static void usage(const char* name)
" --startup-check=SCRIPT_PATH Before starting, run the given script, and only start if it returns 0.\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-socket=IDENTIFIER Use the given identifier to communicate with ODR-PadEnc.\n"
+ " -P, --pad-socket=IDENTIFIER Use the given identifier or path to communicate with ODR-PadEnc.\n"
+ " If it contains '/', it's treated as a full path, otherwise\n"
+ " it's an identifier and sockets are created in /tmp/.\n"
" -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"