From d85753b79e4ce0fa7a5ddac5b2ed0cf65f7aecd8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 27 Dec 2015 02:07:01 +0100 Subject: sub: refactor initialization Just simplify by removing parts not needed anymore. This includes merging dec_sub allocation and initialization (since things making initialization complicated were removed), or format support queries (it simply tries to create a decoder, and if that fails, tries the next one). --- sub/sd_lavc.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'sub/sd_lavc.c') diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index 86aaf4fda9..d9b9f507e7 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -64,21 +64,6 @@ struct sd_lavc_priv { int num_seekpoints; }; -static bool supports_format(const char *format) -{ - enum AVCodecID cid = mp_codec_to_av_codec_id(format); - // Supported codecs must be known to decode to paletted bitmaps - switch (cid) { - case AV_CODEC_ID_DVB_SUBTITLE: - case AV_CODEC_ID_HDMV_PGS_SUBTITLE: - case AV_CODEC_ID_XSUB: - case AV_CODEC_ID_DVD_SUBTITLE: - return true; - default: - return false; - } -} - static void get_resolution(struct sd *sd, int wh[2]) { struct sd_lavc_priv *priv = sd->priv; @@ -110,8 +95,20 @@ static void get_resolution(struct sd *sd, int wh[2]) static int init(struct sd *sd) { - struct sd_lavc_priv *priv = talloc_zero(NULL, struct sd_lavc_priv); enum AVCodecID cid = mp_codec_to_av_codec_id(sd->sh->codec); + + // Supported codecs must be known to decode to paletted bitmaps + switch (cid) { + case AV_CODEC_ID_DVB_SUBTITLE: + case AV_CODEC_ID_HDMV_PGS_SUBTITLE: + case AV_CODEC_ID_XSUB: + case AV_CODEC_ID_DVD_SUBTITLE: + break; + default: + return -1; + } + + struct sd_lavc_priv *priv = talloc_zero(NULL, struct sd_lavc_priv); AVCodecContext *ctx = NULL; AVCodec *sub_codec = avcodec_find_decoder(cid); if (!sub_codec) @@ -467,7 +464,6 @@ static int control(struct sd *sd, enum sd_ctrl cmd, void *arg) const struct sd_functions sd_lavc = { .name = "lavc", - .supports_format = supports_format, .init = init, .decode = decode, .get_bitmaps = get_bitmaps, -- cgit v1.2.3