@ -7,11 +7,13 @@
# include "config.h"
# include "config.h"
# include "log.h"
# include "log.h"
# include "recorder.h"
struct args {
struct args {
const char * serial ;
const char * serial ;
const char * crop ;
const char * crop ;
const char * record_filename ;
const char * record_filename ;
enum recorder_format record_format ;
SDL_bool fullscreen ;
SDL_bool fullscreen ;
SDL_bool help ;
SDL_bool help ;
SDL_bool version ;
SDL_bool version ;
@ -42,6 +44,9 @@ static void usage(const char *arg0) {
" -f, --fullscreen \n "
" -f, --fullscreen \n "
" Start in fullscreen. \n "
" Start in fullscreen. \n "
" \n "
" \n "
" -F, --record-format \n "
" Force recording format (either mp4 or mkv). \n "
" \n "
" -h, --help \n "
" -h, --help \n "
" Print this help. \n "
" Print this help. \n "
" \n "
" \n "
@ -57,6 +62,8 @@ static void usage(const char *arg0) {
" \n "
" \n "
" -r, --record file.mp4 \n "
" -r, --record file.mp4 \n "
" Record screen to file. \n "
" Record screen to file. \n "
" The format is determined by the -F/--record-format option if \n "
" set, or by the file extension (.mp4 or .mkv). \n "
" \n "
" \n "
" -s, --serial \n "
" -s, --serial \n "
" The device serial number. Mandatory only if several devices \n "
" The device serial number. Mandatory only if several devices \n "
@ -208,6 +215,36 @@ static SDL_bool parse_port(char *optarg, Uint16 *port) {
return SDL_TRUE ;
return SDL_TRUE ;
}
}
static SDL_bool
parse_record_format ( const char * optarg , enum recorder_format * format ) {
if ( ! strcmp ( optarg , " mp4 " ) ) {
* format = RECORDER_FORMAT_MP4 ;
return SDL_TRUE ;
}
if ( ! strcmp ( optarg , " mkv " ) ) {
* format = RECORDER_FORMAT_MKV ;
return SDL_TRUE ;
}
LOGE ( " Unsupported format: %s (expected mp4 or mkv) " , optarg ) ;
return SDL_FALSE ;
}
static enum recorder_format
guess_record_format ( const char * filename ) {
size_t len = strlen ( filename ) ;
if ( len < 4 ) {
return 0 ;
}
const char * ext = & filename [ len - 4 ] ;
if ( ! strcmp ( ext , " .mp4 " ) ) {
return RECORDER_FORMAT_MP4 ;
}
if ( ! strcmp ( ext , " .mkv " ) ) {
return RECORDER_FORMAT_MKV ;
}
return 0 ;
}
static SDL_bool parse_args ( struct args * args , int argc , char * argv [ ] ) {
static SDL_bool parse_args ( struct args * args , int argc , char * argv [ ] ) {
static const struct option long_options [ ] = {
static const struct option long_options [ ] = {
{ " always-on-top " , no_argument , NULL , ' T ' } ,
{ " always-on-top " , no_argument , NULL , ' T ' } ,
@ -218,13 +255,14 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
{ " max-size " , required_argument , NULL , ' m ' } ,
{ " max-size " , required_argument , NULL , ' m ' } ,
{ " port " , required_argument , NULL , ' p ' } ,
{ " port " , required_argument , NULL , ' p ' } ,
{ " record " , required_argument , NULL , ' r ' } ,
{ " record " , required_argument , NULL , ' r ' } ,
{ " record-format " , required_argument , NULL , ' f ' } ,
{ " serial " , required_argument , NULL , ' s ' } ,
{ " serial " , required_argument , NULL , ' s ' } ,
{ " show-touches " , no_argument , NULL , ' t ' } ,
{ " show-touches " , no_argument , NULL , ' t ' } ,
{ " version " , no_argument , NULL , ' v ' } ,
{ " version " , no_argument , NULL , ' v ' } ,
{ NULL , 0 , NULL , 0 } ,
{ NULL , 0 , NULL , 0 } ,
} ;
} ;
int c ;
int c ;
while ( ( c = getopt_long ( argc , argv , " b:c:f hm:p:r:s:tTv" , long_options , NULL ) ) ! = - 1 ) {
while ( ( c = getopt_long ( argc , argv , " b:c:f F: hm:p:r:s:tTv" , long_options , NULL ) ) ! = - 1 ) {
switch ( c ) {
switch ( c ) {
case ' b ' :
case ' b ' :
if ( ! parse_bit_rate ( optarg , & args - > bit_rate ) ) {
if ( ! parse_bit_rate ( optarg , & args - > bit_rate ) ) {
@ -237,6 +275,11 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
case ' f ' :
case ' f ' :
args - > fullscreen = SDL_TRUE ;
args - > fullscreen = SDL_TRUE ;
break ;
break ;
case ' F ' :
if ( ! parse_record_format ( optarg , & args - > record_format ) ) {
return SDL_FALSE ;
}
break ;
case ' h ' :
case ' h ' :
args - > help = SDL_TRUE ;
args - > help = SDL_TRUE ;
break ;
break ;
@ -276,6 +319,21 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
LOGE ( " Unexpected additional argument: %s " , argv [ index ] ) ;
LOGE ( " Unexpected additional argument: %s " , argv [ index ] ) ;
return SDL_FALSE ;
return SDL_FALSE ;
}
}
if ( args - > record_format & & ! args - > record_filename ) {
LOGE ( " Record format specified without recording " ) ;
return SDL_FALSE ;
}
if ( args - > record_filename & & ! args - > record_format ) {
args - > record_format = guess_record_format ( args - > record_filename ) ;
if ( ! args - > record_format ) {
LOGE ( " No format specified for \" %s \" (try with -F mkv) " ,
args - > record_filename ) ;
return SDL_FALSE ;
}
}
return SDL_TRUE ;
return SDL_TRUE ;
}
}
@ -290,6 +348,7 @@ int main(int argc, char *argv[]) {
. serial = NULL ,
. serial = NULL ,
. crop = NULL ,
. crop = NULL ,
. record_filename = NULL ,
. record_filename = NULL ,
. record_format = 0 ,
. help = SDL_FALSE ,
. help = SDL_FALSE ,
. version = SDL_FALSE ,
. version = SDL_FALSE ,
. show_touches = SDL_FALSE ,
. show_touches = SDL_FALSE ,
@ -329,6 +388,7 @@ int main(int argc, char *argv[]) {
. crop = args . crop ,
. crop = args . crop ,
. port = args . port ,
. port = args . port ,
. record_filename = args . record_filename ,
. record_filename = args . record_filename ,
. record_format = args . record_format ,
. max_size = args . max_size ,
. max_size = args . max_size ,
. bit_rate = args . bit_rate ,
. bit_rate = args . bit_rate ,
. show_touches = args . show_touches ,
. show_touches = args . show_touches ,