Enlightenment CVS committal
Author : tsauerbeck
Project : misc
Module : eplayer
Dir : misc/eplayer/src
Modified Files:
Makefile.am callbacks.c callbacks.h eplayer.c eplayer.h
interface.c playlist.c playlist.h
Added Files:
plugin.c plugin.h track.c track.h
Removed Files:
output_plugin.c output_plugin.h vorbis.c vorbis.h
Log Message:
Added input plugin stuff, fixed some playlist bugs
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- Makefile.am 21 Oct 2003 17:53:38 -0000 1.6
+++ Makefile.am 23 Oct 2003 17:01:49 -0000 1.7
@@ -1,6 +1,6 @@
-# $Id: Makefile.am,v 1.6 2003/10/21 17:53:38 tsauerbeck Exp $
+# $Id: Makefile.am,v 1.7 2003/10/23 17:01:49 tsauerbeck Exp $
-SUBDIRS = output
+SUBDIRS = input output
AM_CFLAGS = @ECORE_CFLAGS@ @EVAS_CFLAGS@ @EDJE_CFLAGS@ @ESMART_CFLAGS@
@@ -9,9 +9,9 @@
eplayer_SOURCES = eplayer.c eplayer.h \
interface.c interface.h \
callbacks.c callbacks.h \
- vorbis.c vorbis.h \
+ track.c track.h \
playlist.c playlist.h \
- output_plugin.c output_plugin.h
+ plugin.c plugin.h
-eplayer_LDADD = @DL_LIBS@ @VORBIS_LIBS@ \
+eplayer_LDADD = @DL_LIBS@ \
@ECORE_LIBS@ @EVAS_LIBS@ @EDJE_LIBS@ @ESMART_LIBS@
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/callbacks.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- callbacks.c 22 Oct 2003 18:50:05 -0000 1.8
+++ callbacks.c 23 Oct 2003 17:01:49 -0000 1.9
@@ -2,13 +2,20 @@
#include <Edje.h>
#include <Esmart/container.h>
#include "eplayer.h"
-#include "vorbis.h"
+#include "track.h"
#include "interface.h"
static int paused = 0;
-void cb_play(ePlayer *player, Evas *e, Evas_Object *obj,
- void *event_info) {
+/**
+ * Starts/resumes playback.
+ *
+ * @param player
+ * @param e
+ * @param o
+ * @param event
+ */
+void cb_play(ePlayer *player, Evas *e, Evas_Object *o, void *event) {
#ifdef DEBUG
printf("Play callback entered\n");
#endif
@@ -21,8 +28,15 @@
}
}
-void cb_pause(ePlayer *player, Evas *e, Evas_Object *obj,
- void *event_info) {
+/**
+ * Pauses/resumes playback.
+ *
+ * @param player
+ * @param e
+ * @param o
+ * @param event
+ */
+void cb_pause(ePlayer *player, Evas *e, Evas_Object *o, void *event) {
#ifdef DEBUG
printf("Pause callback entered\n");
#endif
@@ -41,11 +55,11 @@
*
* @param player
* @param e
- * @param obj
- * @param event_info
+ * @param o
+ * @param event
*/
-void cb_track_next(ePlayer *player, Evas *e, Evas_Object *obj,
- void *event_info) {
+void cb_track_next(ePlayer *player, Evas *e, Evas_Object *o,
+ void *event) {
#ifdef DEBUG
printf("DEBUG: Next File Called\n");
#endif
@@ -60,12 +74,21 @@
* but don't start playing yet.
*/
player->playlist->cur_item = player->playlist->items;
- vorbis_open(player); /* refresh track info parts */
+ track_open(player); /* refresh track info parts */
}
}
-void cb_track_prev(ePlayer *player, Evas *e, Evas_Object *obj,
- void *event_info) {
+/**
+ * Moves to the previous track and plays it, except when we're
+ * at the first track already.
+ *
+ * @param player
+ * @param e
+ * @param o
+ * @param event
+ */
+void cb_track_prev(ePlayer *player, Evas *e, Evas_Object *o,
+ void *event) {
#ifdef DEBUG
printf("DEBUG: Previous File Called\n");
#endif
@@ -115,7 +138,7 @@
void cb_time_display_toggle(ePlayer *player, Evas_Object *obj,
const char *emission, const char *src) {
player->cfg.time_display = !player->cfg.time_display;
- vorbis_update_time(player);
+ track_update_time(player);
}
/**
@@ -142,4 +165,35 @@
void cb_playlist_scroll_down(void *udata, Evas_Object *obj,
const char *emission, const char *src) {
playlist_scroll(udata, -1);
+}
+
+void cb_seek_forward(void *udata, Evas_Object *obj,
+ const char *emission, const char *src) {
+ ePlayer *player = udata;
+ PlayListItem *pli = player->playlist->cur_item->data;
+
+#ifdef DEBUG
+ printf("DEBUG: Seeking forward\n");
+#endif
+
+ /* We don't care if you seek past the file, the play loop
+ * will catch EOF and play next file
+ */
+ pli->plugin->set_current_pos(pli->plugin->get_current_pos() + 5);
+}
+
+void cb_seek_backward(void *udata, Evas_Object *obj,
+ const char *emission, const char *src) {
+ ePlayer *player = udata;
+ PlayListItem *pli = player->playlist->cur_item->data;
+ int cur_time = pli->plugin->get_current_pos();
+
+#ifdef DEBUG
+ printf("DEBUG: Seeking backward - Current Pos: %i\n", cur_time);
+#endif
+
+ if (cur_time < 6) /* restart from the beginning */
+ eplayer_playback_start(player, 1);
+ else
+ pli->plugin->set_current_pos(cur_time - 5);
}
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/callbacks.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- callbacks.h 17 Oct 2003 23:46:20 -0000 1.3
+++ callbacks.h 23 Oct 2003 17:01:49 -0000 1.4
@@ -26,5 +26,10 @@
void cb_playlist_scroll_down(void *udata, Evas_Object *obj,
const char *emission, const char *src);
+void cb_seek_forward(void *udata, Evas_Object *obj,
+ const char *emission, const char *src);
+void cb_seek_backward(void *udata, Evas_Object *obj,
+ const char *emission, const char *src);
+
#endif
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/eplayer.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- eplayer.c 22 Oct 2003 18:50:05 -0000 1.9
+++ eplayer.c 23 Oct 2003 17:01:49 -0000 1.10
@@ -5,9 +5,54 @@
#include <Ecore_Evas.h>
#include <Edb.h>
#include <string.h>
+#include <sys/stat.h>
+#include <dirent.h>
#include "eplayer.h"
#include "interface.h"
-#include "vorbis.h"
+#include "track.h"
+
+int is_dir(const char *dir) {
+ struct stat st;
+
+ if (stat(dir, &st))
+ return 0;
+
+ return (S_ISDIR(st.st_mode));
+}
+
+static Evas_List *load_input_plugins() {
+ Evas_List *list = NULL;
+ InputPlugin *ip;
+ DIR *dir;
+ struct dirent *entry;
+ char name[128];
+
+ if (!(dir = opendir(PLUGIN_DIR "/input")))
+ return NULL;
+
+ /* ignore "." and ".." */
+ while ((entry = readdir(dir))
+ && (!strcmp(entry->d_name, ".")
+ || !strcmp(entry->d_name, "..")));
+
+ if (!entry)
+ return NULL;
+
+ /* real entries */
+ do {
+ if (!is_dir(entry->d_name)) {
+ /* get the plugin name from the filename */
+ sscanf(entry->d_name, "lib%[^.].so", name);
+
+ if ((ip = plugin_new(name, PLUGIN_TYPE_INPUT)))
+ list = evas_list_prepend(list, ip);
+ }
+ } while ((entry = readdir(dir)));
+
+ closedir(dir);
+
+ return list;
+}
static void config_init(Config *cfg) {
snprintf(cfg->evas_engine, sizeof(cfg->evas_engine),
@@ -44,15 +89,19 @@
}
static void eplayer_free(ePlayer *player) {
+ Evas_List *l;
+
if (!player)
return;
playlist_free(player->playlist);
- if (player->output) {
- player->output->shutdown();
- output_plugin_free(player->output);
- }
+ /* unload plugins */
+ if (player->output)
+ plugin_free(player->output);
+
+ for (l = player->input_plugins; l; l = l->next)
+ plugin_free(l->data);
free(player);
}
@@ -66,8 +115,6 @@
memset(player, 0, sizeof(ePlayer));
- player->playlist = playlist_new();
-
/* load config */
config_init(&player->cfg);
@@ -86,8 +133,13 @@
}
}
+ player->input_plugins = load_input_plugins();
+
+ player->playlist = playlist_new(player->input_plugins);
+
/* load the output plugin */
- player->output = output_plugin_new(player->cfg.output_plugin);
+ player->output = plugin_new(player->cfg.output_plugin,
+ PLUGIN_TYPE_OUTPUT);
if (!player->output) {
fprintf(stderr, "Cannot load %s output plugin!\n",
@@ -123,8 +175,8 @@
}
if (rewind_track) {
- vorbis_close(player);
- vorbis_open(player);
+ track_close(player);
+ track_open(player);
}
}
@@ -136,19 +188,19 @@
*/
void eplayer_playback_start(ePlayer *player, int rewind_track) {
if (rewind_track) {
- vorbis_close(player);
- vorbis_open(player);
+ track_close(player);
+ track_open(player);
}
/* start the playloop */
- player->play_idler = ecore_idler_add(vorbis_play_chunk, player);
- player->time_timer = ecore_timer_add(0.5, vorbis_update_time,
+ player->play_idler = ecore_idler_add(track_play_chunk, player);
+ player->time_timer = ecore_timer_add(0.5, track_update_time,
player);
}
int main(int argc, const char **argv) {
ePlayer *player;
- int args;
+ int i;
if (!(player = eplayer_new()))
return 1;
@@ -160,12 +212,18 @@
}
/* Parse Args */
- for (args = 1; args < argc; args++) {
+ for (i = 1; i < argc; i++) {
#ifdef DEBUG
- printf("Adding file to playlist: %s\n", argv[args]);
+ printf("Adding file to playlist: %s\n", argv[i]);
#endif
- playlist_load_any(player->playlist, argv[args], args > 1);
+ playlist_load_any(player->playlist, argv[i], i > 1);
+ }
+
+ if (!player->playlist->num) {
+ fprintf(stderr, "No files loaded!\n");
+ eplayer_free(player);
+ return 1;
}
if (!setup_gui(player)) {
@@ -178,7 +236,7 @@
refresh_volume(player);
ecore_timer_add(1.5, refresh_volume, player);
- vorbis_open(player);
+ track_open(player);
refresh_time(player, 0);
#ifdef DEBUG
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/eplayer.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- eplayer.h 22 Oct 2003 18:50:05 -0000 1.7
+++ eplayer.h 23 Oct 2003 17:01:49 -0000 1.8
@@ -2,9 +2,8 @@
#define __EPLAYER_H
#include <Ecore.h>
-#include <vorbis/vorbisfile.h>
#include "playlist.h"
-#include "output_plugin.h"
+#include "plugin.h"
typedef enum {
TIME_DISPLAY_ELAPSED,
@@ -30,8 +29,8 @@
Ecore_Idler *play_idler;
Ecore_Timer *time_timer;
- OggVorbis_File current_track;
OutputPlugin *output;
+ Evas_List *input_plugins; /* lists all available input plugins */
Config cfg;
Gui gui;
@@ -39,6 +38,8 @@
void eplayer_playback_stop(ePlayer *player, int rewind_track);
void eplayer_playback_start(ePlayer *player, int rewind_track);
+
+int is_dir(const char *dir);
#endif
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/interface.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -3 -r1.8 -r1.9
--- interface.c 22 Oct 2003 18:50:05 -0000 1.8
+++ interface.c 23 Oct 2003 17:01:49 -0000 1.9
@@ -4,7 +4,7 @@
#include <Esmart/container.h>
#include <Edje.h>
#include "callbacks.h"
-#include "vorbis.h"
+#include "track.h"
static int app_signal_exit(void *data, int type, void *event) {
#ifdef DEBUG
@@ -130,7 +130,7 @@
for (l = player->playlist->items; l; l = l->next) {
/* get the information we want to display */
- title = ((PlayListItem *) l->data)->title;
+ title = ((PlayListItem *) l->data)->comment[COMMENT_ID_TITLE];
duration = ((PlayListItem *) l->data)->duration;
snprintf(len, sizeof(len), "%i:%02i", duration / 60,
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/playlist.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- playlist.c 21 Oct 2003 17:53:39 -0000 1.5
+++ playlist.c 23 Oct 2003 17:01:49 -0000 1.6
@@ -1,24 +1,10 @@
#include <config.h>
-#include <vorbis/vorbisfile.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
-#include <limits.h>
#include <dirent.h>
#include <ctype.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
#include "playlist.h"
-
-static int is_dir (const char *dir) {
- struct stat st;
-
- if (stat(dir, &st))
- return 0;
-
- return (S_ISDIR(st.st_mode));
-}
+#include "eplayer.h"
/**
* Removes leading and trailing whitespace from a string.
@@ -55,32 +41,31 @@
}
/**
- * Searches a Vorbis comment for title, artist and album and stores
- * them in a PlayListItem.
+ * Fills a PlayListItem's comments/info fields.
*
- * @param pli The PlayListItem to store the comments in
- * @param comment The Vorbis comment to search.
+ * @param pli The PlayListItem to store the comments/info stuff in.
*/
-void playlist_item_read_comments(PlayListItem *pli,
- vorbis_comment *comment) {
-#define NUM_COMMENTS 3
- char *cmt, *key[NUM_COMMENTS] = {"artist=", "title=", "album="};
- char *dest[NUM_COMMENTS] = {pli->artist, pli->title, pli->album};
- int i, j, len[NUM_COMMENTS];
-
- for (i = 0; i < NUM_COMMENTS; i++)
- len[i] = strlen (key[i]);
-
- for (i = 0; i < comment->comments; i++) {
- cmt = comment->user_comments[i];
-
- for (j = 0; j < NUM_COMMENTS; j++)
- if (!strncmp(cmt, key[j], len[j])) {
- snprintf(dest[j], PLAYLIST_ITEM_COMMENT_LEN,
- "%s", &cmt[len[j]]);
- }
- }
-#undef NUM_COMMENTS
+void playlist_item_get_info(PlayListItem *pli) {
+ int i;
+
+ pli->sample_rate = pli->plugin->get_sample_rate();
+ pli->channels = pli->plugin->get_channels();
+ pli->duration = pli->plugin->get_duration();
+ pli->sample_rate = pli->plugin->get_sample_rate();
+
+ for (i = 0; i < COMMENT_ID_NUM; i++)
+ snprintf(pli->comment[i], MAX_COMMENT_LEN, "%s",
+ pli->plugin->get_comment(i));
+}
+
+/**
+ * Frees a PlayListItem object.
+ *
+ * @param pli
+ */
+void playlist_item_free(PlayListItem *pli) {
+ if (pli)
+ free(pli);
}
/**
@@ -89,52 +74,48 @@
* @param file File to load.
* @return The new PlayListItem object.
*/
-PlayListItem *playlist_item_new(const char *file) {
+PlayListItem *playlist_item_new(Evas_List *plugins, const char *file) {
PlayListItem *pli;
- FILE *fp;
- OggVorbis_File vf = {0};
- vorbis_info *info;
+ Evas_List *l;
+ InputPlugin *ip;
- if (!(fp = fopen(file, "rb")) || ov_open(fp, &vf, NULL, 0))
- return NULL;
-
if (!(pli = malloc(sizeof(PlayListItem))))
return NULL;
-
+
memset(pli, 0, sizeof(PlayListItem));
- snprintf(pli->file, sizeof(pli->file), "%s", file);
- /* read the vorbis comments etc */
- playlist_item_read_comments(pli, ov_comment(&vf, -1));
+ /* find the plugin for this file */
+ for (l = plugins; l; l = l->next) {
+ ip = l->data;
+
+ if (ip->open(file)) {
+ pli->plugin = ip;
+ break;
+ }
+ }
+
+ if (!pli->plugin) {
+#ifdef DEBUG
+ printf("No plugin found for %s!\n", file);
+#endif
- /* get bitrate and number of channels */
- info = ov_info(&vf, -1);
- pli->channels = info->channels;
- pli->rate = info->rate;
-
- pli->duration = ov_time_total(&vf, -1);
+ playlist_item_free(pli);
+ return NULL;
+ }
- ov_clear(&vf); /* ov_clear closes the file, too */
+ snprintf(pli->file, sizeof(pli->file), "%s", file);
+ playlist_item_get_info(pli);
return pli;
}
/**
- * Frees a PlayListItem object.
- *
- * @param pli
- */
-void playlist_item_free(PlayListItem *pli) {
- if (pli)
- free(pli);
-}
-
-/**
* Creates a new PlayList object.
*
+ * @param plugins
* @return The newly created PlayList.
*/
-PlayList *playlist_new() {
+PlayList *playlist_new(Evas_List *plugins) {
PlayList *pl;
if (!(pl = malloc(sizeof(PlayList))))
@@ -142,6 +123,8 @@
memset(pl, 0, sizeof(PlayList));
+ pl->plugins = plugins;
+
return pl;
}
@@ -203,7 +186,7 @@
int playlist_load_file(PlayList *pl, const char *file, int append) {
PlayListItem *pli;
- if (!pl || !(pli = playlist_item_new(file)))
+ if (!pl || !(pli = playlist_item_new(pl->plugins, file)))
return 0;
if (!append)
@@ -213,6 +196,8 @@
if (!append)
pl->cur_item = pl->items;
+
+ pl->num++;
return 1;
}
@@ -237,15 +222,20 @@
/* ignore "." and ".." */
while ((entry = readdir(dir))
&& (!strcmp(entry->d_name, ".")
- || strcmp(entry->d_name, "..")));
+ || !strcmp(entry->d_name, "..")));
+
+ if (!entry)
+ return 0;
/* real entries: load directories recursively */
- while ((entry = readdir(dir))) {
+ do {
if (is_dir(entry->d_name))
playlist_load_dir(pl, entry->d_name, 1);
- else if ((pli = playlist_item_new(entry->d_name)))
+ else if ((pli = playlist_item_new(pl->plugins, entry->d_name))) {
tmp = evas_list_prepend(tmp, pli);
- }
+ pl->num++;
+ }
+ } while ((entry = readdir(dir)));
closedir(dir);
@@ -284,15 +274,16 @@
ptr = strrchr(dir, '/');
*ptr = 0;
- while (fgets (buf, sizeof (buf), fp)) {
+ while (fgets(buf, sizeof (buf), fp)) {
if (!(ptr = strstrip(buf)) || !*ptr || *ptr == '#')
continue;
- else if (*ptr != '/') { /* if it's a relative path, prepend the
directory */
+ else if (*ptr != '/') {
+ /* if it's a relative path, prepend the directory */
snprintf(path, sizeof(path), "%s/%s", dir, buf);
ptr = path;
}
- if ((pli = playlist_item_new(ptr))) {
+ if ((pli = playlist_item_new(pl->plugins, ptr))) {
tmp = evas_list_prepend(tmp, pli);
pl->num++;
}
@@ -315,7 +306,7 @@
}
/**
- * Add a M3U file, an Ogg file or a directory to a PlayList.
+ * Add a M3U file, a media file or a directory to a PlayList.
*
* @param pl
* @param path
@@ -328,13 +319,11 @@
if (is_dir(path))
return playlist_load_dir(pl, path, append);
- /* FIXME we check for m3u or ogg using the suffix :/ */
+ /* FIXME we check for m3u using the suffix :/ */
ptr = (char *) &path[strlen(path) - 3];
- if (!strcasecmp(ptr, "ogg"))
- return playlist_load_file(pl, path, append);
- else if (!strcasecmp(ptr, "m3u"))
+ if (!strcasecmp(ptr, "m3u"))
return playlist_load_m3u(pl, path, append);
else
- return 0;
+ return playlist_load_file(pl, path, append);
}
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/playlist.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- playlist.h 21 Oct 2003 17:53:39 -0000 1.3
+++ playlist.h 23 Oct 2003 17:01:49 -0000 1.4
@@ -3,33 +3,33 @@
#include <Evas.h>
#include <limits.h>
+#include "plugin.h"
#ifdef __cplusplus
extern "C" {
#endif
-#define PLAYLIST_ITEM_COMMENT_LEN 256
-
typedef struct {
char file[PATH_MAX + 1];
- /* vorbis comments: */
- char artist[PLAYLIST_ITEM_COMMENT_LEN];
- char title[PLAYLIST_ITEM_COMMENT_LEN];
- char album[PLAYLIST_ITEM_COMMENT_LEN];
- int duration;
+ char comment[COMMENT_ID_NUM][MAX_COMMENT_LEN];
+ int duration;
int channels; /* number of channels */
- long rate; /* bitrate */
+ long sample_rate; /* sample rate */
+
+ InputPlugin *plugin; /* plugin that's used for this item */
} PlayListItem;
typedef struct {
int num; /* number of entries */
Evas_List *items;
Evas_List *cur_item;
+
+ Evas_List *plugins; /* lists all available plugins */
} PlayList;
-PlayList *playlist_new();
+PlayList *playlist_new(Evas_List *plugins);
void playlist_free();
int playlist_load_file(PlayList *pl, const char *file, int append);
-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community? Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs