static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,

                              AVStream *st, AVPacket *pkt, uint32_t *timestamp,

                              const uint8_t *buf, int len, uint16_t seq,

                              int flags)

{

    uint8_t nal;

    uint8_t type;

    int result = 0;



    if (!len) {

        av_log(ctx, AV_LOG_ERROR, "Empty H264 RTP packet\n");

        return AVERROR_INVALIDDATA;

    }

    nal  = buf[0];

    type = nal & 0x1f;



    assert(data);

    assert(buf);



    /* Simplify the case (these are all the nal types used internally by

     * the h264 codec). */

    if (type >= 1 && type <= 23)

        type = 1;

    switch (type) {

    case 0:                    // undefined, but pass them through

    case 1:

        av_new_packet(pkt, len + sizeof(start_sequence));

        memcpy(pkt->data, start_sequence, sizeof(start_sequence));

        memcpy(pkt->data + sizeof(start_sequence), buf, len);

        COUNT_NAL_TYPE(data, nal);

        break;



    case 24:                   // STAP-A (one packet, multiple nals)

        // consume the STAP-A NAL

        buf++;

        len--;

        // first we are going to figure out the total size

        {

            int pass         = 0;

            int total_length = 0;

            uint8_t *dst     = NULL;



            for (pass = 0; pass < 2; pass++) {

                const uint8_t *src = buf;

                int src_len        = len;



                while (src_len > 2) {

                    uint16_t nal_size = AV_RB16(src);



                    // consume the length of the aggregate

                    src     += 2;

                    src_len -= 2;



                    if (nal_size <= src_len) {

                        if (pass == 0) {

                            // counting

                            total_length += sizeof(start_sequence) + nal_size;

                        } else {

                            // copying

                            assert(dst);

                            memcpy(dst, start_sequence, sizeof(start_sequence));

                            dst += sizeof(start_sequence);

                            memcpy(dst, src, nal_size);

                            COUNT_NAL_TYPE(data, *src);

                            dst += nal_size;

                        }

                    } else {

                        av_log(ctx, AV_LOG_ERROR,

                               "nal size exceeds length: %d %d\n", nal_size, src_len);

                    }



                    // eat what we handled

                    src     += nal_size;

                    src_len -= nal_size;



                    if (src_len < 0)

                        av_log(ctx, AV_LOG_ERROR,

                               "Consumed more bytes than we got! (%d)\n", src_len);

                }



                if (pass == 0) {

                    /* now we know the total size of the packet (with the

                     * start sequences added) */

                    av_new_packet(pkt, total_length);

                    dst = pkt->data;

                } else {

                    assert(dst - pkt->data == total_length);

                }

            }

        }

        break;



    case 25:                   // STAP-B

    case 26:                   // MTAP-16

    case 27:                   // MTAP-24

    case 29:                   // FU-B

        av_log(ctx, AV_LOG_ERROR,

               "Unhandled type (%d) (See RFC for implementation details\n",

               type);

        result = AVERROR(ENOSYS);

        break;



    case 28:                   // FU-A (fragmented nal)

        buf++;

        len--;                 // skip the fu_indicator

        if (len > 1) {

            // these are the same as above, we just redo them here for clarity

            uint8_t fu_indicator      = nal;

            uint8_t fu_header         = *buf;

            uint8_t start_bit         = fu_header >> 7;

            uint8_t av_unused end_bit = (fu_header & 0x40) >> 6;

            uint8_t nal_type          = fu_header & 0x1f;

            uint8_t reconstructed_nal;



            // Reconstruct this packet's true nal; only the data follows.

            /* The original nal forbidden bit and NRI are stored in this

             * packet's nal. */

            reconstructed_nal  = fu_indicator & 0xe0;

            reconstructed_nal |= nal_type;



            // skip the fu_header

            buf++;

            len--;



            if (start_bit)

                COUNT_NAL_TYPE(data, nal_type);

            if (start_bit) {

                /* copy in the start sequence, and the reconstructed nal */

                av_new_packet(pkt, sizeof(start_sequence) + sizeof(nal) + len);

                memcpy(pkt->data, start_sequence, sizeof(start_sequence));

                pkt->data[sizeof(start_sequence)] = reconstructed_nal;

                memcpy(pkt->data + sizeof(start_sequence) + sizeof(nal), buf, len);

            } else {

                av_new_packet(pkt, len);

                memcpy(pkt->data, buf, len);

            }

        } else {

            av_log(ctx, AV_LOG_ERROR, "Too short data for FU-A H264 RTP packet\n");

            result = AVERROR_INVALIDDATA;

        }

        break;



    case 30:                   // undefined

    case 31:                   // undefined

    default:

        av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)\n", type);

        result = AVERROR_INVALIDDATA;

        break;

    }



    pkt->stream_index = st->index;



    return result;

}

static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,

                              AVStream *st, AVPacket *pkt, uint32_t *timestamp,

                              const uint8_t *buf, int len, uint16_t seq,

                              int flags)

{

    uint8_t nal;

    uint8_t type;

    int result = 0;



    if (!len) {

        av_log(ctx, AV_LOG_ERROR, "Empty H264 RTP packet\n");

        return AVERROR_INVALIDDATA;

    }

    nal  = buf[0];

    type = nal & 0x1f;



    assert(data);

    assert(buf);



    



    if (type >= 1 && type <= 23)

        type = 1;

    switch (type) {

    case 0:                    

    case 1:

        av_new_packet(pkt, len + sizeof(start_sequence));

        memcpy(pkt->data, start_sequence, sizeof(start_sequence));

        memcpy(pkt->data + sizeof(start_sequence), buf, len);

        COUNT_NAL_TYPE(data, nal);

        break;



    case 24:                   

        

        buf++;

        len--;

        

        {

            int pass         = 0;

            int total_length = 0;

            uint8_t *dst     = NULL;



            for (pass = 0; pass < 2; pass++) {

                const uint8_t *src = buf;

                int src_len        = len;



                while (src_len > 2) {

                    uint16_t nal_size = AV_RB16(src);



                    

                    src     += 2;

                    src_len -= 2;



                    if (nal_size <= src_len) {

                        if (pass == 0) {

                            

                            total_length += sizeof(start_sequence) + nal_size;

                        } else {

                            

                            assert(dst);

                            memcpy(dst, start_sequence, sizeof(start_sequence));

                            dst += sizeof(start_sequence);

                            memcpy(dst, src, nal_size);

                            COUNT_NAL_TYPE(data, *src);

                            dst += nal_size;

                        }

                    } else {

                        av_log(ctx, AV_LOG_ERROR,

                               "nal size exceeds length: %d %d\n", nal_size, src_len);

                    }



                    

                    src     += nal_size;

                    src_len -= nal_size;



                    if (src_len < 0)

                        av_log(ctx, AV_LOG_ERROR,

                               "Consumed more bytes than we got! (%d)\n", src_len);

                }



                if (pass == 0) {

                    



                    av_new_packet(pkt, total_length);

                    dst = pkt->data;

                } else {

                    assert(dst - pkt->data == total_length);

                }

            }

        }

        break;



    case 25:                   

    case 26:                   

    case 27:                   

    case 29:                   

        av_log(ctx, AV_LOG_ERROR,

               "Unhandled type (%d) (See RFC for implementation details\n",

               type);

        result = AVERROR(ENOSYS);

        break;



    case 28:                   

        buf++;

        len--;                 

        if (len > 1) {

            

            uint8_t fu_indicator      = nal;

            uint8_t fu_header         = *buf;

            uint8_t start_bit         = fu_header >> 7;

            uint8_t av_unused end_bit = (fu_header & 0x40) >> 6;

            uint8_t nal_type          = fu_header & 0x1f;

            uint8_t reconstructed_nal;



            

            



            reconstructed_nal  = fu_indicator & 0xe0;

            reconstructed_nal |= nal_type;



            

            buf++;

            len--;



            if (start_bit)

                COUNT_NAL_TYPE(data, nal_type);

            if (start_bit) {

                

                av_new_packet(pkt, sizeof(start_sequence) + sizeof(nal) + len);

                memcpy(pkt->data, start_sequence, sizeof(start_sequence));

                pkt->data[sizeof(start_sequence)] = reconstructed_nal;

                memcpy(pkt->data + sizeof(start_sequence) + sizeof(nal), buf, len);

            } else {

                av_new_packet(pkt, len);

                memcpy(pkt->data, buf, len);

            }

        } else {

            av_log(ctx, AV_LOG_ERROR, "Too short data for FU-A H264 RTP packet\n");

            result = AVERROR_INVALIDDATA;

        }

        break;



    case 30:                   

    case 31:                   

    default:

        av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)\n", type);

        result = AVERROR_INVALIDDATA;

        break;

    }



    pkt->stream_index = st->index;



    return result;

}

        av_new_packet(pkt, len + sizeof(start_sequence));                 av_new_packet(pkt, sizeof(start_sequence) + sizeof(nal) + len);                 av_new_packet(pkt, len);
static int FUNC_0(AVFormatContext *VAR_0, PayloadContext *VAR_1,

                              AVStream *VAR_2, AVPacket *VAR_3, uint32_t *VAR_4,

                              const uint8_t *VAR_5, int VAR_6, uint16_t VAR_7,

                              int VAR_8)

{

    uint8_t nal;

    uint8_t type;

    int VAR_9 = 0;



    if (!VAR_6) {

        av_log(VAR_0, AV_LOG_ERROR, "Empty H264 RTP packet\n");

        return AVERROR_INVALIDDATA;

    }

    nal  = VAR_5[0];

    type = nal & 0x1f;



    assert(VAR_1);

    assert(VAR_5);



    



    if (type >= 1 && type <= 23)

        type = 1;

    switch (type) {

    case 0:                    

    case 1:

        av_new_packet(VAR_3, VAR_6 + sizeof(start_sequence));

        memcpy(VAR_3->VAR_1, start_sequence, sizeof(start_sequence));

        memcpy(VAR_3->VAR_1 + sizeof(start_sequence), VAR_5, VAR_6);

        COUNT_NAL_TYPE(VAR_1, nal);

        break;



    case 24:                   

        

        VAR_5++;

        VAR_6--;

        

        {

            int VAR_10         = 0;

            int VAR_11 = 0;

            uint8_t *dst     = NULL;



            for (VAR_10 = 0; VAR_10 < 2; VAR_10++) {

                const uint8_t *VAR_12 = VAR_5;

                int VAR_13        = VAR_6;



                while (VAR_13 > 2) {

                    uint16_t nal_size = AV_RB16(VAR_12);



                    

                    VAR_12     += 2;

                    VAR_13 -= 2;



                    if (nal_size <= VAR_13) {

                        if (VAR_10 == 0) {

                            

                            VAR_11 += sizeof(start_sequence) + nal_size;

                        } else {

                            

                            assert(dst);

                            memcpy(dst, start_sequence, sizeof(start_sequence));

                            dst += sizeof(start_sequence);

                            memcpy(dst, VAR_12, nal_size);

                            COUNT_NAL_TYPE(VAR_1, *VAR_12);

                            dst += nal_size;

                        }

                    } else {

                        av_log(VAR_0, AV_LOG_ERROR,

                               "nal size exceeds length: %d %d\n", nal_size, VAR_13);

                    }



                    

                    VAR_12     += nal_size;

                    VAR_13 -= nal_size;



                    if (VAR_13 < 0)

                        av_log(VAR_0, AV_LOG_ERROR,

                               "Consumed more bytes than we got! (%d)\n", VAR_13);

                }



                if (VAR_10 == 0) {

                    



                    av_new_packet(VAR_3, VAR_11);

                    dst = VAR_3->VAR_1;

                } else {

                    assert(dst - VAR_3->VAR_1 == VAR_11);

                }

            }

        }

        break;



    case 25:                   

    case 26:                   

    case 27:                   

    case 29:                   

        av_log(VAR_0, AV_LOG_ERROR,

               "Unhandled type (%d) (See RFC for implementation details\n",

               type);

        VAR_9 = AVERROR(ENOSYS);

        break;



    case 28:                   

        VAR_5++;

        VAR_6--;                 

        if (VAR_6 > 1) {

            

            uint8_t fu_indicator      = nal;

            uint8_t fu_header         = *VAR_5;

            uint8_t start_bit         = fu_header >> 7;

            uint8_t av_unused end_bit = (fu_header & 0x40) >> 6;

            uint8_t nal_type          = fu_header & 0x1f;

            uint8_t reconstructed_nal;



            

            



            reconstructed_nal  = fu_indicator & 0xe0;

            reconstructed_nal |= nal_type;



            

            VAR_5++;

            VAR_6--;



            if (start_bit)

                COUNT_NAL_TYPE(VAR_1, nal_type);

            if (start_bit) {

                

                av_new_packet(VAR_3, sizeof(start_sequence) + sizeof(nal) + VAR_6);

                memcpy(VAR_3->VAR_1, start_sequence, sizeof(start_sequence));

                VAR_3->VAR_1[sizeof(start_sequence)] = reconstructed_nal;

                memcpy(VAR_3->VAR_1 + sizeof(start_sequence) + sizeof(nal), VAR_5, VAR_6);

            } else {

                av_new_packet(VAR_3, VAR_6);

                memcpy(VAR_3->VAR_1, VAR_5, VAR_6);

            }

        } else {

            av_log(VAR_0, AV_LOG_ERROR, "Too short VAR_1 for FU-A H264 RTP packet\n");

            VAR_9 = AVERROR_INVALIDDATA;

        }

        break;



    case 30:                   

    case 31:                   

    default:

        av_log(VAR_0, AV_LOG_ERROR, "Undefined type (%d)\n", type);

        VAR_9 = AVERROR_INVALIDDATA;

        break;

    }



    VAR_3->stream_index = VAR_2->index;



    return VAR_9;

}

static int FUNC_0(AVFormatContext *VAR_0, PayloadContext *VAR_1,
AVStream *VAR_2, AVPacket *VAR_3, uint32_t *VAR_4,
const uint8_t *VAR_5, int VAR_6, uint16_t VAR_7,
int VAR_8)
{ uint8_t nal; uint8_t type; int VAR_9 = 0; if (!VAR_6) { av_log(VAR_0, AV_LOG_ERROR, "Empty H264 RTP packet\n"); return AVERROR_INVALIDDATA; } nal  = VAR_5[0]; type = nal & 0x1f; assert(VAR_1); assert(VAR_5); if (type >= 1 && type <= 23)
type = 1; switch (type) { case 0:
case 1:
av_new_packet(VAR_3, VAR_6 + sizeof(start_sequence)); memcpy(VAR_3->VAR_1, start_sequence, sizeof(start_sequence)); memcpy(VAR_3->VAR_1 + sizeof(start_sequence), VAR_5, VAR_6); COUNT_NAL_TYPE(VAR_1, nal); break; case 24:
VAR_5++; VAR_6--; { int VAR_10         = 0; int VAR_11 = 0; uint8_t *dst     = NULL; for (VAR_10 = 0; VAR_10 < 2; VAR_10++) { const uint8_t *VAR_12 = VAR_5; int VAR_13        = VAR_6; while (VAR_13 > 2) { uint16_t nal_size = AV_RB16(VAR_12); VAR_12     += 2; VAR_13 -= 2; if (nal_size <= VAR_13) { if (VAR_10 == 0) { VAR_11 += sizeof(start_sequence) + nal_size; } else { assert(dst); memcpy(dst, start_sequence, sizeof(start_sequence)); dst += sizeof(start_sequence); memcpy(dst, VAR_12, nal_size); COUNT_NAL_TYPE(VAR_1, *VAR_12); dst += nal_size; } } else { av_log(VAR_0, AV_LOG_ERROR,
"nal size exceeds length: %d %d\n", nal_size, VAR_13); } VAR_12     += nal_size; VAR_13 -= nal_size; if (VAR_13 < 0)
av_log(VAR_0, AV_LOG_ERROR,
"Consumed more bytes than we got! (%d)\n", VAR_13); } if (VAR_10 == 0) { av_new_packet(VAR_3, VAR_11); dst = VAR_3->VAR_1; } else { assert(dst - VAR_3->VAR_1 == VAR_11); } } } break; case 25:
case 26:
case 27:
case 29:
av_log(VAR_0, AV_LOG_ERROR,
"Unhandled type (%d) (See RFC for implementation details\n",
type); VAR_9 = AVERROR(ENOSYS); break; case 28:
VAR_5++; VAR_6--; if (VAR_6 > 1) { uint8_t fu_indicator      = nal; uint8_t fu_header         = *VAR_5; uint8_t start_bit         = fu_header >> 7; uint8_t av_unused end_bit = (fu_header & 0x40) >> 6; uint8_t nal_type          = fu_header & 0x1f; uint8_t reconstructed_nal; reconstructed_nal  = fu_indicator & 0xe0; reconstructed_nal |= nal_type; VAR_5++; VAR_6--; if (start_bit)
COUNT_NAL_TYPE(VAR_1, nal_type); if (start_bit) { av_new_packet(VAR_3, sizeof(start_sequence) + sizeof(nal) + VAR_6); memcpy(VAR_3->VAR_1, start_sequence, sizeof(start_sequence)); VAR_3->VAR_1[sizeof(start_sequence)] = reconstructed_nal; memcpy(VAR_3->VAR_1 + sizeof(start_sequence) + sizeof(nal), VAR_5, VAR_6); } else { av_new_packet(VAR_3, VAR_6); memcpy(VAR_3->VAR_1, VAR_5, VAR_6); } } else { av_log(VAR_0, AV_LOG_ERROR, "Too short VAR_1 for FU-A H264 RTP packet\n"); VAR_9 = AVERROR_INVALIDDATA; } break; case 30:
case 31:
default:
av_log(VAR_0, AV_LOG_ERROR, "Undefined type (%d)\n", type); VAR_9 = AVERROR_INVALIDDATA; break; } VAR_3->stream_index = VAR_2->index; return VAR_9; }