r2826 - in trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2: . src
abraxa at sita.openmoko.org
abraxa at sita.openmoko.org
Fri Aug 24 03:11:54 CEST 2007
Author: abraxa
Date: 2007-08-24 03:11:46 +0200 (Fri, 24 Aug 2007)
New Revision: 2826
Added:
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/omp_spiff_c.cpp
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/omp_spiff_c.h
Modified:
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/configure.ac
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/Makefile.am
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/editor_page.c
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main.c
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main_page.c
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main_page.h
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/persistent.c
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/persistent.h
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playback.c
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist.c
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist.h
trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist_page.c
Log:
Added custom libSpiff C binding for better XSPF support
Fixed notices from -pedantic
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/configure.ac
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/configure.ac 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/configure.ac 2007-08-24 01:11:46 UTC (rev 2826)
@@ -7,12 +7,19 @@
AC_ISC_POSIX
AC_PROG_CC
+AC_PROG_CXX
AC_STDC_HEADERS
AC_PROG_LIBTOOL
AM_GNU_GETTEXT
AM_GNU_GETTEXT_VERSION([0.12.1])
+
+CFLAGS="-I${prefix}/include $CFLAGS"
+AC_SUBST(CFLAGS)
+CPPFLAGS="-I${prefix}/include $CPPFLAGS"
+AC_SUBST(CPPFLAGS)
+
# Check for GTK/GLib/GThread/Pango, dbus, OpenMoko libs, gstreamer, expat, uriparser and XSPF
PKG_CHECK_MODULES(GTK, [glib-2.0 >= 2.4.0 gtk+-2.0 >= 2.4.0 gthread-2.0 pango],,
@@ -28,7 +35,6 @@
AC_MSG_ERROR([*** Cannot find gstreamer ***]))
LIBS="-lexpat -L${prefix}/lib $LIBS"
-CFLAGS="-I${prefix}/include"
AC_CHECK_LIB(expat, XML_Parse, [], [echo "Error: libexpat not found"; exit -1])
LIBS="-luriparser $LIBS"
@@ -51,7 +57,6 @@
OMP_DEFINES="-DDATA_DIR=\\\"$datadir/openmoko-mediaplayer\\\" -DLOCALEDIR=\\\"$localedir\\\""
AC_SUBST(OMP_DEFINES)
-
AC_CONFIG_FILES([
Makefile
src/Makefile
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/Makefile.am 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/Makefile.am 2007-08-24 01:11:46 UTC (rev 2826)
@@ -1,9 +1,4 @@
-AM_CPPFLAGS = -DDATADIR=\"$(datadir)\" \
- -DPKGDATADIR=\"$(pkgdatadir)\"
-#AM_CFLAGS = -Wall -pedantic -std=c99 @OPENMOKO_CFLAGS@
-AM_CFLAGS = -Wall -pedantic -std=c99
-
bin_PROGRAMS = openmoko-mediaplayer
openmoko_mediaplayer_LDADD = \
@@ -16,11 +11,10 @@
$(DBUS_CFLAGS) \
$(OPENMOKO_CFLAGS) \
$(OMP_DEFINES) \
- -I$(top_srcdir) \
- -I$(top_srcdir)/intl\
- -g -DDEBUG
+ -I${top_srcdir}/intl -Wall -pedantic -std=c99
-INCLUDES = $(openmoko_mediaplayer_CFLAGS)
+openmoko_mediaplayer_CPPFLAGS = \
+ -Wall -pedantic
openmoko_mediaplayer_SOURCES = \
main.c main.h \
@@ -31,4 +25,6 @@
main_page.c main_page.h \
playlist_page.c playlist_page.h \
editor_page.c editor_page.h \
- files_page.c files_page.h
+ files_page.c files_page.h \
+ \
+ omp_spiff_c.cpp omp_spiff_c.h
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/editor_page.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/editor_page.c 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/editor_page.c 2007-08-24 01:11:46 UTC (rev 2826)
@@ -72,32 +72,32 @@
* Updates a track's title and duration upon arrival of metadata
*/
void
-omp_editor_page_update_track_info(gpointer instance, guint track_id, gpointer user_data)
+omp_editor_page_update_track_info(gpointer instance, gpointer track_infos, gpointer user_data)
{
- guint duration;
+/* omp_track_infos *infos;
gchar *track_title, *track_duration, *path;
GtkTreeIter tree_iter;
- omp_playlist_get_track_info(track_id, &track_title, &duration);
+ infos = (omp_track_infos*)track_infos;
- if (duration > 0)
+ if (infos->duration > 0)
{
track_duration = g_strdup_printf(OMP_WIDGET_CAPTION_EDITOR_TRACK_TIME,
- duration / 60000, (duration/1000) % 60);
+ infos->duration / 60000, (infos->duration/1000) % 60);
} else {
track_duration = NULL;
}
- path = g_strdup_printf("%d", track_id);
+ path = g_strdup_printf("%d", infos->id);
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(omp_editor_page_list_store),
&tree_iter, path);
-
+
gtk_list_store_set(omp_editor_page_list_store, &tree_iter,
- TITLE_COLUMN, track_title,
+ TITLE_COLUMN, infos->title,
DURATION_COLUMN, track_duration, -1);
g_free(path);
- g_free(track_duration);
+ g_free(track_duration); */
}
/**
@@ -115,7 +115,7 @@
gboolean
omp_editor_page_list_clicked(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
{
-
+ return TRUE;
}
/**
@@ -127,7 +127,7 @@
GtkTreeIter tree_iter;
guint track_num, duration;
gchar *track_title, *track_duration;
- struct playlist_iter *pl_iter;
+ omp_playlist_iter *pl_iter;
gtk_list_store_clear(omp_editor_page_list_store);
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main.c 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main.c 2007-08-24 01:11:46 UTC (rev 2826)
@@ -34,9 +34,9 @@
#include <gdk/gdk.h>
#include <stdlib.h>
-
#include <errno.h>
#include <fcntl.h>
+#include <unistd.h>
#include <signal.h>
#define DBUS_API_SUBJECT_TO_CHANGE
@@ -62,7 +62,7 @@
//define DEBUG_MEM_PROFILE
// Forces the window to the native size of the Neo1973's screen area if enabled
-#define EMULATE_SIZE
+//define EMULATE_SIZE
// The padding applied to the page handle's contents
#define NOTEBOOK_PAGE_PADDING 6
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main_page.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main_page.c 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main_page.c 2007-08-24 01:11:46 UTC (rev 2826)
@@ -184,6 +184,8 @@
// Prevent UI callbacks from messing with the slider position
omp_main_time_slider_can_update = FALSE;
+
+ return TRUE;
}
/**
@@ -199,6 +201,8 @@
// Notify the slider change callback that this time we indeed want to change position
omp_main_time_slider_was_dragged = TRUE;
+
+ return TRUE;
}
/**
@@ -333,7 +337,7 @@
GtkWidget *mainvbox;
GtkWidget *upper_hbox, *middle_hbox, *lower_hbox;
GtkWidget *middle_right_vbox;
- GtkWidget *image, *button;
+ GtkWidget *button;
gchar *image_file_name, *caption;
gint i;
@@ -496,7 +500,7 @@
{
GtkWidget *alignment;
GtkWidget *mainvbox;
- GtkWidget *vbox, *hbox, *vol_vbox, *bal_hbox;
+ GtkWidget *hbox;
GtkWidget *image, *button, *vol_scale;
// Add mainvbox to destination container
@@ -666,8 +670,8 @@
// Update label and slider
text = g_strdup_printf(OMP_WIDGET_CAPTION_TRACK_TIME,
- track_position / 60000, (track_position/1000) % 60,
- track_length / 60000, (track_length/1000) % 60);
+ (guint)(track_position / 60000), (guint)(track_position/1000) % 60,
+ (guint)(track_length / 60000), (guint)(track_length/1000) % 60);
gtk_label_set_text(GTK_LABEL(main_widgets.time_label), text);
g_free(text);
@@ -706,7 +710,7 @@
void
omp_main_update_repeat_mode(gpointer instance, guint mode, gpointer user_data)
{
- gchar *image_file_name;
+ gchar *image_file_name = NULL;
switch (mode)
{
@@ -770,8 +774,8 @@
// Update UI
text = g_strdup_printf(OMP_WIDGET_CAPTION_TRACK_TIME,
- track_position / 60000, (track_position/1000) % 60,
- track_length / 60000, (track_length/1000) % 60);
+ (guint)(track_position / 60000), (guint)(track_position/1000) % 60,
+ (guint)track_length / 60000, (guint)(track_length/1000) % 60);
gtk_label_set_text(GTK_LABEL(main_widgets.time_label), text);
g_free(text);
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main_page.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main_page.h 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/main_page.h 2007-08-24 01:11:46 UTC (rev 2826)
@@ -29,9 +29,9 @@
#include <gtk/gtk.h>
-#define OMP_WIDGET_CAPTION_TRACK_TIME "%d:%.2d / %d:%.2d"
-#define OMP_WIDGET_CAPTION_TRACK_NUM "%.3d / %.3d"
-#define OMP_WIDGET_CAPTION_VOLUME "%d%%"
+#define OMP_WIDGET_CAPTION_TRACK_TIME "%u:%.2u / %u:%.2u"
+#define OMP_WIDGET_CAPTION_TRACK_NUM "%.3u / %.3u"
+#define OMP_WIDGET_CAPTION_VOLUME "%u%%"
// Determines how many milliseconds the engine will seek if the FFWD/REW buttons are clicked
#define BUTTON_SEEK_DISTANCE 10000
Added: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/omp_spiff_c.cpp
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/omp_spiff_c.cpp 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/omp_spiff_c.cpp 2007-08-24 01:11:46 UTC (rev 2826)
@@ -0,0 +1,362 @@
+/*
+ * omp_spiff_c - Enhanced C interface for libSpiff
+ *
+ * Copyright (C) 2007, Ed Schouten / Xiph.Org Foundation
+ * All rights reserved.
+ *
+ * Modified by Soeren Apel (abraxa) for OpenMoko to include XSPF
+ * features not found in the simple C bindings
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * * Neither the name of the Xiph.Org Foundation nor the names of
+ * its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Ed Schouten <ed at fxq.nl>
+ */
+
+/**
+ * @file omp_spiff_c.cpp
+ * Enhanced libSpiff C bindings
+ */
+
+#include <spiff/SpiffIndentFormatter.h>
+#include <spiff/SpiffProps.h>
+#include <spiff/SpiffPropsWriter.h>
+#include <spiff/SpiffReader.h>
+#include <spiff/SpiffReaderCallback.h>
+#include <spiff/SpiffTrack.h>
+#include <spiff/SpiffTrackWriter.h>
+#include <spiff/SpiffWriter.h>
+
+extern "C"
+{
+ #include "omp_spiff_c.h"
+}
+
+/*****************************************************************************/
+/*** Private C++ interface ***/
+/*****************************************************************************/
+
+using namespace Spiff;
+
+/// Spiff list reading callback that stores data in a specific C-style Spiff list
+class SpiffCReaderCallback : public SpiffReaderCallback
+{
+ private:
+ /// The C-style Spiff list the tracks should be appended to
+ omp_spiff_list *list;
+
+ /// Pointer to the `next' field in the last inserted item for improving append speed
+ omp_spiff_track **newtrack;
+
+ /// Callback which adds tracks to the list
+ void addTrack(SpiffTrack *track);
+
+ /// Callback which sets properties in the list
+ void setProps(SpiffProps *props);
+
+ public:
+ /// Creates the callback interface for filling an omp_spiff_list
+ SpiffCReaderCallback(omp_spiff_list *list);
+
+ /// Finalize the list
+ virtual ~SpiffCReaderCallback();
+};
+
+SpiffCReaderCallback::SpiffCReaderCallback(omp_spiff_list *list)
+{
+ this->list = list;
+ newtrack = &list->tracks;
+}
+
+SpiffCReaderCallback::~SpiffCReaderCallback()
+{
+ // Null-terminate the tracks list
+ *newtrack = NULL;
+}
+
+void
+SpiffCReaderCallback::addTrack(SpiffTrack *track)
+{
+ omp_spiff_mvalue **newmv;
+ char *str;
+
+ // Append new item to the track list
+ *newtrack = new omp_spiff_track;
+
+ (*newtrack)->title = track->stealTitle();
+ (*newtrack)->album = track->stealAlbum();
+ (*newtrack)->duration = track->getDuration();
+ (*newtrack)->tracknum = track->getTrackNum();
+
+ // Locations
+ newmv = &(*newtrack)->locations;
+ while ((str = track->stealFirstLocation()) != NULL) {
+ *newmv = new omp_spiff_mvalue;
+ (*newmv)->value = str;
+
+ // On to the next location
+ newmv = &(*newmv)->next;
+ }
+ *newmv = NULL;
+
+ // Identifiers
+ newmv = &(*newtrack)->identifiers;
+ while ((str = track->stealFirstIdentifier()) != NULL) {
+ *newmv = new omp_spiff_mvalue;
+ (*newmv)->value = str;
+
+ // On to the next location
+ newmv = &(*newmv)->next;
+ }
+ *newmv = NULL;
+
+ // Clean up and move to the next track
+ delete track;
+ newtrack = &(*newtrack)->next;
+}
+
+void
+SpiffCReaderCallback::setProps(SpiffProps *props)
+{
+ list->license = props->stealLicense();
+ list->location = props->stealLocation();
+ list->identifier = props->stealIdentifier();
+
+ delete props;
+}
+
+/*****************************************************************************/
+/*** Private C functions ***/
+/*****************************************************************************/
+
+/**
+ * Deallocates all objects in an omp_spiff_mvalue linked list
+ */
+static void
+omp_spiff_mvalue_free(omp_spiff_mvalue *mv)
+{
+ omp_spiff_mvalue *nmv;
+
+ for (; mv != NULL; mv = nmv) {
+ // Back-up pointer
+ nmv = mv->next;
+ delete mv->value;
+ delete mv;
+ }
+}
+
+/*****************************************************************************/
+/*** Public C interface ***/
+/*****************************************************************************/
+
+/**
+ * Parses an XSPF file by filename
+ */
+extern "C" omp_spiff_list *
+omp_spiff_parse(const char *filename)
+{
+ SpiffReader read;
+ omp_spiff_list *ret;
+
+ // Allocate empty playlist
+ ret = new omp_spiff_list;
+
+ // Fill the list with parser results
+ SpiffCReaderCallback readcb(ret);
+
+ if (read.parseFile(filename, &readcb) == SPIFF_READER_SUCCESS)
+ {
+ return ret;
+
+ } else {
+
+ delete ret;
+ return NULL;
+ }
+}
+
+/**
+ * Creates a new empty XSPF playlist
+ */
+extern "C" omp_spiff_list *
+omp_spiff_new(void)
+{
+ omp_spiff_list *ret;
+
+ ret = new omp_spiff_list;
+
+ ret->license = NULL;
+ ret->location = NULL;
+ ret->identifier = NULL;
+ ret->tracks = NULL;
+
+ return ret;
+}
+
+/**
+ * Frees the parser results
+ */
+extern "C" void
+omp_spiff_free(omp_spiff_list *list)
+{
+ omp_spiff_track *tr, *ntr;
+
+ delete list->license;
+ delete list->location;
+ delete list->identifier;
+
+ for (tr = list->tracks; tr != NULL; tr = ntr)
+ {
+ // Back-up pointer
+ ntr = tr->next;
+
+ delete tr->title;
+ delete tr->album;
+
+ omp_spiff_mvalue_free(tr->locations);
+ omp_spiff_mvalue_free(tr->identifiers);
+
+ delete tr;
+ }
+
+ delete list;
+}
+
+/**
+ * Writes the XSPF playlist to a file
+ */
+extern "C" int
+omp_spiff_write(omp_spiff_list *list, const char *filename)
+{
+ omp_spiff_track *strack;
+ omp_spiff_mvalue *smvalue;
+
+ SpiffIndentFormatter formatter(-2);
+ SpiffProps props;
+
+ // Playlist properties
+ props.lendLicense(list->license);
+ props.lendLocation(list->location);
+ props.lendIdentifier(list->identifier);
+ SpiffPropsWriter pwriter(&props);
+ SpiffTrackWriter twriter;
+ SpiffWriter writer(1, formatter, pwriter);
+
+ SPIFF_LIST_FOREACH_TRACK(list, strack)
+ {
+ // Tracks
+ SpiffTrack track;
+ track.lendTitle(strack->title);
+ track.lendAlbum(strack->album);
+ track.setDuration(strack->duration);
+ track.setTrackNum(strack->tracknum);
+
+ // Track locations and identifiers
+ SPIFF_TRACK_FOREACH_LOCATION(strack,smvalue)
+ track.lendAppendLocation(smvalue->value);
+
+ SPIFF_TRACK_FOREACH_IDENTIFIER(strack, smvalue)
+ track.lendAppendIdentifier(smvalue->value);
+
+ twriter.setTrack(&track);
+ writer.addTrack(twriter);
+ }
+
+ return writer.writeFile(filename);
+}
+
+/**
+ * @brief Sets or overwrites a value in the omp_spiff_list, omp_spiff_track or
+ * @brief omp_spiff_mvalue structures
+ * @note Passing NULL will unset the string.
+ */
+extern "C" void
+omp_spiff_setvalue(char **str, const char *nstr)
+{
+ // Delete old string
+ delete *str;
+
+ if (nstr == NULL) {
+ // Unset value
+ *str = NULL;
+
+ } else {
+
+ // Copy value
+ size_t len;
+ len = strlen(nstr)+1;
+ *str = new char[len];
+ strcpy(*str, nstr);
+ }
+}
+
+/**
+ * @brief Inserts a new mvalue to the linked list before the specified one
+ * @note This routine can also be used to insert a new mvalue to
+ * the end of the list (or an empty list) by passing the address
+ * of the mvalue list or the next field in the last object.
+ */
+extern "C" omp_spiff_mvalue *
+omp_spiff_new_mvalue_before(omp_spiff_mvalue **mvalue)
+{
+ omp_spiff_mvalue *ret;
+
+ ret = new omp_spiff_mvalue;
+ ret->value = NULL;
+ ret->next = *mvalue;
+ *mvalue = ret;
+
+ return ret;
+}
+
+/**
+ * @brief Inserts a new track to the linked list before the specified one
+ * @note This routine can also be used to insert a new track to
+ * the end of the list (or an empty list) by passing the address
+ * of the track list or the next field in the last object.
+ */
+extern "C" omp_spiff_track *
+omp_spiff_new_track_before(omp_spiff_track **track)
+{
+ omp_spiff_track *ret;
+
+ ret = new omp_spiff_track;
+ ret->title = NULL;
+ ret->album = NULL;
+ ret->duration = -1;
+ ret->tracknum = -1;
+ ret->locations = NULL;
+ ret->identifiers = NULL;
+ ret->next = *track;
+ *track = ret;
+
+ return ret;
+}
Added: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/omp_spiff_c.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/omp_spiff_c.h 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/omp_spiff_c.h 2007-08-24 01:11:46 UTC (rev 2826)
@@ -0,0 +1,134 @@
+/*
+ * omp_spiff_c - Enhanced C interface for libSpiff
+ *
+ * Copyright (C) 2007, Ed Schouten / Xiph.Org Foundation
+ * All rights reserved.
+ *
+ * Modified by Soeren Apel (abraxa) for OpenMoko to include XSPF
+ * features not found in the simple C bindings
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * * Neither the name of the Xiph.Org Foundation nor the names of
+ * its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Ed Schouten <ed at fxq.nl>
+ */
+
+/**
+ * @file omp_spiff_c.h
+ * Enhanced libSpiff C bindings
+ */
+
+#ifndef OMP_SPIFF_C_H
+#define OMP_SPIFF_C_H
+
+/// Linked list for values inside tracks or lists with strings
+typedef struct _omp_spiff_mvalue
+{
+ /// Value of the current list entry
+ char *value;
+
+ /// Pointer to next object in the list
+ struct _omp_spiff_mvalue *next;
+
+} omp_spiff_mvalue;
+
+
+/// Single track in an XSPF list
+typedef struct _omp_spiff_track
+{
+ /// Track's display name
+ char *title;
+
+ /// Album or collection of origin
+ char *album;
+
+ /// Track duration in milliseconds
+ int duration;
+
+ /// Track number
+ int tracknum;
+
+ /// Track's file locations
+ omp_spiff_mvalue *locations;
+
+ /// Unique track identifiers
+ omp_spiff_mvalue *identifiers;
+
+ /// Pointer to next track
+ struct _omp_spiff_track *next;
+
+} omp_spiff_track;
+
+
+/// Parsed XSPF file
+typedef struct _omp_spiff_list
+{
+ /// Playlist's license
+ char *license;
+
+ /// Playlist's file location
+ char *location;
+
+ /// Playlist's unique indentifier
+ char *identifier;
+
+ /// Linked list of tracks inside the playlist
+ omp_spiff_track *tracks;
+
+} omp_spiff_list;
+
+
+/// Easy interface for walking through tracks
+#define SPIFF_LIST_FOREACH_TRACK(l,t) \
+ for ((t) = (l)->tracks; (t) != NULL; (t) = (t)->next)
+
+/// Easy interface for walking through locations
+#define SPIFF_TRACK_FOREACH_LOCATION(t,l) \
+ for ((l) = (t)->locations; (l) != NULL; (l) = (l)->next)
+
+/// Easy interface for walking through identifiers
+#define SPIFF_TRACK_FOREACH_IDENTIFIER(t,i) \
+ for ((i) = (t)->identifiers; (i) != NULL; (i) = (i)->next)
+
+omp_spiff_list *omp_spiff_parse(const char *filename);
+omp_spiff_list *omp_spiff_new(void);
+void omp_spiff_free(omp_spiff_list *list);
+int omp_spiff_write(omp_spiff_list *list, const char *filename);
+
+void omp_spiff_setvalue(char **str, const char *nstr);
+
+omp_spiff_mvalue *omp_spiff_new_mvalue_before(
+ omp_spiff_mvalue **mvalue);
+
+omp_spiff_track *omp_spiff_new_track_before(
+ omp_spiff_track **track);
+
+#endif /* !OMP_SPIFF_C_H */
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/persistent.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/persistent.c 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/persistent.c 2007-08-24 01:11:46 UTC (rev 2826)
@@ -25,14 +25,19 @@
*/
#include <glib.h>
+
#include <string.h>
+#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <unistd.h>
#include "persistent.h"
#include "main.h"
+#include "playlist.h"
+#include "playback.h"
/// The default configuration
struct _omp_config omp_default_config =
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/persistent.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/persistent.h 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/persistent.h 2007-08-24 01:11:46 UTC (rev 2826)
@@ -80,7 +80,9 @@
void omp_session_save();
void omp_session_load();
+void omp_session_set_playback_state(glong track_position, gboolean is_playing);
void omp_session_set_playlist(gchar *playlist_file);
void omp_session_set_track_id(guint track_id);
+void omp_session_set_volume(guint volume);
#endif
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playback.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playback.c 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playback.c 2007-08-24 01:11:46 UTC (rev 2826)
@@ -26,7 +26,10 @@
#include <gst/gst.h>
+#include <uriparser/Uri.h>
+
#include "playback.h"
+#include "persistent.h"
#include "main.h"
GstElement *omp_gst_playbin = NULL; ///< Our ticket to the gstreamer world
@@ -162,6 +165,7 @@
g_printf("Loading track: %s\n", uri);
#endif
+ // Update gstreamer pipe
gst_element_set_state(omp_gst_playbin, GST_STATE_NULL);
g_object_set(G_OBJECT(omp_gst_playbin), "uri", uri, NULL);
gst_element_set_state(omp_gst_playbin, GST_STATE_PAUSED);
@@ -419,7 +423,7 @@
// Do we have a pending playback position change that we can apply?
if ( ( (GST_STATE(omp_gst_playbin) == GST_STATE_PLAYING) || (GST_STATE(omp_gst_playbin) == GST_STATE_PAUSED) )
- && omp_playback_pending_position)
+ && omp_playback_pending_position)
{
omp_playback_set_track_position(omp_playback_pending_position);
}
@@ -441,9 +445,8 @@
static gboolean
omp_gst_message_error(GstBus *bus, GstMessage *message, gpointer data)
{
- GError *error;
-
#ifdef DEBUG
+ GError *error;
gst_message_parse_error(message, &error, NULL);
g_printerr("gstreamer error: %s\n", error->message);
g_error_free(error);
@@ -458,9 +461,8 @@
static gboolean
omp_gst_message_warning(GstBus *bus, GstMessage *message, gpointer data)
{
- GError *error;
-
#ifdef DEBUG
+ GError *error;
gst_message_parse_warning(message, &error, NULL);
g_printerr("gstreamer warning: %s\n", error->message);
g_error_free(error);
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist.c 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist.c 2007-08-24 01:11:46 UTC (rev 2826)
@@ -28,17 +28,18 @@
#include <glib/gprintf.h>
#include <glib-object.h>
#include <glib/gi18n.h>
-#include <spiff/spiff_c.h>
+#include <glib/gstdio.h>
#include <string.h>
#include "playlist.h"
+#include "omp_spiff_c.h"
#include "main.h"
#include "playback.h"
#include "persistent.h"
/// Loaded playlist
-struct spiff_list *omp_playlist = NULL;
+omp_spiff_list *omp_playlist = NULL;
/// File name of currently loaded playlist
gchar *omp_playlist_file = NULL;
@@ -47,7 +48,7 @@
guint omp_playlist_track_count = 0;
/// Current track's data
-struct spiff_track *omp_playlist_current_track = NULL;
+omp_spiff_track *omp_playlist_current_track = NULL;
/// Numerical id of the current track within the playlist
guint omp_playlist_current_track_id = -1;
@@ -56,11 +57,11 @@
GSList *omp_track_history = NULL;
/// Single element for the track history
-struct omp_track_history_entry
+typedef struct _omp_track_history_entry
{
- struct spiff_track *track;
+ omp_spiff_track *track;
guint track_id;
-};
+} omp_track_history_entry;
/// Flag that indicates whether the current track has already been repeated once or not
gboolean omp_playlist_track_repeated_once = FALSE;
@@ -69,7 +70,7 @@
void omp_playlist_process_eos_event(gpointer instance, gpointer user_data);
void omp_playlist_process_tag_artist_change(gpointer instance, gchar *artist, gpointer user_data);
void omp_playlist_process_tag_title_change(gpointer instance, gchar *title, gpointer user_data);
-void omp_playlist_check_track_duration();
+void omp_playlist_update_track_duration();
@@ -123,7 +124,7 @@
// Let XSPF clean up, too
if (omp_playlist)
{
- spiff_free(omp_playlist);
+ omp_spiff_free(omp_playlist);
g_free(omp_playlist_file);
}
}
@@ -137,8 +138,6 @@
gboolean
omp_playlist_load(gchar *playlist_file, gboolean do_state_reset)
{
- struct spiff_track *track;
- guint track_num;
GtkWidget *dialog;
gchar *title;
@@ -152,7 +151,7 @@
// Let XSPF clean up, too
if (omp_playlist)
{
- spiff_free(omp_playlist);
+ omp_spiff_free(omp_playlist);
g_free(omp_playlist_file);
}
@@ -163,7 +162,7 @@
}
// Load playlist
- omp_playlist = spiff_parse(playlist_file);
+ omp_playlist = omp_spiff_parse(playlist_file);
if (omp_playlist)
{
@@ -218,12 +217,12 @@
{
if (omp_playlist)
{
- spiff_free(omp_playlist);
+ omp_spiff_free(omp_playlist);
g_free(omp_playlist_file);
}
// Create new playlist, save and load it
- omp_playlist = spiff_new();
+ omp_playlist = omp_spiff_new();
omp_playlist_file = g_strdup(playlist_file);
omp_playlist_save();
omp_playlist_load(playlist_file, TRUE);
@@ -237,7 +236,7 @@
{
if (omp_playlist && omp_playlist_file)
{
- spiff_write(omp_playlist, omp_playlist_file);
+ omp_spiff_write(omp_playlist, omp_playlist_file);
}
}
@@ -250,7 +249,7 @@
{
if (strcmp(omp_playlist_file, playlist_file) == 0)
{
- spiff_free(omp_playlist);
+ omp_spiff_free(omp_playlist);
g_free(omp_playlist_file);
omp_playback_reset();
}
@@ -266,7 +265,7 @@
omp_playlist_set_current_track(gint playlist_pos)
{
gboolean position_valid = FALSE;
- struct spiff_track *track;
+ omp_spiff_track *track;
gint track_num = 0;
if (!omp_playlist)
@@ -305,14 +304,14 @@
gboolean
omp_playlist_set_prev_track()
{
- struct omp_track_history_entry *history_entry;
- struct spiff_track *track;
+ omp_track_history_entry *history_entry;
+ omp_spiff_track *track;
gboolean was_playing;
gboolean track_determined = FALSE;
if (!omp_playlist_current_track)
{
- return;
+ return FALSE;
}
// If track playing time is >= 10 seconds we just jump back to the beginning of the track
@@ -346,7 +345,7 @@
// Do we have tracks in the history to go back to?
if (omp_track_history)
{
- history_entry = (struct omp_track_history_entry*)(omp_track_history->data);
+ history_entry = (omp_track_history_entry*)(omp_track_history->data);
omp_playlist_current_track = history_entry->track;
omp_playlist_current_track_id = history_entry->track_id;
@@ -412,7 +411,7 @@
gboolean
omp_playlist_set_next_track()
{
- struct omp_track_history_entry *history_entry;
+ omp_track_history_entry *history_entry;
gboolean was_playing;
guint repeat_mode;
gboolean track_determined = FALSE;
@@ -420,7 +419,7 @@
if (!omp_playlist_current_track)
{
- return;
+ return FALSE;
}
// Get player state so we can continue playback if necessary
@@ -446,7 +445,7 @@
try_again:
// Prepare the history entry - if we don't need it we'll just free it again
- history_entry = g_new(struct omp_track_history_entry, 1);
+ history_entry = g_new(omp_track_history_entry, 1);
history_entry->track = omp_playlist_current_track;
history_entry->track_id = omp_playlist_current_track_id;
@@ -543,7 +542,7 @@
gchar **tokens;
// Now that we have received metadata information we might also have the track duration ready
- omp_playlist_check_track_duration();
+ omp_playlist_update_track_duration();
if (!omp_playlist_current_track) return;
@@ -590,7 +589,7 @@
gchar **tokens;
// Now that we have received metadata information we might also have the track duration ready
- omp_playlist_check_track_duration();
+ omp_playlist_update_track_duration();
if (!omp_playlist_current_track) return;
@@ -628,7 +627,7 @@
* Checks to see if we can get track duration information from the playback interface
*/
void
-omp_playlist_check_track_duration()
+omp_playlist_update_track_duration()
{
gulong duration;
@@ -654,7 +653,7 @@
* @todo Actually make this function do what it's supposed to do :)
*/
gchar *
-omp_playlist_resolve_track(struct spiff_track *track)
+omp_playlist_resolve_track(omp_spiff_track *track)
{
if (!track)
{
@@ -704,7 +703,7 @@
track_loaded = omp_playback_load_track_from_uri(track_uri);
g_free(track_uri);
- omp_playlist_check_track_duration();
+ omp_playlist_update_track_duration();
return track_loaded;
}
@@ -744,7 +743,7 @@
void
omp_playlist_update_track_count()
{
- struct spiff_track *track;
+ omp_spiff_track *track;
gint tracks = 0;
if (!omp_playlist) return;
@@ -760,15 +759,15 @@
* Creates an iterator for iterating over the playlist
* @return Returns a new iterator which is deallocated by omp_playlist_advance_iter() - or yourself
*/
-playlist_iter *
+omp_playlist_iter *
omp_playlist_init_iterator()
{
- playlist_iter *iter;
+ omp_playlist_iter *iter;
if (!omp_playlist) return NULL;
if (!omp_playlist->tracks) return NULL;
- iter = g_new(playlist_iter, 1);
+ iter = g_new(omp_playlist_iter, 1);
iter->track = omp_playlist->tracks;
iter->track_num = 0;
@@ -783,7 +782,7 @@
* @param track_title Destination for the track title (can be NULL), must be freed after use
*/
void
-omp_playlist_get_track_from_iter(playlist_iter *iter, guint *track_num, gchar **track_title,
+omp_playlist_get_track_from_iter(omp_playlist_iter *iter, guint *track_num, gchar **track_title,
guint *duration)
{
// Sanity checks - one silent, one not
@@ -817,7 +816,7 @@
* Advances a playlist iterator by one track
*/
void
-omp_playlist_advance_iter(playlist_iter *iter)
+omp_playlist_advance_iter(omp_playlist_iter *iter)
{
if (iter)
{
@@ -833,7 +832,7 @@
* Determines whether an iterator has reached the end of the playlist
*/
gboolean
-omp_playlist_iter_finished(struct playlist_iter *iter)
+omp_playlist_iter_finished(omp_playlist_iter *iter)
{
if (!iter) return TRUE;
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist.h 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist.h 2007-08-24 01:11:46 UTC (rev 2826)
@@ -28,8 +28,9 @@
#define PLAYLIST_H
#include <glib.h>
-#include <spiff/spiff_c.h>
+#include "omp_spiff_c.h"
+
#define OMP_PLAYLIST_FILE_EXTENSION "xspf"
#define OMP_EVENT_PLAYLIST_LOADED "playlist_loaded"
@@ -37,6 +38,14 @@
#define OMP_EVENT_PLAYLIST_TRACK_INFO_CHANGED "playlist_track_info_changed"
#define OMP_EVENT_PLAYLIST_TRACK_COUNT_CHANGED "playlist_track_count_changed"
+/// Track info data used with the OMP_EVENT_PLAYLIST_TRACK_INFO_CHANGED signal
+typedef struct _omp_track_info
+{
+ guint id;
+ gchar *artist, *title;
+ gulong duration;
+} omp_track_info;
+
/// Modes available for repetitive track playback
enum omp_repeat_modes
{
@@ -47,19 +56,19 @@
OMP_REPEAT_COUNT ///< End-of-list marker for mode iteration
};
-extern struct spiff_list *omp_playlist;
+extern omp_spiff_list *omp_playlist;
extern guint omp_playlist_track_count;
extern gchar *omp_playlist_title;
-extern struct spiff_track *omp_playlist_current_track;
+extern omp_spiff_track *omp_playlist_current_track;
extern guint omp_playlist_current_track_id;
/// Playlist iterator
-typedef struct playlist_iter
+typedef struct _omp_playlist_iter
{
- struct spiff_track *track;
+ omp_spiff_track *track;
guint track_num;
-} playlist_iter;
+} omp_playlist_iter;
void omp_playlist_init();
void omp_playlist_free();
@@ -72,16 +81,16 @@
gboolean omp_playlist_set_prev_track();
gboolean omp_playlist_set_next_track();
-gchar *omp_playlist_resolve_track(struct spiff_track *track);
+gchar *omp_playlist_resolve_track(omp_spiff_track *track);
gboolean omp_playlist_load_current_track();
void omp_playlist_get_track_info(guint track_id, gchar **title, guint *duration);
void omp_playlist_update_track_count();
-playlist_iter *omp_playlist_init_iterator();
-void omp_playlist_get_track_info_from_iter(playlist_iter *iter, guint *track_num,
+omp_playlist_iter *omp_playlist_init_iterator();
+void omp_playlist_get_track_from_iter(omp_playlist_iter *iter, guint *track_num,
gchar **track_title, guint *duration);
-void omp_playlist_advance_iter(playlist_iter *iter);
-gboolean omp_playlist_iter_finished(playlist_iter *iter);
+void omp_playlist_advance_iter(omp_playlist_iter *iter);
+gboolean omp_playlist_iter_finished(omp_playlist_iter *iter);
gchar *get_playlist_title(gchar *playlist_file);
Modified: trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist_page.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist_page.c 2007-08-23 17:38:43 UTC (rev 2825)
+++ trunk/src/target/OM-2007.2/applications/openmoko-mediaplayer2/src/playlist_page.c 2007-08-24 01:11:46 UTC (rev 2826)
@@ -133,12 +133,12 @@
gint column_id;
gchar *playlist_name, *playlist_file, *playlist_file_abs;
- g_return_if_fail(GTK_IS_TREE_VIEW(widget));
+ g_return_val_if_fail(GTK_IS_TREE_VIEW(widget), TRUE);
// Find colum that was hit
gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), event->x, event->y,
&tree_path, &tree_column, NULL, NULL);
- if (!tree_path) return;
+ if (!tree_path) return TRUE;
columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(widget));
column_id = g_list_index(columns, (gpointer)tree_column);
More information about the commitlog
mailing list