diff options
| -rw-r--r-- | man/odr-audioenc.1 | 4 | ||||
| -rw-r--r-- | src/PadInterface.cpp | 26 | ||||
| -rw-r--r-- | src/PadInterface.h | 6 | ||||
| -rw-r--r-- | src/odr-audioenc.cpp | 4 | 
4 files changed, 34 insertions, 6 deletions
| diff --git a/man/odr-audioenc.1 b/man/odr-audioenc.1 index 9d9089d..e070b11 100644 --- a/man/odr-audioenc.1 +++ b/man/odr-audioenc.1 @@ -153,7 +153,9 @@ Before starting, run the given script, and only start if it returns 0.  Enable PAD insertion and set PAD size in bytes.  .TP  \fB\-P\fR, \fB\-\-pad\-socket\fR=\fI\,IDENTIFIER\/\fR -Use the given identifier to communicate with ODR\-PadEnc. +Use the given identifier or path to communicate with ODR\-PadEnc. +If it contains '/', it's treated as a full path, otherwise +it's an identifier and sockets are created in /tmp/.  .TP  \fB\-l\fR, \fB\-\-level\fR  Show peak audio level indication. 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 d456c89..98e9c34 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" | 
