Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding getters and setters in VideoCaptureWrap #559

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion src/VideoCaptureWrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ void VideoCaptureWrap::Init(Local<Object> target) {
Nan::SetPrototypeMethod(ctor, "setHeight", SetHeight);
Nan::SetPrototypeMethod(ctor, "getWidth", GetWidth);
Nan::SetPrototypeMethod(ctor, "getHeight", GetHeight);
Nan::SetPrototypeMethod(ctor, "getPosition", GetPosition);
Nan::SetPrototypeMethod(ctor, "getPositionMS", GetPositionMS);
Nan::SetPrototypeMethod(ctor, "setPosition", SetPosition);
Nan::SetPrototypeMethod(ctor, "getFrameAt", GetFrameAt);
Nan::SetPrototypeMethod(ctor, "setPositionMS", SetPositionMS);
Nan::SetPrototypeMethod(ctor, "getFourCC", GetFourCC);
Nan::SetPrototypeMethod(ctor, "getFrameCount", GetFrameCount);
Nan::SetPrototypeMethod(ctor, "getFPS", GetFPS);
Nan::SetPrototypeMethod(ctor, "release", Release);
Expand All @@ -44,6 +48,33 @@ void VideoCaptureWrap::Init(Local<Object> target) {
target->Set(Nan::New("VideoCapture").ToLocalChecked(), ctor->GetFunction());
}

NAN_METHOD(VideoCaptureWrap::GetPosition) {
Nan::HandleScope scope;
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());

int cnt = int(v->cap.get(CV_CAP_PROP_POS_FRAMES));

info.GetReturnValue().Set(Nan::New<Number>(cnt));
}

NAN_METHOD(VideoCaptureWrap::GetPositionMS) {
Nan::HandleScope scope;
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());

int cnt = int(v->cap.get(CV_CAP_PROP_POS_MSEC));

info.GetReturnValue().Set(Nan::New<Number>(cnt));
}

NAN_METHOD(VideoCaptureWrap::GetFourCC) {
Nan::HandleScope scope;
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());

int cnt = int(v->cap.get(CV_CAP_PROP_FOURCC));

info.GetReturnValue().Set(Nan::New<Number>(cnt));
}

NAN_METHOD(VideoCaptureWrap::New) {
Nan::HandleScope scope;

Expand Down Expand Up @@ -122,7 +153,7 @@ NAN_METHOD(VideoCaptureWrap::GetFPS) {

int fps = int(v->cap.get(CV_CAP_PROP_FPS));

info.GetReturnValue().Set(Nan::New<Number>(fps));
info.GetReturnValue().Set(Nan::New<Number>(fps));
}


Expand Down Expand Up @@ -177,6 +208,20 @@ NAN_METHOD(VideoCaptureWrap::GetFrameAt) {
return;
}

NAN_METHOD(VideoCaptureWrap::SetPositionMS) {
Nan::HandleScope scope;
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());

if(info.Length() != 1)
return;

int pos = info[0]->IntegerValue();

v->cap.set(CV_CAP_PROP_POS_MSEC, pos);

return;
}

NAN_METHOD(VideoCaptureWrap::Release) {
Nan::HandleScope scope;
VideoCaptureWrap *v = Nan::ObjectWrap::Unwrap<VideoCaptureWrap>(info.This());
Expand Down
17 changes: 15 additions & 2 deletions src/VideoCaptureWrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,24 @@ class VideoCaptureWrap: public Nan::ObjectWrap {

// to set frame position
static NAN_METHOD(SetPosition);
static NAN_METHOD(GetFrameCount);

// to set frame position in milliseconds
static NAN_METHOD(SetPositionMS);
static NAN_METHOD(GetFrameAt); // would deprecate as naming is confusing

// to get 0-based index of the frame to be decoded/captured next
static NAN_METHOD(GetPosition);

// to get frame position in milliseconds
static NAN_METHOD(GetPositionMS);

// to get frame rate
static NAN_METHOD(GetFPS);

static NAN_METHOD(GetFrameAt);
// to get 4-character code of codec
static NAN_METHOD(GetFourCC);

static NAN_METHOD(GetFrameCount);

// release the stream
static NAN_METHOD(Release);
Expand Down