Mir

Merge lp:~kdub/mir/mirscreencast-limited-capture into lp:mir

Proposed by Kevin DuBois
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 1416
Proposed branch: lp:~kdub/mir/mirscreencast-limited-capture
Merge into: lp:mir
Diff against target: 81 lines (+19/-5)
1 file modified
src/utils/screencast.cpp (+19/-5)
To merge this branch: bzr merge lp:~kdub/mir/mirscreencast-limited-capture
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alberto Aguirre (community) Approve
Alan Griffiths Approve
Review via email: mp+207314@code.launchpad.net

Commit message

mirscreencast: allow for a limited number of frames to be captured by setting -n <number> on the command line. Useful for taking a screenshot.

Description of the change

mirscreencast: allow for a limited number of frames to be captured by setting -n <number> on the command line. Useful for taking a screenshot.

$ mirscreencast -n 1
$ convert -depth 8 -size 768x1280 mir_screencast_768x1280.rgba out.png
will get you a png of the screencap

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

56 + number_of_captures = atoi(optarg);

Maybe replace with
std::stoi(std::string(optarg));

Then it will throw if it can't parse a number.

review: Needs Fixing
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

I agree that better handling would be appropriate - so stoi() or strtol() might be better. But I don't think atoi()s undefined behavior is dangerous.

review: Approve
Revision history for this message
Kevin DuBois (kdub) wrote :

> 56 + number_of_captures = atoi(optarg);
>
> Maybe replace with
> std::stoi(std::string(optarg));
>
> Then it will throw if it can't parse a number.

It should return 0 if it can't parse and then it would just exit. I don't mind fixing to print the help msg on a bad param though.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alberto Aguirre (albaguirre) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/utils/screencast.cpp'
2--- src/utils/screencast.cpp 2014-02-17 05:15:06 +0000
3+++ src/utils/screencast.cpp 2014-02-20 17:19:20 +0000
4@@ -114,6 +114,8 @@
5 std::cout << "Usage " << std::endl
6 << " -m <Mir server socket>" << std::endl
7 << " -o <Output id>" << std::endl
8+ << " -n <Number of frames to capture>" << std::endl
9+ << " default (-1) is to capture infinite frames" << std::endl
10 << " -h: this help text" << std::endl;
11 }
12
13@@ -198,7 +200,7 @@
14 };
15
16 void do_screencast(MirConnection* connection, MirScreencast* screencast,
17- uint32_t output_id)
18+ uint32_t output_id, int32_t number_of_captures)
19 {
20 static int const rgba_pixel_size{4};
21
22@@ -218,7 +220,7 @@
23 ss << (format == GL_BGRA_EXT ? ".bgra" : ".rgba");
24 std::ofstream video_file(ss.str());
25
26- while (running)
27+ while (running && (number_of_captures != 0))
28 {
29 read_pixels(format, frame_size, frame_data.data());
30
31@@ -231,6 +233,9 @@
32 egl_setup.swap_buffers();
33
34 write_out_future.wait();
35+
36+ if (number_of_captures > 0)
37+ number_of_captures--;
38 }
39 }
40
41@@ -243,14 +248,18 @@
42 opterr = 0;
43 char const* socket_file = nullptr;
44 uint32_t output_id = mir_display_output_id_invalid;
45+ int32_t number_of_captures = -1;
46
47 //avoid unused warning/error
48 tls_hack[0] = 0;
49
50- while ((arg = getopt (argc, argv, "hm:o:")) != -1)
51+ while ((arg = getopt (argc, argv, "hm:o:n:")) != -1)
52 {
53 switch (arg)
54 {
55+ case 'n':
56+ number_of_captures = std::stoi(std::string(optarg));
57+ break;
58 case 'm':
59 socket_file = optarg;
60 break;
61@@ -303,13 +312,18 @@
62 if (screencast == nullptr)
63 throw std::runtime_error("Failed to create screencast");
64
65- do_screencast(connection.get(), screencast.get(), output_id);
66+ do_screencast(connection.get(), screencast.get(), output_id, number_of_captures);
67
68 return EXIT_SUCCESS;
69 }
70+catch(std::invalid_argument const& e)
71+{
72+ std::cerr << "Invalid Argument" << std::endl;
73+ print_usage();
74+ return EXIT_FAILURE;
75+}
76 catch(std::exception const& e)
77 {
78 std::cerr << e.what() << std::endl;
79-
80 return EXIT_FAILURE;
81 }

Subscribers

People subscribed via source and target branches