1 #include "newpacket.hpp"
10 #include "timeparse.hpp"
12 unsigned image_seq
= 0;
13 char namebuffer
[4096];
16 #define MAXTIME 0xFFFFFFFFFFFFFFFFULL
18 struct packet
* old_packet
;
20 uint64_t* target_stamps
;
21 unsigned target_count
;
23 int in_range(uint64_t low
, uint64_t high
)
25 for(unsigned i
= 0; i
< target_count
; i
++)
26 if(target_stamps
[i
] >= low
&& target_stamps
[i
] < high
)
31 void handle_packet(struct packet
* p
)
36 if(old_packet
&& in_range(old_packet
->rp_timestamp
, MAXTIME
))
41 if(old_packet
&& in_range(old_packet
->rp_timestamp
, p
->rp_timestamp
))
45 if(do_it
&& old_packet
) {
47 image_frame
f(*old_packet
);
48 std::stringstream name
;
49 name
<< prefix
<< std::setfill('0') << std::setw(5) << image_seq
++ << ".png";
50 std::cerr
<< "Saving screenshot '" << name
.str() << "'." << std::endl
;
51 f
.save_png(name
.str());
52 } catch(std::exception
& e
) {
53 std::cerr
<< "Can't save screenshot: " << e
.what() << std::endl
;
61 void packet_loop(const char* name
)
64 read_channel
rc(name
);
65 while((p
= rc
.read()))
70 int main(int argc
, char** argv
)
72 const char* _prefix
= "screenshot-";
75 for(int i
= 1; i
< argc
; i
++) {
76 if(!strncmp(argv
[i
], "--input=", 8))
78 else if(!strncmp(argv
[i
], "--prefix=", 9))
80 else if(!strncmp(argv
[i
], "-", 1)) {
81 std::cerr
<< "Unknown option '" << argv
[i
] << "'." << std::endl
;
84 uint64_t stamp
= parse_timespec(argv
[i
]);
85 target_stamps
= (uint64_t*)realloc(target_stamps
, sizeof(uint64_t) * (target_count
+ 1));
86 target_stamps
[target_count
++] = stamp
;
90 if(!_input
|| !target_count
) {
91 std::cerr
<< "syntax: " << argv
[0] << " --input=<file> [--prefix=<prefix>] <timespec>..."
95 strcpy(prefix
, _prefix
);