From c14524dfca001eb9a320ec7652a0e0c2486d6ece Mon Sep 17 00:00:00 2001 From: Romain Bouqueau Date: Tue, 3 Aug 2010 08:26:59 +0000 Subject: [PATCH] [daud] adding beta support for directfb module git-svn-id: http://svn.code.sf.net/p/gpac/code/trunk/gpac@1963 63c20433-aa62-49bd-875c-5a186b69a8fb --- modules/directfb_out/Makefile | 56 ++++++ modules/directfb_out/directfb_out.c | 269 ++++++++++++++++++++++++++++ modules/directfb_out/directfb_out.h | 50 ++++++ 3 files changed, 375 insertions(+) create mode 100644 modules/directfb_out/Makefile create mode 100755 modules/directfb_out/directfb_out.c create mode 100755 modules/directfb_out/directfb_out.h diff --git a/modules/directfb_out/Makefile b/modules/directfb_out/Makefile new file mode 100644 index 000000000..027a92ff8 --- /dev/null +++ b/modules/directfb_out/Makefile @@ -0,0 +1,56 @@ +include ../../config.mak + +vpath %.c $(SRC_PATH)/modules/directfb_out + +CFLAGS= $(OPTFLAGS) + +ifeq ($(DEBUGBUILD), yes) +CFLAGS+=-g +LDFLAGS+=-g +endif + +ifeq ($(GPROFBUILD), yes) +CFLAGS+=-pg +LDFLAGS+=-pg +endif + +CFLAGS+=-I$(SRC_PATH)/include -I/opt/STM/STLinux-2.3/devkit/sh4/target/usr/include/directfb-1.4.3/ +LDFLAGS+=-L/opt/STM/STLinux-2.3/devkit/sh4/target/usr/lib -ldirectfb-1.4 -lfusion-1.4 -ldirect-1.4 + +#common obj +OBJS=directfb_out.o + +SRCS := $(OBJS:.o=.c) + +LIB=gm_directfb_out.$(DYN_LIB_SUFFIX) + + +all: $(LIB) + + +$(LIB): $(OBJS) + $(CC) $(SHFLAGS) $(LDFLAGS) -L../../bin/gcc -lgpac -o ../../bin/gcc/$@ $(OBJS) + +%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + + +clean: + rm -f $(OBJS) ../../bin/gcc/$(LIB) + +dep: depend + +depend: + rm -f .depend + $(CC) -MM $(CFLAGS) $(SRCS) 1>.depend + +distclean: clean + rm -f Makefile.bak .depend + + + +# include dependency files if they exist +# +ifneq ($(wildcard .depend),) +include .depend +endif diff --git a/modules/directfb_out/directfb_out.c b/modules/directfb_out/directfb_out.c new file mode 100755 index 000000000..00762330c --- /dev/null +++ b/modules/directfb_out/directfb_out.c @@ -0,0 +1,269 @@ +#include "directfb_out.h" + +#define DirectFBVID() DirectFBVidCtx *ctx = (DirectFBVidCtx *)driv->opaque +// this was supposed to contain argc and argv from main !!!!! +int argc; +char **argv = {"toto"}; + +u32 DirectFBVid_TranslatePixelFormatToGPAC(u32 dfbpf) +{ + switch (dfbpf) { + case DSPF_RGB16: return GF_PIXEL_RGB_565; + case DSPF_RGB555: return GF_PIXEL_RGB_555; + case DSPF_RGB24: return GF_PIXEL_RGB_24; + case DSPF_RGB32: return GF_PIXEL_RGB_32; + case DSPF_ARGB: return GF_PIXEL_ARGB; +// case DSPF_YUY2: return GF_PIXEL_YUY2; +// case DSPF_YV12: return GF_PIXEL_YV12; +// case DSPF_I420: return GF_PIXEL_YV12; + default: return 0; + } +} + +u32 DirectFBVid_TranslatePixelFormatFromGPAC(u32 dfbpf) +{ + switch (dfbpf) { + case GF_PIXEL_RGB_565: return DSPF_RGB16; + case GF_PIXEL_RGB_555 : return DSPF_RGB555; + case GF_PIXEL_RGB_24 : return DSPF_RGB24; + case GF_PIXEL_RGB_32 : return DSPF_RGB32; + case GF_PIXEL_ARGB: return DSPF_ARGB; + case GF_PIXEL_YUY2 : return DSPF_YUY2; + case GF_PIXEL_YV12 : return DSPF_YV12; + default: return 0; + } +} + +GF_Err DirectFBVid_Setup(GF_VideoOutput *driv, void *os_handle, void *os_display, u32 init_flags) +{ + DFBResult err; + DFBSurfaceDescription dsc; + DFBSurfacePixelFormat dfbpf; + + DirectFBVID(); + ctx->is_init = 0; + argc=0; + DFBCHECK(DirectFBInit(&argc, & (argv) )); + + /* create the super interface */ + DFBCHECK(DirectFBCreate( &(ctx->dfb) )); + + GF_LOG(GF_LOG_DEBUG, GF_LOG_MMIO, ("[DirectFB] Initialization\n")); + /* create an input buffer for key events */ +// DFBCHECK(ctx->dfb->CreateInputEventBuffer( ctx->dfb, DICAPS_KEYS, DFB_FALSE, &key_events )); + + /* Set the cooperative level */ + err = ctx->dfb->SetCooperativeLevel( ctx->dfb, DFSCL_FULLSCREEN ); + if (err) + DirectFBError( "Failed to set cooperative level", err ); + + /* Get the primary surface, i.e. the surface of the primary layer. */ + dsc.flags = DSDESC_CAPS; + dsc.caps = DSCAPS_PRIMARY | DSCAPS_DOUBLE; + + if (ctx->use_systems_memory) + dsc.caps |= DSCAPS_SYSTEMONLY; + + DFBCHECK(ctx->dfb->CreateSurface( ctx->dfb, &dsc, &(ctx->primary) )); + + ctx->primary->GetPixelFormat( ctx->primary, &dfbpf ); + ctx->pixel_format = DirectFBVid_TranslatePixelFormatToGPAC(dfbpf); + ctx->primary->GetSize( ctx->primary, &(ctx->width), &(ctx->height) ); + ctx->primary->Clear( ctx->primary, 0, 0, 0, 0xFF); + + ctx->is_init = 1; + GF_LOG(GF_LOG_DEBUG, GF_LOG_MMIO, ("[DirectFB] Initialization success\n")); + return GF_OK; +} + +static void DirectFBVid_Shutdown(GF_VideoOutput *driv) +{ + DirectFBVID(); + if (!ctx->is_init) return; + ctx->primary->Release( ctx->primary ); +// ctx->key_events->Release( ctx->key_events ); + ctx->dfb->Release( ctx->dfb ); + ctx->is_init = 0; +} + +static GF_Err DirectFBVid_Flush(GF_VideoOutput *driv, GF_Window *dest) +{ + + DirectFBVID(); + GF_LOG(GF_LOG_DEBUG, GF_LOG_MMIO, ("[DirectFB] Fliping backbuffer\n")); + ctx->primary->Flip( ctx->primary, NULL, DSFLIP_ONSYNC ); +} + + +GF_Err DirectFBVid_SetFullScreen(GF_VideoOutput *driv, u32 bFullScreenOn, u32 *screen_width, u32 *screen_height) +{ + DFBResult err; + DirectFBVID(); + + *screen_width = ctx->width; + *screen_height = ctx->height; + return GF_OK; +} + +#if 0 +Bool DirectFBVid_ProcessMessageQueue(DirectFBVidCtx *ctx, GF_VideoOutput *driv) +{ + DFBInputEvent ev; + u32 err; + + while (ctx->key_events->GetEvent( ctx->key_events, DFB_EVENT(&ev) ) == DFB_OK) + { + if (ev.type == DIET_KEYPRESS) + { + switch (ev.key_symbol) + { + case DIKS_ESCAPE: + case DIKS_SMALL_Q: + case DIKS_CAPITAL_Q: + case DIKS_BACK: + case DIKS_STOP: + DirectFBVid_Shutdown(driv); + exit( 42 ); + break; + default: + break; + } + } + } + return 1; +} +#endif + +static GF_Err DirectFBVid_ProcessEvent(GF_VideoOutput *driv, GF_Event *evt) +{ + DirectFBVID(); + if (!evt) { + //DirectFBVid_ProcessMessageQueue(ctx, driv); + return GF_OK; + } + switch (evt->type) { + case GF_EVENT_SIZE: + if ((ctx->width !=evt->size.width) || (ctx->height != evt->size.height)) { + GF_Event gpac_evt; + gpac_evt.type = GF_EVENT_SIZE; + gpac_evt.size.width = ctx->width; + gpac_evt.size.height = ctx->height; + driv->on_event(driv->evt_cbk_hdl, &gpac_evt); + } + return GF_OK; + + case GF_EVENT_VIDEO_SETUP: + if (evt->setup.opengl_mode) return GF_NOT_SUPPORTED; + + if ((ctx->width !=evt->setup.width) || (ctx->height != evt->setup.height)) { + GF_Event gpac_evt; + gpac_evt.type = GF_EVENT_SIZE; + gpac_evt.size.width = ctx->width; + gpac_evt.size.height = ctx->height; + driv->on_event(driv->evt_cbk_hdl, &gpac_evt); + } + return GF_OK; + default: + return GF_OK; + } +} + +static GF_Err DirectFBVid_LockBackBuffer(GF_VideoOutput *driv, GF_VideoSurface *video_info, u32 do_lock) +{ + DFBResult ret; + u32 pitch; + void *buf; + u32 width, height; + DFBSurfacePixelFormat format; + + DirectFBVID(); + if (!ctx->primary) return GF_BAD_PARAM; + if (do_lock) + { + if (!video_info) return GF_BAD_PARAM; + ret = ctx->primary->Lock(ctx->primary, DSLF_READ | DSLF_WRITE, &buf, &pitch); + if (ret != DFB_OK) return GF_IO_ERR; + + video_info->width = ctx->width; + video_info->height = ctx->height; + video_info->pitch_x = 0; + video_info->pitch_y = pitch; + video_info->video_buffer = buf; + video_info->pixel_format = ctx->pixel_format; + video_info->is_hardware_memory = !ctx->use_systems_memory; + + GF_LOG(GF_LOG_DEBUG, GF_LOG_MMIO, ("[DirectFB] backbuffer locked\n")); + } else { + ctx->primary->Unlock(ctx->primary); + } + return GF_OK; + +} + +static GF_Err DirectFBVid_Blit(GF_VideoOutput *driv, GF_VideoSurface *video_src, GF_Window *src_wnd, GF_Window *dst_wnd, u32 overlay_type) +{ + DirectFBVID(); + return GF_NOT_SUPPORTED; +} + +void *DirectFBNewVideo() +{ + DirectFBVidCtx *ctx; + GF_VideoOutput *driv; + + driv = gf_malloc(sizeof(GF_VideoOutput)); + memset(driv, 0, sizeof(GF_VideoOutput)); + GF_REGISTER_MODULE_INTERFACE(driv, GF_VIDEO_OUTPUT_INTERFACE, "DirectFB Video Output", "gpac distribution"); + + ctx = gf_malloc(sizeof(DirectFBVidCtx)); + memset(ctx, 0, sizeof(DirectFBVidCtx)); + + /* GF_VideoOutput */ + driv->opaque = ctx; + driv->Setup = DirectFBVid_Setup; + driv->Shutdown = DirectFBVid_Shutdown; + driv->Flush = DirectFBVid_Flush; + driv->SetFullScreen = DirectFBVid_SetFullScreen; + driv->ProcessEvent = DirectFBVid_ProcessEvent; + driv->LockBackBuffer = DirectFBVid_LockBackBuffer; + driv->LockOSContext = NULL; + driv->Blit = DirectFBVid_Blit; + driv->hw_caps |= GF_VIDEO_HW_HAS_RGB | GF_VIDEO_HW_HAS_RGBA | GF_VIDEO_HW_HAS_YUV; + return driv; +} + +void DirectFBDeleteVideo(void *ifce) +{ + GF_VideoOutput *driv = (GF_VideoOutput *)ifce; + DirectFBVID(); + gf_free(ctx); + gf_free(driv); +} + + +/*interface query*/ +const u32 *QueryInterfaces() +{ + static u32 si [] = { + GF_VIDEO_OUTPUT_INTERFACE, + 0 + }; + return si; +} + +/*interface create*/ +GF_BaseInterface *LoadInterface(u32 InterfaceType) +{ + if (InterfaceType == GF_VIDEO_OUTPUT_INTERFACE) return DirectFBNewVideo(); + return NULL; +} + +/*interface destroy*/ +void ShutdownInterface(GF_BaseInterface *ifce) +{ + switch (ifce->InterfaceType) { + case GF_VIDEO_OUTPUT_INTERFACE: + DirectFBDeleteVideo(ifce); + break; + } +} diff --git a/modules/directfb_out/directfb_out.h b/modules/directfb_out/directfb_out.h new file mode 100755 index 000000000..1926999d7 --- /dev/null +++ b/modules/directfb_out/directfb_out.h @@ -0,0 +1,50 @@ +#ifndef _DIRECTFB_OUT_H_ +#define _DIRECTFB_OUT_H_ + + +#include + +/* DirectFB */ +#define __DIRECT__STDTYPES__ //prevent u8, s8, ... definitions by directFB as we have them in GPAC +#include +#include +#include +#include + + +/* macro for a safe call to DirectFB functions */ +#define DFBCHECK(x...) \ + do { \ + err = x; \ + if (err != DFB_OK) { \ + fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \ + DirectFBErrorFatal( #x, err ); \ + } \ + } while (0) + +typedef struct +{ + /* the super interface */ + IDirectFB *dfb; + /* the primary surface */ + IDirectFBSurface *primary; + + /* screen width, height */ + u32 width, height, pixel_format; + Bool use_systems_memory, disable_acceleration, disable_aa, is_init; + + /* Input interfaces: event buffer */ +// IDirectFBEventBuffer *key_events; + +} DirectFBVidCtx; + +void *DirectFBNewVideo(); +void DirectFBDeleteVideo(void *ifce); + +#endif + + + + + +