Skip to content

Commit

Permalink
Merge pull request #7 from tomberek/tomberek/timing
Browse files Browse the repository at this point in the history
Expose GstBuffer timing values
  • Loading branch information
notedit authored May 17, 2020
2 parents 1cb52f7 + ae3ab64 commit 8a550c7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,16 @@ func (e *Element) PullSample() (sample *Sample, err error) {
copy(data, CData[:])

duration := uint64(C.X_gst_buffer_get_duration(gstBuffer))
pts := uint64(C.X_gst_buffer_get_pts(gstBuffer))
dts := uint64(C.X_gst_buffer_get_dts(gstBuffer))
offset := uint64(C.X_gst_buffer_get_offset(gstBuffer))

sample = &Sample{
Data: data,
Duration: duration,
Pts: pts,
Dts: dts,
Offset: offset,
}

C.gst_buffer_unmap(gstBuffer, mapInfo)
Expand Down
18 changes: 18 additions & 0 deletions gst.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ gboolean X_gst_buffer_map(GstBuffer* gstBuffer, GstMapInfo* mapInfo) {
return gst_buffer_map(gstBuffer, mapInfo, GST_MAP_READ);
}

void X_gst_pipeline_use_clock_real(GstElement *element) {
GstClock *d = gst_pipeline_get_clock(GST_PIPELINE(element));
g_object_set(d,"clock-type", GST_CLOCK_TYPE_REALTIME, NULL);
}

void X_gst_pipeline_use_clock(GstElement *element, GstClock *clock) {
gst_pipeline_use_clock(GST_PIPELINE(element), clock);
}
Expand Down Expand Up @@ -210,6 +215,19 @@ GstClockTime X_gst_buffer_get_duration(GstBuffer* buffer) {
return GST_BUFFER_DURATION(buffer);
}


GstClockTime X_gst_buffer_get_pts(GstBuffer* buffer) {
return GST_BUFFER_PTS(buffer);
}

GstClockTime X_gst_buffer_get_dts(GstBuffer* buffer) {
return GST_BUFFER_DTS(buffer);
}

GstClockTime X_gst_buffer_get_offset(GstBuffer* buffer) {
return GST_BUFFER_OFFSET(buffer);
}

gchar* X_gst_pad_get_name(GstPad* pad) {
return gst_pad_get_name(pad);
}
Expand Down
3 changes: 3 additions & 0 deletions gst.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func init() {
type Sample struct {
Data []byte
Duration uint64
Pts uint64
Dts uint64
Offset uint64
}

func CheckPlugins(plugins []string) error {
Expand Down
5 changes: 5 additions & 0 deletions gst.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern void X_g_signal_emit_buffer_by_name(GstElement* element, const gchar* det
extern GstBuffer *X_gst_buffer_new_wrapped(gchar* src, gsize len);
extern gboolean X_gst_buffer_map(GstBuffer* gstBuffer, GstMapInfo* mapInfo);
extern void X_gst_pipeline_use_clock(GstElement *element, GstClock *clock);
extern void X_gst_pipeline_use_clock_real(GstElement *element);
extern void X_gst_element_set_start_time_none(GstElement *element);
extern void X_gst_structure_set_string(GstStructure *structure, const gchar *name, gchar* value);
extern void X_gst_structure_set_int(GstStructure *structure, const gchar *name, gint value);
Expand All @@ -53,6 +54,10 @@ extern void X_gst_pipeline_set_latency(GstElement* element, GstClockTime clockTi
extern GstFlowReturn X_gst_app_src_push_buffer(GstElement* element, void *buffer,int len);
extern GstClockTime X_gst_buffer_get_duration(GstBuffer* buffer);

extern GstClockTime X_gst_buffer_get_pts(GstBuffer* buffer);
extern GstClockTime X_gst_buffer_get_dts(GstBuffer* buffer);
extern GstClockTime X_gst_buffer_get_offset(GstBuffer* buffer);

extern gchar* X_gst_pad_get_name(GstPad* pad);
extern void cb_bus_message(GstBus * bus, GstMessage * message, gpointer poll_data);
extern void X_g_signal_connect_data(gpointer instance, const gchar *detailed_signal, void (*f)(GstElement*, GstBus*, GstMessage*, gpointer), gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags);
4 changes: 4 additions & 0 deletions pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func ParseLaunch(pipelineStr string) (p *Pipeline, err error) {
p = &Pipeline{}
p.GstElement = gstElt

C.X_gst_pipeline_use_clock_real(p.GstElement)

runtime.SetFinalizer(p, func(p *Pipeline) {
C.gst_object_unref(C.gpointer(unsafe.Pointer(p.GstElement)))
})
Expand Down Expand Up @@ -60,6 +62,8 @@ func PipelineNew(name string) (e *Pipeline, err error) {

e.GstElement = gstElt

C.X_gst_pipeline_use_clock_real(e.GstElement)

runtime.SetFinalizer(e, func(e *Pipeline) {
C.gst_object_unref(C.gpointer(unsafe.Pointer(e.GstElement)))
})
Expand Down

0 comments on commit 8a550c7

Please sign in to comment.