Ejemplo n.º 1
0
static int do_format(json_config *config, const char *filename, const char *outputfile)
{
    FILE *input, *output;
    json_parser parser;
    json_printer printer;
    int ret;
    int col, lines;

    input = open_filename(filename, "r", 1);
    if (!input)
        return 2;

    output = open_filename(outputfile, "a+", 0);
    if (!output)
        return 2;

    /* initialize printer and parser structures */
    ret = json_print_init(&printer, printchannel, stdout);
    if (ret) {
        fprintf(stderr, "error: initializing printer failed: [code=%d] %s\n", ret, string_of_errors[ret]);
        return ret;
    }
    if (indent_string)
        printer.indentstr = indent_string;

    ret = json_parser_init(&parser, config, &prettyprint, &printer);
    if (ret) {
        fprintf(stderr, "error: initializing parser failed: [code=%d] %s\n", ret, string_of_errors[ret]);
        return ret;
    }

    ret = process_file(&parser, input, &lines, &col);
    if (ret) {
        fprintf(stderr, "line %d, col %d: [code=%d] %s\n",
                lines, col, ret, string_of_errors[ret]);
        return 1;
    }

    ret = json_parser_is_done(&parser);
    if (!ret) {
        fprintf(stderr, "syntax error\n");
        return 1;
    }

    /* cleanup */
    json_parser_free(&parser);
    json_print_free(&printer);
    fwrite("\n", 1, 1, stdout);
    close_filename(filename, input);
    return 0;
}
Ejemplo n.º 2
0
static int do_parse(json_config *config, const char *filename)
{
    FILE *input;
    json_parser parser;
    int ret;
    int col, lines;

    input = open_filename(filename, "r", 1);
    if (!input)
        return 2;

    /* initialize the parser structure. we don't need a callback in verify */
    ret = json_parser_init(&parser, config, NULL, NULL);
    if (ret) {
        fprintf(stderr, "error: initializing parser failed (code=%d): %s\n", ret, string_of_errors[ret]);
        return ret;
    }

    ret = process_file(&parser, input, &lines, &col);
    if (ret) {
        fprintf(stderr, "line %d, col %d: [code=%d] %s\n",
                lines, col, ret, string_of_errors[ret]);
        return 1;
    }

    ret = json_parser_is_done(&parser);
    if (!ret) {
        fprintf(stderr, "syntax error\n");
        return 1;
    }

    close_filename(filename, input);
    return 0;
}
Ejemplo n.º 3
0
int
archive_write_open_filename_w(struct archive *a, const wchar_t *filename)
{

	if (filename == NULL || filename[0] == L'\0')
		return (archive_write_open_fd(a, 1));

	return (open_filename(a, 0, filename));
}
Ejemplo n.º 4
0
int
archive_write_open_filename(struct archive *a, const char *filename)
{

	if (filename == NULL || filename[0] == '\0')
		return (archive_write_open_fd(a, 1));

	return (open_filename(a, 1, filename));
}
Ejemplo n.º 5
0
static int print_tree(json_val_t *root_structure, char *outputfile)
{
    FILE *output;

    output = open_filename(outputfile, "a+", 0);
    if (!output)
        return 2;
    print_tree_iter(root_structure, output);
    close_filename(outputfile, output);
    return 0;
}
Ejemplo n.º 6
0
static int do_tree(json_config *config, const char *filename, json_val_t **root_structure)
{
    FILE *input;
    json_parser parser;
    json_parser_dom dom;
    int ret;
    int col, lines;

    input = open_filename(filename, "r", 1);
    if (!input)
        return 2;

    ret = json_parser_dom_init(&dom, tree_create_structure, tree_create_data, tree_append);
    if (ret) {
        fprintf(stderr, "error: initializing helper failed: [code=%d] %s\n", ret, string_of_errors[ret]);
        return ret;
    }

    ret = json_parser_init(&parser, config, json_parser_dom_callback, &dom);
    if (ret) {
        fprintf(stderr, "error: initializing parser failed: [code=%d] %s\n", ret, string_of_errors[ret]);
        return ret;
    }

    ret = process_file(&parser, input, &lines, &col);
    if (ret) {
        fprintf(stderr, "line %d, col %d: [code=%d] %s\n",
                lines, col, ret, string_of_errors[ret]);

        return 1;
    }

    ret = json_parser_is_done(&parser);
    if (!ret) {
        fprintf(stderr, "syntax error\n");
        return 1;
    }

    if (root_structure)
        *root_structure = dom.root_structure;

    /* cleanup */
    json_parser_free(&parser);
    close_filename(filename, input);
    return 0;
}
Ejemplo n.º 7
0
RaspiCamCvCapture * raspiCamCvCreateCameraCapture(int index)
{
	RaspiCamCvCapture * capture = (RaspiCamCvCapture*)malloc(sizeof(RaspiCamCvCapture));
	// Our main data storage vessel..
	RASPIVID_STATE * state = (RASPIVID_STATE*)malloc(sizeof(RASPIVID_STATE));
	capture->pState = state;

	MMAL_STATUS_T status = -1;
	MMAL_PORT_T *camera_video_port = NULL;
	MMAL_PORT_T *camera_video_port_2 = NULL;
	//MMAL_PORT_T *camera_still_port = NULL;
	MMAL_PORT_T *encoder_input_port = NULL;
	MMAL_PORT_T *encoder_output_port = NULL;

	bcm_host_init();

	// read default status
	default_status(state);

	int w = state->width;
	int h = state->height;

	state->py = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3);		// Y component of YUV I420 frame

	if (state->graymode==0)
	{
		state->pu = cvCreateImage(cvSize(w/2,h/2), IPL_DEPTH_8U, 1);	// U component of YUV I420 frame
		state->pv = cvCreateImage(cvSize(w/2,h/2), IPL_DEPTH_8U, 1);	// V component of YUV I420 frame
	}
	vcos_semaphore_create(&state->capture_sem, "Capture-Sem", 0);
	vcos_semaphore_create(&state->capture_done_sem, "Capture-Done-Sem", 0);

	if (state->graymode==0)
	{
		state->pu_big = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 1);
		state->pv_big = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 1);
		state->yuvImage = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3);
		state->dstImage = cvCreateImage(cvSize(w,h), IPL_DEPTH_8U, 3); // final picture to display
	}

	//printf("point2.0\n");
	// create camera
	if (!create_camera_component(state))
	{
		vcos_log_error("%s: Failed to create camera component", __func__);
		raspiCamCvReleaseCapture(&capture);
		return NULL;
	} else if ((status = create_encoder_component(state)) != MMAL_SUCCESS)
	{
		vcos_log_error("%s: Failed to create encode component", __func__);
		destroy_camera_component(state);
		return NULL;
	}

	//printf("point2.1\n");
	//create_encoder_component(state);

	camera_video_port = state->camera_component->output[MMAL_CAMERA_VIDEO_PORT];
	camera_video_port_2 = state->camera_component->output[MMAL_CAMERA_VIDEO_PORT_2];
	//camera_still_port = state->camera_component->output[MMAL_CAMERA_CAPTURE_PORT];
	encoder_input_port  = state->encoder_component->input[0];
	encoder_output_port = state->encoder_component->output[0];

	// assign data to use for callback
	camera_video_port->userdata = (struct MMAL_PORT_USERDATA_T *)state;

	// assign data to use for callback
	camera_video_port_2->userdata = (struct MMAL_PORT_USERDATA_T *)state;

	// Now connect the camera to the encoder
	status = connect_ports(camera_video_port_2, encoder_input_port, &state->encoder_connection);	

	if (state->filename)
	{
		if (state->filename[0] == '-')
		{
			state->callback_data.file_handle = stdout;
		}
		else
		{
			state->callback_data.file_handle = open_filename(state);
		}

		if (!state->callback_data.file_handle)
		{
			// Notify user, carry on but discarding encoded output buffers
			vcos_log_error("%s: Error opening output file: %s\nNo output file will be generated\n", __func__, state->filename);
		}
	}

	// Set up our userdata - this is passed though to the callback where we need the information.
	state->callback_data.pstate = state;
	state->callback_data.abort = 0;
	encoder_output_port->userdata = (struct MMAL_PORT_USERDATA_T *)&state->callback_data;

	// Enable the encoder output port and tell it its callback function
	status = mmal_port_enable(encoder_output_port, encoder_buffer_callback);

	if (status != MMAL_SUCCESS)
	{
		state->encoder_connection = NULL;
		vcos_log_error("%s: Failed to connect camera video port to encoder input", __func__);
		return NULL;
	}

	if (status != MMAL_SUCCESS)
	{
		vcos_log_error("Failed to setup encoder output");
		return NULL;
	}

	//mmal_port_enable(encoder_output_port, encoder_buffer_callback);

	// Only encode stuff if we have a filename and it opened
	// Note we use the copy in the callback, as the call back MIGHT change the file handle
	if (state->callback_data.file_handle)
	{
		int running = 1;

		// Send all the buffers to the encoder output port
		{
			int num = mmal_queue_length(state->encoder_pool->queue);
			int q;
			for (q=0;q<num;q++)
			{
				MMAL_BUFFER_HEADER_T *buffer2 = mmal_queue_get(state->encoder_pool->queue);

				if (!buffer2)
					vcos_log_error("Unable to get a required buffer %d from pool queue", q);

				if (mmal_port_send_buffer(encoder_output_port, buffer2)!= MMAL_SUCCESS)
					vcos_log_error("Unable to send a buffer to encoder output port (%d)", q);
			}
		}
	}


	// start capture
	if (mmal_port_parameter_set_boolean(camera_video_port_2, MMAL_PARAMETER_CAPTURE, 1) != MMAL_SUCCESS)
	{
		vcos_log_error("%s: Failed to start capture", __func__);
		raspiCamCvReleaseCapture(&capture);
		return NULL;
	}

	// Send all the buffers to the video port

	int num = mmal_queue_length(state->video_pool->queue);
	int q;
	for (q = 0; q < num; q++)
	{
		MMAL_BUFFER_HEADER_T *buffer = mmal_queue_get(state->video_pool->queue);

		if (!buffer)
			vcos_log_error("Unable to get a required buffer %d from pool queue", q);

		if (mmal_port_send_buffer(camera_video_port, buffer)!= MMAL_SUCCESS)
			vcos_log_error("Unable to send a buffer to encoder output port (%d)", q);
	}

	//mmal_status_to_int(status);	

	// Disable all our ports that are not handled by connections
	//check_disable_port(camera_still_port);

	//if (status != 0)
	//	raspicamcontrol_check_configuration(128);

	vcos_semaphore_wait(&state->capture_done_sem);
	return capture;
}