-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Maxime Gervais <[email protected]>
- Loading branch information
Showing
14 changed files
with
2,159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
mediainfolib | ||
================== | ||
Native MediaInfo library wrapper for Node.js using N-API. | ||
|
||
Install | ||
------- | ||
```sh | ||
$ npm install --save mediainfolib | ||
``` | ||
|
||
Build | ||
----- | ||
```sh | ||
npm install node-addon-api | ||
node-gyp configure | ||
node-gyp build | ||
``` | ||
|
||
Usage | ||
----- | ||
First install the MediaInfo native library on your system (see https://mediaarea.net/MediaInfo) | ||
|
||
```js | ||
var mod = require('mediainfolib'); | ||
var mi = mod.MediaInfo(); | ||
|
||
mi.Open('Example.ogg'); | ||
console.log(mi.Inform()); | ||
``` | ||
See example.js for more examples. | ||
|
||
License | ||
------- | ||
Use of this source code is governed by a BSD-style license. | ||
See https://mediaarea.net/en/MediaInfo/License for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* Copyright (c) MediaArea.net SARL. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by a BSD-style license that can | ||
* be found in the License.html file in the root of the source tree. | ||
*/ | ||
|
||
#include <locale> | ||
#include <codecvt> | ||
|
||
#include "Helpers.h" | ||
|
||
// | ||
// Helpers functions | ||
// | ||
bool To_Uint32(napi_env Environment, napi_value Source, uint32_t& Destination) | ||
{ napi_valuetype Value_Type; | ||
if (napi_typeof(Environment, Source, &Value_Type)!=napi_ok || Value_Type!=napi_number) | ||
return false; | ||
|
||
if (napi_get_value_uint32(Environment, Source, &Destination)!=napi_ok) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
bool To_Int64(napi_env Environment, napi_value Source, int64_t& Destination) | ||
{ | ||
napi_valuetype Value_Type; | ||
if (napi_typeof(Environment, Source, &Value_Type)!=napi_ok || Value_Type!=napi_number) | ||
return false; | ||
|
||
if (napi_get_value_int64(Environment, Source, &Destination)!=napi_ok) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
bool To_SizeT(napi_env Environment, napi_value Source, size_t& Destination) | ||
{ | ||
napi_valuetype Value_Type; | ||
if (napi_typeof(Environment, Source, &Value_Type)!=napi_ok || Value_Type!=napi_number) | ||
return false; | ||
|
||
switch (sizeof(size_t)) | ||
{ | ||
case 4: // size_t is 32 bits | ||
if (napi_get_value_uint32(Environment, Source, (uint32_t*)&Destination)!=napi_ok) | ||
return false; | ||
break; | ||
break; | ||
case 8: // size_t is 64 bits | ||
if (napi_get_value_int64(Environment, Source, (int64_t*)&Destination)!=napi_ok) | ||
return false; | ||
break; | ||
default: // unsupported | ||
napi_throw_error(Environment, NULL, "internal error: unsupported size_t size"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool To_Unicode(napi_env Environment, napi_value Source, std::wstring& Destination) | ||
{ | ||
napi_valuetype Value_Type; | ||
if (napi_typeof(Environment, Source, &Value_Type)!=napi_ok || Value_Type!=napi_string) | ||
return false; | ||
|
||
size_t Source_Size=0; | ||
if (napi_get_value_string_utf8(Environment, Source, NULL, 0, &Source_Size)!=napi_ok) | ||
return false; | ||
|
||
char Buffer[Source_Size+1]; | ||
if (napi_get_value_string_utf8(Environment, Source, (char*)Buffer, Source_Size+1, &Source_Size)!=napi_ok) | ||
return false; | ||
|
||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> Codec; | ||
Destination=Codec.from_bytes((char*)Buffer); | ||
|
||
return true; | ||
} | ||
|
||
std::string From_Unicode(std::wstring Source) | ||
{ | ||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> Codec; | ||
return Codec.to_bytes(Source); | ||
} | ||
|
||
napi_value From_SizeT(napi_env Environment, const size_t Source) | ||
{ | ||
napi_value ToReturn; | ||
switch (sizeof(size_t)) | ||
{ | ||
case 4: // size_t is 32 bits | ||
if (napi_create_uint32(Environment, Source, &ToReturn)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: napi_create_uint32() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
break; | ||
break; | ||
case 8: // size_t is 64 bits | ||
if (napi_create_int64(Environment, Source, &ToReturn)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: napi_create_int64() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
break; | ||
default: // unsupported | ||
napi_throw_error(Environment, NULL, "internal error: unsupported size_t size"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
return ToReturn; | ||
} | ||
|
||
napi_value Undefined(napi_env Environment) | ||
{ | ||
napi_value ToReturn; | ||
if (napi_get_undefined(Environment, &ToReturn)!=napi_ok) | ||
napi_throw_error(Environment, NULL, "internal error: napi_get_undefined() failed, returned value may be inconsistent"); | ||
|
||
return ToReturn; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright (c) MediaArea.net SARL. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by a BSD-style license that can | ||
* be found in the License.html file in the root of the source tree. | ||
*/ | ||
|
||
#ifndef HelpersH | ||
#define HelpersH | ||
|
||
#include <string> | ||
#include <node_api.h> | ||
|
||
bool To_Uint32(napi_env Environment, napi_value Source, uint32_t& Destination); | ||
bool To_Int64(napi_env Environment, napi_value Source, int64_t& Destination); | ||
bool To_SizeT(napi_env Environment, napi_value Source, size_t& Destination); | ||
bool To_Unicode(napi_env Environment, napi_value Source, std::wstring& Destination); | ||
std::string From_Unicode(std::wstring Source); | ||
napi_value From_SizeT(napi_env Environment, const size_t Source); | ||
napi_value Undefined(napi_env Environment); | ||
|
||
#endif //HelpersH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* Copyright (c) MediaArea.net SARL. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by a BSD-style license that can | ||
* be found in the License.html file in the root of the source tree. | ||
*/ | ||
|
||
#include "Helpers.h" | ||
#include "NodeMediaInfo.h" | ||
#include "NodeMediaInfoList.h" | ||
|
||
napi_value CreateMediaInfoObject(napi_env Environment, napi_callback_info Info) | ||
{ | ||
size_t ArgumentsCount=1; | ||
napi_value Arguments[ArgumentsCount]; | ||
|
||
if (napi_get_cb_info(Environment, Info, &ArgumentsCount, Arguments, NULL, NULL)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: napi_get_cb_info() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
napi_value Instance; | ||
if (NodeMediaInfo::NewInstance(Environment, ArgumentsCount, Arguments, &Instance)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: NodeMediaInfo::NewInstance() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
return Instance; | ||
} | ||
|
||
napi_value CreateMediaInfoListObject(napi_env Environment, napi_callback_info Info) | ||
{ | ||
size_t ArgumentsCount=1; | ||
napi_value Arguments[ArgumentsCount]; | ||
|
||
if (napi_get_cb_info(Environment, Info, &ArgumentsCount, Arguments, NULL, NULL)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: napi_get_cb_info() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
napi_value Instance; | ||
if (NodeMediaInfoList::NewInstance(Environment, ArgumentsCount, Arguments, &Instance)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: NodeMediaInfoList::NewInstance() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
return Instance; | ||
} | ||
|
||
napi_value Init(napi_env Environment, napi_value Exports) | ||
{ | ||
if (NodeMediaInfo::Init(Environment)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: NodeMediaInfo::Init() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
if (NodeMediaInfoList::Init(Environment)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: NodeMediaInfoList::Init() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
napi_value MediaInfoFunc; | ||
if (napi_create_function(Environment, "MediaInfo", NAPI_AUTO_LENGTH, CreateMediaInfoObject, NULL, &MediaInfoFunc)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: napi_create_function() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
napi_value MediaInfoListFunc; | ||
if (napi_create_function(Environment, "MediaInfoList", NAPI_AUTO_LENGTH, CreateMediaInfoListObject, NULL, &MediaInfoListFunc)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: napi_create_function() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
if (napi_set_named_property(Environment, Exports, "MediaInfo", MediaInfoFunc)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: napi_set_named_property() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
if (napi_set_named_property(Environment, Exports, "MediaInfoList", MediaInfoListFunc)!=napi_ok) | ||
{ | ||
napi_throw_error(Environment, NULL, "internal error: napi_set_named_property() failed"); | ||
return Undefined(Environment); //undefined | ||
} | ||
|
||
return Exports; | ||
} | ||
|
||
NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) |
Oops, something went wrong.