|
67 | 67 | #include "pipewire_common.hpp" |
68 | 68 | #include "pixfmt_conv.h" |
69 | 69 | #include "utils/misc.h" |
| 70 | +#include "utils/string_view_utils.hpp" |
70 | 71 |
|
71 | 72 | #define MOD_NAME "[PW vcap] " |
72 | 73 |
|
@@ -479,51 +480,44 @@ static void show_generic_help(){ |
479 | 480 |
|
480 | 481 |
|
481 | 482 | static int parse_params(const struct vidcap_params *params, vcap_pw_state *s) { |
482 | | - if(const char *fmt = vidcap_params_get_fmt(params)) { |
483 | | - std::istringstream params_stream(fmt); |
484 | | - |
485 | | - std::string param; |
486 | | - while (std::getline(params_stream, param, ':')) { |
487 | | - if (param == "help") { |
488 | | - if(s->mode == vcap_pw_state::Mode::Screen_capture) |
489 | | - show_screen_help(); |
490 | | - else |
491 | | - show_generic_help(); |
492 | | - return VIDCAP_INIT_NOERR; |
493 | | - } |
| 483 | + std::string_view cfg; |
| 484 | + if(auto fmt = vidcap_params_get_fmt(params)){ |
| 485 | + cfg = fmt; |
| 486 | + } |
| 487 | + |
| 488 | + while(!cfg.empty()){ |
| 489 | + auto tok = tokenize(cfg, ':', '"'); |
494 | 490 |
|
495 | | - if (param == "cursor") { |
496 | | - s->user_options.show_cursor = true; |
497 | | - } else if (param == "nocrop") { |
498 | | - s->user_options.crop = false; |
499 | | - } else { |
500 | | - auto split_index = param.find('='); |
501 | | - if(split_index != std::string::npos && split_index != 0){ |
502 | | - std::string name = param.substr(0, split_index); |
503 | | - std::string value = param.substr(split_index + 1); |
504 | | - |
505 | | - if (name == "fps" || name == "FPS"){ |
506 | | - std::istringstream is(value); |
507 | | - is >> s->user_options.fps; |
508 | | - continue; |
509 | | - } |
510 | | - |
511 | | - if(name == "restore"){ |
512 | | - s->user_options.restore_file = std::move(value); |
513 | | - continue; |
514 | | - } |
515 | | - |
516 | | - if(name =="target"){ |
517 | | - s->user_options.target = std::move(value); |
518 | | - continue; |
519 | | - } |
520 | | - } |
521 | | - |
522 | | - LOG(LOG_LEVEL_ERROR) << MOD_NAME "invalid option: \"" << param << "\"\n"; |
| 491 | + const auto key = tokenize(tok, '='); |
| 492 | + const auto val = tokenize(tok, '='); |
| 493 | + |
| 494 | + if (key == "help") { |
| 495 | + if(s->mode == vcap_pw_state::Mode::Screen_capture) |
| 496 | + show_screen_help(); |
| 497 | + else |
| 498 | + show_generic_help(); |
| 499 | + return VIDCAP_INIT_NOERR; |
| 500 | + } |
| 501 | + |
| 502 | + if (key == "cursor") { |
| 503 | + s->user_options.show_cursor = true; |
| 504 | + } else if (key == "nocrop") { |
| 505 | + s->user_options.crop = false; |
| 506 | + } else if (key == "fps" || key == "FPS"){ |
| 507 | + if(!parse_num(val, s->user_options.fps)){ |
| 508 | + log_msg(LOG_LEVEL_FATAL, MOD_NAME "Failed to parse fps\n"); |
523 | 509 | return VIDCAP_INIT_FAIL; |
524 | 510 | } |
| 511 | + } else if(key == "restore"){ |
| 512 | + s->user_options.restore_file = val; |
| 513 | + } else if(key == "target"){ |
| 514 | + s->user_options.target = val; |
| 515 | + } else{ |
| 516 | + log_msg(LOG_LEVEL_FATAL, MOD_NAME "Unknown parameter %s\n", std::string(key).c_str()); |
| 517 | + return VIDCAP_INIT_FAIL; |
525 | 518 | } |
526 | 519 | } |
| 520 | + |
527 | 521 | return VIDCAP_INIT_OK; |
528 | 522 | } |
529 | 523 |
|
|
0 commit comments