aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-08-15 00:37:05 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-08-15 00:37:05 +0200
commitcdc6708aec8aad8af54aeaec47f371c47bad0460 (patch)
treefc20c9d73fa0ec4baaa6a0d4152f39b5ed01dac5
parent9346215a47a199df6573f083066ee23680e0e8c0 (diff)
downloadosc-graphics-cdc6708aec8aad8af54aeaec47f371c47bad0460.tar.gz
video layer using libVLC
-rw-r--r--Makefile9
-rw-r--r--effect-pad.c95
2 files changed, 102 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 2e336a7..5f6f6f9 100644
--- a/Makefile
+++ b/Makefile
@@ -9,9 +9,14 @@ SDL_IMAGE_LDFLAGS := $(shell pkg-config SDL_image --libs)
SDL_GFX_CFLAGS := $(shell pkg-config SDL_gfx --cflags)
SDL_GFX_LDFLAGS := $(shell pkg-config SDL_gfx --libs)
+LIBVLC_CFLAGS := $(shell pkg-config libvlc --cflags)
+LIBVLC_LDFLAGS := $(shell pkg-config libvlc --libs)
+
CFLAGS := -std=c99 -Wall -g -O0 \
- $(SDL_CFLAGS) $(SDL_IMAGE_CFLAGS) $(SDL_GFX_CFLAGS)
-LDFLAGS := $(SDL_LDFLAGS) $(SDL_IMAGE_LDFLAGS) $(SDL_GFX_LDFLAGS)
+ $(SDL_CFLAGS) $(SDL_IMAGE_CFLAGS) $(SDL_GFX_CFLAGS) \
+ $(LIBVLC_CFLAGS)
+LDFLAGS := $(SDL_LDFLAGS) $(SDL_IMAGE_LDFLAGS) $(SDL_GFX_LDFLAGS) \
+ $(LIBVLC_LDFLAGS)
all : effect-pad
diff --git a/effect-pad.c b/effect-pad.c
index 235a43a..ef84739 100644
--- a/effect-pad.c
+++ b/effect-pad.c
@@ -9,6 +9,8 @@
#include <SDL_rotozoom.h>
#include <SDL_gfxPrimitives.h>
+#include <vlc/vlc.h>
+
//#define EFFECT_FIRE_COLORKEYED
#define NARRAY(ARRAY) \
@@ -322,6 +324,85 @@ effect_image_change(const char *file)
}
}
+static struct EffectVideoCtx {
+ libvlc_instance_t *vlcinst;
+ libvlc_media_player_t *mp;
+
+ SDL_Surface *surf;
+ SDL_mutex *mutex;
+} effect_video_ctx;
+
+static void *
+effect_video_lock(void *data, void **p_pixels)
+{
+ struct EffectVideoCtx *ctx = data;
+
+ SDL_LockMutex(ctx->mutex);
+ SDL_LockSurface(ctx->surf);
+ *p_pixels = ctx->surf->pixels;
+
+ return NULL; /* picture identifier, not needed here */
+}
+
+static void
+effect_video_unlock(void *data, void *id, void *const *p_pixels)
+{
+ struct EffectVideoCtx *ctx = data;
+
+ SDL_UnlockSurface(ctx->surf);
+ SDL_UnlockMutex(ctx->mutex);
+
+ assert(id == NULL); /* picture identifier, not needed here */
+}
+
+static void
+effect_video_display(void *data __attribute__((unused)), void *id)
+{
+ /* VLC wants to display the video */
+ assert(id == NULL);
+}
+
+static inline void
+effect_video_init(void)
+{
+ char const *vlc_argv[] = {
+ "--no-audio", /* skip any audio track */
+ "--no-xlib", /* tell VLC to not use Xlib */
+ };
+
+ effect_video_ctx.surf = SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h,
+ 16, 0x001f, 0x07e0, 0xf800, 0);
+ effect_video_ctx.mutex = SDL_CreateMutex();
+
+ effect_video_ctx.vlcinst = libvlc_new(NARRAY(vlc_argv), vlc_argv);
+}
+
+static void
+effect_video_change(const char *file)
+{
+ libvlc_media_t *m;
+
+ if (file == NULL) {
+ if (effect_video_ctx.mp != NULL)
+ libvlc_media_player_release(effect_video_ctx.mp);
+ effect_video_ctx.mp = NULL;
+ return;
+ }
+
+ m = libvlc_media_new_location(effect_video_ctx.vlcinst, file);
+ effect_video_ctx.mp = libvlc_media_player_new_from_media(m);
+ libvlc_media_release(m);
+
+ libvlc_video_set_callbacks(effect_video_ctx.mp,
+ effect_video_lock, effect_video_unlock, effect_video_display,
+ &effect_video_ctx);
+ libvlc_video_set_format(effect_video_ctx.mp, "RV16",
+ effect_video_ctx.surf->w,
+ effect_video_ctx.surf->h,
+ effect_video_ctx.surf->w*2);
+ libvlc_media_player_play(effect_video_ctx.mp);
+}
+
static SDL_Color effect_bg_color = {0, 0, 0};
static inline void
@@ -455,6 +536,13 @@ process_events(void)
case SDLK_2:
effect_image_change("image_2.png");
break;
+ case SDLK_3:
+ effect_video_change("v4l2://");
+ break;
+ case SDLK_4:
+ effect_video_change("/mnt/data/movies/Godzilla.-.1967.-.Frankenstein.jagt.Godzillas.Sohn.KHPP.avi");
+ break;
+
case SDLK_f:
currentEffect = EFFECT_FIRE;
@@ -520,6 +608,7 @@ main(int argc, char **argv)
SDL_setFramerate(&fpsm, FRAMERATE);
effect_generic_init();
+ effect_video_init();
fire_surface = effect_fire_init();
for (;;) {
@@ -531,6 +620,12 @@ main(int argc, char **argv)
effect_bg_color.g,
effect_bg_color.b));
+ if (effect_video_ctx.mp != NULL) {
+ SDL_LockMutex(effect_video_ctx.mutex);
+ SDL_BlitSurface(effect_video_ctx.surf, NULL, screen, NULL);
+ SDL_UnlockMutex(effect_video_ctx.mutex);
+ }
+
if (image_surface != NULL)
SDL_BlitSurface(image_surface, NULL, screen, NULL);