instantBufferBytes are now a configurable option

This commit is contained in:
seansaleh 2014-04-27 18:54:05 -07:00 committed by Sean Saleh
parent 35648a0a1d
commit 7ea657e0d4
2 changed files with 9 additions and 8 deletions

View file

@ -44,6 +44,7 @@ var defaultConfig = {
mpdHost: '0.0.0.0',
mpdPort: 6600,
acoustidAppKey: 'bgFvC4vW',
instantBufferBytes: 220 * 1024,
};
defaultConfig.permissions[genPassword()] = {
@ -139,7 +140,7 @@ GrooveBasin.prototype.start = function() {
self.initializeDownload();
self.initializeUpload();
self.player = new Player(self.db, self.config.musicDirectory);
self.player = new Player(self.db, self.config.musicDirectory, self.config.instantBufferBytes);
self.player.initialize(function(err) {
if (err) {
console.error("unable to initialize player:", err.stack);

View file

@ -201,10 +201,6 @@ var OPEN_FILE_COUNT = 8;
var PREV_FILE_COUNT = Math.floor(OPEN_FILE_COUNT / 2);
var NEXT_FILE_COUNT = OPEN_FILE_COUNT - PREV_FILE_COUNT;
// when a streaming client connects we send them many buffers quickly
// in order to get the stream started, then we slow down.
var instantBufferBytes = 220 * 1024;
var DB_SCALE = Math.log(10.0) * 0.05;
var REPLAYGAIN_PREAMP = 0.75;
var REPLAYGAIN_DEFAULT = 0.25;
@ -216,7 +212,7 @@ Player.REPEAT_ALL = 2;
Player.trackWithoutIndex = trackWithoutIndex;
util.inherits(Player, EventEmitter);
function Player(db, musicDirectory) {
function Player(db, musicDirectory, instantBufferBytes) {
EventEmitter.call(this);
this.setMaxListeners(0);
@ -225,6 +221,10 @@ function Player(db, musicDirectory) {
this.dbFilesByPath = {};
this.libraryIndex = new MusicLibraryIndex();
this.addQueue = new DedupedQueue({processOne: this.addToLibrary.bind(this)});
// when a streaming client connects we send them many buffers quickly
// in order to get the stream started, then we slow down.
this.instantBufferBytes = instantBufferBytes;
this.dirs = {};
this.dirScanQueue = new DedupedQueue({
@ -320,7 +320,7 @@ Player.prototype.initialize = function(cb) {
// available or we get enough buffered
while (1) {
var bufferedSeconds = self.secondsIntoFuture(self.lastEncodeItem, self.lastEncodePos);
if (bufferedSeconds > 0.5 && self.recentBuffersByteCount >= instantBufferBytes) return;
if (bufferedSeconds > 0.5 && self.recentBuffersByteCount >= self.instantBufferBytes) return;
var buf = self.grooveEncoder.getBuffer();
if (!buf) return;
if (buf.buffer) {
@ -334,7 +334,7 @@ Player.prototype.initialize = function(cb) {
self.recentBuffers.push(buf.buffer);
self.recentBuffersByteCount += buf.buffer.length;
while (self.recentBuffers.length > 0 &&
self.recentBuffersByteCount - self.recentBuffers[0].length >= instantBufferBytes)
self.recentBuffersByteCount - self.recentBuffers[0].length >= self.instantBufferBytes)
{
self.recentBuffersByteCount -= self.recentBuffers.shift().length;
}