[vlc-commits] image: read images from an es_format instead of video_format plus extra data

Steve Lhomme git at videolan.org
Fri Feb 8 14:00:39 CET 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Feb  8 09:12:07 2019 +0100| [5d3d9c809ed9be34a2951f60d926390183e9e715] | committer: Steve Lhomme

image: read images from an es_format instead of video_format plus extra data

In most cases the source was already an es_format anyway.

Get rid a redundant image_ReadExt().

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

 include/vlc_image.h           |  5 ++---
 modules/codec/oggspots.c      |  2 +-
 modules/codec/subsusf.c       |  9 +++++----
 modules/codec/ttml/substtml.c |  9 +++++----
 modules/demux/image.c         |  9 +++++----
 modules/demux/mp4/heif.c      |  4 ++--
 src/misc/image.c              | 44 ++++++++++++++++++++-----------------------
 7 files changed, 40 insertions(+), 42 deletions(-)

diff --git a/include/vlc_image.h b/include/vlc_image.h
index fafe0fbbd9..78a4ab98a4 100644
--- a/include/vlc_image.h
+++ b/include/vlc_image.h
@@ -38,7 +38,7 @@ extern "C" {
 struct image_handler_t
 {
     picture_t * (*pf_read)      ( image_handler_t *, block_t *,
-                                  const video_format_t *, const uint8_t *, size_t,
+                                  const es_format_t *,
                                   video_format_t * );
     picture_t * (*pf_read_url)  ( image_handler_t *, const char *,
                                   video_format_t * );
@@ -64,8 +64,7 @@ VLC_API image_handler_t * image_HandlerCreate( vlc_object_t * ) VLC_USED;
 #define image_HandlerCreate( a ) image_HandlerCreate( VLC_OBJECT(a) )
 VLC_API void image_HandlerDelete( image_handler_t * );
 
-#define image_Read( a, b, c, d ) a->pf_read( a, b, c, NULL, 0, d )
-#define image_ReadExt( a, b, c, d, e, f ) a->pf_read( a, b, c, d, e, f )
+#define image_Read( a, b, c, d ) a->pf_read( a, b, c, d )
 #define image_ReadUrl( a, b, c ) a->pf_read_url( a, b, c )
 #define image_Write( a, b, c, d ) a->pf_write( a, b, c, d )
 #define image_WriteUrl( a, b, c, d, e ) a->pf_write_url( a, b, c, d, e )
diff --git a/modules/codec/oggspots.c b/modules/codec/oggspots.c
index e39c7647df..fc54fe2b62 100644
--- a/modules/codec/oggspots.c
+++ b/modules/codec/oggspots.c
@@ -374,7 +374,7 @@ static picture_t* DecodePacket(decoder_t* p_dec, block_t* p_block)
     p_block->p_buffer += i_img_offset;
 
     p_pic = image_Read(p_sys->p_image, p_block,
-                       &p_dec->fmt_in.video,
+                       &p_dec->fmt_in,
                        &p_dec->fmt_out.video);
     if (p_pic == NULL) {
         return NULL;
diff --git a/modules/codec/subsusf.c b/modules/codec/subsusf.c
index 9131e3f693..c02c52b52f 100644
--- a/modules/codec/subsusf.c
+++ b/modules/codec/subsusf.c
@@ -507,12 +507,13 @@ static int ParseImageAttachments( decoder_t *p_dec )
 
                 if( p_block != NULL )
                 {
-                    video_format_t     fmt_in;
+                    es_format_t        es_in;
                     video_format_t     fmt_out;
 
                     memcpy( p_block->p_buffer, p_attach->p_data, p_attach->i_data );
 
-                    video_format_Init( &fmt_in,  type );
+                    es_format_Init( &es_in, VIDEO_ES, type );
+                    es_in.video.i_chroma = type;
                     video_format_Init( &fmt_out, VLC_CODEC_YUVA );
 
                     /* Find a suitable decoder module */
@@ -525,9 +526,9 @@ static int ParseImageAttachments( decoder_t *p_dec )
                         var_SetString( p_dec, "codec", "sdl_image" );
                     }
 
-                    p_pic = image_Read( p_image, p_block, &fmt_in, &fmt_out );
+                    p_pic = image_Read( p_image, p_block, &es_in, &fmt_out );
                     var_Destroy( p_dec, "codec" );
-                    video_format_Clean( &fmt_in );
+                    es_format_Clean( &es_in );
                     video_format_Clean( &fmt_out );
                 }
 
diff --git a/modules/codec/ttml/substtml.c b/modules/codec/ttml/substtml.c
index 0320858788..4c8240fefe 100644
--- a/modules/codec/ttml/substtml.c
+++ b/modules/codec/ttml/substtml.c
@@ -1161,8 +1161,9 @@ static picture_t * picture_CreateFromPNG( decoder_t *p_dec,
         return NULL;
     video_format_t fmt_out;
     video_format_Init( &fmt_out, VLC_CODEC_YUVA );
-    video_format_t fmt_in;
-    video_format_Init( &fmt_in, VLC_CODEC_PNG );
+    es_format_t es_in;
+    es_format_Init( &es_in, VIDEO_ES, VLC_CODEC_PNG );
+    es_in.video.i_chroma = es_in.i_codec;
 
     block_t *p_block = block_Alloc( i_data );
     if( !p_block )
@@ -1175,12 +1176,12 @@ static picture_t * picture_CreateFromPNG( decoder_t *p_dec,
     image_handler_t *p_image = image_HandlerCreate( p_dec );
     if( p_image )
     {
-        p_pic = image_Read( p_image, p_block, &fmt_in, &fmt_out );
+        p_pic = image_Read( p_image, p_block, &es_in, &fmt_out );
         image_HandlerDelete( p_image );
     }
     else block_Release( p_block );
     p_dec->obj.flags = i_flags;
-    video_format_Clean( &fmt_in );
+    es_format_Clean( &es_in );
     video_format_Clean( &fmt_out );
 
     return p_pic;
diff --git a/modules/demux/image.c b/modules/demux/image.c
index d966f96d2d..464f8f3eab 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -137,7 +137,7 @@ static block_t *Load(demux_t *demux)
 }
 
 static block_t *Decode(demux_t *demux,
-                       video_format_t *fmt, vlc_fourcc_t chroma, block_t *data)
+                       es_format_t *fmt, vlc_fourcc_t chroma, block_t *data)
 {
     image_handler_t *handler = image_HandlerCreate(demux);
     if (!handler) {
@@ -154,8 +154,9 @@ static block_t *Decode(demux_t *demux,
     if (!image)
         return NULL;
 
-    video_format_Clean(fmt);
-    *fmt = decoded;
+    es_format_Clean(fmt);
+    es_format_InitFromVideo(fmt, &decoded);
+    video_format_Clean(&decoded);
 
     size_t size = 0;
     for (int i = 0; i < image->i_planes; i++)
@@ -697,7 +698,7 @@ static int Open(vlc_object_t *object)
         vlc_fourcc_t chroma = vlc_fourcc_GetCodecFromString(VIDEO_ES, string);
         free(string);
 
-        data = Decode(demux, &fmt.video, chroma, data);
+        data = Decode(demux, &fmt, chroma, data);
         fmt.i_codec = fmt.video.i_chroma;
     }
     fmt.i_id    = var_InheritInteger(demux, "image-id");
diff --git a/modules/demux/mp4/heif.c b/modules/demux/mp4/heif.c
index e2a236f8da..18ad595e72 100644
--- a/modules/demux/mp4/heif.c
+++ b/modules/demux/mp4/heif.c
@@ -565,8 +565,8 @@ static int LoadGridImage( demux_t *p_demux, uint32_t i_pic_item_id,
     video_format_Init( &decoded, VLC_CODEC_RGBA );
 
     fmt.video.i_chroma = fmt.i_codec;
-    picture_t *p_picture = image_ReadExt( handler, p_sample, &fmt.video,
-                                          fmt.p_extra, fmt.i_extra, &decoded );
+
+    picture_t *p_picture = image_Read( handler, p_sample, &fmt, &decoded );
     image_HandlerDelete( handler );
 
     es_format_Clean( &fmt );
diff --git a/src/misc/image.c b/src/misc/image.c
index e987c98bcf..b9482b8700 100644
--- a/src/misc/image.c
+++ b/src/misc/image.c
@@ -60,7 +60,7 @@ static inline struct decoder_owner *dec_get_owner( decoder_t *p_dec )
 }
 
 static picture_t *ImageRead( image_handler_t *, block_t *,
-                             const video_format_t *, const uint8_t *, size_t,
+                             const es_format_t *,
                              video_format_t * );
 static picture_t *ImageReadUrl( image_handler_t *, const char *,
                                 video_format_t * );
@@ -72,8 +72,7 @@ static int ImageWriteUrl( image_handler_t *, picture_t *,
 static picture_t *ImageConvert( image_handler_t *, picture_t *,
                                 const video_format_t *, video_format_t * );
 
-static decoder_t *CreateDecoder( image_handler_t *, const video_format_t *,
-                                 const uint8_t *, size_t );
+static decoder_t *CreateDecoder( image_handler_t *, const es_format_t * );
 static void DeleteDecoder( decoder_t * );
 static encoder_t *CreateEncoder( vlc_object_t *, const video_format_t *,
                                  const video_format_t * );
@@ -140,15 +139,20 @@ static void ImageQueueVideo( decoder_t *p_dec, picture_t *p_pic )
 }
 
 static picture_t *ImageRead( image_handler_t *p_image, block_t *p_block,
-                             const video_format_t *p_fmt_in,
-                             const uint8_t *p_extra, size_t i_extra,
+                             const es_format_t *p_es_in,
                              video_format_t *p_fmt_out )
 {
     picture_t *p_pic = NULL;
 
+    if ( p_es_in->i_cat != VIDEO_ES )
+    {
+        block_Release(p_block);
+        return NULL;
+    }
+
     /* Check if we can reuse the current decoder */
     if( p_image->p_dec &&
-        p_image->p_dec->fmt_in.i_codec != p_fmt_in->i_chroma )
+        p_image->p_dec->fmt_in.i_codec != p_es_in->video.i_chroma )
     {
         DeleteDecoder( p_image->p_dec );
         p_image->p_dec = 0;
@@ -157,8 +161,7 @@ static picture_t *ImageRead( image_handler_t *p_image, block_t *p_block,
     /* Start a decoder */
     if( !p_image->p_dec )
     {
-        p_image->p_dec = CreateDecoder( p_image, p_fmt_in,
-                                        p_extra, i_extra );
+        p_image->p_dec = CreateDecoder( p_image, p_es_in );
         if( !p_image->p_dec )
         {
             block_Release(p_block);
@@ -299,26 +302,26 @@ static picture_t *ImageReadUrl( image_handler_t *p_image, const char *psz_url,
     if( p_block == NULL )
         goto error;
 
-    video_format_t fmtin;
-    video_format_Init( &fmtin, 0 ); /* no chroma, the MIME type of the picture will be used */
+    es_format_t fmtin;
+    es_format_Init( &fmtin, VIDEO_ES, 0 ); /* no chroma, the MIME type of the picture will be used */
 
     char *psz_mime = stream_MimeType( p_stream );
     if( psz_mime != NULL )
     {
-        fmtin.i_chroma = image_Mime2Fourcc( psz_mime );
+        fmtin.video.i_chroma = image_Mime2Fourcc( psz_mime );
         free( psz_mime );
     }
-    if( !fmtin.i_chroma )
+    if( !fmtin.video.i_chroma )
     {
        /* Try to guess format from file name */
-       fmtin.i_chroma = image_Ext2Fourcc( psz_url );
+       fmtin.video.i_chroma = image_Ext2Fourcc( psz_url );
     }
     vlc_stream_Delete( p_stream );
 
 
-    p_pic = ImageRead( p_image, p_block, &fmtin, NULL, 0, p_fmt_out );
+    p_pic = ImageRead( p_image, p_block, &fmtin, p_fmt_out );
 
-    video_format_Clean( &fmtin );
+    es_format_Clean( &fmtin );
 
     return p_pic;
 error:
@@ -658,8 +661,7 @@ static picture_t *video_new_buffer( decoder_t *p_dec )
     return picture_NewFromFormat( &p_dec->fmt_out.video );
 }
 
-static decoder_t *CreateDecoder( image_handler_t *p_image, const video_format_t *fmt,
-                                 const uint8_t *p_extra, size_t i_extra )
+static decoder_t *CreateDecoder( image_handler_t *p_image, const es_format_t *fmt )
 {
     decoder_t *p_dec;
     struct decoder_owner *p_owner;
@@ -672,13 +674,7 @@ static decoder_t *CreateDecoder( image_handler_t *p_image, const video_format_t
 
     p_dec->p_module = NULL;
 
-    es_format_t es_fmt;
-    es_format_InitFromVideo( &es_fmt, fmt );
-    if ( es_fmt.p_extra ) free( es_fmt.p_extra );
-    es_fmt.p_extra = p_extra;
-    es_fmt.i_extra = i_extra;
-
-    es_format_Copy( &p_dec->fmt_in, &es_fmt );
+    es_format_Copy( &p_dec->fmt_in, fmt );
     es_format_Init( &p_dec->fmt_out, VIDEO_ES, 0 );
     p_dec->b_frame_drop_allowed = false;
 



More information about the vlc-commits mailing list