[vlc-commits] avcodec: search codec mapping by category
Rémi Denis-Courmont
git at videolan.org
Sat Jun 17 17:32:04 CEST 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jun 17 18:21:54 2017 +0300| [2826791f59fbac64c1a62d08951fde9bfc2bb355] | committer: Rémi Denis-Courmont
avcodec: search codec mapping by category
Category is now an input rather than output parameter.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2826791f59fbac64c1a62d08951fde9bfc2bb355
---
modules/codec/avcodec/avcodec.c | 19 ++++++++----
modules/codec/avcodec/avcodec.h | 4 +--
modules/codec/avcodec/encoder.c | 21 ++++++++-----
modules/codec/avcodec/fourcc.c | 66 +++++++++++++++++++----------------------
4 files changed, 58 insertions(+), 52 deletions(-)
diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index 05626aecbd..3b60ef2434 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -258,12 +258,19 @@ static int OpenDecoder( vlc_object_t *p_this )
const AVCodec *p_codec = NULL;
/* *** determine codec type *** */
- if( !GetFfmpegCodec( p_dec->fmt_in.i_codec, &i_cat, &i_codec_id,
- &psz_namecodec )
- || i_cat == UNKNOWN_ES )
- {
+ if( GetFfmpegCodec( VIDEO_ES, p_dec->fmt_in.i_codec, &i_codec_id,
+ &psz_namecodec ) )
+ i_cat = VIDEO_ES;
+ else
+ if( GetFfmpegCodec( AUDIO_ES, p_dec->fmt_in.i_codec, &i_codec_id,
+ &psz_namecodec ) )
+ i_cat = AUDIO_ES;
+ else
+ if( GetFfmpegCodec( SPU_ES, p_dec->fmt_in.i_codec, &i_codec_id,
+ &psz_namecodec ) )
+ i_cat = SPU_ES;
+ else
return VLC_EGENERIC;
- }
msg_Dbg( p_this, "using %s %s", AVPROVIDER(LIBAVCODEC), LIBAVCODEC_IDENT );
@@ -315,7 +322,7 @@ static int OpenDecoder( vlc_object_t *p_this )
ret = InitSubtitleDec( p_dec, avctx, p_codec );
break;
default:
- ret = VLC_EGENERIC;
+ vlc_assert_unreachable();
}
if( ret != VLC_SUCCESS )
diff --git a/modules/codec/avcodec/avcodec.h b/modules/codec/avcodec/avcodec.h
index f09cdb1cd7..e7d47b889e 100644
--- a/modules/codec/avcodec/avcodec.h
+++ b/modules/codec/avcodec/avcodec.h
@@ -25,8 +25,8 @@
#include "avcommon.h"
/* VLC <-> avcodec tables */
-int GetFfmpegCodec( vlc_fourcc_t i_fourcc, int *pi_cat,
- unsigned *pi_ffmpeg_codec, const char **ppsz_name );
+bool GetFfmpegCodec( unsigned cat, vlc_fourcc_t i_fourcc,
+ unsigned *pi_ffmpeg_codec, const char **ppsz_name );
vlc_fourcc_t GetVlcFourcc( unsigned i_ffmpeg_codec );
vlc_fourcc_t GetVlcAudioFormat( int i_sample_fmt );
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 854dcb9383..a82afd6c9d 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -391,19 +391,24 @@ int OpenEncoder( vlc_object_t *p_this )
i_codec_id = AV_CODEC_ID_MPEG1VIDEO;
psz_namecodec = "MPEG-1 video";
}
- else if( !GetFfmpegCodec( p_enc->fmt_out.i_codec, &i_cat, &i_codec_id,
+ else if( GetFfmpegCodec( VIDEO_ES, p_enc->fmt_out.i_codec, &i_codec_id,
&psz_namecodec ) )
+ i_cat = VIDEO_ES;
+ else if( GetFfmpegCodec( AUDIO_ES, p_enc->fmt_out.i_codec, &i_codec_id,
+ &psz_namecodec ) )
+ i_cat = AUDIO_ES;
+ else if( GetFfmpegCodec( SPU_ES, p_enc->fmt_out.i_codec, &i_codec_id,
+ &psz_namecodec ) )
+ i_cat = SPU_ES;
+ else
+ if( FindFfmpegChroma( p_enc->fmt_out.i_codec ) != AV_PIX_FMT_NONE )
{
- if( FindFfmpegChroma( p_enc->fmt_out.i_codec ) == AV_PIX_FMT_NONE )
- return VLC_EGENERIC; /* handed chroma output */
-
- i_cat = VIDEO_ES;
+ i_cat = VIDEO_ES;
i_codec_id = AV_CODEC_ID_RAWVIDEO;
psz_namecodec = "Raw video";
}
-
- if( i_cat == UNKNOWN_ES )
- return VLC_EGENERIC;
+ else
+ return VLC_EGENERIC; /* handed chroma output */
if( p_enc->fmt_out.i_cat == VIDEO_ES && i_cat != VIDEO_ES )
{
diff --git a/modules/codec/avcodec/fourcc.c b/modules/codec/avcodec/fourcc.c
index ec8ccc1069..592edc25f9 100644
--- a/modules/codec/avcodec/fourcc.c
+++ b/modules/codec/avcodec/fourcc.c
@@ -490,51 +490,45 @@ static const struct vlc_avcodec_fourcc spu_codecs[] =
/* ffmpeg only: AV_CODEC_ID_ASS */
};
-int GetFfmpegCodec( vlc_fourcc_t i_fourcc, int *pi_cat,
- unsigned *pi_ffmpeg_codec, const char **ppsz_name )
+bool GetFfmpegCodec( unsigned cat, vlc_fourcc_t i_fourcc,
+ unsigned *pi_ffmpeg_codec, const char **ppsz_name )
{
- const struct vlc_avcodec_fourcc *mapping;
- unsigned cat;
+ const struct vlc_avcodec_fourcc *base;
+ size_t count;
- i_fourcc = vlc_fourcc_GetCodec( UNKNOWN_ES, i_fourcc );
-
- for( size_t i = 0; i < ARRAY_SIZE(video_codecs); i++ )
+ switch( cat )
{
- mapping = video_codecs + i;
- if( mapping->i_fourcc == i_fourcc )
- {
- cat = VIDEO_ES;
- goto found;
- }
+ case VIDEO_ES:
+ base = video_codecs;
+ count = ARRAY_SIZE(video_codecs);
+ break;
+ case AUDIO_ES:
+ base = audio_codecs;
+ count = ARRAY_SIZE(audio_codecs);
+ break;
+ case SPU_ES:
+ base = spu_codecs;
+ count = ARRAY_SIZE(spu_codecs);
+ break;
+ default:
+ base = NULL;
+ count = 0;
}
- for( size_t i = 0; i < ARRAY_SIZE(audio_codecs); i++ )
- {
- mapping = audio_codecs + i;
- if( mapping->i_fourcc == i_fourcc )
- {
- cat = AUDIO_ES;
- goto found;
- }
- }
- for( size_t i = 0; i < ARRAY_SIZE(spu_codecs); i++ )
+
+ i_fourcc = vlc_fourcc_GetCodec( cat, i_fourcc );
+
+ for( size_t i = 0; i < count; i++ )
{
- mapping = spu_codecs + i;
- if( mapping->i_fourcc == i_fourcc )
+ if( base[i].i_fourcc == i_fourcc )
{
- cat = SPU_ES;
- goto found;
+ if( pi_ffmpeg_codec != NULL )
+ *pi_ffmpeg_codec = base[i].i_codec;
+ if( ppsz_name )
+ *ppsz_name = vlc_fourcc_GetDescription( cat, i_fourcc );
+ return true;
}
}
return false;
-
-found:
- if( pi_cat != NULL )
- *pi_cat = cat;
- if( pi_ffmpeg_codec != NULL )
- *pi_ffmpeg_codec = mapping->i_codec;
- if( ppsz_name )
- *ppsz_name = vlc_fourcc_GetDescription( cat, i_fourcc );
- return true;
}
vlc_fourcc_t GetVlcFourcc( unsigned i_ffmpeg_codec )
More information about the vlc-commits
mailing list