void clean_struct (struct ALL_DATA *all_data) { struct GWIDGET *gwidget = all_data->gwidget; struct VidState *s = all_data->s; struct paRecordData *pdata = all_data->pdata; struct GLOBAL *global = all_data->global; struct focusData *AFdata = all_data->AFdata; struct vdIn *videoIn = all_data->videoIn; struct VideoFormatData *videoF = all_data->videoF; gboolean control_only = (global->control_only || global->add_ctrls); if((!control_only) && (pdata != NULL)) { /*destroy mutex for sound buffers*/ if (global->debug) g_printf("free audio mutex\n"); g_mutex_free( pdata->mutex ); g_free(pdata); pdata=NULL; all_data->pdata=NULL; g_free(videoF); videoF=NULL; } if(videoIn) close_v4l2(videoIn, control_only); videoIn=NULL; if (global->debug) g_printf("closed v4l2 strutures\n"); if (s->control_list) { free_control_list (s->control_list); s->control_list = NULL; g_printf("free controls\n"); } g_free(s); s = NULL; all_data->s = NULL; g_free(gwidget); gwidget = NULL; all_data->gwidget = NULL; if (global->debug) g_printf("free controls - vidState\n"); g_free(AFdata); AFdata = NULL; all_data->AFdata = NULL; if(global) closeGlobals(global); global=NULL; all_data->global=NULL; g_printf("cleaned allocations - 100%%\n"); }
/*------------------------- read command line options ------------------------*/ void readOpts(int argc,char *argv[], struct GLOBAL *global) { gchar *device=NULL; gchar *format=NULL; gchar *size = NULL; gchar *image = NULL; gchar *video=NULL; gchar *profile=NULL; gchar *separateur=NULL; gboolean help = FALSE; gboolean help_gtk = FALSE; gboolean help_all = FALSE; gboolean vers = FALSE; gchar *help_str = NULL; gchar *help_gtk_str = NULL; gchar *help_all_str = NULL; gchar *config = NULL; int hwaccel=-1; int FpsCount=-1; int cap_meth=-1; GOptionEntry entries[] = { { "help-all", 'h', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &help_all, "Display all help options", NULL}, { "help-gtk", '!', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &help_gtk, "DISPLAY GTK+ help", NULL}, { "help", '?', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &help, "Display help", NULL}, { "version", 0, 0, G_OPTION_ARG_NONE, &vers, N_("Prints version"), NULL}, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &global->debug, N_("Displays debug information"), NULL }, { "device", 'd', 0, G_OPTION_ARG_STRING, &device, N_("Video Device to use [default: /dev/video0]"), "VIDEO_DEVICE" }, { "add_ctrls", 'a', 0, G_OPTION_ARG_NONE, &global->add_ctrls, N_("Exit after adding UVC extension controls (needs root/sudo)"), NULL}, { "control_only", 'o', 0, G_OPTION_ARG_NONE, &global->control_only, N_("Don't stream video (image controls only)"), NULL}, { "no_display", 0,0, G_OPTION_ARG_NONE, &global->no_display, N_("Don't display a GUI"), NULL}, { "capture_method", 'r', 0, G_OPTION_ARG_INT, &cap_meth, N_("Capture method (1-mmap (default) 2-read)"), "[1 | 2]"}, { "config", 'g', 0, G_OPTION_ARG_STRING, &config, N_("Configuration file"), "FILENAME" }, { "hwd_acel", 'w', 0, G_OPTION_ARG_INT, &hwaccel, N_("Hardware accelaration (enable(1) | disable(0))"), "[1 | 0]" }, { "format", 'f', 0, G_OPTION_ARG_STRING, &format, N_("Pixel format(mjpg|jpeg|yuyv|yvyu|uyvy|yyuv|yu12|yv12|nv12|nv21|nv16|nv61|y41p|grey|y10b|y16 |s501|s505|s508|gbrg|grbg|ba81|rggb|bgr3|rgb3)"), "FORMAT" }, { "size", 's', 0, G_OPTION_ARG_STRING, &size, N_("Frame size, default: 640x480"), "WIDTHxHEIGHT"}, { "image", 'i', 0, G_OPTION_ARG_STRING, &image, N_("Image File name"), "FILENAME"}, { "cap_time", 'c', 0, G_OPTION_ARG_INT, &global->image_timer, N_("Image capture interval in seconds"), "TIME"}, { "npics", 'm', 0, G_OPTION_ARG_INT, &global->image_npics, N_("Number of Pictures to capture"), "NUMPIC"}, { "video", 'n', 0, G_OPTION_ARG_STRING, &video, N_("Video File name (capture from start)"), "FILENAME"}, { "vid_time", 't', 0, G_OPTION_ARG_INT, &global->Capture_time,N_("Video capture time (in seconds)"), "TIME"}, { "exit_on_close", 0, 0, G_OPTION_ARG_NONE, &global->exit_on_close, N_("Exits guvcview after closing video"), NULL}, { "skip", 'j', 0, G_OPTION_ARG_INT, &global->skip_n, N_("Number of initial frames to skip"), "N_FRAMES"}, { "show_fps", 'p', 0, G_OPTION_ARG_INT, &FpsCount, N_("Show FPS value (enable(1) | disable (0))"), "[1 | 0]"}, { "profile", 'l', 0, G_OPTION_ARG_STRING, &profile, N_("Load Profile at start"), "FILENAME"}, { "lctl_method", 'k', 0, G_OPTION_ARG_INT, &global->lctl_method, N_("List controls method (0:loop, 1:next_ctrl flag [def])"), "[0 |1]"}, { NULL } }; GError *error = NULL; GOptionContext *context; context = g_option_context_new (N_("- local options")); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_set_prgname (PACKAGE); help_str = g_option_context_get_help (context, TRUE, NULL); help_gtk_str = g_option_context_get_help (context, FALSE, gtk_get_option_group (TRUE)); help_all_str = g_option_context_get_help (context, FALSE, NULL); /*disable automatic help parsing - must clean global before exit*/ g_option_context_set_help_enabled (context, FALSE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s\n", error->message); g_error_free ( error ); closeGlobals(global); global=NULL; g_print("%s",help_all_str); g_free(help_all_str); g_free(help_str); g_free(help_gtk_str); g_option_context_free (context); exit (1); } if(vers) { //print version and exit //version already printed in guvcview.c closeGlobals(global); global=NULL; g_free(help_all_str); g_free(help_str); g_free(help_gtk_str); g_option_context_free (context); exit(0); } /*Display help message and exit*/ if(help_all) { closeGlobals(global); global=NULL; g_print("%s",help_all_str); g_free(help_all_str); g_free(help_str); g_free(help_gtk_str); g_option_context_free (context); exit(0); } else if(help) { closeGlobals(global); global=NULL; g_print("%s",help_str); g_free(help_str); g_free(help_gtk_str); g_free(help_all_str); g_option_context_free (context); exit(0); } else if(help_gtk) { closeGlobals(global); global=NULL; g_print("%s",help_gtk_str); g_free(help_str); g_free(help_gtk_str); g_free(help_all_str); g_option_context_free (context); exit(0); } /*regular options*/ if(device) { gchar *basename = NULL; gchar *dirname = NULL; basename = g_path_get_basename(device); if(!(g_str_has_prefix(basename,"video"))) { g_printerr("%s not a valid video device name\n", basename); } else { g_free(global->videodevice); global->videodevice=NULL; dirname = g_path_get_dirname(device); if(g_strcmp0(".",dirname)==0) { g_free(dirname); dirname=g_strdup("/dev"); } global->videodevice = g_strjoin("/", dirname, basename, NULL); if(global->flg_config < 1) { if(g_strcmp0("video0",basename) !=0 ) { g_free(global->confPath); global->confPath=NULL; global->confPath = g_strjoin("/", g_get_home_dir(), ".config", "guvcview", basename, NULL); } } } g_free(dirname); g_free(basename); } if(config) { g_free(global->confPath); global->confPath=NULL; global->confPath = g_strdup(config); global->flg_config = 1; } if(format) { /*use fourcc but keep compatability with luvcview*/ if(g_strcmp0("yuv",format)==0) g_snprintf(global->mode,5,"yuyv"); else if (g_strcmp0("bggr",format)==0) // be compatible with guvcview < 1.1.4 g_snprintf(global->mode,5,"ba81"); else g_snprintf(global->mode,5,"%s ",format); printf("requested format \"%s\" from command line\n", global->mode); global->flg_mode = TRUE; } if(size) { global->width = (int) g_ascii_strtoull(size, &separateur, 10); if (*separateur != 'x') { g_printerr("Error in size usage: -s[--size] WIDTHxHEIGHT \n"); } else { ++separateur; global->height = (int) g_ascii_strtoull(separateur, &separateur, 10); if (*separateur != 0) g_printerr("hmm.. don't like that!! trying this height \n"); } global->flg_res = 1; } if(image) { global->imgFPath=splitPath(image,global->imgFPath); /*get the file type*/ global->imgFormat = check_image_type(global->imgFPath[0]); global->flg_imgFPath = TRUE; if(global->image_inc>0) { uint64_t suffix = get_file_suffix(global->imgFPath[1], global->imgFPath[0]); fprintf(stderr, "Image file suffix detected: %" PRIu64 "\n", suffix); if(suffix >= G_MAXUINT64) { global->imgFPath[0] = add_file_suffix(global->imgFPath[0], suffix); suffix = 0; } if(suffix > 0) { global->image_inc = suffix + 1; } } } if(global->image_timer > 0 ) { g_print("capturing images every %i seconds\n",global->image_timer); } if(video) { global->vidFPath=splitPath(video, global->vidFPath); if(global->vid_inc>0) { uint64_t suffix = get_file_suffix(global->vidFPath[1], global->vidFPath[0]); fprintf(stderr, "Video file suffix detected: %" PRIu64 "\n", suffix); if(suffix >= G_MAXUINT64) { global->vidFPath[0] = add_file_suffix(global->vidFPath[0], suffix); suffix = 0; } if(suffix > 0) global->vid_inc = suffix + 1; } global->vidfile = joinPath(global->vidfile, global->vidFPath); g_print("capturing video: %s , from start\n",global->vidfile); /*get the file type*/ global->VidFormat = check_video_type(global->vidFPath[0]); } if(profile) { global->lprofile=1; global->profile_FPath=splitPath(profile,global->profile_FPath); } if(hwaccel != -1 ) { global->hwaccel = hwaccel; global->flg_hwaccel = 1; } if(FpsCount != -1) { global->FpsCount = FpsCount; global->flg_FpsCount = 1; } if(cap_meth != -1) { global->flg_cap_meth = TRUE; global->cap_meth = cap_meth; } //g_print("option capture meth is %i\n", global->cap_meth); g_free(help_str); g_free(help_gtk_str); g_free(help_all_str); g_free(device); g_free(config); g_free(format); g_free(size); g_free(image); g_free(video); g_free(profile); g_option_context_free (context); }