[Mplayer-cvslog] CVS: main/libmpdemux asf_mmst_streaming.c,1.9,1.10 asf_streaming.c,1.38,1.39 network.c,1.82,1.83 network.h,1.16,1.17 pnm.c,1.6,1.7 rtp.c,1.5,1.6 rtp.h,1.1,1.2 stream.c,1.66,1.67 stream_netstream.c,1.3,1.4

Diego Biurrun CVS diego at mplayerhq.hu
Wed Jun 11 18:48:40 CEST 2003


Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv719/libmpdemux

Modified Files:
	asf_mmst_streaming.c asf_streaming.c network.c network.h pnm.c 
	rtp.c rtp.h stream.c stream_netstream.c 
Log Message:
Networking support under MinGW.
Patch by flo/yepyep <flodt8 at yahoo.de>.


Index: asf_mmst_streaming.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/asf_mmst_streaming.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- asf_mmst_streaming.c	29 May 2003 19:33:33 -0000	1.9
+++ asf_mmst_streaming.c	11 Jun 2003 16:48:07 -0000	1.10
@@ -16,6 +16,12 @@
 
 #include "config.h"
 
+#ifndef HAVE_WINSOCK2
+#define closesocket close
+#else
+#include <winsock2.h>
+#endif
+
 #include "url.h"
 #include "asf.h"
 
@@ -433,7 +439,7 @@
   int s = stream->fd;
 
   if( s>0 ) {
-	  close( stream->fd );
+	  closesocket( stream->fd );
 	  stream->fd = -1;
   }
   

Index: asf_streaming.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/asf_streaming.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- asf_streaming.c	29 May 2003 19:33:33 -0000	1.38
+++ asf_streaming.c	11 Jun 2003 16:48:07 -0000	1.39
@@ -6,6 +6,12 @@
 
 #include "config.h"
 
+#ifndef HAVE_WINSOCK2
+#define closesocket close
+#else
+#include <winsock2.h>
+#endif
+
 #include "url.h"
 #include "http.h"
 #include "asf.h"
@@ -643,7 +649,7 @@
 
 	do {
 		done = 1;
-		if( fd>0 ) close( fd );
+		if( fd>0 ) closesocket( fd );
 
 		if( !strcasecmp( url->protocol, "http_proxy" ) ) {
 			if( url->port==0 ) url->port = 8080;
@@ -729,7 +735,7 @@
 			case ASF_Unknown_e:
 			default:
 				mp_msg(MSGT_NETWORK,MSGL_ERR,"Unknown ASF streaming type\n");
-				close(fd);
+				closesocket(fd);
 				http_free( http_hdr );
 				return -1;
 		}

Index: network.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/network.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- network.c	29 May 2003 19:33:33 -0000	1.82
+++ network.c	11 Jun 2003 16:48:07 -0000	1.83
@@ -16,6 +16,13 @@
 
 #include "config.h"
 
+#ifndef HAVE_WINSOCK2
+#define closesocket close
+#else
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#endif
+
 #include "stream.h"
 #include "demuxer.h"
 #include "../m_config.h"
@@ -194,6 +201,10 @@
 	struct hostent *hp=NULL;
 	char buf[255];
 	
+#ifdef HAVE_WINSOCK2
+	u_long val;
+#endif
+	
 	socket_server_fd = socket(af, SOCK_STREAM, 0);
 	
 	
@@ -215,11 +226,15 @@
 	
 	bzero(&server_address, sizeof(server_address));
 	
+#ifndef HAVE_WINSOCK2
 #ifdef USE_ATON
 	if (inet_aton(host, our_s_addr)!=1)
 #else
 	if (inet_pton(af, host, our_s_addr)!=1)
 #endif
+#else
+	if ( inet_addr(host)==INADDR_NONE )
+#endif
 	{
 		mp_msg(MSGT_NETWORK,MSGL_STATUS,"Resolving %s for %s...\n", host, af2String(af));
 		
@@ -235,6 +250,12 @@
 		
 		memcpy( our_s_addr, (void*)hp->h_addr, hp->h_length );
 	}
+#ifdef HAVE_WINSOCK2
+	else {
+		unsigned long addr = inet_addr(host);
+		memcpy( our_s_addr, (void*)&addr, sizeof(addr) );
+	}
+#endif
 	
 	switch (af) {
 		case AF_INET:
@@ -254,7 +275,7 @@
 			return -2;
 	}
 
-#ifdef USE_ATON
+#if defined(USE_ATON) || defined(HAVE_WINSOCK2)
 	strncpy( buf, inet_ntoa( *((struct in_addr*)our_s_addr) ), 255);
 #else
 	inet_ntop(af, our_s_addr, buf, 255);
@@ -262,11 +283,20 @@
 	mp_msg(MSGT_NETWORK,MSGL_STATUS,"Connecting to server %s[%s]:%d ...\n", host, buf , port );
 
 	// Turn the socket as non blocking so we can timeout on the connection
+#ifndef HAVE_WINSOCK2
 	fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK );
+#else
+	val = 1;
+	ioctlsocket( socket_server_fd, FIONBIO, &val );
+#endif
 	if( connect( socket_server_fd, (struct sockaddr*)&server_address, server_address_size )==-1 ) {
+#ifndef HAVE_WINSOCK2
 		if( errno!=EINPROGRESS ) {
+#else
+		if( (WSAGetLastError() != WSAEINPROGRESS) && (WSAGetLastError() != WSAEWOULDBLOCK) ) {
+#endif
 			mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to connect to server with %s\n", af2String(af));
-			close(socket_server_fd);
+			closesocket(socket_server_fd);
 			return -1;
 		}
 	}
@@ -293,7 +323,12 @@
 	}
 
 	// Turn back the socket as blocking
+#ifndef HAVE_WINSOCK2
 	fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) & ~O_NONBLOCK );
+#else
+	val = 0;
+	ioctlsocket( socket_server_fd, FIONBIO, &val );
+#endif
 	// Check if there were any error
 	err_len = sizeof(int);
 	ret =  getsockopt(socket_server_fd,SOL_SOCKET,SO_ERROR,&err,&err_len);
@@ -655,7 +690,7 @@
 
 			http_hdr = http_read_response( fd );
 			if( http_hdr==NULL ) {
-				close( fd );
+				closesocket( fd );
 				http_free( http_hdr );
 				return -1;
 			}
@@ -734,7 +769,7 @@
 					// TODO: RFC 2616, recommand to detect infinite redirection loops
 					next_url = http_get_field( http_hdr, "Location" );
 					if( next_url!=NULL ) {
-						close( fd );
+						closesocket( fd );
 						url_free( url );
 						streaming_ctrl->url = url = url_new( next_url );
 						http_free( http_hdr );
@@ -840,7 +875,7 @@
 				break;
 			default:
 				mp_msg(MSGT_NETWORK,MSGL_ERR,"Server return %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
-				close( fd );
+				closesocket( fd );
 				fd = -1;
 		}
 		stream->fd = fd;
@@ -938,7 +973,7 @@
 	if ( redirected == 1 ) {
 		url_free(stream->streaming_ctrl->url);
 		stream->streaming_ctrl->url = url_new(mrl);
-		close(fd);
+		closesocket(fd);
 	}
 
 	free(mrl);
@@ -988,19 +1023,28 @@
 		}
 		memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
 	} else {
+#ifndef HAVE_WINSOCK2
 #ifdef USE_ATON
 		inet_aton(url->hostname, &server_address.sin_addr);
 #else
 		inet_pton(AF_INET, url->hostname, &server_address.sin_addr);
 #endif
+#else
+		unsigned int addr = inet_addr(url->hostname);
+		memcpy( (void*)&server_address.sin_addr, (void*)&addr, sizeof(addr) );
+#endif
 	}
 	server_address.sin_family=AF_INET;
 	server_address.sin_port=htons(url->port);
 
 	if( bind( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) {
+#ifndef HAVE_WINSOCK2
 		if( errno!=EINPROGRESS ) {
+#else
+		if( WSAGetLastError() != WSAEINPROGRESS ) {
+#endif
 			mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to connect to server\n");
-			close(socket_server_fd);
+			closesocket(socket_server_fd);
 			return -1;
 		}
 	}
@@ -1032,7 +1076,7 @@
 		if( err ) {
 			mp_msg(MSGT_NETWORK,MSGL_ERR,"Timeout! No data from host %s\n", url->hostname );
 			mp_msg(MSGT_NETWORK,MSGL_DBG2,"Socket error: %d\n", err );
-			close(socket_server_fd);
+			closesocket(socket_server_fd);
 			return -1;
 		}
 	}
@@ -1091,7 +1135,7 @@
 	// For RTP streams, we usually don't know the stream type until we open it.
 	if( !strcasecmp( stream->streaming_ctrl->url->protocol, "rtp")) {
 		if(stream->fd >= 0) {
-			if(close(stream->fd) < 0)
+			if(closesocket(stream->fd) < 0)
 				mp_msg(MSGT_NETWORK,MSGL_ERR,"streaming_start : Closing socket %d failed %s\n",stream->fd,strerror(errno));
 		}
 		stream->fd = -1;

Index: network.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/network.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- network.h	9 Apr 2003 16:21:42 -0000	1.16
+++ network.h	11 Jun 2003 16:48:07 -0000	1.17
@@ -8,12 +8,16 @@
 #define __NETWORK_H
 
 #include <fcntl.h>
-#include <netdb.h>
-#include <netinet/in.h>
 #include <sys/time.h>
 #include <sys/types.h>
+
+#include "config.h"
+#ifndef HAVE_WINSOCK2
+#include <netdb.h>
+#include <netinet/in.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
+#endif
 
 #include "url.h"
 #include "http.h"

Index: pnm.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/pnm.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- pnm.c	1 Jun 2003 20:27:07 -0000	1.6
+++ pnm.c	11 Jun 2003 16:48:07 -0000	1.7
@@ -26,9 +26,6 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <assert.h>
-#include <sys/socket.h>
-//#include <netinet/in.h>
-//#include <netdb.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -37,6 +34,16 @@
 #include <sys/time.h>
 #include <inttypes.h>
 
+#include "config.h"
+#ifndef HAVE_WINSOCK2
+#define closesocket close
+#include <sys/socket.h>
+//#include <netinet/in.h>
+//#include <netdb.h>
+#else
+#include <winsock2.h>
+#endif
+
 #include "pnm.h"
 //#include "libreal/rmff.h"
 
@@ -207,7 +214,11 @@
     if (n > 0)
       total += n;
     else if (n < 0) {
+#ifndef HAVE_WINSOCK2
       if ((timeout>0) && ((errno == EAGAIN) || (errno == EINPROGRESS))) {
+#else
+      if ((timeout>0) && ((errno == EAGAIN) || (WSAGetLastError() == WSAEINPROGRESS))) {
+#endif
         sleep (1); timeout--;
       } else
         return -1;
@@ -810,7 +821,7 @@
 
 void pnm_close(pnm_t *p) {
 
-  if (p->s >= 0) close(p->s);
+  if (p->s >= 0) closesocket(p->s);
   free(p->path);
   free(p);
 }

Index: rtp.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/rtp.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- rtp.c	22 Sep 2002 02:33:26 -0000	1.5
+++ rtp.c	11 Jun 2003 16:48:07 -0000	1.6
@@ -2,12 +2,18 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <netinet/in.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/types.h>
+#include "config.h"
+#ifndef HAVE_WINSOCK2
+#include <netinet/in.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
+#else
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#endif
 
 /* MPEG-2 TS RTP stack */
 

Index: rtp.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/rtp.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- rtp.h	23 Dec 2001 22:09:02 -0000	1.1
+++ rtp.h	11 Jun 2003 16:48:07 -0000	1.2
@@ -1,7 +1,12 @@
 #ifndef _RTP_H
 #define _RTP_H
 
+#include "config.h"
+#ifndef HAVE_WINSOCK2
 #include <sys/socket.h>
+#else
+#include <winsock2.h>
+#endif
 
 struct rtpbits {
   unsigned int v:2;           /* version: 2 */

Index: stream.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- stream.c	3 Jun 2003 17:43:49 -0000	1.66
+++ stream.c	11 Jun 2003 16:48:07 -0000	1.67
@@ -14,6 +14,13 @@
 #include <strings.h>
 
 #include "config.h"
+
+#ifndef HAVE_WINSOCK2
+#define closesocket close
+#else
+#include <winsock2.h>
+#endif
+
 #include "mp_msg.h"
 #include "help_mp.h"
 #include "../osdep/shmem.h"
@@ -376,6 +383,14 @@
   stream_t *s=malloc(sizeof(stream_t));
   if(s==NULL) return NULL;
   memset(s,0,sizeof(stream_t));
+
+#ifdef HAVE_WINSOCK2
+  {
+    WSADATA wsdata;
+    int temp = WSAStartup(0x0202, &wsdata); // there might be a better place for this (-> later)
+    mp_msg(MSGT_STREAM,MSGL_V,"WINSOCK2 init: %i\n", temp);
+  }
+#endif
   
   s->fd=fd;
   s->type=type;
@@ -414,7 +429,11 @@
   default:
     if(s->close) s->close(s);
   }
-  if(s->fd>0) close(s->fd);
+  if(s->fd>0) closesocket(s->fd);
+#ifdef HAVE_WINSOCK2
+  mp_msg(MSGT_STREAM,MSGL_V,"WINSOCK2 uninit\n");
+  WSACleanup(); // there might be a better place for this (-> later)
+#endif
   // Disabled atm, i don't like that. s->priv can be anything after all
   // streams should destroy their priv on close
   //if(s->priv) free(s->priv);

Index: stream_netstream.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/stream_netstream.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- stream_netstream.c	17 May 2003 12:24:01 -0000	1.3
+++ stream_netstream.c	11 Jun 2003 16:48:07 -0000	1.4
@@ -48,9 +48,14 @@
 #include <inttypes.h>
 #include <errno.h>
 
+#ifndef HAVE_WINSOCK2
+#define closesocket close
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#else
+#include <winsock2.h>
+#endif
 
 #include "mp_msg.h"
 #include "stream.h"
@@ -89,6 +94,7 @@
 //// When the cache is running we need a lock as
 //// fill_buffer is called from another proccess
 static int lock_fd(int fd) {
+#ifndef HAVE_WINSOCK2
   struct flock lock;
 
   memset(&lock,0,sizeof(struct flock));
@@ -104,10 +110,14 @@
     }
   } while(0);
   mp_msg(MSGT_STREAM,MSGL_DBG2, "Locked (%d)\n",getpid());
+#else
+printf("FIXME? should lock here\n");
+#endif
   return 1;
 }
 
 static int unlock_fd(int fd) {
+#ifndef HAVE_WINSOCK2
   struct flock lock;
 
   memset(&lock,0,sizeof(struct flock));
@@ -119,6 +129,9 @@
 	   strerror(errno));
     return 0;
   }
+#else
+printf("FIXME? should unlock here\n");
+#endif
   return 1;
 }
 
@@ -280,7 +293,7 @@
   return STREAM_OK;
 
   error:
-  close(f);
+  closesocket(f);
   m_struct_free(&stream_opts,opts);
   return STREAM_ERROR;
 }



More information about the MPlayer-cvslog mailing list