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

live555helper and nodejs integration - nodejs C++ Addon #8

Open
juvasquezg opened this issue Apr 26, 2017 · 0 comments
Open

live555helper and nodejs integration - nodejs C++ Addon #8

juvasquezg opened this issue Apr 26, 2017 · 0 comments

Comments

@juvasquezg
Copy link

Hi,

I am creating a native module in nodejs (uses libuv event loop)

I am using live555helper live555helper.

The initial intention is to get the buffer from nodejs, however the program stays in the event loop of live555 and not run the callback that I pass to it from nodejs and the api of v8 (not return to javascript).

The program in nodejs is.

'use strict'

const addon = require('./build/Release/eas-rtsp')

addon.getBuffer((err, buffer) => {
  if (err) {
    console.log(err)
  } else {
    console.log(buffer.toString('hex'))
  }
})

// Code not reached
console.log('continue...')

The c ++ addon is:

#include <rtspconnectionclient.h>

using namespace v8;

NAN_METHOD(getBuffer) {
	Nan:: HandleScope scope;
	
	Nan::Callback *node_callback = new Nan::Callback(info[0].As<Function>());

	class RTSPCallback : public RTSPConnection::Callback
	{
	public:
		virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime,  Nan::Callback* node_callback) {
			// std::cout << id << " " << size << " ts:" << presentationTime.tv_sec << "." << presentationTime.tv_usec << std::endl;
			v8::Local<v8::Object> node_buffer = Nan::NewBuffer((char *)buffer, size).ToLocalChecked();
			v8::Local<v8::Value> argv[] = { node_buffer };
			node_callback->Call(1, argv);
			return true;
		}
	};
  
	Environment env;
	RTSPCallback cb;
	RTSPConnection rtspClient(env, &cb, "rtsp://admin:@192.168.1.38:554/live1.sdp", node_callback);
	env.mainloop();
}


NAN_MODULE_INIT(Initialize) {
    NAN_EXPORT(target, getBuffer);
}

NODE_MODULE(addon, Initialize);
  1. get Callback from node.
Nan::Callback *node_callback = new Nan::Callback(info[0].As<Function>());
  1. overwrite onData of live555helper.

  2. The live555 event loop starts.

env.mainloop();

The code eas-rtsp commit bb08a5e

The node program does not continue.

  • Should I add the live555 event loop in another thread?

  • How do I add an event type to the live555 event loop so that from the event loop of nodejs
    I will be able to read the buffer.

  • Maybe use EventEmitter but I don't know.

What do you think?. It is posible?

Your opinion is very important to me.

Thank you!!!

Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant