emotion/generic: Add support for fetching meta info.
authorantognolli <antognolli@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 5 Sep 2011 21:52:14 +0000 (21:52 +0000)
committerantognolli <antognolli@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 5 Sep 2011 21:52:14 +0000 (21:52 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/emotion@63219 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/generic_players/vlc/emotion_generic_vlc.c
src/modules/generic/Emotion_Generic_Plugin.h
src/modules/generic/emotion_generic.c
src/modules/generic/emotion_generic.h

index 2e13ed4..b3e1eb1 100644 (file)
@@ -186,7 +186,10 @@ static void
 _send_cmd_str(struct _App *app, const char *str)
 {
    int len;
-   len = strlen(str) + 1;
+   if (str)
+     len = strlen(str) + 1;
+   else
+     len = 0;
    _em_write_safe(app->em_write, &len, sizeof(len));
    _em_write_safe(app->em_write, str, len);
 }
@@ -650,6 +653,36 @@ _send_all_track_info(struct _App *app)
 }
 
 static void
+_send_all_meta_info(struct _App *app)
+{
+   const char *meta;
+
+   _send_cmd_start(app, EM_RESULT_META_INFO);
+
+   /*
+    * Will send in this order: title, artist, album, year,
+    * genre, comments, disc id and track count.
+    */
+   meta = libvlc_media_get_meta(app->m, libvlc_meta_Title);
+   _send_cmd_str(app, meta);
+   meta = libvlc_media_get_meta(app->m, libvlc_meta_Artist);
+   _send_cmd_str(app, meta);
+   meta = libvlc_media_get_meta(app->m, libvlc_meta_Album);
+   _send_cmd_str(app, meta);
+   meta = libvlc_media_get_meta(app->m, libvlc_meta_Date);
+   _send_cmd_str(app, meta);
+   meta = libvlc_media_get_meta(app->m, libvlc_meta_Genre);
+   _send_cmd_str(app, meta);
+   meta = NULL; // sending empty comments
+   _send_cmd_str(app, meta);
+   meta = NULL; // sending empty disc id
+   _send_cmd_str(app, meta);
+   meta = libvlc_media_get_meta(app->m, libvlc_meta_TrackNumber);
+   _send_cmd_str(app, meta);
+   _send_cmd_finish(app);
+}
+
+static void
 _position_changed(struct _App *app)
 {
    if (!app->opening)
@@ -665,6 +698,9 @@ _position_changed(struct _App *app)
    /* sending audio track info */
    _send_all_track_info(app);
 
+   /* sending meta info */
+   _send_all_meta_info(app);
+
    libvlc_media_player_stop(app->mp);
 }
 
index 4731d33..b418ebc 100644 (file)
@@ -53,6 +53,7 @@ enum _Emotion_Generic_Result
    EM_RESULT_VIDEO_TRACK_INFO, // param: current track, track count, track_id, track_name, track_id2, track_name2, ...
    EM_RESULT_SPU_TRACK_INFO, // param: current spu, spu count, spu_id, spu_name, spu_id2, spu_name2, ...
                               // (int, int, int, string, int, string, ...)
+   EM_RESULT_META_INFO, // param: title, artist, album, year, genre, comments, disc id, count (all int)
    EM_RESULT_LAST
 };
 
index d13507b..eee92bd 100644 (file)
@@ -498,6 +498,51 @@ _player_spu_tracks_info(Emotion_Generic_Video *ev)
 }
 
 static void
+_player_helper_str_read(Emotion_Generic_Video *ev, const char **pstr)
+{
+   int len;
+   char buf[PATH_MAX];
+   if (_player_str_read(ev, buf, &len))
+     *pstr = eina_stringshare_add_length(buf, len);
+}
+
+static void
+_player_meta_info_free(Emotion_Generic_Video *ev)
+{
+   eina_stringshare_replace(&ev->meta.title, NULL);
+   eina_stringshare_replace(&ev->meta.artist, NULL);
+   eina_stringshare_replace(&ev->meta.album, NULL);
+   eina_stringshare_replace(&ev->meta.year, NULL);
+   eina_stringshare_replace(&ev->meta.genre, NULL);
+   eina_stringshare_replace(&ev->meta.comment, NULL);
+   eina_stringshare_replace(&ev->meta.disc_id, NULL);
+   eina_stringshare_replace(&ev->meta.count, NULL);
+}
+
+static void
+_player_meta_info_read(Emotion_Generic_Video *ev)
+{
+   INF("Receiving meta info:");
+   _player_meta_info_free(ev);
+   _player_helper_str_read(ev, &ev->meta.title);
+   _player_helper_str_read(ev, &ev->meta.artist);
+   _player_helper_str_read(ev, &ev->meta.album);
+   _player_helper_str_read(ev, &ev->meta.year);
+   _player_helper_str_read(ev, &ev->meta.genre);
+   _player_helper_str_read(ev, &ev->meta.comment);
+   _player_helper_str_read(ev, &ev->meta.disc_id);
+   _player_helper_str_read(ev, &ev->meta.count);
+   INF("title: '%s'", ev->meta.title);
+   INF("artist: '%s'", ev->meta.artist);
+   INF("album: '%s'", ev->meta.album);
+   INF("year: '%s'", ev->meta.year);
+   INF("genre: '%s'", ev->meta.genre);
+   INF("comment: '%s'", ev->meta.comment);
+   INF("disc_id: '%s'", ev->meta.disc_id);
+   INF("count: '%s'", ev->meta.count);
+}
+
+static void
 _player_file_closed(Emotion_Generic_Video *ev)
 {
    INF("Closed previous file.");
@@ -593,6 +638,9 @@ _player_read_cmd(Emotion_Generic_Video *ev)
       case EM_RESULT_SPU_TRACK_INFO:
         _player_spu_tracks_info(ev);
         break;
+      case EM_RESULT_META_INFO:
+        _player_meta_info_read(ev);
+        break;
       default:
         WRN("received wrong command: %d", type);
    };
@@ -812,6 +860,7 @@ em_shutdown(void *data)
    _audio_channels_free(ev);
    _video_channels_free(ev);
    _spu_channels_free(ev);
+   _player_meta_info_free(ev);
 
    eina_stringshare_del(ev->cmdline);
    eina_stringshare_del(ev->shmname);
@@ -1330,10 +1379,30 @@ em_eject(void *ef __UNUSED__)
 }
 
 static const char *
-em_meta_get(void *ef __UNUSED__, int meta __UNUSED__)
+em_meta_get(void *data, int meta)
 {
-   char * meta_data = NULL;
-   return meta_data;
+   Emotion_Generic_Video *ev = data;
+
+   switch (meta) {
+      case EMOTION_META_INFO_TRACK_TITLE:
+        return ev->meta.title;
+      case EMOTION_META_INFO_TRACK_ARTIST:
+        return ev->meta.artist;
+      case EMOTION_META_INFO_TRACK_ALBUM:
+        return ev->meta.album;
+      case EMOTION_META_INFO_TRACK_YEAR:
+        return ev->meta.year;
+      case EMOTION_META_INFO_TRACK_GENRE:
+        return ev->meta.genre;
+      case EMOTION_META_INFO_TRACK_COMMENT:
+        return ev->meta.comment;
+      case EMOTION_META_INFO_TRACK_DISC_ID:
+        return ev->meta.disc_id;
+      case EMOTION_META_INFO_TRACK_COUNT:
+        return ev->meta.count;
+   }
+
+   return NULL;
 }
 
 static Emotion_Video_Module em_module =
index ea68ae0..2ca8bf8 100644 (file)
@@ -8,6 +8,7 @@
 typedef struct _Emotion_Generic_Video       Emotion_Generic_Video;
 typedef struct _Emotion_Generic_Player       Emotion_Generic_Player;
 typedef struct _Emotion_Generic_Channel Emotion_Generic_Channel;
+typedef struct _Emotion_Generic_Meta       Emotion_Generic_Meta;
 
 struct _Emotion_Generic_Player
 {
@@ -20,6 +21,18 @@ struct _Emotion_Generic_Channel
    const char *name;
 };
 
+struct _Emotion_Generic_Meta
+{
+   const char *title;
+   const char *artist;
+   const char *album;
+   const char *year;
+   const char *genre;
+   const char *comment;
+   const char *disc_id;
+   const char *count;
+};
+
 /* emotion/generic main structure */
 struct _Emotion_Generic_Video
 {
@@ -64,6 +77,7 @@ struct _Emotion_Generic_Video
    int                      spu_channels_count;
    int                      spu_channel_current;
    struct _Emotion_Generic_Channel *spu_channels;
+   Emotion_Generic_Meta             meta;
 };
 
 #endif