Пример #1
0
struct video_export * video_export_init(char *path)
{
        struct video_export *s;

        s = (struct video_export *) malloc(sizeof(struct video_export));
        assert(s != NULL);

        platform_sem_init(&s->semaphore, 0, 0);
        pthread_mutex_init(&s->lock, NULL);
        s->total = s->queue_len = 0;
        assert(path != NULL);
        s->path = path;
        s->head = s->tail = NULL;

        memset(&s->saved_desc, 0, sizeof(s->saved_desc));

        if(pthread_create(&s->thread_id, NULL, video_export_thread, s) != 0) {
                fprintf(stderr, "[Video exporter] Failed to create thread.\n");
                free(s);
                return NULL;
        }

        return s;
}
Пример #2
0
void *fastdxt_init(char *num_threads_str)
{
        /* This function does the following:
         * 1. Allocate memory for buffers 
         * 2. Spawn compressor threads
         */
        int x;
        int i;
        struct video_compress *compress;

        if(num_threads_str && strcmp(num_threads_str, "help") == 0) {
                printf("FastDXT usage:\n");
                printf("\t-FastDXT[:<num_threads>]\n");
                printf("\t\t<num_threads> - count of compress threads (default %d)\n", NUM_THREADS_DEFAULT);
                return NULL;
        }

        compress = calloc(1, sizeof(struct video_compress));
        /* initial values */
        compress->num_threads = 0;
        if(num_threads_str == NULL)
                compress->num_threads = NUM_THREADS_DEFAULT;
        else
                compress->num_threads = atoi(num_threads_str);
        assert (compress->num_threads >= 1 && compress->num_threads <= MAX_THREADS);

        for(i = 0; i < 2; ++i) {
                compress->out[i] = vf_alloc(1);
                compress->tile[i] = vf_get_tile(compress->out[i], 0);
        }
        
        for(i = 0; i < 2; ++i) {
                compress->tile[i]->width = 0;
                compress->tile[i]->height = 0;
        }

        compress->thread_count = 0;
        if (pthread_mutex_init(&(compress->lock), NULL)) {
                perror("Error initializing mutex!");
                return NULL;
        }

        for (x = 0; x < compress->num_threads; x++) {
                platform_sem_init(&compress->thread_compress[x], 0, 0);
                platform_sem_init(&compress->thread_done[x], 0, 0);
        }

        pthread_mutex_lock(&(compress->lock));

        for (x = 0; x < compress->num_threads; x++) {
                if (pthread_create
                    (&(compress->thread_ids[x]), NULL, (void *)compress_thread,
                     (void *)compress)) {
                        perror("Unable to create compressor thread!");
                        exit_uv(x);
                        return NULL;
                }
        }
        pthread_mutex_unlock(&(compress->lock));
        
        while(compress->num_threads != compress->thread_count) /* wait for all threads online */
                ;
        fprintf(stderr, "All compression threads are online.\n");
        
        return compress;
}