~ubuntu-branches/ubuntu/quantal/gst-plugins-bad-multiverse0.10/quantal

« back to all changes in this revision

Viewing changes to gst/selector/gstoutputselector.c

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2009-02-23 02:23:58 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223022358-9yhx5izc7dz60yc8
Tags: 0.10.10-0ubuntu1
* New upstream release.
* debian/rules
  - Disable some plugins which get built by default but we do not ship in 
    multiverse package.
  - Do not build docs as there is no multiverse-doc package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
/**
21
21
 * SECTION:element-output-selector
22
 
 * @short_description: 1-to-N stream selectoring
23
22
 * @see_also: #GstTee, #GstInputSelector
24
23
 *
25
24
 * Direct input stream to one out of N output pads.
56
55
 
57
56
enum
58
57
{
59
 
  PROP_ACTIVE_PAD = 1,
60
 
  PROP_RESEND_LATEST
 
58
  PROP_0,
 
59
  PROP_ACTIVE_PAD,
 
60
  PROP_RESEND_LATEST,
 
61
  PROP_LAST
61
62
};
62
63
 
 
64
GST_BOILERPLATE (GstOutputSelector, gst_output_selector, GstElement,
 
65
    GST_TYPE_ELEMENT);
 
66
 
63
67
static void gst_output_selector_dispose (GObject * object);
64
 
static void gst_output_selector_init (GstOutputSelector * sel);
65
 
static void gst_output_selector_base_init (GstOutputSelectorClass * klass);
66
 
static void gst_output_selector_class_init (GstOutputSelectorClass * klass);
67
68
static void gst_output_selector_set_property (GObject * object,
68
69
    guint prop_id, const GValue * value, GParamSpec * pspec);
69
70
static void gst_output_selector_get_property (GObject * object,
78
79
static gboolean gst_output_selector_handle_sink_event (GstPad * pad,
79
80
    GstEvent * event);
80
81
 
81
 
static GstElementClass *parent_class = NULL;
82
 
 
83
 
GType
84
 
gst_output_selector_get_type (void)
85
 
{
86
 
  static GType output_selector_type = 0;
87
 
 
88
 
  if (!output_selector_type) {
89
 
    static const GTypeInfo output_selector_info = {
90
 
      sizeof (GstOutputSelectorClass),
91
 
      (GBaseInitFunc) gst_output_selector_base_init,
92
 
      NULL,
93
 
      (GClassInitFunc) gst_output_selector_class_init,
94
 
      NULL,
95
 
      NULL,
96
 
      sizeof (GstOutputSelector),
97
 
      0,
98
 
      (GInstanceInitFunc) gst_output_selector_init,
99
 
    };
100
 
    output_selector_type =
101
 
        g_type_register_static (GST_TYPE_ELEMENT,
102
 
        "GstOutputSelector", &output_selector_info, 0);
103
 
    GST_DEBUG_CATEGORY_INIT (output_selector_debug,
104
 
        "output-selector", 0, "An output stream selector element");
105
 
  }
106
 
 
107
 
  return output_selector_type;
108
 
}
109
 
 
110
82
static void
111
 
gst_output_selector_base_init (GstOutputSelectorClass * klass)
 
83
gst_output_selector_base_init (gpointer g_class)
112
84
{
113
 
  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
 
85
  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
114
86
 
115
87
  gst_element_class_set_details (element_class, &gst_output_selector_details);
116
88
  gst_element_class_add_pad_template (element_class,
126
98
  GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
127
99
 
128
100
  parent_class = g_type_class_peek_parent (klass);
 
101
 
 
102
  gobject_class->dispose = gst_output_selector_dispose;
 
103
 
129
104
  gobject_class->set_property =
130
105
      GST_DEBUG_FUNCPTR (gst_output_selector_set_property);
131
106
  gobject_class->get_property =
132
107
      GST_DEBUG_FUNCPTR (gst_output_selector_get_property);
 
108
 
133
109
  g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD,
134
 
      g_param_spec_string ("active-pad", "Active pad",
135
 
          "Name of the currently active src pad", NULL, G_PARAM_READWRITE));
 
110
      g_param_spec_object ("active-pad", "Active pad",
 
111
          "Currently active src pad", GST_TYPE_PAD, G_PARAM_READWRITE));
136
112
  g_object_class_install_property (gobject_class, PROP_RESEND_LATEST,
137
113
      g_param_spec_boolean ("resend-latest", "Resend latest buffer",
138
114
          "Resend latest buffer after a switch to a new pad", FALSE,
139
115
          G_PARAM_READWRITE));
140
 
  gobject_class->dispose = gst_output_selector_dispose;
 
116
 
141
117
  gstelement_class->request_new_pad =
142
118
      GST_DEBUG_FUNCPTR (gst_output_selector_request_new_pad);
143
119
  gstelement_class->release_pad =
144
120
      GST_DEBUG_FUNCPTR (gst_output_selector_release_pad);
 
121
 
145
122
  gstelement_class->change_state = gst_output_selector_change_state;
146
123
 
 
124
  GST_DEBUG_CATEGORY_INIT (output_selector_debug,
 
125
      "output-selector", 0, "An output stream selector element");
147
126
}
148
127
 
149
128
static void
150
 
gst_output_selector_init (GstOutputSelector * sel)
 
129
gst_output_selector_init (GstOutputSelector * sel,
 
130
    GstOutputSelectorClass * g_class)
151
131
{
152
132
  sel->sinkpad =
153
133
      gst_pad_new_from_static_template (&gst_output_selector_sink_factory,
201
181
  GstOutputSelector *sel = GST_OUTPUT_SELECTOR (object);
202
182
 
203
183
  switch (prop_id) {
204
 
    case PROP_ACTIVE_PAD:{
205
 
      GstPad *next_pad =
206
 
          gst_element_get_static_pad (GST_ELEMENT (sel),
207
 
          g_value_get_string (value));
208
 
      if (!next_pad) {
209
 
        GST_WARNING ("pad %s not found, activation failed",
210
 
            g_value_get_string (value));
211
 
        break;
212
 
      }
 
184
    case PROP_ACTIVE_PAD:
 
185
    {
 
186
      GstPad *next_pad;
 
187
 
 
188
      next_pad = g_value_get_object (value);
 
189
 
 
190
      GST_LOG_OBJECT (sel, "Activating pad %s:%s",
 
191
          GST_DEBUG_PAD_NAME (next_pad));
 
192
 
 
193
      GST_OBJECT_LOCK (object);
213
194
      if (next_pad != sel->active_srcpad) {
214
195
        /* switch to new srcpad in next chain run */
215
196
        if (sel->pending_srcpad != NULL) {
216
197
          GST_INFO ("replacing pending switch");
217
198
          gst_object_unref (sel->pending_srcpad);
218
199
        }
 
200
        if (next_pad)
 
201
          gst_object_ref (next_pad);
219
202
        sel->pending_srcpad = next_pad;
220
203
      } else {
221
204
        GST_INFO ("pad already active");
222
 
        gst_object_unref (next_pad);
 
205
        if (sel->pending_srcpad != NULL) {
 
206
          gst_object_unref (sel->pending_srcpad);
 
207
          sel->pending_srcpad = NULL;
 
208
        }
223
209
      }
 
210
      GST_OBJECT_UNLOCK (object);
224
211
      break;
225
212
    }
226
213
    case PROP_RESEND_LATEST:{
240
227
  GstOutputSelector *sel = GST_OUTPUT_SELECTOR (object);
241
228
 
242
229
  switch (prop_id) {
243
 
    case PROP_ACTIVE_PAD:{
 
230
    case PROP_ACTIVE_PAD:
244
231
      GST_OBJECT_LOCK (object);
245
 
      if (sel->active_srcpad != NULL) {
246
 
        g_value_take_string (value, gst_pad_get_name (sel->active_srcpad));
247
 
      } else {
248
 
        g_value_set_string (value, "");
249
 
      }
 
232
      g_value_set_object (value, sel->active_srcpad);
250
233
      GST_OBJECT_UNLOCK (object);
251
234
      break;
252
 
    }
253
235
    case PROP_RESEND_LATEST:{
254
236
      GST_OBJECT_LOCK (object);
255
237
      g_value_set_boolean (value, sel->resend_latest);
328
310
    ev = gst_event_new_new_segment (TRUE, seg->rate,
329
311
        seg->format, start, seg->stop, position);
330
312
    if (!gst_pad_push_event (osel->pending_srcpad, ev)) {
331
 
      GST_WARNING ("newsegment handling failed in %" GST_PTR_FORMAT,
 
313
      GST_WARNING_OBJECT (osel,
 
314
          "newsegment handling failed in %" GST_PTR_FORMAT,
332
315
          osel->pending_srcpad);
333
316
    }
334
317
 
342
325
    /* Switch */
343
326
    osel->active_srcpad = osel->pending_srcpad;
344
327
  } else {
345
 
    GST_WARNING ("switch failed, pad not linked");
 
328
    GST_WARNING_OBJECT (osel, "switch failed, pad not linked");
346
329
    res = FALSE;
347
330
  }
348
331
 
367
350
  }
368
351
 
369
352
  /* Keep reference to latest buffer to resend it after switch */
370
 
  if (osel->resend_latest) {
371
 
    if (osel->latest_buffer)
372
 
      gst_buffer_unref (osel->latest_buffer);
373
 
    osel->latest_buffer = gst_buffer_ref (buf);
374
 
  }
 
353
  if (osel->latest_buffer)
 
354
    gst_buffer_unref (osel->latest_buffer);
 
355
  osel->latest_buffer = gst_buffer_ref (buf);
375
356
 
376
357
  /* Keep track of last stop and use it in NEWSEGMENT start after 
377
358
     switching to a new src pad */
381
362
    if (GST_CLOCK_TIME_IS_VALID (duration)) {
382
363
      last_stop += duration;
383
364
    }
384
 
    GST_LOG ("setting last stop %" GST_TIME_FORMAT, GST_TIME_ARGS (last_stop));
 
365
    GST_LOG_OBJECT (osel, "setting last stop %" GST_TIME_FORMAT,
 
366
        GST_TIME_ARGS (last_stop));
385
367
    gst_segment_set_last_stop (&osel->segment, osel->segment.format, last_stop);
386
368
  }
387
369
 
388
 
  GST_LOG ("pushing buffer to %" GST_PTR_FORMAT, osel->active_srcpad);
 
370
  GST_LOG_OBJECT (osel, "pushing buffer to %" GST_PTR_FORMAT,
 
371
      osel->active_srcpad);
389
372
  res = gst_pad_push (osel->active_srcpad, buf);
390
373
  gst_object_unref (osel);
391
374
 
404
387
{
405
388
  gboolean res = TRUE;
406
389
  GstOutputSelector *sel;
 
390
  GstPad *output_pad = NULL;
407
391
 
408
392
  sel = GST_OUTPUT_SELECTOR (gst_pad_get_parent (pad));
409
393
 
418
402
      gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
419
403
          &start, &stop, &time);
420
404
 
421
 
      GST_DEBUG ("configured NEWSEGMENT update %d, rate %lf, applied rate %lf, "
422
 
          "format %d, "
423
 
          "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
 
405
      GST_DEBUG_OBJECT (sel,
 
406
          "configured NEWSEGMENT update %d, rate %lf, applied rate %lf, "
 
407
          "format %d, " "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
424
408
          G_GINT64_FORMAT, update, rate, arate, format, start, stop, time);
425
409
 
426
410
      gst_segment_set_newsegment_full (&sel->segment, update,
436
420
      gst_pad_event_default (pad, event);
437
421
      break;
438
422
    default:
439
 
      /* Send other events to active src pad */
440
 
      res = gst_pad_push_event (sel->active_srcpad, event);
 
423
      /* Send other events to pending or active src pad */
 
424
      output_pad =
 
425
          sel->pending_srcpad ? sel->pending_srcpad : sel->active_srcpad;
 
426
      res = gst_pad_push_event (output_pad, event);
441
427
      break;
442
428
  }
443
429