29
29
GST_DEBUG_CATEGORY_STATIC (bz2dec_debug);
30
30
#define GST_CAT_DEFAULT bz2dec_debug
32
static const GstElementDetails bz2dec_details =
33
GST_ELEMENT_DETAILS ("BZ2 decoder",
34
"Codec/Decoder", "Decodes compressed streams",
35
"Lutz Mueller <lutz@users.sourceforge.net>");
37
32
static GstStaticPadTemplate sink_template =
38
33
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
39
34
GST_STATIC_CAPS ("application/x-bzip"));
105
103
static GstFlowReturn
106
104
gst_bz2dec_chain (GstPad * pad, GstBuffer * in)
108
GstBz2dec *b = GST_BZ2DEC (gst_pad_get_parent (pad));
109
GstPad *src = gst_element_get_pad (GST_ELEMENT (b), "src");
112
gst_object_unref (b);
113
gst_object_unref (src);
115
GST_ELEMENT_ERROR (b, CORE, FAILED, (NULL), ("Decompressor not ready."));
116
return GST_FLOW_ERROR;
111
b = GST_BZ2DEC (GST_PAD_PARENT (pad));
119
116
b->stream.next_in = (char *) GST_BUFFER_DATA (in);
120
117
b->stream.avail_in = GST_BUFFER_SIZE (in);
122
while (r != BZ_STREAM_END) {
127
122
/* Create the output buffer */
128
if ((fr = gst_pad_alloc_buffer (src, b->offset,
129
b->offset ? b->buffer_size : b->first_buffer_size,
130
GST_PAD_CAPS (src), &out)) != GST_FLOW_OK) {
123
flow = gst_pad_alloc_buffer (b->src, b->offset,
124
b->offset ? b->buffer_size : b->first_buffer_size,
125
GST_PAD_CAPS (b->src), &out);
127
if (flow != GST_FLOW_OK) {
128
GST_DEBUG_OBJECT (b, "pad alloc failed: %s", gst_flow_get_name (flow));
131
129
gst_bz2dec_decompress_init (b);
136
134
b->stream.next_out = (char *) GST_BUFFER_DATA (out);
137
135
b->stream.avail_out = GST_BUFFER_SIZE (out);
138
136
r = BZ2_bzDecompress (&b->stream);
139
if ((r != BZ_OK) && (r != BZ_STREAM_END)) {
140
GST_ELEMENT_ERROR (b, STREAM, DECODE, (NULL),
141
("Failed to decompress data (error code %i).", r));
142
gst_bz2dec_decompress_init (b);
143
gst_buffer_unref (out);
144
return GST_FLOW_ERROR;
137
if ((r != BZ_OK) && (r != BZ_STREAM_END))
146
140
if (b->stream.avail_out >= GST_BUFFER_SIZE (out)) {
147
141
gst_buffer_unref (out);
157
151
caps = gst_type_find_helper_for_buffer (GST_OBJECT (b), out, NULL);
159
153
gst_buffer_set_caps (out, caps);
160
gst_pad_set_caps (src, caps);
154
gst_pad_set_caps (b->src, caps);
155
gst_pad_use_fixed_caps (b->src);
161
156
gst_caps_unref (caps);
158
/* FIXME: shouldn't we queue output buffers until we have a type? */
166
163
n = GST_BUFFER_SIZE (out);
167
if ((fr = gst_pad_push (src, out)) != GST_FLOW_OK)
164
flow = gst_pad_push (b->src, out);
165
if (flow != GST_FLOW_OK)
168
} while (r != BZ_STREAM_END);
171
172
gst_buffer_unref (in);
178
GST_ELEMENT_ERROR (b, STREAM, DECODE, (NULL),
179
("Failed to decompress data (error code %i).", r));
180
gst_bz2dec_decompress_init (b);
181
gst_buffer_unref (out);
182
flow = GST_FLOW_ERROR;
187
GST_ELEMENT_ERROR (b, LIBRARY, FAILED, (NULL), ("Decompressor not ready."));
188
flow = GST_FLOW_WRONG_STATE;
176
194
gst_bz2dec_init (GstBz2dec * b, GstBz2decClass * klass)
180
196
b->first_buffer_size = DEFAULT_FIRST_BUFFER_SIZE;
181
197
b->buffer_size = DEFAULT_BUFFER_SIZE;
182
pad = gst_pad_new_from_static_template (&sink_template, "sink");
183
gst_pad_set_chain_function (pad, gst_bz2dec_chain);
184
gst_element_add_pad (GST_ELEMENT (b), pad);
185
pad = gst_pad_new_from_static_template (&src_template, "src");
186
gst_element_add_pad (GST_ELEMENT (b), pad);
187
gst_pad_use_fixed_caps (pad);
199
b->sink = gst_pad_new_from_static_template (&sink_template, "sink");
200
gst_pad_set_chain_function (b->sink, GST_DEBUG_FUNCPTR (gst_bz2dec_chain));
201
gst_element_add_pad (GST_ELEMENT (b), b->sink);
203
b->src = gst_pad_new_from_static_template (&src_template, "src");
204
gst_element_add_pad (GST_ELEMENT (b), b->src);
205
gst_pad_use_fixed_caps (b->src);
189
207
gst_bz2dec_decompress_init (b);
198
216
gst_static_pad_template_get (&sink_template));
199
217
gst_element_class_add_pad_template (ec,
200
218
gst_static_pad_template_get (&src_template));
201
gst_element_class_set_details (ec, &bz2dec_details);
219
gst_element_class_set_details_simple (ec, "BZ2 decoder",
220
"Codec/Decoder", "Decodes compressed streams",
221
"Lutz Mueller <lutz@users.sourceforge.net>");