static int mpegts_set_stream_info(AVStream *st, PESContext *pes,

                                  uint32_t stream_type, uint32_t prog_reg_desc)

{

    int old_codec_type= st->codec->codec_type;

    int old_codec_id  = st->codec->codec_id;



    if (old_codec_id != AV_CODEC_ID_NONE && avcodec_is_open(st->codec)) {

        av_log(pes->stream, AV_LOG_DEBUG, "cannot set stream info, codec is open\n");

        return 0;

    }



    avpriv_set_pts_info(st, 33, 1, 90000);

    st->priv_data = pes;

    st->codec->codec_type = AVMEDIA_TYPE_DATA;

    st->codec->codec_id   = AV_CODEC_ID_NONE;

    st->need_parsing = AVSTREAM_PARSE_FULL;

    pes->st = st;

    pes->stream_type = stream_type;



    av_log(pes->stream, AV_LOG_DEBUG,

           "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n",

           st->index, pes->stream_type, pes->pid, (char*)&prog_reg_desc);



    st->codec->codec_tag = pes->stream_type;



    mpegts_find_stream_type(st, pes->stream_type, ISO_types);

    if ((prog_reg_desc == AV_RL32("HDMV") ||

         prog_reg_desc == AV_RL32("HDPR")) &&

        st->codec->codec_id == AV_CODEC_ID_NONE) {

        mpegts_find_stream_type(st, pes->stream_type, HDMV_types);

        if (pes->stream_type == 0x83) {

            // HDMV TrueHD streams also contain an AC3 coded version of the

            // audio track - add a second stream for this

            AVStream *sub_st;

            // priv_data cannot be shared between streams

            PESContext *sub_pes = av_malloc(sizeof(*sub_pes));

            if (!sub_pes)

                return AVERROR(ENOMEM);

            memcpy(sub_pes, pes, sizeof(*sub_pes));



            sub_st = avformat_new_stream(pes->stream, NULL);

            if (!sub_st) {

                av_free(sub_pes);

                return AVERROR(ENOMEM);

            }



            sub_st->id = pes->pid;

            avpriv_set_pts_info(sub_st, 33, 1, 90000);

            sub_st->priv_data = sub_pes;

            sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO;

            sub_st->codec->codec_id   = AV_CODEC_ID_AC3;

            sub_st->need_parsing = AVSTREAM_PARSE_FULL;

            sub_pes->sub_st = pes->sub_st = sub_st;

        }

    }

    if (st->codec->codec_id == AV_CODEC_ID_NONE)

        mpegts_find_stream_type(st, pes->stream_type, MISC_types);

    if (st->codec->codec_id == AV_CODEC_ID_NONE){

        st->codec->codec_id  = old_codec_id;

        st->codec->codec_type= old_codec_type;

    }



    return 0;

}

static int mpegts_set_stream_info(AVStream *st, PESContext *pes,

                                  uint32_t stream_type, uint32_t prog_reg_desc)

{

    int old_codec_type= st->codec->codec_type;

    int old_codec_id  = st->codec->codec_id;



    if (old_codec_id != AV_CODEC_ID_NONE && avcodec_is_open(st->codec)) {

        av_log(pes->stream, AV_LOG_DEBUG, "cannot set stream info, codec is open\n");

        return 0;

    }



    avpriv_set_pts_info(st, 33, 1, 90000);

    st->priv_data = pes;

    st->codec->codec_type = AVMEDIA_TYPE_DATA;

    st->codec->codec_id   = AV_CODEC_ID_NONE;

    st->need_parsing = AVSTREAM_PARSE_FULL;

    pes->st = st;

    pes->stream_type = stream_type;



    av_log(pes->stream, AV_LOG_DEBUG,

           "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n",

           st->index, pes->stream_type, pes->pid, (char*)&prog_reg_desc);



    st->codec->codec_tag = pes->stream_type;



    mpegts_find_stream_type(st, pes->stream_type, ISO_types);

    if ((prog_reg_desc == AV_RL32("HDMV") ||

         prog_reg_desc == AV_RL32("HDPR")) &&

        st->codec->codec_id == AV_CODEC_ID_NONE) {

        mpegts_find_stream_type(st, pes->stream_type, HDMV_types);

        if (pes->stream_type == 0x83) {

            

            

            AVStream *sub_st;

            

            PESContext *sub_pes = av_malloc(sizeof(*sub_pes));

            if (!sub_pes)

                return AVERROR(ENOMEM);

            memcpy(sub_pes, pes, sizeof(*sub_pes));



            sub_st = avformat_new_stream(pes->stream, NULL);

            if (!sub_st) {

                av_free(sub_pes);

                return AVERROR(ENOMEM);

            }



            sub_st->id = pes->pid;

            avpriv_set_pts_info(sub_st, 33, 1, 90000);

            sub_st->priv_data = sub_pes;

            sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO;

            sub_st->codec->codec_id   = AV_CODEC_ID_AC3;

            sub_st->need_parsing = AVSTREAM_PARSE_FULL;

            sub_pes->sub_st = pes->sub_st = sub_st;

        }

    }

    if (st->codec->codec_id == AV_CODEC_ID_NONE)

        mpegts_find_stream_type(st, pes->stream_type, MISC_types);

    if (st->codec->codec_id == AV_CODEC_ID_NONE){

        st->codec->codec_id  = old_codec_id;

        st->codec->codec_type= old_codec_type;

    }



    return 0;

}

static int FUNC_0(AVStream *VAR_0, PESContext *VAR_1,

                                  uint32_t VAR_2, uint32_t VAR_3)

{

    int VAR_4= VAR_0->codec->codec_type;

    int VAR_5  = VAR_0->codec->codec_id;



    if (VAR_5 != AV_CODEC_ID_NONE && avcodec_is_open(VAR_0->codec)) {

        av_log(VAR_1->stream, AV_LOG_DEBUG, "cannot set stream info, codec is open\n");

        return 0;

    }



    avpriv_set_pts_info(VAR_0, 33, 1, 90000);

    VAR_0->priv_data = VAR_1;

    VAR_0->codec->codec_type = AVMEDIA_TYPE_DATA;

    VAR_0->codec->codec_id   = AV_CODEC_ID_NONE;

    VAR_0->need_parsing = AVSTREAM_PARSE_FULL;

    VAR_1->VAR_0 = VAR_0;

    VAR_1->VAR_2 = VAR_2;



    av_log(VAR_1->stream, AV_LOG_DEBUG,

           "stream=%d VAR_2=%x pid=%x VAR_3=%.4s\n",

           VAR_0->index, VAR_1->VAR_2, VAR_1->pid, (char*)&VAR_3);



    VAR_0->codec->codec_tag = VAR_1->VAR_2;



    mpegts_find_stream_type(VAR_0, VAR_1->VAR_2, ISO_types);

    if ((VAR_3 == AV_RL32("HDMV") ||

         VAR_3 == AV_RL32("HDPR")) &&

        VAR_0->codec->codec_id == AV_CODEC_ID_NONE) {

        mpegts_find_stream_type(VAR_0, VAR_1->VAR_2, HDMV_types);

        if (VAR_1->VAR_2 == 0x83) {

            

            

            AVStream *sub_st;

            

            PESContext *sub_pes = av_malloc(sizeof(*sub_pes));

            if (!sub_pes)

                return AVERROR(ENOMEM);

            memcpy(sub_pes, VAR_1, sizeof(*sub_pes));



            sub_st = avformat_new_stream(VAR_1->stream, NULL);

            if (!sub_st) {

                av_free(sub_pes);

                return AVERROR(ENOMEM);

            }



            sub_st->id = VAR_1->pid;

            avpriv_set_pts_info(sub_st, 33, 1, 90000);

            sub_st->priv_data = sub_pes;

            sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO;

            sub_st->codec->codec_id   = AV_CODEC_ID_AC3;

            sub_st->need_parsing = AVSTREAM_PARSE_FULL;

            sub_pes->sub_st = VAR_1->sub_st = sub_st;

        }

    }

    if (VAR_0->codec->codec_id == AV_CODEC_ID_NONE)

        mpegts_find_stream_type(VAR_0, VAR_1->VAR_2, MISC_types);

    if (VAR_0->codec->codec_id == AV_CODEC_ID_NONE){

        VAR_0->codec->codec_id  = VAR_5;

        VAR_0->codec->codec_type= VAR_4;

    }



    return 0;

}

static int FUNC_0(AVStream *VAR_0, PESContext *VAR_1,
uint32_t VAR_2, uint32_t VAR_3)
{ int VAR_4= VAR_0->codec->codec_type; int VAR_5  = VAR_0->codec->codec_id; if (VAR_5 != AV_CODEC_ID_NONE && avcodec_is_open(VAR_0->codec)) { av_log(VAR_1->stream, AV_LOG_DEBUG, "cannot set stream info, codec is open\n"); return 0; } avpriv_set_pts_info(VAR_0, 33, 1, 90000); VAR_0->priv_data = VAR_1; VAR_0->codec->codec_type = AVMEDIA_TYPE_DATA; VAR_0->codec->codec_id   = AV_CODEC_ID_NONE; VAR_0->need_parsing = AVSTREAM_PARSE_FULL; VAR_1->VAR_0 = VAR_0; VAR_1->VAR_2 = VAR_2; av_log(VAR_1->stream, AV_LOG_DEBUG,
"stream=%d VAR_2=%x pid=%x VAR_3=%.4s\n",
VAR_0->index, VAR_1->VAR_2, VAR_1->pid, (char*)&VAR_3); VAR_0->codec->codec_tag = VAR_1->VAR_2; mpegts_find_stream_type(VAR_0, VAR_1->VAR_2, ISO_types); if ((VAR_3 == AV_RL32("HDMV") ||
VAR_3 == AV_RL32("HDPR")) &&
VAR_0->codec->codec_id == AV_CODEC_ID_NONE) { mpegts_find_stream_type(VAR_0, VAR_1->VAR_2, HDMV_types); if (VAR_1->VAR_2 == 0x83) { AVStream *sub_st; PESContext *sub_pes = av_malloc(sizeof(*sub_pes)); if (!sub_pes)
return AVERROR(ENOMEM); memcpy(sub_pes, VAR_1, sizeof(*sub_pes)); sub_st = avformat_new_stream(VAR_1->stream, NULL); if (!sub_st) { av_free(sub_pes); return AVERROR(ENOMEM); } sub_st->id = VAR_1->pid; avpriv_set_pts_info(sub_st, 33, 1, 90000); sub_st->priv_data = sub_pes; sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO; sub_st->codec->codec_id   = AV_CODEC_ID_AC3; sub_st->need_parsing = AVSTREAM_PARSE_FULL; sub_pes->sub_st = VAR_1->sub_st = sub_st; } } if (VAR_0->codec->codec_id == AV_CODEC_ID_NONE)
mpegts_find_stream_type(VAR_0, VAR_1->VAR_2, MISC_types); if (VAR_0->codec->codec_id == AV_CODEC_ID_NONE){ VAR_0->codec->codec_id  = VAR_5; VAR_0->codec->codec_type= VAR_4; } return 0; }