diff -Naur libmpdemux/demux_avi.c.orig libmpdemux/demux_avi.c --- libmpdemux/demux_avi.c.orig Wed Oct 22 22:01:37 2003 +++ libmpdemux/demux_avi.c Sun Jan 11 22:40:31 2004 @@ -214,7 +214,7 @@ } pos = priv->idx_offset + (unsigned long)idx->dwChunkOffset; - if((posmovi_start || pos>=demux->movi_end) && (demux->movi_end>demux->movi_start) && (demux->stream->type!=STREAMTYPE_STREAM)){ + if((posmovi_start || pos>=demux->movi_end) && (demux->movi_end>demux->movi_start) && (demux->stream->type!=STREAMTYPE_STREAM || demux->stream->seek)){ mp_msg(MSGT_DEMUX,MSGL_V,"ChunkOffset out of range! idx=0x%X \n",pos); continue; } @@ -246,7 +246,7 @@ if(!(idx->dwFlags&AVIIF_KEYFRAME)) flags=0; } else { demux->filepos=stream_tell(demux->stream); - if(demux->filepos>=demux->movi_end && demux->movi_end>demux->movi_start && (demux->stream->type!=STREAMTYPE_STREAM)){ + if(demux->filepos>=demux->movi_end && demux->movi_end>demux->movi_start && (demux->stream->type!=STREAMTYPE_STREAM || demux->stream->seek)){ demux->stream->eof=1; return 0; } @@ -449,7 +449,7 @@ demuxer->priv=(void*)priv; //---- AVI header: - read_avi_header(demuxer,(demuxer->stream->type!=STREAMTYPE_STREAM)?index_mode:-2); + read_avi_header(demuxer,(demuxer->stream->type!=STREAMTYPE_STREAM || demuxer->stream->seek)?index_mode:-2); if(demuxer->audio->id>=0 && !demuxer->a_streams[demuxer->audio->id]){ mp_msg(MSGT_DEMUX,MSGL_WARN,"AVI: invalid audio stream ID: %d - ignoring (nosound)\n",demuxer->audio->id); diff -Naur libmpdemux/network.c.orig libmpdemux/network.c --- libmpdemux/network.c.orig Mon Dec 8 15:25:32 2003 +++ libmpdemux/network.c Sun Jan 11 21:39:31 2004 @@ -428,7 +428,8 @@ } int -http_send_request( URL_t *url ) { +http_send_request2( URL_t *url, off_t pos ) { +// Extend http_send_request with possibility to do partial content retrieval HTTP_header_t *http_hdr; URL_t *server_url; char str[256]; @@ -455,6 +456,11 @@ } else http_set_field( http_hdr, "User-Agent: MPlayer/"VERSION); + + if(pos>0) { + snprintf(str, 256, "Range: bytes=%d-", pos); + http_set_field(http_hdr, str); + } if (network_cookies_enabled) cookies_set( http_hdr, server_url->hostname, server_url->url ); @@ -488,6 +494,12 @@ return fd; } +int +http_send_request( URL_t *url ) { +// old http_send_request functionality + return http_send_request2(url,0); +} + HTTP_header_t * http_read_response( int fd ) { HTTP_header_t *http_hdr; @@ -572,6 +584,50 @@ return 0; } +int +http_seek( stream_t *stream, off_t pos ) { + HTTP_header_t *http_hdr = NULL; + int fd; + if( stream==NULL ) return -1; + + if( stream->fd>0 ) closesocket(stream->fd); // need to reconnect to seek in http-stream + fd = http_send_request2( stream->streaming_ctrl->url, pos ); + if( fd<0 ) return -1; + + http_hdr = http_read_response( fd ); + + if( http_hdr==NULL ) return -1; + + switch( http_hdr->status_code ) { + case 200: + case 206: // OK + mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") ); + mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") ); + if( http_hdr->body_size>0 ) { + if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { + http_free( http_hdr ); + return -1; + } + } + break; + default: + mp_msg(MSGT_NETWORK,MSGL_ERR,"Server return %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase ); + close( fd ); + fd = -1; + } + stream->fd = fd; + + if( http_hdr ) { + http_free( http_hdr ); + stream->streaming_ctrl->data = NULL; + } + + stream->pos=pos; + + return 0; +} + + // By using the protocol, the extension of the file or the content-type // we might be able to guess the streaming type. int @@ -581,6 +637,7 @@ int fd=-1; int redirect; int auth_retry=0; + int seekable=0; char *extension; char *content_type; char *next_url; @@ -701,7 +758,10 @@ } streaming_ctrl->data = (void*)http_hdr; - + + // Check if can make partial content requests and thus seek in http-streams + seekable=(http_hdr!=NULL && http_hdr->status_code==200 && strncmp(http_get_field(http_hdr,"Accept-Ranges"),"bytes",5)==0); + // Check if the response is an ICY status_code reason_phrase if( !strcasecmp(http_hdr->protocol, "ICY") ) { switch( http_hdr->status_code ) { @@ -756,13 +816,13 @@ for( i=0 ; i<(sizeof(mime_type_table)/sizeof(mime_type_table[0])) ; i++ ) { if( !strcasecmp( content_type, mime_type_table[i].mime_type ) ) { *file_format = mime_type_table[i].demuxer_type; - return 0; + return seekable; // for streaming_start } } } // Not found in the mime type table, don't fail, // we should try raw HTTP - return 0; + return seekable; // for streaming_start // Redirect case 301: // Permanently case 302: // Temporarily @@ -1121,6 +1181,11 @@ if( ret<0 ) { return -1; } + if( ret==1 ) { + stream->flags |= STREAM_SEEK; + stream->seek = http_seek; + } + ret = -1; // Get the bandwidth available diff -Naur libmpdemux/stream.c.orig libmpdemux/stream.c --- libmpdemux/stream.c.orig Sun Aug 31 21:51:05 2003 +++ libmpdemux/stream.c Sun Jan 11 21:47:06 2004 @@ -314,6 +314,14 @@ // A function call that return -1 can tell that the protocol // doesn't support seeking. #ifdef MPLAYER_NETWORK + if(s->seek) { // new stream seek is much cleaner than streaming_ctrl one + if(!s->seek(s,newpos)) { + mp_msg(MSGT_STREAM,MSGL_ERR, "Seek failed\n"); + return 1; + } + break; + } + if( s->streaming_ctrl!=NULL && s->streaming_ctrl->streaming_seek ) { if( s->streaming_ctrl->streaming_seek( s->fd, pos, s->streaming_ctrl )<0 ) { mp_msg(MSGT_STREAM,MSGL_INFO,"Stream not seekable!\n"); diff -Naur libmpdemux/stream.h.orig libmpdemux/stream.h --- libmpdemux/stream.h.orig Wed Aug 13 19:29:31 2003 +++ libmpdemux/stream.h Sun Jan 11 22:39:26 2004 @@ -216,7 +216,7 @@ } inline static int stream_skip(stream_t *s,off_t len){ - if(len<0 || (len>2*STREAM_BUFFER_SIZE && s->type!=STREAMTYPE_STREAM)){ + if(len<0 || (len>2*STREAM_BUFFER_SIZE && (s->type!=STREAMTYPE_STREAM || s->seek))) { // negative or big skip! return stream_seek(s,stream_tell(s)+len); }