2004-02-24 00:41:20 +01:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
2004-02-24 00:41:20 +01:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "playerData.h"
|
2008-08-26 08:40:47 +02:00
|
|
|
#include "decode.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "conf.h"
|
|
|
|
#include "log.h"
|
2008-04-12 06:17:12 +02:00
|
|
|
#include "utils.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2007-05-27 15:12:02 +02:00
|
|
|
#define DEFAULT_BUFFER_SIZE 2048
|
|
|
|
#define DEFAULT_BUFFER_BEFORE_PLAY 10
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2008-06-02 12:10:26 +02:00
|
|
|
unsigned int buffered_before_play;
|
2008-04-13 03:15:50 +02:00
|
|
|
PlayerControl pc;
|
2008-04-13 03:16:27 +02:00
|
|
|
OutputBuffer ob;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void initPlayerData(void)
|
|
|
|
{
|
2004-10-28 07:14:55 +02:00
|
|
|
float perc = DEFAULT_BUFFER_BEFORE_PLAY;
|
2006-07-20 18:02:40 +02:00
|
|
|
char *test;
|
2004-02-24 00:41:20 +01:00
|
|
|
int crossfade = 0;
|
2004-10-28 07:14:55 +02:00
|
|
|
size_t bufferSize = DEFAULT_BUFFER_SIZE;
|
2008-04-12 06:18:12 +02:00
|
|
|
unsigned int buffered_chunks;
|
2006-07-20 18:02:40 +02:00
|
|
|
ConfigParam *param;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2004-10-28 07:14:55 +02:00
|
|
|
param = getConfigParam(CONF_AUDIO_BUFFER_SIZE);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (param) {
|
2004-10-28 07:14:55 +02:00
|
|
|
bufferSize = strtol(param->value, &test, 10);
|
2006-07-20 18:02:40 +02:00
|
|
|
if (*test != '\0' || bufferSize <= 0) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("buffer size \"%s\" is not a positive integer, "
|
2006-07-20 18:02:40 +02:00
|
|
|
"line %i\n", param->value, param->line);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
bufferSize *= 1024;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
buffered_chunks = bufferSize / CHUNK_SIZE;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (buffered_chunks >= 1 << 15) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("buffer size \"%li\" is too big\n", (long)bufferSize);
|
2004-04-01 02:33:35 +02:00
|
|
|
}
|
|
|
|
|
2004-10-28 07:14:55 +02:00
|
|
|
param = getConfigParam(CONF_BUFFER_BEFORE_PLAY);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (param) {
|
2004-10-28 07:14:55 +02:00
|
|
|
perc = strtod(param->value, &test);
|
2006-07-20 18:02:40 +02:00
|
|
|
if (*test != '%' || perc < 0 || perc > 100) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("buffered before play \"%s\" is not a positive "
|
2006-07-20 18:02:40 +02:00
|
|
|
"percentage and less than 100 percent, line %i"
|
|
|
|
"\n", param->value, param->line);
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
buffered_before_play = (perc / 100) * buffered_chunks;
|
|
|
|
if (buffered_before_play > buffered_chunks) {
|
2004-02-25 22:10:56 +01:00
|
|
|
buffered_before_play = buffered_chunks;
|
2008-04-12 06:07:01 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-08-26 08:27:05 +02:00
|
|
|
ob_init(buffered_chunks, &pc.notify);
|
2008-04-12 06:17:55 +02:00
|
|
|
|
2008-06-02 00:24:44 +02:00
|
|
|
notify_init(&pc.notify);
|
2008-08-26 08:27:07 +02:00
|
|
|
pc.command = PLAYER_COMMAND_NONE;
|
2008-04-13 03:15:50 +02:00
|
|
|
pc.error = PLAYER_ERROR_NOERROR;
|
|
|
|
pc.state = PLAYER_STATE_STOP;
|
|
|
|
pc.queueState = PLAYER_QUEUE_BLANK;
|
|
|
|
pc.queueLockState = PLAYER_QUEUE_UNLOCKED;
|
|
|
|
pc.crossFade = crossfade;
|
|
|
|
pc.softwareVolume = 1000;
|
2008-04-12 06:17:55 +02:00
|
|
|
|
2008-06-02 00:24:44 +02:00
|
|
|
notify_init(&dc.notify);
|
2008-04-13 03:16:03 +02:00
|
|
|
dc.state = DECODE_STATE_STOP;
|
2008-08-26 08:27:04 +02:00
|
|
|
dc.command = DECODE_COMMAND_NONE;
|
2008-04-13 03:16:03 +02:00
|
|
|
dc.error = DECODE_ERROR_NOERROR;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-04-12 06:17:12 +02:00
|
|
|
|