Factorize record format parsing
Convert either the filename extension or the explicit record format to a sc_record_format using the same function. PR #3978 <https://github.com/Genymobile/scrcpy/pull/3978>
This commit is contained in:
parent
8c650e53cd
commit
be86e14e05
1 changed files with 23 additions and 19 deletions
|
@ -1479,20 +1479,29 @@ sc_parse_shortcut_mods(const char *s, struct sc_shortcut_mods *mods) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static enum sc_record_format
|
||||||
|
get_record_format(const char *name) {
|
||||||
|
if (!strcmp(name, "mp4")) {
|
||||||
|
return SC_RECORD_FORMAT_MP4;
|
||||||
|
}
|
||||||
|
if (!strcmp(name, "mkv")) {
|
||||||
|
return SC_RECORD_FORMAT_MKV;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_record_format(const char *optarg, enum sc_record_format *format) {
|
parse_record_format(const char *optarg, enum sc_record_format *format) {
|
||||||
if (!strcmp(optarg, "mp4")) {
|
enum sc_record_format fmt = get_record_format(optarg);
|
||||||
*format = SC_RECORD_FORMAT_MP4;
|
if (!fmt) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!strcmp(optarg, "mkv")) {
|
|
||||||
*format = SC_RECORD_FORMAT_MKV;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
LOGE("Unsupported format: %s (expected mp4 or mkv)", optarg);
|
LOGE("Unsupported format: %s (expected mp4 or mkv)", optarg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*format = fmt;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_ip(const char *optarg, uint32_t *ipv4) {
|
parse_ip(const char *optarg, uint32_t *ipv4) {
|
||||||
return net_parse_ipv4(optarg, ipv4);
|
return net_parse_ipv4(optarg, ipv4);
|
||||||
|
@ -1510,18 +1519,13 @@ parse_port(const char *optarg, uint16_t *port) {
|
||||||
|
|
||||||
static enum sc_record_format
|
static enum sc_record_format
|
||||||
guess_record_format(const char *filename) {
|
guess_record_format(const char *filename) {
|
||||||
size_t len = strlen(filename);
|
const char *dot = strrchr(filename, '.');
|
||||||
if (len < 4) {
|
if (!dot) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
const char *ext = &filename[len - 4];
|
|
||||||
if (!strcmp(ext, ".mp4")) {
|
const char *ext = dot + 1;
|
||||||
return SC_RECORD_FORMAT_MP4;
|
return get_record_format(ext);
|
||||||
}
|
|
||||||
if (!strcmp(ext, ".mkv")) {
|
|
||||||
return SC_RECORD_FORMAT_MKV;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
Loading…
Reference in a new issue