mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-25 07:49:38 +03:00
Beginnings of a gstreamer binding. I've been sitting on this for too long
svn path=/trunk/netsurf/; revision=13248
This commit is contained in:
parent
61a36faf7f
commit
4e3a4448ec
@ -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.
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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)))
|
||||
|
202
image/video.c
Normal file
202
image/video.c
Normal file
@ -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);
|
||||
|
26
image/video.h
Normal file
26
image/video.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user