1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-25 04:38:01 +00:00

Continue implementation.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@906 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
bertrand 2001-05-29 17:09:19 +00:00
parent 529e11ebc6
commit e244354ce3

View File

@ -5,7 +5,9 @@
#include "asf.h" #include "asf.h"
#include "url.h" #include "url.h"
#include "http.h" #include "http.h"
#include "network.h"
#define BUFFER_SIZE 2048
const char *temp_response = const char *temp_response =
"HTTP/1.0 200 OK\r\n" "HTTP/1.0 200 OK\r\n"
@ -19,9 +21,7 @@ const char *temp_response =
"Pragma: features=\"broadcast\"\r\n" "Pragma: features=\"broadcast\"\r\n"
*/ "\r\n"; */ "\r\n";
static ASF_StreamType_e stream_type = ASF_Unknown_e; static ASF_StreamType_e streaming_type = ASF_Unknown_e;
void void
asf_streaming(char *data, int length) { asf_streaming(char *data, int length) {
@ -55,16 +55,19 @@ asf_streaming(char *data, int length) {
} }
} }
void int
asf_stream_type(char *content_type, char *features) { asf_http_streaming_type(char *content_type, char *features) {
stream_type = ASF_Unknown_e; if( content_type==NULL ) return ASF_Unknown_e;
if( !strcasecmp(content_type, "application/octet-stream") ) { if( !strcasecmp(content_type, "application/octet-stream") ) {
if( strstr(features, "broadcast")) { if( features==NULL ) {
printf("=====> Prerecorded\n");
return ASF_Prerecorded_e;
} else if( strstr(features, "broadcast")) {
printf("=====> Live stream\n"); printf("=====> Live stream\n");
stream_type = ASF_Live_e; return ASF_Live_e;
} else { } else {
printf("=====> Prerecorded\n"); printf("=====> Prerecorded\n");
stream_type = ASF_Prerecorded_e; return ASF_Prerecorded_e;
} }
} else { } else {
if( (!strcasecmp(content_type, "audio/x-ms-wax")) || if( (!strcasecmp(content_type, "audio/x-ms-wax")) ||
@ -75,24 +78,24 @@ asf_stream_type(char *content_type, char *features) {
(!strcasecmp(content_type, "video/x-ms-wmv")) || (!strcasecmp(content_type, "video/x-ms-wmv")) ||
(!strcasecmp(content_type, "video/x-ms-wma")) ) { (!strcasecmp(content_type, "video/x-ms-wma")) ) {
printf("=====> Redirector\n"); printf("=====> Redirector\n");
stream_type = ASF_Redirector_e; return ASF_Redirector_e;
} else { } else {
printf("=====> unknown content-type: %s\n", content_type ); printf("=====> unknown content-type: %s\n", content_type );
stream_type = ASF_Unknown_e; return ASF_Unknown_e;
} }
} }
return ASF_Unknown_e;
} }
//void asf_http_request(stream_t *stream, URL_t *url) { //void asf_http_request(stream_t *stream, URL_t *url) {
void HTTP_header_t *
asf_http_request(URL_t *url) { asf_http_request(URL_t *url) {
HTTP_header_t *http_hdr; HTTP_header_t *http_hdr;
char str[250]; char str[250];
char *request; char *request;
// int size;
int offset_hi=0, offset_lo=0, req_nb=1, length=0; int offset_hi=0, offset_lo=0, req_nb=1, length=0;
int asf_nb_stream=1; int asf_nb_stream=1; // FIXME
// Common header for all requests. // Common header for all requests.
http_hdr = http_new_header(); http_hdr = http_new_header();
@ -107,13 +110,13 @@ asf_http_request(URL_t *url) {
offset_hi, offset_lo, req_nb, length ); offset_hi, offset_lo, req_nb, length );
http_set_field( http_hdr, str ); http_set_field( http_hdr, str );
switch( stream_type ) { switch( streaming_type ) {
case ASF_Live_e: case ASF_Live_e:
case ASF_Prerecorded_e: case ASF_Prerecorded_e:
http_set_field( http_hdr, "Pragma: xPlayStrm=1" ); http_set_field( http_hdr, "Pragma: xPlayStrm=1" );
sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream ); sprintf( str, "Pragma: stream-switch-count=%d", asf_nb_stream );
http_set_field( http_hdr, str ); http_set_field( http_hdr, str );
http_set_field( http_hdr, "Pragma: stream-switch-entry=ffff:1:0" ); http_set_field( http_hdr, "Pragma: stream-switch-entry=ffff:1:0" ); // FIXME
break; break;
case ASF_Redirector_e: case ASF_Redirector_e:
break; break;
@ -125,21 +128,20 @@ asf_http_request(URL_t *url) {
} }
http_set_field( http_hdr, "Connection: Close" ); http_set_field( http_hdr, "Connection: Close" );
request = http_get_request( http_hdr ); http_build_request( http_hdr );
printf("%s\n", request );
return http_hdr;
} }
int int
asf_http_parse_response( char *response, int length ) { asf_http_parse_response( HTTP_header_t *http_hdr ) {
HTTP_header_t *http_hdr;
char *content_type, *pragma; char *content_type, *pragma;
char features[64] = "\0"; char features[64] = "\0";
int len; int len;
if( http_response_parse(http_hdr)<0 ) {
http_hdr = http_new_response( response, length ); printf("Failed to parse HTTP response\n");
return -1;
}
if( http_hdr->status_code!=200 ) { if( http_hdr->status_code!=200 ) {
printf("Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase); printf("Server return %d:%s\n", http_hdr->status_code, http_hdr->reason_phrase);
return -1; return -1;
@ -148,7 +150,7 @@ asf_http_parse_response( char *response, int length ) {
content_type = http_get_field( http_hdr, "Content-Type"); content_type = http_get_field( http_hdr, "Content-Type");
pragma = http_get_field( http_hdr, "Pragma"); pragma = http_get_field( http_hdr, "Pragma");
do { while( pragma!=NULL ) {
char *comma_ptr=NULL; char *comma_ptr=NULL;
char *end; char *end;
// The pragma line can get severals attributes // The pragma line can get severals attributes
@ -172,19 +174,91 @@ asf_http_parse_response( char *response, int length ) {
} }
} while( comma_ptr!=NULL ); } while( comma_ptr!=NULL );
pragma = http_get_next_field( http_hdr ); pragma = http_get_next_field( http_hdr );
} while( pragma!=NULL ); }
asf_stream_type( content_type, features ); streaming_type = asf_http_streaming_type( content_type, features );
if( http_hdr->body_size>0 ) {
asf_streaming( http_hdr->body, http_hdr->body_size );
}
return 0; return 0;
} }
#ifdef STREAMING_TEST URL_t *
int main() { asf_http_ASX_redirect( HTTP_header_t *http_hdr ) {
URL_t *url = set_url("http://toto.com:12/coucou"); URL_t *url_redirect=NULL;
asf_http_request( url ); printf("=========>> ASX parser not yet implemented <<==========\n");
asf_http_parse_response( temp_response, strlen(temp_response) );
asf_http_request( url ); printf("ASX=[%s]\n", http_hdr->body );
return 0;
return url_redirect;
} }
#endif
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 ) );
//http_hdr->buffer[http_hdr->buffer_len]='\0';
//printf("[%s]\n", http_hdr->buffer );
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:
url_next = asf_http_ASX_redirect( http_hdr );
if( url_next==NULL ) {
printf("Failed to parse ASX file\n");
close(fd);
return -1;
}
if( url_next->port==0 ) url_next->port=80;
url_free( url );
url = url_next;
*url_ref = url_next;
url_next = NULL;
break;
case ASF_Unknown_e:
default:
printf("Unknown ASF streaming type\n");
close(fd);
return -1;
}
// Check if we got a redirect.
} while(!done);
return fd;
}