Commit Graph

2218 Commits

Author SHA1 Message Date
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
9340e291f0 imported list.h from the Linux kernel sources
linux/list.h is a nice doubly linked list library - it is lightweight
and powerful at the same time.  It will be useful later, when we begin
to allocate client structures dynamically.  Import it, and strip out
all the stuff which we are not going to use.
2008-08-28 20:02:20 +02:00
Max Kellermann
bc1c8835c6 const pointers
The usual bunch of pointer arguments which should be const.
2008-08-28 20:02:17 +02:00
Max Kellermann
801c71ed1c unsigned integers and size_t
Use "unsigned int" whenever negative values are not meaningful.  Use
size_t whenever we are going to describe buffer sizes.
2008-08-28 20:02:16 +02:00
Max Kellermann
1560a70b01 include cleanup
Only include headers which are really needed.
2008-08-28 20:01:08 +02:00
Max Kellermann
b7861868cf protect locate.h from double inclusion 2008-08-28 20:01:08 +02:00
Max Kellermann
f34f694ec3 moved player_command_finished() to player_thread.c 2008-08-26 08:45:15 +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
b616dff77d no commandError() in playerSeek()
We should avoid having protocol specific code in player.c.  Just
return success or failure, and let the caller send the error code to
the MPD client.
2008-08-26 08:44:34 +02:00
Max Kellermann
bf4af19f54 don't initialize "i" if we overwrite it anyway 2008-08-26 08:44:33 +02:00
Max Kellermann
a2b24462e8 renamed decoderInit() to decoder_thread_start() 2008-08-26 08:44:29 +02:00
Max Kellermann
56cdce6946 renamed decode.h to decoder_control.h 2008-08-26 08:44:19 +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
a94845ee00 moved global variable "ob" to outputBuffer.h
This releases several include file dependencies.  As a side effect,
"CHUNK_SIZE" isn't defined by decoder_api.h anymore, so we have to
define it directly in the plugins which need it.  It just isn't worth
it to add it to the decoder plugin API.
2008-08-26 08:41:05 +02:00
Max Kellermann
15c9352bb6 moved enum decoder_command to decoder_api.h
The decoder plugins need this type, so export it in the public API.
This allows is to remove "decode.h" from "decoder_api.h", uncluttering
the API namespace some more.
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
9521c92f66 player_thread: removed decode(), renamed decodeParent()
decode() is a trivial wrapper for decodeParent().  Merge both and
rename them to do_play().
2008-08-26 08:29:37 +02:00
Max Kellermann
70904adf18 hide DecoderControl accesses in inline functions
Unfortunately, we have to pass the DecoderControl pointer to these
inline functions, because the global variable "dc" may not be
available here.  This will be fixed later.
2008-08-26 08:29:35 +02:00
Max Kellermann
a1ce999978 check for decoder error before state!=START
When dc->error!=NOERROR, we do not need to check state!=START.
Simplify the checks by moving the error check to the top.
2008-08-26 08:27:18 +02:00
Max Kellermann
c6035ea332 don't reset dc->command in quitDecode()
The decoder thread is responsible for resetting dc->command after a
command was executed.  As a consequence, we can assume that
dc->command is already NONE after decoder_stop().
2008-08-26 08:27:18 +02:00
Max Kellermann
8a4970f863 added decoder_control.c
The source "decoder_control.c" provides an API for controlling the
decoder.  This replaces various direct accesses to the DecoderControl
struct.
2008-08-26 08:27:18 +02:00
Max Kellermann
7d3429a6d8 removed the "queue" parameter from syncPlaylistWithQueue()
There is only one caller which passes "true", so we can move the
queueNextSongInPlaylist() invocation there.
2008-08-26 08:27:18 +02:00
Max Kellermann
a9f0d85115 merge the playlist lock functions into clearPlayerQueue()
There is no unlocked caller of clearPlayerQueue(), and the functions
lockPlaylistInteraction() and unlockPlaylistInteraction() are trivial
- merge them.
2008-08-26 08:27:17 +02:00
Max Kellermann
2a06e2dafa use switch/case in syncPlaylistWithQueue() 2008-08-26 08:27:17 +02:00
Max Kellermann
110cef6fda don't call playerStop() before playerPlay()
Since playerPlay() already calls playerStop(), we can remove its
invocation of playerStop() from playPlaylistOrderNumber().

We can also make playerStop a static function.
2008-08-26 08:27:17 +02:00
Max Kellermann
7125fdc4f2 assert locked/unlocked in queue lock functions
There are no nested queue locks in mpd, thus replace the locked checks
in playerQueueLock(), playerQueueUnlock() with assertions.
2008-08-26 08:27:17 +02:00
Max Kellermann
f168695699 don't unlock player queue in playerStop(), playerWait()
There is no caller of these two functions which locks the player
queue; replace the playerQueueUnlock() call with an assertion.
2008-08-26 08:27:17 +02:00
Max Kellermann
113c1c0af5 queueSong() cannot fail
All (indirect) callers of queueSong() ensure that the queue state is
BLANK, so there is no need to check it in queueSong() again.  As a
side effect, queueSong() cannot fail anymore, and can return void.
Also, playlist_queueError and all its error handling can go away.
2008-08-26 08:27:17 +02:00
Max Kellermann
b94af79134 fix a comment regarding the player queue 2008-08-26 08:27:17 +02:00
Max Kellermann
4613115bec document the PLAYER_QUEUE_ constants 2008-08-26 08:27:17 +02:00
Max Kellermann
55377fbd9f added enum player_queue_state 2008-08-26 08:27:16 +02:00
Max Kellermann
ae00330285 rewrote playerKill()
playerKill() was marked as deprecated, but it seems like a good idea
to do proper cleanup in all threads (e.g. for usable valgrind
results).  Introduce the command "EXIT" which makes the player thread
exit cleanly.
2008-08-26 08:27:16 +02:00
Max Kellermann
92d9797b8c player: don't call STOP before CLOSE_AUDIO
playerWait() stops the player thread (twice!) and closes the output
device.  It should be well enough to just send CLOSE_AUDIO, without
STOP.

This requires a tiny change to the player thread code: make it break
when CLOSE_AUDIO is sent.
2008-08-26 08:27:16 +02:00
Max Kellermann
cff923b9d8 playlist: eliminate unused fd parameters
Again, remove file descriptor parameters, which are not actually
used.  These functions can also be converted to return void.
2008-08-26 08:27:16 +02:00
Max Kellermann
3db333b5a4 player: no "fd" and no return value
Most player*() functions do not actually use the file descriptor, and
always return 0 (success).  Eliminate them to get a leaner interface.
2008-08-26 08:27:16 +02:00
Max Kellermann
6df980a996 flac: decoder command means EOF
It was possible for the decoder thread to go into an endless loop
(flac and oggflac decoders): when a "STOP" command arrived, the Read()
callback would return 0, but the EOF() callback returned false.  Fix:
when decoder_get_command()!=NONE, return EOF==true.
2008-08-26 08:27:16 +02:00
Max Kellermann
8a5109483d made "sample_size" static const
sample_size is a variable which is computed at compile time.  Declare
it "static const", so the compiler can optimize it away.
2008-08-26 08:27:16 +02:00
Max Kellermann
e056ff2b02 moved jack configuration to the JackData struct
Storing local configuration in global (static) variables is obviously
a bad idea.  Move all those variables into the JackData struct,
including the locks.
2008-08-26 08:27:16 +02:00
Max Kellermann
479d02da0e jack: removed unused macros 2008-08-26 08:27:15 +02:00
Max Kellermann
edd7e2f94e jack: don't set audioOutput->data=NULL
There is only one caller of freeJackData() left: jack_finishDriver().
This function is called by the mpd core, and is called exactly once
for every successful jack_initDriver().  We do not need to clear
audioOutput->data, since this variable is invalidated anyway.
2008-08-26 08:27:15 +02:00
Max Kellermann
806a9f02a1 jack: initialize JackData in jack_initDriver()
Over the lifetime of the jack AudioOutput object, we want a single
valid JackData object, so we can persistently store data there
(configuration etc.).  Allocate JackData in jack_initDriver().  After
that, we can safely remove all audioOutput->data==NULL checks (and
replace them with assertions).
2008-08-26 08:27:15 +02:00
Max Kellermann
83215bf9ce jack: added freeJackClient()
No need to destroy the JackData object when an error occurs, since
jack_finishDriver() already frees it.  Only deinitialize the jack
library, introduce freeJackClient() for that, and move code from
freeJackData().
2008-08-26 08:27:15 +02:00
Max Kellermann
dc989987ab jack: initialize jd->client after !jd check
Prepare the next patch: make the "!jd" check independent of the
jd->client initialization.  This way we can change the "jd"
initialization semantics later.
2008-08-26 08:27:15 +02:00
Max Kellermann
2383231123 jack: eliminate superfluous freeJackData() calls
connect_jack() invokes freeJackData() in every error handler, although
its caller also invokes this function after a failure.  We can save a
lot of lines in connect_jack() by removing these redundant
freeJackData() invocations.
2008-08-26 08:27:15 +02:00
Max Kellermann
f46de2c32f mp3, flac: check for seek command after decoder_read()
When we introduced decoder_read(), we added code which aborts the read
operation when a decoder command arrives.  Several plugins however did
not expect that when they were converted to decoder_read().  Add
proper checks to the mp3 and flac decoder plugins.
2008-08-26 08:27:15 +02:00
Max Kellermann
e530181e23 check decoder_command!=NONE instead of decoder_command==STOP
The code said "decoder_command==STOP" because that was a conversion
from the old "dc->stop" test.  As we can now check for all commands in
one test, we can simply rewrite that to decoder_command!=NONE.
2008-08-26 08:27:15 +02:00
Max Kellermann
4515ac5ecb mp3: converted the MUTEFRAME_ macros to an enum
Also introduce MUTEFRAME_NONE; previously, the code used "0".
2008-08-26 08:27:14 +02:00
Max Kellermann
95fff55d7e mp3: converted the DECODE_ constants to an enum 2008-08-26 08:27:14 +02:00