diff --git a/binding.gyp b/binding.gyp index 0e932600a6..a7257e1a4b 100644 --- a/binding.gyp +++ b/binding.gyp @@ -177,6 +177,7 @@ '-lXxf86vm', '-lXrandr', '-lXi', + '-lx264', '-lasound', '-lexpat', ], diff --git a/deps/exokit-bindings/videocontext/include/Video.h b/deps/exokit-bindings/videocontext/include/Video.h index 1f80ef4f37..0530e5b30d 100644 --- a/deps/exokit-bindings/videocontext/include/Video.h +++ b/deps/exokit-bindings/videocontext/include/Video.h @@ -4,6 +4,10 @@ #include #include #include +#include +#include +#include +#include extern "C" { #include @@ -13,6 +17,7 @@ extern "C" { #include } +#include #include using namespace std; @@ -33,7 +38,7 @@ class AppData { ~AppData(); void resetState(); - bool set(vector &memory, string *error = nullptr); + bool set(vector &&memory, string *error = nullptr); static int bufferRead(void *opaque, unsigned char *buf, int buf_size); static int64_t bufferSeek(void *opaque, int64_t offset, int whence); double getTimeBase(); @@ -56,10 +61,20 @@ class AppData { double lastTimestamp; }; +class VideoRequest { +public: + std::function)>)> fn; +}; + +class VideoResponse { +public: + std::function fn; +}; + class Video : public ObjectWrap { public: static Handle Initialize(Isolate *isolate); - bool Load(uint8_t *bufferValue, size_t bufferLength, string *error = nullptr); + void Load(WebGLRenderingContext *gl, uint8_t *bufferValue, size_t bufferLength); void Update(); void Play(); void Pause(); @@ -77,7 +92,12 @@ class Video : public ObjectWrap { static NAN_GETTER(HeightGetter); static NAN_GETTER(LoopGetter); static NAN_SETTER(LoopSetter); - static NAN_GETTER(DataGetter); + static NAN_GETTER(OnLoadGetter); + static NAN_SETTER(OnLoadSetter); + static NAN_GETTER(OnErrorGetter); + static NAN_SETTER(OnErrorSetter); + // static NAN_GETTER(DataGetter); + static NAN_GETTER(TextureGetter); static NAN_GETTER(CurrentTimeGetter); static NAN_SETTER(CurrentTimeSetter); static NAN_GETTER(DurationGetter); @@ -87,23 +107,32 @@ class Video : public ObjectWrap { double getRequiredCurrentTimeS(); double getFrameCurrentTimeS(); FrameStatus advanceToFrameAt(double timestamp); + void queueInVideoThread(std::function)>)> fn); + static void runInMainThread(uv_async_t *handle); Video(); ~Video(); private: - AppData data; + AppData appData; + WebGLRenderingContext *gl; + GLuint texture; bool loaded; bool playing; bool loop; int64_t startTime; double startFrameTime; - Nan::Persistent dataArray; - bool dataDirty; + Nan::Persistent onload; + Nan::Persistent onerror; + + std::thread thread; + uv_sem_t requestSem; + // uv_sem_t responseSem; + std::mutex requestMutex; + std::deque requestQueue; }; class VideoCamera; - class VideoDevice : public ObjectWrap { public: static Handle Initialize(Isolate *isolate, Local imageDataCons); @@ -116,6 +145,7 @@ class VideoDevice : public ObjectWrap { static NAN_GETTER(HeightGetter); static NAN_GETTER(SizeGetter); static NAN_GETTER(DataGetter); + // static NAN_GETTER(TextureGetter); static NAN_GETTER(ImageDataGetter); VideoDevice(); @@ -126,6 +156,9 @@ class VideoDevice : public ObjectWrap { Nan::Persistent imageData; }; +extern std::mutex responseMutex; +extern std::deque responseQueue; +extern uv_async_t responseAsync; extern std::vector