~ubuntu-branches/ubuntu/trusty/gstreamer1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to libs/gst/base/gstbasesrc.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2012-10-25 13:23:04 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20121025132304-d4h5101bepls2o8n
Tags: 1.0.2-1
New upstream stable release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
#define GST_LIVE_SIGNAL(elem)                 g_cond_signal (GST_LIVE_GET_COND (elem));
184
184
#define GST_LIVE_BROADCAST(elem)              g_cond_broadcast (GST_LIVE_GET_COND (elem));
185
185
 
 
186
 
 
187
#define GST_ASYNC_GET_COND(elem)              (&GST_BASE_SRC_CAST(elem)->priv->async_cond)
 
188
#define GST_ASYNC_WAIT(elem)                  g_cond_wait (GST_ASYNC_GET_COND (elem), GST_OBJECT_GET_LOCK (elem))
 
189
#define GST_ASYNC_SIGNAL(elem)                g_cond_signal (GST_ASYNC_GET_COND (elem));
 
190
 
 
191
 
186
192
/* BaseSrc signals and args */
187
193
enum
188
194
{
251
257
  GstBufferPool *pool;
252
258
  GstAllocator *allocator;
253
259
  GstAllocationParams params;
 
260
 
 
261
  GCond async_cond;
254
262
};
255
263
 
256
264
static GstElementClass *parent_class = NULL;
444
452
  basesrc->priv->do_timestamp = DEFAULT_DO_TIMESTAMP;
445
453
  g_atomic_int_set (&basesrc->priv->have_events, FALSE);
446
454
 
 
455
  g_cond_init (&basesrc->priv->async_cond);
447
456
  basesrc->priv->start_result = GST_FLOW_FLUSHING;
448
457
  GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTED);
449
458
  GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTING);
462
471
 
463
472
  g_mutex_clear (&basesrc->live_lock);
464
473
  g_cond_clear (&basesrc->live_cond);
 
474
  g_cond_clear (&basesrc->priv->async_cond);
465
475
 
466
476
  event_p = &basesrc->pending_seek;
467
477
  gst_event_replace (event_p, NULL);
3091
3101
  gboolean result;
3092
3102
 
3093
3103
  GST_LIVE_LOCK (basesrc);
 
3104
 
 
3105
  GST_OBJECT_LOCK (basesrc);
3094
3106
  if (GST_BASE_SRC_IS_STARTING (basesrc))
3095
3107
    goto was_starting;
3096
3108
  if (GST_BASE_SRC_IS_STARTED (basesrc))
3098
3110
 
3099
3111
  basesrc->priv->start_result = GST_FLOW_FLUSHING;
3100
3112
  GST_OBJECT_FLAG_SET (basesrc, GST_BASE_SRC_FLAG_STARTING);
 
3113
  gst_segment_init (&basesrc->segment, basesrc->segment.format);
 
3114
  GST_OBJECT_UNLOCK (basesrc);
 
3115
 
3101
3116
  basesrc->num_buffers_left = basesrc->num_buffers;
3102
3117
  basesrc->running = FALSE;
3103
3118
  basesrc->priv->segment_pending = FALSE;
3104
 
  GST_OBJECT_LOCK (basesrc);
3105
 
  gst_segment_init (&basesrc->segment, basesrc->segment.format);
3106
 
  GST_OBJECT_UNLOCK (basesrc);
3107
3119
  GST_LIVE_UNLOCK (basesrc);
3108
3120
 
3109
3121
  bclass = GST_BASE_SRC_GET_CLASS (basesrc);
3115
3127
  if (!result)
3116
3128
    goto could_not_start;
3117
3129
 
3118
 
  if (!gst_base_src_is_async (basesrc))
 
3130
  if (!gst_base_src_is_async (basesrc)) {
3119
3131
    gst_base_src_start_complete (basesrc, GST_FLOW_OK);
 
3132
    /* not really waiting here, we call this to get the result
 
3133
     * from the start_complete call */
 
3134
    result = gst_base_src_start_wait (basesrc) == GST_FLOW_OK;
 
3135
  }
3120
3136
 
3121
3137
  return result;
3122
3138
 
3124
3140
was_starting:
3125
3141
  {
3126
3142
    GST_DEBUG_OBJECT (basesrc, "was starting");
 
3143
    GST_OBJECT_UNLOCK (basesrc);
3127
3144
    GST_LIVE_UNLOCK (basesrc);
3128
3145
    return TRUE;
3129
3146
  }
3130
3147
was_started:
3131
3148
  {
3132
3149
    GST_DEBUG_OBJECT (basesrc, "was started");
 
3150
    GST_OBJECT_UNLOCK (basesrc);
3133
3151
    GST_LIVE_UNLOCK (basesrc);
3134
3152
    return TRUE;
3135
3153
  }
3232
3250
      goto no_get_range;
3233
3251
  }
3234
3252
 
3235
 
  GST_LIVE_LOCK (basesrc);
 
3253
  GST_OBJECT_LOCK (basesrc);
3236
3254
  GST_OBJECT_FLAG_SET (basesrc, GST_BASE_SRC_FLAG_STARTED);
3237
3255
  GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTING);
3238
3256
  basesrc->priv->start_result = ret;
3239
 
  GST_LIVE_SIGNAL (basesrc);
3240
 
  GST_LIVE_UNLOCK (basesrc);
 
3257
  GST_ASYNC_SIGNAL (basesrc);
 
3258
  GST_OBJECT_UNLOCK (basesrc);
3241
3259
 
3242
3260
  GST_PAD_STREAM_UNLOCK (basesrc->srcpad);
3243
3261
 
3263
3281
  }
3264
3282
error:
3265
3283
  {
3266
 
    GST_LIVE_LOCK (basesrc);
 
3284
    GST_OBJECT_LOCK (basesrc);
3267
3285
    basesrc->priv->start_result = ret;
3268
3286
    GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTING);
3269
 
    GST_LIVE_SIGNAL (basesrc);
3270
 
    GST_LIVE_UNLOCK (basesrc);
 
3287
    GST_ASYNC_SIGNAL (basesrc);
 
3288
    GST_OBJECT_UNLOCK (basesrc);
3271
3289
    return;
3272
3290
  }
3273
3291
}
3285
3303
{
3286
3304
  GstFlowReturn result;
3287
3305
 
3288
 
  GST_LIVE_LOCK (basesrc);
3289
 
  if (G_UNLIKELY (basesrc->priv->flushing))
3290
 
    goto flushing;
3291
 
 
 
3306
  GST_OBJECT_LOCK (basesrc);
3292
3307
  while (GST_BASE_SRC_IS_STARTING (basesrc)) {
3293
 
    GST_LIVE_WAIT (basesrc);
3294
 
    if (G_UNLIKELY (basesrc->priv->flushing))
3295
 
      goto flushing;
 
3308
    GST_ASYNC_WAIT (basesrc);
3296
3309
  }
3297
3310
  result = basesrc->priv->start_result;
3298
 
  GST_LIVE_UNLOCK (basesrc);
 
3311
  GST_OBJECT_UNLOCK (basesrc);
 
3312
 
 
3313
  GST_DEBUG_OBJECT (basesrc, "got %s", gst_flow_get_name (result));
3299
3314
 
3300
3315
  return result;
3301
 
 
3302
 
  /* ERRORS */
3303
 
flushing:
3304
 
  {
3305
 
    GST_DEBUG_OBJECT (basesrc, "we are flushing");
3306
 
    GST_LIVE_UNLOCK (basesrc);
3307
 
    return GST_FLOW_FLUSHING;
3308
 
  }
3309
3316
}
3310
3317
 
3311
3318
static gboolean
3321
3328
  /* stop the task */
3322
3329
  gst_pad_stop_task (basesrc->srcpad);
3323
3330
 
3324
 
  GST_LIVE_LOCK (basesrc);
 
3331
  GST_OBJECT_LOCK (basesrc);
3325
3332
  if (!GST_BASE_SRC_IS_STARTED (basesrc) && !GST_BASE_SRC_IS_STARTING (basesrc))
3326
3333
    goto was_stopped;
3327
3334
 
3328
3335
  GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTING);
3329
3336
  GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_FLAG_STARTED);
3330
3337
  basesrc->priv->start_result = GST_FLOW_FLUSHING;
3331
 
  GST_LIVE_SIGNAL (basesrc);
3332
 
  GST_LIVE_UNLOCK (basesrc);
 
3338
  GST_ASYNC_SIGNAL (basesrc);
 
3339
  GST_OBJECT_UNLOCK (basesrc);
3333
3340
 
3334
3341
  bclass = GST_BASE_SRC_GET_CLASS (basesrc);
3335
3342
  if (bclass->stop)
3342
3349
was_stopped:
3343
3350
  {
3344
3351
    GST_DEBUG_OBJECT (basesrc, "was started");
3345
 
    GST_LIVE_UNLOCK (basesrc);
 
3352
    GST_OBJECT_UNLOCK (basesrc);
3346
3353
    return TRUE;
3347
3354
  }
3348
3355
}