1. 程式人生 > >mjpg-streamer學習筆記5----輸入通道

mjpg-streamer學習筆記5----輸入通道

設定預設引數
{
char *argv[MAX_ARGUMENTS]={NULL}, *dev = "/dev/video0", *s;
int argc=1, width=640, height=480, fps=5, format=V4L2_PIX_FMT_MJPEG, i;
in_cmd_type led = IN_CMD_LED_AUTO;


/* initialize the mutes variable */
if( pthread_mutex_init(&controls_mutex, NULL) != 0 )// 初始化 controls_mutex,是互斥鎖相關的全域性變數
{
IPRINT("could not initialize mutex variable\n");
exit(EXIT_FAILURE);
}

對命令列引數的解析

/* convert the single parameter-string to an array of strings */
argv[0] = INPUT_PLUGIN_NAME;
if ( param->parameter_string != NULL && strlen(param->parameter_string) != 0 ) {
char *arg=NULL, *saveptr=NULL, *token=NULL;


arg=(char *)strdup(param->parameter_string);


if ( strchr(arg, ' ') != NULL ) {
token=strtok_r(arg, " ", &saveptr);
if ( token != NULL ) {
argv[argc] = strdup(token);
argc++;
while ( (token=strtok_r(NULL, " ", &saveptr)) != NULL ) {
argv[argc] = strdup(token);
argc++;
if (argc >= MAX_ARGUMENTS) {
IPRINT("ERROR: too many arguments to input plugin\n");
return 1;
}
}
}
}
}


/* show all parameters for DBG purposes */

for (i=0; i<argc; i++) {
DBG("argv[%d]=%s\n", i, argv[i]);
}


/* parse the parameters */解析引數
reset_getopt();
while(1)
{
int option_index = 0, c=0;
static struct option long_options[] = \
{
{"h", no_argument, 0, 0},
{"help", no_argument, 0, 0},
{"d", required_argument, 0, 0},
{"device", required_argument, 0, 0},
{"r", required_argument, 0, 0},
{"resolution", required_argument, 0, 0},
{"f", required_argument, 0, 0},
{"fps", required_argument, 0, 0},
{"y", no_argument, 0, 0},
{"yuv", no_argument, 0, 0},
{"q", required_argument, 0, 0},
{"quality", required_argument, 0, 0},
{"m", required_argument, 0, 0},
{"minimum_size", required_argument, 0, 0},
{"n", no_argument, 0, 0},
{"no_dynctrl", no_argument, 0, 0},
{"l", required_argument, 0, 0},
{"led", required_argument, 0, 0},
{0, 0, 0, 0}
};


/* parsing all parameters according to the list above is sufficent */

c = getopt_long_only(argc, argv, "", long_options, &option_index);


/* no more options to parse */
if (c == -1) break;


/* unrecognized option */
if (c == '?'){
help();
return 1;
}


/* dispatch the given options */
switch (option_index) {
/* h, help */
case 0:
case 1:
DBG("case 0,1\n");
help();
return 1;
break;


/* d, device */
case 2:
case 3:
DBG("case 2,3\n");
dev = strdup(optarg);
break;


/* r, resolution */
case 4:
case 5:
DBG("case 4,5\n");
width = -1;
height = -1;


/* try to find the resolution in lookup table "resolutions" */
for ( i=0; i < LENGTH_OF(resolutions); i++ ) {
if ( strcmp(resolutions[i].string, optarg) == 0 ) {
width  = resolutions[i].width;
height = resolutions[i].height;

}
}
/* done if width and height were set */
if(width != -1 && height != -1)
break;
/* parse value as decimal value */
width  = strtol(optarg, &s, 10);
height = strtol(s+1, NULL, 10);
break;


/* f, fps */
case 6:
case 7:
DBG("case 6,7\n");
fps=atoi(optarg);
break;


/* y, yuv */
case 8:
case 9:
DBG("case 8,9\n");