Enlightenment CVS committal

Author  : raster
Project : e17
Module  : apps/elation

Dir     : e17/apps/elation/src/modules


Modified Files:
        Makefile.am elation_disk.c elation_dvd.c 
Added Files:
        elation_cd.c elation_media.c elation_vcd.c 


Log Message:


now auto-detects media type (vcd, dvd, audio cd etc.) and launches an
appropriate module to handle it... vcd i have not tested at all - i just used
the dvd module verbatim. - i hope it works. theres an audio cd module- dvd
module copied verbatim. need to fix that one heavily.

===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/elation/src/modules/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- Makefile.am 20 Jul 2004 08:11:59 -0000      1.3
+++ Makefile.am 24 Jul 2004 05:19:33 -0000      1.4
@@ -6,7 +6,13 @@
 
 pkgdir               = $(libdir)/elation
 
-pkg_LTLIBRARIES      = elation_menu.la elation_dvd.la elation_disk.la
+pkg_LTLIBRARIES      = \
+elation_menu.la \
+elation_dvd.la \
+elation_disk.la \
+elation_media.la \
+elation_vcd.la \
+elation_cd.la
 
 elation_menu_la_SOURCES      = elation_menu.c
 elation_menu_la_LIBADD       = @my_libs@
@@ -22,3 +28,19 @@
 elation_disk_la_LIBADD       = @my_libs@
 elation_disk_la_LDFLAGS      = $(LDFLAGS) -no-undefined -module -avoid-version 
 elation_disk_la_DEPENDENCIES = $(top_builddir)/config.h
+
+elation_media_la_SOURCES      = elation_media.c
+elation_media_la_LIBADD       = @my_libs@
+elation_media_la_LDFLAGS      = $(LDFLAGS) -no-undefined -module -avoid-version 
+elation_media_la_DEPENDENCIES = $(top_builddir)/config.h
+
+elation_vcd_la_SOURCES      = elation_vcd.c
+elation_vcd_la_LIBADD       = @my_libs@
+elation_vcd_la_LDFLAGS      = $(LDFLAGS) -no-undefined -module -avoid-version 
+elation_vcd_la_DEPENDENCIES = $(top_builddir)/config.h
+
+elation_cd_la_SOURCES      = elation_cd.c
+elation_cd_la_LIBADD       = @my_libs@
+elation_cd_la_LDFLAGS      = $(LDFLAGS) -no-undefined -module -avoid-version 
+elation_cd_la_DEPENDENCIES = $(top_builddir)/config.h
+
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/elation/src/modules/elation_disk.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- elation_disk.c      20 Jul 2004 08:11:59 -0000      1.1
+++ elation_disk.c      24 Jul 2004 05:19:33 -0000      1.2
@@ -2,11 +2,14 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <linux/cdrom.h>
+#include <sys/types.h>
+#include <dirent.h>
 
 /* external module symbols. the rest is private */
 void *init(Elation_Module *em);
@@ -26,6 +29,9 @@
    
    Ecore_Fd_Handler *slave_fd_handler;
    
+   char *mount_dir;
+   char *device;
+   
    unsigned char have_media : 1;
    unsigned char check_media_done : 1;
 };
@@ -35,6 +41,14 @@
 
 #define INF_NO_MEDIA 1
 #define INF_MEDIA    2
+#define TYPE_UNKNOWN 3
+#define TYPE_AUDIO   4
+#define TYPE_VCD     5
+#define TYPE_SVCD    6
+#define TYPE_DVD     7
+#define TYPE_DATA    8
+#define TYPE_MIXED   9
+#define TYPE_BLANK   10
 
 static void shutdown(Elation_Module *em);
 static void resize(Elation_Module *em);
@@ -47,6 +61,10 @@
 static int  media_check_timer_cb(void *data);
 static void media_eject(Elation_Module *em);
 static int  slave_fd_cb(void *data, Ecore_Fd_Handler *fdh);
+
+static char *disk_mount(char *dev);
+static void  disk_unmount(char *mount_dir);
+static int   disk_has_top_dir(char *mount_dir, char *dir);
     
 void *
 init(Elation_Module *em)
@@ -65,6 +83,7 @@
    em->unfocus = unfocus;
    em->action = action;
 
+   pr->device = strdup("/dev/dvd");
      {
        int fds_in[2], fds_out[2];
        pid_t pid;
@@ -95,6 +114,7 @@
          {
             for (;;)
               {
+                 int type = 0;
                  int buf;
                  
                  read(pr->slave_side_read_fd, &buf, sizeof(buf));
@@ -105,7 +125,7 @@
                       
                       printf("check...\n");
                       if (pr->have_media) continue;
-                      fd = open("/dev/dvd", O_RDONLY | O_NONBLOCK);
+                      fd = open(pr->device, O_RDONLY | O_NONBLOCK);
                       if (fd >= 0)
                         {
                            if (pr->check_media_done)
@@ -149,29 +169,95 @@
                                   ok = 0;
                                 else
                                   ok = 1;
+                                printf("first check: %i\n", ok);
                                 pr->check_media_done = 1;
                              }
                            close(fd);
                         }
                       if (ok)
                         {
+                           int fd;
+                           
                            pr->have_media = 1;
                            printf("have media\n");
                            /* FIXME: this is where we should check what kind of media 
we have */
+                           fd = open(pr->device, O_RDONLY | O_NONBLOCK);
+                           if (fd >= 0)
+                             {
+                                int ret;
+                                
+                                ret = ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
+                                if (ret == CDS_DISC_OK)
+                                  {
+                                     struct cdrom_tochdr hd;
+                                     
+                                     ret = ioctl(fd, CDROMREADTOCHDR, &hd);
+                                     if (ret != 0) /* blank */
+                                       type = 7;
+                                     else
+                                       {
+                                          ret = ioctl(fd, CDROM_DISC_STATUS, 
CDSL_CURRENT);
+                                          if (ret == CDS_AUDIO)
+                                            type = 1;
+                                          else if (ret == CDS_MIXED)
+                                            type = 6;
+                                          else if ((ret == CDS_DATA_1) ||
+                                                   (ret == CDS_DATA_2))
+                                            {
+                                               pr->mount_dir = disk_mount(pr->device);
+                                               if (pr->mount_dir)
+                                                 {
+                                                    if 
(disk_has_top_dir(pr->mount_dir, "video_ts"))
+                                                      type = 4;
+                                                    else if 
(disk_has_top_dir(pr->mount_dir, "vcd"))
+                                                      type = 2;
+                                                    else if 
(disk_has_top_dir(pr->mount_dir, "svcd"))
+                                                      type = 3;
+                                                    else
+                                                      type = 5;
+                                                 }
+                                            }
+                                       }
+                                  }
+                                close(fd);                              
+                             }
                         }
                       else
                         pr->have_media = 0;
                       if (pr->have_media) buf = INF_MEDIA;
                       else buf = INF_NO_MEDIA;
                       write(pr->slave_side_write_fd, &buf, sizeof(buf));
+                      if (type == 0) /* unknown */
+                        buf = TYPE_UNKNOWN;
+                      else if (type == 1) /* audio */
+                        buf = TYPE_AUDIO;
+                      else if (type == 2) /* vcd */
+                        buf = TYPE_VCD;
+                      else if (type == 3) /* svcd */
+                        buf = TYPE_SVCD;
+                      else if (type == 4) /* dvd */
+                        buf = TYPE_DVD;
+                      else if (type == 5) /* data */
+                        buf = TYPE_DATA;
+                      else if (type == 6) /* mixed */
+                        buf = TYPE_MIXED;
+                      else if (type == 7) /* mixed */
+                        buf = TYPE_BLANK;
+                      printf("disk type: %i\n", type);
+                      write(pr->slave_side_write_fd, &buf, sizeof(buf));
                    }
                  else if (buf == CMD_EJECT)
                    {
                       int fd;
                       
                       printf("eject..\n");
+                      if (pr->mount_dir)
+                        {
+                           disk_unmount(pr->mount_dir);
+                           free(pr->mount_dir);
+                        }
                       pr->have_media = 0;
-                      fd = open("/dev/dvd", O_RDONLY | O_NONBLOCK);
+                      fd = open(pr->device, O_RDONLY | O_NONBLOCK);
                       if (fd >= 0)
                         {
                            int i;
@@ -205,6 +291,12 @@
    if (pr->media_check_timer) ecore_timer_del(pr->media_check_timer);
    close(pr->slave_read_fd);
    kill(pr->slave_pid, SIGKILL);
+   free(pr->device);
+   if (pr->mount_dir)
+     {
+       disk_unmount(pr->mount_dir);
+       free(pr->mount_dir);
+     }
    free(pr);
 }
 
@@ -295,7 +387,100 @@
               em->info->func.action_broadcast(ELATION_ACT_DISK_OUT);
             else if (buf == INF_MEDIA)
               em->info->func.action_broadcast(ELATION_ACT_DISK_IN);
+            else if (buf == TYPE_UNKNOWN)
+              em->info->func.action_broadcast(ELATION_ACT_DISK_TYPE_UNKNOWN);
+            else if (buf == TYPE_AUDIO)
+              em->info->func.action_broadcast(ELATION_ACT_DISK_TYPE_AUDIO);
+            else if (buf == TYPE_VCD)
+              em->info->func.action_broadcast(ELATION_ACT_DISK_TYPE_VCD);
+            else if (buf == TYPE_SVCD)
+              em->info->func.action_broadcast(ELATION_ACT_DISK_TYPE_SVCD);
+            else if (buf == TYPE_DVD)
+              em->info->func.action_broadcast(ELATION_ACT_DISK_TYPE_DVD);
+            else if (buf == TYPE_DATA)
+              em->info->func.action_broadcast(ELATION_ACT_DISK_TYPE_DATA);
+            else if (buf == TYPE_MIXED)
+              em->info->func.action_broadcast(ELATION_ACT_DISK_TYPE_MIXED);
+            else if (buf == TYPE_BLANK)
+              em->info->func.action_broadcast(ELATION_ACT_DISK_TYPE_BLANK);
          }
      }
    return 1;
 }
+
+static char *
+disk_mount(char *dev)
+{
+   FILE *f;
+   char buf[4096];
+   char realdev[PATH_MAX];
+   char *mountpoint = NULL;
+   
+   if (!realpath(dev, realdev)) return NULL;
+   f = fopen("/etc/fstab", "rb");
+   while (fgets(buf, sizeof(buf), f))
+     {
+       char tdev[PATH_MAX];
+       char realtdev[PATH_MAX];
+       char mount[PATH_MAX];
+       
+       if (buf[0] != '#')
+         {
+            sscanf(buf, "%s %s", tdev, mount);
+            if (realpath(tdev, realtdev))
+              {
+                 if (!strcmp(realtdev, realdev))
+                   {
+                      mountpoint = strdup(mount);
+                      break;
+                   }
+              }
+         }
+     }
+   fclose(f);
+   if (mountpoint)
+     {
+       snprintf(buf, sizeof(buf), "mount %s", mountpoint);
+       system(buf);
+     }
+   return mountpoint;
+}
+
+static void
+disk_unmount(char *mount_dir)
+{
+   if (mount_dir)
+     {
+       char buf[4096];
+       
+       snprintf(buf, sizeof(buf), "umount %s", mount_dir);
+       system(buf);
+     }
+}
+
+static int
+disk_has_top_dir(char *mount_dir, char *dir)
+{
+   DIR                *dirp;
+   struct dirent      *dp;
+   
+    dirp = opendir(mount_dir);
+   if (!dirp) return 0;
+   while ((dp = readdir(dirp)))
+     {
+       if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, "..")))
+         {
+            char buf[PATH_MAX];
+            int i;
+            
+            strcpy(buf, dp->d_name);
+            if (!strcasecmp(dp->d_name, dir))
+              {
+                 closedir(dirp);
+                 return 1;
+              }
+         }
+     }
+   closedir(dirp);
+   return 0;
+}
===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/elation/src/modules/elation_dvd.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- elation_dvd.c       20 Jul 2004 08:11:59 -0000      1.5
+++ elation_dvd.c       24 Jul 2004 05:19:33 -0000      1.6
@@ -16,16 +16,13 @@
 
 struct _Elation_Module_Private
 {
-   Evas_Object *overlay;
    Evas_Object *background1;
    Evas_Object *background2;
    Evas_Object *video;
    
-   Ecore_Timer *media_play_timer;
    double       media_fade_in_start;
    Ecore_Timer *media_fade_in_timer;
    
-   unsigned char have_media : 1;
    unsigned char menu_visible : 1;
 };
 
@@ -90,9 +87,11 @@
    
    emotion_object_smooth_scale_set(pr->video, 1);
    
-   pr->overlay = edje_object_add(em->info->evas);
-   edje_object_file_set(pr->overlay, PACKAGE_DATA_DIR"/data/theme.eet", "dvd");
-   edje_object_signal_emit(pr->overlay, "media", "0");
+   emotion_object_file_set(pr->video, "dvd:/");
+   emotion_object_play_set(pr->video, 1);
+   
+   pr->media_fade_in_timer = ecore_timer_add(1.0 / 30.0, media_fade_in_timer_cb, em);
+   pr->media_fade_in_start = ecore_time_get();
    
    return pr;
 }
@@ -106,8 +105,6 @@
    evas_object_del(pr->background1);
    evas_object_del(pr->background2);
    evas_object_del(pr->video);
-   evas_object_del(pr->overlay);
-   if (pr->media_play_timer) ecore_timer_del(pr->media_play_timer);
    if (pr->media_fade_in_timer) ecore_timer_del(pr->media_fade_in_timer);
    free(pr);
 }
@@ -126,9 +123,6 @@
    ww = w;
    hh = h;
    
-   evas_object_move(pr->overlay, 0, 0);
-   evas_object_resize(pr->overlay, w, h);
-   
    emotion_object_size_get(pr->video, &vw, &vh);
    ratio = emotion_object_ratio_get(pr->video);
    if (ratio > 0.0)
@@ -188,13 +182,9 @@
    Elation_Module_Private *pr;
    
    pr = em->data;
-   if (pr->have_media)
-     {
-       evas_object_show(pr->background1);
-       evas_object_show(pr->background2);
-       evas_object_show(pr->video);
-     }
-   evas_object_show(pr->overlay);
+   evas_object_show(pr->background1);
+   evas_object_show(pr->background2);
+   evas_object_show(pr->video);
 }
 
 static void
@@ -206,7 +196,6 @@
    evas_object_hide(pr->background1);
    evas_object_hide(pr->background2);
    evas_object_hide(pr->video);
-   evas_object_hide(pr->overlay);
 }
 
 static void
@@ -262,48 +251,8 @@
        break;
       case ELATION_ACT_EXIT:
          {
-            int fd;
-            
-            printf("stop...\n");
-//          emotion_object_play_set(pr->video, 0);
-            printf("eject...\n");
-//          emotion_object_eject(pr->video);
-            printf("fset...\n");
-            if (1)
-              {
-                 evas_object_del(pr->video);
-                 pr->video = emotion_object_add(em->info->evas);
-                 evas_object_event_callback_add(pr->video, EVAS_CALLBACK_KEY_DOWN, 
key_down_cb, em);
-                 
-                 evas_object_smart_callback_add(pr->video, "frame_decode", 
frame_decode_cb, em);
-                 evas_object_smart_callback_add(pr->video, "frame_resize", 
frame_resize_cb, em);
-                 evas_object_smart_callback_add(pr->video, 
"length_change",length_change_cb, em);
-                 evas_object_smart_callback_add(pr->video, "decode_stop", 
decode_stop_cb, em);
-                 evas_object_smart_callback_add(pr->video, "button_num_change", 
button_num_change_cb, em);
-                 
-                 evas_object_smart_callback_add(pr->video, "title_change", 
title_change_cb, em);
-                 evas_object_smart_callback_add(pr->video, "progress_change", 
progress_change_cb, em);
-                 evas_object_smart_callback_add(pr->video, "channels_change", 
channels_change_cb, em);
-                 evas_object_smart_callback_add(pr->video, "ref_change", 
ref_change_cb, em);
-                 evas_object_smart_callback_add(pr->video, "button_change", 
button_change_cb, em);
-                 
-                 emotion_object_smooth_scale_set(pr->video, 1);
-                 
-                 evas_object_stack_above(pr->video, pr->background1);
-                 evas_object_focus_set(pr->video, 1);
-              }
-            else
-              {
-                 emotion_object_file_set(pr->video, NULL);
-                 emotion_object_play_set(pr->video, 0);
-              }
-            printf("emit..\n");
-            edje_object_signal_emit(pr->overlay, "media", "0");
-            evas_object_hide(pr->background1);
-            evas_object_hide(pr->background2);
-            evas_object_hide(pr->video);
-            pr->have_media = 0;
             em->info->func.action_broadcast(ELATION_ACT_DISK_EJECT);
+            em->shutdown(em);
          }
        break;
       case ELATION_ACT_UP:
@@ -402,15 +351,6 @@
             emotion_object_position_set(pr->video, 0.0);
          }
        break;
-      case ELATION_ACT_DISK_IN:
-       pr->have_media = 1;
-       edje_object_signal_emit(pr->overlay, "media", "1");
-       pr->media_play_timer = ecore_timer_add(2.0, media_play_timer_cb, em);
-       break;
-      case ELATION_ACT_DISK_OUT:
-       pr->have_media = 0;
-       break;
-      case ELATION_ACT_NONE:
       default:
        break;
      }
@@ -572,37 +512,6 @@
 }
 
 static int
-media_play_timer_cb(void *data)
-{
-   Elation_Module *em;
-   Elation_Module_Private *pr;
-   
-   em = data;
-   pr = em->data;
-   pr->media_play_timer = NULL;
-   if (!pr->have_media) return 0;
-   
-   edje_object_signal_emit(pr->overlay, "media", "ok");
-   emotion_object_file_set(pr->video, "dvd:/");
-   emotion_object_play_set(pr->video, 1);
-   if (evas_object_visible_get(pr->overlay))
-     {
-       evas_object_color_set(pr->background1, 0, 0, 0, 0);
-       evas_object_color_set(pr->background2, 0, 0, 0, 0);
-       evas_object_color_set(pr->video, 255, 255, 255, 0);
-       evas_object_show(pr->background1);
-       evas_object_show(pr->background2);
-       evas_object_show(pr->video);
-     }
-   em->resize(em);
-   
-   pr->media_fade_in_timer = ecore_timer_add(1.0 / 30.0, media_fade_in_timer_cb, em);
-   pr->media_fade_in_start = ecore_time_get();
-   
-   return 0;
-}
-
-static int
 media_fade_in_timer_cb(void *data)
 {
    Elation_Module *em;




-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to