+
+ GST_INPUT_SELECTOR_LOCK (sel);
+ while (TRUE) {
+ GstPad *active_sinkpad;
+ GstSelectorPad *active_selpad;
+ GstClock *clock;
+ gint64 cur_running_time;
+ GstClockTime running_time;
+
+ active_sinkpad = gst_input_selector_get_active_sinkpad (sel);
+ active_selpad = GST_SELECTOR_PAD_CAST (active_sinkpad);
+
+ if (seg->format != GST_FORMAT_TIME) {
+ GST_DEBUG_OBJECT (selpad,
+ "Not waiting because we don't have a TIME segment");
+ GST_INPUT_SELECTOR_UNLOCK (sel);
+ return FALSE;
+ }
+
+ running_time = gst_input_selector_get_clipped_running_time (seg, buf);
+ /* If this is outside the segment don't sync */
+ if (running_time == -1) {
+ GST_DEBUG_OBJECT (selpad,
+ "Not waiting because buffer is outside segment");
+ GST_INPUT_SELECTOR_UNLOCK (sel);
+ return FALSE;
+ }
+
+ cur_running_time = GST_CLOCK_TIME_NONE;
+ if (sel->sync_mode == GST_INPUT_SELECTOR_SYNC_MODE_CLOCK) {
+ clock = gst_element_get_clock (GST_ELEMENT_CAST (sel));
+ if (clock) {
+ GstClockTime base_time;
+
+ cur_running_time = gst_clock_get_time (clock);
+ base_time = gst_element_get_base_time (GST_ELEMENT_CAST (sel));
+ if (base_time <= cur_running_time)
+ cur_running_time -= base_time;
+ else
+ cur_running_time = 0;
+
+ gst_object_unref (clock);
+ }
+ } else {
+ GstSegment *active_seg;
+
+ active_seg = &active_selpad->segment;
+
+ /* If the active segment is configured but not to time format
+ * we can't do any syncing at all */
+ if ((active_seg->format != GST_FORMAT_TIME
+ && active_seg->format != GST_FORMAT_UNDEFINED)) {
+ GST_DEBUG_OBJECT (selpad,
+ "Not waiting because active segment isn't in TIME format");
+ GST_INPUT_SELECTOR_UNLOCK (sel);
+ return FALSE;
+ }
+
+ /* Get active pad's running time, if no configured segment yet keep at -1 */
+ if (active_seg->format == GST_FORMAT_TIME)
+ cur_running_time = gst_segment_to_running_time (active_seg,
+ GST_FORMAT_TIME, active_seg->position);
+ }
+
+ /* Don't wait if the group is finished on the active pad,
+ * as the running time won't progress now */
+ if (selpad != active_selpad && active_selpad->group_done &&
+ selpad->group_id == active_selpad->group_id) {
+ GST_DEBUG_OBJECT (selpad, "Active pad received group-done. Unblocking");
+ GST_INPUT_SELECTOR_UNLOCK (sel);
+ break;
+ }
+
+ if (selpad != active_selpad && !sel->eos && !sel->flushing
+ && !selpad->flushing && (cur_running_time == GST_CLOCK_TIME_NONE
+ || running_time >= cur_running_time)) {
+ GST_DEBUG_OBJECT (selpad,