mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-22 01:40:28 +00:00
Added platform independent semaphores wrappers:
platform_sem_init platform_sem_post platform_sem_wait with parameters identical to those on Linux. Changed code in video_display/* and Makefile.in accordingly. The only thing left is some workaround for sem_getvalue on Mac. I have some ideas how to do that (as seen in SDL implementation and comming from the discussion with Jirka Matela). Unfortunately both are not thread safe. Some cleaning in rtp_callback.c
This commit is contained in:
@@ -36,8 +36,8 @@
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# $Revision: 1.11 $
|
||||
# $Date: 2008/02/18 20:17:36 $
|
||||
# $Revision: 1.12 $
|
||||
# $Date: 2008/03/06 12:55:51 $
|
||||
#
|
||||
|
||||
AR = ar
|
||||
@@ -63,6 +63,7 @@ OBJS = src/bitstream.o \
|
||||
src/rtp/net_udp.o \
|
||||
src/rtp/rtp.o \
|
||||
src/rtp/rtp_callback.o \
|
||||
src/compat/platform_semaphore.o \
|
||||
src/crypto/crypt_aes.o \
|
||||
src/crypto/crypt_aes_impl.o \
|
||||
src/crypto/crypt_des.o \
|
||||
|
||||
40
ultragrid/src/compat/platform_semaphore.c
Normal file
40
ultragrid/src/compat/platform_semaphore.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
|
||||
#ifdef HAVE_MACOSX
|
||||
#include <mach/semaphore.h>
|
||||
#include <mach/task.h>
|
||||
#include <mach/mach.h>
|
||||
#else
|
||||
#include <semaphore.h>
|
||||
#endif /* HAVE_MACOSX */
|
||||
|
||||
#include "compat/platform_semaphore.h"
|
||||
|
||||
void platform_sem_init(void * semStructure, int pshared, int initialValue)
|
||||
{
|
||||
#ifdef HAVE_MACOSX
|
||||
UNUSED(pshared);
|
||||
semaphore_create(mach_task_self(), (semaphore_t *)semStructure, SYNC_POLICY_FIFO, initialValue);
|
||||
#else
|
||||
sem_init((sem_t *)semStructure, pshared, initialValue);
|
||||
#endif /* HAVE_MACOSX */
|
||||
}
|
||||
|
||||
void platform_sem_post(void * semStructure)
|
||||
{
|
||||
#ifdef HAVE_MACOSX
|
||||
semaphore_signal(*((semaphore_t *)semStructure));
|
||||
#else
|
||||
sem_post((sem_t *)semStructure);
|
||||
#endif /* HAVE_MACOSX */
|
||||
}
|
||||
|
||||
void platform_sem_wait(void * semStructure)
|
||||
{
|
||||
#ifdef HAVE_MACOSX
|
||||
semaphore_wait(*((semaphore_t *)semStructure));
|
||||
#else
|
||||
sem_wait((sem_t *)semStructure);
|
||||
#endif /* HAVE_MACOSX */
|
||||
}
|
||||
12
ultragrid/src/compat/platform_semaphore.h
Normal file
12
ultragrid/src/compat/platform_semaphore.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_MACOSX
|
||||
#include <mach/semaphore.h>
|
||||
#include <mach/task.h>
|
||||
|
||||
typedef semaphore_t sem_t;
|
||||
#endif /* HAVE_MACOSX */
|
||||
|
||||
void platform_sem_init(void * semStructure, int pshared, int initialValue);
|
||||
void platform_sem_post(void * semStructure);
|
||||
void platform_sem_wait(void * semStructure);
|
||||
@@ -40,8 +40,8 @@
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2007/11/08 09:48:59 $
|
||||
* $Revision: 1.2 $
|
||||
* $Date: 2008/03/06 12:55:51 $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -88,8 +88,7 @@ process_rr(struct rtp *session, rtp_event *e)
|
||||
/* other users of the network. */
|
||||
fract_lost = (r->fract_lost * 100.0) / 256.0; /* percentage lost packets */
|
||||
if (fract_lost > 20) {
|
||||
printf("Receiver 0x%08x reports excessive congestion, exiting\n", e->ssrc);
|
||||
//exit(1);
|
||||
printf("Receiver 0x%08x reports excessive congestion\n", e->ssrc);
|
||||
}
|
||||
|
||||
/* Compute network round-trip time: */
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <GL/glext.h>
|
||||
#endif /* HAVE_MACOSX */
|
||||
#include <SDL/SDL.h>
|
||||
#include <semaphore.h>
|
||||
#include "compat/platform_semaphore.h"
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
@@ -134,7 +134,7 @@ void * display_dxt_init(void)
|
||||
|
||||
asm("emms\n");
|
||||
|
||||
sem_init(&s->semaphore, 0, 0);
|
||||
platform_sem_init(&s->semaphore, 0, 0);
|
||||
if (pthread_create(&(s->thread_id), NULL, display_thread_dxt, (void *) s) != 0) {
|
||||
perror("Unable to create display thread\n");
|
||||
return NULL;
|
||||
@@ -419,7 +419,7 @@ static void * display_thread_dxt(void *arg)
|
||||
|
||||
while(1) {
|
||||
display_dxt_handle_events(s);
|
||||
sem_wait(&s->semaphore);
|
||||
platform_sem_wait(&s->semaphore);
|
||||
|
||||
dxt_bind_texture(s);
|
||||
dxt_draw(s);
|
||||
@@ -505,7 +505,7 @@ int display_dxt_putf(void *state, unsigned char *frame)
|
||||
s->image_network = tmp;
|
||||
|
||||
/* ...and signal the worker */
|
||||
sem_post(&s->semaphore);
|
||||
platform_sem_post(&s->semaphore);
|
||||
sem_getvalue(&s->semaphore, &tmp);
|
||||
if(tmp > 1)
|
||||
printf("frame drop!\n");
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <GL/glext.h>
|
||||
#endif /* HAVE_MACOSX */
|
||||
#include <SDL/SDL.h>
|
||||
#include <semaphore.h>
|
||||
#include "compat/platform_semaphore.h"
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
@@ -156,7 +156,7 @@ void * display_gl_init(void)
|
||||
|
||||
asm("emms\n");
|
||||
|
||||
sem_init(&s->semaphore, 0, 0);
|
||||
platform_sem_init(&s->semaphore, 0, 0);
|
||||
if (pthread_create(&(s->thread_id), NULL, display_thread_gl, (void *) s) != 0) {
|
||||
perror("Unable to create display thread\n");
|
||||
return NULL;
|
||||
@@ -445,7 +445,7 @@ static void * display_thread_gl(void *arg)
|
||||
while(1) {
|
||||
GLubyte *line1, *line2;
|
||||
display_gl_handle_events(s);
|
||||
sem_wait(&s->semaphore);
|
||||
platform_sem_wait(&s->semaphore);
|
||||
|
||||
|
||||
/* 10-bit YUV ->8 bit YUV [I think...] */
|
||||
@@ -797,7 +797,7 @@ int display_gl_putf(void *state, unsigned char *frame)
|
||||
s->image_network = tmp;
|
||||
|
||||
/* ...and signal the worker */
|
||||
sem_post(&s->semaphore);
|
||||
platform_sem_post(&s->semaphore);
|
||||
sem_getvalue(&s->semaphore, &tmp);
|
||||
if(tmp > 1)
|
||||
printf("frame drop!\n");
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <Carbon/Carbon.h>
|
||||
#include <QuickTime/QuickTime.h>
|
||||
|
||||
#include <semaphore.h>
|
||||
#include "compat/platform_semaphore.h"
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
@@ -29,6 +29,7 @@ struct state_kona {
|
||||
char *buffers[2];
|
||||
int image_display, image_network;
|
||||
|
||||
int frames_to_process;
|
||||
/* Thread related information follows... */
|
||||
pthread_t thread_id;
|
||||
sem_t semaphore;
|
||||
@@ -58,10 +59,9 @@ display_thread_kona(void *arg)
|
||||
DisposeHandle((Handle)imageDesc);
|
||||
|
||||
while (1) {
|
||||
ret = sem_wait(&s->semaphore);
|
||||
if (ret != 0) {
|
||||
perror("sem_wait");
|
||||
}
|
||||
platform_sem_wait(&s->semaphore);
|
||||
s->frames_to_process--;
|
||||
|
||||
/* TODO */
|
||||
// memcpy(GetPixBaseAddr(GetGWorldPixMap(s->gworld)), s->buffers[s->image_display], hd_size_x*hd_size_y*hd_color_bpp);
|
||||
|
||||
@@ -85,7 +85,6 @@ display_thread_kona(void *arg)
|
||||
t0 = t;
|
||||
frames = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -115,9 +114,9 @@ display_kona_putf(void *state, char *frame)
|
||||
s->image_network = tmp;
|
||||
|
||||
/* ...and signal the worker */
|
||||
sem_post(&s->semaphore);
|
||||
sem_getvalue(&s->semaphore, &tmp);
|
||||
if(tmp > 1)
|
||||
platform_sem_post(&s->semaphore);
|
||||
s->frames_to_process++;
|
||||
if(s->frames_to_process > 1)
|
||||
printf("frame drop!\n");
|
||||
return 0;
|
||||
|
||||
@@ -140,6 +139,7 @@ display_kona_init(void)
|
||||
s->magic = KONA_MAGIC;
|
||||
s->videoDisplayComponentInstance = 0;
|
||||
s->seqID = 0;
|
||||
s->frames_to_process = 0;
|
||||
|
||||
InitCursor();
|
||||
EnterMovies();
|
||||
@@ -235,10 +235,7 @@ display_kona_init(void)
|
||||
}
|
||||
|
||||
|
||||
ret = sem_init(&s->semaphore, 0, 0);
|
||||
if (ret != 0) {
|
||||
perror(sem_init);
|
||||
}
|
||||
platform_sem_init(&s->semaphore, 0, 0);
|
||||
|
||||
s->buffers[0] = malloc(hd_size_x*hd_size_y*hd_color_bpp);
|
||||
s->buffers[1] = malloc(hd_size_x*hd_size_y*hd_color_bpp);
|
||||
|
||||
@@ -35,8 +35,8 @@
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Revision: 1.8 $
|
||||
* $Date: 2008/03/05 18:29:24 $
|
||||
* $Revision: 1.9 $
|
||||
* $Date: 2008/03/06 12:55:51 $
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
#include <sys/io.h>
|
||||
#endif /* HAVE_MACOSX */
|
||||
#include <sys/time.h>
|
||||
#include <semaphore.h>
|
||||
#include "compat/platform_semaphore.h"
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_syswm.h>
|
||||
@@ -96,7 +96,7 @@ struct state_sdl {
|
||||
int xv_port;
|
||||
/* Thread related information follows... */
|
||||
pthread_t thread_id;
|
||||
sem_t semaphore;
|
||||
sem_t semaphore;
|
||||
/* For debugging... */
|
||||
uint32_t magic;
|
||||
|
||||
@@ -280,7 +280,7 @@ display_thread_sdl(void *arg)
|
||||
char *line1, *line2;
|
||||
display_sdl_handle_events();
|
||||
|
||||
sem_wait(&s->semaphore);
|
||||
platform_sem_wait(&s->semaphore);
|
||||
|
||||
assert(s->vw_image != NULL);
|
||||
|
||||
@@ -359,7 +359,7 @@ display_sdl_init(void)
|
||||
|
||||
asm("emms\n");
|
||||
|
||||
sem_init(&s->semaphore, 0, 0);
|
||||
platform_sem_init(&s->semaphore, 0, 0);
|
||||
|
||||
debug_msg("Window initialized %p\n", s);
|
||||
|
||||
@@ -496,7 +496,7 @@ display_sdl_putf(void *state, char *frame)
|
||||
s->image_network = tmp;
|
||||
|
||||
/* ...and signal the worker */
|
||||
sem_post(&s->semaphore);
|
||||
platform_sem_post(&s->semaphore);
|
||||
sem_getvalue(&s->semaphore, &tmp);
|
||||
if(tmp > 1)
|
||||
printf("frame drop!\n");
|
||||
|
||||
Reference in New Issue
Block a user