int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
                             int *got_sub_ptr,
                             AVPacket *avpkt)
{
    int i, ret = 0;
    if (!avpkt->data && avpkt->size) {
        av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
        return AVERROR(EINVAL);
    if (!avctx->codec)
        return AVERROR(EINVAL);
    if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) {
        av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n");
        return AVERROR(EINVAL);
    *got_sub_ptr = 0;
    avcodec_get_subtitle_defaults(sub);
    if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
        AVPacket pkt_recoded;
        AVPacket tmp = *avpkt;
        int did_split = av_packet_split_side_data(&tmp);
        //apply_param_change(avctx, &tmp);
        pkt_recoded = tmp;
        ret = recode_subtitle(avctx, &pkt_recoded, &tmp);
        if (ret < 0) {
            *got_sub_ptr = 0;
        } else {
            avctx->internal->pkt = &pkt_recoded;
            if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE)
                sub->pts = av_rescale_q(avpkt->pts,
                                        avctx->pkt_timebase, AV_TIME_BASE_Q);
            ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &pkt_recoded);
            av_assert1((ret >= 0) >= !!*got_sub_ptr &&
                       !!*got_sub_ptr >= !!sub->num_rects);
            if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
                avctx->pkt_timebase.num) {
                AVRational ms = { 1, 1000 };
                sub->end_display_time = av_rescale_q(avpkt->duration,
                                                     avctx->pkt_timebase, ms);
            for (i = 0; i < sub->num_rects; i++) {
                if (sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
                    av_log(avctx, AV_LOG_ERROR,
                           "Invalid UTF-8 in decoded subtitles text; "
                           "maybe missing -sub_charenc option\n");
                    avsubtitle_free(sub);
                    return AVERROR_INVALIDDATA;
            if (tmp.data != pkt_recoded.data) { // did we recode?
                /* prevent from destroying side data from original packet */
                pkt_recoded.side_data = NULL;
                pkt_recoded.side_data_elems = 0;
                av_free_packet(&pkt_recoded);
            if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
                sub->format = 0;
            else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
                sub->format = 1;
            avctx->internal->pkt = NULL;
            av_packet_free_side_data(&tmp);
            if(ret == tmp.size)
                ret = avpkt->size;
        if (*got_sub_ptr)
            avctx->frame_number++;
    return ret;
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
                             int *got_sub_ptr,
                             AVPacket *avpkt)
{
    int i, ret = 0;
    if (!avpkt->data && avpkt->size) {
        av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
        return AVERROR(EINVAL);
    if (!avctx->codec)
        return AVERROR(EINVAL);
    if (avctx->codec->type != AVMEDIA_TYPE_SUBTITLE) {
        av_log(avctx, AV_LOG_ERROR, "Invalid media type for subtitles\n");
        return AVERROR(EINVAL);
    *got_sub_ptr = 0;
    avcodec_get_subtitle_defaults(sub);
    if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
        AVPacket pkt_recoded;
        AVPacket tmp = *avpkt;
        int did_split = av_packet_split_side_data(&tmp);
        
        pkt_recoded = tmp;
        ret = recode_subtitle(avctx, &pkt_recoded, &tmp);
        if (ret < 0) {
            *got_sub_ptr = 0;
        } else {
            avctx->internal->pkt = &pkt_recoded;
            if (avctx->pkt_timebase.den && avpkt->pts != AV_NOPTS_VALUE)
                sub->pts = av_rescale_q(avpkt->pts,
                                        avctx->pkt_timebase, AV_TIME_BASE_Q);
            ret = avctx->codec->decode(avctx, sub, got_sub_ptr, &pkt_recoded);
            av_assert1((ret >= 0) >= !!*got_sub_ptr &&
                       !!*got_sub_ptr >= !!sub->num_rects);
            if (sub->num_rects && !sub->end_display_time && avpkt->duration &&
                avctx->pkt_timebase.num) {
                AVRational ms = { 1, 1000 };
                sub->end_display_time = av_rescale_q(avpkt->duration,
                                                     avctx->pkt_timebase, ms);
            for (i = 0; i < sub->num_rects; i++) {
                if (sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
                    av_log(avctx, AV_LOG_ERROR,
                           "Invalid UTF-8 in decoded subtitles text; "
                           "maybe missing -sub_charenc option\n");
                    avsubtitle_free(sub);
                    return AVERROR_INVALIDDATA;
            if (tmp.data != pkt_recoded.data) { 
                
                pkt_recoded.side_data = NULL;
                pkt_recoded.side_data_elems = 0;
                av_free_packet(&pkt_recoded);
            if (avctx->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
                sub->format = 0;
            else if (avctx->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
                sub->format = 1;
            avctx->internal->pkt = NULL;
            av_packet_free_side_data(&tmp);
            if(ret == tmp.size)
                ret = avpkt->size;
        if (*got_sub_ptr)
            avctx->frame_number++;
    return ret;
int FUNC_0(AVCodecContext *VAR_0, AVSubtitle *VAR_1,
                             int *VAR_2,
                             AVPacket *VAR_3)
{
    int VAR_4, VAR_5 = 0;
    if (!VAR_3->data && VAR_3->size) {
        av_log(VAR_0, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n");
        return AVERROR(EINVAL);
    if (!VAR_0->codec)
        return AVERROR(EINVAL);
    if (VAR_0->codec->type != AVMEDIA_TYPE_SUBTITLE) {
        av_log(VAR_0, AV_LOG_ERROR, "Invalid media type for subtitles\n");
        return AVERROR(EINVAL);
    *VAR_2 = 0;
    avcodec_get_subtitle_defaults(VAR_1);
    if ((VAR_0->codec->capabilities & CODEC_CAP_DELAY) || VAR_3->size) {
        AVPacket pkt_recoded;
        AVPacket tmp = *VAR_3;
        int VAR_6 = av_packet_split_side_data(&tmp);
        
        pkt_recoded = tmp;
        VAR_5 = recode_subtitle(VAR_0, &pkt_recoded, &tmp);
        if (VAR_5 < 0) {
            *VAR_2 = 0;
        } else {
            VAR_0->internal->pkt = &pkt_recoded;
            if (VAR_0->pkt_timebase.den && VAR_3->pts != AV_NOPTS_VALUE)
                VAR_1->pts = av_rescale_q(VAR_3->pts,
                                        VAR_0->pkt_timebase, AV_TIME_BASE_Q);
            VAR_5 = VAR_0->codec->decode(VAR_0, VAR_1, VAR_2, &pkt_recoded);
            av_assert1((VAR_5 >= 0) >= !!*VAR_2 &&
                       !!*VAR_2 >= !!VAR_1->num_rects);
            if (VAR_1->num_rects && !VAR_1->end_display_time && VAR_3->duration &&
                VAR_0->pkt_timebase.num) {
                AVRational ms = { 1, 1000 };
                VAR_1->end_display_time = av_rescale_q(VAR_3->duration,
                                                     VAR_0->pkt_timebase, ms);
            for (VAR_4 = 0; VAR_4 < VAR_1->num_rects; VAR_4++) {
                if (VAR_1->rects[VAR_4]->ass && !utf8_check(VAR_1->rects[VAR_4]->ass)) {
                    av_log(VAR_0, AV_LOG_ERROR,
                           "Invalid UTF-8 in decoded subtitles text; "
                           "maybe missing -sub_charenc option\n");
                    avsubtitle_free(VAR_1);
                    return AVERROR_INVALIDDATA;
            if (tmp.data != pkt_recoded.data) { 
                
                pkt_recoded.side_data = NULL;
                pkt_recoded.side_data_elems = 0;
                av_free_packet(&pkt_recoded);
            if (VAR_0->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
                VAR_1->format = 0;
            else if (VAR_0->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
                VAR_1->format = 1;
            VAR_0->internal->pkt = NULL;
            av_packet_free_side_data(&tmp);
            if(VAR_5 == tmp.size)
                VAR_5 = VAR_3->size;
        if (*VAR_2)
            VAR_0->frame_number++;
    return VAR_5;
int FUNC_0(AVCodecContext *VAR_0, AVSubtitle *VAR_1,
int *VAR_2,
AVPacket *VAR_3)
{ int VAR_4, VAR_5 = 0; if (!VAR_3->data && VAR_3->size) { av_log(VAR_0, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n"); return AVERROR(EINVAL); if (!VAR_0->codec)
return AVERROR(EINVAL); if (VAR_0->codec->type != AVMEDIA_TYPE_SUBTITLE) { av_log(VAR_0, AV_LOG_ERROR, "Invalid media type for subtitles\n"); return AVERROR(EINVAL); *VAR_2 = 0; avcodec_get_subtitle_defaults(VAR_1); if ((VAR_0->codec->capabilities & CODEC_CAP_DELAY) || VAR_3->size) { AVPacket pkt_recoded; AVPacket tmp = *VAR_3; int VAR_6 = av_packet_split_side_data(&tmp); pkt_recoded = tmp; VAR_5 = recode_subtitle(VAR_0, &pkt_recoded, &tmp); if (VAR_5 < 0) { *VAR_2 = 0; } else { VAR_0->internal->pkt = &pkt_recoded; if (VAR_0->pkt_timebase.den && VAR_3->pts != AV_NOPTS_VALUE)
VAR_1->pts = av_rescale_q(VAR_3->pts,
VAR_0->pkt_timebase, AV_TIME_BASE_Q); VAR_5 = VAR_0->codec->decode(VAR_0, VAR_1, VAR_2, &pkt_recoded); av_assert1((VAR_5 >= 0) >= !!*VAR_2 &&
!!*VAR_2 >= !!VAR_1->num_rects); if (VAR_1->num_rects && !VAR_1->end_display_time && VAR_3->duration &&
VAR_0->pkt_timebase.num) { AVRational ms = { 1, 1000 }; VAR_1->end_display_time = av_rescale_q(VAR_3->duration,
VAR_0->pkt_timebase, ms); for (VAR_4 = 0; VAR_4 < VAR_1->num_rects; VAR_4++) { if (VAR_1->rects[VAR_4]->ass && !utf8_check(VAR_1->rects[VAR_4]->ass)) { av_log(VAR_0, AV_LOG_ERROR,
"Invalid UTF-8 in decoded subtitles text; " "maybe missing -sub_charenc option\n"); avsubtitle_free(VAR_1); return AVERROR_INVALIDDATA; if (tmp.data != pkt_recoded.data) { pkt_recoded.side_data = NULL; pkt_recoded.side_data_elems = 0; av_free_packet(&pkt_recoded); if (VAR_0->codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
VAR_1->format = 0; else if (VAR_0->codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
VAR_1->format = 1; VAR_0->internal->pkt = NULL; av_packet_free_side_data(&tmp); if(VAR_5 == tmp.size)
VAR_5 = VAR_3->size; if (*VAR_2)
VAR_0->frame_number++; return VAR_5;