Simulator first commit

This commit is contained in:
2019-09-18 11:11:16 +03:00
commit 6e1686be67
5028 changed files with 985331 additions and 0 deletions

38
node_modules/lame/src/bindings.cc generated vendored Normal file
View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2011, Nathan Rajlich <nathan@tootallnate.net>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <v8.h>
#include <node.h>
#include "nan.h"
using namespace v8;
using namespace node;
namespace nodelame {
void InitLame(Handle<Object>);
void InitMPG123(Handle<Object>);
void Initialize(Handle<Object> target) {
Nan::HandleScope scope;
InitLame(target);
InitMPG123(target);
}
} // nodelame namespace
NODE_MODULE(bindings, nodelame::Initialize);

490
node_modules/lame/src/node_lame.cc generated vendored Normal file
View File

@ -0,0 +1,490 @@
/*
* Copyright (c) 2011, Nathan Rajlich <nathan@tootallnate.net>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <v8.h>
#include <node.h>
#include <node_buffer.h>
#include "node_pointer.h"
#include "node_lame.h"
#include "lame.h"
#include "nan.h"
using namespace v8;
using namespace node;
using namespace nodelame;
namespace nodelame {
#define PASTE2(a, b) a##b
#define PASTE(a, b) PASTE2(a, b)
#define UNWRAP_GFP \
Nan::HandleScope scope; \
lame_global_flags *gfp = reinterpret_cast<lame_global_flags *>(UnwrapPointer(info[0]));
#define FN(type, v8type, fn) \
NAN_METHOD(PASTE(node_lame_get_, fn)) { \
UNWRAP_GFP; \
type output = PASTE(lame_get_, fn)(gfp); \
info.GetReturnValue().Set(Nan::New<Number>(output)); \
} \
NAN_METHOD(PASTE(node_lame_set_, fn)) { \
UNWRAP_GFP; \
type input = (type)info[1]->PASTE(v8type, Value)(); \
int output = PASTE(lame_set_, fn)(gfp, input); \
info.GetReturnValue().Set(Nan::New<Number>(output)); \
}
/* get_lame_version() */
NAN_METHOD(node_get_lame_version) {
info.GetReturnValue().Set(Nan::New<String>(get_lame_version()).ToLocalChecked());
}
/* get_lame_os_bitness() */
NAN_METHOD(node_get_lame_os_bitness) {
info.GetReturnValue().Set(Nan::New<String>(get_lame_os_bitness()).ToLocalChecked());
}
/* lame_close() */
NAN_METHOD(node_lame_close) {
UNWRAP_GFP;
lame_close(gfp);
}
/* malloc()'s a `lame_t` struct and returns it to JS land */
NAN_METHOD(node_lame_init) {
lame_global_flags *gfp = lame_init();
if (gfp == NULL) return info.GetReturnValue().SetNull();
Nan::MaybeLocal<v8::Object> wrapper = WrapPointer((char *)gfp);
info.GetReturnValue().Set(wrapper.ToLocalChecked());
}
/* lame_encode_buffer_interleaved()
* The main encoding function */
NAN_METHOD(node_lame_encode_buffer) {
UNWRAP_GFP;
// the input buffer
char *input = UnwrapPointer(info[1]);
pcm_type input_type = static_cast<pcm_type>(Nan::To<int32_t>(info[2]).FromMaybe(0));
int32_t channels = Nan::To<int32_t>(info[3]).FromMaybe(0);
int32_t num_samples = Nan::To<int32_t>(info[4]).FromMaybe(0);
// the output buffer
int out_offset = Nan::To<int32_t>(info[6]).FromMaybe(0);
char *output = UnwrapPointer(info[5], out_offset);
int output_size = Nan::To<int32_t>(info[7]).FromMaybe(0);
encode_req *request = new encode_req;
request->gfp = gfp;
request->input = (unsigned char *)input;
request->input_type = input_type;
request->channels = channels;
request->num_samples = num_samples;
request->output = (unsigned char *)output;
request->output_size = output_size;
request->callback.Reset(info[8].As<Function>());
// set a circular pointer so we can get the "encode_req" back later
request->req.data = request;
uv_queue_work(uv_default_loop(), &request->req,
node_lame_encode_buffer_async,
(uv_after_work_cb)node_lame_encode_buffer_after);
}
/* encode a buffer on the thread pool. */
void node_lame_encode_buffer_async (uv_work_t *req) {
encode_req *r = (encode_req *)req->data;
if (r->input_type == PCM_TYPE_SHORT_INT) {
if (r->channels > 1) {
// encoding short int interleaved input buffer
r->rtn = lame_encode_buffer_interleaved(
r->gfp,
(short int *)r->input,
r->num_samples,
r->output,
r->output_size
);
} else {
// encoding short int input buffer
r->rtn = lame_encode_buffer(
r->gfp,
(short int *)r->input,
NULL,
r->num_samples,
r->output,
r->output_size
);
}
} else if (r->input_type == PCM_TYPE_FLOAT) {
if (r->channels > 1) {
// encoding float interleaved input buffer
r->rtn = lame_encode_buffer_interleaved_ieee_float(
r->gfp,
(float *)r->input,
r->num_samples,
r->output,
r->output_size
);
} else {
// encoding float input buffer
r->rtn = lame_encode_buffer_ieee_float(
r->gfp,
(float *)r->input,
NULL,
r->num_samples,
r->output,
r->output_size
);
}
} else if (r->input_type == PCM_TYPE_DOUBLE) {
if (r->channels > 1) {
// encoding double interleaved input buffer
r->rtn = lame_encode_buffer_interleaved_ieee_double(
r->gfp,
(double *)r->input,
r->num_samples,
r->output,
r->output_size
);
} else {
// encoding double input buffer
r->rtn = lame_encode_buffer_ieee_double(
r->gfp,
(double *)r->input,
NULL,
r->num_samples,
r->output,
r->output_size
);
}
}
}
void node_lame_encode_buffer_after (uv_work_t *req) {
Nan::HandleScope scope;
encode_req *r = (encode_req *)req->data;
Handle<Value> argv[1];
argv[0] = Nan::New<Integer>(r->rtn);
Nan::TryCatch try_catch;
Nan::New(r->callback)->Call(Nan::GetCurrentContext()->Global(), 1, argv);
// cleanup
r->callback.Reset();
delete r;
if (try_catch.HasCaught()) {
FatalException(try_catch);
}
}
/* lame_encode_flush_nogap() */
NAN_METHOD(node_lame_encode_flush_nogap) {
UNWRAP_GFP;
// the output buffer
int out_offset = Nan::To<int32_t>(info[2]).FromMaybe(0);
char *output = UnwrapPointer(info[1], out_offset);
int output_size = Nan::To<int32_t>(info[3]).FromMaybe(0);
encode_req *request = new encode_req;
request->gfp = gfp;
request->output = (unsigned char *)output;
request->output_size = output_size;
request->callback.Reset(info[4].As<Function>());
// set a circular pointer so we can get the "encode_req" back later
request->req.data = request;
uv_queue_work(uv_default_loop(), &request->req,
node_lame_encode_flush_nogap_async,
(uv_after_work_cb)node_lame_encode_flush_nogap_after);
}
void node_lame_encode_flush_nogap_async (uv_work_t *req) {
encode_req *r = (encode_req *)req->data;
r->rtn = lame_encode_flush_nogap(
r->gfp,
r->output,
r->output_size
);
}
/**
* lame_get_id3v1_tag()
* Must be called *after* lame_encode_flush()
* TODO: Make async
*/
NAN_METHOD(node_lame_get_id3v1_tag) {
UNWRAP_GFP;
Local<Object> outbuf = info[1]->ToObject();
unsigned char *buf = (unsigned char *)Buffer::Data(outbuf);
size_t buf_size = (size_t)Buffer::Length(outbuf);
size_t b = lame_get_id3v1_tag(gfp, buf, buf_size);
info.GetReturnValue().Set(Nan::New<Integer>(static_cast<uint32_t>(b)));
}
/**
* lame_get_id3v2_tag()
* Must be called *before* lame_init_params()
* TODO: Make async
*/
NAN_METHOD(node_lame_get_id3v2_tag) {
UNWRAP_GFP;
Local<Object> outbuf = info[1]->ToObject();
unsigned char *buf = (unsigned char *)Buffer::Data(outbuf);
size_t buf_size = (size_t)Buffer::Length(outbuf);
size_t b = lame_get_id3v2_tag(gfp, buf, buf_size);
info.GetReturnValue().Set(Nan::New<Integer>(static_cast<uint32_t>(b)));
}
/* lame_init_params(gfp) */
NAN_METHOD(node_lame_init_params) {
UNWRAP_GFP;
info.GetReturnValue().Set(Nan::New<Number>(lame_init_params(gfp)));
}
/* lame_print_internals() */
NAN_METHOD(node_lame_print_internals) {
UNWRAP_GFP;
lame_print_internals(gfp);
}
/* lame_print_config() */
NAN_METHOD(node_lame_print_config) {
UNWRAP_GFP;
lame_print_config(gfp);
}
/* lame_get_bitrate() */
NAN_METHOD(node_lame_bitrates) {
int v;
int x = 3;
int y = 16;
Local<Array> n;
Local<Array> ret = Nan::New<Array>();
for (int i = 0; i < x; i++) {
n = Nan::New<Array>();
for (int j = 0; j < y; j++) {
v = lame_get_bitrate(i, j);
if (v >= 0) {
Nan::Set(n, j, Nan::New<Integer>(v));
}
}
Nan::Set(ret, i, n);
}
info.GetReturnValue().Set(ret);
}
/* lame_get_samplerate() */
NAN_METHOD(node_lame_samplerates) {
int v;
int x = 3;
int y = 4;
Local<Array> n;
Local<Array> ret = Nan::New<Array>();
for (int i = 0; i < x; i++) {
n = Nan::New<Array>();
for (int j = 0; j < y; j++) {
v = lame_get_samplerate(i, j);
if (v >= 0) {
Nan::Set(n, j, Nan::New<Integer>(v));
}
}
Nan::Set(ret, i, n);
}
info.GetReturnValue().Set(ret);
}
// define the node_lame_get/node_lame_set functions
FN(unsigned long, Number, num_samples);
FN(int, Int32, in_samplerate);
FN(int, Int32, num_channels);
FN(float, Number, scale);
FN(float, Number, scale_left);
FN(float, Number, scale_right);
FN(int, Int32, out_samplerate);
FN(int, Int32, analysis);
FN(int, Int32, bWriteVbrTag);
FN(int, Int32, quality);
FN(MPEG_mode, Int32, mode);
FN(int, Int32, brate);
FN(float, Number, compression_ratio);
FN(int, Int32, copyright);
FN(int, Int32, original);
FN(int, Int32, error_protection);
FN(int, Int32, extension);
FN(int, Int32, strict_ISO);
FN(int, Int32, disable_reservoir);
FN(int, Int32, quant_comp);
FN(int, Int32, quant_comp_short);
FN(int, Int32, exp_nspsytune);
FN(vbr_mode, Int32, VBR);
FN(int, Int32, VBR_q);
FN(float, Number, VBR_quality);
FN(int, Int32, VBR_mean_bitrate_kbps);
FN(int, Int32, VBR_min_bitrate_kbps);
FN(int, Int32, VBR_max_bitrate_kbps);
FN(int, Int32, VBR_hard_min);
FN(int, Int32, lowpassfreq);
FN(int, Int32, lowpasswidth);
FN(int, Int32, highpassfreq);
FN(int, Int32, highpasswidth);
// ...
void InitLame(Handle<Object> target) {
Nan::HandleScope scope;
/* sizeof's */
#define SIZEOF(value) \
Nan::ForceSet(target, Nan::New<String>("sizeof_" #value).ToLocalChecked(), Nan::New<Integer>(static_cast<uint32_t>(sizeof(value))), \
static_cast<PropertyAttribute>(ReadOnly|DontDelete))
SIZEOF(short);
SIZEOF(int);
SIZEOF(float);
SIZEOF(double);
#define CONST_INT(value) \
Nan::ForceSet(target, Nan::New<String>(#value).ToLocalChecked(), Nan::New<Integer>(value), \
static_cast<PropertyAttribute>(ReadOnly|DontDelete));
// vbr_mode_e
CONST_INT(vbr_off);
CONST_INT(vbr_mt);
CONST_INT(vbr_rh);
CONST_INT(vbr_abr);
CONST_INT(vbr_mtrh);
CONST_INT(vbr_default);
// MPEG_mode_e
CONST_INT(STEREO);
CONST_INT(JOINT_STEREO);
CONST_INT(MONO);
CONST_INT(NOT_SET);
// Padding_type_e
CONST_INT(PAD_NO);
CONST_INT(PAD_ALL);
CONST_INT(PAD_ADJUST);
// Maximum size of an album art
CONST_INT(LAME_MAXALBUMART);
// lame_errorcodes_t
CONST_INT(LAME_OKAY);
CONST_INT(LAME_NOERROR);
CONST_INT(LAME_GENERICERROR);
CONST_INT(LAME_NOMEM);
CONST_INT(LAME_BADBITRATE);
CONST_INT(LAME_BADSAMPFREQ);
CONST_INT(LAME_INTERNALERROR);
//define PCM types
CONST_INT(PCM_TYPE_SHORT_INT)
CONST_INT(PCM_TYPE_FLOAT)
CONST_INT(PCM_TYPE_DOUBLE)
// Functions
Nan::SetMethod(target, "get_lame_version", node_get_lame_version);
Nan::SetMethod(target, "get_lame_os_bitness", node_get_lame_os_bitness);
Nan::SetMethod(target, "lame_close", node_lame_close);
Nan::SetMethod(target, "lame_encode_buffer", node_lame_encode_buffer);
Nan::SetMethod(target, "lame_encode_flush_nogap", node_lame_encode_flush_nogap);
Nan::SetMethod(target, "lame_get_id3v1_tag", node_lame_get_id3v1_tag);
Nan::SetMethod(target, "lame_get_id3v2_tag", node_lame_get_id3v2_tag);
Nan::SetMethod(target, "lame_init_params", node_lame_init_params);
Nan::SetMethod(target, "lame_print_config", node_lame_print_config);
Nan::SetMethod(target, "lame_print_internals", node_lame_print_internals);
Nan::SetMethod(target, "lame_init", node_lame_init);
Nan::SetMethod(target, "lame_bitrates", node_lame_bitrates);
Nan::SetMethod(target, "lame_samplerates", node_lame_samplerates);
// Get/Set functions
#define LAME_SET_METHOD(fn) \
Nan::SetMethod(target, "lame_get_" #fn, PASTE(node_lame_get_, fn)); \
Nan::SetMethod(target, "lame_set_" #fn, PASTE(node_lame_set_, fn));
LAME_SET_METHOD(num_samples);
LAME_SET_METHOD(in_samplerate);
LAME_SET_METHOD(num_channels);
LAME_SET_METHOD(scale);
LAME_SET_METHOD(scale_left);
LAME_SET_METHOD(scale_right);
LAME_SET_METHOD(out_samplerate);
LAME_SET_METHOD(analysis);
LAME_SET_METHOD(bWriteVbrTag);
LAME_SET_METHOD(quality);
LAME_SET_METHOD(mode);
LAME_SET_METHOD(brate);
LAME_SET_METHOD(compression_ratio);
LAME_SET_METHOD(copyright);
LAME_SET_METHOD(original);
LAME_SET_METHOD(error_protection);
LAME_SET_METHOD(extension);
LAME_SET_METHOD(strict_ISO);
LAME_SET_METHOD(disable_reservoir);
LAME_SET_METHOD(quant_comp);
LAME_SET_METHOD(quant_comp_short);
LAME_SET_METHOD(exp_nspsytune);
LAME_SET_METHOD(VBR);
LAME_SET_METHOD(VBR_q);
LAME_SET_METHOD(VBR_quality);
LAME_SET_METHOD(VBR_mean_bitrate_kbps);
LAME_SET_METHOD(VBR_min_bitrate_kbps);
LAME_SET_METHOD(VBR_max_bitrate_kbps);
LAME_SET_METHOD(VBR_hard_min);
LAME_SET_METHOD(lowpassfreq);
LAME_SET_METHOD(lowpasswidth);
LAME_SET_METHOD(highpassfreq);
LAME_SET_METHOD(highpasswidth);
// ...
/*
Nan::SetMethod(target, "lame_get_decode_only", node_lame_get_decode_only);
Nan::SetMethod(target, "lame_set_decode_only", node_lame_set_decode_only);
Nan::SetMethod(target, "lame_get_framesize", node_lame_get_framesize);
Nan::SetMethod(target, "lame_get_frameNum", node_lame_get_frameNum);
Nan::SetMethod(target, "lame_get_version", node_lame_get_version);
*/
}
} // nodelame namespace

34
node_modules/lame/src/node_lame.h generated vendored Normal file
View File

@ -0,0 +1,34 @@
#include <v8.h>
#include <node.h>
#include "lame.h"
namespace nodelame {
/* enums used to set the type of the input PCM */
typedef enum {
PCM_TYPE_SHORT_INT,
PCM_TYPE_FLOAT,
PCM_TYPE_DOUBLE
} pcm_type;
/* struct that's used for async encoding */
struct encode_req {
uv_work_t req;
lame_global_flags *gfp;
unsigned char *input;
pcm_type input_type;
int channels;
int num_samples;
unsigned char *output;
int output_size;
int rtn;
Nan::Persistent<v8::Function> callback;
};
void node_lame_encode_buffer_async (uv_work_t *);
void node_lame_encode_buffer_after (uv_work_t *);
void node_lame_encode_flush_nogap_async (uv_work_t *);
#define node_lame_encode_flush_nogap_after node_lame_encode_buffer_after
} // nodelame namespace

505
node_modules/lame/src/node_mpg123.cc generated vendored Normal file
View File

@ -0,0 +1,505 @@
/*
* Copyright (c) 2011, Nathan Rajlich <nathan@tootallnate.net>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <v8.h>
#include <node.h>
#include <node_buffer.h>
#include <string.h>
#include "node_pointer.h"
#include "node_mpg123.h"
#include "nan.h"
using namespace v8;
using namespace node;
using namespace Nan;
namespace nodelame {
#define UNWRAP_MH \
Nan::HandleScope scope; \
mpg123_handle *mh = reinterpret_cast<mpg123_handle *>(UnwrapPointer(info[0]));
/* not a macro because we're passing function calls in here */
inline int min (int a, int b) {
return a < b ? a : b;
}
NAN_METHOD(node_mpg123_init) {
info.GetReturnValue().Set(Nan::New<Integer>(mpg123_init()));
}
NAN_METHOD(node_mpg123_exit) {
mpg123_exit();
}
NAN_METHOD(node_mpg123_new) {
// TODO: Accept an input decoder String
int error = MPG123_OK;
mpg123_handle *mh = mpg123_new(NULL, &error);
if (error == MPG123_OK) {
info.GetReturnValue().Set(WrapPointer(mh).ToLocalChecked());
} else {
info.GetReturnValue().Set(Nan::New<Integer>(error));
}
}
NAN_METHOD(node_mpg123_current_decoder) {
UNWRAP_MH;
const char *decoder = mpg123_current_decoder(mh);
info.GetReturnValue().Set(Nan::New<String>(decoder).ToLocalChecked());
}
NAN_METHOD(node_mpg123_supported_decoders) {
const char **decoders = mpg123_supported_decoders();
int i = 0;
v8::Local<Array> rtn = Nan::New<Array>();
while (*decoders != NULL) {
Nan::Set(rtn, i++, Nan::New<String>(*decoders).ToLocalChecked());
decoders++;
}
info.GetReturnValue().Set(rtn);
}
NAN_METHOD(node_mpg123_decoders) {
const char **decoders = mpg123_decoders();
int i = 0;
v8::Local<Array> rtn = Nan::New<Array>();
while (*decoders != NULL) {
Nan::Set(rtn, i++, Nan::New<String>(*decoders).ToLocalChecked());
decoders++;
}
info.GetReturnValue().Set(rtn);
}
NAN_METHOD(node_mpg123_open_feed) {
UNWRAP_MH;
int ret = mpg123_open_feed(mh);
info.GetReturnValue().Set(Nan::New<Integer>(ret));
}
NAN_METHOD(node_mpg123_getformat) {
UNWRAP_MH;
long rate;
int channels;
int encoding;
int ret;
Local<Value> rtn;
ret = mpg123_getformat(mh, &rate, &channels, &encoding);
if (ret == MPG123_OK) {
Local<Object> o = Nan::New<Object>();
Nan::Set(o, Nan::New<String>("raw_encoding").ToLocalChecked(), Nan::New<Number>(encoding));
Nan::Set(o, Nan::New<String>("sampleRate").ToLocalChecked(), Nan::New<Number>(rate));
Nan::Set(o, Nan::New<String>("channels").ToLocalChecked(), Nan::New<Number>(channels));
Nan::Set(o, Nan::New<String>("signed").ToLocalChecked(), Nan::New<Boolean>(encoding & MPG123_ENC_SIGNED));
Nan::Set(o, Nan::New<String>("float").ToLocalChecked(), Nan::New<Boolean>(encoding & MPG123_ENC_FLOAT));
Nan::Set(o, Nan::New<String>("ulaw").ToLocalChecked(), Nan::New<Boolean>(encoding & MPG123_ENC_ULAW_8));
Nan::Set(o, Nan::New<String>("alaw").ToLocalChecked(), Nan::New<Boolean>(encoding & MPG123_ENC_ALAW_8));
if (encoding & MPG123_ENC_8)
Nan::Set(o, Nan::New<String>("bitDepth").ToLocalChecked(), Nan::New<Integer>(8));
else if (encoding & MPG123_ENC_16)
Nan::Set(o, Nan::New<String>("bitDepth").ToLocalChecked(), Nan::New<Integer>(16));
else if (encoding & MPG123_ENC_24)
Nan::Set(o, Nan::New<String>("bitDepth").ToLocalChecked(), Nan::New<Integer>(24));
else if (encoding & MPG123_ENC_32 || encoding & MPG123_ENC_FLOAT_32)
Nan::Set(o, Nan::New<String>("bitDepth").ToLocalChecked(), Nan::New<Integer>(32));
else if (encoding & MPG123_ENC_FLOAT_64)
Nan::Set(o, Nan::New<String>("bitDepth").ToLocalChecked(), Nan::New<Integer>(64));
rtn = o;
} else {
rtn = Nan::New<Integer>(ret);
}
info.GetReturnValue().Set(rtn);
}
NAN_METHOD(node_mpg123_safe_buffer) {
info.GetReturnValue().Set(Nan::New<Number>(mpg123_safe_buffer()));
}
NAN_METHOD(node_mpg123_outblock) {
UNWRAP_MH;
info.GetReturnValue().Set(Nan::New<Number>(mpg123_outblock(mh)));
}
NAN_METHOD(node_mpg123_framepos) {
UNWRAP_MH;
info.GetReturnValue().Set(Nan::New<Number>(mpg123_framepos(mh)));
}
NAN_METHOD(node_mpg123_tell) {
UNWRAP_MH;
info.GetReturnValue().Set(Nan::New<Number>(mpg123_tell(mh)));
}
NAN_METHOD(node_mpg123_tellframe) {
UNWRAP_MH;
info.GetReturnValue().Set(Nan::New<Number>(mpg123_tellframe(mh)));
}
NAN_METHOD(node_mpg123_tell_stream) {
UNWRAP_MH;
info.GetReturnValue().Set(Nan::New<Number>(mpg123_tell_stream(mh)));
}
NAN_METHOD(node_mpg123_feed) {
UNWRAP_MH;
// input buffer
char *input = UnwrapPointer(info[1]);
size_t size = Nan::To<int32_t>(info[2]).FromMaybe(0);
feed_req *request = new feed_req;
request->mh = mh;
request->in = (const unsigned char *)input;
request->size = size;
request->callback.Reset(info[3].As<Function>());
request->req.data = request;
uv_queue_work(uv_default_loop(), &request->req,
node_mpg123_feed_async,
(uv_after_work_cb)node_mpg123_feed_after);
}
void node_mpg123_feed_async (uv_work_t *req) {
feed_req *r = (feed_req *)req->data;
r->rtn = mpg123_feed(
r->mh,
r->in,
r->size
);
}
void node_mpg123_feed_after (uv_work_t *req) {
Nan::HandleScope scope;
feed_req *r = (feed_req *)req->data;
Handle<Value> argv[1];
argv[0] = Nan::New<Integer>(r->rtn);
Nan::TryCatch try_catch;
Nan::New(r->callback)->Call(Nan::GetCurrentContext()->Global(), 1, argv);
// cleanup
r->callback.Reset();
delete r;
if (try_catch.HasCaught()) {
FatalException(try_catch);
}
}
NAN_METHOD(node_mpg123_read) {
UNWRAP_MH;
// output buffer
char *output = UnwrapPointer(info[1]);
size_t size = Nan::To<int32_t>(info[2]).FromMaybe(0);
read_req *request = new read_req;
request->mh = mh;
request->out = (unsigned char *)output;
request->size = size;
request->done = 0;
request->callback.Reset(info[3].As<Function>());
request->req.data = request;
uv_queue_work(uv_default_loop(), &request->req,
node_mpg123_read_async,
(uv_after_work_cb)node_mpg123_read_after);
}
void node_mpg123_read_async (uv_work_t *req) {
read_req *r = (read_req *)req->data;
r->rtn = mpg123_read(
r->mh,
r->out,
r->size,
&r->done
);
/* any new metadata? */
r->meta = mpg123_meta_check(r->mh);
}
void node_mpg123_read_after (uv_work_t *req) {
Nan::HandleScope scope;
read_req *r = (read_req *)req->data;
Handle<Value> argv[3];
argv[0] = Nan::New<Integer>(r->rtn);
argv[1] = Nan::New<Integer>(static_cast<uint32_t>(r->done));
argv[2] = Nan::New<Integer>(r->meta);
Nan::TryCatch try_catch;
Nan::New(r->callback)->Call(Nan::GetCurrentContext()->Global(), 3, argv);
// cleanup
r->callback.Reset();
delete r;
if (try_catch.HasCaught()) {
FatalException(try_catch);
}
}
NAN_METHOD(node_mpg123_id3) {
UNWRAP_MH;
id3_req *request = new id3_req;
request->mh = mh;
request->callback.Reset(info[1].As<Function>());
request->req.data = request;
uv_queue_work(uv_default_loop(), &request->req,
node_mpg123_id3_async,
(uv_after_work_cb)node_mpg123_id3_after);
}
void node_mpg123_id3_async (uv_work_t *req) {
id3_req *r = (id3_req *)req->data;
r->rtn = mpg123_id3(
r->mh,
&r->v1,
&r->v2
);
}
void node_mpg123_id3_after (uv_work_t *req) {
Nan::HandleScope scope;
id3_req *ireq = (id3_req *)req->data;
mpg123_id3v1 *v1 = ireq->v1;
mpg123_id3v2 *v2 = ireq->v2;
int r = ireq->rtn;
Handle<Value> rtn;
if (r == MPG123_OK) {
if (v1 != NULL) {
/* got id3v1 tags */
Local<Object> o = Nan::New<Object>();
#define SET(prop) \
Nan::Set(o, Nan::New<String>(#prop).ToLocalChecked(), Nan::New<String>(v1->prop, min(sizeof(v1->prop), v1->prop == NULL ? 0 : strlen(v1->prop))).ToLocalChecked());
SET(tag);
SET(title);
SET(artist);
SET(album);
SET(year);
if (v1->comment[28] == 0 && v1->comment[29] >= 1) {
/* ID3v1.1 */
Nan::Set(o, Nan::New<String>("comment").ToLocalChecked(), Nan::New<String>(v1->comment, min(sizeof(v1->comment) - 2, v1->comment == NULL ? 0 : strlen(v1->comment))).ToLocalChecked());
Nan::Set(o, Nan::New<String>("trackNumber").ToLocalChecked(), Nan::New<Integer>(v1->comment[29]));
} else {
/* ID3v1 */
SET(comment);
}
Nan::Set(o, Nan::New<String>("genre").ToLocalChecked(), Nan::New<Integer>(v1->genre));
rtn = o;
#undef SET
} else if (v2 != NULL) {
/* got id3v2 tags */
mpg123_string *s;
mpg123_text *t;
Local<Object> o = Nan::New<Object>();
Local<Array> a;
Local<Object> text;
#define SET(prop) \
s = v2->prop; \
if (s != NULL) \
Nan::Set(o, Nan::New<String>(#prop).ToLocalChecked(), Nan::New<String>(s->p, mpg123_strlen(s, 1)).ToLocalChecked());
SET(title)
SET(artist)
SET(album)
SET(year)
SET(genre)
SET(comment)
#undef SET
#define SET_ARRAY(array, count) \
a = Nan::New<Array>(v2->count); \
for (size_t i = 0; i < v2->count; i++) { \
t = &v2->array[i]; \
text = Nan::New<Object>(); \
Nan::Set(a, i, text); \
Nan::Set(text, Nan::New<String>("lang").ToLocalChecked(), Nan::New<String>(t->lang, min(sizeof(t->lang), strlen(t->lang))).ToLocalChecked()); \
Nan::Set(text, Nan::New<String>("id").ToLocalChecked(), Nan::New<String>(t->id, min(sizeof(t->id), strlen(t->id))).ToLocalChecked()); \
s = &t->description; \
if (s != NULL) \
Nan::Set(text, Nan::New<String>("description").ToLocalChecked(), Nan::New<String>(s->p, mpg123_strlen(s, 1)).ToLocalChecked()); \
s = &t->text; \
if (s != NULL) \
Nan::Set(text, Nan::New<String>("text").ToLocalChecked(), Nan::New<String>(s->p, mpg123_strlen(s, 1)).ToLocalChecked()); \
} \
Nan::Set(o, Nan::New<String>(#count).ToLocalChecked(), a);
SET_ARRAY(comment_list, comments)
SET_ARRAY(text, texts)
SET_ARRAY(extra, extras)
#undef SET_ARRAY
rtn = o;
} else {
rtn = Nan::Null();
}
}
Handle<Value> argv[2];
argv[0] = Nan::New<Integer>(ireq->rtn);
argv[1] = rtn;
Nan::TryCatch try_catch;
Nan::New(ireq->callback)->Call(Nan::GetCurrentContext()->Global(), 2, argv);
// cleanup
ireq->callback.Reset();
delete ireq;
if (try_catch.HasCaught()) {
FatalException(try_catch);
}
}
void InitMPG123(Handle<Object> target) {
Nan::HandleScope scope;
#define CONST_INT(value) \
Nan::ForceSet(target, Nan::New<String>(#value).ToLocalChecked(), Nan::New<Integer>(value), \
static_cast<PropertyAttribute>(ReadOnly|DontDelete));
// mpg123_errors
CONST_INT(MPG123_DONE); /**< Message: Track ended. Stop decoding. */
CONST_INT(MPG123_NEW_FORMAT); /**< Message: Output format will be different on next call. Note that some libmpg123 versions between 1.4.3 and 1.8.0 insist on you calling mpg123_getformat() after getting this message code. Newer verisons behave like advertised: You have the chance to call mpg123_getformat(), but you can also just continue decoding and get your data. */
CONST_INT(MPG123_NEED_MORE); /**< Message: For feed reader: "Feed me more!" (call mpg123_feed() or mpg123_decode() with some new input data). */
CONST_INT(MPG123_ERR); /**< Generic Error */
CONST_INT(MPG123_OK); /**< Success */
CONST_INT(MPG123_BAD_OUTFORMAT); /**< Unable to set up output format! */
CONST_INT(MPG123_BAD_CHANNEL); /**< Invalid channel number specified. */
CONST_INT(MPG123_BAD_RATE); /**< Invalid sample rate specified. */
CONST_INT(MPG123_ERR_16TO8TABLE); /**< Unable to allocate memory for 16 to 8 converter table! */
CONST_INT(MPG123_BAD_PARAM); /**< Bad parameter id! */
CONST_INT(MPG123_BAD_BUFFER); /**< Bad buffer given -- invalid pointer or too small size. */
CONST_INT(MPG123_OUT_OF_MEM); /**< Out of memory -- some malloc() failed. */
CONST_INT(MPG123_NOT_INITIALIZED); /**< You didn't initialize the library! */
CONST_INT(MPG123_BAD_DECODER); /**< Invalid decoder choice. */
CONST_INT(MPG123_BAD_HANDLE); /**< Invalid mpg123 handle. */
CONST_INT(MPG123_NO_BUFFERS); /**< Unable to initialize frame buffers (out of memory?). */
CONST_INT(MPG123_BAD_RVA); /**< Invalid RVA mode. */
CONST_INT(MPG123_NO_GAPLESS); /**< This build doesn't support gapless decoding. */
CONST_INT(MPG123_NO_SPACE); /**< Not enough buffer space. */
CONST_INT(MPG123_BAD_TYPES); /**< Incompatible numeric data types. */
CONST_INT(MPG123_BAD_BAND); /**< Bad equalizer band. */
CONST_INT(MPG123_ERR_NULL); /**< Null pointer given where valid storage address needed. */
CONST_INT(MPG123_ERR_READER); /**< Error reading the stream. */
CONST_INT(MPG123_NO_SEEK_FROM_END);/**< Cannot seek from end (end is not known). */
CONST_INT(MPG123_BAD_WHENCE); /**< Invalid 'whence' for seek function.*/
CONST_INT(MPG123_NO_TIMEOUT); /**< Build does not support stream timeouts. */
CONST_INT(MPG123_BAD_FILE); /**< File access error. */
CONST_INT(MPG123_NO_SEEK); /**< Seek not supported by stream. */
CONST_INT(MPG123_NO_READER); /**< No stream opened. */
CONST_INT(MPG123_BAD_PARS); /**< Bad parameter handle. */
CONST_INT(MPG123_BAD_INDEX_PAR); /**< Bad parameters to mpg123_index() and mpg123_set_index() */
CONST_INT(MPG123_OUT_OF_SYNC); /**< Lost track in bytestream and did not try to resync. */
CONST_INT(MPG123_RESYNC_FAIL); /**< Resync failed to find valid MPEG data. */
CONST_INT(MPG123_NO_8BIT); /**< No 8bit encoding possible. */
CONST_INT(MPG123_BAD_ALIGN); /**< Stack aligmnent error */
CONST_INT(MPG123_NULL_BUFFER); /**< NULL input buffer with non-zero size... */
CONST_INT(MPG123_NO_RELSEEK); /**< Relative seek not possible (screwed up file offset) */
CONST_INT(MPG123_NULL_POINTER); /**< You gave a null pointer somewhere where you shouldn't have. */
CONST_INT(MPG123_BAD_KEY); /**< Bad key value given. */
CONST_INT(MPG123_NO_INDEX); /**< No frame index in this build. */
CONST_INT(MPG123_INDEX_FAIL); /**< Something with frame index went wrong. */
CONST_INT(MPG123_BAD_DECODER_SETUP); /**< Something prevents a proper decoder setup */
CONST_INT(MPG123_MISSING_FEATURE); /**< This feature has not been built into libmpg123. */
CONST_INT(MPG123_BAD_VALUE); /**< A bad value has been given, somewhere. */
CONST_INT(MPG123_LSEEK_FAILED); /**< Low-level seek failed. */
CONST_INT(MPG123_BAD_CUSTOM_IO); /**< Custom I/O not prepared. */
CONST_INT(MPG123_LFS_OVERFLOW); /**< Offset value overflow during translation of large file API calls -- your client program cannot handle that large file. */
/* mpg123_enc_enum */
CONST_INT(MPG123_ENC_8);
CONST_INT(MPG123_ENC_16);
CONST_INT(MPG123_ENC_24);
CONST_INT(MPG123_ENC_32);
CONST_INT(MPG123_ENC_SIGNED);
CONST_INT(MPG123_ENC_FLOAT);
CONST_INT(MPG123_ENC_SIGNED_16);
CONST_INT(MPG123_ENC_UNSIGNED_16);
CONST_INT(MPG123_ENC_UNSIGNED_8);
CONST_INT(MPG123_ENC_SIGNED_8);
CONST_INT(MPG123_ENC_ULAW_8);
CONST_INT(MPG123_ENC_ALAW_8);
CONST_INT(MPG123_ENC_SIGNED_32);
CONST_INT(MPG123_ENC_UNSIGNED_32);
CONST_INT(MPG123_ENC_SIGNED_24);
CONST_INT(MPG123_ENC_UNSIGNED_24);
CONST_INT(MPG123_ENC_FLOAT_32);
CONST_INT(MPG123_ENC_FLOAT_64);
CONST_INT(MPG123_ENC_ANY);
/* mpg123_channelcount */
CONST_INT(MPG123_MONO);
CONST_INT(MPG123_STEREO);
/* mpg123_channels */
CONST_INT(MPG123_LEFT);
CONST_INT(MPG123_RIGHT);
CONST_INT(MPG123_LR);
CONST_INT(MPG123_ID3);
CONST_INT(MPG123_NEW_ID3);
CONST_INT(MPG123_ICY);
CONST_INT(MPG123_NEW_ICY);
Nan::SetMethod(target, "mpg123_init", node_mpg123_init);
Nan::SetMethod(target, "mpg123_exit", node_mpg123_exit);
Nan::SetMethod(target, "mpg123_new", node_mpg123_new);
Nan::SetMethod(target, "mpg123_decoders", node_mpg123_decoders);
Nan::SetMethod(target, "mpg123_current_decoder", node_mpg123_current_decoder);
Nan::SetMethod(target, "mpg123_supported_decoders", node_mpg123_supported_decoders);
Nan::SetMethod(target, "mpg123_getformat", node_mpg123_getformat);
Nan::SetMethod(target, "mpg123_safe_buffer", node_mpg123_safe_buffer);
Nan::SetMethod(target, "mpg123_outblock", node_mpg123_outblock);
Nan::SetMethod(target, "mpg123_framepos", node_mpg123_framepos);
Nan::SetMethod(target, "mpg123_tell", node_mpg123_tell);
Nan::SetMethod(target, "mpg123_tellframe", node_mpg123_tellframe);
Nan::SetMethod(target, "mpg123_tell_stream", node_mpg123_tell_stream);
Nan::SetMethod(target, "mpg123_open_feed", node_mpg123_open_feed);
Nan::SetMethod(target, "mpg123_feed", node_mpg123_feed);
Nan::SetMethod(target, "mpg123_read", node_mpg123_read);
Nan::SetMethod(target, "mpg123_id3", node_mpg123_id3);
}
} // nodelame namespace

46
node_modules/lame/src/node_mpg123.h generated vendored Normal file
View File

@ -0,0 +1,46 @@
#include <v8.h>
#include <node.h>
#include "mpg123.h"
namespace nodelame {
/* structs used for async decoding */
struct feed_req {
uv_work_t req;
mpg123_handle *mh;
const unsigned char *in;
size_t size;
int rtn;
Nan::Persistent<v8::Function> callback;
};
struct read_req {
uv_work_t req;
mpg123_handle *mh;
unsigned char *out;
size_t size;
size_t done;
int rtn;
int meta;
Nan::Persistent<v8::Function> callback;
};
struct id3_req {
uv_work_t req;
mpg123_handle *mh;
mpg123_id3v1 *v1;
mpg123_id3v2 *v2;
int rtn;
Nan::Persistent<v8::Function> callback;
};
void node_mpg123_feed_async (uv_work_t *);
void node_mpg123_feed_after (uv_work_t *);
void node_mpg123_read_async (uv_work_t *);
void node_mpg123_read_after (uv_work_t *);
void node_mpg123_id3_async (uv_work_t *);
void node_mpg123_id3_after (uv_work_t *);
} // nodelame namespace

55
node_modules/lame/src/node_pointer.h generated vendored Normal file
View File

@ -0,0 +1,55 @@
/*
* Helper functions for treating node Buffer instances as C "pointers".
*/
#include "v8.h"
#include "nan.h"
#include "node_buffer.h"
/*
* Called when the "pointer" is garbage collected.
*/
inline static void wrap_pointer_cb(char *data, void *hint) {
//fprintf(stderr, "wrap_pointer_cb\n");
}
/*
* Wraps "ptr" into a new SlowBuffer instance with size "length".
*/
inline static Nan::MaybeLocal<v8::Object> WrapPointer(void *ptr, size_t length) {
void *user_data = NULL;
return Nan::NewBuffer((char *)ptr, length, wrap_pointer_cb, user_data);
}
/*
* Wraps "ptr" into a new SlowBuffer instance with length 0.
*/
inline static Nan::MaybeLocal<v8::Object> WrapPointer(void *ptr) {
return WrapPointer((char *)ptr, 0);
}
/*
* Unwraps Buffer instance "buffer" to a C `char *` with the offset specified.
*/
inline static char * UnwrapPointer(v8::Handle<v8::Value> buffer, int64_t offset = 0) {
if (node::Buffer::HasInstance(buffer)) {
return node::Buffer::Data(buffer.As<v8::Object>()) + offset;
} else {
return NULL;
}
}
/**
* Templated version of UnwrapPointer that does a reinterpret_cast() on the
* pointer before returning it.
*/
template <typename Type>
inline static Type UnwrapPointer(v8::Handle<v8::Value> buffer) {
return reinterpret_cast<Type>(UnwrapPointer(buffer));
}