comparison libmpdemux/network.c @ 4251:05affdf4bdcd

Moved network related code from open.c to network.c
author bertrand
date Sat, 19 Jan 2002 09:04:02 +0000
parents 0c809c541aa1
children 973c6912c586
comparison
equal deleted inserted replaced
4250:49746d2bfda7 4251:05affdf4bdcd
81 } 81 }
82 82
83 void 83 void
84 streaming_ctrl_free( streaming_ctrl_t *streaming_ctrl ) { 84 streaming_ctrl_free( streaming_ctrl_t *streaming_ctrl ) {
85 if( streaming_ctrl==NULL ) return; 85 if( streaming_ctrl==NULL ) return;
86 if( streaming_ctrl->url ) url_free( streaming_ctrl->url );
87 if( streaming_ctrl->buffer ) free( streaming_ctrl->buffer );
88 if( streaming_ctrl->data ) free( streaming_ctrl->data );
86 free( streaming_ctrl ); 89 free( streaming_ctrl );
87 } 90 }
88 91
89 int 92 int
90 read_rtp_from_server(int fd, char *buffer, int length) { 93 read_rtp_from_server(int fd, char *buffer, int length) {
175 return socket_server_fd; 178 return socket_server_fd;
176 } 179 }
177 180
178 URL_t* 181 URL_t*
179 check4proxies( URL_t *url ) { 182 check4proxies( URL_t *url ) {
183 if( url==NULL ) return NULL;
180 if( !strcasecmp(url->protocol, "http_proxy") ) { 184 if( !strcasecmp(url->protocol, "http_proxy") ) {
181 printf("Using HTTP proxy: http://%s:%d\n", url->hostname, url->port ); 185 printf("Using HTTP proxy: http://%s:%d\n", url->hostname, url->port );
182 return url; 186 return url;
183 } 187 }
184 // Check if the http_proxy environment variable is set. 188 // Check if the http_proxy environment variable is set.
205 return url; 209 return url;
206 } 210 }
207 sprintf( new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url); 211 sprintf( new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url);
208 tmp_url = url_new( new_url ); 212 tmp_url = url_new( new_url );
209 if( tmp_url==NULL ) { 213 if( tmp_url==NULL ) {
210 return url; 214 return url;
211 } 215 }
212 url_free( url ); 216 url_free( url );
213 url = tmp_url; 217 url = tmp_url;
214 free( new_url ); 218 free( new_url );
215 url_free( proxy_url ); 219 url_free( proxy_url );
442 return -1; 446 return -1;
443 } 447 }
444 448
445 int 449 int
446 streaming_bufferize( streaming_ctrl_t *streaming_ctrl, char *buffer, int size) { 450 streaming_bufferize( streaming_ctrl_t *streaming_ctrl, char *buffer, int size) {
447 printf("streaming_bufferize\n"); 451 //printf("streaming_bufferize\n");
448 streaming_ctrl->buffer = (char*)malloc(size); 452 streaming_ctrl->buffer = (char*)malloc(size);
449 if( streaming_ctrl->buffer==NULL ) { 453 if( streaming_ctrl->buffer==NULL ) {
450 printf("Memory allocation failed\n"); 454 printf("Memory allocation failed\n");
451 return -1; 455 return -1;
452 } 456 }
459 nop_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) { 463 nop_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) {
460 int len=0; 464 int len=0;
461 //printf("nop_streaming_read\n"); 465 //printf("nop_streaming_read\n");
462 if( stream_ctrl->buffer_size!=0 ) { 466 if( stream_ctrl->buffer_size!=0 ) {
463 int buffer_len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos; 467 int buffer_len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos;
464 printf("%d bytes in buffer\n", stream_ctrl->buffer_size); 468 //printf("%d bytes in buffer\n", stream_ctrl->buffer_size);
465 len = (size<buffer_len)?size:buffer_len; 469 len = (size<buffer_len)?size:buffer_len;
466 memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len ); 470 memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len );
467 stream_ctrl->buffer_pos += len; 471 stream_ctrl->buffer_pos += len;
468 printf("buffer_pos = %d\n", stream_ctrl->buffer_pos ); 472 //printf("buffer_pos = %d\n", stream_ctrl->buffer_pos );
469 if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) { 473 if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) {
470 free( stream_ctrl->buffer ); 474 free( stream_ctrl->buffer );
471 stream_ctrl->buffer = NULL; 475 stream_ctrl->buffer = NULL;
472 stream_ctrl->buffer_size = 0; 476 stream_ctrl->buffer_size = 0;
473 stream_ctrl->buffer_pos = 0; 477 stream_ctrl->buffer_pos = 0;
474 printf("buffer cleaned\n"); 478 //printf("buffer cleaned\n");
475 } 479 }
476 printf("read %d bytes from buffer\n", len ); 480 //printf("read %d bytes from buffer\n", len );
477 } 481 }
478 482
479 if( len<size ) { 483 if( len<size ) {
480 int ret; 484 int ret;
481 ret = read( fd, buffer+len, size-len ); 485 ret = read( fd, buffer+len, size-len );
527 } else { 531 } else {
528 http_hdr = (HTTP_header_t*)stream->streaming_ctrl->data; 532 http_hdr = (HTTP_header_t*)stream->streaming_ctrl->data;
529 if( http_hdr->body_size>0 ) { 533 if( http_hdr->body_size>0 ) {
530 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { 534 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) {
531 http_free( http_hdr ); 535 http_free( http_hdr );
536 stream->streaming_ctrl->data = NULL;
532 return -1; 537 return -1;
533 } 538 }
534 } 539 }
535 } 540 }
536 541
649 streaming_ctrl->status = streaming_playing_e; 654 streaming_ctrl->status = streaming_playing_e;
650 return 0; 655 return 0;
651 } 656 }
652 657
653 int 658 int
654 streaming_start(stream_t *stream, int demuxer_type) { 659 streaming_start(stream_t *stream, int demuxer_type, URL_t *url) {
655 int ret=-1; 660 int ret;
656 if( stream==NULL ) return -1; 661 if( stream==NULL ) return -1;
662
663 stream->streaming_ctrl = streaming_ctrl_new();
664 if( stream->streaming_ctrl==NULL ) {
665 return -1;
666 }
667 stream->streaming_ctrl->url = check4proxies( url_copy(url) );
668 ret = autodetectProtocol( stream->streaming_ctrl, &stream->fd, &demuxer_type );
669 if( ret<0 ) {
670 return -1;
671 }
672 ret = -1;
657 673
658 // For RTP streams, we usually don't know the stream type until we open it. 674 // For RTP streams, we usually don't know the stream type until we open it.
659 if( !strcasecmp( stream->streaming_ctrl->url->protocol, "rtp")) { 675 if( !strcasecmp( stream->streaming_ctrl->url->protocol, "rtp")) {
660 if(stream->fd >= 0) { 676 if(stream->fd >= 0) {
661 if(close(stream->fd) < 0) 677 if(close(stream->fd) < 0)
691 printf("Unable to detect the streaming type\n"); 707 printf("Unable to detect the streaming type\n");
692 ret = -1; 708 ret = -1;
693 } 709 }
694 710
695 if( ret<0 ) { 711 if( ret<0 ) {
696 free( stream->streaming_ctrl ); 712 streaming_ctrl_free( stream->streaming_ctrl );
713 stream->streaming_ctrl = NULL;
697 } 714 }
698 return ret; 715 return ret;
699 } 716 }
700 717
701 int 718 int