[SCM] libav/experimental: BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
siretart at users.alioth.debian.org
siretart at users.alioth.debian.org
Sun Jun 30 15:42:15 UTC 2013
The following commit has been merged in the experimental branch:
commit 2450cff2c3317b589575fc99dce26ddc605883ee
Author: François Revol <revol at free.fr>
Date: Sun Nov 21 18:04:56 2004 +0000
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
Originally committed as revision 3702 to svn://svn.ffmpeg.org/ffmpeg/trunk
diff --git a/configure b/configure
index 289a327..2722a9d 100755
--- a/configure
+++ b/configure
@@ -323,7 +323,7 @@ esac
# of AltiVec on PowerPC
TARGET_OS=`( uname -s ) 2>&1`
case "$TARGET_OS" in
- Linux|FreeBSD|NetBSD|BSD/OS|OpenBSD|SunOS|QNX|Darwin|GNU)
+ Linux|FreeBSD|NetBSD|BSD/OS|OpenBSD|SunOS|QNX|Darwin|GNU|BeOS)
;;
IRIX*)
TARGET_OS=IRIX
@@ -1215,6 +1215,7 @@ fi
if test "$pthreads" = "yes" ; then
echo "HAVE_PTHREADS=yes" >> config.mak
echo "#define HAVE_PTHREADS 1" >> $TMPH
+ echo "#define HAVE_THREADS 1" >> $TMPH
if test $targetos != FreeBSD; then
extralibs="$extralibs -lpthread"
fi
@@ -1366,6 +1367,7 @@ if test "$mingw32" = "yes" ; then
echo "CONFIG_WIN32=yes" >> config.mak
echo "HAVE_W32THREADS=yes" >> config.mak
echo "#define HAVE_W32THREADS 1" >> $TMPH
+ echo "#define HAVE_THREADS 1" >> $TMPH
echo "#ifndef __MINGW32__" >> $TMPH
echo "#define __MINGW32__ 1" >> $TMPH
echo "#endif" >> $TMPH
@@ -1380,6 +1382,12 @@ if test "$TARGET_OS" = "SunOS" ; then
echo "#define CONFIG_SUNOS 1" >> $TMPH
fi
+if test "$TARGET_OS" = "BeOS" ; then
+ echo "HAVE_BEOSTHREADS=yes" >> config.mak
+ echo "#define HAVE_BEOSTHREADS 1" >> $TMPH
+ echo "#define HAVE_THREADS 1" >> $TMPH
+fi
+
if test "$darwin" = "yes"; then
echo "#define CONFIG_DARWIN 1" >> $TMPH
echo "CONFIG_DARWIN=yes" >> config.mak
diff --git a/ffmpeg.c b/ffmpeg.c
index 31efd0c..1c7118e 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2555,7 +2555,7 @@ static void opt_me_range(const char *arg)
static void opt_thread_count(const char *arg)
{
thread_count= atoi(arg);
-#if !defined(HAVE_PTHREADS) && !defined(HAVE_W32THREADS)
+#if !defined(HAVE_THREADS)
if (verbose >= 0)
fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
#endif
@@ -2825,7 +2825,7 @@ static void opt_input_file(const char *filename)
/* update the current parameters so that they match the one of the input stream */
for(i=0;i<ic->nb_streams;i++) {
AVCodecContext *enc = &ic->streams[i]->codec;
-#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS)
+#if defined(HAVE_THREADS)
if(thread_count>1)
avcodec_thread_init(enc, thread_count);
#endif
@@ -2992,7 +2992,7 @@ static void opt_output_file(const char *filename)
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
-#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS)
+#if defined(HAVE_THREADS)
if(thread_count>1)
avcodec_thread_init(&st->codec, thread_count);
#endif
@@ -3244,7 +3244,7 @@ static void opt_output_file(const char *filename)
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
-#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS)
+#if defined(HAVE_THREADS)
if(thread_count>1)
avcodec_thread_init(&st->codec, thread_count);
#endif
diff --git a/ffplay.c b/ffplay.c
index c8d9199..13fbd98 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1174,7 +1174,7 @@ static int stream_component_open(VideoState *is, int stream_index)
if (!codec ||
avcodec_open(enc, codec) < 0)
return -1;
-#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS)
+#if defined(HAVE_THREADS)
if(thread_count>1)
avcodec_thread_init(enc, thread_count);
#endif
@@ -1809,7 +1809,7 @@ static void opt_vismv(const char *arg)
static void opt_thread_count(const char *arg)
{
thread_count= atoi(arg);
-#if !defined(HAVE_PTHREADS) && !defined(HAVE_W32THREADS)
+#if !defined(HAVE_THREADS)
fprintf(stderr, "Warning: not compiled with thread support, using thread emulation\n");
#endif
}
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 7d5e780..67e6a30 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -43,6 +43,10 @@ ifeq ($(HAVE_W32THREADS),yes)
OBJS+= w32thread.o
endif
+ifeq ($(HAVE_BEOSTHREADS),yes)
+OBJS+= beosthread.o
+endif
+
ifeq ($(AMR_WB),yes)
OBJS+= amr.o amrwb_float/dec_acelp.o amrwb_float/dec_dtx.o amrwb_float/dec_gain.o \
amrwb_float/dec_if.o amrwb_float/dec_lpc.o amrwb_float/dec_main.o \
diff --git a/libavcodec/w32thread.c b/libavcodec/beosthread.c
similarity index 75%
copy from libavcodec/w32thread.c
copy to libavcodec/beosthread.c
index 186e302..90ff1f4 100644
--- a/libavcodec/w32thread.c
+++ b/libavcodec/beosthread.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 Michael Niedermayer <michaelni at gmx.at>
+ * Copyright (c) 2004 François Revol <revol at free.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -21,37 +21,35 @@
#include "avcodec.h"
#include "common.h"
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include <process.h>
+#include <OS.h>
typedef struct ThreadContext{
AVCodecContext *avctx;
- HANDLE thread;
- HANDLE work_sem;
- HANDLE done_sem;
+ thread_id thread;
+ sem_id work_sem;
+ sem_id done_sem;
int (*func)(AVCodecContext *c, void *arg);
void *arg;
int ret;
}ThreadContext;
-static unsigned __stdcall thread_func(void *v){
+static int32 ff_thread_func(void *v){
ThreadContext *c= v;
for(;;){
//printf("thread_func %X enter wait\n", (int)v); fflush(stdout);
- WaitForSingleObject(c->work_sem, INFINITE);
+ acquire_sem(c->work_sem);
//printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout);
if(c->func)
c->ret= c->func(c->avctx, c->arg);
else
return 0;
//printf("thread_func %X signal complete\n", (int)v); fflush(stdout);
- ReleaseSemaphore(c->done_sem, 1, 0);
+ release_sem(c->done_sem);
}
- return 0;
+ return B_OK;
}
/**
@@ -61,14 +59,15 @@ static unsigned __stdcall thread_func(void *v){
void avcodec_thread_free(AVCodecContext *s){
ThreadContext *c= s->thread_opaque;
int i;
+ int32 ret;
for(i=0; i<s->thread_count; i++){
c[i].func= NULL;
- ReleaseSemaphore(c[i].work_sem, 1, 0);
- WaitForSingleObject(c[i].thread, INFINITE);
- if(c[i].work_sem) CloseHandle(c[i].work_sem);
- if(c[i].done_sem) CloseHandle(c[i].done_sem);
+ release_sem(c[i].work_sem);
+ wait_for_thread(c[i].thread, &ret);
+ if(c[i].work_sem > B_OK) delete_sem(c[i].work_sem);
+ if(c[i].done_sem > B_OK) delete_sem(c[i].done_sem);
}
av_freep(&s->thread_opaque);
@@ -88,10 +87,10 @@ int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, vo
c[i].func= func;
c[i].ret= 12345;
- ReleaseSemaphore(c[i].work_sem, 1, 0);
+ release_sem(c[i].work_sem);
}
for(i=0; i<count; i++){
- WaitForSingleObject(c[i].done_sem, INFINITE);
+ acquire_sem(c[i].done_sem);
c[i].func= NULL;
if(ret) ret[i]= c[i].ret;
@@ -102,7 +101,6 @@ int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, vo
int avcodec_thread_init(AVCodecContext *s, int thread_count){
int i;
ThreadContext *c;
- uint32_t threadid;
s->thread_count= thread_count;
@@ -114,14 +112,15 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){
//printf("init semaphors %d\n", i); fflush(stdout);
c[i].avctx= s;
- if(!(c[i].work_sem = CreateSemaphore(NULL, 0, s->thread_count, NULL)))
+ if((c[i].work_sem = create_sem(0, "ff work sem")) < B_OK)
goto fail;
- if(!(c[i].done_sem = CreateSemaphore(NULL, 0, s->thread_count, NULL)))
+ if((c[i].done_sem = create_sem(0, "ff done sem")) < B_OK)
goto fail;
//printf("create thread %d\n", i); fflush(stdout);
- c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid );
- if( !c[i].thread ) goto fail;
+ c[i].thread = spawn_thread(ff_thread_func, "libavcodec thread", B_LOW_PRIORITY, &c[i] );
+ if( c[i].thread < B_OK ) goto fail;
+ resume_thread(c[i].thread );
}
//printf("init done\n"); fflush(stdout);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 6702cd1..c1f88d0 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -912,7 +912,7 @@ void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
av_log_callback = callback;
}
-#if !defined(HAVE_PTHREADS) && !defined(HAVE_W32THREADS)
+#if !defined(HAVE_THREADS)
int avcodec_thread_init(AVCodecContext *s, int thread_count){
return -1;
}
--
Libav/FFmpeg packaging
More information about the pkg-multimedia-commits
mailing list