[vlc-commits] codec/jpeg: move some setup in init function

Maxim Bublis git at videolan.org
Fri Jan 31 12:45:33 CET 2014


vlc | branch: master | Maxim Bublis <b at codemonkey.ru> | Thu Jan 30 15:21:55 2014 +0400| [0d75e9fadad423a49706e71e4f75ce555fe0c9fd] | committer: Rafaël Carré

codec/jpeg: move some setup in init function

Signed-off-by: Rafaël Carré <funman at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0d75e9fadad423a49706e71e4f75ce555fe0c9fd
---

 modules/codec/jpeg.c |  128 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 76 insertions(+), 52 deletions(-)

diff --git a/modules/codec/jpeg.c b/modules/codec/jpeg.c
index ad09d56..fb67f66 100644
--- a/modules/codec/jpeg.c
+++ b/modules/codec/jpeg.c
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * jpeg.c: jpeg decoder module making use of libjpeg.
  *****************************************************************************
- * Copyright (C) 2013 VLC authors and VideoLAN
+ * Copyright (C) 2013-2014 VLC authors and VideoLAN
  *
  * Authors: Maxim Bublis <b at codemonkey.ru>
  *
@@ -30,18 +30,39 @@
 #include <jpeglib.h>
 #include <setjmp.h>
 
+/* JPEG_SYS_COMMON_MEMBERS:
+ * members common to encoder and decoder descriptors
+ */
+#define JPEG_SYS_COMMON_MEMBERS                             \
+/**@{*/                                                     \
+    /* libjpeg error handler manager */                     \
+    struct jpeg_error_mgr err;                              \
+                                                            \
+    /* setjmp buffer for internal libjpeg error handling */ \
+    jmp_buf setjmp_buffer;                                  \
+                                                            \
+    vlc_object_t *p_obj;                                    \
+                                                            \
+/**@}*/                                                     \
+
+/*
+ * jpeg common descriptor
+ */
+struct jpeg_sys_t
+{
+    JPEG_SYS_COMMON_MEMBERS
+};
+
+typedef struct jpeg_sys_t jpeg_sys_t;
+
 /*
  * jpeg decoder descriptor
  */
 struct decoder_sys_t
 {
-    /* libjpeg error handler manager */
-    struct jpeg_error_mgr err;
+    JPEG_SYS_COMMON_MEMBERS
 
-    /* setjmp buffer for internal libjpeg error handling */
-    jmp_buf setjmp_buffer;
-
-    decoder_t *p_dec;
+    struct jpeg_decompress_struct p_jpeg;
 };
 
 static int  OpenDecoder(vlc_object_t *);
@@ -61,6 +82,29 @@ vlc_module_begin()
     add_shortcut("jpeg")
 vlc_module_end()
 
+
+/*
+ * Exit error handler for libjpeg
+ */
+static void user_error_exit(j_common_ptr p_jpeg)
+{
+    jpeg_sys_t *p_sys = (jpeg_sys_t *)p_jpeg->err;
+    p_sys->err.output_message(p_jpeg);
+    longjmp(p_sys->setjmp_buffer, 1);
+}
+
+/*
+ * Emit message error handler for libjpeg
+ */
+static void user_error_message(j_common_ptr p_jpeg)
+{
+    char error_msg[JMSG_LENGTH_MAX];
+
+    jpeg_sys_t *p_sys = (jpeg_sys_t *)p_jpeg->err;
+    p_sys->err.format_message(p_jpeg, error_msg);
+    msg_Err(p_sys->p_obj, "%s", error_msg);
+}
+
 /*
  * Probe the decoder and return score
  */
@@ -74,13 +118,19 @@ static int OpenDecoder(vlc_object_t *p_this)
     }
 
     /* Allocate the memory needed to store the decoder's structure */
-    p_dec->p_sys = malloc(sizeof(decoder_sys_t));
-    if (p_dec->p_sys == NULL)
+    decoder_sys_t *p_sys = malloc(sizeof(decoder_sys_t));
+    if (p_sys == NULL)
     {
         return VLC_ENOMEM;
     }
 
-    p_dec->p_sys->p_dec = p_dec;
+    p_dec->p_sys = p_sys;
+
+    p_sys->p_obj = p_this;
+
+    p_sys->p_jpeg.err = jpeg_std_error(&p_sys->err);
+    p_sys->err.error_exit = user_error_exit;
+    p_sys->err.output_message = user_error_message;
 
     /* Set output properties */
     p_dec->fmt_out.i_cat = VIDEO_ES;
@@ -92,28 +142,6 @@ static int OpenDecoder(vlc_object_t *p_this)
 }
 
 /*
- * Exit error handler for libjpeg
- */
-static void user_error_exit(j_common_ptr p_jpeg)
-{
-    decoder_sys_t *p_sys = (decoder_sys_t *)p_jpeg->err;
-    p_sys->err.output_message(p_jpeg);
-    longjmp(p_sys->setjmp_buffer, 1);
-}
-
-/*
- * Emit message error handler for libjpeg
- */
-static void user_error_message(j_common_ptr p_jpeg)
-{
-    char error_msg[JMSG_LENGTH_MAX];
-
-    decoder_sys_t *p_sys = (decoder_sys_t *)p_jpeg->err;
-    p_sys->err.format_message(p_jpeg, error_msg);
-    msg_Err(p_sys->p_dec, "%s", error_msg);
-}
-
-/*
  * This function must be fed with a complete compressed frame.
  */
 static picture_t *DecodeBlock(decoder_t *p_dec, block_t **pp_block)
@@ -122,7 +150,6 @@ static picture_t *DecodeBlock(decoder_t *p_dec, block_t **pp_block)
     block_t *p_block;
     picture_t *p_pic = 0;
 
-    struct jpeg_decompress_struct p_jpeg;
     JSAMPARRAY p_row_pointers = NULL;
 
     if (!pp_block || !*pp_block)
@@ -139,28 +166,24 @@ static picture_t *DecodeBlock(decoder_t *p_dec, block_t **pp_block)
         return NULL;
     }
 
-    p_jpeg.err = jpeg_std_error(&p_sys->err);
-    p_sys->err.error_exit = user_error_exit;
-    p_sys->err.output_message = user_error_message;
-
     /* libjpeg longjmp's there in case of error */
     if (setjmp(p_sys->setjmp_buffer))
     {
         goto error;
     }
 
-    jpeg_create_decompress(&p_jpeg);
-    jpeg_mem_src(&p_jpeg, p_block->p_buffer, p_block->i_buffer);
-    jpeg_read_header(&p_jpeg, TRUE);
+    jpeg_create_decompress(&p_sys->p_jpeg);
+    jpeg_mem_src(&p_sys->p_jpeg, p_block->p_buffer, p_block->i_buffer);
+    jpeg_read_header(&p_sys->p_jpeg, TRUE);
 
-    p_jpeg.out_color_space = JCS_RGB;
+    p_sys->p_jpeg.out_color_space = JCS_RGB;
 
-    jpeg_start_decompress(&p_jpeg);
+    jpeg_start_decompress(&p_sys->p_jpeg);
 
     /* Set output properties */
     p_dec->fmt_out.i_codec = VLC_CODEC_RGB24;
-    p_dec->fmt_out.video.i_width = p_jpeg.output_width;
-    p_dec->fmt_out.video.i_height = p_jpeg.output_height;
+    p_dec->fmt_out.video.i_width = p_sys->p_jpeg.output_width;
+    p_dec->fmt_out.video.i_height = p_sys->p_jpeg.output_height;
     p_dec->fmt_out.video.i_sar_num = 1;
     p_dec->fmt_out.video.i_sar_den = 1;
     p_dec->fmt_out.video.i_rmask = 0x000000ff;
@@ -175,23 +198,24 @@ static picture_t *DecodeBlock(decoder_t *p_dec, block_t **pp_block)
     }
 
     /* Decode picture */
-    p_row_pointers = malloc(sizeof(JSAMPROW) * p_jpeg.output_height);
+    p_row_pointers = malloc(sizeof(JSAMPROW) * p_sys->p_jpeg.output_height);
     if (!p_row_pointers)
     {
         goto error;
     }
-    for (unsigned i = 0; i < p_jpeg.output_height; i++) {
+    for (unsigned i = 0; i < p_sys->p_jpeg.output_height; i++) {
         p_row_pointers[i] = p_pic->p->p_pixels + p_pic->p->i_pitch * i;
     }
 
-    while (p_jpeg.output_scanline < p_jpeg.output_height)
+    while (p_sys->p_jpeg.output_scanline < p_sys->p_jpeg.output_height)
     {
-        jpeg_read_scanlines(&p_jpeg, p_row_pointers + p_jpeg.output_scanline,
-                                     p_jpeg.output_height - p_jpeg.output_scanline);
+        jpeg_read_scanlines(&p_sys->p_jpeg,
+                p_row_pointers + p_sys->p_jpeg.output_scanline,
+                p_sys->p_jpeg.output_height - p_sys->p_jpeg.output_scanline);
     }
 
-    jpeg_finish_decompress(&p_jpeg);
-    jpeg_destroy_decompress(&p_jpeg);
+    jpeg_finish_decompress(&p_sys->p_jpeg);
+    jpeg_destroy_decompress(&p_sys->p_jpeg);
     free(p_row_pointers);
 
     p_pic->date = p_block->i_pts > VLC_TS_INVALID ? p_block->i_pts : p_block->i_dts;
@@ -203,7 +227,7 @@ static picture_t *DecodeBlock(decoder_t *p_dec, block_t **pp_block)
 
 error:
 
-    jpeg_destroy_decompress(&p_jpeg);
+    jpeg_destroy_decompress(&p_sys->p_jpeg);
     free(p_row_pointers);
 
     block_Release(p_block);



More information about the vlc-commits mailing list