summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-12-21 00:13:08 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-12-21 00:13:08 +0000
commit0791efc730b69a7c93d97ecc1124486288e520f0 (patch)
tree21bf936f693ee9fc63676edb8a5f953023203ca5 /stream
parentc5ab28319de7bc86640ff73a7cdb722151be22a6 (diff)
downloadmpv-0791efc730b69a7c93d97ecc1124486288e520f0.tar.bz2
mpv-0791efc730b69a7c93d97ecc1124486288e520f0.tar.xz
Reduce code duplication: add a asf_read_wrapper function that never does partial reads
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@25478 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'stream')
-rw-r--r--stream/asf_streaming.c57
1 files changed, 23 insertions, 34 deletions
diff --git a/stream/asf_streaming.c b/stream/asf_streaming.c
index e243e54566..fc13db1a48 100644
--- a/stream/asf_streaming.c
+++ b/stream/asf_streaming.c
@@ -37,6 +37,20 @@ extern int network_bandwidth;
int asf_mmst_streaming_start( stream_t *stream );
static int asf_http_streaming_start(stream_t *stream, int *demuxer_type);
+static int asf_read_wrapper(int fd, void *buffer, int len, streaming_ctrl_t *stream_ctrl) {
+ uint8_t *buf = buffer;
+ while (len > 0) {
+ int got = nop_streaming_read(fd, buf, len, stream_ctrl);
+ if (got <= 0) {
+ mp_msg(MSGT_NETWORK, MSGL_ERR, MSGTR_MPDEMUX_ASF_ErrReadingNetworkStream);
+ return got;
+ }
+ buf += got;
+ len -= got;
+ }
+ return 1;
+}
+
// We can try several protocol for asf streaming
// * first the UDP protcol, if there is a firewall, UDP
// packets will not come back, so the mmsu will fail.
@@ -177,11 +191,8 @@ static int asf_streaming_parse_header(int fd, streaming_ctrl_t* streaming_ctrl)
// is big, the ASF header will be split in 2 network chunk.
// So we need to retrieve all the chunk before starting to parse the header.
do {
- for( r=0; r < (int)sizeof(ASF_stream_chunck_t) ; ) {
- i = nop_streaming_read(fd,((char*)&chunk)+r,sizeof(ASF_stream_chunck_t) - r,streaming_ctrl);
- if(i <= 0) return -1;
- r += i;
- }
+ if (asf_read_wrapper(fd, &chunk, sizeof(ASF_stream_chunck_t), streaming_ctrl) <= 0)
+ return -1;
// Endian handling of the stream chunk
le2me_ASF_stream_chunck_t(&chunk);
size = asf_streaming( &chunk, &r) - sizeof(ASF_stream_chunck_t);
@@ -210,14 +221,8 @@ static int asf_streaming_parse_header(int fd, streaming_ctrl_t* streaming_ctrl)
buffer += buffer_size;
buffer_size += size;
- for(r = 0; r < size;) {
- i = nop_streaming_read(fd,buffer+r,size-r,streaming_ctrl);
- if(i < 0) {
- mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrReadingNetworkStream);
- return -1;
- }
- r += i;
- }
+ if (asf_read_wrapper(fd, buffer, size, streaming_ctrl) <= 0)
+ return -1;
if( chunk_size2read==0 ) {
if(size < (int)sizeof(asfh)) {
@@ -414,18 +419,8 @@ static int asf_http_streaming_read( int fd, char *buffer, int size, streaming_ct
while(1) {
if (rest == 0 && waiting == 0) {
- read = 0;
- while(read < (int)sizeof(ASF_stream_chunck_t)){
- int r = nop_streaming_read( fd, ((char*)&chunk) + read,
- sizeof(ASF_stream_chunck_t)-read,
- streaming_ctrl );
- if(r <= 0){
- if( r < 0)
- mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrReadingChunkHeader);
- return -1;
- }
- read += r;
- }
+ if (asf_read_wrapper(fd, &chunk, sizeof(ASF_stream_chunck_t), streaming_ctrl) <= 0)
+ return -1;
// Endian handling of the stream chunk
le2me_ASF_stream_chunck_t(&chunk);
@@ -457,15 +452,9 @@ static int asf_http_streaming_read( int fd, char *buffer, int size, streaming_ct
rest = chunk_size - size;
chunk_size = size;
}
- while(read < chunk_size) {
- int got = nop_streaming_read( fd,buffer+read,chunk_size-read,streaming_ctrl );
- if(got <= 0) {
- if(got < 0)
- mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_ASF_ErrReadingChunk);
- return -1;
- }
- read += got;
- }
+ if (asf_read_wrapper(fd, buffer, chunk_size, streaming_ctrl) <= 0)
+ return -1;
+ read = chunk_size;
waiting -= read;
if (drop_chunk) continue;
}