int jpeg_decompress_reconfigure(void *state, struct video_desc desc, int rshift, int gshift, int bshift, int pitch, codec_t out_codec) { struct state_decompress_jpeg *s = (struct state_decompress_jpeg *) state; int ret; assert(out_codec == RGB || out_codec == UYVY); if(s->out_codec == out_codec && s->pitch == pitch && s->rshift == rshift && s->gshift == gshift && s->bshift == bshift && video_desc_eq_excl_param(s->desc, desc, PARAM_INTERLACING)) { return TRUE; } else { s->out_codec = out_codec; s->pitch = pitch; s->rshift = rshift; s->gshift = gshift; s->bshift = bshift; if(s->decoder) { gpujpeg_decoder_destroy(s->decoder); } return configure_with(s, desc); } }
void jpeg_to_dxt_decompress_done(void *state) { struct state_decompress_jpeg_to_dxt *s = (struct state_decompress_jpeg_to_dxt *) state; if(!state) { return; } pthread_mutex_lock(&s->lock); { should_exit_threads = true; for(unsigned int i = 0; i < cuda_devices_count; ++i) { if(s->worker_waiting[i]) { pthread_cond_signal(&s->worker_cv[i]); } } } pthread_mutex_unlock(&s->lock); for(unsigned int i = 0; i < cuda_devices_count; ++i) { pthread_join(s->thread_id[i], NULL); } for(unsigned int i = 0; i < cuda_devices_count; ++i) { if(s->jpeg_decoder[i]) { gpujpeg_decoder_destroy(s->jpeg_decoder[i]); } cudaFree(s->dxt_out_buff[i]); free(s->input[i]); free(s->output[i]); } free(s); }
void jpeg_decompress_done(void *state) { struct state_decompress_jpeg *s = (struct state_decompress_jpeg *) state; if(s->decoder) { gpujpeg_decoder_destroy(s->decoder); } free(s); }
/** Documented at declaration */ struct gpujpeg_decoder* gpujpeg_decoder_create() { struct gpujpeg_decoder* decoder = malloc(sizeof(struct gpujpeg_decoder)); if ( decoder == NULL ) return NULL; // Get coder struct gpujpeg_coder* coder = &decoder->coder; // Set parameters memset(decoder, 0, sizeof(struct gpujpeg_decoder)); gpujpeg_set_default_parameters(&coder->param); gpujpeg_image_set_default_parameters(&coder->param_image); coder->param_image.comp_count = 0; coder->param_image.width = 0; coder->param_image.height = 0; coder->param.restart_interval = 0; int result = 1; // Create reader decoder->reader = gpujpeg_reader_create(); if ( decoder->reader == NULL ) result = 0; // Allocate quantization tables in device memory for ( int comp_type = 0; comp_type < GPUJPEG_COMPONENT_TYPE_COUNT; comp_type++ ) { if ( cudaSuccess != cudaMalloc((void**)&decoder->table_quantization[comp_type].d_table, 64 * sizeof(uint16_t)) ) result = 0; } // Allocate huffman tables in device memory for ( int comp_type = 0; comp_type < GPUJPEG_COMPONENT_TYPE_COUNT; comp_type++ ) { for ( int huff_type = 0; huff_type < GPUJPEG_HUFFMAN_TYPE_COUNT; huff_type++ ) { if ( cudaSuccess != cudaMalloc((void**)&decoder->d_table_huffman[comp_type][huff_type], sizeof(struct gpujpeg_table_huffman_decoder)) ) result = 0; } } gpujpeg_cuda_check_error("Decoder table allocation"); // Init huffman encoder if ( gpujpeg_huffman_gpu_decoder_init() != 0 ) result = 0; if ( result == 0 ) { gpujpeg_decoder_destroy(decoder); return NULL; } // Timers GPUJPEG_CUSTOM_TIMER_CREATE(decoder->def); GPUJPEG_CUSTOM_TIMER_CREATE(decoder->in_gpu); return decoder; }
/** * @return maximal buffer size needed to image with such a properties */ int jpeg_to_dxt_decompress_reconfigure_real(void *state, struct video_desc desc, int rshift, int gshift, int bshift, int pitch, codec_t out_codec, int i) { UNUSED(rshift); UNUSED(gshift); UNUSED(bshift); struct state_decompress_jpeg_to_dxt *s = (struct state_decompress_jpeg_to_dxt *) state; assert(out_codec == DXT1 || out_codec == DXT5); assert(pitch == (int) desc.width / s->ppb); // default for DXT1 free(s->input[i]); free(s->output[i]); if(s->jpeg_decoder[i] != NULL) { gpujpeg_decoder_destroy(s->jpeg_decoder[i]); } else { gpujpeg_init_device(cuda_devices[i], 0); } if(s->dxt_out_buff[i] != NULL) { cudaFree(s->dxt_out_buff[i]); } if(cudaSuccess != cudaMallocHost((void **) &s->dxt_out_buff[i], desc.width * desc.height / s->ppb)) { fprintf(stderr, "Could not allocate CUDA output buffer.\n"); return 0; } //gpujpeg_init_device(cuda_device, GPUJPEG_OPENGL_INTEROPERABILITY); s->jpeg_decoder[i] = gpujpeg_decoder_create(); if(!s->jpeg_decoder[i]) { fprintf(stderr, "Creating JPEG decoder failed.\n"); return 0; } s->input[i] = malloc(desc.width * desc.height); s->output[i] = malloc(desc.width / s->ppb * desc.height); return desc.width * desc.height; }