int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)

{

    if (len > 6) {

        /* check for h264 start code */

        if (AV_RB32(data) == 0x00000001 ||

            AV_RB24(data) == 0x000001) {

            uint8_t *buf=NULL, *end, *start;

            uint32_t sps_size=0, pps_size=0;

            uint8_t *sps=0, *pps=0;



            int ret = ff_avc_parse_nal_units_buf(data, &buf, &len);

            if (ret < 0)

                return ret;

            start = buf;

            end = buf + len;



            /* look for sps and pps */

            while (buf < end) {

                unsigned int size;

                uint8_t nal_type;

                size = AV_RB32(buf);

                nal_type = buf[4] & 0x1f;

                if (nal_type == 7) { /* SPS */

                    sps = buf + 4;

                    sps_size = size;

                } else if (nal_type == 8) { /* PPS */

                    pps = buf + 4;

                    pps_size = size;

                }

                buf += size + 4;

            }

            assert(sps);

            assert(pps);



            avio_w8(pb, 1); /* version */

            avio_w8(pb, sps[1]); /* profile */

            avio_w8(pb, sps[2]); /* profile compat */

            avio_w8(pb, sps[3]); /* level */

            avio_w8(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */

            avio_w8(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */



            avio_wb16(pb, sps_size);

            avio_write(pb, sps, sps_size);

            avio_w8(pb, 1); /* number of pps */

            avio_wb16(pb, pps_size);

            avio_write(pb, pps, pps_size);

            av_free(start);

        } else {

            avio_write(pb, data, len);

        }

    }

    return 0;

}

int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)

{

    if (len > 6) {

        

        if (AV_RB32(data) == 0x00000001 ||

            AV_RB24(data) == 0x000001) {

            uint8_t *buf=NULL, *end, *start;

            uint32_t sps_size=0, pps_size=0;

            uint8_t *sps=0, *pps=0;



            int ret = ff_avc_parse_nal_units_buf(data, &buf, &len);

            if (ret < 0)

                return ret;

            start = buf;

            end = buf + len;



            

            while (buf < end) {

                unsigned int size;

                uint8_t nal_type;

                size = AV_RB32(buf);

                nal_type = buf[4] & 0x1f;

                if (nal_type == 7) { 

                    sps = buf + 4;

                    sps_size = size;

                } else if (nal_type == 8) { 

                    pps = buf + 4;

                    pps_size = size;

                }

                buf += size + 4;

            }

            assert(sps);

            assert(pps);



            avio_w8(pb, 1); 

            avio_w8(pb, sps[1]); 

            avio_w8(pb, sps[2]); 

            avio_w8(pb, sps[3]); 

            avio_w8(pb, 0xff); 

            avio_w8(pb, 0xe1); 



            avio_wb16(pb, sps_size);

            avio_write(pb, sps, sps_size);

            avio_w8(pb, 1); 

            avio_wb16(pb, pps_size);

            avio_write(pb, pps, pps_size);

            av_free(start);

        } else {

            avio_write(pb, data, len);

        }

    }

    return 0;

}

int FUNC_0(AVIOContext *VAR_0, const uint8_t *VAR_1, int VAR_2)

{

    if (VAR_2 > 6) {

        

        if (AV_RB32(VAR_1) == 0x00000001 ||

            AV_RB24(VAR_1) == 0x000001) {

            uint8_t *buf=NULL, *end, *start;

            uint32_t sps_size=0, pps_size=0;

            uint8_t *sps=0, *pps=0;



            int VAR_3 = ff_avc_parse_nal_units_buf(VAR_1, &buf, &VAR_2);

            if (VAR_3 < 0)

                return VAR_3;

            start = buf;

            end = buf + VAR_2;



            

            while (buf < end) {

                unsigned int VAR_4;

                uint8_t nal_type;

                VAR_4 = AV_RB32(buf);

                nal_type = buf[4] & 0x1f;

                if (nal_type == 7) { 

                    sps = buf + 4;

                    sps_size = VAR_4;

                } else if (nal_type == 8) { 

                    pps = buf + 4;

                    pps_size = VAR_4;

                }

                buf += VAR_4 + 4;

            }

            assert(sps);

            assert(pps);



            avio_w8(VAR_0, 1); 

            avio_w8(VAR_0, sps[1]); 

            avio_w8(VAR_0, sps[2]); 

            avio_w8(VAR_0, sps[3]); 

            avio_w8(VAR_0, 0xff); 

            avio_w8(VAR_0, 0xe1); 



            avio_wb16(VAR_0, sps_size);

            avio_write(VAR_0, sps, sps_size);

            avio_w8(VAR_0, 1); 

            avio_wb16(VAR_0, pps_size);

            avio_write(VAR_0, pps, pps_size);

            av_free(start);

        } else {

            avio_write(VAR_0, VAR_1, VAR_2);

        }

    }

    return 0;

}

int FUNC_0(AVIOContext *VAR_0, const uint8_t *VAR_1, int VAR_2)
{ if (VAR_2 > 6) { if (AV_RB32(VAR_1) == 0x00000001 ||
AV_RB24(VAR_1) == 0x000001) { uint8_t *buf=NULL, *end, *start; uint32_t sps_size=0, pps_size=0; uint8_t *sps=0, *pps=0; int VAR_3 = ff_avc_parse_nal_units_buf(VAR_1, &buf, &VAR_2); if (VAR_3 < 0)
return VAR_3; start = buf; end = buf + VAR_2; while (buf < end) { unsigned int VAR_4; uint8_t nal_type; VAR_4 = AV_RB32(buf); nal_type = buf[4] & 0x1f; if (nal_type == 7) { sps = buf + 4; sps_size = VAR_4; } else if (nal_type == 8) { pps = buf + 4; pps_size = VAR_4; } buf += VAR_4 + 4; } assert(sps); assert(pps); avio_w8(VAR_0, 1); avio_w8(VAR_0, sps[1]); avio_w8(VAR_0, sps[2]); avio_w8(VAR_0, sps[3]); avio_w8(VAR_0, 0xff); avio_w8(VAR_0, 0xe1); avio_wb16(VAR_0, sps_size); avio_write(VAR_0, sps, sps_size); avio_w8(VAR_0, 1); avio_wb16(VAR_0, pps_size); avio_write(VAR_0, pps, pps_size); av_free(start); } else { avio_write(VAR_0, VAR_1, VAR_2); } } return 0; }