Mercurial > libavformat.hg
comparison rtsp.c @ 391:1cf22651d33b libavformat
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
this is needed for compatibility with tcp.c 1.10
author | michael |
---|---|
date | Sat, 20 Mar 2004 19:57:28 +0000 |
parents | 845f9de2c883 |
children | 056991ab9f10 |
comparison
equal
deleted
inserted
replaced
390:3a40642dc4df | 391:1cf22651d33b |
---|---|
560 } else if (stristart(p, "Range:", &p)) { | 560 } else if (stristart(p, "Range:", &p)) { |
561 rtsp_parse_range_npt(reply, p); | 561 rtsp_parse_range_npt(reply, p); |
562 } | 562 } |
563 } | 563 } |
564 | 564 |
565 static int url_readbuf(URLContext *h, unsigned char *buf, int size) | |
566 { | |
567 int ret, len; | |
568 | |
569 len = 0; | |
570 while (len < size) { | |
571 ret = url_read(h, buf+len, size-len); | |
572 if (ret < 1) | |
573 return ret; | |
574 len += ret; | |
575 } | |
576 return len; | |
577 } | |
578 | |
565 /* skip a RTP/TCP interleaved packet */ | 579 /* skip a RTP/TCP interleaved packet */ |
566 static void rtsp_skip_packet(AVFormatContext *s) | 580 static void rtsp_skip_packet(AVFormatContext *s) |
567 { | 581 { |
568 RTSPState *rt = s->priv_data; | 582 RTSPState *rt = s->priv_data; |
569 int ret, len, len1; | 583 int ret, len, len1; |
570 uint8_t buf[1024]; | 584 uint8_t buf[1024]; |
571 | 585 |
572 ret = url_read(rt->rtsp_hd, buf, 3); | 586 ret = url_readbuf(rt->rtsp_hd, buf, 3); |
573 if (ret != 3) | 587 if (ret != 3) |
574 return; | 588 return; |
575 len = (buf[1] << 8) | buf[2]; | 589 len = (buf[1] << 8) | buf[2]; |
576 #ifdef DEBUG | 590 #ifdef DEBUG |
577 printf("skipping RTP packet len=%d\n", len); | 591 printf("skipping RTP packet len=%d\n", len); |
579 /* skip payload */ | 593 /* skip payload */ |
580 while (len > 0) { | 594 while (len > 0) { |
581 len1 = len; | 595 len1 = len; |
582 if (len1 > sizeof(buf)) | 596 if (len1 > sizeof(buf)) |
583 len1 = sizeof(buf); | 597 len1 = sizeof(buf); |
584 ret = url_read(rt->rtsp_hd, buf, len1); | 598 ret = url_readbuf(rt->rtsp_hd, buf, len1); |
585 if (ret != len1) | 599 if (ret != len1) |
586 return; | 600 return; |
587 len -= len1; | 601 len -= len1; |
588 } | 602 } |
589 } | 603 } |
619 line_count = 0; | 633 line_count = 0; |
620 rt->last_reply[0] = '\0'; | 634 rt->last_reply[0] = '\0'; |
621 for(;;) { | 635 for(;;) { |
622 q = buf; | 636 q = buf; |
623 for(;;) { | 637 for(;;) { |
624 if (url_read(rt->rtsp_hd, &ch, 1) != 1) | 638 if (url_readbuf(rt->rtsp_hd, &ch, 1) != 1) |
625 break; | 639 break; |
626 if (ch == '\n') | 640 if (ch == '\n') |
627 break; | 641 break; |
628 if (ch == '$') { | 642 if (ch == '$') { |
629 /* XXX: only parse it if first char on line ? */ | 643 /* XXX: only parse it if first char on line ? */ |
659 | 673 |
660 content_length = reply->content_length; | 674 content_length = reply->content_length; |
661 if (content_length > 0) { | 675 if (content_length > 0) { |
662 /* leave some room for a trailing '\0' (useful for simple parsing) */ | 676 /* leave some room for a trailing '\0' (useful for simple parsing) */ |
663 content = av_malloc(content_length + 1); | 677 content = av_malloc(content_length + 1); |
664 url_read(rt->rtsp_hd, content, content_length); | 678 (void)url_readbuf(rt->rtsp_hd, content, content_length); |
665 content[content_length] = '\0'; | 679 content[content_length] = '\0'; |
666 } | 680 } |
667 if (content_ptr) | 681 if (content_ptr) |
668 *content_ptr = content; | 682 *content_ptr = content; |
669 } | 683 } |
919 #ifdef DEBUG_RTP_TCP | 933 #ifdef DEBUG_RTP_TCP |
920 printf("tcp_read_packet:\n"); | 934 printf("tcp_read_packet:\n"); |
921 #endif | 935 #endif |
922 redo: | 936 redo: |
923 for(;;) { | 937 for(;;) { |
924 ret = url_read(rt->rtsp_hd, buf, 1); | 938 ret = url_readbuf(rt->rtsp_hd, buf, 1); |
925 #ifdef DEBUG_RTP_TCP | 939 #ifdef DEBUG_RTP_TCP |
926 printf("ret=%d c=%02x [%c]\n", ret, buf[0], buf[0]); | 940 printf("ret=%d c=%02x [%c]\n", ret, buf[0], buf[0]); |
927 #endif | 941 #endif |
928 if (ret != 1) | 942 if (ret != 1) |
929 return -1; | 943 return -1; |
930 if (buf[0] == '$') | 944 if (buf[0] == '$') |
931 break; | 945 break; |
932 } | 946 } |
933 ret = url_read(rt->rtsp_hd, buf, 3); | 947 ret = url_readbuf(rt->rtsp_hd, buf, 3); |
934 if (ret != 3) | 948 if (ret != 3) |
935 return -1; | 949 return -1; |
936 id = buf[0]; | 950 id = buf[0]; |
937 len = (buf[1] << 8) | buf[2]; | 951 len = (buf[1] << 8) | buf[2]; |
938 #ifdef DEBUG_RTP_TCP | 952 #ifdef DEBUG_RTP_TCP |
939 printf("id=%d len=%d\n", id, len); | 953 printf("id=%d len=%d\n", id, len); |
940 #endif | 954 #endif |
941 if (len > buf_size || len < 12) | 955 if (len > buf_size || len < 12) |
942 goto redo; | 956 goto redo; |
943 /* get the data */ | 957 /* get the data */ |
944 ret = url_read(rt->rtsp_hd, buf, len); | 958 ret = url_readbuf(rt->rtsp_hd, buf, len); |
945 if (ret != len) | 959 if (ret != len) |
946 return -1; | 960 return -1; |
947 | 961 |
948 /* find the matching stream */ | 962 /* find the matching stream */ |
949 for(i = 0; i < rt->nb_rtsp_streams; i++) { | 963 for(i = 0; i < rt->nb_rtsp_streams; i++) { |