Skip to content

Commit

Permalink
No throttle in openradio-pulse
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonle committed Jul 29, 2021
1 parent b30b3bc commit a604ec7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
48 changes: 37 additions & 11 deletions cli/pulse.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
const supportedPlatform = ["Linux"];
const { spawn } = require("child_process");
const openradio = require("../");
const { FFmpeg } = require("prism-media");
const fs = require("fs");
const http = require("http");
const server = http.createServer();
Expand Down Expand Up @@ -40,6 +40,37 @@ let error = (text) => {
process.exit(1);
};

function pcmconv(opt = {}, pcmopt) {
return new FFmpeg({
args: [
"-analyzeduration",
"0",
"-loglevel",
"0",
"-f",
"s16le",
"-ac",
pcmopt.channels || 2,
"-ar",
pcmopt.rate || "44100",
"-i",
"-",
"-f",
opt.format || "mp3",
"-ar",
opt.rate || "48000",
"-ac",
opt.channels || "2",
"-ab",
`${opt.bitrate || "96"}k`,
"-map",
"0:a",
"-map_metadata",
"-1",
]
});
}

if (config.force)
console.warn("Warning: I'm sure you know what are you doing.");

Expand Down Expand Up @@ -220,23 +251,18 @@ let listener = server.listen(config.server.port, config.server.address, () => {
listener.address().port
);

let radio = openradio(config.output);
function play() {
let parec = spawn(config.parec_path, config.input);
parec.on("close", play);
parec.on("error", (err) => console.error(`[${Date()}]`, err));
parec.stderr.pipe(process.stderr);
radio.playPCM(parec.stdout, config.input);
}

radio.on("data", (chunk) => {
if (!header) header = chunk;
sink.forEach((res, id) => {
res.write(chunk, (err) => {
parec.stdout.pipe(pcmconv(config.output, config.input)).on('error', err => console.error(`[${Date()}]`, err)).on('data', chunk => {
if (!header) header = chunk;
sink.forEach((res, id) => res.write(chunk, err => {
if (err) sink.delete(id);
});
}));
});
});
}

play();
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openradio",
"version": "1.1.45",
"version": "1.1.46",
"description": "Let you create your own livestream radio.",
"main": "./core",
"scripts": {
Expand Down

0 comments on commit a604ec7

Please sign in to comment.