Enlightenment CVS committal

Author  : tsauerbeck
Project : misc
Module  : eplayer

Dir     : misc/eplayer/src


Modified Files:
        .cvsignore Makefile.am callbacks.c eplayer.c eplayer.h 
        interface.c interface.h playlist.c playlist.h vorbis.c 
        vorbis.h 
Added Files:
        output_plugin.c output_plugin.h 
Removed Files:
        mixer.c mixer.h 


Log Message:
Replaced libao by our own plugin system. At the moment, there's only an OSS plugin, 
ALSA will probably follow soon. See ChangeLog for details ;)
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/.cvsignore,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -3 -r1.1 -r1.2
--- .cvsignore  16 Oct 2003 14:54:33 -0000      1.1
+++ .cvsignore  21 Oct 2003 17:53:38 -0000      1.2
@@ -1,4 +1,5 @@
 .deps
+.libs
 Makefile
 Makefile.in
 eplayer
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- Makefile.am 16 Oct 2003 17:25:40 -0000      1.5
+++ Makefile.am 21 Oct 2003 17:53:38 -0000      1.6
@@ -1,5 +1,8 @@
-AM_CFLAGS = @AO_CFLAGS@ \
-       @ECORE_CFLAGS@ @EVAS_CFLAGS@ @EDJE_CFLAGS@ @ESMART_CFLAGS@
+# $Id: Makefile.am,v 1.6 2003/10/21 17:53:38 tsauerbeck Exp $
+
+SUBDIRS = output
+
+AM_CFLAGS = @ECORE_CFLAGS@ @EVAS_CFLAGS@ @EDJE_CFLAGS@ @ESMART_CFLAGS@
 
 bin_PROGRAMS = eplayer
 
@@ -8,7 +11,7 @@
        callbacks.c callbacks.h \
        vorbis.c vorbis.h \
        playlist.c playlist.h \
-       mixer.c mixer.h
+       output_plugin.c output_plugin.h
 
-eplayer_LDADD = -lvorbis -lvorbisfile @AO_LIBS@ \
+eplayer_LDADD = @DL_LIBS@ @VORBIS_LIBS@ \
        @ECORE_LIBS@ @EVAS_LIBS@ @EDJE_LIBS@ @ESMART_LIBS@
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/callbacks.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- callbacks.c 18 Oct 2003 15:24:30 -0000      1.6
+++ callbacks.c 21 Oct 2003 17:53:38 -0000      1.7
@@ -2,7 +2,6 @@
 #include <Edje.h>
 #include <Esmart/container.h>
 #include "eplayer.h"
-#include "mixer.h"
 #include "vorbis.h"
 #include "interface.h"
 
@@ -61,7 +60,7 @@
                 * but don't start playing yet.
                 */
                player->playlist->cur_item = player->playlist->items;
-               track_open(player); /* refresh track info parts */
+               vorbis_open(player); /* refresh track info parts */
        }
 }
 
@@ -85,28 +84,38 @@
 
 void cb_volume_raise(ePlayer *player, Evas_Object *obj,
                      const char *emission, const char *src) {
+       int left = 0, right = 0;
+       
 #ifdef DEBUG
        printf("DEBUG: Raising volume\n");
 #endif
 
-       mixer_change(player->mixer, 5);
-       refresh_volume(player, 0);
+       if (!player->output->volume_get(&left, &right))
+               return;
+       
+       player->output->volume_set(left + 5, right + 5);
+       refresh_volume(player);
 }
 
 void cb_volume_lower(ePlayer *player, Evas_Object *obj,
                      const char *emission, const char *src) {
+       int left = 0, right = 0;
+       
 #ifdef DEBUG
        printf("DEBUG: Lowering volume\n");
 #endif
        
-       mixer_change(player->mixer, -5);
-       refresh_volume(player, 0);
+       if (!player->output->volume_get(&left, &right))
+               return;
+       
+       player->output->volume_set(left - 5, right - 5);
+       refresh_volume(player);
 }
 
 void cb_time_display_toggle(ePlayer *player, Evas_Object *obj,
                             const char *emission, const char *src) {
        player->time_display = !player->time_display;
-       update_time(player);
+       vorbis_update_time(player);
 }
 
 /**
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/eplayer.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- eplayer.c   17 Oct 2003 23:46:20 -0000      1.7
+++ eplayer.c   21 Oct 2003 17:53:38 -0000      1.8
@@ -12,16 +12,14 @@
                return;
 
        playlist_free(player->playlist);
-       mixer_free(player->mixer);
-       ao_shutdown();
+       output_plugin_free(player->output);
        
        free(player);
 }
 
 static ePlayer *eplayer_new() {
        ePlayer *player;
-       int driver;
-       ao_info *driver_info;
+       const char *plugin = PLUGIN_DIR"/output/libOSS.so";
 
        if (!(player = malloc(sizeof(ePlayer))))
                return NULL;
@@ -30,24 +28,14 @@
 
        player->playlist = playlist_new();
 
-       /* FIXME: the user should be able to choose which control
-        * will be used
-        */
-       player->mixer = mixer_new(MIXER_CONTROL_VOL);
+       /* load the output plugin */
+       player->output = output_plugin_new(plugin);
 
-       ao_initialize();
-
-       if ((driver = ao_default_driver_id()) == -1) {
-               fprintf(stderr, "AO: Can't get default driver!\n");
+       if (!player->output) {
+               fprintf(stderr, "Cannot load output plugin %s!\n", plugin);
                eplayer_free(player);
                return NULL;
        }
-       
-       driver_info = ao_driver_info(driver);
-
-#ifdef DEBUG
-       printf("AO DEBUG: Audio Device: %s\n", driver_info->name);
-#endif
 
        return player;
 }
@@ -75,8 +63,8 @@
        }
 
        if (rewind_track) {
-               track_close(player);
-               track_open(player);
+               vorbis_close(player);
+               vorbis_open(player);
        }
 }
 
@@ -88,19 +76,14 @@
  */
 void eplayer_playback_start(ePlayer *player, int rewind_track) {
        if (rewind_track) {
-               track_close(player);
-               track_open(player);
+               vorbis_close(player);
+               vorbis_open(player);
        }
 
        /* start the playloop */
-       player->play_idler = ecore_idler_add(track_play_chunk, player);
-       player->time_timer = ecore_timer_add(0.5, update_time, player);
-}
-
-static int read_mixer(void *udata) {
-       refresh_volume(udata, 1);
-
-       return 1;
+       player->play_idler = ecore_idler_add(vorbis_play_chunk, player);
+       player->time_timer = ecore_timer_add(0.5, vorbis_update_time,
+                                            player);
 }
 
 int main(int argc, const char **argv) {
@@ -127,13 +110,17 @@
                playlist_load_any(player->playlist, argv[args], args > 1);
        }
        
-       setup_ecore(player);
+       if (!setup_gui(player)) {
+               eplayer_free(player);
+               return 1;
+       }
+               
        show_playlist(player);
 
-       read_mixer(player);
-       ecore_timer_add(1.5, read_mixer, player);
+       refresh_volume(player);
+       ecore_timer_add(1.5, refresh_volume, player);
 
-       track_open(player);
+       vorbis_open(player);
        refresh_time(player, 0);
 
 #ifdef DEBUG
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/eplayer.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- eplayer.h   17 Oct 2003 23:46:20 -0000      1.5
+++ eplayer.h   21 Oct 2003 17:53:39 -0000      1.6
@@ -3,9 +3,8 @@
 
 #include <Ecore.h>
 #include <vorbis/vorbisfile.h>
-#include <ao/ao.h>
 #include "playlist.h"
-#include "mixer.h"
+#include "output_plugin.h"
 
 typedef enum {
        TIME_DISPLAY_ELAPSED,
@@ -14,7 +13,6 @@
 
 typedef struct {
        PlayList *playlist;
-       Mixer *mixer;
        Ecore_Idler *play_idler;
        Ecore_Timer *time_timer;
        
@@ -29,7 +27,7 @@
        TimeDisplay time_display;
 
        OggVorbis_File current_track;
-       ao_device *ao_dev;
+       OutputPlugin *output;
 } ePlayer;
 
 void eplayer_playback_stop(ePlayer *player, int rewind_track);
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/interface.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- interface.c 17 Oct 2003 23:46:20 -0000      1.6
+++ interface.c 21 Oct 2003 17:53:39 -0000      1.7
@@ -4,14 +4,8 @@
 #include <Esmart/container.h>
 #include <Edje.h>
 #include "callbacks.h"
-#include "mixer.h"
 #include "vorbis.h"
 
-#define        WIDTH 500
-#define        HEIGHT 500
-
-static Ecore_Evas *ee = NULL;
-
 static int app_signal_exit(void *data, int type, void *event) {
 #ifdef DEBUG
        printf("DEBUG: Exit called, shutting down\n");
@@ -21,7 +15,8 @@
        return 1;
 }
 
-void setup_ecore(ePlayer *player) {
+int setup_gui(ePlayer *player) {
+       Ecore_Evas *ee;
        double edje_w = 0, edje_h = 0;
 
 #ifdef DEBUG
@@ -32,7 +27,7 @@
        ecore_evas_init();
        ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, app_signal_exit, NULL);
 
-       ee = ecore_evas_software_x11_new(NULL, 0,  0, 0, WIDTH, HEIGHT);
+       ee = ecore_evas_software_x11_new(NULL, 0,  0, 0, 500, 500);
        ecore_evas_title_set(ee, "eVorbisPlayer");
        ecore_evas_name_class_set(ee, "ecore_test", "test_evas");
        ecore_evas_borderless_set(ee, 1);
@@ -48,8 +43,13 @@
 #endif
 
        player->gui.edje = edje_object_add(player->gui.evas);
-       edje_object_file_set(player->gui.edje,
-                            DATA_DIR"/themes/eplayer.eet", "eplayer");
+       
+       if (!(edje_object_file_set(player->gui.edje,
+                            DATA_DIR"/themes/eplayer.eet", "eplayer"))) {
+               fprintf(stderr, "Cannot load theme!\n");
+               return 0;
+       }
+       
        evas_object_move(player->gui.edje, 0, 0);
        edje_object_size_min_get(player->gui.edje, &edje_w, &edje_h);
        evas_object_resize(player->gui.edje, edje_w, edje_h);
@@ -96,6 +96,8 @@
        edje_object_signal_callback_add(player->gui.edje,
                                        "SWITCH_TIME_DISPLAY", "time_text",
                                        cb_time_display_toggle, player);
+
+       return 1;
 }
 
 static Evas_Object *playlist_column_add(ePlayer *player,
@@ -125,7 +127,7 @@
                title = ((PlayListItem *) l->data)->title;
                duration = ((PlayListItem *) l->data)->duration;
                
-               snprintf(len, sizeof(len), "%i:%02i", (duration / 60),
+               snprintf(len, sizeof(len), "%i:%02i", duration / 60,
                         duration % 60);
                
                /* add the title/length items to the container */
@@ -180,14 +182,18 @@
                                        cb_playlist_scroll_up, player);
 }
 
-void refresh_volume(ePlayer *player, int read) {
+int refresh_volume(void *udata) {
+       ePlayer *player = udata;
        char buf[8];
+       int left = 0, right = 0;
 
-       if (read)
-               mixer_read(player->mixer);
+       if (!player->output->volume_get(&left, &right))
+               return 1;
        
-       snprintf(buf, sizeof(buf), "%i", player->mixer->volume);
+       snprintf(buf, sizeof(buf), "%i", (left + right) / 2);
        edje_object_part_text_set(player->gui.edje, "vol_display_text", buf);
+       
+       return 1;
 }
 
 int refresh_time(ePlayer *player, int time) {
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/interface.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- interface.h 17 Oct 2003 17:00:29 -0000      1.2
+++ interface.h 21 Oct 2003 17:53:39 -0000      1.3
@@ -4,9 +4,9 @@
 #include "eplayer.h"
 
 void show_playlist(ePlayer *player);
-void setup_ecore(ePlayer *player);
+int setup_gui(ePlayer *player);
 
-void refresh_volume(ePlayer *player, int read);
+int refresh_volume(void *udata);
 int refresh_time(ePlayer *player, int time);
 
 #endif
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/playlist.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- playlist.c  17 Oct 2003 17:00:30 -0000      1.4
+++ playlist.c  21 Oct 2003 17:53:39 -0000      1.5
@@ -74,11 +74,10 @@
        for (i = 0; i < comment->comments; i++) {
                cmt = comment->user_comments[i];
 
-               for (j = 0; j < NUM_COMMENTS; j++) {
+               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
@@ -199,6 +198,7 @@
  * @param pl
  * @param file File to add
  * @param append If 0, the old entries will be overwritten.
+ * @return Boolean success or failure.
  */
 int playlist_load_file(PlayList *pl, const char *file, int append) {
        PlayListItem *pli;
@@ -223,6 +223,7 @@
  * @param pl
  * @param path Directory to load
  * @param append If 0, the old entries will be overwritten.
+ * @return Boolean success or failure.
  */
 int playlist_load_dir(PlayList *pl, const char *path, int append) {
        PlayListItem *pli = NULL;
@@ -267,6 +268,7 @@
  * @param pl
  * @param file
  * @param append If 0, the old entries will be overwritten.
+ * @return Boolean success or failure.
  */
 int playlist_load_m3u(PlayList *pl, const char *file, int append) {
        PlayListItem *pli = NULL;
@@ -318,6 +320,7 @@
  * @param pl
  * @param path
  * @param append If 0, the old entries will be overwritten.
+ * @return Boolean success or failure.
  */
 int playlist_load_any(PlayList *pl, const char *path, int append) {
        char *ptr = NULL;
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/playlist.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- playlist.h  16 Oct 2003 14:54:33 -0000      1.2
+++ playlist.h  21 Oct 2003 17:53:39 -0000      1.3
@@ -17,7 +17,7 @@
        char artist[PLAYLIST_ITEM_COMMENT_LEN];
        char title[PLAYLIST_ITEM_COMMENT_LEN];
        char album[PLAYLIST_ITEM_COMMENT_LEN];
-       double duration;
+       int duration;
 
        int channels; /* number of channels */
        long rate; /* bitrate */
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/vorbis.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- vorbis.c    18 Oct 2003 15:24:30 -0000      1.9
+++ vorbis.c    21 Oct 2003 17:53:39 -0000      1.10
@@ -12,7 +12,7 @@
  *
  * @param udata Pointer to an ePlayer struct.
  */
-int track_play_chunk(void *udata) {
+int vorbis_play_chunk(void *udata) {
        ePlayer *player = udata;
        long bytes_read;
        int big_endian = 0;
@@ -25,12 +25,12 @@
        /* read the data ... */
        bytes_read = ov_read(&player->current_track, pcmout, sizeof(pcmout),
                             big_endian, 2, 1, NULL);
-
-    if (bytes_read) /* ... and play it */
-               ao_play(player->ao_dev, pcmout, bytes_read);
+       
+       if (bytes_read) /* ...and play it */
+               player->output->play(pcmout, bytes_read);
        else /* EOF -> move to the next track */
                edje_object_signal_emit(player->gui.edje,
-                                   "PLAY_NEXT", "next_button");
+                                       "PLAY_NEXT", "next_button");
 
        /* the edje callback will re-add the idler, so we can remove it here,
         * in case ov_read() failed
@@ -38,15 +38,16 @@
        return !!bytes_read;
 }
 
-int update_time(void *udata) {
+int vorbis_update_time(void *udata) {
        ePlayer *player = udata;
+       PlayListItem *current_item = player->playlist->cur_item->data;
        static int old_time = -1;
        int cur_time;
 
        cur_time = ov_time_tell(&player->current_track);
        
        if (player->time_display == TIME_DISPLAY_LEFT)
-               cur_time = ov_time_total(&player->current_track, -1) - cur_time;
+               cur_time = current_item->duration - cur_time;
 
        if (cur_time == old_time) /* value didn't change, so don't update */
                return 1;
@@ -57,26 +58,17 @@
        return 1;
 }
 
-static int setup_ao(ePlayer *player) {
+static int prepare_output(ePlayer *player) {
        PlayListItem *current = player->playlist->cur_item->data;
-       ao_sample_format format = {0};
-       
-       format.bits = 16;
-       format.channels = current->channels;
-       format.rate = current->rate;
-       format.byte_format = AO_FMT_NATIVE;
-
-#ifdef DEBUG
-       printf("AO DEBUG: %d Channels at %d Hz, in %d bit words\n",
-              format.channels, format.rate, format.bits);
-#endif
-       
-       player->ao_dev = ao_open_live(ao_default_driver_id(), &format, NULL);
+       int bigendian = 0;
 
-       if (!player->ao_dev)
-               fprintf(stderr, "Error opening device.\n");
+#ifdef WORDS_BIGENDIAN
+       bigendian = 1;
+#endif
 
-       return !!player->ao_dev;
+       return player->output->configure(current->channels,
+                                        current->rate,
+                                        16, bigendian);
 }
 
 /**
@@ -84,17 +76,16 @@
  *
  * @param player
  */
-void track_close(ePlayer *player) {
-       ao_close(player->ao_dev);
+void vorbis_close(ePlayer *player) {
        ov_clear(&player->current_track);
 }
 
 /**
- * Opens the current track and prepares libao for playing.
+ * Opens the current track and configured the output plugin for playback.
  *
  * @param player
  */
-void track_open(ePlayer *player) {
+void vorbis_open(ePlayer *player) {
        PlayListItem *pli;
        FILE *fp;
 
@@ -112,7 +103,13 @@
        edje_object_part_text_set(player->gui.edje, "album_name", pli->album);
        edje_object_part_text_set(player->gui.edje, "time_text", "0:00");
 
-       setup_ao(player);
+       if (!prepare_output(player)) {
+               fprintf(stderr, "Cannot configure output plugin\n");
+       
+               /* move to the next track */
+               edje_object_signal_emit(player->gui.edje,
+                                       "PLAY_NEXT", "next_button");
+       }
 }
 
 void cb_seek_forward(void *udata, Evas_Object *obj,
===================================================================
RCS file: /cvsroot/enlightenment/misc/eplayer/src/vorbis.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- vorbis.h    17 Oct 2003 17:00:31 -0000      1.2
+++ vorbis.h    21 Oct 2003 17:53:39 -0000      1.3
@@ -3,11 +3,11 @@
 
 #include "eplayer.h"
 
-int track_play_chunk(void *udata);
-int update_time(void *udata);
+int vorbis_play_chunk(void *udata);
+int vorbis_update_time(void *udata);
 
-void track_open(ePlayer *player);
-void track_close(ePlayer *player);
+void vorbis_open(ePlayer *player);
+void vorbis_close(ePlayer *player);
 
 void cb_seek_forward(void *udata, Evas_Object *obj,
                      const char *emission, const char *src);




-------------------------------------------------------
This SF.net email is sponsored by OSDN developer relations
Here's your chance to show off your extensive product knowledge
We want to know what you know. Tell us and you have a chance to win $100
http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to