diff options
-rw-r--r-- | utils/wbcap.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/utils/wbcap.cpp b/utils/wbcap.cpp index 38a8cc0..5a94a70 100644 --- a/utils/wbcap.cpp +++ b/utils/wbcap.cpp | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <poll.h> | 2 | #include <poll.h> |
3 | #include <unistd.h> | 3 | #include <unistd.h> |
4 | #include <algorithm> | 4 | #include <algorithm> |
5 | #include <fstream> | ||
5 | 6 | ||
6 | #include <kms++/kms++.h> | 7 | #include <kms++/kms++.h> |
7 | #include <kms++util/kms++util.h> | 8 | #include <kms++util/kms++util.h> |
@@ -56,7 +57,7 @@ public: | |||
56 | m_capdev.stream_off(); | 57 | m_capdev.stream_off(); |
57 | } | 58 | } |
58 | 59 | ||
59 | void Dequeue() | 60 | DumbFramebuffer* Dequeue() |
60 | { | 61 | { |
61 | auto fb = m_capdev.dequeue(); | 62 | auto fb = m_capdev.dequeue(); |
62 | 63 | ||
@@ -64,6 +65,8 @@ public: | |||
64 | s_wb_fbs.erase(iter); | 65 | s_wb_fbs.erase(iter); |
65 | 66 | ||
66 | s_ready_fbs.insert(s_ready_fbs.begin(), fb); | 67 | s_ready_fbs.insert(s_ready_fbs.begin(), fb); |
68 | |||
69 | return fb; | ||
67 | } | 70 | } |
68 | 71 | ||
69 | void Queue() | 72 | void Queue() |
@@ -248,7 +251,10 @@ static const char* usage_str = | |||
248 | "Options:\n" | 251 | "Options:\n" |
249 | " -s, --src=CONN Source connector\n" | 252 | " -s, --src=CONN Source connector\n" |
250 | " -d, --dst=CONN Destination connector\n" | 253 | " -d, --dst=CONN Destination connector\n" |
251 | " -f, --format=4CC Format" | 254 | " -m, --smode=MODE Source connector videomode\n" |
255 | " -M, --dmode=MODE Destination connector videomode\n" | ||
256 | " -f, --format=4CC Format\n" | ||
257 | " -w, --write Write captured frames to wbcap.raw file\n" | ||
252 | " -h, --help Print this help\n" | 258 | " -h, --help Print this help\n" |
253 | ; | 259 | ; |
254 | 260 | ||
@@ -259,6 +265,7 @@ int main(int argc, char** argv) | |||
259 | string dst_conn_name; | 265 | string dst_conn_name; |
260 | string dst_mode_name; | 266 | string dst_mode_name; |
261 | PixelFormat pixfmt = PixelFormat::XRGB8888; | 267 | PixelFormat pixfmt = PixelFormat::XRGB8888; |
268 | bool write_file = false; | ||
262 | 269 | ||
263 | OptionSet optionset = { | 270 | OptionSet optionset = { |
264 | Option("s|src=", [&](string s) | 271 | Option("s|src=", [&](string s) |
@@ -281,6 +288,10 @@ int main(int argc, char** argv) | |||
281 | { | 288 | { |
282 | pixfmt = FourCCToPixelFormat(s); | 289 | pixfmt = FourCCToPixelFormat(s); |
283 | }), | 290 | }), |
291 | Option("w|write", [&]() | ||
292 | { | ||
293 | write_file = true; | ||
294 | }), | ||
284 | Option("h|help", [&]() | 295 | Option("h|help", [&]() |
285 | { | 296 | { |
286 | puts(usage_str); | 297 | puts(usage_str); |
@@ -366,6 +377,13 @@ int main(int argc, char** argv) | |||
366 | fds[2].fd = card.fd(); | 377 | fds[2].fd = card.fd(); |
367 | fds[2].events = POLLIN; | 378 | fds[2].events = POLLIN; |
368 | 379 | ||
380 | uint32_t dst_frame_num = 0; | ||
381 | |||
382 | const string filename = "wbcap.raw"; | ||
383 | unique_ptr<ofstream> os; | ||
384 | if (write_file) | ||
385 | os = unique_ptr<ofstream>(new ofstream(filename, ofstream::binary)); | ||
386 | |||
369 | while (true) { | 387 | while (true) { |
370 | int r = poll(fds.data(), fds.size(), -1); | 388 | int r = poll(fds.data(), fds.size(), -1); |
371 | ASSERT(r > 0); | 389 | ASSERT(r > 0); |
@@ -376,7 +394,17 @@ int main(int argc, char** argv) | |||
376 | if (fds[1].revents) { | 394 | if (fds[1].revents) { |
377 | fds[1].revents = 0; | 395 | fds[1].revents = 0; |
378 | 396 | ||
379 | wb.Dequeue(); | 397 | DumbFramebuffer* fb = wb.Dequeue(); |
398 | |||
399 | if (write_file) { | ||
400 | printf("Writing frame %u to %s\n", dst_frame_num, filename.c_str()); | ||
401 | |||
402 | for (unsigned i = 0; i < fb->num_planes(); ++i) | ||
403 | os->write((char*)fb->map(i), fb->size(i)); | ||
404 | |||
405 | dst_frame_num++; | ||
406 | } | ||
407 | |||
380 | wbflipper.queue_next(); | 408 | wbflipper.queue_next(); |
381 | } | 409 | } |
382 | 410 | ||