void video_server_set_framerate(video_server_t * server, unsigned int value) { server->conf->framerate = get_closest_framerate(value); fprintf(stderr, "Video server playing -> ready\n"); gst_element_set_state(server->pipeline, GST_STATE_READY); fprintf(stderr, "New video framerate: %d fps\n", server->conf->framerate); gst_caps_set_simple(GST_CAPS(server->h264caps), "framerate", GST_TYPE_FRACTION, server->conf->framerate, 1, NULL); fprintf(stderr, "Video server ready -> playing\n"); gst_element_set_state(server->pipeline, GST_STATE_PLAYING); }
config_t *config_create(int argc, char *argv[]) { config_t *conf = malloc(sizeof(config_t)); /* add sensible defaults */ conf->device = g_strdup("/dev/video0"); conf->width = 1280; conf->height = 720; conf->framerate = 24; conf->bitrate = 3000; conf->iframe_period = 10000; conf->udp_host = g_strdup("localhost"); conf->udp_port = 4000; conf->cmd_port = 4242; /* parse command line options */ int opt, val; while ((opt = getopt(argc, argv, "d:s:f:b:i:a:p:h")) != -1) { switch (opt) { case 'd': g_free(conf->device); conf->device = g_strdup(optarg); break; case 's': get_frame_size(optarg, conf); break; case 'f': val = atoi(optarg); conf->framerate = get_closest_framerate(val); break; case 'b': val = atoi(optarg); if (val >= 50 && val <= 15000) conf->bitrate = val; else goto help; break; case 'i': val = atoi(optarg); if (val >= 1000 && val <= 60000) conf->iframe_period = val; else goto help; break; case 'a': g_free(conf->udp_host); conf->udp_host = g_strdup(optarg); break; case 'p': val = atoi(optarg); if (val >= 0 && val <= 65535) conf->udp_port = val; else goto help; break; case 'c': val = atoi(optarg); if (val >= 0 && val <= 65535) conf->cmd_port = val; else goto help; case 'h': goto help; break; default: break; } } return conf; help: show_help(); config_destroy(conf); exit(EXIT_FAILURE); }