2 * Copyright (C) 2015 Sebastian Dröge <sebastian@centricular.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef __GST_PTP_CLOCK_H__
22 #define __GST_PTP_CLOCK_H__
25 #include <gst/gstsystemclock.h>
26 #include <gst/net/net-prelude.h>
30 #define GST_TYPE_PTP_CLOCK \
31 (gst_ptp_clock_get_type())
32 #define GST_PTP_CLOCK(obj) \
33 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PTP_CLOCK,GstPtpClock))
34 #define GST_PTP_CLOCK_CLASS(klass) \
35 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PTP_CLOCK,GstPtpClockClass))
36 #define GST_IS_PTP_CLOCK(obj) \
37 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PTP_CLOCK))
38 #define GST_IS_PTP_CLOCK_CLASS(klass) \
39 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PTP_CLOCK))
41 typedef struct _GstPtpClock GstPtpClock;
42 typedef struct _GstPtpClockClass GstPtpClockClass;
43 typedef struct _GstPtpClockPrivate GstPtpClockPrivate;
48 * Opaque #GstPtpClock structure.
54 GstPtpClockPrivate *priv;
56 gpointer _gst_reserved[GST_PADDING];
61 * @parent_class: parented to #GstSystemClockClass
63 * Opaque #GstPtpClockClass structure.
65 struct _GstPtpClockClass {
66 GstSystemClockClass parent_class;
69 gpointer _gst_reserved[GST_PADDING];
73 * GST_PTP_CLOCK_ID_NONE:
74 * PTP clock identification that can be passed to gst_ptp_init() to
75 * automatically select one based on the MAC address of interfaces
77 #define GST_PTP_CLOCK_ID_NONE ((guint64) -1)
80 GType gst_ptp_clock_get_type (void);
83 gboolean gst_ptp_is_supported (void);
86 gboolean gst_ptp_is_initialized (void);
89 gboolean gst_ptp_init (guint64 clock_id,
92 void gst_ptp_deinit (void);
94 #define GST_PTP_STATISTICS_NEW_DOMAIN_FOUND "GstPtpStatisticsNewDomainFound"
95 #define GST_PTP_STATISTICS_BEST_MASTER_CLOCK_SELECTED "GstPtpStatisticsBestMasterClockSelected"
96 #define GST_PTP_STATISTICS_PATH_DELAY_MEASURED "GstPtpStatisticsPathDelayMeasured"
97 #define GST_PTP_STATISTICS_TIME_UPDATED "GstPtpStatisticsTimeUpdated"
100 * GstPtpStatisticsCallback:
101 * @domain: PTP domain identifier
102 * @stats: New statistics
103 * @user_data: Data passed to gst_ptp_statistics_callback_add()
105 * The statistics can be the following structures:
107 * GST_PTP_STATISTICS_NEW_DOMAIN_FOUND:
108 * "domain" G_TYPE_UINT The domain identifier of the domain
109 * "clock" GST_TYPE_CLOCK The internal clock that is slaved to the
112 * GST_PTP_STATISTICS_BEST_MASTER_CLOCK_SELECTED:
113 * "domain" G_TYPE_UINT The domain identifier of the domain
114 * "master-clock-id" G_TYPE_UINT64 PTP clock identifier of the selected master
116 * "master-clock-port" G_TYPE_UINT PTP port number of the selected master clock
117 * "grandmaster-clock-id" G_TYPE_UINT64 PTP clock identifier of the grandmaster clock
119 * GST_PTP_STATISTICS_PATH_DELAY_MEASURED:
120 * "domain" G_TYPE_UINT The domain identifier of the domain
121 * "mean-path-delay-avg" GST_TYPE_CLOCK_TIME Average mean path delay
122 * "mean-path-delay" GST_TYPE_CLOCK_TIME Latest mean path delay
123 * "delay-request-delay" GST_TYPE_CLOCK_TIME Delay of DELAY_REQ / DELAY_RESP messages
125 * GST_PTP_STATISTICS_TIME_UPDATED:
126 * "domain" G_TYPE_UINT The domain identifier of the domain
127 * "mean-path-delay-avg" GST_TYPE_CLOCK_TIME Average mean path delay
128 * "local-time" GST_TYPE_CLOCK_TIME Local time that corresponds to ptp-time
129 * "ptp-time" GST_TYPE_CLOCK_TIME Newly measured PTP time at local-time
130 * "estimated-ptp-time" GST_TYPE_CLOCK_TIME Estimated PTP time based on previous measurements
131 * "discontinuity" G_TYPE_INT64 Difference between estimated and measured PTP time
132 * "synced" G_TYPE_BOOLEAN Currently synced to the remote clock
133 * "r-squared" G_TYPE_DOUBLE R² of clock estimation regression
134 * "internal-time" GST_TYPE_CLOCK_TIME Internal time clock parameter
135 * "external-time" GST_TYPE_CLOCK_TIME External time clock parameter
136 * "rate-num" G_TYPE_UINT64 Internal/external rate numerator
137 * "rate-den" G_TYPE_UINT64 Internal/external rate denominator
138 * "rate" G_TYPE_DOUBLE Internal/external rate
140 * If %FALSE is returned, the callback is removed and never called again.
143 typedef gboolean (*GstPtpStatisticsCallback) (guint8 domain,
144 const GstStructure * stats,
147 gulong gst_ptp_statistics_callback_add (GstPtpStatisticsCallback callback,
148 gpointer user_data, GDestroyNotify destroy_data);
150 void gst_ptp_statistics_callback_remove (gulong id);
153 GstClock* gst_ptp_clock_new (const gchar *name,
156 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
157 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstPtpClock, gst_object_unref)
162 #endif /* __GST_PTP_CLOCK_H__ */