void * vidcap_aggregate_init(char *init_fmt, unsigned int flags) { struct vidcap_aggregate_state *s; char *save_ptr = NULL; char *item; char *parse_string; char *tmp; int i; printf("vidcap_aggregate_init\n"); s = (struct vidcap_aggregate_state *) calloc(1, sizeof(struct vidcap_aggregate_state)); if(s == NULL) { printf("Unable to allocate aggregate capture state\n"); return NULL; } s->frames = 0; gettimeofday(&s->t0, NULL); if(!init_fmt || strcmp(init_fmt, "help") == 0) { show_help(); return NULL; } s->devices_cnt = 0; tmp = parse_string = strdup(init_fmt); while(strtok_r(tmp, "#", &save_ptr)) { s->devices_cnt++; tmp = NULL; } free(parse_string); s->devices = calloc(1, s->devices_cnt * sizeof(struct vidcap *)); i = 0; tmp = parse_string = strdup(init_fmt); while((item = strtok_r(tmp, "#", &save_ptr))) { char *device; char *config = strdup(item); char *save_ptr_dev = NULL; char *device_cfg; unsigned int dev_flags = 0u; device = strtok_r(config, ":", &save_ptr_dev); device_cfg = save_ptr_dev; if(i == 0) { dev_flags = flags; } else { // do not grab from second and other devices dev_flags = flags & ~(VIDCAP_FLAG_AUDIO_EMBEDDED | VIDCAP_FLAG_AUDIO_AESEBU | VIDCAP_FLAG_AUDIO_ANALOG); } s->devices[i] = initialize_video_capture(device, device_cfg, dev_flags); free(config); if(!s->devices[i]) { fprintf(stderr, "[aggregate] Unable to initialize device %d (%s:%s).\n", i, device, device_cfg); goto error; } ++i; tmp = NULL; } free(parse_string); s->frame = vf_alloc(s->devices_cnt); return s; error: if(s->devices) { int i; for (i = 0u; i < s->devices_cnt; ++i) { if(s->devices[i]) { vidcap_done(s->devices[i]); } } } free(s); return NULL; }
static int vidcap_aggregate_init(const struct vidcap_params *params, void **state) { struct vidcap_aggregate_state *s; printf("vidcap_aggregate_init\n"); s = (struct vidcap_aggregate_state *) calloc(1, sizeof(struct vidcap_aggregate_state)); if(s == NULL) { printf("Unable to allocate aggregate capture state\n"); return VIDCAP_INIT_FAIL; } s->audio_source_index = -1; s->frames = 0; gettimeofday(&s->t0, NULL); if(vidcap_params_get_fmt(params) && strcmp(vidcap_params_get_fmt(params), "") != 0) { show_help(); free(s); return VIDCAP_INIT_NOERR; } s->devices_cnt = 0; const struct vidcap_params *tmp = params; while((tmp = vidcap_params_get_next(tmp))) { if (vidcap_params_get_driver(tmp) != NULL) s->devices_cnt++; else break; } s->devices = calloc(s->devices_cnt, sizeof(struct vidcap *)); tmp = params; for (int i = 0; i < s->devices_cnt; ++i) { tmp = vidcap_params_get_next(tmp); int ret = initialize_video_capture(NULL, (struct vidcap_params *) tmp, &s->devices[i]); if(ret != 0) { fprintf(stderr, "[aggregate] Unable to initialize device %d (%s:%s).\n", i, vidcap_params_get_driver(tmp), vidcap_params_get_fmt(tmp)); goto error; } } s->captured_frames = calloc(s->devices_cnt, sizeof(struct video_frame *)); s->frame = vf_alloc(s->devices_cnt); *state = s; return VIDCAP_INIT_OK; error: if(s->devices) { int i; for (i = 0u; i < s->devices_cnt; ++i) { if(s->devices[i]) { vidcap_done(s->devices[i]); } } } free(s); return VIDCAP_INIT_FAIL; }