Skip to content

Commit 772a072

Browse files
committed
add add-reference-timestamp-meta to aravissrc
Add add-reference-timestamp-meta property, mirroring the property of the same name on rtspsrc. When enabled, each buffer gets a GstReferenceTimestampMeta with reference caps "timestamp/x-ptp", carrying the unmodified device timestamp. Buffers without a device timestamp (zero) get no meta. The property defaults to FALSE, as devices with unsynchronized clocks will not provide absolute time
1 parent 214f840 commit 772a072

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

gst/gstaravis.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ enum
7373
PROP_USB_MODE,
7474
PROP_STREAM,
7575
PROP_TRIGGER,
76+
PROP_ADD_REFERENCE_TIMESTAMP_META,
7677
N_PROPERTIES
7778
};
7879

@@ -560,6 +561,11 @@ gst_aravis_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
560561
}
561562
}
562563

564+
/* Reference caps for the optional capture-time meta. The device timestamp is
565+
* nanoseconds on the PTP timescale when the device is PTP-synchronized (IEEE
566+
* 1588), matching the timestamp/x-ptp convention of rtpjitterbuffer. */
567+
static GstStaticCaps ptp_reference_timestamp_caps = GST_STATIC_CAPS ("timestamp/x-ptp");
568+
563569
static GstFlowReturn
564570
gst_aravis_create (GstPushSrc * push_src, GstBuffer ** buffer)
565571
{
@@ -623,6 +629,17 @@ gst_aravis_create (GstPushSrc * push_src, GstBuffer ** buffer)
623629
gst_aravis->last_timestamp = timestamp_ns;
624630
}
625631

632+
/* Optionally expose the absolute device timestamp, which is otherwise lost
633+
* when it is folded into the first-frame-relative GST_BUFFER_PTS. A zero
634+
* timestamp means the device did not provide one. */
635+
if (gst_aravis->add_reference_timestamp_meta && timestamp_ns != 0) {
636+
GstCaps *reference = gst_static_caps_get (&ptp_reference_timestamp_caps);
637+
638+
gst_buffer_add_reference_timestamp_meta (*buffer, reference,
639+
timestamp_ns, GST_CLOCK_TIME_NONE);
640+
gst_caps_unref (reference);
641+
}
642+
626643
arv_stream_push_buffer (gst_aravis->stream, arv_buffer);
627644
GST_OBJECT_UNLOCK (gst_aravis);
628645

@@ -709,6 +726,7 @@ gst_aravis_init (GstAravis *gst_aravis)
709726
gst_aravis->frame_rate = 0.0;
710727

711728
gst_aravis->trigger_source = NULL;
729+
gst_aravis->add_reference_timestamp_meta = FALSE;
712730

713731
gst_aravis->camera = NULL;
714732
gst_aravis->stream = NULL;
@@ -863,6 +881,11 @@ gst_aravis_set_property (GObject * object, guint prop_id,
863881
gst_aravis->trigger_source = g_strdup (g_value_get_string (value));
864882
GST_OBJECT_UNLOCK (gst_aravis);
865883
break;
884+
case PROP_ADD_REFERENCE_TIMESTAMP_META:
885+
GST_OBJECT_LOCK (gst_aravis);
886+
gst_aravis->add_reference_timestamp_meta = g_value_get_boolean (value);
887+
GST_OBJECT_UNLOCK (gst_aravis);
888+
break;
866889
default:
867890
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
868891
break;
@@ -976,6 +999,11 @@ gst_aravis_get_property (GObject * object, guint prop_id, GValue * value,
976999
g_value_set_string (value, gst_aravis->trigger_source);
9771000
GST_OBJECT_UNLOCK (gst_aravis);
9781001
break;
1002+
case PROP_ADD_REFERENCE_TIMESTAMP_META:
1003+
GST_OBJECT_LOCK (gst_aravis);
1004+
g_value_set_boolean (value, gst_aravis->add_reference_timestamp_meta);
1005+
GST_OBJECT_UNLOCK (gst_aravis);
1006+
break;
9791007
default:
9801008
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
9811009
break;
@@ -1171,6 +1199,15 @@ gst_aravis_class_init (GstAravisClass * klass)
11711199
NULL,
11721200
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
11731201

1202+
properties[PROP_ADD_REFERENCE_TIMESTAMP_META] =
1203+
g_param_spec_boolean("add-reference-timestamp-meta",
1204+
"Add reference timestamp meta",
1205+
"Add a GstReferenceTimestampMeta with timestamp/x-ptp reference"
1206+
" caps to buffers, carrying the device timestamp. Only an"
1207+
" absolute time if the device clock is PTP-synchronized",
1208+
FALSE,
1209+
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1210+
11741211
g_object_class_install_properties (gobject_class,
11751212
G_N_ELEMENTS (properties),
11761213
properties);

gst/gstaravis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ struct _GstAravis {
8585
char *trigger_source;
8686

8787
char *features;
88+
89+
gboolean add_reference_timestamp_meta;
8890
};
8991

9092
struct _GstAravisClass {

0 commit comments

Comments
 (0)