Ejemplo n.º 1
0
int
main(int argc, char **argv)
{
	struct state state;

	if (initialize_state(&state)) {
		printf("ERROR in initialization\n");
		return 1;
	}

	if (parse_args(argc, argv, &state)) {
		printf("ERROR parsing arguments\n");
		return 1; // TODO: cleanup_state()
	}

	if (bmp_load(state.inf, state.inname, &state)) {
		printf("ERROR loading BMP!\n");
		return 1; // TODO: cleanup_state()
	}

	if (font_save(state.outf, state.outname, &state)) {
		printf("ERROR saving font!\n");
		return 1; // TODO: cleanup_state()
	}

	cleanup_state(&state);
	return 0;
}
Ejemplo n.º 2
0
void
vl_zscan_cleanup(struct vl_zscan *zscan)
{
   assert(zscan);

   cleanup_shaders(zscan);
   cleanup_state(zscan);
}
Ejemplo n.º 3
0
void jpeg_compress_done(void *arg)
{
        struct compress_jpeg_state *s = (struct compress_jpeg_state *) arg;

        cleanup_state(s);
        
        free(s);
}
Ejemplo n.º 4
0
void
vl_idct_cleanup(struct vl_idct *idct)
{
    cleanup_shaders(idct);
    cleanup_state(idct);

    pipe_sampler_view_reference(&idct->matrix, NULL);
    pipe_sampler_view_reference(&idct->transpose, NULL);
}
Ejemplo n.º 5
0
static void jpeg_compress_done(struct module *mod)
{
        struct state_video_compress_jpeg *s = (struct state_video_compress_jpeg *) mod->priv_data;

        cleanup_state(s);

        platform_spin_destroy(&s->spin);
        
        free(s);
}
Ejemplo n.º 6
0
int main_split(int argc, char** argv)
{
    int ret = 1;
    parsed_opts_t* opts = parse_args(argc, argv);
    if (!opts) goto cleanup_opts;
    state_t* status = init(opts);
    if (!status) goto cleanup_opts;

    if (!split(status)) {
        cleanup_state(status, false);
        goto cleanup_opts;
    }

    ret = cleanup_state(status, true);

cleanup_opts:
    cleanup_opts(opts);

    return ret;
}
Ejemplo n.º 7
0
int main_addreplacerg(int argc, char** argv)
{
    parsed_opts_t* opts = NULL;
    state_t* state = NULL;

    if (!parse_args(argc, argv, &opts)) goto error;
    if (opts == NULL) return EXIT_SUCCESS; // Not an error but user doesn't want us to proceed
    if (!opts || !init(opts, &state)) goto error;

    if (!readgroupise(state)) goto error;

    cleanup_opts(opts);
    cleanup_state(state);

    return EXIT_SUCCESS;
error:
    cleanup_opts(opts);
    cleanup_state(state);

    return EXIT_FAILURE;
}
Ejemplo n.º 8
0
static struct packet_module_state *init_state(int thread_id)
{
	static const u_int16_t proto_family[] = { AF_INET, AF_INET6 };
	int i;
	struct packet_module_state *state = malloc(sizeof(struct packet_module_state));
	if (!state) {
		return NULL;
	}

	/* Setup nfqueue connection */
	state->handle = nfq_open();
	if (!state->handle) {
		message(HAKA_LOG_ERROR, MODULE_NAME, L"unable to open nfqueue handle");
		cleanup_state(state);
		return NULL;
	}

	for (i=0; i<sizeof(proto_family)/sizeof(proto_family[0]); ++i) {
		if (nfq_unbind_pf(state->handle, proto_family[i]) < 0) {
			message(HAKA_LOG_ERROR, MODULE_NAME, L"cannot unbind queue");
			cleanup_state(state);
			return NULL;
		}

		if (nfq_bind_pf(state->handle, proto_family[i]) < 0) {
			message(HAKA_LOG_ERROR, MODULE_NAME, L"cannot bind queue");
			cleanup_state(state);
			return NULL;
		}

		state->send_fd = open_send_socket(false);
		if (state->send_fd < 0) {
			cleanup_state(state);
			return NULL;
		}

		state->send_mark_fd = open_send_socket(true);
		if (state->send_fd < 0) {
			cleanup_state(state);
			return NULL;
		}
	}

	state->queue = nfq_create_queue(state->handle, thread_id,
			&packet_callback, state);
	if (!state->queue) {
		message(HAKA_LOG_ERROR, MODULE_NAME, L"cannot create queue");
		cleanup_state(state);
		return NULL;
	}

	if (nfq_set_mode(state->queue, NFQNL_COPY_PACKET,
			PACKET_BUFFER_SIZE) < 0) {
		message(HAKA_LOG_ERROR, MODULE_NAME, L"cannot set mode to copy packet");
		cleanup_state(state);
		return NULL;
	}

	state->fd = nfq_fd(state->handle);

	/* Change nfq queue len and netfilter receive size */
	if (nfq_set_queue_maxlen(state->queue, nfqueue_len) < 0) {
		message(HAKA_LOG_WARNING, MODULE_NAME, L"cannot change netfilter queue len");
	}

	nfnl_rcvbufsiz(nfq_nfnlh(state->handle), nfqueue_len * 1500);

	return state;
}
Ejemplo n.º 9
0
// Set the initial state
static state_t* init(parsed_opts_t* opts)
{
    state_t* retval = calloc(sizeof(state_t), 1);
    if (!retval) {
        fprintf(pysamerr, "Out of memory");
        return NULL;
    }

    retval->merged_input_file = sam_open(opts->merged_input_name, "rb");
    if (!retval->merged_input_file) {
        fprintf(pysamerr, "Could not open input file (%s)\n", opts->merged_input_name);
        free(retval);
        return NULL;
    }
    retval->merged_input_header = sam_hdr_read(retval->merged_input_file);

    if (opts->unaccounted_name) {
        if (opts->unaccounted_header_name) {
            samFile* hdr_load = sam_open(opts->unaccounted_header_name, "r");
            if (!hdr_load) {
                fprintf(pysamerr, "Could not open unaccounted header file (%s)\n", opts->unaccounted_header_name);
                cleanup_state(retval);
                return NULL;
            }
            retval->unaccounted_header = sam_hdr_read(hdr_load);
            sam_close(hdr_load);
        } else {
            retval->unaccounted_header = bam_hdr_dup(retval->merged_input_header);
        }

        retval->unaccounted_file = sam_open(opts->unaccounted_name, "wb");
        if (retval->unaccounted_file == NULL) {
            fprintf(pysamerr, "Could not open unaccounted output file: %s\n", opts->unaccounted_name);
            cleanup_state(retval);
            return NULL;
        }
    }

    // Open output files for RGs
    if (!count_RG(retval->merged_input_header, &retval->output_count, &retval->rg_id)) return NULL;
    if (opts->verbose) fprintf(pysamerr, "@RG's found %zu\n",retval->output_count);

    retval->rg_output_file = (samFile**)calloc(retval->output_count, sizeof(samFile*));
    retval->rg_output_header = (bam_hdr_t**)calloc(retval->output_count, sizeof(bam_hdr_t*));
    retval->rg_hash = kh_init_c2i();
    if (!retval->rg_output_file || !retval->rg_output_header) {
        fprintf(pysamerr, "Could not allocate memory for output file array. Out of memory?");
        cleanup_state(retval);
        return NULL;
    }

    char* dirsep = strrchr(opts->merged_input_name, '/');
    char* input_base_name = strdup(dirsep? dirsep+1 : opts->merged_input_name);
    if (!input_base_name) {
        fprintf(pysamerr, "Out of memory\n");
        cleanup_state(retval);
        return NULL;
    }
    char* extension = strrchr(input_base_name, '.');
    if (extension) *extension = '\0';

    size_t i;
    for (i = 0; i < retval->output_count; i++) {
        char* output_filename = NULL;

        if ( ( output_filename = expand_format_string(opts->output_format_string, input_base_name, retval->rg_id[i], i) ) == NULL) {
            fprintf(pysamerr, "Error expanding output filename format string.\r\n");
            cleanup_state(retval);
            free(input_base_name);
            return NULL;
        }

        retval->rg_output_file[i] = sam_open(output_filename, "wb");
        if (retval->rg_output_file[i] == NULL) {
            fprintf(pysamerr, "Could not open output file: %s\r\n", output_filename);
            cleanup_state(retval);
            free(input_base_name);
            return NULL;
        }

        // Record index in hash
        int ret;
        khiter_t iter = kh_put_c2i(retval->rg_hash, retval->rg_id[i], &ret);
        kh_val(retval->rg_hash,iter) = i;

        // Set and edit header
        retval->rg_output_header[i] = bam_hdr_dup(retval->merged_input_header);
        if ( !filter_header_rg(retval->rg_output_header[i], retval->rg_id[i]) ) {
            fprintf(pysamerr, "Could not rewrite header for file: %s\r\n", output_filename);
            cleanup_state(retval);
            free(output_filename);
            free(input_base_name);
            return NULL;
        }
        free(output_filename);
    }

    free(input_base_name);

    return retval;
}
Ejemplo n.º 10
0
struct video_frame * jpeg_compress(struct module *mod, struct video_frame * tx, int buffer_idx)
{
        struct state_video_compress_jpeg *s = (struct state_video_compress_jpeg *) mod->priv_data;
        int i;
        unsigned char *line1, *line2;
        struct video_frame *out;

        unsigned int x;

        cudaSetDevice(cuda_devices[0]);
        
        if(!s->encoder) {
                int ret;
                ret = configure_with(s, tx);
                if(!ret) {
                        return NULL;
                }
        }

        struct video_desc desc;
        desc = video_desc_from_frame(tx);

        // if format changed, reconfigure
        if(!video_desc_eq_excl_param(s->saved_desc, desc, PARAM_INTERLACING)) {
                cleanup_state(s);
                int ret;
                ret = configure_with(s, tx);
                if(!ret) {
                        return NULL;
                }
        }

        out = s->out[buffer_idx];

        for (x = 0; x < tx->tile_count;  ++x) {
                struct tile *in_tile = vf_get_tile(tx, x);
                struct tile *out_tile = vf_get_tile(out, x);
                
                line1 = (unsigned char *) in_tile->data;
                line2 = (unsigned char *) s->decoded;
                
                for (i = 0; i < (int) in_tile->height; ++i) {
                        s->decoder(line2, line1, s->encoder_input_linesize,
                                        0, 8, 16);
                        line1 += vc_get_linesize(in_tile->width, tx->color_spec);
                        line2 += s->encoder_input_linesize;
                }
                
                line1 = (unsigned char *) out_tile->data + (in_tile->height - 1) * s->encoder_input_linesize;
                for( ; i < (int) out->tiles[0].height; ++i) {
                        memcpy(line2, line1, s->encoder_input_linesize);
                        line2 += s->encoder_input_linesize;
                }
                
                /*if(s->interlaced_input)
                        vc_deinterlace((unsigned char *) s->decoded, s->encoder_input_linesize,
                                        s->out->tiles[0].height);*/
                
                uint8_t *compressed;
                int size;
                int ret;


                struct gpujpeg_encoder_input encoder_input;
                gpujpeg_encoder_input_set_image(&encoder_input, (uint8_t *) s->decoded);
                ret = gpujpeg_encoder_encode(s->encoder, &encoder_input, &compressed, &size);
                
                if(ret != 0)
                        return NULL;
                
                out_tile->data_len = size;
                memcpy(out_tile->data, compressed, size);
        }
        
        return out;
}