[Mplayer-cvslog] CVS: main asf_streaming.c,1.3,1.4
Bertrand Baudet
bertrand at users.sourceforge.net
Mon Jun 4 19:55:01 CEST 2001
Update of /cvsroot/mplayer/main
In directory usw-pr-cvs1:/tmp/cvs-serv18619
Modified Files:
asf_streaming.c
Log Message:
Continue implementation of ASF streaming.
Index: asf_streaming.c
===================================================================
RCS file: /cvsroot/mplayer/main/asf_streaming.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** asf_streaming.c 2001/05/29 17:09:19 1.3
--- asf_streaming.c 2001/06/04 17:54:59 1.4
***************
*** 3,44 ****
#include <string.h>
- #include "asf.h"
#include "url.h"
#include "http.h"
#include "network.h"
! #define BUFFER_SIZE 2048
! const char *temp_response =
! "HTTP/1.0 200 OK\r\n"
! "Date: Tue, 20 Mar 2001 11:40:35 GMT\r\n"
! "Content-Type: application/octet-stream\r\n"
! "Server: Cougar 4.1.0.3920\r\n"
! "Cache-Control: no-cache\r\n"
! "Pragma: no-cache, client-id=290092, features=\"broadcast\"\r\n"
! /* "Pragma: no-cache\r\n"
! "Pragma: client-id=290092\r\n"
! "Pragma: features=\"broadcast\"\r\n"
! */ "\r\n";
static ASF_StreamType_e streaming_type = ASF_Unknown_e;
! void
! asf_streaming(char *data, int length) {
ASF_stream_chunck_t *stream_chunck=(ASF_stream_chunck_t*)data;
printf("ASF stream chunck size=%d\n", stream_chunck->size);
if( stream_chunck->size<8 ) {
printf("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size);
! return;
}
if( stream_chunck->size!=stream_chunck->size_confirm ) {
printf("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm);
! return;
}
switch(stream_chunck->type) {
case 0x4324: // Clear ASF configuration
printf("=====> Clearing ASF stream configuration!\n");
break;
case 0x4424: // Data follows
--- 3,76 ----
#include <string.h>
#include "url.h"
#include "http.h"
+ #include "asf.h"
#include "network.h"
! #include "stream.h"
! #include "demuxer.h"
! extern demuxer_t *demuxer;
static ASF_StreamType_e streaming_type = ASF_Unknown_e;
! int
! asf_http_streaming_read( streaming_ctrl_t *streaming_ctrl ) {
! char *buffer;
! int drop_packet;
! int ret;
! printf("asf_streaming_read\n");
! ret = asf_streaming( streaming_ctrl->buffer->buffer, streaming_ctrl->buffer->length, &drop_packet );
! printf("ret: %d\n", ret);
! if( ret<0 ) return -1;
! if( ret>streaming_ctrl->buffer->length ) return 0;
! buffer = (char*)malloc(ret);
! if( buffer==NULL ) {
! printf("Memory allocation failed\n");
! return -1;
! }
! printf("buffer length: %d\n", streaming_ctrl->buffer->length );
! net_fifo_pop( streaming_ctrl->buffer, buffer, ret );
! printf(" pop: 0x%02X\n", *((unsigned int*)buffer) );
! printf("buffer length: %d\n", streaming_ctrl->buffer->length );
! printf("0x%02X\n", *((unsigned int*)(buffer+sizeof(ASF_stream_chunck_t))) );
! if( !drop_packet ) {
! write( streaming_ctrl->fd_pipe_in, buffer+sizeof(ASF_stream_chunck_t), ret-sizeof(ASF_stream_chunck_t) );
! }
! free( buffer );
! return ret;
! }
!
! int
! asf_streaming(char *data, int length, int *drop_packet ) {
ASF_stream_chunck_t *stream_chunck=(ASF_stream_chunck_t*)data;
printf("ASF stream chunck size=%d\n", stream_chunck->size);
+ printf("length: %d\n", length );
+ printf("0x%02X\n", stream_chunck->type );
+
+ if( drop_packet!=NULL ) *drop_packet = 0;
+ if( data==NULL || length<=0 ) return -1;
if( stream_chunck->size<8 ) {
printf("Ahhhh, stream_chunck size is too small: %d\n", stream_chunck->size);
! return -1;
}
if( stream_chunck->size!=stream_chunck->size_confirm ) {
printf("size_confirm mismatch!: %d %d\n", stream_chunck->size, stream_chunck->size_confirm);
! return -1;
}
+ printf(" type: 0x%02X\n", stream_chunck->type );
+ printf(" size: %d (0x%02X)\n", stream_chunck->size, stream_chunck->size );
+ printf(" sequence_number: 0x%04X\n", stream_chunck->sequence_number );
+ printf(" unknown: 0x%02X\n", stream_chunck->unknown );
+ printf(" size_confirm: 0x%02X\n", stream_chunck->size_confirm );
+
+
switch(stream_chunck->type) {
case 0x4324: // Clear ASF configuration
printf("=====> Clearing ASF stream configuration!\n");
+ if( drop_packet!=NULL ) *drop_packet = 1;
+ return stream_chunck->size;
break;
case 0x4424: // Data follows
***************
*** 47,50 ****
--- 79,84 ----
case 0x4524: // Transfer complete
printf("=====> Transfer complete\n");
+ if( drop_packet!=NULL ) *drop_packet = 1;
+ return stream_chunck->size;
break;
case 0x4824: // ASF header chunk follows
***************
*** 54,57 ****
--- 88,92 ----
printf("=====> Unknown stream type 0x%x\n", stream_chunck->type );
}
+ return stream_chunck->size+4;
}
***************
*** 61,71 ****
if( !strcasecmp(content_type, "application/octet-stream") ) {
if( features==NULL ) {
! printf("=====> Prerecorded\n");
return ASF_Prerecorded_e;
} else if( strstr(features, "broadcast")) {
! printf("=====> Live stream\n");
return ASF_Live_e;
} else {
! printf("=====> Prerecorded\n");
return ASF_Prerecorded_e;
}
--- 96,106 ----
if( !strcasecmp(content_type, "application/octet-stream") ) {
if( features==NULL ) {
! printf("=====> ASF Prerecorded\n");
return ASF_Prerecorded_e;
} else if( strstr(features, "broadcast")) {
! printf("=====> ASF Live stream\n");
return ASF_Live_e;
} else {
! printf("=====> ASF Prerecorded\n");
return ASF_Prerecorded_e;
}
***************
*** 78,85 ****
(!strcasecmp(content_type, "video/x-ms-wmv")) ||
(!strcasecmp(content_type, "video/x-ms-wma")) ) {
! printf("=====> Redirector\n");
return ASF_Redirector_e;
} else {
! printf("=====> unknown content-type: %s\n", content_type );
return ASF_Unknown_e;
}
--- 113,120 ----
(!strcasecmp(content_type, "video/x-ms-wmv")) ||
(!strcasecmp(content_type, "video/x-ms-wma")) ) {
! printf("=====> ASF Redirector\n");
return ASF_Redirector_e;
} else {
! printf("=====> ASF unknown content-type: %s\n", content_type );
return ASF_Unknown_e;
}
***************
*** 88,100 ****
}
- //void asf_http_request(stream_t *stream, URL_t *url) {
HTTP_header_t *
asf_http_request(URL_t *url) {
HTTP_header_t *http_hdr;
char str[250];
char *request;
int offset_hi=0, offset_lo=0, req_nb=1, length=0;
! int asf_nb_stream=1; // FIXME
// Common header for all requests.
--- 123,136 ----
}
HTTP_header_t *
asf_http_request(URL_t *url) {
HTTP_header_t *http_hdr;
char str[250];
+ char *ptr;
char *request;
+ int i;
int offset_hi=0, offset_lo=0, req_nb=1, length=0;
! int asf_nb_stream;
// Common header for all requests.
***************
*** 115,121 ****
case ASF_Prerecorded_e:
http_set_field( http_hdr, "Pragma: xPlayStrm=1" );
sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream );
http_set_field( http_hdr, str );
- http_set_field( http_hdr, "Pragma: stream-switch-entry=ffff:1:0" ); // FIXME
break;
case ASF_Redirector_e:
--- 151,176 ----
case ASF_Prerecorded_e:
http_set_field( http_hdr, "Pragma: xPlayStrm=1" );
+ ptr = str;
+ ptr += sprintf( ptr, "Pragma: stream-switch-entry=");
+ for( i=0, asf_nb_stream=0 ; i<256 ; i++ ) {
+ // FIXME START
+ if( demuxer==NULL ) {
+ ptr += sprintf( ptr, " ffff:1:0" );
+ asf_nb_stream = 1;
+ break;
+ }
+ // FIXME END
+ if( demuxer->a_streams[i] ) {
+ ptr += sprintf( ptr, " ffff:%d:0", i );
+ asf_nb_stream++;
+ }
+ if( demuxer->v_streams[i] ) {
+ ptr += sprintf( ptr, " ffff:%d:0", i );
+ asf_nb_stream++;
+ }
+ }
+ http_set_field( http_hdr, str );
sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream );
http_set_field( http_hdr, str );
break;
case ASF_Redirector_e:
***************
*** 180,184 ****
if( http_hdr->body_size>0 ) {
! asf_streaming( http_hdr->body, http_hdr->body_size );
}
--- 235,239 ----
if( http_hdr->body_size>0 ) {
! asf_streaming( http_hdr->body, http_hdr->body_size, NULL);
}
***************
*** 197,222 ****
int
! asf_http_streaming_start( URL_t **url_ref ) {
HTTP_header_t *http_hdr=NULL;
URL_t *url_next=NULL;
! URL_t *url=*url_ref;
char buffer[BUFFER_SIZE];
int i;
! int fd=-1;
int done=1;
do {
if( fd>0 ) close( fd );
fd = connect2Server( url->hostname, url->port );
if( fd<0 ) return -1;
http_hdr = asf_http_request( url );
! //printf("[%s]\n", http_hdr->buffer );
write( fd, http_hdr->buffer, http_hdr->buffer_size );
! http_free( http_hdr );
http_hdr = http_new_header();
do {
! i = read( fd, buffer, BUFFER_SIZE );
printf("read: %d\n", i );
http_response_append( http_hdr, buffer, i );
} while( !http_is_header_entired( http_hdr ) );
--- 252,285 ----
int
! asf_http_streaming_start( streaming_ctrl_t *streaming_ctrl ) {
HTTP_header_t *http_hdr=NULL;
URL_t *url_next=NULL;
! URL_t *url = *(streaming_ctrl->url);
char buffer[BUFFER_SIZE];
int i;
! int fd = streaming_ctrl->fd_net;
int done=1;
+
+ streaming_type = ASF_Live_e;
do {
if( fd>0 ) close( fd );
+
fd = connect2Server( url->hostname, url->port );
if( fd<0 ) return -1;
http_hdr = asf_http_request( url );
! printf("[%s]\n", http_hdr->buffer );
write( fd, http_hdr->buffer, http_hdr->buffer_size );
! // http_free( http_hdr );
http_hdr = http_new_header();
do {
! i = readFromServer( fd, buffer, BUFFER_SIZE );
printf("read: %d\n", i );
+ if( i<0 ) {
+ perror("read");
+ http_free( http_hdr );
+ return -1;
+ }
http_response_append( http_hdr, buffer, i );
} while( !http_is_header_entired( http_hdr ) );
***************
*** 225,239 ****
if( asf_http_parse_response(http_hdr)<0 ) {
printf("Failed to parse header\n");
return -1;
}
!
! switch(streaming_type) {
case ASF_Live_e:
case ASF_Prerecorded_e:
! if( http_hdr->body_size==0 ) {
! i = read( fd, buffer, BUFFER_SIZE );
printf("read: %d\n", i );
! asf_streaming( buffer, i );
}
break;
case ASF_Redirector_e:
--- 288,312 ----
if( asf_http_parse_response(http_hdr)<0 ) {
printf("Failed to parse header\n");
+ http_free( http_hdr );
return -1;
}
! switch( streaming_type ) {
case ASF_Live_e:
case ASF_Prerecorded_e:
! if( http_hdr->body_size>0 ) {
! printf("--- 0x%02X\n", streaming_ctrl->buffer );
! net_fifo_push( streaming_ctrl->buffer, http_hdr->body, http_hdr->body_size );
! } else {
! ASF_stream_chunck_t *ptr;
! int ret;
! i = readFromServer( fd, buffer, sizeof(ASF_stream_chunck_t) );
printf("read: %d\n", i );
! ret = asf_streaming( buffer, i, NULL );
! net_fifo_push( streaming_ctrl->buffer, buffer, i );
! ptr = (ASF_stream_chunck_t*)buffer;
! if( ret==ptr->size ) {
! }
}
+ // done = 0;
break;
case ASF_Redirector_e:
***************
*** 242,245 ****
--- 315,319 ----
printf("Failed to parse ASX file\n");
close(fd);
+ http_free( http_hdr );
return -1;
}
***************
*** 247,251 ****
url_free( url );
url = url_next;
! *url_ref = url_next;
url_next = NULL;
break;
--- 321,325 ----
url_free( url );
url = url_next;
! *(streaming_ctrl->url) = url_next;
url_next = NULL;
break;
***************
*** 254,257 ****
--- 328,332 ----
printf("Unknown ASF streaming type\n");
close(fd);
+ http_free( http_hdr );
return -1;
}
***************
*** 260,263 ****
--- 335,345 ----
} while(!done);
+ streaming_ctrl->fd_net = fd;
+ streaming_ctrl->streaming_read = asf_http_streaming_read;
+ streaming_ctrl->prebuffer_size = 10000;
+ streaming_ctrl->buffering = 1;
+ streaming_ctrl->status = streaming_playing_e;
+
+ http_free( http_hdr );
return fd;
}
_______________________________________________
Mplayer-cvslog mailing list
Mplayer-cvslog at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-cvslog
More information about the MPlayer-cvslog
mailing list