1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

avio: make url_read_complete() internal.

This commit is contained in:
Anton Khirnov 2011-03-31 16:40:31 +02:00
parent bc371aca46
commit dce3756459
9 changed files with 41 additions and 35 deletions

View File

@ -184,6 +184,10 @@ int url_read(URLContext *h, unsigned char *buf, int size)
{ {
return ffurl_read(h, buf, size); return ffurl_read(h, buf, size);
} }
int url_read_complete(URLContext *h, unsigned char *buf, int size)
{
return ffurl_read_complete(h, buf, size);
}
#endif #endif
#define URL_SCHEME_CHARS \ #define URL_SCHEME_CHARS \
@ -269,7 +273,7 @@ int ffurl_read(URLContext *h, unsigned char *buf, int size)
return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read); return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
} }
int url_read_complete(URLContext *h, unsigned char *buf, int size) int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
{ {
if (h->flags & URL_WRONLY) if (h->flags & URL_WRONLY)
return AVERROR(EIO); return AVERROR(EIO);

View File

@ -106,17 +106,9 @@ attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags);
attribute_deprecated int url_connect(URLContext *h); attribute_deprecated int url_connect(URLContext *h);
attribute_deprecated int url_open(URLContext **h, const char *url, int flags); attribute_deprecated int url_open(URLContext **h, const char *url, int flags);
attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size); attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size);
attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size);
#endif #endif
/**
* Read as many bytes as possible (up to size), calling the
* read function multiple times if necessary.
* This makes special short-read handling in applications
* unnecessary, if the return value is < size then it is
* certain there was either an error or the end of file was reached.
*/
int url_read_complete(URLContext *h, unsigned char *buf, int size);
/** /**
* Write size bytes from buf to the resource accessed by h. * Write size bytes from buf to the resource accessed by h.
* *

View File

@ -79,7 +79,7 @@ static ChunkType get_chunk_header(MMSHContext *mmsh, int *len)
ChunkType chunk_type; ChunkType chunk_type;
int chunk_len, res, ext_header_len; int chunk_len, res, ext_header_len;
res = url_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH); res = ffurl_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH);
if (res != CHUNK_HEADER_LENGTH) { if (res != CHUNK_HEADER_LENGTH) {
av_log(NULL, AV_LOG_ERROR, "Read data packet header failed!\n"); av_log(NULL, AV_LOG_ERROR, "Read data packet header failed!\n");
return AVERROR(EIO); return AVERROR(EIO);
@ -101,7 +101,7 @@ static ChunkType get_chunk_header(MMSHContext *mmsh, int *len)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
res = url_read_complete(mms->mms_hd, ext_header, ext_header_len); res = ffurl_read_complete(mms->mms_hd, ext_header, ext_header_len);
if (res != ext_header_len) { if (res != ext_header_len) {
av_log(NULL, AV_LOG_ERROR, "Read ext header failed!\n"); av_log(NULL, AV_LOG_ERROR, "Read ext header failed!\n");
return AVERROR(EIO); return AVERROR(EIO);
@ -122,7 +122,7 @@ static int read_data_packet(MMSHContext *mmsh, const int len)
len, sizeof(mms->in_buffer)); len, sizeof(mms->in_buffer));
return AVERROR(EIO); return AVERROR(EIO);
} }
res = url_read_complete(mms->mms_hd, mms->in_buffer, len); res = ffurl_read_complete(mms->mms_hd, mms->in_buffer, len);
av_dlog(NULL, "Data packet len = %d\n", len); av_dlog(NULL, "Data packet len = %d\n", len);
if (res != len) { if (res != len) {
av_log(NULL, AV_LOG_ERROR, "Read data packet failed!\n"); av_log(NULL, AV_LOG_ERROR, "Read data packet failed!\n");
@ -174,7 +174,7 @@ static int get_http_header_data(MMSHContext *mmsh)
len, mms->asf_header_size); len, mms->asf_header_size);
return AVERROR(EIO); return AVERROR(EIO);
} }
res = url_read_complete(mms->mms_hd, mms->asf_header, len); res = ffurl_read_complete(mms->mms_hd, mms->asf_header, len);
if (res != len) { if (res != len) {
av_log(NULL, AV_LOG_ERROR, av_log(NULL, AV_LOG_ERROR,
"Recv asf header data len %d != expected len %d\n", res, len); "Recv asf header data len %d != expected len %d\n", res, len);
@ -197,7 +197,7 @@ static int get_http_header_data(MMSHContext *mmsh)
len, sizeof(mms->in_buffer)); len, sizeof(mms->in_buffer));
return AVERROR(EIO); return AVERROR(EIO);
} }
res = url_read_complete(mms->mms_hd, mms->in_buffer, len); res = ffurl_read_complete(mms->mms_hd, mms->in_buffer, len);
if (res != len) { if (res != len) {
av_log(NULL, AV_LOG_ERROR, "Read other chunk type data failed!\n"); av_log(NULL, AV_LOG_ERROR, "Read other chunk type data failed!\n");
return AVERROR(EIO); return AVERROR(EIO);

View File

@ -241,7 +241,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst)
MMSSCPacketType packet_type= -1; MMSSCPacketType packet_type= -1;
MMSContext *mms = &mmst->mms; MMSContext *mms = &mmst->mms;
for(;;) { for(;;) {
read_result = url_read_complete(mms->mms_hd, mms->in_buffer, 8); read_result = ffurl_read_complete(mms->mms_hd, mms->in_buffer, 8);
if (read_result != 8) { if (read_result != 8) {
if(read_result < 0) { if(read_result < 0) {
av_log(NULL, AV_LOG_ERROR, av_log(NULL, AV_LOG_ERROR,
@ -261,7 +261,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst)
int length_remaining, hr; int length_remaining, hr;
mmst->incoming_flags= mms->in_buffer[3]; mmst->incoming_flags= mms->in_buffer[3];
read_result= url_read_complete(mms->mms_hd, mms->in_buffer+8, 4); read_result= ffurl_read_complete(mms->mms_hd, mms->in_buffer+8, 4);
if(read_result != 4) { if(read_result != 4) {
av_log(NULL, AV_LOG_ERROR, av_log(NULL, AV_LOG_ERROR,
"Reading command packet length failed: %d (%s)\n", "Reading command packet length failed: %d (%s)\n",
@ -281,7 +281,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst)
length_remaining, sizeof(mms->in_buffer) - 12); length_remaining, sizeof(mms->in_buffer) - 12);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
read_result = url_read_complete(mms->mms_hd, mms->in_buffer + 12, read_result = ffurl_read_complete(mms->mms_hd, mms->in_buffer + 12,
length_remaining) ; length_remaining) ;
if (read_result != length_remaining) { if (read_result != length_remaining) {
av_log(NULL, AV_LOG_ERROR, av_log(NULL, AV_LOG_ERROR,
@ -319,7 +319,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst)
} }
mms->remaining_in_len = length_remaining; mms->remaining_in_len = length_remaining;
mms->read_in_ptr = mms->in_buffer; mms->read_in_ptr = mms->in_buffer;
read_result= url_read_complete(mms->mms_hd, mms->in_buffer, length_remaining); read_result= ffurl_read_complete(mms->mms_hd, mms->in_buffer, length_remaining);
if(read_result != length_remaining) { if(read_result != length_remaining) {
av_log(NULL, AV_LOG_ERROR, av_log(NULL, AV_LOG_ERROR,
"Failed to read packet data of size %d: %d (%s)\n", "Failed to read packet data of size %d: %d (%s)\n",

View File

@ -86,7 +86,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
if (channel_id < 2) { //special case for channel number >= 64 if (channel_id < 2) { //special case for channel number >= 64
buf[1] = 0; buf[1] = 0;
if (url_read_complete(h, buf, channel_id + 1) != channel_id + 1) if (ffurl_read_complete(h, buf, channel_id + 1) != channel_id + 1)
return AVERROR(EIO); return AVERROR(EIO);
size += channel_id + 1; size += channel_id + 1;
channel_id = AV_RL16(buf) + 64; channel_id = AV_RL16(buf) + 64;
@ -99,28 +99,28 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
if (hdr == RTMP_PS_ONEBYTE) { if (hdr == RTMP_PS_ONEBYTE) {
timestamp = prev_pkt[channel_id].ts_delta; timestamp = prev_pkt[channel_id].ts_delta;
} else { } else {
if (url_read_complete(h, buf, 3) != 3) if (ffurl_read_complete(h, buf, 3) != 3)
return AVERROR(EIO); return AVERROR(EIO);
size += 3; size += 3;
timestamp = AV_RB24(buf); timestamp = AV_RB24(buf);
if (hdr != RTMP_PS_FOURBYTES) { if (hdr != RTMP_PS_FOURBYTES) {
if (url_read_complete(h, buf, 3) != 3) if (ffurl_read_complete(h, buf, 3) != 3)
return AVERROR(EIO); return AVERROR(EIO);
size += 3; size += 3;
data_size = AV_RB24(buf); data_size = AV_RB24(buf);
if (url_read_complete(h, buf, 1) != 1) if (ffurl_read_complete(h, buf, 1) != 1)
return AVERROR(EIO); return AVERROR(EIO);
size++; size++;
type = buf[0]; type = buf[0];
if (hdr == RTMP_PS_TWELVEBYTES) { if (hdr == RTMP_PS_TWELVEBYTES) {
if (url_read_complete(h, buf, 4) != 4) if (ffurl_read_complete(h, buf, 4) != 4)
return AVERROR(EIO); return AVERROR(EIO);
size += 4; size += 4;
extra = AV_RL32(buf); extra = AV_RL32(buf);
} }
} }
if (timestamp == 0xFFFFFF) { if (timestamp == 0xFFFFFF) {
if (url_read_complete(h, buf, 4) != 4) if (ffurl_read_complete(h, buf, 4) != 4)
return AVERROR(EIO); return AVERROR(EIO);
timestamp = AV_RB32(buf); timestamp = AV_RB32(buf);
} }
@ -140,7 +140,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
prev_pkt[channel_id].extra = extra; prev_pkt[channel_id].extra = extra;
while (data_size > 0) { while (data_size > 0) {
int toread = FFMIN(data_size, chunk_size); int toread = FFMIN(data_size, chunk_size);
if (url_read_complete(h, p->data + offset, toread) != toread) { if (ffurl_read_complete(h, p->data + offset, toread) != toread) {
ff_rtmp_packet_destroy(p); ff_rtmp_packet_destroy(p);
return AVERROR(EIO); return AVERROR(EIO);
} }
@ -148,7 +148,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
offset += chunk_size; offset += chunk_size;
size += chunk_size; size += chunk_size;
if (data_size > 0) { if (data_size > 0) {
url_read_complete(h, &t, 1); //marker ffurl_read_complete(h, &t, 1); //marker
size++; size++;
if (t != (0xC0 + channel_id)) if (t != (0xC0 + channel_id))
return -1; return -1;

View File

@ -487,12 +487,12 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
client_pos = rtmp_handshake_imprint_with_digest(tosend + 1); client_pos = rtmp_handshake_imprint_with_digest(tosend + 1);
url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1); url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1);
i = url_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1); i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1);
if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) { if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) {
av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
return -1; return -1;
} }
i = url_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE); i = ffurl_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE);
if (i != RTMP_HANDSHAKE_PACKET_SIZE) { if (i != RTMP_HANDSHAKE_PACKET_SIZE) {
av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
return -1; return -1;

View File

@ -818,7 +818,7 @@ void ff_rtsp_skip_packet(AVFormatContext *s)
int ret, len, len1; int ret, len, len1;
uint8_t buf[1024]; uint8_t buf[1024];
ret = url_read_complete(rt->rtsp_hd, buf, 3); ret = ffurl_read_complete(rt->rtsp_hd, buf, 3);
if (ret != 3) if (ret != 3)
return; return;
len = AV_RB16(buf + 1); len = AV_RB16(buf + 1);
@ -830,7 +830,7 @@ void ff_rtsp_skip_packet(AVFormatContext *s)
len1 = len; len1 = len;
if (len1 > sizeof(buf)) if (len1 > sizeof(buf))
len1 = sizeof(buf); len1 = sizeof(buf);
ret = url_read_complete(rt->rtsp_hd, buf, len1); ret = ffurl_read_complete(rt->rtsp_hd, buf, len1);
if (ret != len1) if (ret != len1)
return; return;
len -= len1; len -= len1;
@ -855,7 +855,7 @@ int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
for (;;) { for (;;) {
q = buf; q = buf;
for (;;) { for (;;) {
ret = url_read_complete(rt->rtsp_hd, &ch, 1); ret = ffurl_read_complete(rt->rtsp_hd, &ch, 1);
#ifdef DEBUG_RTP_TCP #ifdef DEBUG_RTP_TCP
av_dlog(s, "ret=%d c=%02x [%c]\n", ret, ch, ch); av_dlog(s, "ret=%d c=%02x [%c]\n", ret, ch, ch);
#endif #endif
@ -903,7 +903,7 @@ int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
if (content_length > 0) { if (content_length > 0) {
/* leave some room for a trailing '\0' (useful for simple parsing) */ /* leave some room for a trailing '\0' (useful for simple parsing) */
content = av_malloc(content_length + 1); content = av_malloc(content_length + 1);
(void)url_read_complete(rt->rtsp_hd, content, content_length); ffurl_read_complete(rt->rtsp_hd, content, content_length);
content[content_length] = '\0'; content[content_length] = '\0';
} }
if (content_ptr) if (content_ptr)

View File

@ -28,6 +28,7 @@
#include "os_support.h" #include "os_support.h"
#include "rtsp.h" #include "rtsp.h"
#include "rdt.h" #include "rdt.h"
#include "url.h"
//#define DEBUG //#define DEBUG
//#define DEBUG_RTP_TCP //#define DEBUG_RTP_TCP
@ -200,7 +201,7 @@ redo:
if (rt->state != RTSP_STATE_STREAMING) if (rt->state != RTSP_STATE_STREAMING)
return 0; return 0;
} }
ret = url_read_complete(rt->rtsp_hd, buf, 3); ret = ffurl_read_complete(rt->rtsp_hd, buf, 3);
if (ret != 3) if (ret != 3)
return -1; return -1;
id = buf[0]; id = buf[0];
@ -211,7 +212,7 @@ redo:
if (len > buf_size || len < 12) if (len > buf_size || len < 12)
goto redo; goto redo;
/* get the data */ /* get the data */
ret = url_read_complete(rt->rtsp_hd, buf, len); ret = ffurl_read_complete(rt->rtsp_hd, buf, len);
if (ret != len) if (ret != len)
return -1; return -1;
if (rt->transport == RTSP_TRANSPORT_RDT && if (rt->transport == RTSP_TRANSPORT_RDT &&

View File

@ -69,4 +69,13 @@ int ffurl_open(URLContext **h, const char *url, int flags);
*/ */
int ffurl_read(URLContext *h, unsigned char *buf, int size); int ffurl_read(URLContext *h, unsigned char *buf, int size);
/**
* Read as many bytes as possible (up to size), calling the
* read function multiple times if necessary.
* This makes special short-read handling in applications
* unnecessary, if the return value is < size then it is
* certain there was either an error or the end of file was reached.
*/
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
#endif //AVFORMAT_URL_H #endif //AVFORMAT_URL_H