diff --git a/Makefile.in b/Makefile.in index 76d487b11..77259875f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -216,9 +216,6 @@ src/video_capture/DeckLinkAPIDispatch.o: $(DECKLINK_PATH)/DeckLinkAPIDispatch.cp src/video_capture/DeckLinkAPI_i.o: $(DECKLINK_PATH)/DeckLinkAPI_i.c $(CC) $(CFLAGS) -c $(INC) -o src/video_capture/DeckLinkAPI_i.o $(DECKLINK_PATH)/DeckLinkAPI_i.c -src/video_display/sage_wrapper.o: src/video_display/sage_wrapper.cxx - $(CXX) $(CXXFLAGS) -c $(INC) -DQUANTA_USE_PTHREADS -DQUANTA_THREAD_SAFE -DGLSL_YUV -o src/video_display/sage_wrapper.o src/video_display/sage_wrapper.cxx - dxt_compress/dxt_encoder.o: dxt_compress/dxt_encoder.c dxt_compress/dxt_glsl.h $(CC) $(CFLAGS) $(INC) $(DXT_GLSL_CFLAGS) $< -c -o $@ diff --git a/configure.ac b/configure.ac index 05f71c89c..897049e96 100644 --- a/configure.ac +++ b/configure.ac @@ -2010,10 +2010,11 @@ if test $sage_req != no -a $FOUND_SAGE_L = yes -a $FOUND_SAGE_H = yes then SAGE_INC=-I${SAGE_INC} SAGE_LIB=-"L${SAGE_LIB} -lsail -lquanta" - SAGE_OBJ="src/video_display/sage.o src/video_display/sage_wrapper.o" + SAGE_OBJ="src/video_display/sage.o" AC_DEFINE([HAVE_SAGE], [1], [Build with SAGE support]) LINKER=$CXX AC_SUBST(SAGE_LIB_TARGET, "lib/ultragrid/display_sage.so.$video_display_abi_version") + CXXFLAGS="$CXXFLAGS -DQUANTA_USE_PTHREADS -DQUANTA_THREAD_SAFE -DGLSL_YUV" LIB_TARGETS="$LIB_TARGETS $SAGE_LIB_TARGET" LIB_OBJS="$LIB_OBJS $SAGE_OBJ" sage=yes diff --git a/src/video_display/sage.c b/src/video_display/sage.cpp similarity index 82% rename from src/video_display/sage.c rename to src/video_display/sage.cpp index e37f7ea8b..f2bf60d1d 100644 --- a/src/video_display/sage.c +++ b/src/video_display/sage.cpp @@ -68,7 +68,9 @@ #include #include -#include "video_display/sage_wrapper.h" +#include +#include + #include #include @@ -94,7 +96,7 @@ struct state_sage { uint32_t magic; int appID, nodeID; - void *sage_state; + sail *sage_state; const char *confName; const char *fsIP; @@ -123,8 +125,18 @@ void display_sage_run(void *arg) if (should_exit) break; - sage_swapBuffer(s->sage_state); - s->tile->data = (char *) sage_getBuffer(s->sage_state); + s->sage_state->swapBuffer(SAGE_NON_BLOCKING); + sageMessage msg; + if (s->sage_state->checkMsg(msg, false) > 0) { + switch (msg.getCode()) { + case APP_QUIT: + sage::printLog("Ultragrid: QUIT message"); + exit_uv(1); + break; + } + } + + s->tile->data = (char *) s->sage_state->getBuffer(); pthread_mutex_lock(&s->buffer_writable_lock); s->buffer_writable = 1; @@ -178,7 +190,6 @@ void *display_sage_init(char *fmt, unsigned int flags) if(strncmp(item, "config=", strlen("config=")) == 0) { s->confName = item + strlen("config="); } else if(strncmp(item, "codec=", strlen("codec=")) == 0) { - strlen("codec="); uint32_t fourcc; if(strlen(item + strlen("codec=")) != sizeof(fourcc)) { fprintf(stderr, "Malformed FourCC code (wrong length).\n"); @@ -292,8 +303,9 @@ void display_sage_done(void *state) pthread_cond_destroy(&s->buffer_writable_cond); pthread_mutex_destroy(&s->buffer_writable_lock); vf_free(s->frame); - sage_shutdown(s->sage_state); - //sage_delete(s->sage_state); + s->sage_state->shutdown(); + //delete s->sage_state; + free(s); } struct video_frame *display_sage_getf(void *state) @@ -341,6 +353,89 @@ int display_sage_putf(void *state, struct video_frame *frame, int nonblock) return 0; } +/* + * Either confName or fsIP should be NULL + */ +static sail *initSage(const char *confName, const char *fsIP, int appID, int nodeID, int width, + int height, codec_t codec) +{ + sail *sageInf; // sage sail object + + sageInf = new sail; + sailConfig sailCfg; + + // default values + if(fsIP) { + strncpy(sailCfg.fsIP, fsIP, SAGE_IP_LEN); + } + sailCfg.fsPort = 20002; + strncpy(sailCfg.masterIP, "127.0.0.1", SAGE_IP_LEN); + sailCfg.nwID = 1; + sailCfg.msgPort = 23010; + sailCfg.syncPort = 13010; + sailCfg.blockSize = 64; + sailCfg.winX = sailCfg.winY = 0; + sailCfg.winWidth = width; + sailCfg.winHeight = height; + sailCfg.streamType = SAGE_BLOCK_NO_SYNC; + sailCfg.protocol = SAGE_UDP; + sailCfg.asyncUpdate = false; + + if(confName) { + sailCfg.init((char *) confName); + } + char appName[] = "ultragrid"; + sailCfg.setAppName(appName); + sailCfg.rank = nodeID; + sailCfg.appID = appID; + sailCfg.resX = width; + sailCfg.resY = height; + + sageRect renderImageMap; + renderImageMap.left = 0.0; + renderImageMap.right = 1.0; + renderImageMap.bottom = 0.0; + renderImageMap.top = 1.0; + + sailCfg.imageMap = renderImageMap; + switch (codec) { + case DXT1: + sailCfg.pixFmt = PIXFMT_DXT; + break; +#ifdef SAGE_NATIVE_DXT5YCOCG + case DXT5: + sailCfg.pixFmt = PIXFMT_DXT5YCOCG + break; +#endif // SAGE_NATIVE_DXT5YCOCG + case RGBA: + sailCfg.pixFmt = PIXFMT_8888; + break; + case UYVY: + sailCfg.pixFmt = PIXFMT_YUV; + break; + case RGB: + sailCfg.pixFmt = PIXFMT_888; + break; + default: + abort(); + } + + if(codec == DXT1) { + sailCfg.rowOrd = BOTTOM_TO_TOP; +#ifdef SAGE_NATIVE_DXT5YCOCG + } else if(codec == DXT5) { + sailCfg.rowOrd = BOTTOM_TO_TOP; +#endif // SAGE_NATIVE_DXT5YCOCG + } else { + sailCfg.rowOrd = TOP_TO_BOTTOM; + } + sailCfg.master = true; + + sageInf->init(sailCfg); + + return sageInf; +} + int display_sage_reconfigure(void *state, struct video_desc desc) { struct state_sage *s = (struct state_sage *)state; @@ -369,7 +464,8 @@ int display_sage_reconfigure(void *state, struct video_desc desc) pthread_sigmask(SIG_BLOCK, &mask, &old_mask); if(s->sage_state) { - sage_shutdown(s->sage_state); + s->sage_state->shutdown(); + //delete s->sage_state; // this used to cause crashes } s->sage_state = initSage(s->confName, s->fsIP, s->appID, s->nodeID, @@ -378,7 +474,7 @@ int display_sage_reconfigure(void *state, struct video_desc desc) // calling thread should be able to process signals afterwards pthread_sigmask(SIG_UNBLOCK, &old_mask, NULL); - s->tile->data = (char *) sage_getBuffer(s->sage_state); + s->tile->data = (char *) s->sage_state->getBuffer(); s->tile->data_len = vc_get_linesize(s->tile->width, desc.color_spec) * s->tile->height; return TRUE; @@ -388,7 +484,7 @@ display_type_t *display_sage_probe(void) { display_type_t *dt; - dt = malloc(sizeof(display_type_t)); + dt = (display_type_t *) malloc(sizeof(display_type_t)); if (dt != NULL) { dt->id = DISPLAY_SAGE_ID; dt->name = "sage"; diff --git a/src/video_display/sage.h b/src/video_display/sage.h index 601036cb0..0748187ff 100644 --- a/src/video_display/sage.h +++ b/src/video_display/sage.h @@ -48,6 +48,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + #define DISPLAY_SAGE_ID 0xba370a2f struct audio_frame; @@ -69,3 +73,7 @@ void display_sage_put_audio_frame(void *state, struct audio_ int display_sage_reconfigure_audio(void *state, int quant_samples, int channels, int sample_rate); +#ifdef __cplusplus +} +#endif + diff --git a/src/video_display/sage_wrapper.cxx b/src/video_display/sage_wrapper.cxx deleted file mode 100644 index 010c579f7..000000000 --- a/src/video_display/sage_wrapper.cxx +++ /dev/null @@ -1,174 +0,0 @@ -/* - * FILE: video_display/sage_wrapper.cxx - * AUTHORS: Martin Benes - * Lukas Hejtmanek - * Petr Holub - * Milos Liska - * Jiri Matela - * Dalibor Matura <255899@mail.muni.cz> - * Ian Wesley-Smith - * - * Copyright (c) 2005-2209 CESNET z.s.p.o. - * - * Redistribution and use in source and binary forms, with or without - * modification, is permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by CESNET z.s.p.o. - * - * 4. Neither the name of CESNET nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific - * prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * - */ - -#include "sage_wrapper.h" -#include -#include -extern "C" { -#include "host.h" -} - -/* - * Either confName or fsIP should be NULL - */ -void *initSage(const char *confName, const char *fsIP, int appID, int nodeID, int width, - int height, codec_t codec) -{ - sail *sageInf; // sage sail object - - sageInf = new sail; - sailConfig sailCfg; - - // default values - if(fsIP) { - strncpy(sailCfg.fsIP, fsIP, SAGE_IP_LEN); - } - sailCfg.fsPort = 20002; - strncpy(sailCfg.masterIP, "127.0.0.1", SAGE_IP_LEN); - sailCfg.nwID = 1; - sailCfg.msgPort = 23010; - sailCfg.syncPort = 13010; - sailCfg.blockSize = 64; - sailCfg.winX = sailCfg.winY = 0; - sailCfg.winWidth = width; - sailCfg.winHeight = height; - sailCfg.streamType = SAGE_BLOCK_NO_SYNC; - sailCfg.protocol = SAGE_UDP; - sailCfg.asyncUpdate = false; - - if(confName) { - sailCfg.init((char *) confName); - } - sailCfg.setAppName("ultragrid"); - sailCfg.rank = nodeID; - sailCfg.appID = appID; - sailCfg.resX = width; - sailCfg.resY = height; - - sageRect renderImageMap; - renderImageMap.left = 0.0; - renderImageMap.right = 1.0; - renderImageMap.bottom = 0.0; - renderImageMap.top = 1.0; - - sailCfg.imageMap = renderImageMap; - switch (codec) { - case DXT1: - sailCfg.pixFmt = PIXFMT_DXT; - break; -#ifdef SAGE_NATIVE_DXT5YCOCG - case DXT5: - sailCfg.pixFmt = PIXFMT_DXT5YCOCG - break; -#endif // SAGE_NATIVE_DXT5YCOCG - case RGBA: - sailCfg.pixFmt = PIXFMT_8888; - break; - case UYVY: - sailCfg.pixFmt = PIXFMT_YUV; - break; - case RGB: - sailCfg.pixFmt = PIXFMT_888; - break; - } - - if(codec == DXT1) { - sailCfg.rowOrd = BOTTOM_TO_TOP; -#ifdef SAGE_NATIVE_DXT5YCOCG - } else if(codec == DXT5) { - sailCfg.rowOrd = BOTTOM_TO_TOP; -#endif // SAGE_NATIVE_DXT5YCOCG - } else { - sailCfg.rowOrd = TOP_TO_BOTTOM; - } - sailCfg.master = true; - - sageInf->init(sailCfg); - - return sageInf; -} - -void sage_shutdown(void * state) -{ - if(!state) { - return; - } - sail *sageInf = (sail *) state; - sageInf->shutdown(); - // don't try to delete, since it would probably cause crash with current SAGE - //delete sageInf; -} - -void sage_swapBuffer(void *state) -{ - sail *sageInf = (sail *) state; - sageInf->swapBuffer(SAGE_NON_BLOCKING); - - sageMessage msg; - if (sageInf->checkMsg(msg, false) > 0) { - switch (msg.getCode()) { - case APP_QUIT : { - sage::printLog("Ultragrid: QUIT message"); - exit_uv(1); - break; - } - } - } -} - -GLubyte * sage_getBuffer(void *state) -{ - sail *sageInf = (sail *) state; - return (GLubyte *)sageInf->getBuffer(); -} - -void sage_delete(void *state) -{ - sail *sageInf = (sail *) state; - delete sageInf; -} diff --git a/src/video_display/sage_wrapper.h b/src/video_display/sage_wrapper.h deleted file mode 100644 index 330bc27f1..000000000 --- a/src/video_display/sage_wrapper.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * FILE: video_display/sage_wrapper.h - * AUTHORS: Martin Benes - * Lukas Hejtmanek - * Petr Holub - * Milos Liska - * Jiri Matela - * Dalibor Matura <255899@mail.muni.cz> - * Ian Wesley-Smith - * - * Copyright (c) 2005-2209 CESNET z.s.p.o. - * - * Redistribution and use in source and binary forms, with or without - * modification, is permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by CESNET z.s.p.o. - * - * 4. Neither the name of CESNET nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific - * prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * - */ - -#ifndef _SAGE_WRAPPER -#define _SAGE_WRAPPER - -#include "video_codec.h" -#include - -//switching between dircet sage YUV support and yuv2rgba conversion in ug -#define SAGE_GLSL_YUV 1 - -// SAGE headers -#ifdef __cplusplus -extern "C" { -#endif -void* initSage(const char *confName, const char *fsIP, int appID, int nodeID, int width, - int height, codec_t codec); -void sage_swapBuffer(void *); -GLubyte * sage_getBuffer(void *); -void sage_shutdown(void *); -void sage_delete(void *); -#ifdef __cplusplus -} -#endif - -#endif