mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-22 14:06:23 +00:00
timedvaluecontrolsource: Use g_sequence_lookup where possible
When looking for exact matches in the sequence, this results in much simpler code than when using g_sequence_search. https://bugzilla.gnome.org/show_bug.cgi?id=755498
This commit is contained in:
parent
9a30399e4f
commit
d3e9f55302
1 changed files with 15 additions and 33 deletions
|
@ -171,36 +171,25 @@ static void
|
||||||
gst_timed_value_control_source_set_internal (GstTimedValueControlSource *
|
gst_timed_value_control_source_set_internal (GstTimedValueControlSource *
|
||||||
self, GstClockTime timestamp, const gdouble value)
|
self, GstClockTime timestamp, const gdouble value)
|
||||||
{
|
{
|
||||||
GSequenceIter *iter;
|
|
||||||
GstControlPoint *cp;
|
GstControlPoint *cp;
|
||||||
|
|
||||||
g_mutex_lock (&self->lock);
|
g_mutex_lock (&self->lock);
|
||||||
|
|
||||||
/* check if a control point for the timestamp already exists */
|
/* check if a control point for the timestamp already exists */
|
||||||
/* iter contains the iter right *after* timestamp */
|
|
||||||
if (G_LIKELY (self->values)) {
|
if (G_LIKELY (self->values)) {
|
||||||
iter =
|
GSequenceIter *iter = g_sequence_lookup (self->values, ×tamp,
|
||||||
g_sequence_search (self->values, ×tamp,
|
|
||||||
(GCompareDataFunc) gst_control_point_find, NULL);
|
(GCompareDataFunc) gst_control_point_find, NULL);
|
||||||
|
|
||||||
if (iter) {
|
if (iter) {
|
||||||
GSequenceIter *prev = g_sequence_iter_prev (iter);
|
GstControlPoint *cp = g_sequence_get (iter);
|
||||||
|
|
||||||
if (!g_sequence_iter_is_end (prev)) {
|
/* update control point */
|
||||||
GstControlPoint *cp = g_sequence_get (prev);
|
cp->value = value;
|
||||||
|
g_mutex_unlock (&self->lock);
|
||||||
|
|
||||||
/* If the timestamp is the same just update the control point value */
|
g_signal_emit (self,
|
||||||
if (cp->timestamp == timestamp) {
|
gst_timed_value_control_source_signals[VALUE_CHANGED_SIGNAL], 0, cp);
|
||||||
|
goto done;
|
||||||
/* update control point */
|
|
||||||
cp->value = value;
|
|
||||||
g_mutex_unlock (&self->lock);
|
|
||||||
|
|
||||||
g_signal_emit (self,
|
|
||||||
gst_timed_value_control_source_signals[VALUE_CHANGED_SIGNAL], 0,
|
|
||||||
cp);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self->values = g_sequence_new ((GDestroyNotify) gst_control_point_free);
|
self->values = g_sequence_new ((GDestroyNotify) gst_control_point_free);
|
||||||
|
@ -337,24 +326,17 @@ gst_timed_value_control_source_unset (GstTimedValueControlSource * self,
|
||||||
g_mutex_lock (&self->lock);
|
g_mutex_lock (&self->lock);
|
||||||
/* check if a control point for the timestamp exists */
|
/* check if a control point for the timestamp exists */
|
||||||
if (G_LIKELY (self->values) && (iter =
|
if (G_LIKELY (self->values) && (iter =
|
||||||
g_sequence_search (self->values, ×tamp,
|
g_sequence_lookup (self->values, ×tamp,
|
||||||
(GCompareDataFunc) gst_control_point_find, NULL))) {
|
(GCompareDataFunc) gst_control_point_find, NULL))) {
|
||||||
|
|
||||||
/* Iter contains the iter right after timestamp, i.e.
|
/* Iter contains the iter right after timestamp, i.e.
|
||||||
* we need to get the previous one and check the timestamp
|
* we need to get the previous one and check the timestamp
|
||||||
*/
|
*/
|
||||||
iter = g_sequence_iter_prev (iter);
|
cp = g_slice_dup (GstControlPoint, g_sequence_get (iter));
|
||||||
cp = g_sequence_get (iter);
|
g_sequence_remove (iter);
|
||||||
if (cp->timestamp == timestamp) {
|
self->nvalues--;
|
||||||
cp = g_slice_dup (GstControlPoint, cp);
|
self->valid_cache = FALSE;
|
||||||
g_sequence_remove (iter);
|
res = TRUE;
|
||||||
self->nvalues--;
|
|
||||||
self->valid_cache = FALSE;
|
|
||||||
res = TRUE;
|
|
||||||
} else {
|
|
||||||
cp = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
g_mutex_unlock (&self->lock);
|
g_mutex_unlock (&self->lock);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue