New submission from h264 <[email protected]>:

I am using ffmpeg as a libray for my application. It 
seems like if I have a HD camera (1080p) using H264 
streaming to my application based on ffmpeg as a 
decoder, I am getting bad sequence message from time 
to time. As it turned out, it is missing some packets 
on based the sequence numbers I put into the modified 
ffmpeg codes.

Here is the section of the codes i used with stpdec.c
static void finalize_packet(RTPDemuxContext *s, 
AVPacket *pkt, uint32_t timestamp)
{
    if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) {
        int64_t addend;
        int delta_timestamp;

        /* compute pts from timestamp with received 
ntp_time */
        delta_timestamp = timestamp - s-
>last_rtcp_timestamp;
        /* convert to the PTS timebase */
        addend = av_rescale(s->last_rtcp_ntp_time - s-
>first_rtcp_ntp_time, s->st->time_base.den, (uint64_t)
s->st->time_base.num << 32);
        pkt->pts = s->range_start_offset + addend + 
delta_timestamp;
    }
}

/**
 * Parse an RTP or RTCP packet directly sent as a 
buffer.
 * @param s RTP parse context.
 * @param pkt returned packet
 * @param buf input buffer or NULL to read the next 
packets
 * @param len buffer len
 * @return 0 if a packet is returned, 1 if a packet 
is returned and more can follow
 * (use buf as NULL to read the next). -1 if no 
packet (error or no more packet).
 */
int rtp_parse_packet(RTPDemuxContext *s, AVPacket 
*pkt,
                     const uint8_t *buf, int len)
{
    unsigned int ssrc, h;
    int payload_type, seq, ret, pt2bytes, flags = 0;
    AVStream *st;
    uint32_t timestamp;
    int rv= 0;

    if (!buf) {
        /* return the next packets, if any */
        if(s->st && s->parse_packet) {
            timestamp= 0; ///< Should not be used if 
buf is NULL, but should be set to the timestamp of 
the packet returned....
            rv= s->parse_packet(s->ic, s-
>dynamic_protocol_context,
                                s->st, pkt, 
&timestamp, NULL, 0, flags);
            finalize_packet(s, pkt, timestamp);
            return rv;
        } else {
            // TODO: Move to a dynamic packet handler 
(like above)
            if (s->read_buf_index >= s->read_buf_size)
                return -1;
            ret = ff_mpegts_parse_packet(s->ts, pkt, 
s->buf + s->read_buf_index,
                                      s-
>read_buf_size - s->read_buf_index);
            if (ret < 0)
                return -1;
            s->read_buf_index += ret;
            if (s->read_buf_index < s->read_buf_size)
                return 1;
            else
                return 0;
        }
    }

    if (len < 12)
        return -1;

    if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
        return -1;
    if (buf[1] >= 200 && buf[1] <= 204) {
        rtcp_parse_packet(s, buf, len);
        return -1;
    }
    payload_type = buf[1] & 0x7f;
    if (buf[1] & 0x80)
        flags |= RTP_FLAG_MARKER;
    seq  = AV_RB16(buf + 2);
    timestamp = AV_RB32(buf + 4);
    ssrc = AV_RB32(buf + 8);
    pt2bytes = AV_RB32(buf + 12);
    /* store the ssrc in the RTPDemuxContext */
    s->ssrc = ssrc;

// I added this section of codes to track down the 
missing data based sequence #.
    av_log(st?st->codec:NULL, AV_LOG_ERROR, "len %d, 
RTP: PT=%02x: cseq %04x, 1st four bytes PT %04x\n",
           len, payload_type, seq, pt2bytes);
    /* NOTE: we can handle only one payload type */
    if (s->payload_type != payload_type)
        return -1;

    st = s->st;
    // only do something with this if all the rtp 
checks pass...
    if(!rtp_valid_packet_in_sequence(&s->statistics, 
seq))
    {
        av_log(st?st->codec:NULL, AV_LOG_ERROR, "RTP: 
PT=%02x: bad cseq %04x expected=%04x\n",
               payload_type, seq, ((s->seq + 1) & 
0xffff));
        s->seq = seq;   // to sync with next one
        return -1;
          
    }

----------
messages: 12565
priority: normal
status: new
substatus: new
title: ffmpeg streaming live 1080i60 video bad sequence reported.
type: bug

________________________________________________
FFmpeg issue tracker <[email protected]>
<https://roundup.ffmpeg.org/issue2364>
________________________________________________

Reply via email to