]> granicus.if.org Git - rtmpdump/commitdiff
Move thread support to its own files
authorhyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Thu, 31 Dec 2009 02:58:04 +0000 (02:58 +0000)
committerhyc <hyc@400ebc74-4327-4243-bc38-086b20814532>
Thu, 31 Dec 2009 02:58:04 +0000 (02:58 +0000)
git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@150 400ebc74-4327-4243-bc38-086b20814532

Makefile
rtmpsrv.c
rtmpsuck.c
streams.c
thread.c [new file with mode: 0644]
thread.h [new file with mode: 0644]

index d1a142d0b9199b1d76a5af2e893619e75339cac5..90c280b86a9a1a2e14cd88cd53639875197e5069 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -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 thread.o
        $(CC) $(LDFLAGS) $^ -o $@$(EXT) $(SLIBS)
 
-rtmpsuck: log.o rtmp.o amf.o rtmpsuck.o hashswf.o
+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 Makefile
 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
index 1e36e133186548c6394b6e5b0e18abcf99db29c3..9451373db6a2301f5aefc7769a7c4b34cabd770a 100644 (file)
--- a/rtmpsrv.c
+++ b/rtmpsrv.c
 #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, RTMP *r, RTMPPacket *packet)
   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 port)
   server = (STREAMING_SERVER *) calloc(1, sizeof(STREAMING_SERVER));
   server->socket = sockfd;
 
-  ThreadCreate((void *(*)(void *)) serverThread, server);
+  ThreadCreate((thrfunc *)serverThread, server);
 
   return server;
 }
index 07a4863e1ddea5a072ed4d1aa72263c7dc84e1e1..3b87e3225ef622fca65c4986089d2927d1eecd6f 100644 (file)
 #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 pointer, maybe preallocated
   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 port)
   server = (STREAMING_SERVER *) calloc(1, sizeof(STREAMING_SERVER));
   server->socket = sockfd;
 
-  ThreadCreate((void *(*)(void *)) serverThread, server);
+  ThreadCreate((thrfunc *)serverThread, server);
 
   return server;
 }
index abc0d5751a9150ef6912d18b43d7c6d79e9d21af..bcff29cede35a6daf5eb556941e2c54bf2ce3f36 100644 (file)
--- a/streams.c
+++ b/streams.c
 #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,       // target pointer, maybe preallocated
   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 *
diff --git a/thread.c b/thread.c
new file mode 100644 (file)
index 0000000..61e55fa
--- /dev/null
+++ b/thread.c
@@ -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
diff --git a/thread.h b/thread.h
new file mode 100644 (file)
index 0000000..f638661
--- /dev/null
+++ b/thread.h
@@ -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__ */