Commit Graph

2026 Commits

Author SHA1 Message Date
Max Kellermann
7774cd2774 client: moved code to client_defer_output()
Split the large function client_write_output() into two parts; this is
the first code moving patch.
2008-08-28 20:03:51 +02:00
Max Kellermann
4448b17e2e don't free client resources except in client_close()
All of the client's resources are freed in client_close().  It is
enough to set the "expired" flag, no need to duplicate lots of
destruction code again and again.
2008-08-28 20:03:49 +02:00
Max Kellermann
61443c13e6 client: allocate clients dynamically
Due to the large buffers in the client struct, the static client array
eats several megabytes of RAM with a maximum of only 10 clients.  Stop
this waste and allocate each client struct from the heap.
2008-08-28 20:03:48 +02:00
Max Kellermann
a091c148e6 client: added function client_by_fd()
The code becomes less complex and more readable when we move this
linear search into a separate mini function.
2008-08-28 20:03:06 +02:00
Max Kellermann
d15e1e09a2 client: return early in client_new()
This saves one level of indent.
2008-08-28 20:03:03 +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
6d18e00099 client: renamed internal functions and variables
Rename all static functions, variables and macros which have
"interface" in their name to something nicer prefixed with "client_".
2008-08-28 20:02:59 +02:00
Max Kellermann
fe03cb9549 client: renamed Interface to struct client
Second patch: rename the internal struct name.  We will eventually
export this type as an opaque forward-declared struct later, so we
can pass a struct pointer instead of a file descriptor, which would
save us an expensive linear lookup.
2008-08-28 20:02:58 +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
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