📄 gstinterpolation.c
字号:
/* GStreamer * * Copyright (C) <2005> Stefan Kost <ensonic at users dot sf dot net> * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org> * * gstinterpolation.c: Interpolation methods for dynamic properties * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */#ifdef HAVE_CONFIG_H# include "config.h"#endif#include "gstinterpolationcontrolsource.h"#include "gstinterpolationcontrolsourceprivate.h"#define GST_CAT_DEFAULT gst_controller_debugGST_DEBUG_CATEGORY_EXTERN (GST_CAT_DEFAULT);#define EMPTY(x) (x)/* common helper *//* * gst_interpolation_control_source_find_control_point_node: * @self: the interpolation control source to search in * @timestamp: the search key * * Find last value before given timestamp in control point list. * * Returns: the found #GList node or %NULL */static GList *gst_interpolation_control_source_find_control_point_node (GstInterpolationControlSource * self, GstClockTime timestamp){ GList *prev_node = g_list_last (self->priv->values); GList *node; GstControlPoint *cp; /* Check if we can start from the last requested value * to save some time */ node = self->priv->values; if (self->priv->last_requested_value) { GstControlPoint *last_cp = self->priv->last_requested_value->data; if (timestamp > last_cp->timestamp) node = self->priv->last_requested_value; } /* iterate over timed value list */ for (; node; node = g_list_next (node)) { cp = node->data; /* this timestamp is newer that the one we look for */ if (timestamp < cp->timestamp) { /* get previous one again */ prev_node = g_list_previous (node); break; } } /* If we have something to return save it as a * potential start position for the next search */ if (prev_node) self->priv->last_requested_value = prev_node; return prev_node;}/* * gst_interpolation_control_source_get_first_value: * @self: the interpolation control source to search in * * Find the first value and return it. * * Returns: the found #GValue or %NULL if there are none. */static inline GValue *gst_interpolation_control_source_get_first_value (GstInterpolationControlSource * self){ if (self->priv->values && self->priv->nvalues > 0) { GstControlPoint *cp = self->priv->values->data; return &cp->value; } else { return NULL; }}/* steps-like (no-)interpolation, default *//* just returns the value for the most recent key-frame */#define DEFINE_NONE_GET(type) \static inline GValue * \_interpolate_none_get_##type (GstInterpolationControlSource *self, GstClockTime timestamp) \{ \ GValue *ret; \ GList *node; \ \ if ((node = \ gst_interpolation_control_source_find_control_point_node (self, timestamp))) { \ GstControlPoint *cp = node->data; \ g##type ret_val = g_value_get_##type (&cp->value); \ \ if (g_value_get_##type (&self->priv->minimum_value) > ret_val) \ ret = &self->priv->minimum_value; \ else if (g_value_get_##type (&self->priv->maximum_value) < ret_val) \ ret = &self->priv->maximum_value; \ else \ ret = &cp->value; \ } else { \ ret = gst_interpolation_control_source_get_first_value (self); \ } \ return ret; \} \\static gboolean \interpolate_none_get_##type (GstInterpolationControlSource *self, GstClockTime timestamp, GValue *value) \{ \ GValue *ret; \ g_mutex_lock (self->lock); \ \ ret = _interpolate_none_get_##type (self, timestamp); \ if (!ret) { \ g_mutex_unlock (self->lock); \ return FALSE; \ } \ g_value_copy (ret, value); \ g_mutex_unlock (self->lock); \ return TRUE; \} \\static gboolean \interpolate_none_get_##type##_value_array (GstInterpolationControlSource *self, \ GstClockTime timestamp, GstValueArray * value_array) \{ \ gint i; \ GstClockTime ts = timestamp; \ g##type *values = (g##type *) value_array->values; \ GValue *ret; \ \ g_mutex_lock (self->lock); \ for(i = 0; i < value_array->nbsamples; i++) { \ ret = _interpolate_none_get_##type (self, timestamp); \ if (!ret) { \ g_mutex_unlock (self->lock); \ return FALSE; \ } \ *values = g_value_get_##type (ret); \ ts += value_array->sample_interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ return TRUE; \}DEFINE_NONE_GET (int);DEFINE_NONE_GET (uint);DEFINE_NONE_GET (long);DEFINE_NONE_GET (ulong);DEFINE_NONE_GET (int64);DEFINE_NONE_GET (uint64);DEFINE_NONE_GET (float);DEFINE_NONE_GET (double);static inline GValue *_interpolate_none_get (GstInterpolationControlSource * self, GstClockTime timestamp){ GList *node; GValue *ret; if ((node = gst_interpolation_control_source_find_control_point_node (self, timestamp))) { GstControlPoint *cp = node->data; ret = &cp->value; } else { ret = gst_interpolation_control_source_get_first_value (self); } return ret;}static gbooleaninterpolate_none_get (GstInterpolationControlSource * self, GstClockTime timestamp, GValue * value){ GValue *ret; g_mutex_lock (self->lock); ret = _interpolate_none_get (self, timestamp); if (!ret) { g_mutex_unlock (self->lock); return FALSE; } g_value_copy (ret, value); g_mutex_unlock (self->lock); return TRUE;}static gbooleaninterpolate_none_get_boolean_value_array (GstInterpolationControlSource * self, GstClockTime timestamp, GstValueArray * value_array){ gint i; GstClockTime ts = timestamp; gboolean *values = (gboolean *) value_array->values; GValue *ret; g_mutex_lock (self->lock); for (i = 0; i < value_array->nbsamples; i++) { ret = _interpolate_none_get (self, timestamp); if (!ret) { g_mutex_unlock (self->lock); return FALSE; } *values = g_value_get_boolean (ret); ts += value_array->sample_interval; values++; } g_mutex_unlock (self->lock); return TRUE;}static gbooleaninterpolate_none_get_enum_value_array (GstInterpolationControlSource * self, GstClockTime timestamp, GstValueArray * value_array){ gint i; GstClockTime ts = timestamp; gint *values = (gint *) value_array->values; GValue *ret; g_mutex_lock (self->lock); for (i = 0; i < value_array->nbsamples; i++) { ret = _interpolate_none_get (self, timestamp); if (!ret) { g_mutex_unlock (self->lock); return FALSE; } *values = g_value_get_enum (ret); ts += value_array->sample_interval; values++; } g_mutex_unlock (self->lock); return TRUE;}static gbooleaninterpolate_none_get_string_value_array (GstInterpolationControlSource * self, GstClockTime timestamp, GstValueArray * value_array){ gint i; GstClockTime ts = timestamp; gchar **values = (gchar **) value_array->values; GValue *ret; g_mutex_lock (self->lock); for (i = 0; i < value_array->nbsamples; i++) { ret = _interpolate_none_get (self, timestamp); if (!ret) { g_mutex_unlock (self->lock); return FALSE; } *values = (gchar *) g_value_get_string (ret); ts += value_array->sample_interval; values++; } g_mutex_unlock (self->lock); return TRUE;}static GstInterpolateMethod interpolate_none = { (GstControlSourceGetValue) interpolate_none_get_int, (GstControlSourceGetValueArray) interpolate_none_get_int_value_array, (GstControlSourceGetValue) interpolate_none_get_uint, (GstControlSourceGetValueArray) interpolate_none_get_uint_value_array, (GstControlSourceGetValue) interpolate_none_get_long, (GstControlSourceGetValueArray) interpolate_none_get_long_value_array, (GstControlSourceGetValue) interpolate_none_get_ulong, (GstControlSourceGetValueArray) interpolate_none_get_ulong_value_array, (GstControlSourceGetValue) interpolate_none_get_int64, (GstControlSourceGetValueArray) interpolate_none_get_int64_value_array, (GstControlSourceGetValue) interpolate_none_get_uint64, (GstControlSourceGetValueArray) interpolate_none_get_uint64_value_array, (GstControlSourceGetValue) interpolate_none_get_float, (GstControlSourceGetValueArray) interpolate_none_get_float_value_array, (GstControlSourceGetValue) interpolate_none_get_double, (GstControlSourceGetValueArray) interpolate_none_get_double_value_array, (GstControlSourceGetValue) interpolate_none_get, (GstControlSourceGetValueArray) interpolate_none_get_boolean_value_array, (GstControlSourceGetValue) interpolate_none_get, (GstControlSourceGetValueArray) interpolate_none_get_enum_value_array, (GstControlSourceGetValue) interpolate_none_get, (GstControlSourceGetValueArray) interpolate_none_get_string_value_array};/* returns the default value of the property, except for times with specific values *//* needed for one-shot events, such as notes and triggers */#define DEFINE_TRIGGER_GET(type) \static inline GValue * \_interpolate_trigger_get_##type (GstInterpolationControlSource *self, GstClockTime timestamp) \{ \ GList *node; \ GstControlPoint *cp; \ \ /* check if there is a value at the registered timestamp */ \ if ((node = \ gst_interpolation_control_source_find_control_point_node (self, timestamp))) { \ cp = node->data; \ if (timestamp == cp->timestamp) { \ g##type ret = g_value_get_##type (&cp->value); \ if (g_value_get_##type (&self->priv->minimum_value) > ret) \ return &self->priv->minimum_value; \ else if (g_value_get_##type (&self->priv->maximum_value) < ret) \ return &self->priv->maximum_value; \ else \ return &cp->value; \ } \ } \ \ if (self->priv->nvalues > 0) \ return &self->priv->default_value; \ else \ return NULL; \} \\static gboolean \interpolate_trigger_get_##type (GstInterpolationControlSource *self, GstClockTime timestamp, GValue *value) \{ \ GValue *ret; \ g_mutex_lock (self->lock); \ ret = _interpolate_trigger_get_##type (self, timestamp); \ if (!ret) { \ g_mutex_unlock (self->lock); \ return FALSE; \ } \ g_value_copy (ret, value); \ g_mutex_unlock (self->lock); \ return TRUE; \} \\static gboolean \interpolate_trigger_get_##type##_value_array (GstInterpolationControlSource *self, \ GstClockTime timestamp, GstValueArray * value_array) \{ \ gint i; \ GstClockTime ts = timestamp; \ g##type *values = (g##type *) value_array->values; \ GValue *ret; \ \ g_mutex_lock (self->lock); \ for(i = 0; i < value_array->nbsamples; i++) { \ ret = _interpolate_trigger_get_##type (self, timestamp); \ if (!ret) { \ g_mutex_unlock (self->lock); \ return FALSE; \ } \ *values = g_value_get_##type (ret); \ ts += value_array->sample_interval; \ values++; \ } \ g_mutex_unlock (self->lock); \ return TRUE; \}DEFINE_TRIGGER_GET (int);DEFINE_TRIGGER_GET (uint);DEFINE_TRIGGER_GET (long);DEFINE_TRIGGER_GET (ulong);DEFINE_TRIGGER_GET (int64);DEFINE_TRIGGER_GET (uint64);DEFINE_TRIGGER_GET (float);DEFINE_TRIGGER_GET (double);static inline GValue *_interpolate_trigger_get (GstInterpolationControlSource * self, GstClockTime timestamp){ GList *node; GstControlPoint *cp; /* check if there is a value at the registered timestamp */ if ((node = gst_interpolation_control_source_find_control_point_node (self, timestamp))) { cp = node->data; if (timestamp == cp->timestamp) { return &cp->value; } } if (self->priv->nvalues > 0) return &self->priv->default_value; else return NULL;}static gbooleaninterpolate_trigger_get (GstInterpolationControlSource * self, GstClockTime timestamp, GValue * value){ GValue *ret; g_mutex_lock (self->lock); ret = _interpolate_trigger_get (self, timestamp); if (!ret) { g_mutex_unlock (self->lock); return FALSE; } g_value_copy (ret, value); g_mutex_unlock (self->lock); return TRUE;}static gbooleaninterpolate_trigger_get_boolean_value_array (GstInterpolationControlSource * self, GstClockTime timestamp, GstValueArray * value_array)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -