[vlc-devel] [PATCH v2] codec: jpeg encoder implemented

Rafaël Carré funman at videolan.org
Tue Jan 28 15:01:27 CET 2014


On 01/28/14 14:46, Maxim Bublis wrote:
>>
>>> +}
>>> +
>>> +static block_t *EncodeBlock(encoder_t *p_enc, picture_t *p_pic)
>>> +{
>>> +    encoder_sys_t *p_sys = p_enc->p_sys;
>>> +
>>> +    const int bytesPerPixel = p_enc->fmt_out.video.i_bits_per_pixel ?
>>> +                                p_enc->fmt_out.video.i_bits_per_pixel /
>> 8 : 3;
>>
>> You should rather set *input* video format in Open
>>
>>> +    const int blocksize = bytesPerPixel *
>> p_enc->fmt_in.video.i_visible_width * p_enc->fmt_in.video.i_visible_height;
>>> +
>>> +    block_t *p_block = block_Alloc(blocksize);
>>> +    if (p_block == NULL)
>>> +    {
>>> +        return NULL;
>>> +    }
>>> +
>>> +    struct jpeg_compress_struct p_jpeg;
>>> +    JSAMPIMAGE p_row_pointers = NULL;
>>> +
>>> +    p_jpeg.err = jpeg_std_error(&p_sys->err);
>>> +    p_sys->err.error_exit = encoder_error_exit;
>>> +    p_sys->err.output_message = encoder_error_message;
>>> +
>>> +    /* libjpeg longjmp's there in case of error */
>>> +    if (setjmp(p_sys->setjmp_buffer))
>>> +    {
>>> +        goto error;
>>> +    }
>>> +
>>> +    jpeg_create_compress(&p_jpeg);
>>> +    jpeg_mem_dest(&p_jpeg, &p_block->p_buffer, &p_block->i_buffer);
>>> +
>>> +    p_jpeg.image_width = p_enc->fmt_in.video.i_visible_width;
>>> +    p_jpeg.image_height = p_enc->fmt_in.video.i_visible_height;
>>> +    p_jpeg.input_components = bytesPerPixel;
>>> +    p_jpeg.in_color_space = JCS_YCbCr;
>>> +
>>> +    jpeg_set_defaults(&p_jpeg);
>>> +    jpeg_set_colorspace(&p_jpeg, JCS_YCbCr);
>>> +
>>> +    p_jpeg.raw_data_in = TRUE;
>>> +    p_jpeg.do_fancy_downsampling = FALSE;
>>> +
>>> +    jpeg_set_quality(&p_jpeg, p_sys->i_quality, TRUE);
>>> +
>>> +    jpeg_start_compress(&p_jpeg, TRUE);
>>> +
>>
>> This should be done in Open, then you don't even need to store i_quality
>> and
>> both modules can use the same context.
> 
> 
> What will happen if some of jpeg_* functions in Open will call
> user_error_exit?
> Or what will happen if jpeg_destroy_decompress will call user_error_exit in
> CloseDecoder?
> Where will it longjmp?

Very good point.

I will study the libjpeg source code before answering



More information about the vlc-devel mailing list