mirror of
https://github.com/darksaid98/mediaplex.git
synced 2026-12-02 22:17:32 +00:00
0.0.0
This commit is contained in:
1 parent
8d6839244a
commit
dd706e7f23
14 files changed
+766
-8
No files matched your search
Vendored
+88
@@ -0,0 +1,88 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
/* auto-generated by NAPI-RS */
|
||||
|
||||
export interface ProbeResult {
|
||||
/** The number of channels */
|
||||
channels: number
|
||||
/** The sample rate */
|
||||
sampleRate: number
|
||||
/** The number of frames per block */
|
||||
framesPerBlock: number
|
||||
/** The codec type */
|
||||
codec: JsCodecType
|
||||
/** The number of frames */
|
||||
nFrames: number
|
||||
/** The duration of this media in seconds */
|
||||
duration: number
|
||||
}
|
||||
export const enum CodecType {
|
||||
UNKNOWN = 0,
|
||||
PCM_S32LE = 256,
|
||||
PCM_S32LE_PLANAR = 257,
|
||||
PCM_S32BE = 258,
|
||||
PCM_S32BE_PLANAR = 259,
|
||||
PCM_S24LE = 260,
|
||||
PCM_S24LE_PLANAR = 261,
|
||||
PCM_S24BE = 262,
|
||||
PCM_S24BE_PLANAR = 263,
|
||||
PCM_S16LE = 264,
|
||||
PCM_S16LE_PLANAR = 265,
|
||||
PCM_S16BE = 266,
|
||||
PCM_S16BE_PLANAR = 267,
|
||||
PCM_S8 = 268,
|
||||
PCM_S8_PLANAR = 269,
|
||||
PCM_U32LE = 270,
|
||||
PCM_U32LE_PLANAR = 271,
|
||||
PCM_U32BE = 272,
|
||||
PCM_U32BE_PLANAR = 273,
|
||||
PCM_U24LE = 274,
|
||||
PCM_U24LE_PLANAR = 275,
|
||||
PCM_U24BE = 276,
|
||||
PCM_U24BE_PLANAR = 277,
|
||||
PCM_U16LE = 278,
|
||||
PCM_U16LE_PLANAR = 279,
|
||||
PCM_U16BE = 280,
|
||||
PCM_U16BE_PLANAR = 281,
|
||||
PCM_U8 = 282,
|
||||
PCM_U8_PLANAR = 283,
|
||||
PCM_F32LE = 284,
|
||||
PCM_F32LE_PLANAR = 285,
|
||||
PCM_F32BE = 286,
|
||||
PCM_F32BE_PLANAR = 287,
|
||||
PCM_F64LE = 288,
|
||||
PCM_F64LE_PLANAR = 289,
|
||||
PCM_F64BE = 290,
|
||||
PCM_F64BE_PLANAR = 291,
|
||||
PCM_ALAW = 292,
|
||||
PCM_MULAW = 293,
|
||||
ADPCM_G722 = 512,
|
||||
ADPCM_G726 = 513,
|
||||
ADPCM_G726LE = 514,
|
||||
ADPCM_MS = 515,
|
||||
ADPCM_IMA_WAV = 516,
|
||||
ADPCM_IMA_QT = 517,
|
||||
VORBIS = 4096,
|
||||
MP1 = 4097,
|
||||
MP2 = 4098,
|
||||
MP3 = 4099,
|
||||
AAC = 4100,
|
||||
OPUS = 4101,
|
||||
SPEEX = 4102,
|
||||
MUSEPACK = 4103,
|
||||
ATRAC1 = 4104,
|
||||
ATRAC3 = 4105,
|
||||
ATRAC3PLUS = 4106,
|
||||
ATRAC9 = 4107,
|
||||
EAC3 = 4108,
|
||||
AC4 = 4109,
|
||||
DCA = 4110,
|
||||
WMA = 4111,
|
||||
FLAC = 8192,
|
||||
WAVPACK = 8193,
|
||||
MONKEYS_AUDIO = 8194,
|
||||
ALAC = 8195,
|
||||
TTA = 8196
|
||||
}
|
||||
export function probe(data: Buffer): ProbeResult
|
||||
+258
@@ -0,0 +1,258 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
|
||||
/* auto-generated by NAPI-RS */
|
||||
|
||||
const { existsSync, readFileSync } = require('fs')
|
||||
const { join } = require('path')
|
||||
|
||||
const { platform, arch } = process
|
||||
|
||||
let nativeBinding = null
|
||||
let localFileExisted = false
|
||||
let loadError = null
|
||||
|
||||
function isMusl() {
|
||||
// For Node 10
|
||||
if (!process.report || typeof process.report.getReport !== 'function') {
|
||||
try {
|
||||
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
||||
return readFileSync(lddPath, 'utf8').includes('musl')
|
||||
} catch (e) {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
const { glibcVersionRuntime } = process.report.getReport().header
|
||||
return !glibcVersionRuntime
|
||||
}
|
||||
}
|
||||
|
||||
switch (platform) {
|
||||
case 'android':
|
||||
switch (arch) {
|
||||
case 'arm64':
|
||||
localFileExisted = existsSync(join(__dirname, 'mediaplex.android-arm64.node'))
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.android-arm64.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-android-arm64')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
case 'arm':
|
||||
localFileExisted = existsSync(join(__dirname, 'mediaplex.android-arm-eabi.node'))
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.android-arm-eabi.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-android-arm-eabi')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported architecture on Android ${arch}`)
|
||||
}
|
||||
break
|
||||
case 'win32':
|
||||
switch (arch) {
|
||||
case 'x64':
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'mediaplex.win32-x64-msvc.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.win32-x64-msvc.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-win32-x64-msvc')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
case 'ia32':
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'mediaplex.win32-ia32-msvc.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.win32-ia32-msvc.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-win32-ia32-msvc')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
case 'arm64':
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'mediaplex.win32-arm64-msvc.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.win32-arm64-msvc.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-win32-arm64-msvc')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
||||
}
|
||||
break
|
||||
case 'darwin':
|
||||
localFileExisted = existsSync(join(__dirname, 'mediaplex.darwin-universal.node'))
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.darwin-universal.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-darwin-universal')
|
||||
}
|
||||
break
|
||||
} catch {}
|
||||
switch (arch) {
|
||||
case 'x64':
|
||||
localFileExisted = existsSync(join(__dirname, 'mediaplex.darwin-x64.node'))
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.darwin-x64.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-darwin-x64')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
case 'arm64':
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'mediaplex.darwin-arm64.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.darwin-arm64.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-darwin-arm64')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
||||
}
|
||||
break
|
||||
case 'freebsd':
|
||||
if (arch !== 'x64') {
|
||||
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
||||
}
|
||||
localFileExisted = existsSync(join(__dirname, 'mediaplex.freebsd-x64.node'))
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.freebsd-x64.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-freebsd-x64')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
case 'linux':
|
||||
switch (arch) {
|
||||
case 'x64':
|
||||
if (isMusl()) {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'mediaplex.linux-x64-musl.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.linux-x64-musl.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-linux-x64-musl')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
} else {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'mediaplex.linux-x64-gnu.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.linux-x64-gnu.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-linux-x64-gnu')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'arm64':
|
||||
if (isMusl()) {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'mediaplex.linux-arm64-musl.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.linux-arm64-musl.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-linux-arm64-musl')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
} else {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'mediaplex.linux-arm64-gnu.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.linux-arm64-gnu.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-linux-arm64-gnu')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'arm':
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'mediaplex.linux-arm-gnueabihf.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./mediaplex.linux-arm-gnueabihf.node')
|
||||
} else {
|
||||
nativeBinding = require('mediaplex-linux-arm-gnueabihf')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
||||
}
|
||||
|
||||
if (!nativeBinding) {
|
||||
if (loadError) {
|
||||
throw loadError
|
||||
}
|
||||
throw new Error(`Failed to load native binding`)
|
||||
}
|
||||
|
||||
const { CodecType, probe } = nativeBinding
|
||||
|
||||
module.exports.CodecType = CodecType
|
||||
module.exports.probe = probe
|
||||
@@ -0,0 +1,95 @@
|
||||
const binding = require('./binding');
|
||||
const { Readable } = require('stream');
|
||||
|
||||
/**
|
||||
* @typedef StreamProbeResult
|
||||
* @property {Readable} stream The source stream
|
||||
* @property {binding.ProbeResult} result The probe result
|
||||
*/
|
||||
|
||||
/**
|
||||
* Attempt to probe a Readable stream
|
||||
* @param {Readable} stream The readable stream to probe
|
||||
* @param {number} [probeSize] The number of bytes to read
|
||||
* @returns {Promise<StreamProbeResult>}
|
||||
*/
|
||||
async function probeStream(
|
||||
stream,
|
||||
probeSize = 1024
|
||||
) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// preconditions
|
||||
if (stream.readableObjectMode) {
|
||||
reject(new Error('Cannot probe a readable stream in object mode'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (stream.readableEnded) {
|
||||
reject(new Error('Cannot probe a stream that has ended'));
|
||||
return;
|
||||
}
|
||||
|
||||
let readBuffer = Buffer.alloc(0);
|
||||
|
||||
/**
|
||||
* @type {binding.ProbeResult}
|
||||
*/
|
||||
let resolved = null;
|
||||
|
||||
const finish = (data) => {
|
||||
stream.off('data', onData);
|
||||
stream.off('close', onClose);
|
||||
stream.off('end', onClose);
|
||||
stream.pause();
|
||||
|
||||
resolved = data;
|
||||
|
||||
if (stream.readableEnded) {
|
||||
resolve({
|
||||
stream: Readable.from(readBuffer),
|
||||
result: data,
|
||||
});
|
||||
} else {
|
||||
if (readBuffer.length > 0) {
|
||||
stream.push(readBuffer);
|
||||
}
|
||||
|
||||
resolve({
|
||||
stream,
|
||||
result: data,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
if (!resolved) {
|
||||
finish(null);
|
||||
}
|
||||
};
|
||||
|
||||
const onData = (buffer) => {
|
||||
readBuffer = Buffer.concat([readBuffer, buffer]);
|
||||
|
||||
try {
|
||||
const result = binding.probe(readBuffer);
|
||||
return finish(result);
|
||||
} catch {}
|
||||
|
||||
if (readBuffer.length >= probeSize) {
|
||||
stream.off('data', onData);
|
||||
stream.pause();
|
||||
process.nextTick(onClose);
|
||||
}
|
||||
};
|
||||
|
||||
stream.once('error', reject);
|
||||
stream.on('data', onData);
|
||||
stream.once('close', onClose);
|
||||
stream.once('end', onClose);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
...binding,
|
||||
probeStream,
|
||||
};
|
||||
Reference in new issue
Block a user