diff --git a/GObjectWrap.cpp b/GObjectWrap.cpp index e7f936d..cbbc181 100644 --- a/GObjectWrap.cpp +++ b/GObjectWrap.cpp @@ -52,6 +52,7 @@ Local GObjectWrap::NewInstance( const Nan::FunctionCallbackInfo& i } if (GST_IS_APP_SRC(obj)) { Nan::SetMethod(instance, "push", GstAppSrcPush); + Nan::SetMethod(instance, "sendEos", GstAppSrcSendEndOfStream); } info.GetReturnValue().Set(instance); @@ -106,6 +107,7 @@ class PullWorker : public Nan::AsyncWorker { Nan::HandleScope scope; Local buf; + Local pts; Local caps = Nan::New(); if (sample) { @@ -116,14 +118,24 @@ class PullWorker : public Nan::AsyncWorker { } buf = gstsample_to_v8(sample); + + // Extracting pts from the sample + GstBuffer *buffer = gst_sample_get_buffer(sample); + if (buffer) { + pts = Nan::New(static_cast(buffer->pts)); + } else { + pts = Nan::Null(); + } + gst_sample_unref(sample); sample = NULL; } else { - buf = Nan::Null(); + pts = Nan::Null(); + buf = Nan::Null(); } - Local argv[] = { buf, caps }; - callback->Call(2, argv, async_resource); + Local argv[] = { buf, caps, pts }; + callback->Call(3, argv, async_resource); } private: @@ -161,3 +173,13 @@ NAN_METHOD(GObjectWrap::GstAppSrcPush) { } // TODO throw an error if no args are given? } + +NAN_METHOD(GObjectWrap::GstAppSrcSendEndOfStream) { + auto *obj = Nan::ObjectWrap::Unwrap(info.This()); + GstFlowReturn result = gst_app_src_end_of_stream(GST_APP_SRC(obj->obj)); + + if (result != GST_FLOW_OK) { + // Handle error + Nan::ThrowError("Failed to send End-Of-Stream event."); + } +} diff --git a/GObjectWrap.h b/GObjectWrap.h index d0c34e1..764682e 100644 --- a/GObjectWrap.h +++ b/GObjectWrap.h @@ -33,7 +33,8 @@ class GObjectWrap : public Nan::ObjectWrap { static void _pulledBuffer( uv_work_t *req, int ); */ static NAN_METHOD(GstAppSinkPull); - static NAN_METHOD(GstAppSrcPush); + static NAN_METHOD(GstAppSrcPush); + static NAN_METHOD(GstAppSrcSendEndOfStream); }; #endif