static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)

{

    ASFContext *asf = s->priv_data;

    ASFStream *stream;

    int64_t duration;

    AVCodecContext *codec;

    int64_t packet_st, pts;

    int start_sec, i;

    int flags = pkt->flags;



    codec  = s->streams[pkt->stream_index]->codec;

    stream = &asf->streams[pkt->stream_index];



    if (codec->codec_type == AVMEDIA_TYPE_AUDIO)

        flags &= ~AV_PKT_FLAG_KEY;



    pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;



    if (pts < 0) {

        av_log(s, AV_LOG_ERROR,

               "Negative dts not supported stream %d, dts %"PRId64"\n",

               pkt->stream_index, pts);

        return AVERROR(ENOSYS);

    }



    assert(pts != AV_NOPTS_VALUE);

    duration      = pts * 10000;

    asf->duration = FFMAX(asf->duration, duration + pkt->duration * 10000);



    packet_st = asf->nb_packets;

    put_frame(s, stream, s->streams[pkt->stream_index],

              pkt->dts, pkt->data, pkt->size, flags);



    /* check index */

    if ((!asf->is_streamed) && (flags & AV_PKT_FLAG_KEY)) {

        start_sec = (int)(duration / INT64_C(10000000));

        if (start_sec != (int)(asf->last_indexed_pts / INT64_C(10000000))) {

            for (i = asf->nb_index_count; i < start_sec; i++) {

                if (i >= asf->nb_index_memory_alloc) {

                    asf->nb_index_memory_alloc += ASF_INDEX_BLOCK;

                    asf->index_ptr              = (ASFIndex *)av_realloc(asf->index_ptr,

                                                                         sizeof(ASFIndex) *

                                                                         asf->nb_index_memory_alloc);

                }

                // store

                asf->index_ptr[i].packet_number = (uint32_t)packet_st;

                asf->index_ptr[i].packet_count  = (uint16_t)(asf->nb_packets - packet_st);

                asf->maximum_packet             = FFMAX(asf->maximum_packet,

                                                        (uint16_t)(asf->nb_packets - packet_st));

            }

            asf->nb_index_count   = start_sec;

            asf->last_indexed_pts = duration;

        }

    }

    return 0;

}

static int asf_write_packet(AVFormatContext *s, AVPacket *pkt)

{

    ASFContext *asf = s->priv_data;

    ASFStream *stream;

    int64_t duration;

    AVCodecContext *codec;

    int64_t packet_st, pts;

    int start_sec, i;

    int flags = pkt->flags;



    codec  = s->streams[pkt->stream_index]->codec;

    stream = &asf->streams[pkt->stream_index];



    if (codec->codec_type == AVMEDIA_TYPE_AUDIO)

        flags &= ~AV_PKT_FLAG_KEY;



    pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts;



    if (pts < 0) {

        av_log(s, AV_LOG_ERROR,

               "Negative dts not supported stream %d, dts %"PRId64"\n",

               pkt->stream_index, pts);

        return AVERROR(ENOSYS);

    }



    assert(pts != AV_NOPTS_VALUE);

    duration      = pts * 10000;

    asf->duration = FFMAX(asf->duration, duration + pkt->duration * 10000);



    packet_st = asf->nb_packets;

    put_frame(s, stream, s->streams[pkt->stream_index],

              pkt->dts, pkt->data, pkt->size, flags);



    

    if ((!asf->is_streamed) && (flags & AV_PKT_FLAG_KEY)) {

        start_sec = (int)(duration / INT64_C(10000000));

        if (start_sec != (int)(asf->last_indexed_pts / INT64_C(10000000))) {

            for (i = asf->nb_index_count; i < start_sec; i++) {

                if (i >= asf->nb_index_memory_alloc) {

                    asf->nb_index_memory_alloc += ASF_INDEX_BLOCK;

                    asf->index_ptr              = (ASFIndex *)av_realloc(asf->index_ptr,

                                                                         sizeof(ASFIndex) *

                                                                         asf->nb_index_memory_alloc);

                }

                

                asf->index_ptr[i].packet_number = (uint32_t)packet_st;

                asf->index_ptr[i].packet_count  = (uint16_t)(asf->nb_packets - packet_st);

                asf->maximum_packet             = FFMAX(asf->maximum_packet,

                                                        (uint16_t)(asf->nb_packets - packet_st));

            }

            asf->nb_index_count   = start_sec;

            asf->last_indexed_pts = duration;

        }

    }

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    ASFContext *asf = VAR_0->priv_data;

    ASFStream *stream;

    int64_t duration;

    AVCodecContext *codec;

    int64_t packet_st, pts;

    int VAR_2, VAR_3;

    int VAR_4 = VAR_1->VAR_4;



    codec  = VAR_0->streams[VAR_1->stream_index]->codec;

    stream = &asf->streams[VAR_1->stream_index];



    if (codec->codec_type == AVMEDIA_TYPE_AUDIO)

        VAR_4 &= ~AV_PKT_FLAG_KEY;



    pts = (VAR_1->pts != AV_NOPTS_VALUE) ? VAR_1->pts : VAR_1->dts;



    if (pts < 0) {

        av_log(VAR_0, AV_LOG_ERROR,

               "Negative dts not supported stream %d, dts %"PRId64"\n",

               VAR_1->stream_index, pts);

        return AVERROR(ENOSYS);

    }



    assert(pts != AV_NOPTS_VALUE);

    duration      = pts * 10000;

    asf->duration = FFMAX(asf->duration, duration + VAR_1->duration * 10000);



    packet_st = asf->nb_packets;

    put_frame(VAR_0, stream, VAR_0->streams[VAR_1->stream_index],

              VAR_1->dts, VAR_1->data, VAR_1->size, VAR_4);



    

    if ((!asf->is_streamed) && (VAR_4 & AV_PKT_FLAG_KEY)) {

        VAR_2 = (int)(duration / INT64_C(10000000));

        if (VAR_2 != (int)(asf->last_indexed_pts / INT64_C(10000000))) {

            for (VAR_3 = asf->nb_index_count; VAR_3 < VAR_2; VAR_3++) {

                if (VAR_3 >= asf->nb_index_memory_alloc) {

                    asf->nb_index_memory_alloc += ASF_INDEX_BLOCK;

                    asf->index_ptr              = (ASFIndex *)av_realloc(asf->index_ptr,

                                                                         sizeof(ASFIndex) *

                                                                         asf->nb_index_memory_alloc);

                }

                

                asf->index_ptr[VAR_3].packet_number = (uint32_t)packet_st;

                asf->index_ptr[VAR_3].packet_count  = (uint16_t)(asf->nb_packets - packet_st);

                asf->maximum_packet             = FFMAX(asf->maximum_packet,

                                                        (uint16_t)(asf->nb_packets - packet_st));

            }

            asf->nb_index_count   = VAR_2;

            asf->last_indexed_pts = duration;

        }

    }

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ ASFContext *asf = VAR_0->priv_data; ASFStream *stream; int64_t duration; AVCodecContext *codec; int64_t packet_st, pts; int VAR_2, VAR_3; int VAR_4 = VAR_1->VAR_4; codec  = VAR_0->streams[VAR_1->stream_index]->codec; stream = &asf->streams[VAR_1->stream_index]; if (codec->codec_type == AVMEDIA_TYPE_AUDIO)
VAR_4 &= ~AV_PKT_FLAG_KEY; pts = (VAR_1->pts != AV_NOPTS_VALUE) ? VAR_1->pts : VAR_1->dts; if (pts < 0) { av_log(VAR_0, AV_LOG_ERROR,
"Negative dts not supported stream %d, dts %"PRId64"\n",
VAR_1->stream_index, pts); return AVERROR(ENOSYS); } assert(pts != AV_NOPTS_VALUE); duration      = pts * 10000; asf->duration = FFMAX(asf->duration, duration + VAR_1->duration * 10000); packet_st = asf->nb_packets; put_frame(VAR_0, stream, VAR_0->streams[VAR_1->stream_index],
VAR_1->dts, VAR_1->data, VAR_1->size, VAR_4); if ((!asf->is_streamed) && (VAR_4 & AV_PKT_FLAG_KEY)) { VAR_2 = (int)(duration / INT64_C(10000000)); if (VAR_2 != (int)(asf->last_indexed_pts / INT64_C(10000000))) { for (VAR_3 = asf->nb_index_count; VAR_3 < VAR_2; VAR_3++) { if (VAR_3 >= asf->nb_index_memory_alloc) { asf->nb_index_memory_alloc += ASF_INDEX_BLOCK; asf->index_ptr              = (ASFIndex *)av_realloc(asf->index_ptr,
sizeof(ASFIndex) *
asf->nb_index_memory_alloc); } asf->index_ptr[VAR_3].packet_number = (uint32_t)packet_st; asf->index_ptr[VAR_3].packet_count  = (uint16_t)(asf->nb_packets - packet_st); asf->maximum_packet             = FFMAX(asf->maximum_packet,
(uint16_t)(asf->nb_packets - packet_st)); } asf->nb_index_count   = VAR_2; asf->last_indexed_pts = duration; } } return 0; }