Exemplo n.º 1
0
static void configure_with(struct state_decompress *decompressor, struct video_desc desc)
{
        enum dxt_type type;

#ifndef HAVE_MACOSX
        printf("[RTDXT] Trying OpenGL 3.1 context first.\n");
        decompressor->gl_context = glx_init(MK_OPENGL_VERSION(3,1));
        decompressor->legacy = FALSE;
        if(!decompressor->gl_context) {
                fprintf(stderr, "[RTDXT] OpenGL 3.1 profile failed to initialize, falling back to legacy profile.\n");
                decompressor->gl_context = glx_init(OPENGL_VERSION_UNSPECIFIED);
                decompressor->legacy = TRUE;
        }
        glx_validate(decompressor->gl_context);
#else
        decompressor->gl_context = NULL;
        if(get_mac_kernel_version_major() >= 11) {
                printf("[RTDXT] Mac 10.7 or latter detected. Trying OpenGL 3.2 Core profile first.\n");
                decompressor->gl_context = mac_gl_init(MAC_GL_PROFILE_3_2);
                if(!decompressor->gl_context) {
                        fprintf(stderr, "[RTDXT] OpenGL 3.2 Core profile failed to initialize, falling back to legacy profile.\n");
                } else {
                        decompressor->legacy = FALSE;
                }
        }

        if(!decompressor->gl_context) {
                decompressor->gl_context = mac_gl_init(MAC_GL_PROFILE_LEGACY);
                decompressor->legacy = TRUE;
        }
#endif
        if(!decompressor->gl_context) {
                fprintf(stderr, "[RTDXT decompress] Failed to create GL context.");
                exit_uv(128);
                decompressor->compressed_len = 0;
                return;
        }

        if(desc.color_spec == DXT5) {
                type = DXT_TYPE_DXT5_YCOCG;
        } else if(desc.color_spec == DXT1) {
                type = DXT_TYPE_DXT1;
        } else if(desc.color_spec == DXT1_YUV) {
                type = DXT_TYPE_DXT1_YUV;
        } else {
                fprintf(stderr, "Wrong compressiong to decompress.\n");
                return;
        }
        
        decompressor->desc = desc;

        decompressor->decoder = dxt_decoder_create(type, desc.width,
                        desc.height, decompressor->out_codec == RGBA ? DXT_FORMAT_RGBA : DXT_FORMAT_YUV422, decompressor->legacy);

        assert(decompressor->decoder != NULL);
        
        decompressor->compressed_len = dxt_get_size(desc.width, desc.height, type);
        decompressor->configured = TRUE;
}
Exemplo n.º 2
0
static int configure_with(struct state_video_compress_rtdxt *s, struct video_frame *frame)
{
        unsigned int x;
        enum dxt_format format;
        int i;
        
        for (i = 0; i < 2; ++i) {
                s->out[i] = vf_alloc(frame->tile_count);
        }
        
        for (x = 0; x < frame->tile_count; ++x) {
                if (vf_get_tile(frame, x)->width != vf_get_tile(frame, 0)->width ||
                                vf_get_tile(frame, x)->width != vf_get_tile(frame, 0)->width) {

                        fprintf(stderr,"[RTDXT] Requested to compress tiles of different size!");
                        //exit_uv(128);
                        return FALSE;
                }
        }
        
        for (i = 0; i < 2; ++i) {
                s->out[i]->fps = frame->fps;
                s->out[i]->color_spec = s->color_spec;

                for (x = 0; x < frame->tile_count; ++x) {
                        vf_get_tile(s->out[i], x)->width = vf_get_tile(frame, 0)->width;
                        vf_get_tile(s->out[i], x)->height = vf_get_tile(frame, 0)->height;
                }
        }

        switch (frame->color_spec) {
                case RGB:
                        s->decoder = (decoder_t) memcpy;
                        format = DXT_FORMAT_RGB;
                        break;
                case RGBA:
                        s->decoder = (decoder_t) memcpy;
                        format = DXT_FORMAT_RGBA;
                        break;
                case R10k:
                        s->decoder = (decoder_t) vc_copyliner10k;
                        format = DXT_FORMAT_RGBA;
                        break;
                case YUYV:
                        s->decoder = (decoder_t) vc_copylineYUYV;
                        format = DXT_FORMAT_YUV422;
                        break;
                case UYVY:
                case Vuy2:
                case DVS8:
                        s->decoder = (decoder_t) memcpy;
                        format = DXT_FORMAT_YUV422;
                        break;
                case v210:
                        s->decoder = (decoder_t) vc_copylinev210;
                        format = DXT_FORMAT_YUV422;
                        break;
                case DVS10:
                        s->decoder = (decoder_t) vc_copylineDVS10;
                        format = DXT_FORMAT_YUV422;
                        break;
                case DPX10:        
                        s->decoder = (decoder_t) vc_copylineDPX10toRGBA;
                        format = DXT_FORMAT_RGBA;
                        break;
                default:
                        fprintf(stderr, "[RTDXT] Unknown codec: %d\n", frame->color_spec);
                        //exit_uv(128);
                        return FALSE;
        }

        /* We will deinterlace the output frame */
        if(frame->interlacing  == INTERLACED_MERGED) {
                for (i = 0; i < 2; ++i) {
                        s->out[i]->interlacing = PROGRESSIVE;
                }
                s->interlaced_input = TRUE;
                fprintf(stderr, "[DXT compress] Enabling automatic deinterlacing.\n");
        } else {
                for (i = 0; i < 2; ++i) {
                        s->out[i]->interlacing = frame->interlacing;
                }
                s->interlaced_input = FALSE;
        }
        
        int data_len = 0;

        s->encoder = malloc(frame->tile_count * sizeof(struct dxt_encoder *));
        if(s->out[0]->color_spec == DXT1) {
                for(int i = 0; i < (int) frame->tile_count; ++i) {
                        s->encoder[i] =
                                dxt_encoder_create(DXT_TYPE_DXT1, s->out[0]->tiles[0].width, s->out[0]->tiles[0].height, format,
                                                s->gl_context.legacy);
                }
                data_len = dxt_get_size(s->out[0]->tiles[0].width, s->out[0]->tiles[0].height, DXT_TYPE_DXT1);
        } else if(s->out[0]->color_spec == DXT5){
                for(int i = 0; i < (int) frame->tile_count; ++i) {
                        s->encoder[i] =
                                dxt_encoder_create(DXT_TYPE_DXT5_YCOCG, s->out[0]->tiles[0].width, s->out[0]->tiles[0].height, format,
                                                s->gl_context.legacy);
                }
                data_len = dxt_get_size(s->out[0]->tiles[0].width, s->out[0]->tiles[0].height, DXT_TYPE_DXT5_YCOCG);
        }

        for(int i = 0; i < (int) frame->tile_count; ++i) {
                if(s->encoder[i] == NULL) {
                        fprintf(stderr, "[RTDXT] Unable to create decoder.\n");
                        //exit_uv(128);
                        return FALSE;
                }
        }

        s->encoder_input_linesize = s->out[0]->tiles[0].width;
        switch(format) { 
                case DXT_FORMAT_RGBA:
                        s->encoder_input_linesize *= 4;
                        break;
                case DXT_FORMAT_RGB:
                        s->encoder_input_linesize *= 3;
                        break;
                case DXT_FORMAT_YUV422:
                        s->encoder_input_linesize *= 2;
                        break;
                case DXT_FORMAT_YUV:
                        /* not used - just not compilator to complain */
                        abort();
                        break;
        }

        assert(data_len > 0);
        assert(s->encoder_input_linesize > 0);

        for (i = 0; i < 2; ++i) {
                for (x = 0; x < frame->tile_count; ++x) {
                        vf_get_tile(s->out[i], x)->data_len = data_len;
                        vf_get_tile(s->out[i], x)->data = (char *) malloc(data_len);
                }
        }
        
        s->decoded = malloc(4 * s->out[0]->tiles[0].width * s->out[0]->tiles[0].height);
        
        s->configured = TRUE;
        return TRUE;
}