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
=== modified file 'src/utils/screencast.cpp'
--- src/utils/screencast.cpp 2014-02-17 05:15:06 +0000
+++ src/utils/screencast.cpp 2014-02-20 17:19:20 +0000
@@ -114,6 +114,8 @@
114 std::cout << "Usage " << std::endl114 std::cout << "Usage " << std::endl
115 << " -m <Mir server socket>" << std::endl115 << " -m <Mir server socket>" << std::endl
116 << " -o <Output id>" << std::endl116 << " -o <Output id>" << std::endl
117 << " -n <Number of frames to capture>" << std::endl
118 << " default (-1) is to capture infinite frames" << std::endl
117 << " -h: this help text" << std::endl;119 << " -h: this help text" << std::endl;
118}120}
119121
@@ -198,7 +200,7 @@
198};200};
199201
200void do_screencast(MirConnection* connection, MirScreencast* screencast,202void do_screencast(MirConnection* connection, MirScreencast* screencast,
201 uint32_t output_id)203 uint32_t output_id, int32_t number_of_captures)
202{204{
203 static int const rgba_pixel_size{4};205 static int const rgba_pixel_size{4};
204206
@@ -218,7 +220,7 @@
218 ss << (format == GL_BGRA_EXT ? ".bgra" : ".rgba");220 ss << (format == GL_BGRA_EXT ? ".bgra" : ".rgba");
219 std::ofstream video_file(ss.str());221 std::ofstream video_file(ss.str());
220222
221 while (running)223 while (running && (number_of_captures != 0))
222 {224 {
223 read_pixels(format, frame_size, frame_data.data());225 read_pixels(format, frame_size, frame_data.data());
224226
@@ -231,6 +233,9 @@
231 egl_setup.swap_buffers();233 egl_setup.swap_buffers();
232234
233 write_out_future.wait();235 write_out_future.wait();
236
237 if (number_of_captures > 0)
238 number_of_captures--;
234 }239 }
235}240}
236241
@@ -243,14 +248,18 @@
243 opterr = 0;248 opterr = 0;
244 char const* socket_file = nullptr;249 char const* socket_file = nullptr;
245 uint32_t output_id = mir_display_output_id_invalid;250 uint32_t output_id = mir_display_output_id_invalid;
251 int32_t number_of_captures = -1;
246252
247 //avoid unused warning/error253 //avoid unused warning/error
248 tls_hack[0] = 0;254 tls_hack[0] = 0;
249255
250 while ((arg = getopt (argc, argv, "hm:o:")) != -1)256 while ((arg = getopt (argc, argv, "hm:o:n:")) != -1)
251 {257 {
252 switch (arg)258 switch (arg)
253 {259 {
260 case 'n':
261 number_of_captures = std::stoi(std::string(optarg));
262 break;
254 case 'm':263 case 'm':
255 socket_file = optarg;264 socket_file = optarg;
256 break;265 break;
@@ -303,13 +312,18 @@
303 if (screencast == nullptr)312 if (screencast == nullptr)
304 throw std::runtime_error("Failed to create screencast");313 throw std::runtime_error("Failed to create screencast");
305314
306 do_screencast(connection.get(), screencast.get(), output_id);315 do_screencast(connection.get(), screencast.get(), output_id, number_of_captures);
307316
308 return EXIT_SUCCESS;317 return EXIT_SUCCESS;
309}318}
319catch(std::invalid_argument const& e)
320{
321 std::cerr << "Invalid Argument" << std::endl;
322 print_usage();
323 return EXIT_FAILURE;
324}
310catch(std::exception const& e)325catch(std::exception const& e)
311{326{
312 std::cerr << e.what() << std::endl;327 std::cerr << e.what() << std::endl;
313
314 return EXIT_FAILURE;328 return EXIT_FAILURE;
315}329}

Subscribers

People subscribed via source and target branches