Mercurial > libavformat.hg
comparison rtsp.c @ 5004:84a7b7a2f252 libavformat
Move function for reading whole specified amount of data from RTSP
demuxer into more common place.
author | kostya |
---|---|
date | Thu, 04 Jun 2009 06:25:53 +0000 |
parents | 0b15fbb456f4 |
children | 43d99d0e12e0 |
comparison
equal
deleted
inserted
replaced
5003:e1749e19c60b | 5004:84a7b7a2f252 |
---|---|
701 skip_spaces(&p); | 701 skip_spaces(&p); |
702 av_strlcpy(reply->server, p, sizeof(reply->server)); | 702 av_strlcpy(reply->server, p, sizeof(reply->server)); |
703 } | 703 } |
704 } | 704 } |
705 | 705 |
706 static int url_readbuf(URLContext *h, unsigned char *buf, int size) | |
707 { | |
708 int ret, len; | |
709 | |
710 len = 0; | |
711 while (len < size) { | |
712 ret = url_read(h, buf+len, size-len); | |
713 if (ret < 1) | |
714 return ret; | |
715 len += ret; | |
716 } | |
717 return len; | |
718 } | |
719 | |
720 /* skip a RTP/TCP interleaved packet */ | 706 /* skip a RTP/TCP interleaved packet */ |
721 static void rtsp_skip_packet(AVFormatContext *s) | 707 static void rtsp_skip_packet(AVFormatContext *s) |
722 { | 708 { |
723 RTSPState *rt = s->priv_data; | 709 RTSPState *rt = s->priv_data; |
724 int ret, len, len1; | 710 int ret, len, len1; |
725 uint8_t buf[1024]; | 711 uint8_t buf[1024]; |
726 | 712 |
727 ret = url_readbuf(rt->rtsp_hd, buf, 3); | 713 ret = url_read_complete(rt->rtsp_hd, buf, 3); |
728 if (ret != 3) | 714 if (ret != 3) |
729 return; | 715 return; |
730 len = AV_RB16(buf + 1); | 716 len = AV_RB16(buf + 1); |
731 | 717 |
732 dprintf(s, "skipping RTP packet len=%d\n", len); | 718 dprintf(s, "skipping RTP packet len=%d\n", len); |
734 /* skip payload */ | 720 /* skip payload */ |
735 while (len > 0) { | 721 while (len > 0) { |
736 len1 = len; | 722 len1 = len; |
737 if (len1 > sizeof(buf)) | 723 if (len1 > sizeof(buf)) |
738 len1 = sizeof(buf); | 724 len1 = sizeof(buf); |
739 ret = url_readbuf(rt->rtsp_hd, buf, len1); | 725 ret = url_read_complete(rt->rtsp_hd, buf, len1); |
740 if (ret != len1) | 726 if (ret != len1) |
741 return; | 727 return; |
742 len -= len1; | 728 len -= len1; |
743 } | 729 } |
744 } | 730 } |
780 /* parse reply (XXX: use buffers) */ | 766 /* parse reply (XXX: use buffers) */ |
781 rt->last_reply[0] = '\0'; | 767 rt->last_reply[0] = '\0'; |
782 for(;;) { | 768 for(;;) { |
783 q = buf; | 769 q = buf; |
784 for(;;) { | 770 for(;;) { |
785 ret = url_readbuf(rt->rtsp_hd, &ch, 1); | 771 ret = url_read_complete(rt->rtsp_hd, &ch, 1); |
786 #ifdef DEBUG_RTP_TCP | 772 #ifdef DEBUG_RTP_TCP |
787 dprintf(s, "ret=%d c=%02x [%c]\n", ret, ch, ch); | 773 dprintf(s, "ret=%d c=%02x [%c]\n", ret, ch, ch); |
788 #endif | 774 #endif |
789 if (ret != 1) | 775 if (ret != 1) |
790 return -1; | 776 return -1; |
827 | 813 |
828 content_length = reply->content_length; | 814 content_length = reply->content_length; |
829 if (content_length > 0) { | 815 if (content_length > 0) { |
830 /* leave some room for a trailing '\0' (useful for simple parsing) */ | 816 /* leave some room for a trailing '\0' (useful for simple parsing) */ |
831 content = av_malloc(content_length + 1); | 817 content = av_malloc(content_length + 1); |
832 (void)url_readbuf(rt->rtsp_hd, content, content_length); | 818 (void)url_read_complete(rt->rtsp_hd, content, content_length); |
833 content[content_length] = '\0'; | 819 content[content_length] = '\0'; |
834 } | 820 } |
835 if (content_ptr) | 821 if (content_ptr) |
836 *content_ptr = content; | 822 *content_ptr = content; |
837 else | 823 else |
1327 return -1; | 1313 return -1; |
1328 if (ret == 1) /* received '$' */ | 1314 if (ret == 1) /* received '$' */ |
1329 break; | 1315 break; |
1330 /* XXX: parse message */ | 1316 /* XXX: parse message */ |
1331 } | 1317 } |
1332 ret = url_readbuf(rt->rtsp_hd, buf, 3); | 1318 ret = url_read_complete(rt->rtsp_hd, buf, 3); |
1333 if (ret != 3) | 1319 if (ret != 3) |
1334 return -1; | 1320 return -1; |
1335 id = buf[0]; | 1321 id = buf[0]; |
1336 len = AV_RB16(buf + 1); | 1322 len = AV_RB16(buf + 1); |
1337 #ifdef DEBUG_RTP_TCP | 1323 #ifdef DEBUG_RTP_TCP |
1338 dprintf(s, "id=%d len=%d\n", id, len); | 1324 dprintf(s, "id=%d len=%d\n", id, len); |
1339 #endif | 1325 #endif |
1340 if (len > buf_size || len < 12) | 1326 if (len > buf_size || len < 12) |
1341 goto redo; | 1327 goto redo; |
1342 /* get the data */ | 1328 /* get the data */ |
1343 ret = url_readbuf(rt->rtsp_hd, buf, len); | 1329 ret = url_read_complete(rt->rtsp_hd, buf, len); |
1344 if (ret != len) | 1330 if (ret != len) |
1345 return -1; | 1331 return -1; |
1346 if (rt->transport == RTSP_TRANSPORT_RDT && | 1332 if (rt->transport == RTSP_TRANSPORT_RDT && |
1347 ff_rdt_parse_header(buf, len, &id, NULL, NULL, NULL, NULL) < 0) | 1333 ff_rdt_parse_header(buf, len, &id, NULL, NULL, NULL, NULL) < 0) |
1348 return -1; | 1334 return -1; |