[rtmpdump] r150 - in trunk: Makefile rtmpsrv.c rtmpsuck.c streams.c thread.c thread.h

hyc subversion at mplayerhq.hu
Thu Dec 31 03:58:05 CET 2009


Author: hyc
Date: Thu Dec 31 03:58:04 2009
New Revision: 150

Log:
Move thread support to its own files

Added:
   trunk/thread.c
   trunk/thread.h
Modified:
   trunk/Makefile
   trunk/rtmpsrv.c
   trunk/rtmpsuck.c
   trunk/streams.c

Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile	Thu Dec 31 03:43:32 2009	(r149)
+++ trunk/Makefile	Thu Dec 31 03:58:04 2009	(r150)
@@ -37,16 +37,16 @@ arm:
 clean:
 	rm -f *.o rtmpdump$(EXT) streams$(EXT) rtmpsrv$(EXT) rtmpsuck$(EXT)
 
-streams: log.o rtmp.o amf.o streams.o parseurl.o hashswf.o
-	$(CC) $(LDFLAGS) $^ -o $@$(EXT) $(SLIBS)
-
 rtmpdump: log.o rtmp.o amf.o rtmpdump.o parseurl.o hashswf.o
 	$(CC) $(LDFLAGS) $^ -o $@$(EXT) $(LIBS)
 
-rtmpsrv: log.o rtmp.o amf.o rtmpsrv.o
+rtmpsrv: log.o rtmp.o amf.o rtmpsrv.o thread.o
 	$(CC) $(LDFLAGS) $^ -o $@$(EXT) $(SLIBS)
 
-rtmpsuck: log.o rtmp.o amf.o rtmpsuck.o hashswf.o
+rtmpsuck: log.o rtmp.o amf.o rtmpsuck.o hashswf.o thread.o
+	$(CC) $(LDFLAGS) $^ -o $@$(EXT) $(SLIBS)
+
+streams: log.o rtmp.o amf.o streams.o parseurl.o hashswf.o thread.o
 	$(CC) $(LDFLAGS) $^ -o $@$(EXT) $(SLIBS)
 
 log.o: log.c log.h Makefile
@@ -57,3 +57,4 @@ amf.o: amf.c amf.h bytes.h log.h Makefil
 rtmpdump.o: rtmpdump.c rtmp.h log.h amf.h Makefile
 rtmpsrv.o: rtmpsrv.c rtmp.h log.h amf.h Makefile
 hashswf.o: hashswf.c
+thread.o: thread.c thread.h

Modified: trunk/rtmpsrv.c
==============================================================================
--- trunk/rtmpsrv.c	Thu Dec 31 03:43:32 2009	(r149)
+++ trunk/rtmpsrv.c	Thu Dec 31 03:58:04 2009	(r150)
@@ -36,14 +36,11 @@
 #include "rtmp.h"
 #include "parseurl.h"
 
-#ifdef WIN32
-#include <process.h>
-#else
+#include "thread.h"
+
 #ifdef linux
 #include <linux/netfilter_ipv4.h>
 #endif
-#include <pthread.h>
-#endif
 
 #define RTMPDUMP_SERVER_VERSION	"v2.1"
 
@@ -448,40 +445,7 @@ ServePacket(STREAMING_SERVER *server, RT
   return ret;
 }
 
-#ifdef WIN32
-HANDLE
-ThreadCreate(void *(*routine) (void *), void *args)
-{
-  HANDLE thd;
-
-  thd = (HANDLE) _beginthread(routine, 0, args);
-  if (thd == -1L)
-    LogPrintf("%s, _beginthread failed with %d\n", __FUNCTION__, errno);
-
-  return thd;
-}
-#else
-pthread_t
-ThreadCreate(void *(*routine) (void *), void *args)
-{
-  pthread_t id = 0;
-  pthread_attr_t attributes;
-  int ret;
-
-  pthread_attr_init(&attributes);
-  pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
-
-  ret =
-    pthread_create(&id, &attributes, (void *(*)(void *)) routine,
-		   (void *) args);
-  if (ret != 0)
-    LogPrintf("%s, pthread_create failed with %d\n", __FUNCTION__, ret);
-
-  return id;
-}
-#endif
-
-void *
+TFTYPE
 controlServerThread(void *unused)
 {
   char ich;
@@ -499,7 +463,7 @@ controlServerThread(void *unused)
 	  LogPrintf("Unknown command \'%c\', ignoring\n", ich);
 	}
     }
-  return 0;
+  TFRET();
 }
 
 
@@ -565,7 +529,7 @@ quit:
   return;
 }
 
-void *
+TFTYPE
 serverThread(STREAMING_SERVER * server)
 {
   server->state = STREAMING_ACCEPTING;
@@ -601,7 +565,7 @@ serverThread(STREAMING_SERVER * server)
 	}
     }
   server->state = STREAMING_STOPPED;
-  return 0;
+  TFRET();
 }
 
 STREAMING_SERVER *
@@ -640,7 +604,7 @@ startStreaming(const char *address, int 
   server = (STREAMING_SERVER *) calloc(1, sizeof(STREAMING_SERVER));
   server->socket = sockfd;
 
-  ThreadCreate((void *(*)(void *)) serverThread, server);
+  ThreadCreate((thrfunc *)serverThread, server);
 
   return server;
 }

Modified: trunk/rtmpsuck.c
==============================================================================
--- trunk/rtmpsuck.c	Thu Dec 31 03:43:32 2009	(r149)
+++ trunk/rtmpsuck.c	Thu Dec 31 03:58:04 2009	(r150)
@@ -36,14 +36,11 @@
 #include "rtmp.h"
 #include "parseurl.h"
 
-#ifdef WIN32
-#include <process.h>
-#else
+#include "thread.h"
+
 #ifdef linux
 #include <linux/netfilter_ipv4.h>
 #endif
-#include <pthread.h>
-#endif
 
 #define RTMPDUMP_PROXY_VERSION	"v2.1"
 
@@ -610,40 +607,7 @@ WriteStream(char **buf,	// target pointe
   return ret;			// no more media packets
 }
 
-#ifdef WIN32
-HANDLE
-ThreadCreate(void *(*routine) (void *), void *args)
-{
-  HANDLE thd;
-
-  thd = (HANDLE) _beginthread(routine, 0, args);
-  if (thd == -1L)
-    LogPrintf("%s, _beginthread failed with %d\n", __FUNCTION__, errno);
-
-  return thd;
-}
-#else
-pthread_t
-ThreadCreate(void *(*routine) (void *), void *args)
-{
-  pthread_t id = 0;
-  pthread_attr_t attributes;
-  int ret;
-
-  pthread_attr_init(&attributes);
-  pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
-
-  ret =
-    pthread_create(&id, &attributes, (void *(*)(void *)) routine,
-		   (void *) args);
-  if (ret != 0)
-    LogPrintf("%s, pthread_create failed with %d\n", __FUNCTION__, ret);
-
-  return id;
-}
-#endif
-
-void *
+TFTYPE
 controlServerThread(void *unused)
 {
   char ich;
@@ -661,7 +625,7 @@ controlServerThread(void *unused)
 	  LogPrintf("Unknown command \'%c\', ignoring\n", ich);
 	}
     }
-  return 0;
+  TFRET();
 }
 
 void doServe(STREAMING_SERVER * server,	// server socket and state (our listening socket)
@@ -907,7 +871,7 @@ quit:
   return;
 }
 
-void *
+TFTYPE
 serverThread(STREAMING_SERVER * server)
 {
   server->state = STREAMING_ACCEPTING;
@@ -943,7 +907,7 @@ serverThread(STREAMING_SERVER * server)
 	}
     }
   server->state = STREAMING_STOPPED;
-  return 0;
+  TFRET();
 }
 
 STREAMING_SERVER *
@@ -986,7 +950,7 @@ startStreaming(const char *address, int 
   server = (STREAMING_SERVER *) calloc(1, sizeof(STREAMING_SERVER));
   server->socket = sockfd;
 
-  ThreadCreate((void *(*)(void *)) serverThread, server);
+  ThreadCreate((thrfunc *)serverThread, server);
 
   return server;
 }

Modified: trunk/streams.c
==============================================================================
--- trunk/streams.c	Thu Dec 31 03:43:32 2009	(r149)
+++ trunk/streams.c	Thu Dec 31 03:58:04 2009	(r150)
@@ -31,11 +31,7 @@
 #include "rtmp.h"
 #include "parseurl.h"
 
-#ifdef WIN32
-#include <process.h>
-#else
-#include <pthread.h>
-#endif
+#include "thread.h"
 
 #define RTMPDUMP_STREAMS_VERSION	"v2.1"
 
@@ -374,40 +370,7 @@ WriteStream(RTMP * rtmp, char **buf,	// 
   return ret;			// no more media packets
 }
 
-#ifdef WIN32
-HANDLE
-ThreadCreate(void *(*routine) (void *), void *args)
-{
-  HANDLE thd;
-
-  thd = (HANDLE) _beginthread(routine, 0, args);
-  if (thd == -1L)
-    LogPrintf("%s, _beginthread failed with %d\n", __FUNCTION__, errno);
-
-  return thd;
-}
-#else
-pthread_t
-ThreadCreate(void *(*routine) (void *), void *args)
-{
-  pthread_t id = 0;
-  pthread_attr_t attributes;
-  int ret;
-
-  pthread_attr_init(&attributes);
-  pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
-
-  ret =
-    pthread_create(&id, &attributes, (void *(*)(void *)) routine,
-		   (void *) args);
-  if (ret != 0)
-    LogPrintf("%s, pthread_create failed with %d\n", __FUNCTION__, ret);
-
-  return id;
-}
-#endif
-
-void *
+TFTYPE
 controlServerThread(void *unused)
 {
   char ich;
@@ -425,7 +388,7 @@ controlServerThread(void *unused)
 	  LogPrintf("Unknown command \'%c\', ignoring\n", ich);
 	}
     }
-  return 0;
+  TFRET();
 }
 
 /*
@@ -797,7 +760,7 @@ filenotfound:
   goto quit;
 }
 
-void *
+TFTYPE
 serverThread(STREAMING_SERVER * server)
 {
   server->state = STREAMING_ACCEPTING;
@@ -823,7 +786,7 @@ serverThread(STREAMING_SERVER * server)
 	}
     }
   server->state = STREAMING_STOPPED;
-  return 0;
+  TFRET();
 }
 
 STREAMING_SERVER *

Added: trunk/thread.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/thread.c	Thu Dec 31 03:58:04 2009	(r150)
@@ -0,0 +1,54 @@
+/*  Thread compatibility glue
+ *  Copyright (C) 2009 Howard Chu
+ *
+ *  This Program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This Program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with RTMPDump; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "thread.h"
+#include "log.h"
+
+#ifdef WIN32
+HANDLE
+ThreadCreate(thrfunc *routine, void *args)
+{
+  HANDLE thd;
+
+  thd = (HANDLE) _beginthread(routine, 0, args);
+  if (thd == -1L)
+    LogPrintf("%s, _beginthread failed with %d\n", __FUNCTION__, errno);
+
+  return thd;
+}
+#else
+pthread_t
+ThreadCreate(thrfunc *routine, void *args)
+{
+  pthread_t id = 0;
+  pthread_attr_t attributes;
+  int ret;
+
+  pthread_attr_init(&attributes);
+  pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
+
+  ret =
+    pthread_create(&id, &attributes, routine, args);
+  if (ret != 0)
+    LogPrintf("%s, pthread_create failed with %d\n", __FUNCTION__, ret);
+
+  return id;
+}
+#endif

Added: trunk/thread.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/thread.h	Thu Dec 31 03:58:04 2009	(r150)
@@ -0,0 +1,38 @@
+/*  Thread compatibility glue
+ *  Copyright (C) 2009 Howard Chu
+ *
+ *  This Program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This Program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with RTMPDump; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#ifndef __THREAD_H__
+#define __THREAD_H__ 1
+
+#ifdef WIN32
+#include <process.h>
+#define TFTYPE	void
+#define TFRET()
+#define THANDLE	HANDLE
+#else
+#include <pthread.h>
+#define TFTYPE	void *
+#define TFRET()	return 0
+#define THANDLE pthread_t
+#endif
+typedef TFTYPE (thrfunc)(void *arg);
+
+THANDLE ThreadCreate(thrfunc *routine, void *args);
+#endif /* __THREAD_H__ */


More information about the rtmpdump mailing list