Author: jbevain
Date: 2007-08-30 09:21:43 -0400 (Thu, 30 Aug 2007)
New Revision: 85043
Added:
trunk/moon/src/playlist.cpp
trunk/moon/src/playlist.h
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/Makefile.am
trunk/moon/src/media.cpp
trunk/moon/src/media.h
Log:
2007-08-30 Jb Evain <[EMAIL PROTECTED]>
* media.h, media.cpp: introduce a new MediaSource class that a
MediaElement uses, so we can have either a SingleMedia or a Playlist
as a source.
* playlist.cpp, playlist.h: added
* Makefile.am: add the previous files.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-08-30 13:14:14 UTC (rev 85042)
+++ trunk/moon/src/ChangeLog 2007-08-30 13:21:43 UTC (rev 85043)
@@ -1,3 +1,11 @@
+2007-08-30 Jb Evain <[EMAIL PROTECTED]>
+
+ * media.h, media.cpp: introduce a new MediaSource class that a
+ MediaElement uses, so we can have either a SingleMedia or a Playlist
+ as a source.
+ * playlist.cpp, playlist.h: added
+ * Makefile.am: add the previous files.
+
2007-08-30 Sebastien Pouliot <[EMAIL PROTECTED]>
* shape.cpp: Fix small rectangle fills when no stroke brush is
Modified: trunk/moon/src/Makefile.am
===================================================================
--- trunk/moon/src/Makefile.am 2007-08-30 13:14:14 UTC (rev 85042)
+++ trunk/moon/src/Makefile.am 2007-08-30 13:21:43 UTC (rev 85043)
@@ -21,12 +21,13 @@
frameworkelement.h \
garray-ext.h \
geometry.h \
+ list.h \
mango.h \
media.h \
- list.h \
mplayer.h \
namescope.h \
openfile.h \
+ playlist.h \
point.h \
rect.h \
rsvg.h \
@@ -67,6 +68,7 @@
openfile.cpp \
panel.cpp \
point.cpp \
+ playlist.cpp \
rect.cpp \
rsvg.cpp \
runtime.cpp \
Modified: trunk/moon/src/media.cpp
===================================================================
--- trunk/moon/src/media.cpp 2007-08-30 13:14:14 UTC (rev 85042)
+++ trunk/moon/src/media.cpp 2007-08-30 13:21:43 UTC (rev 85043)
@@ -22,6 +22,7 @@
#include "runtime.h"
#include "media.h"
#include "downloader.h"
+#include "playlist.h"
// still too ugly to be exposed in the header files ;-)
cairo_pattern_t *image_brush_create_pattern (cairo_t *cairo, cairo_surface_t
*surface, int sw, int sh, double opacity);
@@ -70,8 +71,48 @@
media->SetValue (MediaBase::StretchProperty, Value (value));
}
+// MediaSource
+MediaSource::MediaSource (MediaElement *element, char *source_name)
+{
+ this->element = element;
+ this->source_name = g_strdup (source_name);
+}
+MediaSource::~MediaSource ()
+{
+ g_free (source_name);
+}
+
+const char *
+MediaSource::GetSource ()
+{
+ return source_name;
+}
+
+MediaSource *
+MediaSource::CreateSource (MediaElement *element, char *source)
+{
+ if (Playlist::IsPlaylistFile (source))
+ return new Playlist (element, source);
+
+ return new SingleMedia (element, source);
+}
+
+// SingleMedia
+
+SingleMedia::SingleMedia (MediaElement *element, char *source_name)
+ : MediaSource (element, source_name)
+{
+}
+
+bool
+SingleMedia::Open ()
+{
+ return element->mplayer->Open (source_name);
+}
+
+
// MediaElement
DependencyProperty *MediaElement::AttributesProperty;
@@ -140,6 +181,7 @@
downloader = NULL;
part_name = NULL;
+ source = NULL;
BufferingProgressChangedEvent = RegisterEvent
("BufferingProgressChanged");
CurrentStateChangedEvent = RegisterEvent ("CurrentStateChanged");
@@ -172,6 +214,7 @@
g_free (part_name);
DownloaderAbort ();
+ delete source;
delete mplayer;
}
@@ -298,12 +341,17 @@
return;
UpdateProgress ();
+
+ if (source)
+ delete source;
+
+ source = MediaSource::CreateSource (this, filename);
printf ("video source changed to `%s'\n", filename);
// FIXME: specify which audio stream index the player should use
- if (!mplayer->Open (filename)) {
+ if (!source->Open ()) {
media_element_set_can_seek (this, false);
media_element_set_can_pause (this, false);
media_element_set_audio_stream_count (this, 0);
Modified: trunk/moon/src/media.h
===================================================================
--- trunk/moon/src/media.h 2007-08-30 13:14:14 UTC (rev 85042)
+++ trunk/moon/src/media.h 2007-08-30 13:21:43 UTC (rev 85043)
@@ -119,8 +119,30 @@
double image_get_download_progress (Image *img);
void image_set_source (Image *img, DependencyObject *Downloader, const char
*PartName);
+class MediaSource {
+protected:
+ MediaElement *element;
+ char *source_name;
+ MediaSource (MediaElement *element, char *source_name);
+public:
+ virtual ~MediaSource ();
+
+ const char *GetSource ();
+
+ virtual bool Open () = 0;
+
+ static MediaSource * CreateSource (MediaElement *element, char
*source_name);
+};
+
+class SingleMedia : public MediaSource {
+public:
+ SingleMedia (MediaElement *element, char *source_name);
+
+ virtual bool Open ();
+};
+
class MediaElement : public MediaBase {
bool recalculate_matrix;
cairo_matrix_t matrix;
@@ -134,6 +156,7 @@
// downloader methods/data
Downloader *downloader;
+ MediaSource *source;
char *part_name;
void DataWrite (guchar *data, gsize n, gsize nn);
Added: trunk/moon/src/playlist.cpp
===================================================================
--- trunk/moon/src/playlist.cpp 2007-08-30 13:14:14 UTC (rev 85042)
+++ trunk/moon/src/playlist.cpp 2007-08-30 13:21:43 UTC (rev 85043)
@@ -0,0 +1,105 @@
+/*
+ * playlist.cpp:
+ *
+ * Author: Jb Evain <[EMAIL PROTECTED]>
+ *
+ * Copyright 2007 Novell, Inc. (http://www.novell.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ */
+
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include "playlist.h"
+#include "downloader.h"
+
+// Playlist
+
+Playlist::Playlist (MediaElement *element, char *source_name)
+ : MediaSource (element, source_name)
+{
+ items = new List ();
+}
+
+Playlist::~Playlist ()
+{
+ delete items;
+}
+
+bool
+Playlist::Open ()
+{
+ if (!Parse ())
+ return false;
+
+ g_warning ("playlists are not implemented");
+ return false;
+}
+
+bool
+Playlist::IsPlaylistFile (const char * file_name)
+{
+ static const char *exts [] = {".asx", ".wax", ".wvx", ".wmx"};
+
+ for (int i = 0; i < 4; i++)
+ if (g_str_has_suffix (file_name, exts [i]))
+ return true;
+
+ return false;
+}
+
+void
+Playlist::parser_on_start_element (GMarkupParseContext *context, const gchar
*element_name,
+ const gchar
**attributes_names, const gchar **attributes_values,
+ gpointer
user_data, GError **error)
+{
+}
+
+void
+Playlist::parser_on_end_element (GMarkupParseContext *context, const gchar
*element_name,
+ gpointer
user_data, GError **error)
+{
+}
+
+void
+Playlist::parser_on_text (GMarkupParseContext *context, const gchar *text,
gsize text_len,
+ gpointer user_data, GError
**error)
+{
+}
+
+void
+Playlist::parser_on_error (GMarkupParseContext *context, GError *error,
gpointer user_data)
+{
+}
+
+bool
+Playlist::Parse ()
+{
+ static const GMarkupParser PlaylistParser = {
+ parser_on_start_element,
+ parser_on_end_element,
+ parser_on_text,
+ NULL, // passthrough
+ parser_on_error,
+ };
+
+ GMarkupParseContext *context;
+ gchar *text;
+ gsize len;
+ bool error = false;
+
+ if (!g_file_get_contents (source_name, &text, &len, NULL))
+ return false;
+
+ context = g_markup_parse_context_new (&PlaylistParser,
(GMarkupParseFlags) 0, this, NULL);
+ if (!g_markup_parse_context_parse (context, text, len, NULL)) {
+ error = true;
+ g_markup_parse_context_end_parse (context, NULL);
+ }
+
+ g_markup_parse_context_free (context);
+ g_free (text);
+
+ return !error;
+}
Added: trunk/moon/src/playlist.h
===================================================================
--- trunk/moon/src/playlist.h 2007-08-30 13:14:14 UTC (rev 85042)
+++ trunk/moon/src/playlist.h 2007-08-30 13:21:43 UTC (rev 85043)
@@ -0,0 +1,46 @@
+/*
+ * playlist.h:
+ *
+ * Author: Jb Evain <[EMAIL PROTECTED]>
+ *
+ * Copyright 2007 Novell, Inc. (http://www.novell.com)
+ *
+ * See the LICENSE file included with the distribution for details.
+ */
+
+#ifndef __PLAYLIST_H__
+#define __PLAYLIST_H__
+
+G_BEGIN_DECLS
+
+#include "downloader.h"
+#include "media.h"
+
+class Playlist : public MediaSource {
+ List *items;
+public:
+ Playlist (MediaElement *element, char *source_name);
+ virtual ~Playlist ();
+
+ virtual bool Open ();
+
+ static bool IsPlaylistFile (const char *file_name);
+private:
+ bool Parse ();
+
+ static void parser_on_start_element (GMarkupParseContext *context,
const gchar *element_name,
+
const gchar **attributes_names, const gchar **attributes_values,
+
gpointer user_data, GError **error);
+
+ static void parser_on_end_element (GMarkupParseContext *context, const
gchar *element_name,
+
gpointer user_data, GError **error);
+
+ static void parser_on_text (GMarkupParseContext *context, const gchar
*text, gsize text_len,
+ gpointer
user_data, GError **error);
+
+ static void parser_on_error (GMarkupParseContext *context, GError
*error, gpointer user_data);
+};
+
+G_END_DECLS
+
+#endif /* __PLAYLIST_H__ */
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches