2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 #include "gsttarkindec.h"
26 extern GstPadTemplate *dec_src_template, *dec_sink_template;
28 /* elementfactory information */
29 GstElementDetails tarkindec_details = {
31 "Filter/Video/Decoder",
32 "Decodes video in OGG Tarkin format",
34 "Monty <monty@xiph.org>, "
35 "Wim Taymans <wim.taymans@chello.be>",
39 /* TarkinDec signals and args */
52 static void gst_tarkindec_class_init (TarkinDecClass *klass);
53 static void gst_tarkindec_init (TarkinDec *arkindec);
55 static void gst_tarkindec_chain (GstPad *pad, GstBuffer *buf);
56 static void gst_tarkindec_setup (TarkinDec *tarkindec);
57 static GstElementStateReturn
58 gst_tarkindec_change_state (GstElement *element);
60 static void gst_tarkindec_get_property (GObject *object, guint prop_id, GValue *value,
62 static void gst_tarkindec_set_property (GObject *object, guint prop_id, const GValue *value,
65 static GstElementClass *parent_class = NULL;
66 /*static guint gst_tarkindec_signals[LAST_SIGNAL] = { 0 }; */
69 tarkindec_get_type (void)
71 static GType tarkindec_type = 0;
73 if (!tarkindec_type) {
74 static const GTypeInfo tarkindec_info = {
75 sizeof (TarkinDecClass),
78 (GClassInitFunc) gst_tarkindec_class_init,
83 (GInstanceInitFunc) gst_tarkindec_init,
86 tarkindec_type = g_type_register_static (GST_TYPE_ELEMENT, "TarkinDec", &tarkindec_info, 0);
88 return tarkindec_type;
92 gst_tarkindec_class_init (TarkinDecClass *klass)
94 GObjectClass *gobject_class;
95 GstElementClass *gstelement_class;
97 gobject_class = (GObjectClass *) klass;
98 gstelement_class = (GstElementClass *) klass;
100 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BITRATE,
101 g_param_spec_int ("bitrate", "bitrate", "bitrate",
102 G_MININT, G_MAXINT, 3000, G_PARAM_READWRITE));
104 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
106 gobject_class->set_property = gst_tarkindec_set_property;
107 gobject_class->get_property = gst_tarkindec_get_property;
109 gstelement_class->change_state = gst_tarkindec_change_state;
113 gst_tarkindec_init (TarkinDec * tarkindec)
115 tarkindec->sinkpad = gst_pad_new_from_template (dec_sink_template, "sink");
116 gst_element_add_pad (GST_ELEMENT (tarkindec), tarkindec->sinkpad);
117 gst_pad_set_chain_function (tarkindec->sinkpad, gst_tarkindec_chain);
119 tarkindec->srcpad = gst_pad_new_from_template (dec_src_template, "src");
120 gst_element_add_pad (GST_ELEMENT (tarkindec), tarkindec->srcpad);
122 tarkindec->bitrate = 3000;
123 tarkindec->setup = FALSE;
124 tarkindec->nheader = 0;
126 /* we're chained and we can deal with events */
127 GST_FLAG_SET (tarkindec, GST_ELEMENT_EVENT_AWARE);
131 gst_tarkindec_setup (TarkinDec *tarkindec)
133 tarkindec->tarkin_stream = tarkin_stream_new ();
135 ogg_sync_init (&tarkindec->oy);
136 ogg_stream_init (&tarkindec->os, 1);
137 tarkin_info_init (&tarkindec->ti);
138 tarkin_comment_init (&tarkindec->tc);
140 tarkindec->setup = TRUE;
144 gst_tarkindec_chain (GstPad *pad, GstBuffer *buf)
146 TarkinDec *tarkindec;
148 g_return_if_fail (pad != NULL);
149 g_return_if_fail (GST_IS_PAD (pad));
150 g_return_if_fail (buf != NULL);
152 tarkindec = GST_TARKINDEC (gst_pad_get_parent (pad));
154 if (!tarkindec->setup) {
155 gst_element_error (GST_ELEMENT (tarkindec), "decoder not initialized (input is not audio?)");
156 if (GST_IS_BUFFER (buf))
157 gst_buffer_unref (buf);
159 gst_pad_event_default (pad, GST_EVENT (buf));
163 if (GST_IS_EVENT (buf)) {
164 switch (GST_EVENT_TYPE (buf)) {
167 gst_pad_event_default (pad, GST_EVENT (buf));
177 TarkinVideoLayerDesc *layer;
180 data = GST_BUFFER_DATA (buf);
181 size = GST_BUFFER_SIZE (buf);
183 buffer = ogg_sync_buffer(&tarkindec->oy, size);
184 memcpy (buffer, data, size);
185 ogg_sync_wrote(&tarkindec->oy, size);
187 if (ogg_sync_pageout (&tarkindec->oy, &tarkindec->og)) {
188 ogg_stream_pagein (&tarkindec->os, &tarkindec->og);
190 while (ogg_stream_packetout (&tarkindec->os, &tarkindec->op)) {
191 if (tarkindec->op.e_o_s)
193 if (tarkindec->nheader < 3) { /* 3 first packets to headerin */
194 tarkin_synthesis_headerin (&tarkindec->ti, &tarkindec->tc, &tarkindec->op);
196 if (tarkindec->nheader == 2) {
197 tarkin_synthesis_init (tarkindec->tarkin_stream, &tarkindec->ti);
199 tarkindec->nheader++;
201 tarkin_synthesis_packetin (tarkindec->tarkin_stream, &tarkindec->op);
203 while (tarkin_synthesis_frameout (tarkindec->tarkin_stream, &rgb, 0, &date) == 0) {
206 layer = &tarkindec->tarkin_stream->layer->desc;
208 if (!GST_PAD_CAPS (tarkindec->srcpad)) {
209 if (!gst_pad_try_set_caps (tarkindec->srcpad,
213 "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("RGB ")),
214 "bpp", GST_PROPS_INT (24),
215 "depth", GST_PROPS_INT (24),
216 "endianness", GST_PROPS_INT (G_BYTE_ORDER),
217 "red_mask", GST_PROPS_INT (0xff0000),
218 "green_mask", GST_PROPS_INT (0xff00),
219 "blue_mask", GST_PROPS_INT (0xff),
220 "width", GST_PROPS_INT (layer->width),
221 "height", GST_PROPS_INT (layer->height)
224 gst_element_error (GST_ELEMENT (tarkindec), "could not output format");
225 gst_buffer_unref (buf);
229 outbuf = gst_buffer_new ();
230 GST_BUFFER_DATA (outbuf) = rgb;
231 GST_BUFFER_SIZE (outbuf) = layer->width * layer->height * 3;
232 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_DONTFREE);
233 gst_pad_push (tarkindec->srcpad, outbuf);
235 tarkin_synthesis_freeframe (tarkindec->tarkin_stream, rgb);
240 gst_buffer_unref (buf);
244 static GstElementStateReturn
245 gst_tarkindec_change_state (GstElement *element)
247 TarkinDec *tarkindec;
249 tarkindec = GST_TARKINDEC (element);
251 switch (GST_STATE_TRANSITION (element)) {
252 case GST_STATE_READY_TO_PAUSED:
253 gst_tarkindec_setup (tarkindec);
255 case GST_STATE_PAUSED_TO_READY:
261 return parent_class->change_state (element);
265 gst_tarkindec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
267 TarkinDec *tarkindec;
269 /* it's not null if we got it, but it might not be ours */
270 g_return_if_fail (GST_IS_TARKINDEC (object));
272 tarkindec = GST_TARKINDEC (object);
276 g_value_set_int (value, tarkindec->bitrate);
284 gst_tarkindec_set_property (GObject *object, guint prop_id, const GValue *value,
287 TarkinDec *tarkindec;
289 /* it's not null if we got it, but it might not be ours */
290 g_return_if_fail (GST_IS_TARKINDEC (object));
292 tarkindec = GST_TARKINDEC (object);
296 tarkindec->bitrate = g_value_get_int (value);