[vlc-commits] [Git][videolan/vlc][master] 2 commits: fourcc: allow smaller than 4 chars strings in vlc_fourcc_GetCodecFromString

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Dec 1 09:38:41 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
188a56a9 by Steve Lhomme at 2023-12-01T09:16:00+00:00
fourcc: allow smaller than 4 chars strings in vlc_fourcc_GetCodecFromString

vlc_fourcc_GetCodecFromString() is used to turn FourCC strings into a
VLC FourCC. Some accepted string found in fourcc_list.h can have space
character padding at the end, see fourcc_list.h. We should always allow
the mapping to work.

- - - - -
13927c42 by Steve Lhomme at 2023-12-01T09:16:00+00:00
transcode: pass the FourCC strings directly

vlc_fourcc_GetCodecFromString() checks the string has the exact size needed.

- - - - -


3 changed files:

- include/vlc_fourcc.h
- modules/stream_out/transcode/transcode.c
- src/misc/fourcc.c


Changes:

=====================================
include/vlc_fourcc.h
=====================================
@@ -737,8 +737,11 @@ VLC_API vlc_fourcc_t vlc_fourcc_GetCodec( int i_cat, vlc_fourcc_t i_fourcc );
  * It returns the codec associated to a fourcc stored in a zero terminated
  * string.
  *
- * If the string is NULL or does not have exactly 4 characters, it will
- * return 0, otherwise it behaves like vlc_fourcc_GetCodec.
+ * If the string is NULL or has more than 4 characters or doesn't correspond
+ * to a string associated with a VLC_CODEC_, it will return 0, otherwise it
+ * will one of the VLC_CODEC_ defined above.
+ *
+ * You may use UNKNOWN_ES for the ES category if you don't have the information.
  *
  * Provided for convenience.
  */


=====================================
modules/stream_out/transcode/transcode.c
=====================================
@@ -254,11 +254,9 @@ static void SetAudioEncoderConfig( sout_stream_t *p_stream, transcode_encoder_co
     p_cfg->i_codec = 0;
     if( psz_string && *psz_string )
     {
-        char fcc[5] = "    \0";
-        memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) );
-        p_cfg->i_codec = vlc_fourcc_GetCodecFromString( AUDIO_ES, fcc );
+        p_cfg->i_codec = vlc_fourcc_GetCodecFromString( AUDIO_ES, psz_string );
         msg_Dbg( p_stream, "Checking codec mapping for %s got %4.4s ",
-                            fcc, (char*)&p_cfg->i_codec);
+                            psz_string, (char*)&p_cfg->i_codec);
     }
     free( psz_string );
 
@@ -304,11 +302,9 @@ static void SetVideoEncoderConfig( sout_stream_t *p_stream, transcode_encoder_co
     psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "vcodec" );
     if( psz_string && *psz_string )
     {
-        char fcc[5] = "    \0";
-        memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) );
-        p_cfg->i_codec = vlc_fourcc_GetCodecFromString( VIDEO_ES, fcc );
+        p_cfg->i_codec = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_string );
         msg_Dbg( p_stream, "Checking video codec mapping for %s got %4.4s ",
-                 fcc, (char*)&p_cfg->i_codec);
+                 psz_string, (char*)&p_cfg->i_codec);
     }
     free( psz_string );
 
@@ -346,10 +342,8 @@ static void SetSPUEncoderConfig( sout_stream_t *p_stream, transcode_encoder_conf
     psz_string = var_GetString( p_stream, SOUT_CFG_PREFIX "scodec" );
     if( psz_string && *psz_string )
     {
-        char fcc[5] = "    \0";
-        memcpy( fcc, psz_string, __MIN( strlen( psz_string ), 4 ) );
-        p_cfg->i_codec = vlc_fourcc_GetCodecFromString( SPU_ES, fcc );
-        msg_Dbg( p_stream, "Checking spu codec mapping for %s got %4.4s ", fcc, (char*)&p_cfg->i_codec);
+        p_cfg->i_codec = vlc_fourcc_GetCodecFromString( SPU_ES, psz_string );
+        msg_Dbg( p_stream, "Checking spu codec mapping for %s got %4.4s ", psz_string, (char*)&p_cfg->i_codec);
     }
     free( psz_string );
 


=====================================
src/misc/fourcc.c
=====================================
@@ -117,11 +117,16 @@ vlc_fourcc_t vlc_fourcc_GetCodec(int cat, vlc_fourcc_t fourcc)
 
 vlc_fourcc_t vlc_fourcc_GetCodecFromString( int i_cat, const char *psz_fourcc )
 {
-    if( !psz_fourcc || strlen(psz_fourcc) != 4 )
+    if( psz_fourcc == NULL )
+        return 0;
+    size_t s = strlen(psz_fourcc);
+    if (s > 4)
         return 0;
     return vlc_fourcc_GetCodec( i_cat,
-                                VLC_FOURCC( psz_fourcc[0], psz_fourcc[1],
-                                            psz_fourcc[2], psz_fourcc[3] ) );
+                                VLC_FOURCC( psz_fourcc[0],
+                                             s > 1 ? psz_fourcc[1] : ' ',
+                                             s > 2 ? psz_fourcc[2] : ' ',
+                                             s > 3 ? psz_fourcc[3] : ' ') );
 }
 
 vlc_fourcc_t vlc_fourcc_GetCodecAudio( vlc_fourcc_t i_fourcc, int i_bits )



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e77ef32a056f1e2ac0b1b502dcdaff15fe44b967...13927c42b448779de7bfa535bb5d3e480d2ed2cb

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e77ef32a056f1e2ac0b1b502dcdaff15fe44b967...13927c42b448779de7bfa535bb5d3e480d2ed2cb
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