Browse Source

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.
pull/162/head
Steve Lhomme 3 years ago
parent
commit
188a56a93c
  1. 7
      include/vlc_fourcc.h
  2. 11
      src/misc/fourcc.c

7
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.
*/

11
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 )

Loading…
Cancel
Save