22 #include "mozilla-config.h"
25 #include <gst/base/gstbasesink.h>
27 #include <nsComponentManagerUtils.h>
28 #include <nsServiceManagerUtils.h>
30 #include <nsIOutputStream.h>
31 #include <nsIProxyObjectManager.h>
56 #define GST_CAT_DEFAULT mozilla_sink_debug
59 GST_ELEMENT_DETAILS ((gchar *)
"Mozilla nsIOutputStream sink",
61 (gchar *)
"Write data to a hosting mozilla "
62 "application's output stream API",
63 (gchar *)
"Pioneers of the Inevitable <songbird@songbirdnest.com");
65 static GstStaticPadTemplate
sink_template = GST_STATIC_PAD_TEMPLATE (
"sink",
77 const GValue *
value, GParamSpec * pspec);
79 GValue *
value, GParamSpec * pspec);
96 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
98 gst_element_class_add_pad_template (element_class,
99 gst_static_pad_template_get (&sink_template));
107 GObjectClass *gobject_class;
108 GstBaseSinkClass *gstbasesink_class;
110 gobject_class = (GObjectClass *) klass;
111 gstbasesink_class = (GstBaseSinkClass *) klass;
116 g_object_class_install_property
118 g_param_spec_pointer (
"stream",
"Stream",
119 "Mozilla output stream", (GParamFlags) G_PARAM_READWRITE));
126 GST_DEBUG_CATEGORY_INIT (mozilla_sink_debug,
"mozillasink", 0,
140 gst_base_sink_set_sync (GST_BASE_SINK (sink), FALSE);
145 const GValue *
value, GParamSpec * pspec)
154 nsCOMPtr<nsIProxyObjectManager> proxyObjectManager =
155 do_GetService(
"@mozilla.org/xpcomproxy;1", &rv);
156 if (NS_FAILED (rv)) {
157 GST_WARNING_OBJECT (sink,
"Failed to get Mozilla proxy object manager");
162 do_QueryInterface((nsIOutputStream *) g_value_get_pointer(value));
164 GST_WARNING_OBJECT (sink,
"Failed to set output stream");
170 rv = proxyObjectManager->GetProxyForObject(
171 NS_PROXY_TO_MAIN_THREAD,
172 NS_GET_IID (nsIOutputStream),
174 NS_PROXY_SYNC | NS_PROXY_ALWAYS,
176 if (NS_FAILED (rv)) {
177 GST_WARNING_OBJECT (sink,
"Failed to get proxy for output stream");
184 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
191 GValue *
value, GParamSpec * pspec)
199 NS_IF_ADDREF (rawStreamPtr);
200 g_value_set_pointer (value, rawStreamPtr);
204 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
216 GST_WARNING_OBJECT (sink,
"Tried to render without a proxied stream");
217 return GST_FLOW_UNEXPECTED;
220 PRUint32 bytesWritten;
222 PRUint32
count = GST_BUFFER_SIZE (buf);
223 char *
data = (
char *) GST_BUFFER_DATA (buf);
224 GST_DEBUG_OBJECT (sink,
"Writing %u byte buffer", count);
226 while (offset < count) {
229 if (NS_FAILED (rv)) {
230 GST_WARNING_OBJECT (sink,
"Failed to write buffer to output stream");
231 return GST_FLOW_UNEXPECTED;
234 GST_DEBUG_OBJECT (sink,
"Wrote %u bytes to output stream", bytesWritten);
235 offset += bytesWritten;
247 GST_WARNING_OBJECT (sink,
"Tried to start with invalid output stream");
270 type = GST_EVENT_TYPE (event);
275 GST_DEBUG_OBJECT (sink,
"Handling EOS event");
279 case GST_EVENT_FLUSH_STOP:
281 GST_DEBUG_OBJECT (sink,
"Handling flush start event");
295 GST_DEBUG_OBJECT (sink,
"Closing output stream");
299 if (NS_FAILED (rv)) {
300 GST_WARNING_OBJECT (sink,
"Failed to close output stream");
307 GST_DEBUG_OBJECT (sink,
"Flushing output stream");
310 if (NS_FAILED (rv)) {
311 GST_WARNING_OBJECT (sink,
"Failed to flush output stream");
static const GstElementDetails gst_mozilla_sink_details
nsCOMPtr< nsIOutputStream > proxied_output_stream
static void gst_mozilla_sink_class_init(GstMozillaSinkClass *klass)
static gboolean gst_mozilla_sink_stop(GstBaseSink *bsink)
static void gst_mozilla_sink_base_init(gpointer g_class)
nsCOMPtr< nsIOutputStream > output_stream
static gboolean gst_mozilla_sink_start(GstBaseSink *bsink)
#define GST_MOZILLA_SINK(obj)
static void gst_mozilla_sink_flush_stream(GstMozillaSink *sink)
GstBaseSinkClass parent_class
static GstFlowReturn gst_mozilla_sink_render(GstBaseSink *bsink, GstBuffer *buf)
GST_BOILERPLATE(GstMozillaSink, gst_mozilla_sink, GstBaseSink, GST_TYPE_BASE_SINK)
GST_DEBUG_CATEGORY_STATIC(mozilla_sink_debug)
static void gst_mozilla_sink_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
static void gst_mozilla_sink_close_stream(GstMozillaSink *sink)
static void gst_mozilla_sink_init(GstMozillaSink *sink, GstMozillaSinkClass *g_class)
static void gst_mozilla_sink_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
static GstStaticPadTemplate sink_template
static gboolean gst_mozilla_sink_event(GstBaseSink *bsink, GstEvent *event)