| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | |||
| 2 | #include <errno.h> | ||
| 3 | #include <getopt.h> | ||
| 4 | #include <inttypes.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <string.h> | ||
| 8 | |||
| 9 | #include <algorithm> | ||
| 10 | #include <list> | ||
| 11 | #include <string> | ||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | #include "fppversion.h" | ||
| 15 | #include "log.h" | ||
| 16 | |||
| 17 | #include "FSEQFile.h" | ||
| 18 | |||
| 19 | void HexDump(const char* title, const void* data, int len, FPPLoggerInstance& facility, int perLine = 16); | ||
| 20 | |||
| 21 | 3 | void usage(char* appname) { | |
| 22 | 3 | printf("Usage: %s [OPTIONS] FileName.fseq\n", appname); | |
| 23 | 3 | printf("\n"); | |
| 24 | 3 | printf(" Options:\n"); | |
| 25 | 3 | printf(" -V - Print version information\n"); | |
| 26 | 3 | printf(" -v - verbose\n"); | |
| 27 | 3 | printf(" -o OUTPUTFILE - Filename for Output FSEQ\n"); | |
| 28 | 3 | printf(" -m FSEQFILE - FSEQ to merge onto the input, ignoring 0\n"); | |
| 29 | 3 | printf(" -M[ FSEQFILE - FSEQ to merge onto the input, copy 0\n"); | |
| 30 | 3 | printf(" -f # - FSEQ Version\n"); | |
| 31 | 3 | printf(" -c (none|zstd|zlib) - Compession type\n"); | |
| 32 | 3 | printf(" -l # - Compression level (-99 for default)\n"); | |
| 33 | 3 | printf(" -r (#-# | #+#) - Channel Range. Use - to separate start/end channel\n"); | |
| 34 | 3 | printf(" Use + to separate start channel + num channels\n"); | |
| 35 | 3 | printf(" If used before first -m/-M argument, sets a sparse range of output\n"); | |
| 36 | 3 | printf(" If used after -m/-M argument, sets a range to read from last merged sequence.\n"); | |
| 37 | 3 | printf(" If used before -d argument, sets the range to dump.\n"); | |
| 38 | 3 | printf(" -n - No Sparse. -r will only read the range, but the resulting fseq is not sparse.\n"); | |
| 39 | 3 | printf(" -j - Output the fseq file metadata to json\n"); | |
| 40 | 3 | printf(" -d - Dump the fseq data to stdout in human-readable format\n"); | |
| 41 | 3 | printf(" -h - This help output\n"); | |
| 42 | 3 | } | |
| 43 | const char* outputFilename = nullptr; | ||
| 44 | |||
| 45 | class MergeFSEQ { | ||
| 46 | public: | ||
| 47 | 6 | MergeFSEQ(const std::string& f, bool cz) : | |
| 48 | 6 | filename(f), | |
| 49 | 6 | copyZero(cz) {} | |
| 50 | |||
| 51 | std::string filename; | ||
| 52 | std::vector<std::pair<uint32_t, uint32_t>> ranges; | ||
| 53 | bool copyZero = false; | ||
| 54 | FSEQFile* srcFile = nullptr; | ||
| 55 | }; | ||
| 56 | |||
| 57 | static std::list<MergeFSEQ> mergeFseqs; | ||
| 58 | static int fseqMajVersion = 2; | ||
| 59 | static int fseqMinVersion = 0; | ||
| 60 | static int compressionLevel = -99; | ||
| 61 | static bool verbose = false; | ||
| 62 | static std::vector<std::pair<uint32_t, uint32_t>> ranges; | ||
| 63 | static bool sparse = true; | ||
| 64 | static bool json = false; | ||
| 65 | static bool dump = false; | ||
| 66 | static V2FSEQFile::CompressionType compressionType = V2FSEQFile::CompressionType::zstd; | ||
| 67 | |||
| 68 | // Channel buffers here are sized to the channel space the FSEQ library writes | ||
| 69 | // (MAX_CHANNEL_SPACE in FSEQFile.cpp, == FPPD_MAX_CHANNELS). Channels past it | ||
| 70 | // are dropped on read and on write, so say so rather than silently producing a | ||
| 71 | // shorter file or dump. | ||
| 72 | static constexpr uint32_t CHANNEL_SPACE = 8192 * 1024; | ||
| 73 | |||
| 74 | 39 | static void warnIfBeyondChannelSpace(const std::vector<std::pair<uint32_t, uint32_t>>& rngs, uint32_t maxChannel) { | |
| 75 | 39 | uint64_t wanted = 0; | |
| 76 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 39 times.
|
80 | for (auto& r : rngs) { |
| 77 | 41 | wanted = std::max(wanted, (uint64_t)r.first + r.second); | |
| 78 | } | ||
| 79 | 39 | wanted = std::min(wanted, (uint64_t)maxChannel); | |
| 80 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 38 times.
|
39 | if (wanted > CHANNEL_SPACE) { |
| 81 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printf("Warning: only the first %u channels are used; channels %u-%" PRIu64 " are dropped.\n", |
| 82 | CHANNEL_SPACE, CHANNEL_SPACE + 1, wanted); | ||
| 83 | } | ||
| 84 | 39 | } | |
| 85 | |||
| 86 | 13 | static bool parseRanges(std::vector<std::pair<uint32_t, uint32_t>>& ranges, char* rng) { | |
| 87 | 13 | char* p = rng; | |
| 88 | 13 | errno = 0; | |
| 89 | 13 | long start = strtol(p, &p, 10); | |
| 90 |
4/8✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 13 times.
|
13 | if (p == rng || errno == ERANGE || start < 1 || (uint64_t)start > UINT32_MAX) { |
| 91 | ✗ | return false; | |
| 92 | } | ||
| 93 | |||
| 94 | // The CLI documents exactly two forms: start-end and start+count. Only | ||
| 95 | // skip a separator we actually saw: advancing unconditionally walked past | ||
| 96 | // the NUL of a bare number and made the next strtol() read out of bounds. | ||
| 97 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
13 | if (*p != '-' && *p != '+') { |
| 98 | ✗ | return false; | |
| 99 | } | ||
| 100 | 13 | char separator = *p++; | |
| 101 | |||
| 102 | 13 | char* numberStart = p; | |
| 103 | 13 | errno = 0; | |
| 104 | 13 | long end = strtol(p, &p, 10); | |
| 105 |
4/8✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 13 times.
|
13 | if (p == numberStart || errno == ERANGE || end < 1 || (uint64_t)end > UINT32_MAX) { |
| 106 | ✗ | return false; | |
| 107 | } | ||
| 108 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
|
13 | while (*p == ' ' || *p == '\t') { |
| 109 | ✗ | p++; | |
| 110 | } | ||
| 111 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (*p != '\0') { |
| 112 | ✗ | return false; | |
| 113 | } | ||
| 114 | |||
| 115 | 13 | uint32_t first = (uint32_t)(start - 1); | |
| 116 | uint64_t count; | ||
| 117 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5 times.
|
13 | if (separator == '-') { |
| 118 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (end < start) { |
| 119 | ✗ | return false; | |
| 120 | } | ||
| 121 | 8 | count = (uint64_t)end - (uint64_t)start + 1; | |
| 122 | } else { | ||
| 123 | 5 | count = (uint64_t)end; | |
| 124 | } | ||
| 125 |
2/4✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
|
13 | if (count == 0 || count > UINT32_MAX) { |
| 126 | ✗ | return false; | |
| 127 | } | ||
| 128 | |||
| 129 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | ranges.emplace_back(first, (uint32_t)count); |
| 130 | 13 | return true; | |
| 131 | } | ||
| 132 | |||
| 133 | 69 | int parseArguments(int argc, char** argv) { | |
| 134 | 69 | char* s = NULL; | |
| 135 | int c; | ||
| 136 | |||
| 137 | 69 | int this_option_optind = optind; | |
| 138 | while (1) { | ||
| 139 |
1/2✓ Branch 0 taken 203 times.
✗ Branch 1 not taken.
|
203 | this_option_optind = optind ? optind : 1; |
| 140 | 203 | int option_index = 0; | |
| 141 | static struct option long_options[] = { | ||
| 142 | { "help", no_argument, 0, 'h' }, | ||
| 143 | { "output", required_argument, 0, 'o' }, | ||
| 144 | { 0, 0, 0, 0 } | ||
| 145 | }; | ||
| 146 | |||
| 147 | 203 | c = getopt_long(argc, argv, "c:l:o:f:r:m:M:hdjVvn", long_options, &option_index); | |
| 148 |
2/2✓ Branch 0 taken 65 times.
✓ Branch 1 taken 138 times.
|
203 | if (c == -1) { |
| 149 | 65 | break; | |
| 150 | } | ||
| 151 | |||
| 152 |
14/14✓ Branch 0 taken 13 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 36 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 12 times.
✓ Branch 7 taken 38 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 3 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
|
138 | switch (c) { |
| 153 | 13 | case 'r': { | |
| 154 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 3 times.
|
13 | auto& rangeList = mergeFseqs.empty() ? ranges : mergeFseqs.back().ranges; |
| 155 |
2/4✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
|
13 | if (!parseRanges(rangeList, optarg)) { |
| 156 | ✗ | printf("Invalid channel range '%s' (expected #-# or #+#)\n", optarg); | |
| 157 | ✗ | exit(EXIT_FAILURE); | |
| 158 | } | ||
| 159 | 13 | break; | |
| 160 | } | ||
| 161 | 21 | case 'j': | |
| 162 | 21 | json = true; | |
| 163 | 21 | break; | |
| 164 | 4 | case 'd': | |
| 165 | 4 | dump = true; | |
| 166 | 4 | break; | |
| 167 | 1 | case 'v': | |
| 168 | 1 | verbose = true; | |
| 169 | 1 | break; | |
| 170 | 36 | case 'c': | |
| 171 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 17 times.
|
36 | if (strcmp(optarg, "none") == 0) { |
| 172 | 19 | compressionType = V2FSEQFile::CompressionType::none; | |
| 173 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 14 times.
|
17 | } else if (strcmp(optarg, "zlib") == 0) { |
| 174 | 3 | compressionType = V2FSEQFile::CompressionType::zlib; | |
| 175 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 1 times.
|
14 | } else if (strcmp(optarg, "zstd") == 0) { |
| 176 | 13 | compressionType = V2FSEQFile::CompressionType::zstd; | |
| 177 | } else { | ||
| 178 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printf("Unknown compression type: %s\n", optarg); |
| 179 | 1 | exit(EXIT_FAILURE); | |
| 180 | } | ||
| 181 | 35 | break; | |
| 182 | 2 | case 'l': | |
| 183 | 2 | compressionLevel = strtol(optarg, NULL, 10); | |
| 184 | 2 | break; | |
| 185 | 12 | case 'f': { | |
| 186 | 12 | char* next = nullptr; | |
| 187 | 12 | fseqMajVersion = strtol(optarg, &next, 10); | |
| 188 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
|
12 | if (*next == '.') { |
| 189 | 3 | next++; | |
| 190 | 3 | fseqMinVersion = strtol(next, &next, 10); | |
| 191 | } | ||
| 192 | 12 | } break; | |
| 193 | 38 | case 'o': | |
| 194 | 38 | outputFilename = optarg; | |
| 195 | 38 | break; | |
| 196 | 3 | case 'm': | |
| 197 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | mergeFseqs.push_back(MergeFSEQ(optarg, false)); |
| 198 | 3 | break; | |
| 199 | 3 | case 'M': | |
| 200 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | mergeFseqs.push_back(MergeFSEQ(optarg, true)); |
| 201 | 3 | break; | |
| 202 | 2 | case 'n': | |
| 203 | 2 | sparse = false; | |
| 204 | 2 | break; | |
| 205 | 1 | case 'V': | |
| 206 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printVersionInfo(); |
| 207 | 1 | exit(0); | |
| 208 | 1 | case 'h': | |
| 209 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | usage(argv[0]); |
| 210 | 1 | exit(EXIT_SUCCESS); | |
| 211 | 1 | default: | |
| 212 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | usage(argv[0]); |
| 213 | 1 | exit(EXIT_FAILURE); | |
| 214 | } | ||
| 215 | 134 | } | |
| 216 | 65 | return this_option_optind; | |
| 217 | } | ||
| 218 | |||
| 219 | 40 | static std::string escape(const std::string& data) { | |
| 220 | 40 | std::string out; | |
| 221 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | out.reserve(data.size() + 16); |
| 222 |
2/2✓ Branch 0 taken 429 times.
✓ Branch 1 taken 40 times.
|
469 | for (char c : data) { |
| 223 | // Keep the existing \" and \\ escaping byte-identical; additionally | ||
| 224 | // escape C0 controls so filenames with newline etc. stay valid JSON. | ||
| 225 | // Header values with controls never reach here (binary placeholder), | ||
| 226 | // but baseName has no such gate. | ||
| 227 |
4/7✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 424 times.
|
429 | switch (c) { |
| 228 | 3 | case '"': | |
| 229 | case '\\': | ||
| 230 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | out.push_back('\\'); |
| 231 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | out.push_back(c); |
| 232 | 3 | break; | |
| 233 | ✗ | case '\b': | |
| 234 | ✗ | out.append("\\b"); | |
| 235 | ✗ | break; | |
| 236 | ✗ | case '\f': | |
| 237 | ✗ | out.append("\\f"); | |
| 238 | ✗ | break; | |
| 239 | 1 | case '\n': | |
| 240 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | out.append("\\n"); |
| 241 | 1 | break; | |
| 242 | ✗ | case '\r': | |
| 243 | ✗ | out.append("\\r"); | |
| 244 | ✗ | break; | |
| 245 | 1 | case '\t': | |
| 246 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | out.append("\\t"); |
| 247 | 1 | break; | |
| 248 | 424 | default: | |
| 249 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 424 times.
|
424 | if ((unsigned char)c < 32) { |
| 250 | char u[7]; | ||
| 251 | ✗ | snprintf(u, sizeof(u), "\\u%04x", (unsigned char)c); | |
| 252 | ✗ | out.append(u); | |
| 253 | } else { | ||
| 254 |
1/2✓ Branch 0 taken 424 times.
✗ Branch 1 not taken.
|
424 | out.push_back(c); |
| 255 | } | ||
| 256 | 424 | break; | |
| 257 | } | ||
| 258 | } | ||
| 259 | 40 | return out; | |
| 260 | ✗ | } | |
| 261 | ✗ | std::string getFPPDDir(const std::string& path) { | |
| 262 | ✗ | return "/tmp"; | |
| 263 | } | ||
| 264 | 69 | int main(int argc, char* argv[]) { | |
| 265 | 69 | int idx = parseArguments(argc, argv); | |
| 266 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 64 times.
|
65 | if (idx >= argc) { |
| 267 | 1 | usage(argv[0]); | |
| 268 | 1 | return 1; | |
| 269 | } | ||
| 270 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63 times.
|
64 | if (verbose) { |
| 271 | 1 | SetLogLevel("debug"); | |
| 272 | } else { | ||
| 273 | 63 | SetLogFile("stderr", false); | |
| 274 | } | ||
| 275 |
2/4✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
|
64 | FSEQFile* src = FSEQFile::openFSEQFile(argv[idx]); |
| 276 |
2/2✓ Branch 0 taken 62 times.
✓ Branch 1 taken 2 times.
|
64 | if (src) { |
| 277 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 42 times.
|
62 | if (json) { |
| 278 | /* | ||
| 279 | getNumFrames() const { return m_seqNumFrames; } | ||
| 280 | int getStepTime() const { return m_seqStepTime; } | ||
| 281 | uint32_t getChannelCount() const { return m_seqChannelCount; } | ||
| 282 | uint64_t getUniqueId() const { return m_uniqueId; } | ||
| 283 | const std::string& getFilename() const { return m_filename; } | ||
| 284 | */ | ||
| 285 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | std::string fullName = src->getFilename(); |
| 286 | 20 | size_t slash = fullName.find_last_of('/'); | |
| 287 |
2/6✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
20 | std::string baseName = (slash == std::string::npos) ? fullName : fullName.substr(slash + 1); |
| 288 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
60 | printf("{\"Name\": \"%s\", \"Version\": \"%d.%d\", \"ID\": \"%" PRIu64 "\", \"StepTime\": %d, \"NumFrames\": %d, \"MaxChannel\": %d, \"ChannelCount\": %d", |
| 289 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
40 | escape(baseName).c_str(), |
| 290 | src->getVersionMajor(), src->getVersionMinor(), | ||
| 291 | src->getUniqueId(), | ||
| 292 | src->getStepTime(), | ||
| 293 | src->getNumFrames(), | ||
| 294 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | src->getMaxChannel(), |
| 295 | src->getChannelCount()); | ||
| 296 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
|
20 | if (!src->getVariableHeaders().empty()) { |
| 297 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | printf(", \"variableHeaders\": {"); |
| 298 | 16 | bool first = true; | |
| 299 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 16 times.
|
36 | for (auto& head : src->getVariableHeaders()) { |
| 300 |
4/8✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
|
20 | if (head.code[0] > 32 && head.code[0] <= 127 && head.code[1] > 32 && head.code[1] <= 127) { |
| 301 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | const auto& vd = head.getData(); |
| 302 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (vd.empty()) { |
| 303 | ✗ | continue; | |
| 304 | } | ||
| 305 | 20 | const char* raw = (const char*)vd.data(); | |
| 306 | 20 | size_t vlen = strnlen(raw, vd.size()); | |
| 307 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | std::string vs(raw, vlen); |
| 308 | // Gate on the truncated view that is actually emitted: | ||
| 309 | // bytes past the first NUL are never printed, so they | ||
| 310 | // must not flip a truncated-ASCII value to binary. | ||
| 311 | 20 | bool allAscii = true; | |
| 312 |
2/2✓ Branch 0 taken 155 times.
✓ Branch 1 taken 20 times.
|
175 | for (unsigned char b : vs) { |
| 313 |
2/4✓ Branch 0 taken 155 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 155 times.
|
155 | if (b < 32 || b > 127) { |
| 314 | ✗ | allAscii = false; | |
| 315 | ✗ | break; | |
| 316 | } | ||
| 317 | } | ||
| 318 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if (allAscii) { |
| 319 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 16 times.
|
20 | if (!first) { |
| 320 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | printf(", "); |
| 321 | } else { | ||
| 322 | 16 | first = false; | |
| 323 | } | ||
| 324 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | printf("\"%c%c\": \"%s\"", head.code[0], head.code[1], escape(vs).c_str()); |
| 325 | } else { | ||
| 326 | ✗ | if (!first) { | |
| 327 | ✗ | printf(", "); | |
| 328 | } else { | ||
| 329 | ✗ | first = false; | |
| 330 | } | ||
| 331 | ✗ | printf("\"%c%c\": \"<binary data of length %d>\"", head.code[0], head.code[1], (int)head.getDataLength()); | |
| 332 | } | ||
| 333 | 20 | } | |
| 334 | } | ||
| 335 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | printf("}"); |
| 336 | } | ||
| 337 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1 times.
|
20 | if (src->getVersionMajor() >= 2) { |
| 338 | 19 | V2FSEQFile* f = (V2FSEQFile*)src; | |
| 339 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 14 times.
|
19 | if (!f->m_sparseRanges.empty()) { |
| 340 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | printf(", \"Ranges\": ["); |
| 341 | 5 | int first = true; | |
| 342 |
2/2✓ Branch 0 taken 859 times.
✓ Branch 1 taken 5 times.
|
864 | for (auto& a : f->m_sparseRanges) { |
| 343 |
2/2✓ Branch 0 taken 854 times.
✓ Branch 1 taken 5 times.
|
859 | if (!first) { |
| 344 |
1/2✓ Branch 0 taken 854 times.
✗ Branch 1 not taken.
|
854 | printf(","); |
| 345 | } | ||
| 346 | 859 | first = false; | |
| 347 |
1/2✓ Branch 0 taken 859 times.
✗ Branch 1 not taken.
|
859 | printf("{\"Start\": %d, \"Length\": %d}", a.first, a.second); |
| 348 | } | ||
| 349 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | printf("]"); |
| 350 | } | ||
| 351 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | printf(", \"CompressionType\": %d", (int)f->m_compressionType); |
| 352 |
2/4✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
|
19 | printf(", \"CompressionTypeString\": \"%s\"", f->CompressionTypeString().c_str()); |
| 353 | } | ||
| 354 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | printf("}\n"); |
| 355 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 38 times.
|
62 | } else if (dump) { |
| 356 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if (ranges.empty()) { |
| 357 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printf("No channel range specified\n"); |
| 358 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | delete src; |
| 359 | 1 | return 1; | |
| 360 | } | ||
| 361 | |||
| 362 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | src->setReadPattern(FSEQFile::ReadPattern::Bulk); |
| 363 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | src->prepareRead(ranges); |
| 364 | |||
| 365 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | warnIfBeyondChannelSpace(ranges, src->getMaxChannel()); |
| 366 | |||
| 367 | char title[50]; | ||
| 368 | 3 | uint8_t* data = (uint8_t*)malloc(CHANNEL_SPACE); | |
| 369 |
2/2✓ Branch 0 taken 3041 times.
✓ Branch 1 taken 3 times.
|
3044 | for (int x = 0; x < src->getNumFrames(); x++) { |
| 370 |
1/2✓ Branch 0 taken 3041 times.
✗ Branch 1 not taken.
|
3041 | FSEQFile::FrameData* fdata = src->getFrame(x); |
| 371 |
1/2✓ Branch 0 taken 3041 times.
✗ Branch 1 not taken.
|
3041 | fdata->readFrame(data, CHANNEL_SPACE); |
| 372 |
1/2✓ Branch 0 taken 3041 times.
✗ Branch 1 not taken.
|
3041 | delete fdata; |
| 373 | |||
| 374 |
2/2✓ Branch 0 taken 3041 times.
✓ Branch 1 taken 3041 times.
|
6082 | for (auto& r : ranges) { |
| 375 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3041 times.
|
3041 | if ((uint64_t)r.first >= CHANNEL_SPACE) { |
| 376 | ✗ | continue; | |
| 377 | } | ||
| 378 | 3041 | uint64_t len = r.second; | |
| 379 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 3021 times.
|
3041 | if ((uint64_t)r.first + len > CHANNEL_SPACE) { |
| 380 | 20 | len = CHANNEL_SPACE - r.first; | |
| 381 | } | ||
| 382 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3041 times.
|
3041 | uint64_t end = len == 0 ? r.first : (uint64_t)r.first + len - 1; |
| 383 | 3041 | snprintf(title, 50, "Frame: %d, Range: %d-%d", x, r.first, (int)end); | |
| 384 |
1/2✓ Branch 0 taken 3041 times.
✗ Branch 1 not taken.
|
3041 | HexDump(title, data + r.first, (int)len, VB_SEQUENCE, 16); |
| 385 | } | ||
| 386 | } | ||
| 387 | 3 | free(data); | |
| 388 | } else { | ||
| 389 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 38 times.
|
44 | for (auto& f : mergeFseqs) { |
| 390 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | FSEQFile* src = FSEQFile::openFSEQFile(f.filename); |
| 391 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (src) { |
| 392 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | src->setReadPattern(FSEQFile::ReadPattern::Bulk); |
| 393 | 6 | f.srcFile = src; | |
| 394 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (f.ranges.empty()) { |
| 395 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | f.ranges.push_back(std::pair<uint32_t, uint32_t>(0, CHANNEL_SPACE)); |
| 396 | } | ||
| 397 | } | ||
| 398 | } | ||
| 399 | |||
| 400 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 37 times.
|
38 | if (outputFilename == nullptr) { |
| 401 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (!verbose) { |
| 402 | 1 | printf("No output file defined!\n"); | |
| 403 | 1 | printf("Use -v to enable verbose output printing for file information.\n"); | |
| 404 | } | ||
| 405 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | delete src; |
| 406 | 1 | return 0; | |
| 407 | } | ||
| 408 | |||
| 409 |
2/4✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
|
74 | FSEQFile* dest = FSEQFile::createFSEQFile(outputFilename, |
| 410 | fseqMajVersion, | ||
| 411 | compressionType, | ||
| 412 | compressionLevel); | ||
| 413 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 36 times.
|
37 | if (dest == nullptr) { |
| 414 | 1 | printf("Failed to create FSEQ file (returned nullptr)!\n"); | |
| 415 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | delete src; |
| 416 | 1 | return 1; | |
| 417 | } | ||
| 418 | 36 | dest->enableMinorVersionFeatures(fseqMinVersion); | |
| 419 | |||
| 420 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 5 times.
|
36 | if (ranges.empty()) { |
| 421 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | ranges.push_back(std::pair<uint32_t, uint32_t>(0, 999999999)); |
| 422 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 2 times.
|
5 | } else if (fseqMajVersion == 2 && sparse) { |
| 423 | 3 | V2FSEQFile* f = (V2FSEQFile*)dest; | |
| 424 | 3 | f->m_sparseRanges = ranges; | |
| 425 | } | ||
| 426 | 36 | warnIfBeyondChannelSpace(ranges, src->getMaxChannel()); | |
| 427 | 36 | src->setReadPattern(FSEQFile::ReadPattern::Bulk); | |
| 428 | 36 | src->prepareRead(ranges); | |
| 429 | |||
| 430 | 36 | dest->initializeFromFSEQ(*src); | |
| 431 | 36 | dest->writeHeader(); | |
| 432 | |||
| 433 | 36 | uint8_t* data = (uint8_t*)calloc(1, CHANNEL_SPACE); | |
| 434 | 36 | uint8_t* mergedata = (uint8_t*)malloc(CHANNEL_SPACE); | |
| 435 | 36 | memset(mergedata, 0, CHANNEL_SPACE); | |
| 436 |
2/2✓ Branch 0 taken 104216 times.
✓ Branch 1 taken 36 times.
|
104252 | for (int x = 0; x < src->getNumFrames(); x++) { |
| 437 | 104216 | FSEQFile::FrameData* fdata = src->getFrame(x); | |
| 438 | 104216 | fdata->readFrame(data, CHANNEL_SPACE); | |
| 439 |
1/2✓ Branch 0 taken 104216 times.
✗ Branch 1 not taken.
|
104216 | delete fdata; |
| 440 | |||
| 441 |
2/2✓ Branch 0 taken 3101 times.
✓ Branch 1 taken 104216 times.
|
107317 | for (auto& m : mergeFseqs) { |
| 442 |
1/2✓ Branch 0 taken 3101 times.
✗ Branch 1 not taken.
|
3101 | if (m.srcFile) { |
| 443 |
1/2✓ Branch 0 taken 3101 times.
✗ Branch 1 not taken.
|
3101 | FSEQFile::FrameData* fdata = m.srcFile->getFrame(x); |
| 444 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 3091 times.
|
3101 | if (!fdata) { |
| 445 | 10 | continue; // past the end of a shorter merge file | |
| 446 | } | ||
| 447 |
1/2✓ Branch 0 taken 3091 times.
✗ Branch 1 not taken.
|
3091 | fdata->readFrame(mergedata, CHANNEL_SPACE); |
| 448 |
1/2✓ Branch 0 taken 3091 times.
✗ Branch 1 not taken.
|
3091 | delete fdata; |
| 449 |
2/2✓ Branch 0 taken 3091 times.
✓ Branch 1 taken 3091 times.
|
6182 | for (auto& r : m.ranges) { |
| 450 | // Merge ranges come from the CLI, but never trust an | ||
| 451 | // index past the buffer: stop instead of corrupting heap. | ||
| 452 |
4/4✓ Branch 0 taken 422503704 times.
✓ Branch 1 taken 3071 times.
✓ Branch 2 taken 422503684 times.
✓ Branch 3 taken 20 times.
|
422506775 | for (uint64_t y = 0, idx = r.first; y < r.second && idx < CHANNEL_SPACE; ++y, ++idx) { |
| 453 |
4/4✓ Branch 0 taken 419430180 times.
✓ Branch 1 taken 3073504 times.
✓ Branch 2 taken 167772180 times.
✓ Branch 3 taken 251658000 times.
|
422503684 | if (mergedata[idx] || m.copyZero) { |
| 454 | 170845684 | data[idx] = mergedata[idx]; | |
| 455 | 170845684 | mergedata[idx] = 0; | |
| 456 | } | ||
| 457 | } | ||
| 458 | } | ||
| 459 | } | ||
| 460 | } | ||
| 461 | 104216 | dest->addFrame(x, data); | |
| 462 | } | ||
| 463 | 36 | free(data); | |
| 464 | 36 | free(mergedata); | |
| 465 | 36 | dest->finalize(); | |
| 466 | |||
| 467 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | if (!strcmp(outputFilename, "-memory-")) { |
| 468 | ✗ | printf("size: %d\n", (int)dest->getMemoryBuffer().size()); | |
| 469 | } | ||
| 470 | |||
| 471 |
1/2✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
|
36 | delete dest; |
| 472 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 36 times.
|
42 | for (auto& a : mergeFseqs) { |
| 473 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (a.srcFile) { |
| 474 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | delete a.srcFile; |
| 475 | } | ||
| 476 | } | ||
| 477 | } | ||
| 478 |
1/2✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
|
59 | delete src; |
| 479 | } | ||
| 480 | |||
| 481 | 61 | return 0; | |
| 482 | } | ||
| 483 |