Exemplo n.º 1
0
/*
 * read from media stream. (real rdp packet)
 * 
 * fill 'buffer' with data, and buffer size is 'max_size'.
 * receive one chunk from netsock->sock, and fills 'max_size' bytes to buffer.
 * and if there are more bytes in the chunk, the data is stored to
 * stream->netsock->buffer.
 *
 *    return value: positive value ... bytes written to buffer.
 *                  0              ... END OF STREAM
 *                 -1              ... ERROR
 */
int real_rdt_get_media_packet(struct stream_t *stream,
			      uint8_t *buffer,size_t max_size)
{
    int ret = 0;
    uint8_t header[8];
    
    ret = read_data(stream,header,8);
    if(ret < 0) {
	goto failed;
    }

    while(!strncmp((char *)header,"SET_",4) ||
	  !strncmp((char *)header,"GET_",4) ||
	  !strncmp((char *)header,"OPTI",4) ||
	  !strncmp((char *)header,"RTSP",4) ||
	  !strncmp((char *)header,"ANNO",4)) {
	
	stream_data_push_back(stream,header,8); /* push back header */
	ret = real_process_header(stream);
	if(ret < 0) {
	    goto failed;
	}
	
	ret = read_data(stream,header,8);
	if(ret < 8) {
	    goto failed;
	}
    }
    
    ret = real_process_media_packet(stream,header,buffer,max_size);
    return ret;

  failed:
    return -1;
}
Exemplo n.º 2
0
Arquivo: rtsp.c Projeto: clkao/msdl
/*
 * receive rtsp message from stream->sock.
 *      header is guraranteed to be complete after this function,
 *      body should not be complete.
 *      get header only, have to get body later after this function.
 *               return status code : success
 *                               -1 : failure
 */
static int rtsp_recv_header_get(struct stream_t *stream, struct rtsp_header_t *rtsp_hdr)
{
    int ret = 0,i = 0,total = 0;
  
    rtsp_hdr->buffer_len = 0;
    rtsp_hdr->buffer = NULL;
    total = 0;
  
    do { /* get rtsp reply */
	rtsp_hdr->buffer_len += BUFSIZE_1K;
	rtsp_hdr->buffer = (char *)xrealloc(rtsp_hdr->buffer,
					    rtsp_hdr->buffer_len + 1);

	i = recv_data(stream,rtsp_hdr->buffer + total,BUFSIZE_1K);
	if(i <= 0) {
	    display(MSDL_ERR,"rtsp_recv_header error: recv_data() returned %d\n",i);
	    goto failed;
	}
	total += i;
    
	rtsp_hdr->buffer[total] = '\0'; /* for rtsp_is_entire_header */
    } while(!rtsp_is_entire_header(rtsp_hdr));
    
    /* rtsp_hdr->buffer_size is length in buffer, not the malloc()ed size.  */
    rtsp_hdr->buffer_len = total;
    rtsp_hdr->buffer[total] = '\0';
  

    ret = rtsp_response_parse(rtsp_hdr);
    if(ret < 0) {
	display(MSDL_ERR,"response RTSP header parse failed\n");
	goto failed;
    }

    /* push body back !!! */
    if(rtsp_hdr->body_len) {
	stream_data_push_back(stream,rtsp_hdr->body,rtsp_hdr->body_len);
    }
  
    /* rtsp_hdr->buffer *ONLY* contains header, no body follows */
    memset(rtsp_hdr->body,0,rtsp_hdr->body_len);

    /* dbg */
    display(MSDL_DBG,"rtsp header===========\n"
	    "%s\n"
	    "==(%d bytes)====================\n",
	    rtsp_hdr->buffer,strlen(rtsp_hdr->buffer));
  
 
   /* success */
    return rtsp_hdr->status_code;
  
  failed:
    if(rtsp_hdr->buffer) free(rtsp_hdr->buffer);
    rtsp_hdr->buffer = NULL;
    return -1;
}