NetSurf
video.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 John-Mark Bell <jmb@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <gst/gst.h>
20
23
24#include "image/video.h"
25
26typedef struct nsvideo_content {
27 struct content base;
28
29 GstElement *playbin;
30 GstElement *appsrc;
32
33static gboolean nsvideo_bus_call(GstBus *bus, GstMessage *msg,
34 nsvideo_content *video)
35{
36 switch (GST_MESSAGE_TYPE(msg)) {
37 case GST_MESSAGE_ERROR:
38 break;
39 case GST_MESSAGE_EOS:
40 break;
41 default:
42 break;
43 }
44
45 return TRUE;
46}
47
48static void nsvideo_need_data_event(GstElement *playbin, guint size,
49 nsvideo_content *video)
50{
51}
52
53static void nsvideo_enough_data_event(GstElement *playbin,
54 nsvideo_content *video)
55{
56}
57
58static void nsvideo_source_event(GObject *object, GObject *orig,
59 GParamSpec *pspec, nsvideo_content *video)
60{
61 g_object_get(orig, pspec->name, &video->appsrc, NULL);
62
63 g_signal_connect(video->appsrc, "need-data",
64 G_CALLBACK(nsvideo_need_data_event), video);
65 g_signal_connect(video->appsrc, "enough-data",
66 G_CALLBACK(nsvideo_enough_data_event), video);
67}
68
70 lwc_string *imime_type, const http_parameter *params,
72 const char *fallback_charset, bool quirks,
73 struct content **c)
74{
75 nsvideo_content *video;
76 nserror error;
77 GstBus *bus;
78
79 video = calloc(1, sizeof(nsvideo_content));
80 if (video == NULL)
81 return NSERROR_NOMEM;
82
83 error = content__init(&video->base, handler, imime_type, params,
85 if (error != NSERROR_OK) {
86 free(video);
87 return error;
88 }
89
91 if (error != NSERROR_OK) {
92 free(video);
93 return error;
94 }
95
96 video->playbin = gst_element_factory_make("playbin2", NULL);
97 if (video->playbin == NULL) {
98 free(video);
99 return NSERROR_NOMEM;
100 }
101
102 bus = gst_pipeline_get_bus(GST_PIPELINE(video->playbin));
103 gst_bus_add_watch(bus, (GstBusFunc) nsvideo_bus_call, video);
104 gst_object_unref(bus);
105
106 g_object_set(video->playbin, "uri", "appsrc://", NULL);
107 g_signal_connect(video->playbin, "deep-notify::source",
108 G_CALLBACK(nsvideo_source_event), video);
109
110 /** \todo Create appsink & register with playbin */
111
112 gst_element_set_state(video->playbin, GST_STATE_PLAYING);
113
114 *c = (struct content *) video;
115
116 return NSERROR_OK;
117}
118
119static bool nsvideo_process_data(struct content *c, const char *data,
120 unsigned int size)
121{
122 nsvideo_content *video = (nsvideo_content *) c;
123 GstBuffer *buffer;
124 GstFlowReturn ret;
125
126 buffer = gst_buffer_new();
127 GST_BUFFER_DATA(buffer) = (guint8 *) data;
128 GST_BUFFER_SIZE(buffer) = (gsize) size;
129
130 /* Send data to appsrc */
131 g_signal_emit_by_name(video->appsrc, "push-buffer", buffer, &ret);
132
133 return ret == GST_FLOW_OK;
134}
135
136static bool nsvideo_convert(struct content *c)
137{
138 nsvideo_content *video = (nsvideo_content *) c;
139 GstFlowReturn ret;
140
141 /* Tell appsrc we're done */
142 g_signal_emit_by_name(video->appsrc, "end-of-stream", &ret);
143
144 /* Appsink will flag DONE on receipt of first frame */
145
146 return ret == GST_FLOW_OK;
147}
148
149static void nsvideo_destroy(struct content *c)
150{
151 nsvideo_content *video = (nsvideo_content *) c;
152
153 gst_element_set_state(video->playbin, GST_STATE_NULL);
154 gst_object_unref(video->playbin);
155}
156
157static bool nsvideo_redraw(struct content *c, struct content_redraw_data *data,
158 const struct rect *clip, const struct redraw_context *ctx)
159{
160 /** \todo Implement */
161 return true;
162}
163
164static nserror nsvideo_clone(const struct content *old, struct content **newc)
165{
166 /** \todo Implement */
168}
169
171{
172 /** \todo Lies */
173 return CONTENT_IMAGE;
174}
175
176static void *nsvideo_get_internal(const struct content *c, void *context)
177{
178 /** \todo Return pointer to bitmap containing current frame, if any? */
179 return NULL;
180}
181
184 .process_data = nsvideo_process_data,
185 .data_complete = nsvideo_convert,
186 .destroy = nsvideo_destroy,
187 .redraw = nsvideo_redraw,
188 .clone = nsvideo_clone,
189 .type = nsvideo_type,
190 .get_internal = nsvideo_get_internal,
191 /* Can't share videos because we stream them */
192 .no_share = true
193};
194
195static const char *nsvideo_types[] = {
196 "video/mp4",
197 "video/webm"
198};
199
202
static osspriteop_area * buffer
The buffer characteristics.
Definition: buffer.c:55
nserror content__init(struct content *c, const content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, llcache_handle *llcache, const char *fallback_charset, bool quirks)
Definition: content.c:190
Protected interface to Content handling.
content_type
The type of a content.
Definition: content_type.h:53
@ CONTENT_IMAGE
All images.
Definition: content_type.h:67
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_NOMEM
Memory exhaustion.
Definition: errors.h:32
@ NSERROR_CLONE_FAILED
Failed to clone handle.
Definition: errors.h:37
@ NSERROR_OK
No error.
Definition: errors.h:30
static struct llcache_s * llcache
low level cache state
Definition: llcache.c:267
nserror llcache_handle_force_stream(llcache_handle *handle)
Force a low-level cache handle into streaming mode.
Definition: llcache.c:4160
Content operation function table.
nserror(* create)(const struct content_handler *handler, lwc_string *imime_type, const struct http_parameter *params, struct llcache_handle *llcache, const char *fallback_charset, bool quirks, struct content **c)
parameters to content redraw
Definition: content.h:40
Content which corresponds to a single URL.
bool quirks
Content is in quirks mode.
char * fallback_charset
Fallback charset, or NULL.
const struct content_handler * handler
Handler for content.
struct textsearch_context * context
unsigned int size
Estimated size of all data associated with this content.
Representation of an HTTP parameter.
Definition: parameter.c:31
Handle to low-level cache object.
Definition: llcache.c:76
GstElement * playbin
Definition: video.c:29
GstElement * appsrc
Definition: video.c:30
struct content base
Definition: video.c:27
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
static void nsvideo_need_data_event(GstElement *playbin, guint size, nsvideo_content *video)
Definition: video.c:48
struct nsvideo_content nsvideo_content
static const content_handler nsvideo_content_handler
Definition: video.c:182
static void * nsvideo_get_internal(const struct content *c, void *context)
Definition: video.c:176
static bool nsvideo_redraw(struct content *c, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
Definition: video.c:157
static gboolean nsvideo_bus_call(GstBus *bus, GstMessage *msg, nsvideo_content *video)
Definition: video.c:33
static void nsvideo_destroy(struct content *c)
Definition: video.c:149
static void nsvideo_enough_data_event(GstElement *playbin, nsvideo_content *video)
Definition: video.c:53
CONTENT_FACTORY_REGISTER_TYPES(nsvideo, nsvideo_types, nsvideo_content_handler)
static content_type nsvideo_type(void)
Definition: video.c:170
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)
Definition: video.c:69
static nserror nsvideo_clone(const struct content *old, struct content **newc)
Definition: video.c:164
static const char * nsvideo_types[]
Definition: video.c:195
static bool nsvideo_process_data(struct content *c, const char *data, unsigned int size)
Definition: video.c:119
static void nsvideo_source_event(GObject *object, GObject *orig, GParamSpec *pspec, nsvideo_content *video)
Definition: video.c:58
static bool nsvideo_convert(struct content *c)
Definition: video.c:136
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357