Permalink
Browse files

Merge pull request #6 from pdeschen/master

v0.6 support
  • Loading branch information...
2 parents 933c78b + 5d645ca commit 4c531e2809c4e63852a60edbef4389aeae01ada7 @pkrumins committed Apr 1, 2012
Showing with 138 additions and 48 deletions.
  1. +2 −0 .gitignore
  2. +38 −30 package.json
  3. +14 −13 readme.txt → readme.md
  4. +50 −2 src/async_stacked_video.cpp
  5. +7 −2 src/async_stacked_video.h
  6. +9 −1 src/fixed_video.cpp
  7. +18 −0 src/stacked_video.cpp
View
@@ -0,0 +1,2 @@
+build
+.lock-wscript
View
@@ -1,33 +1,41 @@
{
- "name": "video",
- "version": "1.0.3",
- "main": "video",
- "description": "A C++ module for node.js that creates Theora/Ogg videos from RGB frames.",
- "keywords": [
- "video",
- "videos",
- "theora",
- "rgb"
- ],
- "author": {
- "name": "Peteris Krumins",
- "email": "peteris.krumins@gmail.com",
- "web": "http://www.catonmat.net",
- "twitter": "pkrumins"
- },
- "license": "MIT",
- "repository": {
- "type": "git",
- "url": "http://github.com/pkrumins/node-video.git"
- },
- "directories": {
- "tests": "tests"
- },
- "engines": {
- "node": ">=0.1.93"
- },
- "scripts": {
- "install": "node-waf configure build"
- }
+ "name": "video",
+ "version": "1.0.4",
+ "main": "build/Release/video.node",
+ "description": "A C++ module for node.js that creates Theora/Ogg videos from RGB frames.",
+ "keywords": [
+ "video",
+ "videos",
+ "theora",
+ "rgb"
+ ],
+ "maintainers": [
+ {
+ "name": "Peteris Krumins",
+ "email": "peteris.krumins@gmail.com",
+ "web": "http://www.catonmat.net",
+ "twitter": "pkrumins"
+ }
+ ],
+ "licenses": [
+ {
+ "type": "MIT"
+ }
+ ],
+ "repositories": [
+ {
+ "type": "git",
+ "url": "http://github.com/pkrumins/node-video.git"
+ }
+ ],
+ "directories": {
+ "tests": "tests"
+ },
+ "engines": {
+ "node": ">=0.1.93 <=v0.6.12"
+ },
+ "scripts": {
+ "install": "node-waf configure build"
+ }
}
@@ -1,3 +1,4 @@
+
This is a node.js module, writen in C++, that produces Theora/Ogg videos from
the given RGB buffers.
@@ -15,9 +16,7 @@ This module exports several objects that you can work with:
// these are not there yet, still hacking them in right now.
// * StreamingVideo - to create streamable videos (works with HTML5 <video>)
-
-FixedVideo
-----------
+##FixedVideo
FixedVideo object is for creating videos from fixed size frames. That is,
each frame is exactly the same size, for example, each frame is 720x400 pixels.
@@ -73,8 +72,7 @@ to garbage collector. If `video` goes out of scope, it also closes the video
file and frees all resources.
-StackedVideo
-------------
+##StackedVideo
StackedVideo object is for stacking many small frame updates together and then
encoding the frame as a whole. Here is how it works. The first frame sent to
@@ -137,8 +135,7 @@ That will close all the file handles and free memory. Alternatively you can let
the `stackedVideo` object go out of scope, which will have the same effect.
-AsyncStackedVideo
------------------
+##AsyncStackedVideo
AsyncStackedVideo is the same as StackedVideo except it's asynchronous.
@@ -166,14 +163,12 @@ callback function, which will be called once the encoding is done:
});
-StreamingVideo
---------------
+##StreamingVideo
Also coming near you soon. This is the most awesome stuff!
-How to compile?
----------------
+##How to compile?
You need node.js installed to compile this module. When installed it comes with
node-waf tool, run it in this libs dir:
@@ -183,9 +178,11 @@ node-waf tool, run it in this libs dir:
This will produce video.node dll. After that, make sure NODE_PATH contains lib's
dir.
+## Installation
-Other stuff in this module
---------------------------
+ npm install node-video [-g]
+
+##Other stuff in this module
The discovery/ directory contains all the snippets I wrote to understand how
to get video working. It's a habit of effective hackers to try lots of small
@@ -207,3 +204,7 @@ Sincerely,
Peteris Krumins
http://www.catonmat.net
+## Contributors
+
+* Node v0.3 buffers (James Halliday substack)
+* Node v0.6 compatibility (Pascal Deschenes <pdeschen at gmail dot com>)
@@ -13,7 +13,11 @@ AsyncStackedVideo::AsyncStackedVideo(int wwidth, int hheight) :
width(wwidth), height(hheight), videoEncoder(wwidth, hheight),
push_id(0), fragment_id(0) {}
+#if NODE_VERSION_AT_LEAST(0,6,0)
void
+#else
+int
+#endif
AsyncStackedVideo::Initialize(Handle<Object> target)
{
HandleScope scope;
@@ -31,7 +35,11 @@ AsyncStackedVideo::Initialize(Handle<Object> target)
target->Set(String::NewSymbol("AsyncStackedVideo"), t->GetFunction());
}
+#if NODE_VERSION_AT_LEAST(0,6,0)
+void
+#else
int
+#endif
AsyncStackedVideo::EIO_Push(eio_req *req)
{
push_request *push_req = (push_request *)req->data;
@@ -42,7 +50,11 @@ AsyncStackedVideo::EIO_Push(eio_req *req)
// async with no callback
fprintf(stderr, "Could not mkdir(%s) in AsyncStackedVideo::EIO_Push.\n",
push_req->tmp_dir);
+ #if NODE_VERSION_AT_LEAST(0,6,0)
+ return;
+ #else
return 0;
+ #endif
}
}
@@ -53,7 +65,11 @@ AsyncStackedVideo::EIO_Push(eio_req *req)
if (mkdir(fragment_dir, 0775) == -1) {
fprintf(stderr, "Could not mkdir(%s) in AsyncStackedVideo::EIO_Push.\n",
fragment_dir);
+ #if NODE_VERSION_AT_LEAST(0,6,0)
+ return;
+ #else
return 0;
+ #endif
}
}
@@ -66,15 +82,23 @@ AsyncStackedVideo::EIO_Push(eio_req *req)
if (!out) {
fprintf(stderr, "Failed to open %s in AsyncStackedVideo::EIO_Push.\n",
filename);
+ #if NODE_VERSION_AT_LEAST(0,6,0)
+ return;
+ #else
return 0;
+ #endif
}
int written = fwrite(push_req->data, sizeof(unsigned char), push_req->data_size, out);
if (written != push_req->data_size) {
fprintf(stderr, "Failed to write all data to %s. Wrote only %d of %d.\n",
filename, written, push_req->data_size);
}
+ #if NODE_VERSION_AT_LEAST(0,6,0)
+ return;
+ #else
return 0;
+ #endif
}
int
@@ -199,7 +223,7 @@ AsyncStackedVideo::Push(const Arguments &args)
return VException("Fifth argument must be integer height.");
AsyncStackedVideo *video = ObjectWrap::Unwrap<AsyncStackedVideo>(args.This());
- Buffer *rgb = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
+ v8::Handle<v8::Object> rgb = args[0]->ToObject();
int x = args[1]->Int32Value();
int y = args[2]->Int32Value();
int w = args[3]->Int32Value();
@@ -223,7 +247,7 @@ AsyncStackedVideo::Push(const Arguments &args)
return VException("Pushed buffer exceeds AsyncStackedVideo's height.");
try {
- video->Push((unsigned char *)rgb->data(), x, y, w, h);
+ video->Push((unsigned char *) Buffer::Data(rgb), x, y, w, h);
}
catch (const char *err) {
return VException(err);
@@ -381,7 +405,11 @@ AsyncStackedVideo::rect_dims(const char *fragment_name)
}
+#if NODE_VERSION_AT_LEAST(0,6,0)
+void
+#else
int
+#endif
AsyncStackedVideo::EIO_Encode(eio_req *req)
{
async_encode_request *enc_req = (async_encode_request *)req->data;
@@ -398,7 +426,11 @@ AsyncStackedVideo::EIO_Encode(eio_req *req)
snprintf(error, 600, "Error in AsyncStackedVideo::EIO_Encode %s is not a dir.",
fragment_path);
enc_req->error = strdup(error);
+ #if NODE_VERSION_AT_LEAST(0,6,0)
+ return;
+ #else
return 0;
+ #endif
}
char **fragments = find_files(fragment_path);
@@ -409,7 +441,11 @@ AsyncStackedVideo::EIO_Encode(eio_req *req)
if (!frame) {
enc_req->error = strdup("malloc failed in AsyncStackedVideo::EIO_Encode.");
+ #if NODE_VERSION_AT_LEAST(0,6,0)
+ return;
+ #else
return 0;
+ #endif
}
for (int i = 0; i < nfragments; i++) {
@@ -421,7 +457,11 @@ AsyncStackedVideo::EIO_Encode(eio_req *req)
snprintf(error, 600, "Failed opening %s in AsyncStackedVideo::EIO_Encode.",
fragment_path);
enc_req->error = strdup(error);
+ #if NODE_VERSION_AT_LEAST(0,6,0)
+ return;
+ #else
return 0;
+ #endif
}
LOKI_ON_BLOCK_EXIT(fclose, in);
int size = file_size(fragment_path);
@@ -432,7 +472,11 @@ AsyncStackedVideo::EIO_Encode(eio_req *req)
char error[600];
snprintf(error, 600, "Error - should have read %d but read only %d from %s in AsyncStackedVideo::EIO_Encode", size, read, fragment_path);
enc_req->error = strdup(error);
+ #if NODE_VERSION_AT_LEAST(0,6,0)
+ return;
+ #else
return 0;
+ #endif
}
Rect dims = rect_dims(fragments[i]);
push_fragment(frame, video->width, video->height,
@@ -442,7 +486,11 @@ AsyncStackedVideo::EIO_Encode(eio_req *req)
}
video->videoEncoder.end();
+ #if NODE_VERSION_AT_LEAST(0,6,0)
+ return;
+ #else
return 0;
+ #endif
}
int
@@ -4,6 +4,7 @@
#include <vector>
#include <string>
#include <node.h>
+#include <node_version.h>
#include "video_encoder.h"
struct push_request {
@@ -38,10 +39,14 @@ class AsyncStackedVideo : public node::ObjectWrap {
std::string tmp_dir;
unsigned int push_id, fragment_id;
+#if NODE_VERSION_AT_LEAST(0,6,0)
+ static void EIO_Push(eio_req *req);
+ static void EIO_Encode(eio_req *req);
+#else
static int EIO_Push(eio_req *req);
- static int EIO_PushAfter(eio_req *req);
-
static int EIO_Encode(eio_req *req);
+#endif
+ static int EIO_PushAfter(eio_req *req);
static int EIO_EncodeAfter(eio_req *req);
static void push_fragment(unsigned char *frame, int width, int height,
View
@@ -1,4 +1,5 @@
#include <node_buffer.h>
+#include <node_version.h>
#include "common.h"
#include "fixed_video.h"
@@ -95,11 +96,18 @@ FixedVideo::NewFrame(const Arguments &args)
if (!Buffer::HasInstance(args[0]))
return VException("First argument must be Buffer.");
-
+#if NODE_VERSION_AT_LEAST(0,3,0)
+ v8::Handle<v8::Object> rgb = args[0]->ToObject();
+#else
Buffer *rgb = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
+#endif
FixedVideo *fv = ObjectWrap::Unwrap<FixedVideo>(args.This());
+#if NODE_VERSION_AT_LEAST(0,3,0)
+ fv->NewFrame((unsigned char *) Buffer::Data(rgb));
+#else
fv->NewFrame((unsigned char *)rgb->data());
+#endif
return Undefined();
}
Oops, something went wrong.

0 comments on commit 4c531e2

Please sign in to comment.