[vlc-commits] [Git][videolan/vlc][master] 2 commits: avcodec: return the AVPixelFormat in GetFfmpegChroma()

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Aug 21 07:22:56 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
38ad102b by Steve Lhomme at 2023-08-21T07:07:00+00:00
avcodec: return the AVPixelFormat in GetFfmpegChroma()

No need to use a pointer and an error code for that.

- - - - -
a309fb4c by Steve Lhomme at 2023-08-21T07:07:00+00:00
avcodec/chroma: prioritize RGB mapping with the same mask

If the mask corresponds exactly, we have an exact match. If the RGB source
has a mask but none of the RGB mapping uses the same mask, we map to
a close RGB format with a different mask.

It's better than using the first VLC_CODEC_RGBxx in the list if there's
one corresponding to the exact match.

Another option would be to move the VLC_RGB_ES() calls at the end of the
list.

- - - - -


5 changed files:

- modules/codec/avcodec/chroma.c
- modules/codec/avcodec/chroma.h
- modules/codec/avcodec/encoder.c
- modules/demux/avformat/mux.c
- modules/video_chroma/swscale.c


Changes:

=====================================
modules/codec/avcodec/chroma.c
=====================================
@@ -215,25 +215,33 @@ static const struct
 };
 
 /* FIXME special case the RGB formats */
-int GetFfmpegChroma( enum AVPixelFormat *restrict i_ffmpeg_chroma, const video_format_t *fmt )
+enum AVPixelFormat GetFfmpegChroma( const video_format_t *fmt )
 {
     for( int i = 0; chroma_table[i].i_chroma != 0; i++ )
     {
-        if( chroma_table[i].i_chroma == fmt->i_chroma )
+        if( chroma_table[i].i_chroma == fmt->i_chroma &&
+            chroma_table[i].i_rmask  == fmt->i_rmask &&
+            chroma_table[i].i_gmask  == fmt->i_gmask &&
+            chroma_table[i].i_bmask  == fmt->i_bmask )
         {
-            if( ( chroma_table[i].i_rmask == 0 &&
-                  chroma_table[i].i_gmask == 0 &&
-                  chroma_table[i].i_bmask == 0 ) ||
-                ( chroma_table[i].i_rmask == fmt->i_rmask &&
-                  chroma_table[i].i_gmask == fmt->i_gmask &&
-                  chroma_table[i].i_bmask == fmt->i_bmask ) )
+            return chroma_table[i].i_chroma_id;
+        }
+    }
+    // try again without the mask as they may not correspond exactly
+    if (fmt->i_rmask || fmt->i_gmask || fmt->i_bmask)
+    {
+        for( int i = 0; chroma_table[i].i_chroma != 0; i++ )
+        {
+            if( chroma_table[i].i_chroma == fmt->i_chroma &&
+                chroma_table[i].i_rmask == 0 &&
+                chroma_table[i].i_gmask == 0 &&
+                chroma_table[i].i_bmask == 0 )
             {
-                *i_ffmpeg_chroma = chroma_table[i].i_chroma_id;
-                return VLC_SUCCESS;
+                return chroma_table[i].i_chroma_id;
             }
         }
     }
-    return VLC_EGENERIC;
+    return AV_PIX_FMT_NONE;
 }
 
 vlc_fourcc_t FindVlcChroma( enum AVPixelFormat i_ffmpeg_id )


=====================================
modules/codec/avcodec/chroma.h
=====================================
@@ -28,7 +28,7 @@
 #include <libavutil/pixfmt.h>
 
 enum AVPixelFormat FindFfmpegChroma( vlc_fourcc_t );
-int GetFfmpegChroma( enum AVPixelFormat *i_ffmpeg_chroma, const video_format_t *fmt );
+enum AVPixelFormat GetFfmpegChroma( const video_format_t *fmt );
 
 vlc_fourcc_t FindVlcChroma( enum AVPixelFormat );
 int GetVlcChroma( video_format_t *fmt, enum AVPixelFormat i_ffmpeg_chroma );


=====================================
modules/codec/avcodec/encoder.c
=====================================
@@ -566,7 +566,7 @@ int InitVideoEnc( vlc_object_t *p_this )
             p_enc->fmt_in.i_codec = VLC_CODEC_RGB24;
 
         p_enc->fmt_in.video.i_chroma = p_enc->fmt_in.i_codec;
-        GetFfmpegChroma( &p_context->pix_fmt, &p_enc->fmt_in.video );
+        p_context->pix_fmt = GetFfmpegChroma( &p_enc->fmt_in.video );
 
         if( p_codec->pix_fmts )
         {
@@ -865,7 +865,7 @@ int InitVideoEnc( vlc_object_t *p_this )
     {
         /* XXX: hack: Force same codec (will be handled by transcode) */
         p_enc->fmt_in.video.i_chroma = p_enc->fmt_in.i_codec = p_enc->fmt_out.i_codec;
-        GetFfmpegChroma( &p_context->pix_fmt, &p_enc->fmt_in.video );
+        p_context->pix_fmt = GetFfmpegChroma( &p_enc->fmt_in.video );
     }
 
     /* Make sure we get extradata filled by the encoder */


=====================================
modules/demux/avformat/mux.c
=====================================
@@ -321,8 +321,8 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
             video_format_t vfmt;
             video_format_Copy(&vfmt, &fmt->video);
             video_format_FixRgb(&vfmt);
-            enum AVPixelFormat avformat = AV_PIX_FMT_NONE;
-            if(GetFfmpegChroma(&avformat, &vfmt))
+            enum AVPixelFormat avformat = GetFfmpegChroma(&vfmt);
+            if(avformat == AV_PIX_FMT_NONE)
                 msg_Warn(p_mux, "can't match format RAW video %4.4s",
                          (const char *)&vfmt.i_chroma);
             video_format_Clean(&vfmt);


=====================================
modules/video_chroma/swscale.c
=====================================
@@ -315,8 +315,8 @@ static int GetParameters( ScalerConfiguration *p_cfg,
                           const video_format_t *p_fmto,
                           int i_sws_flags_default )
 {
-    enum AVPixelFormat i_fmti = AV_PIX_FMT_NONE;
-    enum AVPixelFormat i_fmto = AV_PIX_FMT_NONE;
+    enum AVPixelFormat i_fmti;
+    enum AVPixelFormat i_fmto;
 
     bool b_has_ai = false;
     bool b_has_ao = false;
@@ -324,8 +324,8 @@ static int GetParameters( ScalerConfiguration *p_cfg,
     bool b_swap_uvi = false;
     bool b_swap_uvo = false;
 
-    GetFfmpegChroma( &i_fmti, p_fmti );
-    GetFfmpegChroma( &i_fmto, p_fmto );
+    i_fmti = GetFfmpegChroma( p_fmti );
+    i_fmto = GetFfmpegChroma( p_fmto );
 
     if( p_fmti->i_chroma == p_fmto->i_chroma )
     {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/181697c7b70ca46715d58db61c1ce571682465a1...a309fb4c10f238bb2319abe9ec489daa0c91521c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/181697c7b70ca46715d58db61c1ce571682465a1...a309fb4c10f238bb2319abe9ec489daa0c91521c
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list