static void gst_imx_v4l2src_apply_focus_settings(GstImxV4l2VideoSrc *v4l2src, gboolean activate) { int locks, range; /* even when activating, first ensure that it is not running */ /* ensure that continuous autofocus is not running */ v4l2_s_ctrl(v4l2src, V4L2_CID_FOCUS_AUTO, 0); /* ensure that single shot AF is not running */ v4l2_s_ctrl(v4l2src, V4L2_CID_AUTO_FOCUS_STOP, 0); if (v4l2src->af_clock_id) { gst_clock_id_unschedule(v4l2src->af_clock_id); gst_clock_id_unref(v4l2src->af_clock_id); v4l2src->af_clock_id = NULL; } /* ensure that focus is not locked */ if (v4l2_g_ctrl(v4l2src, V4L2_CID_3A_LOCK, &locks) == 0 && (locks & V4L2_LOCK_FOCUS)) v4l2_s_ctrl(v4l2src, V4L2_CID_3A_LOCK, locks & ~V4L2_LOCK_FOCUS); if (activate) { /* set focus range */ switch (v4l2src->focus_mode) { case GST_PHOTOGRAPHY_FOCUS_MODE_AUTO: range = V4L2_AUTO_FOCUS_RANGE_AUTO; break; case GST_PHOTOGRAPHY_FOCUS_MODE_MACRO: range = V4L2_AUTO_FOCUS_RANGE_MACRO; break; case GST_PHOTOGRAPHY_FOCUS_MODE_INFINITY: range = V4L2_AUTO_FOCUS_RANGE_INFINITY; break; default: range = V4L2_AUTO_FOCUS_RANGE_NORMAL; break; } v4l2_s_ctrl(v4l2src, V4L2_CID_AUTO_FOCUS_RANGE, range); /* enable continuous autofocus if requested */ if (v4l2src->focus_mode == GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_NORMAL) v4l2_s_ctrl(v4l2src, V4L2_CID_FOCUS_AUTO, 1); } }
static void gst_rtp_jitter_buffer_flush_start (GstRtpJitterBuffer * jitterbuffer) { GstRtpJitterBufferPrivate *priv; priv = jitterbuffer->priv; JBUF_LOCK (priv); /* mark ourselves as flushing */ priv->srcresult = GST_FLOW_WRONG_STATE; GST_DEBUG_OBJECT (jitterbuffer, "Disabling pop on queue"); /* this unblocks any waiting pops on the src pad task */ JBUF_SIGNAL (priv); /* unlock clock, we just unschedule, the entry will be released by the * locking streaming thread. */ if (priv->clock_id) gst_clock_id_unschedule (priv->clock_id); JBUF_UNLOCK (priv); }
static void gst_clock_finalize (GObject * object) { GstClock *clock = GST_CLOCK (object); GST_CLOCK_SLAVE_LOCK (clock); if (clock->priv->clockid) { gst_clock_id_unschedule (clock->priv->clockid); gst_clock_id_unref (clock->priv->clockid); clock->priv->clockid = NULL; } g_free (clock->priv->times); clock->priv->times = NULL; GST_CLOCK_SLAVE_UNLOCK (clock); g_mutex_clear (&clock->priv->slave_lock); G_OBJECT_CLASS (parent_class)->finalize (object); }
static void gst_directsound_src_reset (GstAudioSrc * asrc) { GstDirectSoundSrc *dsoundsrc; LPVOID pLockedBuffer = NULL; DWORD dwSizeBuffer = 0; GST_DEBUG_OBJECT (asrc, "reset directsoundsrc"); dsoundsrc = GST_DIRECTSOUND_SRC (asrc); GST_DSOUND_LOCK (dsoundsrc); dsoundsrc->reset_while_sleeping = TRUE; /* Interrupt read sleep if required */ if (dsoundsrc->read_wait_clock_id != NULL) gst_clock_id_unschedule (dsoundsrc->read_wait_clock_id); if (dsoundsrc->pDSBSecondary) { /*stop capturing */ HRESULT hRes = IDirectSoundCaptureBuffer_Stop (dsoundsrc->pDSBSecondary); /*reset position */ /* hRes = IDirectSoundCaptureBuffer_SetCurrentPosition (dsoundsrc->pDSBSecondary, 0); */ /*reset the buffer */ hRes = IDirectSoundCaptureBuffer_Lock (dsoundsrc->pDSBSecondary, dsoundsrc->current_circular_offset, dsoundsrc->buffer_size, pLockedBuffer, &dwSizeBuffer, NULL, NULL, 0L); if (SUCCEEDED (hRes)) { memset (pLockedBuffer, 0, dwSizeBuffer); hRes = IDirectSoundCaptureBuffer_Unlock (dsoundsrc->pDSBSecondary, pLockedBuffer, dwSizeBuffer, NULL, 0); } dsoundsrc->current_circular_offset = 0; } GST_DSOUND_UNLOCK (dsoundsrc); }
static GstStateChangeReturn gst_identity_change_state (GstElement * element, GstStateChange transition) { GstStateChangeReturn ret; GstIdentity *identity = GST_IDENTITY (element); switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: break; case GST_STATE_CHANGE_READY_TO_PAUSED: break; case GST_STATE_CHANGE_PAUSED_TO_PLAYING: break; case GST_STATE_CHANGE_PAUSED_TO_READY: GST_OBJECT_LOCK (identity); if (identity->clock_id) { GST_DEBUG_OBJECT (identity, "unlock clock wait"); gst_clock_id_unschedule (identity->clock_id); gst_clock_id_unref (identity->clock_id); identity->clock_id = NULL; } GST_OBJECT_UNLOCK (identity); break; default: break; } ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); switch (transition) { case GST_STATE_CHANGE_PLAYING_TO_PAUSED: break; case GST_STATE_CHANGE_PAUSED_TO_READY: break; case GST_STATE_CHANGE_READY_TO_NULL: break; default: break; } return ret; }
static void gst_live_adder_flush_start (GstLiveAdder * adder) { GST_DEBUG_OBJECT (adder, "Disabling pop on queue"); GST_OBJECT_LOCK (adder); /* mark ourselves as flushing */ adder->srcresult = GST_FLOW_WRONG_STATE; /* Empty the queue */ g_queue_foreach (adder->buffers, (GFunc) gst_mini_object_unref, NULL); while (g_queue_pop_head (adder->buffers)); /* unlock clock, we just unschedule, the entry will be released by the * locking streaming thread. */ if (adder->clock_id) gst_clock_id_unschedule (adder->clock_id); g_cond_broadcast (adder->not_empty_cond); GST_OBJECT_UNLOCK (adder); }
static gboolean gst_rtp_dtmf_src_unlock (GstBaseSrc * src) { GstRTPDTMFSrc *dtmfsrc = GST_RTP_DTMF_SRC (src); GstRTPDTMFSrcEvent *event = NULL; GST_DEBUG_OBJECT (dtmfsrc, "Called unlock"); GST_OBJECT_LOCK (dtmfsrc); dtmfsrc->paused = TRUE; if (dtmfsrc->clockid) { gst_clock_id_unschedule (dtmfsrc->clockid); } GST_OBJECT_UNLOCK (dtmfsrc); GST_DEBUG_OBJECT (dtmfsrc, "Pushing the PAUSE_TASK event on unlock request"); event = g_slice_new0 (GstRTPDTMFSrcEvent); event->event_type = RTP_DTMF_EVENT_TYPE_PAUSE_TASK; g_async_queue_push (dtmfsrc->event_queue, event); return TRUE; }
void gst_imx_v4l2src_set_autofocus(GstPhotography *photo, gboolean on) { GstImxV4l2VideoSrc *v4l2src = GST_IMX_V4L2SRC(photo); int locks; g_mutex_lock(&v4l2src->af_mutex); if (v4l2src->af_clock_id) { gst_clock_id_unschedule(v4l2src->af_clock_id); gst_clock_id_unref(v4l2src->af_clock_id); v4l2src->af_clock_id = NULL; } if (v4l2src->focus_mode == GST_PHOTOGRAPHY_FOCUS_MODE_CONTINUOUS_NORMAL) { if (v4l2_g_ctrl(v4l2src, V4L2_CID_3A_LOCK, &locks) == 0) { if (on && !(locks & V4L2_LOCK_FOCUS)) v4l2_s_ctrl(v4l2src, V4L2_CID_3A_LOCK, locks | V4L2_LOCK_FOCUS); else if (!on && (locks & V4L2_LOCK_FOCUS)) v4l2_s_ctrl(v4l2src, V4L2_CID_3A_LOCK, locks & ~V4L2_LOCK_FOCUS); } } else { if (on) { if (v4l2_s_ctrl(v4l2src, V4L2_CID_AUTO_FOCUS_START, 0) == 0) gst_imx_v4l2src_af_check_status(v4l2src); } else v4l2_s_ctrl(v4l2src, V4L2_CID_AUTO_FOCUS_STOP, 0); } g_mutex_unlock(&v4l2src->af_mutex); }
gboolean clear_sender (gpointer key, gpointer value, gpointer user_data) { FsRtpTfrc *self = FS_RTP_TFRC (user_data); struct TrackedSource *src = value; src->send_ts_base = 0; src->send_ts_cycles = 0; src->fb_last_ts = 0; src->fb_ts_cycles = 0; if (src->sender_id) { gst_clock_id_unschedule (src->sender_id); gst_clock_id_unref (src->sender_id); src->sender_id = 0; } if (src->sender) tfrc_sender_free (src->sender); src->sender = NULL; if (src->idl) { tfrc_is_data_limited_free (src->idl); src->idl = NULL; } if (self->last_src == src) self->last_src = NULL; if (src->receiver) return FALSE; else return TRUE; }
static void fs_rtp_sub_stream_stop_no_rtcp_timeout_thread (FsRtpSubStream *self) { FS_RTP_SUB_STREAM_LOCK(self); self->priv->next_no_rtcp_timeout = 0; if (self->priv->no_rtcp_timeout_id) gst_clock_id_unschedule (self->priv->no_rtcp_timeout_id); if (self->priv->no_rtcp_timeout_thread == NULL) { FS_RTP_SUB_STREAM_UNLOCK(self); return; } else { FS_RTP_SUB_STREAM_UNLOCK(self); } g_thread_join (self->priv->no_rtcp_timeout_thread); FS_RTP_SUB_STREAM_LOCK(self); self->priv->no_rtcp_timeout_thread = NULL; FS_RTP_SUB_STREAM_UNLOCK(self); }
static GstFlowReturn _chain (GstPad * pad, GstObject * object, GstBuffer * buffer) { GstBuffer *actual_buf = buffer; GstAggregator *self = GST_AGGREGATOR (object); GstAggregatorPrivate *priv = self->priv; GstAggregatorPad *aggpad = GST_AGGREGATOR_PAD (pad); GstAggregatorClass *aggclass = GST_AGGREGATOR_GET_CLASS (object); GstClockTime timeout = gst_aggregator_get_timeout (self); GstClockTime now; GST_DEBUG_OBJECT (aggpad, "Start chaining a buffer %" GST_PTR_FORMAT, buffer); if (aggpad->priv->timeout_id) { gst_clock_id_unschedule (aggpad->priv->timeout_id); gst_clock_id_unref (aggpad->priv->timeout_id); aggpad->priv->timeout_id = NULL; } g_atomic_int_set (&aggpad->unresponsive, FALSE); PAD_STREAM_LOCK (aggpad); if (g_atomic_int_get (&aggpad->priv->flushing) == TRUE) goto flushing; if (g_atomic_int_get (&aggpad->priv->pending_eos) == TRUE) goto eos; PAD_LOCK_EVENT (aggpad); if (aggpad->buffer) { GST_DEBUG_OBJECT (aggpad, "Waiting for buffer to be consumed"); PAD_WAIT_EVENT (aggpad); } PAD_UNLOCK_EVENT (aggpad); if (g_atomic_int_get (&aggpad->priv->flushing) == TRUE) goto flushing; if (aggclass->clip) { aggclass->clip (self, aggpad, buffer, &actual_buf); } PAD_LOCK_EVENT (aggpad); if (aggpad->buffer) gst_buffer_unref (aggpad->buffer); aggpad->buffer = actual_buf; PAD_UNLOCK_EVENT (aggpad); PAD_STREAM_UNLOCK (aggpad); QUEUE_PUSH (self); if (GST_CLOCK_TIME_IS_VALID (timeout)) { now = gst_clock_get_time (self->clock); aggpad->priv->timeout_id = gst_clock_new_single_shot_id (self->clock, now + timeout); gst_clock_id_wait_async (aggpad->priv->timeout_id, _unresponsive_timeout, gst_object_ref (aggpad), gst_object_unref); } GST_DEBUG_OBJECT (aggpad, "Done chaining"); return priv->flow_return; flushing: PAD_STREAM_UNLOCK (aggpad); gst_buffer_unref (buffer); GST_DEBUG_OBJECT (aggpad, "We are flushing"); return GST_FLOW_FLUSHING; eos: PAD_STREAM_UNLOCK (aggpad); gst_buffer_unref (buffer); GST_DEBUG_OBJECT (pad, "We are EOS already..."); return GST_FLOW_EOS; }
static gboolean gst_identity_sink_event (GstBaseTransform * trans, GstEvent * event) { GstIdentity *identity; gboolean ret = TRUE; identity = GST_IDENTITY (trans); if (!identity->silent) { const GstStructure *s; const gchar *tstr; gchar *sstr; GST_OBJECT_LOCK (identity); g_free (identity->last_message); tstr = gst_event_type_get_name (GST_EVENT_TYPE (event)); if ((s = gst_event_get_structure (event))) sstr = gst_structure_to_string (s); else sstr = g_strdup (""); identity->last_message = g_strdup_printf ("event ******* (%s:%s) E (type: %s (%d), %s) %p", GST_DEBUG_PAD_NAME (trans->sinkpad), tstr, GST_EVENT_TYPE (event), sstr, event); g_free (sstr); GST_OBJECT_UNLOCK (identity); gst_identity_notify_last_message (identity); } if (identity->single_segment && (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT)) { if (trans->have_segment == FALSE) { GstEvent *news; GstSegment segment; gst_event_copy_segment (event, &segment); gst_event_copy_segment (event, &trans->segment); trans->have_segment = TRUE; /* This is the first segment, send out a (0, -1) segment */ gst_segment_init (&segment, segment.format); news = gst_event_new_segment (&segment); gst_pad_event_default (trans->sinkpad, GST_OBJECT_CAST (trans), news); } } /* Reset previous timestamp, duration and offsets on NEWSEGMENT * to prevent false warnings when checking for perfect streams */ if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) { identity->prev_timestamp = identity->prev_duration = GST_CLOCK_TIME_NONE; identity->prev_offset = identity->prev_offset_end = GST_BUFFER_OFFSET_NONE; } if (identity->single_segment && GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) { /* eat up segments */ gst_event_unref (event); ret = TRUE; } else { if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_START) { GST_OBJECT_LOCK (identity); if (identity->clock_id) { GST_DEBUG_OBJECT (identity, "unlock clock wait"); gst_clock_id_unschedule (identity->clock_id); gst_clock_id_unref (identity->clock_id); identity->clock_id = NULL; } GST_OBJECT_UNLOCK (identity); } ret = GST_BASE_TRANSFORM_CLASS (parent_class)->sink_event (trans, event); } return ret; }
/* * Method: unschedule * * Cancels an outstanding async notification request. * * Returns: self. */ static VALUE rg_unschedule (VALUE self) { gst_clock_id_unschedule (RGST_CLOCK_ENTRY (self)); return self; }
static GstStateChangeReturn gst_identity_change_state (GstElement * element, GstStateChange transition) { GstStateChangeReturn ret; GstIdentity *identity = GST_IDENTITY (element); gboolean no_preroll = FALSE; switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: break; case GST_STATE_CHANGE_READY_TO_PAUSED: GST_OBJECT_LOCK (identity); identity->blocked = TRUE; GST_OBJECT_UNLOCK (identity); if (identity->sync) no_preroll = TRUE; break; case GST_STATE_CHANGE_PAUSED_TO_PLAYING: GST_OBJECT_LOCK (identity); identity->blocked = FALSE; g_cond_broadcast (&identity->blocked_cond); GST_OBJECT_UNLOCK (identity); break; case GST_STATE_CHANGE_PAUSED_TO_READY: GST_OBJECT_LOCK (identity); if (identity->clock_id) { GST_DEBUG_OBJECT (identity, "unlock clock wait"); gst_clock_id_unschedule (identity->clock_id); } identity->blocked = FALSE; g_cond_broadcast (&identity->blocked_cond); GST_OBJECT_UNLOCK (identity); break; default: break; } ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); switch (transition) { case GST_STATE_CHANGE_PLAYING_TO_PAUSED: GST_OBJECT_LOCK (identity); identity->upstream_latency = 0; identity->blocked = TRUE; GST_OBJECT_UNLOCK (identity); if (identity->sync) no_preroll = TRUE; break; case GST_STATE_CHANGE_PAUSED_TO_READY: break; case GST_STATE_CHANGE_READY_TO_NULL: break; default: break; } if (no_preroll && ret == GST_STATE_CHANGE_SUCCESS) ret = GST_STATE_CHANGE_NO_PREROLL; return ret; }
static void gst_net_client_clock_constructed (GObject * object) { GstNetClientClock *self = GST_NET_CLIENT_CLOCK (object); GstClock *internal_clock; GstClockTime internal; GList *l; ClockCache *cache = NULL; G_OBJECT_CLASS (gst_net_client_clock_parent_class)->constructed (object); G_LOCK (clocks_lock); for (l = clocks; l; l = l->next) { ClockCache *tmp = l->data; GstNetClientInternalClock *internal_clock = GST_NET_CLIENT_INTERNAL_CLOCK (tmp->clock); if (strcmp (internal_clock->address, self->priv->address) == 0 && internal_clock->port == self->priv->port) { cache = tmp; if (cache->remove_id) { gst_clock_id_unschedule (cache->remove_id); cache->remove_id = NULL; } break; } } if (!cache) { cache = g_new0 (ClockCache, 1); cache->clock = g_object_new (GST_TYPE_NET_CLIENT_INTERNAL_CLOCK, "address", self->priv->address, "port", self->priv->port, "is-ntp", self->priv->is_ntp, NULL); clocks = g_list_prepend (clocks, cache); } cache->clocks = g_list_prepend (cache->clocks, self); GST_OBJECT_LOCK (cache->clock); if (gst_clock_is_synced (cache->clock)) gst_clock_set_synced (GST_CLOCK (self), TRUE); self->priv->synced_id = g_signal_connect (cache->clock, "synced", G_CALLBACK (gst_net_client_clock_synced_cb), self); GST_OBJECT_UNLOCK (cache->clock); G_UNLOCK (clocks_lock); self->priv->internal_clock = internal_clock = cache->clock; /* gst_clock_get_time() values are guaranteed to be increasing. because no one * has called get_time on this clock yet we are free to adjust to any value * without worrying about worrying about MAX() issues with the clock's * internal time. */ /* update our internal time so get_time() give something around base_time. assume that the rate is 1 in the beginning. */ internal = gst_clock_get_internal_time (internal_clock); gst_clock_set_calibration (internal_clock, internal, self->priv->base_time, 1, 1); { GstClockTime now = gst_clock_get_time (internal_clock); if (GST_CLOCK_DIFF (now, self->priv->base_time) > 0 || GST_CLOCK_DIFF (now, self->priv->base_time + GST_SECOND) < 0) { g_warning ("unable to set the base time, expect sync problems!"); } } /* all systems go, cap'n */ }
static GstFlowReturn gst_rtp_jitter_buffer_chain (GstPad * pad, GstBuffer * buffer) { GstRtpJitterBuffer *jitterbuffer; GstRtpJitterBufferPrivate *priv; guint16 seqnum; GstFlowReturn ret = GST_FLOW_OK; GstClockTime timestamp; guint64 latency_ts; gboolean tail; jitterbuffer = GST_RTP_JITTER_BUFFER (gst_pad_get_parent (pad)); if (!gst_rtp_buffer_validate (buffer)) goto invalid_buffer; priv = jitterbuffer->priv; if (priv->last_pt != gst_rtp_buffer_get_payload_type (buffer)) { GstCaps *caps; priv->last_pt = gst_rtp_buffer_get_payload_type (buffer); /* reset clock-rate so that we get a new one */ priv->clock_rate = -1; /* Try to get the clock-rate from the caps first if we can. If there are no * caps we must fire the signal to get the clock-rate. */ if ((caps = GST_BUFFER_CAPS (buffer))) { gst_jitter_buffer_sink_parse_caps (jitterbuffer, caps); } } if (priv->clock_rate == -1) { guint8 pt; /* no clock rate given on the caps, try to get one with the signal */ pt = gst_rtp_buffer_get_payload_type (buffer); gst_rtp_jitter_buffer_get_clock_rate (jitterbuffer, pt); if (priv->clock_rate == -1) goto not_negotiated; } /* take the timestamp of the buffer. This is the time when the packet was * received and is used to calculate jitter and clock skew. We will adjust * this timestamp with the smoothed value after processing it in the * jitterbuffer. */ timestamp = GST_BUFFER_TIMESTAMP (buffer); /* bring to running time */ timestamp = gst_segment_to_running_time (&priv->segment, GST_FORMAT_TIME, timestamp); seqnum = gst_rtp_buffer_get_seq (buffer); GST_DEBUG_OBJECT (jitterbuffer, "Received packet #%d at time %" GST_TIME_FORMAT, seqnum, GST_TIME_ARGS (timestamp)); JBUF_LOCK_CHECK (priv, out_flushing); /* don't accept more data on EOS */ if (priv->eos) goto have_eos; /* let's check if this buffer is too late, we can only accept packets with * bigger seqnum than the one we last pushed. */ if (priv->last_popped_seqnum != -1) { gint gap; gap = gst_rtp_buffer_compare_seqnum (priv->last_popped_seqnum, seqnum); if (gap <= 0) { /* priv->last_popped_seqnum >= seqnum, this packet is too late or the * sender might have been restarted with different seqnum. */ if (gap < -100) { GST_DEBUG_OBJECT (jitterbuffer, "reset: buffer too old %d", gap); priv->last_popped_seqnum = -1; priv->next_seqnum = -1; } else { goto too_late; } } else { /* priv->last_popped_seqnum < seqnum, this is a new packet */ if (gap > 3000) { GST_DEBUG_OBJECT (jitterbuffer, "reset: too many dropped packets %d", gap); priv->last_popped_seqnum = -1; priv->next_seqnum = -1; } } } /* let's drop oldest packet if the queue is already full and drop-on-latency * is set. We can only do this when there actually is a latency. When no * latency is set, we just pump it in the queue and let the other end push it * out as fast as possible. */ if (priv->latency_ms && priv->drop_on_latency) { latency_ts = gst_util_uint64_scale_int (priv->latency_ms, priv->clock_rate, 1000); if (rtp_jitter_buffer_get_ts_diff (priv->jbuf) >= latency_ts) { GstBuffer *old_buf; GST_DEBUG_OBJECT (jitterbuffer, "Queue full, dropping old packet #%d", seqnum); old_buf = rtp_jitter_buffer_pop (priv->jbuf); gst_buffer_unref (old_buf); } } /* now insert the packet into the queue in sorted order. This function returns * FALSE if a packet with the same seqnum was already in the queue, meaning we * have a duplicate. */ if (!rtp_jitter_buffer_insert (priv->jbuf, buffer, timestamp, priv->clock_rate, &tail)) goto duplicate; /* signal addition of new buffer when the _loop is waiting. */ if (priv->waiting) JBUF_SIGNAL (priv); /* let's unschedule and unblock any waiting buffers. We only want to do this * when the tail buffer changed */ if (priv->clock_id && tail) { GST_DEBUG_OBJECT (jitterbuffer, "Unscheduling waiting buffer, new tail buffer"); gst_clock_id_unschedule (priv->clock_id); } GST_DEBUG_OBJECT (jitterbuffer, "Pushed packet #%d, now %d packets", seqnum, rtp_jitter_buffer_num_packets (priv->jbuf)); finished: JBUF_UNLOCK (priv); gst_object_unref (jitterbuffer); return ret; /* ERRORS */ invalid_buffer: { /* this is not fatal but should be filtered earlier */ GST_ELEMENT_WARNING (jitterbuffer, STREAM, DECODE, (NULL), ("Received invalid RTP payload, dropping")); gst_buffer_unref (buffer); gst_object_unref (jitterbuffer); return GST_FLOW_OK; } not_negotiated: { GST_WARNING_OBJECT (jitterbuffer, "No clock-rate in caps!"); gst_buffer_unref (buffer); gst_object_unref (jitterbuffer); return GST_FLOW_OK; } out_flushing: { ret = priv->srcresult; GST_DEBUG_OBJECT (jitterbuffer, "flushing %s", gst_flow_get_name (ret)); gst_buffer_unref (buffer); goto finished; } have_eos: { ret = GST_FLOW_UNEXPECTED; GST_WARNING_OBJECT (jitterbuffer, "we are EOS, refusing buffer"); gst_buffer_unref (buffer); goto finished; } too_late: { GST_WARNING_OBJECT (jitterbuffer, "Packet #%d too late as #%d was already" " popped, dropping", seqnum, priv->last_popped_seqnum); priv->num_late++; gst_buffer_unref (buffer); goto finished; } duplicate: { GST_WARNING_OBJECT (jitterbuffer, "Duplicate packet #%d detected, dropping", seqnum); priv->num_duplicates++; gst_buffer_unref (buffer); goto finished; } }
static GstFlowReturn gst_live_live_adder_chain (GstPad * pad, GstBuffer * buffer) { GstLiveAdder *adder = GST_LIVE_ADDER (gst_pad_get_parent_element (pad)); GstLiveAdderPadPrivate *padprivate = NULL; GstFlowReturn ret = GST_FLOW_OK; GList *item = NULL; GstClockTime skip = 0; gint64 drift = 0; /* Positive if new buffer after old buffer */ GST_OBJECT_LOCK (adder); ret = adder->srcresult; GST_DEBUG ("Incoming buffer time:%" GST_TIME_FORMAT " duration:%" GST_TIME_FORMAT, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), GST_TIME_ARGS (GST_BUFFER_DURATION (buffer))); if (ret != GST_FLOW_OK) { GST_DEBUG_OBJECT (adder, "Passing non-ok result from src: %s", gst_flow_get_name (ret)); gst_buffer_unref (buffer); goto out; } padprivate = gst_pad_get_element_private (pad); if (!padprivate) { ret = GST_FLOW_NOT_LINKED; gst_buffer_unref (buffer); goto out; } if (padprivate->eos) { GST_DEBUG_OBJECT (adder, "Received buffer after EOS"); ret = GST_FLOW_UNEXPECTED; gst_buffer_unref (buffer); goto out; } if (!GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) goto invalid_timestamp; if (padprivate->segment.format == GST_FORMAT_UNDEFINED) { GST_WARNING_OBJECT (adder, "No new-segment received," " initializing segment with time 0..-1"); gst_segment_init (&padprivate->segment, GST_FORMAT_TIME); gst_segment_set_newsegment (&padprivate->segment, FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); } if (padprivate->segment.format != GST_FORMAT_TIME) goto invalid_segment; buffer = gst_buffer_make_metadata_writable (buffer); drift = GST_BUFFER_TIMESTAMP (buffer) - padprivate->expected_timestamp; /* Just see if we receive invalid timestamp/durations */ if (GST_CLOCK_TIME_IS_VALID (padprivate->expected_timestamp) && !GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DISCONT) && (drift != 0)) { GST_LOG_OBJECT (adder, "Timestamp discontinuity without the DISCONT flag set" " (expected %" GST_TIME_FORMAT ", got %" GST_TIME_FORMAT " drift:%" G_GINT64_FORMAT "ms)", GST_TIME_ARGS (padprivate->expected_timestamp), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), drift / GST_MSECOND); /* We accept drifts of 10ms */ if (ABS (drift) < (10 * GST_MSECOND)) { GST_DEBUG ("Correcting minor drift"); GST_BUFFER_TIMESTAMP (buffer) = padprivate->expected_timestamp; } } /* If there is no duration, lets set one */ if (!GST_BUFFER_DURATION_IS_VALID (buffer)) { GST_BUFFER_DURATION (buffer) = gst_audio_duration_from_pad_buffer (pad, buffer); padprivate->expected_timestamp = GST_CLOCK_TIME_NONE; } else { padprivate->expected_timestamp = GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer); } /* * Lets clip the buffer to the segment (so we don't have to worry about * cliping afterwards). * This should also guarantee us that we'll have valid timestamps and * durations afterwards */ buffer = gst_audio_buffer_clip (buffer, &padprivate->segment, adder->rate, adder->bps); /* buffer can be NULL if it's completely outside of the segment */ if (!buffer) { GST_DEBUG ("Buffer completely outside of configured segment, dropping it"); goto out; } /* * Make sure all incoming buffers share the same timestamping */ GST_BUFFER_TIMESTAMP (buffer) = gst_segment_to_running_time (&padprivate->segment, padprivate->segment.format, GST_BUFFER_TIMESTAMP (buffer)); if (GST_CLOCK_TIME_IS_VALID (adder->next_timestamp) && GST_BUFFER_TIMESTAMP (buffer) < adder->next_timestamp) { if (GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer) < adder->next_timestamp) { GST_DEBUG_OBJECT (adder, "Buffer is late, dropping (ts: %" GST_TIME_FORMAT " duration: %" GST_TIME_FORMAT ")", GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), GST_TIME_ARGS (GST_BUFFER_DURATION (buffer))); gst_buffer_unref (buffer); goto out; } else { skip = adder->next_timestamp - GST_BUFFER_TIMESTAMP (buffer); GST_DEBUG_OBJECT (adder, "Buffer is partially late, skipping %" GST_TIME_FORMAT, GST_TIME_ARGS (skip)); } } /* If our new buffer's head is higher than the queue's head, lets wake up, * we may not have to wait for as long */ if (adder->clock_id && g_queue_peek_head (adder->buffers) != NULL && GST_BUFFER_TIMESTAMP (buffer) + skip < GST_BUFFER_TIMESTAMP (g_queue_peek_head (adder->buffers))) gst_clock_id_unschedule (adder->clock_id); for (item = g_queue_peek_head_link (adder->buffers); item; item = g_list_next (item)) { GstBuffer *oldbuffer = item->data; GstClockTime old_skip = 0; GstClockTime mix_duration = 0; GstClockTime mix_start = 0; GstClockTime mix_end = 0; /* We haven't reached our place yet */ if (GST_BUFFER_TIMESTAMP (buffer) + skip >= GST_BUFFER_TIMESTAMP (oldbuffer) + GST_BUFFER_DURATION (oldbuffer)) continue; /* We're past our place, lets insert ouselves here */ if (GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer) <= GST_BUFFER_TIMESTAMP (oldbuffer)) break; /* if we reach this spot, we have overlap, so we must mix */ /* First make a subbuffer with the non-overlapping part */ if (GST_BUFFER_TIMESTAMP (buffer) + skip < GST_BUFFER_TIMESTAMP (oldbuffer)) { GstBuffer *subbuffer = NULL; GstClockTime subbuffer_duration = GST_BUFFER_TIMESTAMP (oldbuffer) - (GST_BUFFER_TIMESTAMP (buffer) + skip); subbuffer = gst_buffer_create_sub (buffer, gst_live_adder_length_from_duration (adder, skip), gst_live_adder_length_from_duration (adder, subbuffer_duration)); GST_BUFFER_TIMESTAMP (subbuffer) = GST_BUFFER_TIMESTAMP (buffer) + skip; GST_BUFFER_DURATION (subbuffer) = subbuffer_duration; skip += subbuffer_duration; g_queue_insert_before (adder->buffers, item, subbuffer); } /* Now we are on the overlapping part */ oldbuffer = gst_buffer_make_writable (oldbuffer); item->data = oldbuffer; old_skip = GST_BUFFER_TIMESTAMP (buffer) + skip - GST_BUFFER_TIMESTAMP (oldbuffer); mix_start = GST_BUFFER_TIMESTAMP (oldbuffer) + old_skip; if (GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer) < GST_BUFFER_TIMESTAMP (oldbuffer) + GST_BUFFER_DURATION (oldbuffer)) mix_end = GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer); else mix_end = GST_BUFFER_TIMESTAMP (oldbuffer) + GST_BUFFER_DURATION (oldbuffer); mix_duration = mix_end - mix_start; adder->func (GST_BUFFER_DATA (oldbuffer) + gst_live_adder_length_from_duration (adder, old_skip), GST_BUFFER_DATA (buffer) + gst_live_adder_length_from_duration (adder, skip), gst_live_adder_length_from_duration (adder, mix_duration)); skip += mix_duration; } g_cond_broadcast (adder->not_empty_cond); if (skip == GST_BUFFER_DURATION (buffer)) { gst_buffer_unref (buffer); } else { if (skip) { GstClockTime subbuffer_duration = GST_BUFFER_DURATION (buffer) - skip; GstClockTime subbuffer_ts = GST_BUFFER_TIMESTAMP (buffer) + skip; GstBuffer *new_buffer = gst_buffer_create_sub (buffer, gst_live_adder_length_from_duration (adder, skip), gst_live_adder_length_from_duration (adder, subbuffer_duration)); gst_buffer_unref (buffer); buffer = new_buffer; GST_BUFFER_TIMESTAMP (buffer) = subbuffer_ts; GST_BUFFER_DURATION (buffer) = subbuffer_duration; } if (item) g_queue_insert_before (adder->buffers, item, buffer); else g_queue_push_tail (adder->buffers, buffer); } out: GST_OBJECT_UNLOCK (adder); gst_object_unref (adder); return ret; invalid_timestamp: GST_OBJECT_UNLOCK (adder); gst_buffer_unref (buffer); GST_ELEMENT_ERROR (adder, STREAM, FAILED, ("Buffer without a valid timestamp received"), ("Invalid timestamp received on buffer")); return GST_FLOW_ERROR; invalid_segment: { const gchar *format = gst_format_get_name (padprivate->segment.format); GST_OBJECT_UNLOCK (adder); gst_buffer_unref (buffer); GST_ELEMENT_ERROR (adder, STREAM, FAILED, ("This element only supports TIME segments, received other type"), ("Received a segment of type %s, only support time segment", format)); return GST_FLOW_ERROR; } }
static GstStateChangeReturn gst_mim_enc_change_state (GstElement * element, GstStateChange transition) { GstMimEnc *mimenc = GST_MIM_ENC (element); GstStateChangeReturn ret; gboolean paused_mode; switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: case GST_STATE_CHANGE_READY_TO_PAUSED: GST_OBJECT_LOCK (mimenc); gst_segment_init (&mimenc->segment, GST_FORMAT_UNDEFINED); mimenc->last_buffer = GST_CLOCK_TIME_NONE; GST_OBJECT_UNLOCK (mimenc); break; case GST_STATE_CHANGE_PLAYING_TO_PAUSED: GST_OBJECT_LOCK (mimenc); if (mimenc->clock_id) gst_clock_id_unschedule (mimenc->clock_id); mimenc->stop_paused_mode = TRUE; GST_OBJECT_UNLOCK (mimenc); gst_pad_pause_task (mimenc->srcpad); break; default: break; } ret = GST_ELEMENT_CLASS (gst_mim_enc_parent_class)->change_state (element, transition); if (ret == GST_STATE_CHANGE_FAILURE) return ret; switch (transition) { case GST_STATE_CHANGE_PAUSED_TO_PLAYING: GST_OBJECT_LOCK (mimenc); mimenc->stop_paused_mode = FALSE; paused_mode = mimenc->paused_mode; if (paused_mode) { if (!GST_ELEMENT_CLOCK (mimenc)) { GST_OBJECT_UNLOCK (mimenc); GST_ELEMENT_ERROR (mimenc, RESOURCE, FAILED, ("Using paused-mode requires a clock, but no clock was provided" " to the element"), (NULL)); return GST_STATE_CHANGE_FAILURE; } if (mimenc->last_buffer == GST_CLOCK_TIME_NONE) mimenc->last_buffer = gst_clock_get_time (GST_ELEMENT_CLOCK (mimenc)) - GST_ELEMENT_CAST (mimenc)->base_time; } GST_OBJECT_UNLOCK (mimenc); if (paused_mode) { if (!gst_pad_start_task (mimenc->srcpad, paused_mode_task, mimenc, NULL)) { ret = GST_STATE_CHANGE_FAILURE; GST_ERROR_OBJECT (mimenc, "Can not start task"); } } break; case GST_STATE_CHANGE_READY_TO_NULL: gst_mim_enc_reset (mimenc); break; default: break; } return ret; }