GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
 * shoes/ruby.c: support for VLC 0.9.x.  i'm trying to get both 0.8 and
   0.9 APIs supported simultaneously, so there's going to be some macro
   tricks for a little bit here.
why (author)
Sat Oct 11 23:34:54 -0700 2008
commit  51e784073ea1c0abd8aa90d65448576057cc71f9
tree    0f10ce779f860c1d1f1599c0abd5a3dc47c6bef1
parent  08226c3603bcd359ed743845114c0945c8a28b71
...
14
15
16
 
 
17
18
19
 
20
21
22
...
217
218
219
220
 
221
222
223
...
348
349
350
351
 
 
 
 
 
 
 
 
352
353
354
...
14
15
16
17
18
19
20
 
21
22
23
24
...
219
220
221
 
222
223
224
225
...
350
351
352
 
353
354
355
356
357
358
359
360
361
362
363
0
@@ -14,9 +14,11 @@ VERS = ENV['VERSION'] || "0.r#{REVISION}"
0
 PKG = "#{NAME}-#{VERS}"
0
 APPARGS = ENV['APPARGS']
0
 FLAGS = %w[DEBUG VIDEO]
0
+VLC_VERSION = `vlc --version 2>/dev/null`.split[2]
0
+VLC_0_8 = VLC_VERSION !~ /^0\.9/
0
 
0
 BIN = "*.{bundle,jar,o,so,obj,pdb,pch,res,lib,def,exp,exe,ilk}"
0
-CLEAN.include ["{bin,shoes}/#{BIN}", "dist"]
0
+CLEAN.include ["{bin,shoes}/#{BIN}", "req/**/#{BIN}", "dist"]
0
 
0
 # Guess the environment
0
 unless ENV['MSVC'] or ENV['DDKBUILDENV']
0
@@ -217,7 +219,7 @@ when /win32/
0
     /Ideps\ruby\lib\ruby\1.8\i386-mswin32
0
     /Ideps\curl\include
0
     /Ideps\winhttp\include
0
- /I. /DWINVER=0x0500 /D_WIN32_WINNT=0x0500
0
+ /I. /DVLC_0_8 /DWINVER=0x0500 /D_WIN32_WINNT=0x0500
0
     /O2 /GR /EHsc
0
   ].gsub(/\n\s*/, ' ')
0
 
0
@@ -348,7 +350,14 @@ else
0
     LINUX_LDFLAGS =" #{`pkg-config --libs gtk+-2.0`.strip} #{`curl-config --libs`.strip} -fPIC -shared"
0
     LINUX_LIB_NAMES << 'jpeg'
0
     LINUX_LIB_NAMES << 'rt'
0
- LINUX_LIB_NAMES << "vlc" if ENV['VIDEO']
0
+ if ENV['VIDEO']
0
+ if VLC_0_8
0
+ LINUX_CFLAGS << " -DVLC_0_8"
0
+ else
0
+ LINUX_CFLAGS << " -I/usr/include/vlc/plugins"
0
+ end
0
+ LINUX_LIB_NAMES << "vlc"
0
+ end
0
   end
0
   LINUX_LIBS = LINUX_LIB_NAMES.map { |x| "-l#{x}" }.join(' ')
0
 
...
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
0
@@ -13,6 +13,30 @@
0
 #include <cairo.h>
0
 #include <ruby.h>
0
 
0
+#ifdef VIDEO
0
+#ifdef VLC_0_8
0
+#include <vlc/libvlc.h>
0
+#define SHOES_VLC(self_t) self_t->vlc
0
+#define shoes_libvlc_clear libvlc_playlist_clear
0
+#define shoes_libvlc_prev libvlc_playlist_prev
0
+#define shoes_libvlc_next libvlc_playlist_next
0
+#define shoes_libvlc_pause libvlc_playlist_pause
0
+#define shoes_libvlc_stop libvlc_playlist_stop
0
+#else
0
+#include <vlc/vlc.h>
0
+#include <vlc/libvlc.h>
0
+#define libvlc_destroy libvlc_release
0
+#define vlc_int64_t libvlc_time_t
0
+#define shoes_libvlc_clear libvlc_media_player_pause
0
+#define shoes_libvlc_prev libvlc_media_player_stop
0
+#define shoes_libvlc_next libvlc_media_player_stop
0
+#define shoes_libvlc_pause libvlc_media_player_pause
0
+#define shoes_libvlc_stop libvlc_media_player_stop
0
+#define SHOES_VLC(self_t) shoes_world->vlc
0
+#define VLC_0_9
0
+#endif
0
+#endif
0
+
0
 #include "shoes/canvas.h"
0
 #include "shoes/code.h"
0
 #include "shoes/config.h"
...
3
4
5
6
7
 
8
9
10
...
3
4
5
 
6
7
8
9
10
0
@@ -3,8 +3,8 @@
0
 // Ruby methods for all the drawing ops.
0
 //
0
 #include "shoes/internal.h"
0
-#include "shoes/canvas.h"
0
 #include "shoes/app.h"
0
+#include "shoes/canvas.h"
0
 #include "shoes/ruby.h"
0
 #include "shoes/world.h"
0
 #include "shoes/native.h"
...
11
12
13
14
15
16
17
18
19
...
218
219
220
 
221
 
 
 
222
223
224
...
11
12
13
 
 
 
14
15
16
...
215
216
217
218
219
220
221
222
223
224
225
0
@@ -11,9 +11,6 @@
0
 #include <cairo-pdf.h>
0
 
0
 #include <pango/pangocairo.h>
0
-#ifdef VIDEO
0
-#include <vlc/libvlc.h>
0
-#endif
0
 #include <ruby.h>
0
 
0
 #include "shoes/config.h"
0
@@ -218,7 +215,11 @@ typedef struct {
0
   shoes_place place;
0
   SHOES_CONTROL_REF ref;
0
   libvlc_exception_t excp;
0
+#ifdef VLC_0_8
0
   libvlc_instance_t *vlc;
0
+#else
0
+ libvlc_media_player_t *vlc;
0
+#endif
0
   int init;
0
   VALUE path;
0
   SHOES_SLOT_OS *slot;
...
3
4
5
6
7
 
8
9
10
...
3
4
5
 
6
7
8
9
10
0
@@ -3,8 +3,8 @@
0
 // The blurring and shadowing effects.
0
 //
0
 #include "shoes/internal.h"
0
-#include "shoes/canvas.h"
0
 #include "shoes/app.h"
0
+#include "shoes/canvas.h"
0
 #include "shoes/ruby.h"
0
 #include <math.h>
0
 
...
1238
1239
1240
 
1241
1242
 
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
...
1275
1276
1277
1278
 
 
1279
1280
1281
...
1328
1329
1330
 
1331
1332
 
 
 
 
 
 
 
 
1333
1334
1335
1336
1337
 
1338
 
 
 
1339
1340
1341
...
1354
1355
1356
 
1357
 
 
 
1358
1359
1360
...
1377
1378
1379
 
1380
1381
1382
 
 
 
 
 
1383
1384
1385
...
1390
1391
1392
 
1393
 
 
 
1394
1395
1396
...
1403
1404
1405
1406
 
1407
1408
1409
1410
1411
 
1412
1413
1414
...
1439
1440
1441
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1442
1443
1444
...
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
 
1251
1252
1253
...
1276
1277
1278
 
1279
1280
1281
1282
1283
...
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
...
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
...
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
...
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
...
1432
1433
1434
 
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
...
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
0
@@ -1238,15 +1238,16 @@ shoes_video_mark(shoes_video *video)
0
 static void
0
 shoes_video_free(shoes_video *video)
0
 {
0
+#ifdef VLC_0_8
0
   if (video->vlc != NULL)
0
     libvlc_destroy(video->vlc);
0
+#endif
0
   RUBY_CRITICAL(SHOE_FREE(video));
0
 }
0
 
0
 VALUE
0
 shoes_video_new(VALUE klass, VALUE path, VALUE attr, VALUE parent)
0
 {
0
- GError *error = NULL;
0
   shoes_video *video;
0
   VALUE obj = shoes_video_alloc(klass);
0
   Data_Get_Struct(obj, shoes_video, video);
0
@@ -1275,7 +1276,8 @@ shoes_video_alloc(VALUE klass)
0
 #endif
0
   obj = Data_Wrap_Struct(klass, shoes_video_mark, shoes_video_free, video);
0
   libvlc_exception_init(&video->excp);
0
- video->vlc = libvlc_new(ppsz_argc, ppsz_argv, NULL);
0
+ if (SHOES_VLC(video) == NULL)
0
+ SHOES_VLC(video) = libvlc_new(ppsz_argc, ppsz_argv, NULL);
0
   video->path = Qnil;
0
   video->attr = Qnil;
0
   video->parent = Qnil;
0
@@ -1328,14 +1330,27 @@ shoes_video_draw(VALUE self, VALUE c, VALUE actual)
0
       {
0
         self_t->init = 1;
0
 
0
+#ifdef VLC_0_8
0
         int play_id = libvlc_playlist_add(self_t->vlc,
0
           RSTRING_PTR(self_t->path), NULL, &self_t->excp);
0
+#else
0
+ libvlc_media_t *play = libvlc_media_new(shoes_world->vlc,
0
+ RSTRING_PTR(self_t->path), &self_t->excp);
0
+ shoes_vlc_exception(&self_t->excp);
0
+ self_t->vlc = libvlc_media_player_new_from_media(play, &self_t->excp);
0
+ shoes_vlc_exception(&self_t->excp);
0
+ libvlc_media_release(play);
0
+#endif
0
         shoes_vlc_exception(&self_t->excp);
0
 
0
         self_t->ref = shoes_native_surface_new(canvas, self, &self_t->place);
0
         shoes_native_surface_position(self_t->ref, &self_t->place, self, canvas, &place);
0
 
0
+#ifdef VLC_0_8
0
         libvlc_video_set_parent(self_t->vlc, DRAWABLE(self_t->ref), &self_t->excp);
0
+#else
0
+ libvlc_media_player_set_drawable(self_t->vlc, DRAWABLE(self_t->ref), &self_t->excp);
0
+#endif
0
         shoes_vlc_exception(&self_t->excp);
0
 
0
 #ifdef SHOES_QUARTZ
0
@@ -1354,7 +1369,11 @@ shoes_video_draw(VALUE self, VALUE c, VALUE actual)
0
         if (RTEST(ATTR(self_t->attr, autoplay)))
0
         {
0
           INFO("Starting playlist.\n");
0
+#ifdef VLC_0_8
0
           libvlc_playlist_play(self_t->vlc, 0, 0, NULL, &self_t->excp);
0
+#else
0
+ libvlc_media_player_play(self_t->vlc, &self_t->excp);
0
+#endif
0
           shoes_vlc_exception(&self_t->excp);
0
         }
0
       }
0
@@ -1377,9 +1396,15 @@ shoes_video_is_playing(VALUE self)
0
   GET_STRUCT(video, self_t);
0
   if (self_t->init == 1)
0
   {
0
+#ifdef VLC_0_8
0
     int isp = libvlc_playlist_isplaying(self_t->vlc, &self_t->excp);
0
     shoes_vlc_exception(&self_t->excp);
0
     return isp == 0 ? Qfalse : Qtrue;
0
+#else
0
+ libvlc_state_t s = libvlc_media_player_get_state(self_t->vlc, &self_t->excp);
0
+ shoes_vlc_exception(&self_t->excp);
0
+ return s == libvlc_Playing ? Qtrue : Qfalse;
0
+#endif
0
   }
0
   return Qfalse;
0
 }
0
@@ -1390,7 +1415,11 @@ shoes_video_play(VALUE self)
0
   GET_STRUCT(video, self_t);
0
   if (self_t->init == 1)
0
   {
0
+#ifdef VLC_0_8
0
     libvlc_playlist_play(self_t->vlc, 0, 0, NULL, &self_t->excp);
0
+#else
0
+ libvlc_media_player_play(self_t->vlc, &self_t->excp);
0
+#endif
0
     shoes_vlc_exception(&self_t->excp);
0
   }
0
   return self;
0
@@ -1403,12 +1432,13 @@ shoes_video_play(VALUE self)
0
     GET_STRUCT(video, self_t); \
0
     if (self_t->init == 1) \
0
     { \
0
- libvlc_playlist_##x(self_t->vlc, &self_t->excp); \
0
+ shoes_libvlc_##x(self_t->vlc, &self_t->excp); \
0
       shoes_vlc_exception(&self_t->excp); \
0
     } \
0
     return self; \
0
   }
0
 
0
+#ifdef VLC_0_8
0
 #define VIDEO_GET_METHOD(x, ctype, rbtype) \
0
   VALUE shoes_video_get_##x(VALUE self) \
0
   { \
0
@@ -1439,6 +1469,32 @@ shoes_video_play(VALUE self)
0
     } \
0
     return val; \
0
   }
0
+#else
0
+#define VIDEO_GET_METHOD(x, ctype, rbtype) \
0
+ VALUE shoes_video_get_##x(VALUE self) \
0
+ { \
0
+ GET_STRUCT(video, self_t); \
0
+ if (self_t->init == 1) \
0
+ { \
0
+ ctype len = libvlc_media_player_get_##x(self_t->vlc, &self_t->excp); \
0
+ shoes_vlc_exception(&self_t->excp); \
0
+ return rbtype(len); \
0
+ } \
0
+ return Qnil; \
0
+ }
0
+
0
+#define VIDEO_SET_METHOD(x, rbconv) \
0
+ VALUE shoes_video_set_##x(VALUE self, VALUE val) \
0
+ { \
0
+ GET_STRUCT(video, self_t); \
0
+ if (self_t->init == 1) \
0
+ { \
0
+ libvlc_media_player_set_##x(self_t->vlc, rbconv(val), &self_t->excp); \
0
+ shoes_vlc_exception(&self_t->excp); \
0
+ } \
0
+ return val; \
0
+ }
0
+#endif
0
 
0
 VIDEO_METHOD(clear);
0
 VIDEO_METHOD(prev);
...
67
68
69
 
 
 
70
71
72
...
67
68
69
70
71
72
73
74
75
0
@@ -67,6 +67,9 @@ shoes_world_free_image_cache(char *key, shoes_cache_entry *cached, char *arg)
0
 void
0
 shoes_world_free(shoes_world_t *world)
0
 {
0
+#ifdef VLC_0_9
0
+ if (world->vlc != NULL) libvlc_release(world->vlc);
0
+#endif
0
   shoes_native_cleanup(world);
0
   st_foreach(world->image_cache, CASTFOREACH(shoes_world_free_image_cache), 0);
0
   st_free_table(world->image_cache);
...
25
26
27
 
 
 
28
29
30
...
25
26
27
28
29
30
31
32
33
0
@@ -25,6 +25,9 @@ SHOES_EXTERN typedef struct _shoes_world_t {
0
   cairo_surface_t *blank_image;
0
   shoes_cached_image *blank_cache;
0
   PangoFontDescription *default_font;
0
+#ifdef VLC_0_9
0
+ libvlc_instance_t *vlc;
0
+#endif
0
 } shoes_world_t;
0
 
0
 extern SHOES_EXTERN shoes_world_t *shoes_world;

Comments