| 1990 | } |
| 1991 | |
| 1992 | av_cold int ff_decode_preinit(AVCodecContext *avctx) |
| 1993 | { |
| 1994 | AVCodecInternal *avci = avctx->internal; |
| 1995 | DecodeContext *dc = decode_ctx(avci); |
| 1996 | int ret = 0; |
| 1997 | |
| 1998 | dc->initial_pict_type = AV_PICTURE_TYPE_NONE; |
| 1999 | if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) { |
| 2000 | dc->intra_only_flag = AV_FRAME_FLAG_KEY; |
| 2001 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) |
| 2002 | dc->initial_pict_type = AV_PICTURE_TYPE_I; |
| 2003 | } |
| 2004 | |
| 2005 | /* if the decoder init function was already called previously, |
| 2006 | * free the already allocated subtitle_header before overwriting it */ |
| 2007 | av_freep(&avctx->subtitle_header); |
| 2008 | |
| 2009 | if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) { |
| 2010 | av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n", |
| 2011 | avctx->codec->max_lowres); |
| 2012 | avctx->lowres = avctx->codec->max_lowres; |
| 2013 | } |
| 2014 | if (avctx->sub_charenc) { |
| 2015 | if (avctx->codec_type != AVMEDIA_TYPE_SUBTITLE) { |
| 2016 | av_log(avctx, AV_LOG_ERROR, "Character encoding is only " |
| 2017 | "supported with subtitles codecs\n"); |
| 2018 | return AVERROR(EINVAL); |
| 2019 | } else if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB) { |
| 2020 | av_log(avctx, AV_LOG_WARNING, "Codec '%s' is bitmap-based, " |
| 2021 | "subtitles character encoding will be ignored\n", |
| 2022 | avctx->codec_descriptor->name); |
| 2023 | avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_DO_NOTHING; |
| 2024 | } else { |
| 2025 | /* input character encoding is set for a text based subtitle |
| 2026 | * codec at this point */ |
| 2027 | if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_AUTOMATIC) |
| 2028 | avctx->sub_charenc_mode = FF_SUB_CHARENC_MODE_PRE_DECODER; |
| 2029 | |
| 2030 | if (avctx->sub_charenc_mode == FF_SUB_CHARENC_MODE_PRE_DECODER) { |
| 2031 | #if CONFIG_ICONV |
| 2032 | iconv_t cd = iconv_open("UTF-8", avctx->sub_charenc); |
| 2033 | if (cd == (iconv_t)-1) { |
| 2034 | ret = AVERROR(errno); |
| 2035 | av_log(avctx, AV_LOG_ERROR, "Unable to open iconv context " |
| 2036 | "with input character encoding \"%s\"\n", avctx->sub_charenc); |
| 2037 | return ret; |
| 2038 | } |
| 2039 | iconv_close(cd); |
| 2040 | #else |
| 2041 | av_log(avctx, AV_LOG_ERROR, "Character encoding subtitles " |
| 2042 | "conversion needs a libavcodec built with iconv support " |
| 2043 | "for this codec\n"); |
| 2044 | return AVERROR(ENOSYS); |
| 2045 | #endif |
| 2046 | } |
| 2047 | } |
| 2048 | } |
| 2049 |
no test coverage detected