Skip to content

Commit

Permalink
add vorbis_synthesis_idheader() binding
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Jan 27, 2013
1 parent 6134fcf commit 61eb00e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/binding.cc
Expand Up @@ -105,6 +105,48 @@ Handle<Value> node_get_format (const Arguments& args) {
}


/* vorbis_synthesis_idheader() called on the thread pool */
Handle<Value> node_vorbis_synthesis_idheader (const Arguments& args) {
HandleScope scope;
Local<Function> callback = Local<Function>::Cast(args[1]);

idheader_req *r = new idheader_req;
r->op = UnwrapPointer<ogg_packet *>(args[0]);
r->callback = Persistent<Function>::New(callback);
r->rtn = 0;
r->req.data = r;

uv_queue_work(uv_default_loop(),
&r->req,
node_vorbis_synthesis_idheader_async,
(uv_after_work_cb)node_vorbis_synthesis_idheader_after);
return Undefined();
}

void node_vorbis_synthesis_idheader_async (uv_work_t *req) {
idheader_req *r = reinterpret_cast<idheader_req *>(req->data);
r->rtn = vorbis_synthesis_idheader(r->op);
}

void node_vorbis_synthesis_idheader_after (uv_work_t *req) {
HandleScope scope;
idheader_req *r = reinterpret_cast<idheader_req *>(req->data);

Handle<Value> argv[] = { Null(), Boolean::New(r->rtn) };

TryCatch try_catch;
r->callback->Call(Context::GetCurrent()->Global(), 2, argv);

// cleanup
r->callback.Dispose();
delete r;

if (try_catch.HasCaught()) {
FatalException(try_catch);
}
}


/* vorbis_synthesis_headerin() called on the thread pool */
Handle<Value> node_vorbis_synthesis_headerin (const Arguments& args) {
HandleScope scope;
Expand Down Expand Up @@ -239,6 +281,7 @@ void Initialize(Handle<Object> target) {
NODE_SET_METHOD(target, "vorbis_comment_init", node_vorbis_comment_init);
NODE_SET_METHOD(target, "vorbis_synthesis_init", node_vorbis_synthesis_init);
NODE_SET_METHOD(target, "vorbis_block_init", node_vorbis_block_init);
NODE_SET_METHOD(target, "vorbis_synthesis_idheader", node_vorbis_synthesis_idheader);
NODE_SET_METHOD(target, "vorbis_synthesis_headerin", node_vorbis_synthesis_headerin);
NODE_SET_METHOD(target, "vorbis_synthesis", node_vorbis_synthesis);
NODE_SET_METHOD(target, "vorbis_synthesis_blockin", node_vorbis_synthesis_blockin);
Expand Down
10 changes: 10 additions & 0 deletions src/binding.h
Expand Up @@ -3,6 +3,13 @@

namespace nodevorbis {

struct idheader_req {
uv_work_t req;
ogg_packet *op;
int rtn;
v8::Persistent<v8::Function> callback;
};

struct headerin_req {
uv_work_t req;
vorbis_info *vi;
Expand Down Expand Up @@ -38,6 +45,9 @@ struct pcmout_req {
};

/* Decoding */
void node_vorbis_synthesis_idheader_async (uv_work_t *);
void node_vorbis_synthesis_idheader_after (uv_work_t *);

void node_vorbis_synthesis_headerin_async (uv_work_t *);
void node_vorbis_synthesis_headerin_after (uv_work_t *);

Expand Down

0 comments on commit 61eb00e

Please sign in to comment.