Commit Graph

251 Commits

Author SHA1 Message Date
Max Kellermann 5f77910097 conf: const pointers in block get functions
All config_get_block_*() functions should accept constant config_param
pointers.
2009-01-25 16:03:49 +01:00
Max Kellermann 1a59afa388 stored_playlist: moved configuration variables from playlist.c
Don't declare and export variables specific to stored playlists in
playlist.c/playlist.h.
2009-01-25 13:53:16 +01:00
Max Kellermann 85f7e964de player_thread: start decoder thread in player thread
Start the decoder thread when the player thread starts.  The decoder
thread is already stopped by the player thread.
2009-01-25 13:44:39 +01:00
Max Kellermann 145ab84d51 sticker: new library for storing dynamic information about songs
"Stickers" are pieces of information attached to existing MPD objects
(e.g. song files, directories, albums).  Clients can create arbitrary
name/value pairs.  MPD itself does not assume any special meaning in
them.
2009-01-19 18:51:57 +01:00
Max Kellermann 9c93249412 daemon: pass "detach" flag to daemonize()
This way, we don't have to pass the full "Options" object to
daemonize().
2009-01-18 18:29:30 +01:00
Max Kellermann bfcaecabbd daemon: added daemonize_init(), daemonize_finish()
The constructor/destructor functions parse and free the configuration
properly.  This way, we don't have to load the pid file path more than
once.
2009-01-18 18:29:27 +01:00
Max Kellermann 0dd2dfff9d main: moved the save_state timer to state_file.c
The state_file library should manage its own regular saves.
2009-01-18 18:10:15 +01:00
Max Kellermann 84de45afba state_file: added state_file_init() and state_file_finish()
The constructor/destructor interface should hide the functions
read_state_file() and write_state_file().
2009-01-18 18:09:50 +01:00
Max Kellermann 9c6b2a32f5 conf: added config_get_path()
config_get_path() is an simpler interface than parseConfigFilePath().
2009-01-18 17:54:46 +01:00
Max Kellermann a3f03f3ccd removed playerData.c
Fetch the configuration variables buffered_chunks and
buffered_before_play just when they are needed.
2009-01-18 17:32:43 +01:00
Max Kellermann 90b34f8e6f main: moved code to daemon.c
Moved changeToUser(), cleanUpPidFile(), killFromPidFile() to
daemon.c.  These are daemonization functions.
2009-01-18 17:15:34 +01:00
Max Kellermann 1f0dfb4407 mapper: make the music_directory optional
Without a music_directory, MPD is an excellent streaming client.
2009-01-18 16:56:07 +01:00
Max Kellermann c2cc3b4923 database: pass database file name to db_init()
Don't include conf.h in database.c.
2009-01-18 16:09:01 +01:00
Max Kellermann 004dfddca3 stats: use GTimer instead of time(NULL)
time(NULL) shows the wrong results when the machine's clock is
changed.
2009-01-18 15:40:53 +01:00
Max Kellermann 0d449d8df7 stats: no CamelCase
Renamed functions and types.
2009-01-18 15:22:26 +01:00
Max Kellermann 4d472c265e conf: no CamelCase, part I
Renamed functions, types, variables.
2009-01-17 20:23:27 +01:00
Max Kellermann 63d9827c34 main: remove "save_state" timer event on exit 2009-01-10 18:55:43 +01:00
Max Kellermann a673d6be98 main: deinitialize main_notify on exit 2009-01-10 18:55:28 +01:00
Max Kellermann 5e93d3682f added missing explicit config.h includes 2009-01-08 21:37:02 +01:00
Max Kellermann 0fb21e67ef configure.ac: use AC_CHECK_HEADERS to check for locale.h
AC_CHECK_HEADERS defines HAVE_LOCALE_H, so we don't have to manually
define HAVE_LOCALE.
2009-01-05 09:31:09 +01:00
Max Kellermann 200ef56d4d database: use stdbool
Make db_load(), db_save() and db_check() return bool instead of int.
2009-01-04 21:18:40 +01:00
Max Kellermann 82166b715c database: db_init() initializes library, does not update
For updating the database, directory_update_init() should be called
explicitly.
2009-01-04 21:18:16 +01:00
Max Kellermann e4a53df7db don't exit after --create-db
Start the daemon after --create-db.  This makes --create-db a flag
which discards the old database and starts with a fresh one.
2009-01-04 20:31:23 +01:00
Max Kellermann 48aace1859 event_pipe: moved variable "main_task" to main.c 2009-01-03 13:19:01 +01:00
Max Kellermann cf9bd42416 main: include main.h, fix dependencies 2009-01-02 11:21:33 +01:00
Max Kellermann 272ee5f7d2 event_pipe: replaced PIPE_EVENT_SIGNAL with main_notify
There is only one location using PIPE_EVENT_SIGNAL: to synchronize
player_command() with player_command_finished().  Use the "notify"
library instead of the event_pipe here.
2009-01-02 11:20:41 +01:00
Max Kellermann b3e2635ac1 event_pipe: added pipe_event enum and callbacks
Make the event_pipe (formerly main_notify) send/receive a set of
events, with a callback for each one.

The default event PIPE_EVENT_SIGNAL does not have a callback.  It
is still there for waking up the main thread, when it is waiting for
the player thread.
2009-01-01 18:22:11 +01:00
Max Kellermann 22bb5a5856 event_pipe: renamed functions from main_notify_* to event_pipe_*
Continuing the previous patch.
2009-01-01 18:12:14 +01:00
Max Kellermann 9f5934d95b main_notify: renamed source to event_pipe.c
We are going to migrate away from the concept of notifying the main
thread.  There should be events sent to it instead.  This patch starts
a series to implement that.
2009-01-01 18:12:00 +01:00
Viliam Mateicka 9a70c4d06d Moving mixers to audio outputs 2008-12-31 16:46:41 +01:00
Max Kellermann 3cd0b90ff6 client: run client_manager_expire() in an idle event
With the GLib main loop, the client manager can install its own event
in case a client is expired.  No need for main.c to call
client_manager_expire() manually.
2008-12-31 14:30:03 +01:00
Max Kellermann d40cf1652d main: export the main_loop variable
Other libraries may need to access the main_loop reference, to add or
remove events, or to call g_main_loop_quit().
2008-12-30 19:50:22 +01:00
Max Kellermann 71e7ce5d8e main: use the GLib main loop
This is a rather huge patch, which unfortunately cannot be splitted.

Instead of using our custom ioops.h library, convert everything to use
the GLib main loop.
2008-12-30 19:24:39 +01:00
Max Kellermann 6c0f5fc612 listen: moved redirect_stdin() to daemon.c
redirect_stdin() is a daemonization function, and disconnecting from
the standard input is always a good idea for MPD.
2008-12-30 16:28:13 +01:00
Max Kellermann 671480814c main: moved daemonize() to daemon.c 2008-12-30 16:28:07 +01:00
Max Kellermann d38a7967ab main: disable non-portable code on WIN32
Disable changeToUser(), daemonize(), killFromPidFile().
2008-12-29 17:43:00 +01:00
Max Kellermann 274b919966 main: use g_setenv() instead of setenv()
Removed the fallback setenv() implementation for solaris.
2008-12-29 17:37:40 +01:00
Max Kellermann 91be85a307 main: use GLib logging 2008-12-29 17:35:40 +01:00
Max Kellermann 95b3430f52 removed os_compat.h
Only include headers which are really needed.  os_compat.h aimed to
make MPD easily portable, but was never actually made portable.
2008-12-29 17:28:32 +01:00
Thomas Jansen 28128dc4e3 tag & tag_pool: migrate from pthread to glib threads 2008-12-28 22:09:42 +01:00
Thomas Jansen bfb5657d6d songvec: migrate from pthread to glib threads 2008-12-28 21:02:42 +01:00
Thomas Jansen 4ed895c799 dirvec: migrate from pthread to glib threads 2008-12-28 21:02:30 +01:00
Thomas Jansen 8332a70406 idle: migrate from pthread to glib threads 2008-12-28 21:02:14 +01:00
Max Kellermann d70c2e2285 log: merged initLog() and open_log_files().
The logging library currently has 3 constructor functions: initLog(),
open_log_files(), setup_log_output(), called in this order.  Merged
the first two.
2008-12-28 19:48:53 +01:00
Max Kellermann 786bb8cc33 moved command line parser to cmdline.c 2008-12-27 19:03:33 +01:00
Max Kellermann 0fe0425dee disable archive API without plugins
When there are no archive plugins, we do not need the archive API at
all.  Drop all its overhead.
2008-12-27 14:33:41 +01:00
Viliam Mateicka c73ebac4af new archive api, input_archive stream 2008-12-16 21:42:34 +01:00
Max Kellermann ced4abcd64 update: added update_global_init() and update_global_finish()
Those two functions are called when MPD starts and exits.  It allows
the update library to perform global initialization and
deinitialization.  The implementations are currently empty.
2008-11-27 19:34:54 +01:00
Max Kellermann d85184256e main: destroy the save_state timer on exit
Make valgrind happier.
2008-11-25 17:55:04 +01:00
Max Kellermann 1c0c583216 state_file: save state_file every 5 minutes
When MPD quits in a non-clean way, the state file isn't written, and
on the next start, MPD time warps to the previous clean shutdown.
Save the state file every 5 minutes; this will probably be
configurable at a later time.

Note that we don't set a wakeup timer for that: when there is no MPD
traffic, MPD won't wake up to save the state file.  This minor bug is
tolerated, because usually there is no change in MPD's state when the
main thread is idle.
2008-11-21 18:36:33 +01:00
Max Kellermann 114b3c1e78 replay_gain: no CamelCase
Renamed functions and variables.
2008-11-11 15:55:34 +01:00
Max Kellermann 54ad08ab37 replay_gain: renamed sources to replay_gain.c, replay_gain.h
No CamelCase file names.
2008-11-11 15:55:34 +01:00
Max Kellermann 7f880ab8ba main: print usage to stdout
Using the logging library here is inappropriate.
2008-11-05 20:52:14 +01:00
Max Kellermann 08aaf57ff0 log: removed warning buffer
The warning buffer is a complex piece of code for no good reason.
Remove it and find a better solution, e.g. open the log file earlier.
2008-11-05 18:37:40 +01:00
Max Kellermann b35ca9e5c4 main: initialize locale (LC_CTYPE)
Initialize libc's locale functions.  Currently, we are only interested
in LC_CTYPE (character classification), because this is what is used
by GLib's g_get_charset().
2008-11-05 18:37:39 +01:00
Max Kellermann 3002fd18cb path: no CamelCase
Rename variables and functions.
2008-11-05 18:21:52 +01:00
Max Kellermann 259c6ed164 enable GLib threading
Call g_thread_init() from main() to enable the GLib features which
make it thread safe.
2008-11-05 18:21:49 +01:00
Max Kellermann 06f9b6c379 main: don't close all file descriptors on startup
Removed closeAllFDs().  The caller is responsible for closing all file
handles.
2008-11-05 18:21:36 +01:00
Max Kellermann fd0f195bb7 music_pipe: renamed ob_* functions to music_pipe_*
Rename all functions to the new prefix.
2008-11-02 14:18:34 +01:00
Max Kellermann 767b4c95bd renamed outputBuffer.[ch] to pipe.[ch]
No CamelCase in the file name.  The output_buffer struct is going to
be renamed to music_pipe.  There are so many buffer levels in MPD, and
calling this one "output buffer" is wrong, because it's not the last
buffer before the music reaches the output devices.
2008-11-02 14:12:52 +01:00
Max Kellermann 016d996131 utils: use g_str_has_prefix() instead of prefixcmp()
Remove duplicated code from MPD.
2008-10-28 20:33:56 +01:00
Max Kellermann dbc7e9ba2f input_stream: no CamelCase
Renamed all functions and variables.
2008-10-26 20:34:47 +01:00
Max Kellermann bbaedb17d5 input_stream: renamed sources, no CamelCase
Renamed inputStream.c and inputStream_file.c.
2008-10-26 19:38:50 +01:00
Max Kellermann 6b09e4daef input_stream: added input_stream_global_finish()
The hook input_stream_global_finish() deinitializes global structures
of all input stream implementations.
2008-10-26 19:30:13 +01:00
Max Kellermann 51a6ee88f7 command: no CamelCase
Eliminate CamelCase in all public and static functions.
2008-10-22 21:40:44 +02:00
Max Kellermann 7366191f0d mapper: moved musicDir initialization from path.c
Moved the musicDir variable and its initialization code from path.c to
mapper.c.
2008-10-15 19:36:33 +02:00
Max Kellermann a3e3d2c950 command: added command "idle"
"idle" waits until something noteworthy happens on the server,
e.g. song change, playlist modified, database updated.  This allows
clients to keep up to date without polling.
2008-10-14 22:38:14 +02:00
Max Kellermann ba892cbcb0 changed package name to "mpd-mk", updated version number
This git branch has become a real MPD fork now.  Time to change the
package name to the code name "mpd-mk".  Set the version number to
"0.14~git" to mark this as a non-released version.
2008-10-14 17:21:27 +02:00
Max Kellermann 7dd099a60f update: don't export updateDirectory()
If the user requests database update during startup, call
directory_update_init().  This should be changed to fully asynchronous
update later.

For this to work, main_notify has to be initialized before db_init().
2008-10-09 19:11:54 +02:00
Max Kellermann bb8a9533b1 database: renamed functions, "db_" prefix and no CamelCase
Yet another CamelCase removal patch.
2008-10-08 11:07:55 +02:00
Max Kellermann 8a50e8a266 directory: moved code to database.c
Taming the directory.c monster, part II: move the database management
stuff to database.  directory.c should only contain code which works
on directory objects.
2008-10-08 11:07:35 +02:00
Max Kellermann 7b9bed8398 directory: moved code to update.c
The source directory.c mixes several libraries: directory object
management, database management and database update, resulting in a
1000+ line monster.  Move the whole database update code to update.c.
2008-10-08 10:48:48 +02:00
Eric Wong a0364d38d3 directory: remove "Mp3" references
MPD has supported more audio formats than just MP3
for over five years...
2008-09-29 13:17:42 +02:00
Max Kellermann a0272c2d61 notify: added notify_deinit()
Destroy the mutex when it is not used anymore.
2008-09-24 07:14:11 +02:00
Eric Wong 3f0ae13c4b directory: update do its work inside a thread
A lot of the preparation was needed (and done in previous
months) in making update thread-safe, but here it is.

This was the first thing I made work inside a thread when I
started mpd-uclinux many years ago, and also the last thing I've
done in mainline mpd to work inside a thread, go figure.
2008-09-23 22:37:18 +02:00
Eric Wong 27fad52c6b start using prefixcmp()
LOC reduction and less noise makes things easier for
tired old folks to follow.
2008-09-23 20:48:12 +02:00
Max Kellermann be046b25a4 output: static audio_output_plugin list as array
Instead of having to register each output plugin, store them
statically in an array.  This eliminates the need for the List library
here, and saves some small allocations during startup.
2008-09-08 11:43:13 +02:00
Max Kellermann 91502cd71e tag: renamed functions, no CamelCase 2008-08-29 09:38:21 +02:00
Max Kellermann c0197c58ba client: renamed all public functions
Functions which operate on the whole client list are prefixed with
"client_manager_", and functions which handle just one client just get
"client_".
2008-08-28 20:03:02 +02:00
Max Kellermann deb29e0884 renamed interface.c to client.c
I don't believe "interface" is a good name for something like
"connection by a client to MPD", let's call it "client".  This is the
first patch in the series which changes the name, beginning with the
file name.
2008-08-28 20:02:43 +02:00
Max Kellermann 1560a70b01 include cleanup
Only include headers which are really needed.
2008-08-28 20:01:08 +02:00
Max Kellermann e2c8b960de moved code to pc_init(), dc_init() 2008-08-26 08:45:14 +02:00
Max Kellermann 5e51fa020d renamed player.c to player_control.c
Give player.c a better name, meaning that the code is used to control
the player thread.
2008-08-26 08:44:38 +02:00
Max Kellermann a2b24462e8 renamed decoderInit() to decoder_thread_start() 2008-08-26 08:44:29 +02:00
Max Kellermann dff8c6450b renamed decode.c to decoder_thread.c
It should be obvious in which thread or context a function is being
executed at runtime.  The code which was left in decode.c is for the
decoder thread itself; give the file a better name.
2008-08-26 08:44:12 +02:00
Max Kellermann 4255bba0f7 moved global variable "pc" to player.h
This is the last of the three variables.  Now we don't need
playerData.h anymore in most sources.
2008-08-26 08:41:05 +02:00
Max Kellermann 1c03c721ea moved variable "dc" to decode.h
Now that "dc" is available here, we don't have to pass it to
decoder_is_idle() and decoder_is_starting() anymore.
2008-08-26 08:40:47 +02:00
Max Kellermann e8bd9ddc9f moved code to player_thread.c
Move code which runs in the player thread to player_thread.c.  Having
a lot of player thread code in decode.c isn't easy to understand.
2008-08-26 08:27:09 +02:00
Max Kellermann e754ed01a7 renamed functions in decoder_list.h
InputPlugin to decoder_plugin, and no camelCase.
2008-08-26 08:27:09 +02:00
Max Kellermann 41c5fbbb07 renamed inputPlugin.* to decoder_list.*
Since inputPlugin.c manages the list of registered decoders, we should
rename the source file.
2008-08-26 08:27:08 +02:00
Max Kellermann a383f45117 enable -Wpointer-arith, -Wstrict-prototypes
Also enable -Wunused-parameter - this forces us to add the gcc
"unused" attribute to a lot of parameters (mostly library callback
functions), but it's worth it during code refactorizations.
2008-08-26 08:27:02 +02:00
Eric Wong f57be50d73 remove audioDeviceStates from playerData and getPlayerData
git-svn-id: https://svn.musicpd.org/mpd/trunk@7372 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-06-02 10:10:26 +00:00
Eric Wong dec6b1612e Stop passing our single DecoderControl object everywhere
This at least makes the argument list to a lot of our plugin
functions shorter and removes a good amount of line nois^W^Wcode,
hopefully making things easier to read and follow.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7353 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-13 01:16:03 +00:00
Eric Wong 98acfa8ac5 Get rid of PlayerControl inside the PlayerData struct
It actually increases our image size a small bit and may even
hurt performance a very small bit, but makes the code less
verbose and easier to manage.

I don't see a reason for mpd to ever support playing multiple
files at the same time (users can run multiple instances of mpd
if they really want to play Zaireeka, but that's such an edge
case it's not worth ever supporting in our code).

git-svn-id: https://svn.musicpd.org/mpd/trunk@7352 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-13 01:15:50 +00:00
Eric Wong baf9b94ecf Fix the problem of songs not advancing without client activity
The select() in the main event loop blocks now (saving us many
unnecessary wakeups).  This interacted badly with the threads
that were trying to wakeup the main task via
pthread_cond_signal() since the main task was not blocked
on a condition variable, but on select().

So now if we detect a need to wakeup the player, we write
to a pipe which select() is watching instead of blindly
calling pthread_cond_signal().

git-svn-id: https://svn.musicpd.org/mpd/trunk@7347 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 09:46:11 +00:00
Max Kellermann 14529af732 pass dc to decoder_task()
git-svn-id: https://svn.musicpd.org/mpd/trunk@7323 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:19:50 +00:00
Max Kellermann 1465bfab82 pass pc to player_task()
Another global variable cleanup patch.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7321 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:19:38 +00:00
Max Kellermann 4ee8396f41 use the notify API in the main thread
git-svn-id: https://svn.musicpd.org/mpd/trunk@7283 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:14:45 +00:00
Eric Wong 9cf66d0e8a Initial cut of fork() => pthreads() for decoder and player
I initially started to do a heavy rewrite that changed the way processes
communicated, but that was too much to do at once.  So this change only
focuses on replacing the player and decode processes with threads and
using condition variables instead of polling in loops; so the changeset
itself is quiet small.

* The shared output buffer variables will still need locking
to guard against race conditions.  So in this effect, we're probably
just as buggy as before.  The reduced context-switching overhead of
using threads instead of processes may even make bugs show up more or
less often...

* Basic functionality appears to be working for playing local (and NFS)
audio, including:
play, pause, stop, seek, previous, next, and main playlist editing

* I haven't tested HTTP streams yet, they should work.

* I've only tested ALSA and Icecast.  ALSA works fine, Icecast
metadata seems to get screwy at times and breaks song
advancement in the playlist at times.

* state file loading works, too (after some last-minute hacks with
non-blocking wakeup functions)

* The non-blocking (*_nb) variants of the task management functions are
probably overused.  They're more lenient and easier to use because
much of our code is still based on our previous polling-based system.

* It currently segfaults on exit.  I haven't paid much attention
to the exit/signal-handling routines other than ensuring it
compiles.  At least the state file seems to work.  We don't
do any cleanups of the threads on exit, yet.

* Update is still done in a child process and not in a thread.
To do this in a thread, we'll need to ensure it does proper
locking and communication with the main thread; but should
require less memory in the end because we'll be updating
the database "in-place" rather than updating a copy and
then bulk-loading when done.

* We're more sensitive to bugs in 3rd party libraries now.
My plan is to eventually use a master process which forks()
and restarts the child when it dies:
locking and communication with the main thread; but should
require less memory in the end because we'll be updating
the database "in-place" rather than updating a copy and
then bulk-loading when done.

* We're more sensitive to bugs in 3rd party libraries now.
My plan is to eventually use a master process which forks()
and restarts the child when it dies:

master - just does waitpid() + fork() in a loop
\- main thread
\- decoder thread
\- player thread

At the beginning of every song, the main thread will set
a dirty flag and update the state file.  This way, if we
encounter a song that triggers a segfault killing the
main thread, the master will start the replacement main
on the next song.

* The main thread still wakes up every second on select()
to check for signals; which affects power management.

[merged r7138 from branches/ew]

git-svn-id: https://svn.musicpd.org/mpd/trunk@7240 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-04-12 04:08:00 +00:00
Max Kellermann c6ceceae8a moved handlePendingSignals() check into while() condition
For code unification: for me, it looks ugly to do a break in the
command in a while() block.  This belongs into the while condition.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7193 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:37:02 +00:00