summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2011-12-05 22:33:02 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2011-12-05 22:33:02 +0000
commit4e3a4448ec4b7b3079bcc6fe282985cae402e0d9 (patch)
tree1e614d2b97ad59b47ad9fc8751aaf3d2f89c3494
parent61a36faf7f190ad3e3c1bbc8a06ebbcc8f9128e3 (diff)
downloadnetsurf-4e3a4448ec4b7b3079bcc6fe282985cae402e0d9.tar.gz
netsurf-4e3a4448ec4b7b3079bcc6fe282985cae402e0d9.tar.bz2
Beginnings of a gstreamer binding. I've been sitting on this for too long
svn path=/trunk/netsurf/; revision=13248
-rw-r--r--Makefile.defaults4
-rw-r--r--Makefile.sources1
-rw-r--r--gtk/Makefile.target2
-rw-r--r--image/video.c202
-rw-r--r--image/video.h26
5 files changed, 235 insertions, 0 deletions
diff --git a/Makefile.defaults b/Makefile.defaults
index d13f21ab6..0301bdf86 100644
--- a/Makefile.defaults
+++ b/Makefile.defaults
@@ -57,6 +57,10 @@ NETSURF_USE_MNG := YES
# Valid options: YES, NO
NETSURF_USE_WEBP := NO
+# Enable NetSurf's use of gstreamer for displaying videos
+# Valid options: YES, NO
+NETSURF_USE_VIDEO := NO
+
# Enable NetSurf's use of libharu for PDF export and GTK printing support.
# There is no auto-detection available for this, as it does not have a
# pkg-config file.
diff --git a/Makefile.sources b/Makefile.sources
index 0aaaa1612..5b2764eda 100644
--- a/Makefile.sources
+++ b/Makefile.sources
@@ -48,6 +48,7 @@ S_IMAGE_$(NETSURF_USE_PNG) += png.c
S_IMAGE_$(NETSURF_USE_NSSVG) += svg.c
S_IMAGE_$(NETSURF_USE_RSVG) += rsvg.c
S_IMAGE_$(NETSURF_USE_WEBP) += webp.c
+S_IMAGE_$(NETSURF_USE_VIDEO) += video.c
S_IMAGE := $(addprefix image/,$(S_IMAGE_YES))
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index 29d0a85c7..cce1fe7ef 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -13,6 +13,7 @@ NETSURF_FEATURE_BMP_CFLAGS := -DWITH_BMP
NETSURF_FEATURE_GIF_CFLAGS := -DWITH_GIF
NETSURF_FEATURE_PNG_CFLAGS := -DWITH_PNG
NETSURF_FEATURE_WEBP_CFLAGS := -DWITH_WEBP
+NETSURF_FEATURE_VIDEO_CFLAGS := -DWITH_VIDEO
# add a line similar to below for each optional pkg-configed lib here
$(eval $(call pkg_config_find_and_add,RSVG,librsvg-2.0,SVG))
@@ -21,6 +22,7 @@ $(eval $(call pkg_config_find_and_add,ROSPRITE,librosprite,Sprite))
$(eval $(call pkg_config_find_and_add,BMP,libnsbmp,BMP))
$(eval $(call pkg_config_find_and_add,GIF,libnsgif,GIF))
$(eval $(call pkg_config_find_and_add,PNG,libpng,PNG ))
+$(eval $(call pkg_config_find_and_add,VIDEO,gstreamer-0.10,Video))
# no pkg-config for this library
$(eval $(call feature_enabled,WEBP,-DWITH_WEBP,-lwebp,WebP (libwebp)))
diff --git a/image/video.c b/image/video.c
new file mode 100644
index 000000000..2255208c3
--- /dev/null
+++ b/image/video.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2011 John-Mark Bell <jmb@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gst/gst.h>
+
+#include "content/content_factory.h"
+#include "content/content_protected.h"
+#include "image/video.h"
+#include "utils/talloc.h"
+
+typedef struct nsvideo_content {
+ struct content base;
+
+ GstElement *playbin;
+ GstElement *appsrc;
+} nsvideo_content;
+
+static gboolean nsvideo_bus_call(GstBus *bus, GstMessage *msg,
+ nsvideo_content *video)
+{
+ switch (GST_MESSAGE_TYPE(msg)) {
+ case GST_MESSAGE_ERROR:
+ break;
+ case GST_MESSAGE_EOS:
+ break;
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+static void nsvideo_need_data_event(GstElement *playbin, guint size,
+ nsvideo_content *video)
+{
+}
+
+static void nsvideo_enough_data_event(GstElement *playbin,
+ nsvideo_content *video)
+{
+}
+
+static void nsvideo_source_event(GObject *object, GObject *orig,
+ GParamSpec *pspec, nsvideo_content *video)
+{
+ g_object_get(orig, pspec->name, &video->appsrc, NULL);
+
+ g_signal_connect(video->appsrc, "need-data",
+ G_CALLBACK(nsvideo_need_data_event), video);
+ g_signal_connect(video->appsrc, "enough-data",
+ G_CALLBACK(nsvideo_enough_data_event), video);
+}
+
+static nserror nsvideo_create(const content_handler *handler,
+ lwc_string *imime_type, const http_parameter *params,
+ llcache_handle *llcache,
+ const char *fallback_charset, bool quirks,
+ struct content **c)
+{
+ nsvideo_content *video;
+ nserror error;
+ GstBus *bus;
+
+ video = talloc_zero(0, nsvideo_content);
+ if (video == NULL)
+ return NSERROR_NOMEM;
+
+ error = content__init(&video->base, handler, imime_type, params,
+ llcache, fallback_charset, quirks);
+ if (error != NSERROR_OK) {
+ talloc_free(video);
+ return error;
+ }
+
+ error = llcache_handle_force_stream(llcache);
+ if (error != NSERROR_OK) {
+ talloc_free(video);
+ return error;
+ }
+
+ video->playbin = gst_element_factory_make("playbin2", NULL);
+ if (video->playbin == NULL) {
+ talloc_free(video);
+ return NSERROR_NOMEM;
+ }
+
+ bus = gst_pipeline_get_bus(GST_PIPELINE(video->playbin));
+ gst_bus_add_watch(bus, (GstBusFunc) nsvideo_bus_call, video);
+ gst_object_unref(bus);
+
+ g_object_set(video->playbin, "uri", "appsrc://", NULL);
+ g_signal_connect(video->playbin, "deep-notify::source",
+ G_CALLBACK(nsvideo_source_event), video);
+
+ /** \todo Create appsink & register with playbin */
+
+ gst_element_set_state(video->playbin, GST_STATE_PLAYING);
+
+ *c = (struct content *) video;
+
+ return NSERROR_OK;
+}
+
+static bool nsvideo_process_data(struct content *c, const char *data,
+ unsigned int size)
+{
+ nsvideo_content *video = (nsvideo_content *) c;
+ GstBuffer *buffer;
+ GstFlowReturn ret;
+
+ buffer = gst_buffer_new();
+ GST_BUFFER_DATA(buffer) = (guint8 *) data;
+ GST_BUFFER_SIZE(buffer) = (gsize) size;
+
+ /* Send data to appsrc */
+ g_signal_emit_by_name(video->appsrc, "push-buffer", buffer, &ret);
+
+ return ret == GST_FLOW_OK;
+}
+
+static bool nsvideo_convert(struct content *c)
+{
+ nsvideo_content *video = (nsvideo_content *) c;
+ GstFlowReturn ret;
+
+ /* Tell appsrc we're done */
+ g_signal_emit_by_name(video->appsrc, "end-of-stream", &ret);
+
+ /* Appsink will flag DONE on receipt of first frame */
+
+ return ret == GST_FLOW_OK;
+}
+
+static void nsvideo_destroy(struct content *c)
+{
+ nsvideo_content *video = (nsvideo_content *) c;
+
+ gst_element_set_state(video->playbin, GST_STATE_NULL);
+ gst_object_unref(video->playbin);
+}
+
+static bool nsvideo_redraw(struct content *c, struct content_redraw_data *data,
+ const struct rect *clip, const struct redraw_context *ctx)
+{
+ /** \todo Implement */
+ return true;
+}
+
+static nserror nsvideo_clone(const struct content *old, struct content **newc)
+{
+ /** \todo Implement */
+ return NSERROR_CLONE_FAILED;
+}
+
+static content_type nsvideo_type(void)
+{
+ /** \todo Lies */
+ return CONTENT_IMAGE;
+}
+
+static void *nsvideo_get_internal(const struct content *c, void *context)
+{
+ /** \todo Return pointer to bitmap containing current frame, if any? */
+ return NULL;
+}
+
+static const content_handler nsvideo_content_handler = {
+ .create = nsvideo_create,
+ .process_data = nsvideo_process_data,
+ .data_complete = nsvideo_convert,
+ .destroy = nsvideo_destroy,
+ .redraw = nsvideo_redraw,
+ .clone = nsvideo_clone,
+ .type = nsvideo_type,
+ .get_internal = nsvideo_get_internal,
+ /* Can't share videos because we stream them */
+ .no_share = true
+};
+
+static const char *nsvideo_types[] = {
+ "video/mp4",
+ "video/webm"
+};
+
+CONTENT_FACTORY_REGISTER_TYPES(nsvideo, nsvideo_types,
+ nsvideo_content_handler);
+
diff --git a/image/video.h b/image/video.h
new file mode 100644
index 000000000..376c837ba
--- /dev/null
+++ b/image/video.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2011 John-Mark Bell <jmb@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NETSURF_IMAGE_VIDEO_H_
+#define NETSURF_IMAGE_VIDEO_H_
+
+#include "utils/errors.h"
+
+nserror nsvideo_init(void);
+
+#endif