Example #1
0
int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
                            uint8_t *buf, int buf_size)
{
    RTSPState *rt = s->priv_data;
    int id, len, i, ret;
    RTSPStream *rtsp_st;

#ifdef DEBUG_RTP_TCP
    av_dlog(s, "tcp_read_packet:\n");
#endif
redo:
    for (;;) {
        RTSPMessageHeader reply;

        ret = ff_rtsp_read_reply(s, &reply, NULL, 1, NULL);
        if (ret < 0)
            return ret;
        if (ret == 1) /* received '$' */
            break;
        /* XXX: parse message */
        if (rt->state != RTSP_STATE_STREAMING)
            return 0;
    }
    ret = url_read_complete(rt->rtsp_hd, buf, 3);
    if (ret != 3)
        return -1;
    id  = buf[0];
    len = AV_RB16(buf + 1);
#ifdef DEBUG_RTP_TCP
    av_dlog(s, "id=%d len=%d\n", id, len);
#endif
    if (len > buf_size || len < 12)
        goto redo;
    /* get the data */
    ret = url_read_complete(rt->rtsp_hd, buf, len);
    if (ret != len)
        return -1;
    if (rt->transport == RTSP_TRANSPORT_RDT &&
        ff_rdt_parse_header(buf, len, &id, NULL, NULL, NULL, NULL) < 0)
        return -1;

    /* find the matching stream */
    for (i = 0; i < rt->nb_rtsp_streams; i++) {
        rtsp_st = rt->rtsp_streams[i];
        if (id >= rtsp_st->interleaved_min &&
            id <= rtsp_st->interleaved_max)
            goto found;
    }
    goto redo;
found:
    *prtsp_st = rtsp_st;
    return len;
}
Example #2
0
int
ff_rdt_parse_packet(RDTDemuxContext *s, AVPacket *pkt,
                    uint8_t **bufptr, int len)
{
	uint8_t *buf = bufptr ? *bufptr : NULL;
	int seq_no, flags = 0, stream_id, set_id, is_keyframe;
	uint32_t timestamp;
	int rv= 0;

	if (!s->parse_packet)
		return -1;

	if (!buf && s->prev_stream_id != -1)
	{
		/* return the next packets, if any */
		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->streams[s->prev_stream_id],
		                    pkt, &timestamp, NULL, 0, flags);
		return rv;
	}

	if (len < 12)
		return -1;
	rv = ff_rdt_parse_header(buf, len, &set_id, &seq_no, &stream_id, &is_keyframe, &timestamp);
	if (rv < 0)
		return rv;
	if (is_keyframe &&
	        (set_id != s->prev_set_id || timestamp != s->prev_timestamp ||
	         stream_id != s->prev_stream_id))
	{
		flags |= RTP_FLAG_KEY;
		s->prev_set_id    = set_id;
		s->prev_timestamp = timestamp;
	}
	s->prev_stream_id = stream_id;
	buf += rv;
	len -= rv;

	if (s->prev_stream_id >= s->n_streams)
	{
		s->prev_stream_id = -1;
		return -1;
	}

	rv = s->parse_packet(s->ic, s->dynamic_protocol_context,
	                     s->streams[s->prev_stream_id],
	                     pkt, &timestamp, buf, len, flags);

	return rv;
}