~ubuntu-branches/ubuntu/hardy/gstreamer0.10/hardy-updates

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2007-11-16 18:15:06 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20071116181506-jm07yi8zgtklco5q
Tags: 0.10.15-1ubuntu1
* Sync with Debian, remaining Ubuntu changes:
  + debian/control.in:
    - Set Ubuntu Core Developers as Maintainer.
    - Add Breaks field to libgstreamer0.10-0 for
      libgstreamer-plugins-base0.10-0.
  + debian/patches/80_ia32-hack.patch:
    - Set the plugin dir to /usr/lib32/gstreamer-0.10, when running the
      i386 binaries on amd64.
  + debian/rules:
    - Set the package origin and url for Ubuntu.
    - Symlink the doc directories to avoid duplicate files and remove
      the old ones on upgrade.

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
 * to the #GstBaseSrc::create function.
82
82
 * </para>
83
83
 * <para>
84
 
 * #GstBaseSrc has support for live sources. Live sources are sources that 
85
 
 * produce data at a fixed rate, such as audio or video capture devices. A 
86
 
 * typical live source also provides a clock to publish the rate at which 
87
 
 * they produce data.
 
84
 * #GstBaseSrc has support for live sources. Live sources are sources that when
 
85
 * paused discard data, such as audio or video capture devices. A typical live
 
86
 * source also produces data at a fixed rate and thus provides a clock to publish
 
87
 * this rate.
88
88
 * Use gst_base_src_set_live() to activate the live source mode.
89
89
 * </para>
90
90
 * <para>
95
95
 * </para>
96
96
 * <para>
97
97
 * A typical live source will timestamp the buffers it creates with the 
98
 
 * current stream time of the pipeline. This is one reason why a live source
 
98
 * current running time of the pipeline. This is one reason why a live source
99
99
 * can only produce data in the PLAYING state, when the clock is actually 
100
 
 * distributed and running.
 
100
 * distributed and running. 
101
101
 * </para>
102
102
 * <para>
103
 
 * Live sources that synchronize and block on the clock (and audio source, for
 
103
 * Live sources that synchronize and block on the clock (an audio source, for
104
104
 * example) can since 0.10.12 use gst_base_src_wait_playing() when the ::create
105
105
 * function was interrupted by a state change to PAUSED.
106
106
 * </para>
107
107
 * <para>
108
108
 * The #GstBaseSrc::get_times method can be used to implement pseudo-live 
109
 
 * sources. The base source will wait for the specified stream time returned in 
110
 
 * #GstBaseSrc::get_times before pushing out the buffer. 
 
109
 * sources.
111
110
 * It only makes sense to implement the ::get_times function if the source is 
112
 
 * a live source.
 
111
 * a live source. The ::get_times function should return timestamps starting
 
112
 * from 0, as if it were a non-live source. The base class will make sure that
 
113
 * the timestamps are transformed into the current running_time.
 
114
 * The base source will then wait for the calculated running_time before pushing
 
115
 * out the buffer.
 
116
 * </para>
 
117
 * <para>
 
118
 * For live sources, the base class will by default report a latency of 0.
 
119
 * For pseudo live sources, the base class will by default measure the difference
 
120
 * between the first buffer timestamp and the start time of get_times and will
 
121
 * report this value as the latency. 
 
122
 * Subclasses should override the query function when this behaviour is not
 
123
 * acceptable.
113
124
 * </para>
114
125
 * <para>
115
126
 * There is only support in #GstBaseSrc for exactly one source pad, which 
172
183
 * thread might be blocked in PREROLL.
173
184
 * </para>
174
185
 * <para>
175
 
 * Last reviewed on 2006-09-27 (0.10.11)
 
186
 * Last reviewed on 2007-09-13 (0.10.15)
176
187
 * </para>
177
188
 * </refsect2>
178
189
 */
213
224
#define DEFAULT_BLOCKSIZE       4096
214
225
#define DEFAULT_NUM_BUFFERS     -1
215
226
#define DEFAULT_TYPEFIND        FALSE
 
227
#define DEFAULT_DO_TIMESTAMP    FALSE
216
228
 
217
229
enum
218
230
{
220
232
  PROP_BLOCKSIZE,
221
233
  PROP_NUM_BUFFERS,
222
234
  PROP_TYPEFIND,
 
235
  PROP_DO_TIMESTAMP
223
236
};
224
237
 
225
238
#define GST_BASE_SRC_GET_PRIVATE(obj)  \
230
243
  gboolean last_sent_eos;       /* last thing we did was send an EOS (we set this
231
244
                                 * to avoid the sending of two EOS in some cases) */
232
245
  gboolean discont;
 
246
  gboolean flushing;
233
247
 
234
248
  /* two segments to be sent in the streaming thread with STREAM_LOCK */
235
249
  GstEvent *close_segment;
236
250
  GstEvent *start_segment;
 
251
 
 
252
  /* startup latency is the time it takes between going to PLAYING and producing
 
253
   * the first BUFFER with running_time 0. This value is included in the latency
 
254
   * reporting. */
 
255
  GstClockTime latency;
 
256
  /* timestamp offset, this is the offset add to the values of gst_times for
 
257
   * pseudo live sources */
 
258
  GstClockTimeDiff ts_offset;
 
259
 
 
260
  gboolean do_timestamp;
237
261
};
238
262
 
239
263
static GstElementClass *parent_class = NULL;
291
315
static gboolean gst_base_src_default_prepare_seek_segment (GstBaseSrc * src,
292
316
    GstEvent * event, GstSegment * segment);
293
317
 
294
 
static gboolean gst_base_src_unlock (GstBaseSrc * basesrc);
295
 
static gboolean gst_base_src_unlock_stop (GstBaseSrc * basesrc);
 
318
static gboolean gst_base_src_set_flushing (GstBaseSrc * basesrc,
 
319
    gboolean flushing, gboolean live_play, gboolean unlock, gboolean * playing);
296
320
static gboolean gst_base_src_start (GstBaseSrc * basesrc);
297
321
static gboolean gst_base_src_stop (GstBaseSrc * basesrc);
298
322
 
342
366
      g_param_spec_boolean ("typefind", "Typefind",
343
367
          "Run typefind before negotiating", DEFAULT_TYPEFIND,
344
368
          G_PARAM_READWRITE));
 
369
  g_object_class_install_property (gobject_class, PROP_DO_TIMESTAMP,
 
370
      g_param_spec_boolean ("do-timestamp", "Do timestamp",
 
371
          "Apply current stream time to buffers", DEFAULT_DO_TIMESTAMP,
 
372
          G_PARAM_READWRITE));
345
373
 
346
374
  gstelement_class->change_state =
347
375
      GST_DEBUG_FUNCPTR (gst_base_src_change_state);
410
438
  /* we operate in BYTES by default */
411
439
  gst_base_src_set_format (basesrc, GST_FORMAT_BYTES);
412
440
  basesrc->data.ABI.typefind = DEFAULT_TYPEFIND;
 
441
  basesrc->priv->do_timestamp = DEFAULT_DO_TIMESTAMP;
413
442
 
414
443
  GST_OBJECT_FLAG_UNSET (basesrc, GST_BASE_SRC_STARTED);
415
444
 
428
457
  g_cond_free (basesrc->live_cond);
429
458
 
430
459
  event_p = &basesrc->data.ABI.pending_seek;
431
 
  gst_event_replace ((GstEvent **) event_p, NULL);
 
460
  gst_event_replace (event_p, NULL);
432
461
 
433
462
  G_OBJECT_CLASS (parent_class)->finalize (object);
434
463
}
455
484
gst_base_src_wait_playing (GstBaseSrc * src)
456
485
{
457
486
  /* block until the state changes, or we get a flush, or something */
458
 
  GST_LIVE_LOCK (src);
459
487
  if (src->is_live) {
460
488
    while (G_UNLIKELY (!src->live_running)) {
461
489
      GST_DEBUG ("live source signal waiting");
464
492
      GST_LIVE_WAIT (src);
465
493
      GST_DEBUG ("live source unlocked");
466
494
    }
467
 
    /* FIXME, use another variable to signal stopping so that we don't
468
 
     * have to grab another lock. */
469
 
    GST_OBJECT_LOCK (src->srcpad);
470
 
    if (G_UNLIKELY (GST_PAD_IS_FLUSHING (src->srcpad)))
 
495
    if (src->priv->flushing)
471
496
      goto flushing;
472
 
    GST_OBJECT_UNLOCK (src->srcpad);
473
497
  }
474
 
  GST_LIVE_UNLOCK (src);
475
498
 
476
499
  return GST_FLOW_OK;
477
500
 
478
501
  /* ERRORS */
479
502
flushing:
480
503
  {
481
 
    GST_DEBUG_OBJECT (src, "pad is flushing");
482
 
    GST_OBJECT_UNLOCK (src->srcpad);
483
 
    GST_LIVE_UNLOCK (src);
 
504
    GST_DEBUG_OBJECT (src, "we are flushing");
484
505
    return GST_FLOW_WRONG_STATE;
485
506
  }
486
507
}
502
523
void
503
524
gst_base_src_set_live (GstBaseSrc * src, gboolean live)
504
525
{
505
 
  GST_LIVE_LOCK (src);
 
526
  GST_OBJECT_LOCK (src);
506
527
  src->is_live = live;
507
 
  GST_LIVE_UNLOCK (src);
 
528
  GST_OBJECT_UNLOCK (src);
508
529
}
509
530
 
510
531
/**
520
541
{
521
542
  gboolean result;
522
543
 
523
 
  GST_LIVE_LOCK (src);
 
544
  GST_OBJECT_LOCK (src);
524
545
  result = src->is_live;
525
 
  GST_LIVE_UNLOCK (src);
 
546
  GST_OBJECT_UNLOCK (src);
526
547
 
527
548
  return result;
528
549
}
538
559
 * If a format of GST_FORMAT_BYTES is set, the element will be able to
539
560
 * operate in pull mode if the #GstBaseSrc::is_seekable returns TRUE.
540
561
 *
541
 
 * @Since: 0.10.1
 
562
 * Since: 0.10.1
542
563
 */
543
564
void
544
565
gst_base_src_set_format (GstBaseSrc * src, GstFormat format)
554
575
 * @max_latency: the max latency of the source
555
576
 *
556
577
 * Query the source for the latency parameters. @live will be TRUE when @src is
557
 
 * configured as a live source. @min_latency will be set as the latency between
558
 
 * calling the create function and the timestamp on the resulting buffer.
 
578
 * configured as a live source. @min_latency will be set to the difference
 
579
 * between the running time and the timestamp of the first buffer.
559
580
 * @max_latency is always the undefined value of -1.
560
581
 *
561
582
 * This function is mostly used by subclasses. 
568
589
gst_base_src_query_latency (GstBaseSrc * src, gboolean * live,
569
590
    GstClockTime * min_latency, GstClockTime * max_latency)
570
591
{
571
 
  GST_LIVE_LOCK (src);
 
592
  GstClockTime min;
 
593
 
 
594
  GST_OBJECT_LOCK (src);
572
595
  if (live)
573
596
    *live = src->is_live;
 
597
 
 
598
  /* if we have a startup latency, report this one, else report 0. Subclasses
 
599
   * are supposed to override the query function if they want something
 
600
   * else. */
 
601
  if (src->priv->latency != -1)
 
602
    min = src->priv->latency;
 
603
  else
 
604
    min = 0;
 
605
 
574
606
  if (min_latency)
575
 
    *min_latency = 0;
 
607
    *min_latency = min;
576
608
  if (max_latency)
577
609
    *max_latency = -1;
578
 
  GST_LIVE_UNLOCK (src);
 
610
 
 
611
  GST_LOG_OBJECT (src, "latency: live %d, min %" GST_TIME_FORMAT
 
612
      ", max %" GST_TIME_FORMAT, src->is_live, GST_TIME_ARGS (min),
 
613
      GST_TIME_ARGS (-1));
 
614
  GST_OBJECT_UNLOCK (src);
579
615
 
580
616
  return TRUE;
581
617
}
582
618
 
 
619
/**
 
620
 * gst_base_src_set_do_timestamp:
 
621
 * @src: the source
 
622
 * @timestamp: enable or disable timestamping
 
623
 *
 
624
 * Configure @src to automatically timestamp outgoing buffers based on the
 
625
 * current running_time of the pipeline. This property is mostly useful for live
 
626
 * sources.
 
627
 *
 
628
 * Since: 0.10.15
 
629
 */
 
630
void
 
631
gst_base_src_set_do_timestamp (GstBaseSrc * src, gboolean timestamp)
 
632
{
 
633
  GST_OBJECT_LOCK (src);
 
634
  src->priv->do_timestamp = timestamp;
 
635
  GST_OBJECT_UNLOCK (src);
 
636
}
 
637
 
 
638
/**
 
639
 * gst_base_src_get_do_timestamp:
 
640
 * @src: the source
 
641
 *
 
642
 * Query if @src timestamps outgoing buffers based on the current running_time.
 
643
 *
 
644
 * Returns: %TRUE if the base class will automatically timestamp outgoing buffers.
 
645
 *
 
646
 * Since: 0.10.15
 
647
 */
 
648
gboolean
 
649
gst_base_src_get_do_timestamp (GstBaseSrc * src)
 
650
{
 
651
  gboolean res;
 
652
 
 
653
  GST_OBJECT_LOCK (src);
 
654
  res = src->priv->do_timestamp;
 
655
  GST_OBJECT_UNLOCK (src);
 
656
 
 
657
  return res;
 
658
}
 
659
 
583
660
static gboolean
584
661
gst_base_src_setcaps (GstPad * pad, GstCaps * caps)
585
662
{
707
784
        {
708
785
          gint64 duration;
709
786
 
 
787
          /* this is the duration as configured by the subclass. */
710
788
          duration = src->segment.duration;
711
789
 
712
790
          if (duration != -1) {
713
 
            /* convert to requested format */
 
791
            /* convert to requested format, if this fails, we have a duration
 
792
             * but we cannot answer the query, we must return FALSE. */
714
793
            res =
715
794
                gst_pad_query_convert (src->srcpad, src->segment.format,
716
795
                duration, &format, &duration);
717
796
          } else {
 
797
            /* The subclass did not configure a duration, we assume that the
 
798
             * media has an unknown duration then and we return TRUE to report
 
799
             * this. Note that this is not the same as returning FALSE, which
 
800
             * means that we cannot report the duration at all. */
718
801
            res = TRUE;
719
802
          }
720
803
          gst_query_set_duration (query, format, duration);
784
867
      /* Subclasses should override and implement something usefull */
785
868
      res = gst_base_src_query_latency (src, &live, &min, &max);
786
869
 
 
870
      GST_LOG_OBJECT (src, "report latency: live %d, min %" GST_TIME_FORMAT
 
871
          ", max %" GST_TIME_FORMAT, live, GST_TIME_ARGS (min),
 
872
          GST_TIME_ARGS (max));
 
873
 
787
874
      gst_query_set_latency (query, live, min, max);
788
875
      break;
789
876
    }
944
1031
 * acquire the STREAM_LOCK which is taken when we are in the
945
1032
 * _loop() function or when a getrange() is called. Normally
946
1033
 * we will not receive a seek if we are operating in pull mode
947
 
 * though.
 
1034
 * though. When we operate as a live source we might block on the live
 
1035
 * cond, which does not release the STREAM_LOCK. Therefore we will try
 
1036
 * to grab the LIVE_LOCK instead of the STREAM_LOCK to make sure it is
 
1037
 * safe to perform the seek.
948
1038
 *
949
1039
 * When we are in the loop() function, we might be in the middle
950
1040
 * of pushing a buffer, which might block in a sink. To make sure
957
1047
 * blocks on the sample we might wait a very long time until the sink
958
1048
 * unblocks the sample. In any case we acquire the STREAM_LOCK and
959
1049
 * can continue the seek. A non-flushing seek is normally done in a 
960
 
 * running pipeline to perform seamless playback.
 
1050
 * running pipeline to perform seamless playback, this means that the sink is
 
1051
 * PLAYING and will return from its chain function.
961
1052
 * In the case of a non-flushing seek we need to make sure that the
962
1053
 * data we output after the seek is continuous with the previous data,
963
 
 * this is because a non-flushing seek does not reset the stream-time
 
1054
 * this is because a non-flushing seek does not reset the running-time
964
1055
 * to 0. We do this by closing the currently running segment, ie. sending
965
1056
 * a new_segment event with the stop position set to the last processed 
966
1057
 * position.
990
1081
  GstSeekFlags flags;
991
1082
  GstSeekType cur_type, stop_type;
992
1083
  gint64 cur, stop;
993
 
  gboolean flush;
 
1084
  gboolean flush, playing;
994
1085
  gboolean update;
995
1086
  gboolean relative_seek = FALSE;
996
1087
  gboolean seekseg_configured = FALSE;
1030
1121
  else
1031
1122
    gst_pad_pause_task (src->srcpad);
1032
1123
 
1033
 
  /* unblock streaming thread */
1034
 
  if (unlock)
1035
 
    gst_base_src_unlock (src);
 
1124
  /* unblock streaming thread. */
 
1125
  gst_base_src_set_flushing (src, TRUE, FALSE, unlock, &playing);
1036
1126
 
1037
1127
  /* grab streaming lock, this should eventually be possible, either
1038
 
   * because the task is paused or our streaming thread stopped 
1039
 
   * because our peer is flushing. */
 
1128
   * because the task is paused, our streaming thread stopped 
 
1129
   * or because our peer is flushing. */
1040
1130
  GST_PAD_STREAM_LOCK (src->srcpad);
1041
1131
 
1042
 
  if (unlock)
1043
 
    gst_base_src_unlock_stop (src);
 
1132
  gst_base_src_set_flushing (src, FALSE, playing, unlock, NULL);
1044
1133
 
1045
1134
  /* If we configured the seeksegment above, don't overwrite it now. Otherwise
1046
1135
   * copy the current segment info into the temp segment that we can actually
1174
1263
  return query_types;
1175
1264
}
1176
1265
 
1177
 
/* all events send to this element directly
 
1266
/* all events send to this element directly. This is mainly done from the
 
1267
 * application.
1178
1268
 */
1179
1269
static gboolean
1180
1270
gst_base_src_send_event (GstElement * element, GstEvent * event)
1185
1275
  src = GST_BASE_SRC (element);
1186
1276
 
1187
1277
  switch (GST_EVENT_TYPE (event)) {
 
1278
      /* bidirectional events */
1188
1279
    case GST_EVENT_FLUSH_START:
1189
1280
    case GST_EVENT_FLUSH_STOP:
1190
1281
      /* sending random flushes downstream can break stuff,
1191
1282
       * especially sync since all segment info will get flushed */
1192
1283
      break;
 
1284
 
 
1285
      /* downstream serialized events */
1193
1286
    case GST_EVENT_EOS:
1194
1287
      /* FIXME, queue EOS and make sure the task or pull function 
1195
1288
       * perform the EOS actions. */
1198
1291
      /* sending random NEWSEGMENT downstream can break sync. */
1199
1292
      break;
1200
1293
    case GST_EVENT_TAG:
 
1294
      /* sending tags could be useful, FIXME insert in dataflow */
 
1295
      break;
1201
1296
    case GST_EVENT_BUFFERSIZE:
 
1297
      /* does not seem to make much sense currently */
1202
1298
      break;
 
1299
 
 
1300
      /* upstream events */
1203
1301
    case GST_EVENT_QOS:
 
1302
      /* elements should override send_event and do something */
1204
1303
      break;
1205
1304
    case GST_EVENT_SEEK:
1206
1305
    {
1231
1330
      break;
1232
1331
    }
1233
1332
    case GST_EVENT_NAVIGATION:
 
1333
      /* could make sense for elements that do something with navigation events
 
1334
       * but then they would need to override the send_event function */
 
1335
      break;
 
1336
    case GST_EVENT_LATENCY:
 
1337
      /* does not seem to make sense currently */
 
1338
      break;
 
1339
 
 
1340
      /* custom events */
 
1341
    case GST_EVENT_CUSTOM_UPSTREAM:
 
1342
      /* override send_event if you want this */
 
1343
      break;
 
1344
    case GST_EVENT_CUSTOM_DOWNSTREAM:
 
1345
    case GST_EVENT_CUSTOM_BOTH:
 
1346
      /* FIXME, insert event in the dataflow */
 
1347
      break;
 
1348
    case GST_EVENT_CUSTOM_DOWNSTREAM_OOB:
 
1349
    case GST_EVENT_CUSTOM_BOTH_OOB:
 
1350
      /* insert a random custom event into the pipeline */
 
1351
      GST_DEBUG_OBJECT (src, "pushing custom OOB event downstream");
 
1352
      result = gst_pad_push_event (src->srcpad, event);
 
1353
      /* we gave away the ref to the event in the push */
 
1354
      event = NULL;
1234
1355
      break;
1235
1356
    default:
1236
1357
      break;
1237
1358
  }
1238
1359
done:
1239
 
  gst_event_unref (event);
 
1360
  /* if we still have a ref to the event, unref it now */
 
1361
  if (event)
 
1362
    gst_event_unref (event);
1240
1363
 
1241
1364
  return result;
1242
1365
 
1266
1389
    case GST_EVENT_FLUSH_START:
1267
1390
      /* cancel any blocking getrange, is normally called
1268
1391
       * when in pull mode. */
1269
 
      result = gst_base_src_unlock (src);
 
1392
      result = gst_base_src_set_flushing (src, TRUE, FALSE, TRUE, NULL);
1270
1393
      break;
1271
1394
    case GST_EVENT_FLUSH_STOP:
1272
 
      result = gst_base_src_unlock_stop (src);
 
1395
      result = gst_base_src_set_flushing (src, FALSE, TRUE, TRUE, NULL);
1273
1396
      break;
1274
1397
    default:
1275
1398
      result = TRUE;
1332
1455
    case PROP_TYPEFIND:
1333
1456
      src->data.ABI.typefind = g_value_get_boolean (value);
1334
1457
      break;
 
1458
    case PROP_DO_TIMESTAMP:
 
1459
      src->priv->do_timestamp = g_value_get_boolean (value);
 
1460
      break;
1335
1461
    default:
1336
1462
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1337
1463
      break;
1356
1482
    case PROP_TYPEFIND:
1357
1483
      g_value_set_boolean (value, src->data.ABI.typefind);
1358
1484
      break;
 
1485
    case PROP_DO_TIMESTAMP:
 
1486
      g_value_set_boolean (value, src->priv->do_timestamp);
 
1487
      break;
1359
1488
    default:
1360
1489
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1361
1490
      break;
1364
1493
 
1365
1494
/* with STREAM_LOCK and LOCK */
1366
1495
static GstClockReturn
1367
 
gst_base_src_wait (GstBaseSrc * basesrc, GstClockTime time)
 
1496
gst_base_src_wait (GstBaseSrc * basesrc, GstClock * clock, GstClockTime time)
1368
1497
{
1369
1498
  GstClockReturn ret;
1370
1499
  GstClockID id;
1371
 
  GstClock *clock;
1372
 
 
1373
 
  /* get clock, if no clock, we don't sync */
1374
 
  if ((clock = GST_ELEMENT_CLOCK (basesrc)) == NULL)
1375
 
    return GST_CLOCK_OK;
1376
1500
 
1377
1501
  id = gst_clock_new_single_shot_id (clock, time);
1378
1502
 
1379
1503
  basesrc->clock_id = id;
1380
 
  /* release the object lock while waiting */
1381
 
  GST_OBJECT_UNLOCK (basesrc);
 
1504
  /* release the live lock while waiting */
 
1505
  GST_LIVE_UNLOCK (basesrc);
1382
1506
 
1383
1507
  ret = gst_clock_id_wait (id, NULL);
1384
1508
 
1385
 
  GST_OBJECT_LOCK (basesrc);
 
1509
  GST_LIVE_LOCK (basesrc);
1386
1510
  gst_clock_id_unref (id);
1387
1511
  basesrc->clock_id = NULL;
1388
1512
 
1399
1523
  GstClockTime start, end;
1400
1524
  GstBaseSrcClass *bclass;
1401
1525
  GstClockTime base_time;
 
1526
  GstClock *clock;
 
1527
  GstClockTime now = GST_CLOCK_TIME_NONE, timestamp;
 
1528
  gboolean do_timestamp, first, pseudo_live;
1402
1529
 
1403
1530
  bclass = GST_BASE_SRC_GET_CLASS (basesrc);
1404
1531
 
1406
1533
  if (bclass->get_times)
1407
1534
    bclass->get_times (basesrc, buffer, &start, &end);
1408
1535
 
1409
 
  /* if we don't have a timestamp, we don't sync */
 
1536
  /* get buffer timestamp */
 
1537
  timestamp = GST_BUFFER_TIMESTAMP (buffer);
 
1538
 
 
1539
  /* grab the lock to prepare for clocking and calculate the startup 
 
1540
   * latency. */
 
1541
  GST_OBJECT_LOCK (basesrc);
 
1542
 
 
1543
  /* if we are asked to sync against the clock we are a pseudo live element */
 
1544
  pseudo_live = (start != -1 && basesrc->is_live);
 
1545
  /* check for the first buffer */
 
1546
  first = (basesrc->priv->latency == -1);
 
1547
 
 
1548
  if (timestamp != -1 && pseudo_live) {
 
1549
    GstClockTime latency;
 
1550
 
 
1551
    /* we have a timestamp and a sync time, latency is the diff */
 
1552
    if (timestamp <= start)
 
1553
      latency = start - timestamp;
 
1554
    else
 
1555
      latency = 0;
 
1556
 
 
1557
    if (first) {
 
1558
      GST_DEBUG_OBJECT (basesrc, "pseudo_live with latency %" GST_TIME_FORMAT,
 
1559
          GST_TIME_ARGS (latency));
 
1560
      /* first time we calculate latency, just configure */
 
1561
      basesrc->priv->latency = latency;
 
1562
    } else {
 
1563
      if (basesrc->priv->latency != latency) {
 
1564
        /* we have a new latency, FIXME post latency message */
 
1565
        basesrc->priv->latency = latency;
 
1566
        GST_DEBUG_OBJECT (basesrc, "latency changed to %" GST_TIME_FORMAT,
 
1567
            GST_TIME_ARGS (latency));
 
1568
      }
 
1569
    }
 
1570
  } else if (first) {
 
1571
    GST_DEBUG_OBJECT (basesrc, "no latency needed, live %d, sync %d",
 
1572
        basesrc->is_live, start != -1);
 
1573
    basesrc->priv->latency = 0;
 
1574
  }
 
1575
 
 
1576
  /* get clock, if no clock, we can't sync or do timestamps */
 
1577
  if ((clock = GST_ELEMENT_CLOCK (basesrc)) == NULL)
 
1578
    goto no_clock;
 
1579
 
 
1580
  base_time = GST_ELEMENT_CAST (basesrc)->base_time;
 
1581
 
 
1582
  do_timestamp = basesrc->priv->do_timestamp;
 
1583
 
 
1584
  /* first buffer, calculate the timestamp offset */
 
1585
  if (first) {
 
1586
    GstClockTime running_time;
 
1587
 
 
1588
    now = gst_clock_get_time (clock);
 
1589
    running_time = now - base_time;
 
1590
 
 
1591
    GST_LOG_OBJECT (basesrc,
 
1592
        "startup timestamp: %" GST_TIME_FORMAT ", running_time %"
 
1593
        GST_TIME_FORMAT, GST_TIME_ARGS (timestamp),
 
1594
        GST_TIME_ARGS (running_time));
 
1595
 
 
1596
    if (pseudo_live && timestamp != -1) {
 
1597
      /* live source and we need to sync, add startup latency to all timestamps
 
1598
       * to get the real running_time. Live sources should always timestamp
 
1599
       * according to the current running time. */
 
1600
      basesrc->priv->ts_offset = GST_CLOCK_DIFF (timestamp, running_time);
 
1601
 
 
1602
      GST_LOG_OBJECT (basesrc, "live with sync, ts_offset %" GST_TIME_FORMAT,
 
1603
          GST_TIME_ARGS (basesrc->priv->ts_offset));
 
1604
    } else {
 
1605
      basesrc->priv->ts_offset = 0;
 
1606
      GST_LOG_OBJECT (basesrc, "no timestamp offset needed");
 
1607
    }
 
1608
 
 
1609
    if (!GST_CLOCK_TIME_IS_VALID (timestamp)) {
 
1610
      if (do_timestamp)
 
1611
        timestamp = running_time;
 
1612
      else
 
1613
        timestamp = 0;
 
1614
 
 
1615
      GST_BUFFER_TIMESTAMP (buffer) = timestamp;
 
1616
 
 
1617
      GST_LOG_OBJECT (basesrc, "created timestamp: %" GST_TIME_FORMAT,
 
1618
          GST_TIME_ARGS (timestamp));
 
1619
    }
 
1620
 
 
1621
    /* add the timestamp offset we need for sync */
 
1622
    timestamp += basesrc->priv->ts_offset;
 
1623
  } else {
 
1624
    /* not the first buffer, the timestamp is the diff between the clock and
 
1625
     * base_time */
 
1626
    if (do_timestamp && !GST_CLOCK_TIME_IS_VALID (timestamp)) {
 
1627
      now = gst_clock_get_time (clock);
 
1628
 
 
1629
      GST_BUFFER_TIMESTAMP (buffer) = now - base_time;
 
1630
 
 
1631
      GST_LOG_OBJECT (basesrc, "created timestamp: %" GST_TIME_FORMAT,
 
1632
          GST_TIME_ARGS (now - base_time));
 
1633
    }
 
1634
  }
 
1635
 
 
1636
  /* if we don't have a buffer timestamp, we don't sync */
1410
1637
  if (!GST_CLOCK_TIME_IS_VALID (start))
1411
 
    goto invalid_start;
 
1638
    goto no_sync;
1412
1639
 
1413
 
  /* now do clocking */
1414
 
  GST_OBJECT_LOCK (basesrc);
1415
 
  base_time = GST_ELEMENT_CAST (basesrc)->base_time;
 
1640
  if (basesrc->is_live && GST_CLOCK_TIME_IS_VALID (timestamp)) {
 
1641
    /* for pseudo live sources, add our ts_offset to the timestamp */
 
1642
    GST_BUFFER_TIMESTAMP (buffer) += basesrc->priv->ts_offset;
 
1643
    start += basesrc->priv->ts_offset;
 
1644
  }
1416
1645
 
1417
1646
  GST_LOG_OBJECT (basesrc,
1418
1647
      "waiting for clock, base time %" GST_TIME_FORMAT
1419
1648
      ", stream_start %" GST_TIME_FORMAT,
1420
1649
      GST_TIME_ARGS (base_time), GST_TIME_ARGS (start));
1421
 
 
1422
 
  result = gst_base_src_wait (basesrc, start + base_time);
1423
1650
  GST_OBJECT_UNLOCK (basesrc);
1424
1651
 
 
1652
  result = gst_base_src_wait (basesrc, clock, start + base_time);
 
1653
 
1425
1654
  GST_LOG_OBJECT (basesrc, "clock entry done: %d", result);
1426
1655
 
1427
1656
  return result;
1428
1657
 
1429
1658
  /* special cases */
1430
 
invalid_start:
1431
 
  {
1432
 
    GST_DEBUG_OBJECT (basesrc, "get_times returned invalid start");
 
1659
no_clock:
 
1660
  {
 
1661
    GST_DEBUG_OBJECT (basesrc, "we have no clock");
 
1662
    GST_OBJECT_UNLOCK (basesrc);
 
1663
    return GST_CLOCK_OK;
 
1664
  }
 
1665
no_sync:
 
1666
  {
 
1667
    GST_DEBUG_OBJECT (basesrc, "no sync needed");
 
1668
    GST_OBJECT_UNLOCK (basesrc);
1433
1669
    return GST_CLOCK_OK;
1434
1670
  }
1435
1671
}
1504
1740
  }
1505
1741
}
1506
1742
 
 
1743
/* must be called with LIVE_LOCK */
1507
1744
static GstFlowReturn
1508
1745
gst_base_src_get_range (GstBaseSrc * src, guint64 offset, guint length,
1509
1746
    GstBuffer ** buf)
1541
1778
 
1542
1779
  ret = bclass->create (src, offset, length, buf);
1543
1780
  if (G_UNLIKELY (ret != GST_FLOW_OK))
1544
 
    goto done;
 
1781
    goto not_ok;
1545
1782
 
1546
1783
  /* no timestamp set and we are at offset 0, we can timestamp with 0 */
1547
1784
  if (offset == 0 && src->segment.time == 0
1550
1787
 
1551
1788
  /* now sync before pushing the buffer */
1552
1789
  status = gst_base_src_do_sync (src, *buf);
 
1790
 
 
1791
  /* waiting for the clock could have made us flushing */
 
1792
  if (src->priv->flushing)
 
1793
    goto flushing;
 
1794
 
1553
1795
  switch (status) {
1554
1796
    case GST_CLOCK_EARLY:
1555
1797
      /* the buffer is too late. We currently don't drop the buffer. */
1580
1822
      ret = GST_FLOW_ERROR;
1581
1823
      break;
1582
1824
  }
1583
 
done:
1584
1825
  return ret;
1585
1826
 
1586
1827
  /* ERROR */
1587
1828
stopped:
1588
1829
  {
1589
 
    GST_DEBUG_OBJECT (src, "wait_playing returned %d", ret);
 
1830
    GST_DEBUG_OBJECT (src, "wait_playing returned %d (%s)", ret,
 
1831
        gst_flow_get_name (ret));
 
1832
    return ret;
 
1833
  }
 
1834
not_ok:
 
1835
  {
 
1836
    GST_DEBUG_OBJECT (src, "create returned %d (%s)", ret,
 
1837
        gst_flow_get_name (ret));
1590
1838
    return ret;
1591
1839
  }
1592
1840
not_started:
1610
1858
    GST_DEBUG_OBJECT (src, "sent all buffers");
1611
1859
    return GST_FLOW_UNEXPECTED;
1612
1860
  }
 
1861
flushing:
 
1862
  {
 
1863
    GST_DEBUG_OBJECT (src, "we are flushing");
 
1864
    gst_buffer_unref (*buf);
 
1865
    *buf = NULL;
 
1866
    return GST_FLOW_WRONG_STATE;
 
1867
  }
1613
1868
}
1614
1869
 
1615
1870
static GstFlowReturn
1621
1876
 
1622
1877
  src = GST_BASE_SRC (gst_pad_get_parent (pad));
1623
1878
 
 
1879
  GST_LIVE_LOCK (src);
 
1880
  if (src->priv->flushing)
 
1881
    goto flushing;
 
1882
 
1624
1883
  res = gst_base_src_get_range (src, offset, length, buf);
1625
1884
 
 
1885
done:
 
1886
  GST_LIVE_UNLOCK (src);
 
1887
 
1626
1888
  gst_object_unref (src);
1627
1889
 
1628
1890
  return res;
 
1891
 
 
1892
  /* ERRORS */
 
1893
flushing:
 
1894
  {
 
1895
    GST_DEBUG_OBJECT (src, "we are flushing");
 
1896
    res = GST_FLOW_WRONG_STATE;
 
1897
    goto done;
 
1898
  }
1629
1899
}
1630
1900
 
1631
1901
static gboolean
1700
1970
 
1701
1971
  src = GST_BASE_SRC (gst_pad_get_parent (pad));
1702
1972
 
 
1973
  GST_LIVE_LOCK (src);
 
1974
  if (src->priv->flushing)
 
1975
    goto flushing;
 
1976
 
1703
1977
  src->priv->last_sent_eos = FALSE;
1704
1978
 
1705
1979
  /* if we operate in bytes, we can calculate an offset */
1712
1986
  if (G_UNLIKELY (ret != GST_FLOW_OK)) {
1713
1987
    GST_INFO_OBJECT (src, "pausing after gst_base_src_get_range() = %s",
1714
1988
        gst_flow_get_name (ret));
 
1989
    GST_LIVE_UNLOCK (src);
1715
1990
    goto pause;
1716
1991
  }
1717
1992
  /* this should not happen */
1771
2046
    GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
1772
2047
    src->priv->discont = FALSE;
1773
2048
  }
 
2049
  GST_LIVE_UNLOCK (src);
1774
2050
 
1775
2051
  ret = gst_pad_push (pad, buf);
1776
2052
  if (G_UNLIKELY (ret != GST_FLOW_OK)) {
1790
2066
  return;
1791
2067
 
1792
2068
  /* special cases */
 
2069
flushing:
 
2070
  {
 
2071
    GST_DEBUG_OBJECT (src, "we are flushing");
 
2072
    GST_LIVE_UNLOCK (src);
 
2073
    ret = GST_FLOW_WRONG_STATE;
 
2074
    goto pause;
 
2075
  }
1793
2076
pause:
1794
2077
  {
1795
2078
    const gchar *reason = gst_flow_get_name (ret);
1824
2107
  {
1825
2108
    GST_ELEMENT_ERROR (src, STREAM, FAILED,
1826
2109
        (_("Internal data flow error.")), ("element returned NULL buffer"));
 
2110
    GST_LIVE_UNLOCK (src);
1827
2111
    /* we finished the segment on error */
1828
 
    src->data.ABI.running = FALSE;
1829
 
    gst_pad_pause_task (pad);
1830
 
    gst_pad_push_event (pad, gst_event_new_eos ());
1831
 
    src->priv->last_sent_eos = TRUE;
 
2112
    ret = GST_FLOW_ERROR;
1832
2113
    goto done;
1833
2114
  }
1834
2115
}
1835
2116
 
1836
 
/* this will always be called between start() and stop(). So you can rely on
1837
 
 * resources allocated by start() and freed from stop(). This needs to be added
1838
 
 * to the docs at some point. */
1839
 
static gboolean
1840
 
gst_base_src_unlock (GstBaseSrc * basesrc)
1841
 
{
1842
 
  GstBaseSrcClass *bclass;
1843
 
  gboolean result = TRUE;
1844
 
 
1845
 
  GST_DEBUG ("unlock");
1846
 
  /* unblock whatever the subclass is doing */
1847
 
  bclass = GST_BASE_SRC_GET_CLASS (basesrc);
1848
 
  if (bclass->unlock)
1849
 
    result = bclass->unlock (basesrc);
1850
 
 
1851
 
  GST_DEBUG ("unschedule clock");
1852
 
  /* and unblock the clock as well, if any */
1853
 
  GST_OBJECT_LOCK (basesrc);
1854
 
  if (basesrc->clock_id) {
1855
 
    gst_clock_id_unschedule (basesrc->clock_id);
1856
 
  }
1857
 
  GST_OBJECT_UNLOCK (basesrc);
1858
 
 
1859
 
  GST_DEBUG ("unlock done");
1860
 
 
1861
 
  return result;
1862
 
}
1863
 
 
1864
 
/* this will always be called between start() and stop(). So you can rely on
1865
 
 * resources allocated by start() and freed from stop(). This needs to be added
1866
 
 * to the docs at some point. */
1867
 
static gboolean
1868
 
gst_base_src_unlock_stop (GstBaseSrc * basesrc)
1869
 
{
1870
 
  GstBaseSrcClass *bclass;
1871
 
  gboolean result = TRUE;
1872
 
 
1873
 
  GST_DEBUG_OBJECT (basesrc, "unlock stop");
1874
 
 
1875
 
  /* Finish a previous unblock request, allowing subclasses to flush command
1876
 
   * queues or whatever they need to do */
1877
 
  bclass = GST_BASE_SRC_GET_CLASS (basesrc);
1878
 
  if (bclass->unlock_stop)
1879
 
    result = bclass->unlock_stop (basesrc);
1880
 
 
1881
 
  GST_DEBUG_OBJECT (basesrc, "unlock stop done");
1882
 
 
1883
 
  return result;
1884
 
}
1885
 
 
1886
2117
/* default negotiation code. 
1887
2118
 *
1888
2119
 * Take intersection between src and sink pads, take first
2087
2318
  return result;
2088
2319
}
2089
2320
 
2090
 
static gboolean
2091
 
gst_base_src_deactivate (GstBaseSrc * basesrc, GstPad * pad)
2092
 
{
2093
 
  gboolean result;
2094
 
 
2095
 
  GST_LIVE_LOCK (basesrc);
2096
 
  basesrc->live_running = TRUE;
2097
 
  GST_LIVE_SIGNAL (basesrc);
2098
 
  GST_LIVE_UNLOCK (basesrc);
2099
 
 
2100
 
  /* step 1, unblock clock sync (if any) */
2101
 
  result = gst_base_src_unlock (basesrc);
2102
 
 
2103
 
  /* step 2, make sure streaming finishes */
2104
 
  result &= gst_pad_stop_task (pad);
2105
 
 
2106
 
  /* step 3, clear the unblock condition */
2107
 
  result &= gst_base_src_unlock_stop (basesrc);
2108
 
 
2109
 
  return result;
 
2321
/* start or stop flushing dataprocessing 
 
2322
 */
 
2323
static gboolean
 
2324
gst_base_src_set_flushing (GstBaseSrc * basesrc,
 
2325
    gboolean flushing, gboolean live_play, gboolean unlock, gboolean * playing)
 
2326
{
 
2327
  GstBaseSrcClass *bclass;
 
2328
 
 
2329
  bclass = GST_BASE_SRC_GET_CLASS (basesrc);
 
2330
 
 
2331
  if (flushing && unlock) {
 
2332
    /* unlock any subclasses, we need to do this before grabbing the
 
2333
     * LIVE_LOCK since we hold this lock before going into ::create. We pass an
 
2334
     * unlock to the params because of backwards compat (see seek handler)*/
 
2335
    if (bclass->unlock)
 
2336
      bclass->unlock (basesrc);
 
2337
  }
 
2338
 
 
2339
  /* the live lock is released when we are blocked, waiting for playing or
 
2340
   * when we sync to the clock. */
 
2341
  GST_LIVE_LOCK (basesrc);
 
2342
  if (playing)
 
2343
    *playing = basesrc->live_running;
 
2344
  basesrc->priv->flushing = flushing;
 
2345
  if (flushing) {
 
2346
    /* if we are locked in the live lock, signal it to make it flush */
 
2347
    basesrc->live_running = TRUE;
 
2348
 
 
2349
    /* step 1, now that we have the LIVE lock, clear our unlock request */
 
2350
    if (bclass->unlock_stop)
 
2351
      bclass->unlock_stop (basesrc);
 
2352
 
 
2353
    /* step 2, unblock clock sync (if any) or any other blocking thing */
 
2354
    if (basesrc->clock_id)
 
2355
      gst_clock_id_unschedule (basesrc->clock_id);
 
2356
  } else {
 
2357
    /* signal the live source that it can start playing */
 
2358
    basesrc->live_running = live_play;
 
2359
  }
 
2360
  GST_LIVE_SIGNAL (basesrc);
 
2361
  GST_LIVE_UNLOCK (basesrc);
 
2362
 
 
2363
  return TRUE;
 
2364
}
 
2365
 
 
2366
/* the purpose of this function is to make sure that a live source blocks in the
 
2367
 * LIVE lock or leaves the LIVE lock and continues playing. */
 
2368
static gboolean
 
2369
gst_base_src_set_playing (GstBaseSrc * basesrc, gboolean live_play)
 
2370
{
 
2371
  GstBaseSrcClass *bclass;
 
2372
 
 
2373
  bclass = GST_BASE_SRC_GET_CLASS (basesrc);
 
2374
 
 
2375
  /* unlock subclasses locked in ::create, we only do this when we stop playing. */
 
2376
  if (!live_play) {
 
2377
    GST_DEBUG_OBJECT (basesrc, "unlock");
 
2378
    if (bclass->unlock)
 
2379
      bclass->unlock (basesrc);
 
2380
  }
 
2381
 
 
2382
  /* we are now able to grab the LIVE lock, when we get it, we can be
 
2383
   * waiting for PLAYING while blocked in the LIVE cond or we can be waiting
 
2384
   * for the clock. */
 
2385
  GST_LIVE_LOCK (basesrc);
 
2386
 
 
2387
  /* unblock clock sync (if any) */
 
2388
  if (basesrc->clock_id)
 
2389
    gst_clock_id_unschedule (basesrc->clock_id);
 
2390
 
 
2391
  /* configure what to do when we get to the LIVE lock. */
 
2392
  basesrc->live_running = live_play;
 
2393
 
 
2394
  if (live_play) {
 
2395
    gboolean start;
 
2396
 
 
2397
    /* clear our unlock request when going to PLAYING */
 
2398
    GST_DEBUG_OBJECT (basesrc, "unlock stop");
 
2399
    if (bclass->unlock_stop)
 
2400
      bclass->unlock_stop (basesrc);
 
2401
 
 
2402
    /* for live sources we restart the timestamp correction */
 
2403
    basesrc->priv->latency = -1;
 
2404
    /* have to restart the task in case it stopped because of the unlock when
 
2405
     * we went to PAUSED. Only do this if we operating in push mode. */
 
2406
    GST_OBJECT_LOCK (basesrc->srcpad);
 
2407
    start = (GST_PAD_ACTIVATE_MODE (basesrc->srcpad) == GST_ACTIVATE_PUSH);
 
2408
    GST_OBJECT_UNLOCK (basesrc->srcpad);
 
2409
    if (start)
 
2410
      gst_pad_start_task (basesrc->srcpad, (GstTaskFunction) gst_base_src_loop,
 
2411
          basesrc->srcpad);
 
2412
  }
 
2413
  GST_LIVE_SIGNAL (basesrc);
 
2414
  GST_LIVE_UNLOCK (basesrc);
 
2415
 
 
2416
  return TRUE;
2110
2417
}
2111
2418
 
2112
2419
static gboolean
2128
2435
      goto error_start;
2129
2436
 
2130
2437
    basesrc->priv->last_sent_eos = FALSE;
 
2438
    basesrc->priv->discont = TRUE;
 
2439
    gst_base_src_set_flushing (basesrc, FALSE, FALSE, FALSE, NULL);
2131
2440
 
2132
2441
    /* do initial seek, which will start the task */
2133
2442
    GST_OBJECT_LOCK (basesrc);
2145
2454
      gst_event_unref (event);
2146
2455
  } else {
2147
2456
    GST_DEBUG_OBJECT (basesrc, "Deactivating in push mode");
2148
 
    /* call the unlock function and stop the task */
2149
 
    if (G_UNLIKELY (!gst_base_src_deactivate (basesrc, pad)))
2150
 
      goto deactivate_failed;
2151
 
 
 
2457
    /* flush all */
 
2458
    gst_base_src_set_flushing (basesrc, TRUE, FALSE, TRUE, NULL);
 
2459
    /* stop the task */
 
2460
    gst_pad_stop_task (pad);
2152
2461
    /* now we can stop the source */
2153
2462
    if (G_UNLIKELY (!gst_base_src_stop (basesrc)))
2154
2463
      goto error_stop;
2174
2483
      gst_event_unref (event);
2175
2484
    return FALSE;
2176
2485
  }
2177
 
deactivate_failed:
2178
 
  {
2179
 
    GST_ERROR_OBJECT (basesrc, "Failed to deactivate in push mode");
2180
 
    return FALSE;
2181
 
  }
2182
2486
error_stop:
2183
2487
  {
2184
2488
    GST_DEBUG_OBJECT (basesrc, "Failed to stop in push mode");
2202
2506
    /* if not random_access, we cannot operate in pull mode for now */
2203
2507
    if (G_UNLIKELY (!gst_base_src_check_get_range (basesrc)))
2204
2508
      goto no_get_range;
 
2509
 
 
2510
    /* stop flushing now but for live sources, still block in the LIVE lock when
 
2511
     * we are not yet PLAYING */
 
2512
    gst_base_src_set_flushing (basesrc, FALSE, FALSE, FALSE, NULL);
2205
2513
  } else {
2206
2514
    GST_DEBUG_OBJECT (basesrc, "Deactivating in pull mode");
2207
 
    /* call the unlock function. We have no task to stop. */
2208
 
    if (G_UNLIKELY (!gst_base_src_deactivate (basesrc, pad)))
2209
 
      goto deactivate_failed;
 
2515
    /* flush all, there is no task to stop */
 
2516
    gst_base_src_set_flushing (basesrc, TRUE, FALSE, TRUE, NULL);
2210
2517
 
2211
2518
    /* don't send EOS when going from PAUSED => READY when in pull mode */
2212
2519
    basesrc->priv->last_sent_eos = TRUE;
2228
2535
    gst_base_src_stop (basesrc);
2229
2536
    return FALSE;
2230
2537
  }
2231
 
deactivate_failed:
2232
 
  {
2233
 
    GST_ERROR_OBJECT (basesrc, "Failed to deactivate in pull mode");
2234
 
    return FALSE;
2235
 
  }
2236
2538
error_stop:
2237
2539
  {
2238
2540
    GST_ERROR_OBJECT (basesrc, "Failed to stop in pull mode");
2253
2555
    case GST_STATE_CHANGE_NULL_TO_READY:
2254
2556
      break;
2255
2557
    case GST_STATE_CHANGE_READY_TO_PAUSED:
2256
 
      GST_LIVE_LOCK (element);
2257
 
      if (basesrc->is_live) {
2258
 
        no_preroll = TRUE;
2259
 
        basesrc->live_running = FALSE;
2260
 
      }
2261
 
      basesrc->priv->last_sent_eos = FALSE;
2262
 
      basesrc->priv->discont = TRUE;
2263
 
      GST_LIVE_UNLOCK (element);
 
2558
      no_preroll = gst_base_src_is_live (basesrc);
2264
2559
      break;
2265
2560
    case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
2266
 
      GST_LIVE_LOCK (element);
2267
 
      if (basesrc->is_live) {
2268
 
        basesrc->live_running = TRUE;
2269
 
        GST_LIVE_SIGNAL (element);
 
2561
      if (gst_base_src_is_live (basesrc)) {
 
2562
        /* now we can start playback */
 
2563
        gst_base_src_set_playing (basesrc, TRUE);
2270
2564
      }
2271
 
      GST_LIVE_UNLOCK (element);
2272
2565
      break;
2273
2566
    default:
2274
2567
      break;
2281
2574
 
2282
2575
  switch (transition) {
2283
2576
    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
2284
 
      GST_LIVE_LOCK (element);
2285
 
      if (basesrc->is_live) {
 
2577
      if (gst_base_src_is_live (basesrc)) {
 
2578
        /* make sure we block in the live lock in PAUSED */
 
2579
        gst_base_src_set_playing (basesrc, FALSE);
2286
2580
        no_preroll = TRUE;
2287
 
        basesrc->live_running = FALSE;
2288
2581
      }
2289
 
      GST_LIVE_UNLOCK (element);
2290
2582
      break;
2291
2583
    case GST_STATE_CHANGE_PAUSED_TO_READY:
2292
2584
    {
2293
2585
      GstEvent **event_p;
2294
2586
 
 
2587
      /* we don't need to unblock anything here, the pad deactivation code
 
2588
       * already did this */
 
2589
 
2295
2590
      /* FIXME, deprecate this behaviour, it is very dangerous.
2296
2591
       * the prefered way of sending EOS downstream is by sending
2297
2592
       * the EOS event to the element */