Skip to content

Commit

Permalink
Add feature to specify the directory for FIFOs
Browse files Browse the repository at this point in the history
  • Loading branch information
xtne6f committed May 1, 2024
1 parent 1fefd20 commit bbc1ec3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tsmemseg - In-memory transport stream segmenter mainly for HLS/LL-HLS

Usage:

tsmemseg [-4][-i inittime][-t time][-p ptime][-a acc_timeout][-c cmd][-r readrate][-f fill_readrate][-s seg_num][-m max_kbytes] seg_name
tsmemseg [-4][-i inittime][-t time][-p ptime][-a acc_timeout][-c cmd][-r readrate][-f fill_readrate][-s seg_num][-m max_kbytes][-g dir] seg_name

-4
Convert to fragmented MP4.
Expand Down Expand Up @@ -34,6 +34,10 @@ tsmemseg [-4][-i inittime][-t time][-p ptime][-a acc_timeout][-c cmd][-r readrat
-m max_kbytes (kbytes), 32<=range<=32768, default=4096
Maximum size of each segment. If segment length exceeds this limit, the segment is forcibly cut whether on a key packet or not.

-g dir, default=""
Specify the directory for creating FIFOs. If not specified, created in "/tmp" with 0600 permission.
This option is ignored on Windows.

seg_name
Used for the name pattern of named-pipes/FIFOs used to access segments, or "-" (stdout).
If "-" is specified, simply prints stream to standard output. -a -c -r -f -s options are ignored.
Expand Down
25 changes: 21 additions & 4 deletions tsmemseg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#else
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <sys/types.h>
Expand Down Expand Up @@ -95,7 +96,7 @@ struct SEGMENT_PIPE_CONTEXT

struct SEGMENT_CONTEXT
{
char path[128];
char path[256];
SEGMENT_PIPE_CONTEXT pipes[2];
std::vector<uint8_t> buf;
std::vector<uint8_t> backBuf;
Expand Down Expand Up @@ -677,6 +678,9 @@ int main(int argc, char **argv)
int nextReadRatePerMille = 0;
size_t segNum = 8;
size_t segMaxBytes = 4096 * 1024;
#ifndef _WIN32
const char *fifoDir = "";
#endif
const char *destName = "";
CMp4Fragmenter mp4frag;

Expand All @@ -686,7 +690,7 @@ int main(int argc, char **argv)
c = argv[i][1];
}
if (c == 'h') {
fprintf(stderr, "Usage: tsmemseg [-4][-i inittime][-t time][-p ptime][-a acc_timeout][-c cmd][-r readrate][-f fill_readrate][-s seg_num][-m max_kbytes] seg_name\n");
fprintf(stderr, "Usage: tsmemseg [-4][-i inittime][-t time][-p ptime][-a acc_timeout][-c cmd][-r readrate][-f fill_readrate][-s seg_num][-m max_kbytes][-g dir] seg_name\n");
return 2;
}
bool invalid = false;
Expand Down Expand Up @@ -729,6 +733,12 @@ int main(int argc, char **argv)
segMaxBytes = static_cast<size_t>(strtol(argv[++i], nullptr, 10) * 1024);
invalid = segMaxBytes < 32 * 1024 || 32 * 1024 * 1024 < segMaxBytes;
}
else if (c == 'g') {
++i;
#ifndef _WIN32
fifoDir = argv[i];
#endif
}
}
else {
destName = argv[i];
Expand Down Expand Up @@ -851,8 +861,15 @@ int main(int argc, char **argv)
break;
}
#else
sprintf(seg.path, "/tmp/tsmemseg_%s%02d.fifo", destName, static_cast<int>(segments.size()));
if (mkfifo(seg.path, S_IRWXU) != 0) {
size_t dirLen = strlen(fifoDir);
if ((dirLen ? dirLen + (fifoDir[dirLen - 1] != '/' ? 1 : 0) : 5) + strlen(destName) + 16 >= sizeof(seg.path)) {
// path too long
break;
}
sprintf(seg.path, "%s%stsmemseg_%s%02d.fifo", dirLen ? fifoDir : "/tmp/",
dirLen && fifoDir[dirLen - 1] != '/' ? "/" : "",
destName, static_cast<int>(segments.size()));
if (mkfifo(seg.path, S_IRUSR + S_IWUSR + (dirLen ? S_IRGRP + S_IWGRP + S_IROTH + S_IWOTH : 0)) != 0) {
break;
}
#endif
Expand Down

0 comments on commit bbc1ec3

Please sign in to comment.