Allow size-specific resizers
[jpcrr.git] / streamtools / demuxdump.cpp
blobb8f9e7bf7559e0e83d5cfa0e8c3f5a79a69cce78
1 #include "newpacket.hpp"
2 #include <iostream>
3 #include <sstream>
4 #include <cstdio>
5 #include <cstring>
6 #include <stdexcept>
7 #include <algorithm>
9 int main(int argc, char** argv)
11 if(argc != 4) {
12 std::cerr << "syntax: demuxdump.exe <input> <channel> <output>" << std::endl;
13 exit(1);
16 read_channel rchan(argv[1]);
17 uint32_t pchan = rchan.number_for_channel(argv[2]);
18 write_channel wchan(argv[3]);
20 packet* p;
21 bool segtable_present = false;
22 uint16_t lasttype = 65535;
23 uint64_t lasttime = 0;
24 while((p = rchan.read())) {
25 lasttime = p->rp_timestamp;
26 if(p->rp_channel_perm == pchan) {
27 if(!segtable_present || lasttype != p->rp_major) {
28 std::vector<struct channel> channels;
29 channels.resize(2);
30 channels[0].c_channel = 0;
31 channels[0].c_type = lasttype = p->rp_major;
32 channels[0].c_channel_name = p->rp_channel_name;
33 channels[1].c_channel = 1;
34 channels[1].c_type = 3;
35 channels[1].c_channel_name = "<DUMMY>";
36 wchan.start_segment(channels);
37 segtable_present = true;
39 p->rp_channel = 0;
40 wchan.write(*p);
42 delete p;
44 struct packet p2;
45 p2.rp_channel = 1;
46 p2.rp_timestamp = lasttime;
47 p2.rp_minor = 0;
48 wchan.write(p2);