~ubuntu-branches/ubuntu/karmic/gst-plugins-bad0.10/karmic-proposed

« back to all changes in this revision

Viewing changes to ext/bz2/gstbz2dec.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge, Fabian Greffrath, Sebastian Dröge
  • Date: 2009-05-12 09:51:24 UTC
  • mfrom: (18.3.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20090512095124-6h887drc2pk2imm3
Tags: 0.10.11.2-1
[ Fabian Greffrath ]
* debian/TODO.Debian:
  + Removed, I don't think any of these things are still relevant.

[ Sebastian Dröge ]
* New upstream pre-release:
  + debian/build-deps.in,
    debian/rules:
    - Update build dependencies.
  + debian/gstreamer-plugins-bad.install:
    - Add new debugutilsbad plugin.
* debian/build-deps.in:
  + Use unversioned libjack-dev b-d (Closes: #526109).

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
GST_DEBUG_CATEGORY_STATIC (bz2dec_debug);
30
30
#define GST_CAT_DEFAULT bz2dec_debug
31
31
 
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>");
36
 
 
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"));
45
40
{
46
41
  GstElement parent;
47
42
 
 
43
  GstPad *sink;
 
44
  GstPad *src;
 
45
 
48
46
  /* Properties */
49
47
  guint first_buffer_size;
50
48
  guint buffer_size;
105
103
static GstFlowReturn
106
104
gst_bz2dec_chain (GstPad * pad, GstBuffer * in)
107
105
{
108
 
  GstBz2dec *b = GST_BZ2DEC (gst_pad_get_parent (pad));
109
 
  GstPad *src = gst_element_get_pad (GST_ELEMENT (b), "src");
 
106
  GstFlowReturn flow;
 
107
  GstBuffer *out;
 
108
  GstBz2dec *b;
110
109
  int r = BZ_OK;
111
110
 
112
 
  gst_object_unref (b);
113
 
  gst_object_unref (src);
114
 
  if (!b->ready) {
115
 
    GST_ELEMENT_ERROR (b, CORE, FAILED, (NULL), ("Decompressor not ready."));
116
 
    return GST_FLOW_ERROR;
117
 
  }
 
111
  b = GST_BZ2DEC (GST_PAD_PARENT (pad));
 
112
 
 
113
  if (!b->ready)
 
114
    goto not_ready;
118
115
 
119
116
  b->stream.next_in = (char *) GST_BUFFER_DATA (in);
120
117
  b->stream.avail_in = GST_BUFFER_SIZE (in);
121
118
 
122
 
  while (r != BZ_STREAM_END) {
123
 
    GstBuffer *out;
 
119
  do {
124
120
    guint n;
125
 
    GstFlowReturn fr;
126
121
 
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);
 
126
 
 
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);
132
 
      return fr;
 
130
      break;
133
131
    }
134
132
 
135
133
    /* Decode */
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;
145
 
    }
 
137
    if ((r != BZ_OK) && (r != BZ_STREAM_END))
 
138
      goto decode_failed;
 
139
 
146
140
    if (b->stream.avail_out >= GST_BUFFER_SIZE (out)) {
147
141
      gst_buffer_unref (out);
148
142
      break;
157
151
      caps = gst_type_find_helper_for_buffer (GST_OBJECT (b), out, NULL);
158
152
      if (caps) {
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);
 
157
      } else {
 
158
        /* FIXME: shouldn't we queue output buffers until we have a type? */
162
159
      }
163
160
    }
164
161
 
165
162
    /* Push data */
166
163
    n = GST_BUFFER_SIZE (out);
167
 
    if ((fr = gst_pad_push (src, out)) != GST_FLOW_OK)
168
 
      return fr;
 
164
    flow = gst_pad_push (b->src, out);
 
165
    if (flow != GST_FLOW_OK)
 
166
      break;
169
167
    b->offset += n;
170
 
  }
 
168
  } while (r != BZ_STREAM_END);
 
169
 
 
170
done:
 
171
 
171
172
  gst_buffer_unref (in);
172
 
  return GST_FLOW_OK;
 
173
  return flow;
 
174
 
 
175
/* ERRORS */
 
176
decode_failed:
 
177
  {
 
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;
 
183
    goto done;
 
184
  }
 
185
not_ready:
 
186
  {
 
187
    GST_ELEMENT_ERROR (b, LIBRARY, FAILED, (NULL), ("Decompressor not ready."));
 
188
    flow = GST_FLOW_WRONG_STATE;
 
189
    goto done;
 
190
  }
173
191
}
174
192
 
175
193
static void
176
194
gst_bz2dec_init (GstBz2dec * b, GstBz2decClass * klass)
177
195
{
178
 
  GstPad *pad;
179
 
 
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);
 
198
 
 
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);
 
202
 
 
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);
188
206
 
189
207
  gst_bz2dec_decompress_init (b);
190
208
}
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>");
202
222
}
203
223
 
204
224
static void