static void put_frame(

                    AVFormatContext *s,

                    ASFStream       *stream,

                    AVStream        *avst,

                    int             timestamp,

                    const uint8_t   *buf,

                    int             m_obj_size,

                    int             flags

                )

{

    ASFContext *asf = s->priv_data;

    int m_obj_offset, payload_len, frag_len1;



    m_obj_offset = 0;

    while (m_obj_offset < m_obj_size) {

        payload_len = m_obj_size - m_obj_offset;

        if (asf->packet_timestamp_start == -1) {

            asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);



            asf->packet_size_left = PACKET_SIZE;

            if (asf->multi_payloads_present){

                frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;

            }

            else {

                frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;

            }

            asf->packet_timestamp_start = timestamp;

        }

        else {

            // multi payloads

            frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1;



            asf->packet_timestamp_start = timestamp;



            if(frag_len1 < payload_len && avst->codec->codec_type == CODEC_TYPE_AUDIO){

                flush_packet(s);

                continue;

            }

        }

        if (frag_len1 > 0) {

            if (payload_len > frag_len1)

                payload_len = frag_len1;

            else if (payload_len == (frag_len1 - 1))

                payload_len = frag_len1 - 2;  //additional byte need to put padding length



            put_payload_header(s, stream, timestamp+PREROLL_TIME, m_obj_size, m_obj_offset, payload_len, flags);

            put_buffer(&asf->pb, buf, payload_len);



            if (asf->multi_payloads_present)

                asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS);

            else

                asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD);

            asf->packet_timestamp_end = timestamp;



            asf->packet_nb_payloads++;

        } else {

            payload_len = 0;

        }

        m_obj_offset += payload_len;

        buf += payload_len;



        if (!asf->multi_payloads_present)

            flush_packet(s);

        else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + PACKET_HEADER_MIN_SIZE + 1))

            flush_packet(s);

    }

    stream->seq++;

}

static void put_frame(

                    AVFormatContext *s,

                    ASFStream       *stream,

                    AVStream        *avst,

                    int             timestamp,

                    const uint8_t   *buf,

                    int             m_obj_size,

                    int             flags

                )

{

    ASFContext *asf = s->priv_data;

    int m_obj_offset, payload_len, frag_len1;



    m_obj_offset = 0;

    while (m_obj_offset < m_obj_size) {

        payload_len = m_obj_size - m_obj_offset;

        if (asf->packet_timestamp_start == -1) {

            asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT);



            asf->packet_size_left = PACKET_SIZE;

            if (asf->multi_payloads_present){

                frag_len1 = MULTI_PAYLOAD_CONSTANT - 1;

            }

            else {

                frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH;

            }

            asf->packet_timestamp_start = timestamp;

        }

        else {

            

            frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1;



            asf->packet_timestamp_start = timestamp;



            if(frag_len1 < payload_len && avst->codec->codec_type == CODEC_TYPE_AUDIO){

                flush_packet(s);

                continue;

            }

        }

        if (frag_len1 > 0) {

            if (payload_len > frag_len1)

                payload_len = frag_len1;

            else if (payload_len == (frag_len1 - 1))

                payload_len = frag_len1 - 2;  



            put_payload_header(s, stream, timestamp+PREROLL_TIME, m_obj_size, m_obj_offset, payload_len, flags);

            put_buffer(&asf->pb, buf, payload_len);



            if (asf->multi_payloads_present)

                asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS);

            else

                asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD);

            asf->packet_timestamp_end = timestamp;



            asf->packet_nb_payloads++;

        } else {

            payload_len = 0;

        }

        m_obj_offset += payload_len;

        buf += payload_len;



        if (!asf->multi_payloads_present)

            flush_packet(s);

        else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + PACKET_HEADER_MIN_SIZE + 1))

            flush_packet(s);

    }

    stream->seq++;

}

static void FUNC_0(

                    AVFormatContext *VAR_0,

                    ASFStream       *VAR_1,

                    AVStream        *VAR_2,

                    int             VAR_3,

                    const uint8_t   *VAR_4,

                    int             VAR_5,

                    int             VAR_6

                )

{

    ASFContext *asf = VAR_0->priv_data;

    int VAR_7, VAR_8, VAR_9;



    VAR_7 = 0;

    while (VAR_7 < VAR_5) {

        VAR_8 = VAR_5 - VAR_7;

        if (asf->packet_timestamp_start == -1) {

            asf->multi_payloads_present = (VAR_8 < MULTI_PAYLOAD_CONSTANT);



            asf->packet_size_left = PACKET_SIZE;

            if (asf->multi_payloads_present){

                VAR_9 = MULTI_PAYLOAD_CONSTANT - 1;

            }

            else {

                VAR_9 = SINGLE_PAYLOAD_DATA_LENGTH;

            }

            asf->packet_timestamp_start = VAR_3;

        }

        else {

            

            VAR_9 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1;



            asf->packet_timestamp_start = VAR_3;



            if(VAR_9 < VAR_8 && VAR_2->codec->codec_type == CODEC_TYPE_AUDIO){

                flush_packet(VAR_0);

                continue;

            }

        }

        if (VAR_9 > 0) {

            if (VAR_8 > VAR_9)

                VAR_8 = VAR_9;

            else if (VAR_8 == (VAR_9 - 1))

                VAR_8 = VAR_9 - 2;  



            put_payload_header(VAR_0, VAR_1, VAR_3+PREROLL_TIME, VAR_5, VAR_7, VAR_8, VAR_6);

            put_buffer(&asf->pb, VAR_4, VAR_8);



            if (asf->multi_payloads_present)

                asf->packet_size_left -= (VAR_8 + PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS);

            else

                asf->packet_size_left -= (VAR_8 + PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD);

            asf->packet_timestamp_end = VAR_3;



            asf->packet_nb_payloads++;

        } else {

            VAR_8 = 0;

        }

        VAR_7 += VAR_8;

        VAR_4 += VAR_8;



        if (!asf->multi_payloads_present)

            flush_packet(VAR_0);

        else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + PACKET_HEADER_MIN_SIZE + 1))

            flush_packet(VAR_0);

    }

    VAR_1->seq++;

}

static void FUNC_0(
AVFormatContext *VAR_0,
ASFStream       *VAR_1,
AVStream        *VAR_2,
int             VAR_3,
const uint8_t   *VAR_4,
int             VAR_5,
int             VAR_6
)
{ ASFContext *asf = VAR_0->priv_data; int VAR_7, VAR_8, VAR_9; VAR_7 = 0; while (VAR_7 < VAR_5) { VAR_8 = VAR_5 - VAR_7; if (asf->packet_timestamp_start == -1) { asf->multi_payloads_present = (VAR_8 < MULTI_PAYLOAD_CONSTANT); asf->packet_size_left = PACKET_SIZE; if (asf->multi_payloads_present){ VAR_9 = MULTI_PAYLOAD_CONSTANT - 1; } else { VAR_9 = SINGLE_PAYLOAD_DATA_LENGTH; } asf->packet_timestamp_start = VAR_3; } else { VAR_9 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1; asf->packet_timestamp_start = VAR_3; if(VAR_9 < VAR_8 && VAR_2->codec->codec_type == CODEC_TYPE_AUDIO){ flush_packet(VAR_0); continue; } } if (VAR_9 > 0) { if (VAR_8 > VAR_9)
VAR_8 = VAR_9; else if (VAR_8 == (VAR_9 - 1))
VAR_8 = VAR_9 - 2; put_payload_header(VAR_0, VAR_1, VAR_3+PREROLL_TIME, VAR_5, VAR_7, VAR_8, VAR_6); put_buffer(&asf->pb, VAR_4, VAR_8); if (asf->multi_payloads_present)
asf->packet_size_left -= (VAR_8 + PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS); else
asf->packet_size_left -= (VAR_8 + PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD); asf->packet_timestamp_end = VAR_3; asf->packet_nb_payloads++; } else { VAR_8 = 0; } VAR_7 += VAR_8; VAR_4 += VAR_8; if (!asf->multi_payloads_present)
flush_packet(VAR_0); else if (asf->packet_size_left <= (PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS + PACKET_HEADER_MIN_SIZE + 1))
flush_packet(VAR_0); } VAR_1->seq++; }