Commit Graph

98 Commits

Author SHA1 Message Date
Max Kellermann d213f9a3e5 player_thread: make the music_buffer instance global
Preparation for the next patch: since the output devices stay open
even when the player thread stops playing, we will need a persistent
music buffer.
2009-03-09 19:12:06 +01:00
Max Kellermann 94d1a87d04 music_chunk: added assertions on the audio format
In !NDEBUG, remember which audio_format is stored in every chunk and
every pipe.  Check the audio_format of every new data block appended
to the music_chunk, and the format of every new chunk appended to the
music_pipe.
2009-03-08 13:45:24 +01:00
Max Kellermann fc6d836a2d player_thread: moved code to player_check_decoder_startup() 2009-03-07 23:11:43 +01:00
Max Kellermann 01cf7feac7 pipe: added music_buffer, rewrite music_pipe
Turn the music_pipe into a simple music_chunk queue.  The music_chunk
allocation code is moved to music_buffer, and is now managed with a
linked list instead of a ring buffer.  Two separate music_pipe objects
are used by the decoder for the "current" and the "next" song, which
greatly simplifies the cross-fading code.
2009-03-06 00:42:03 +01:00
Max Kellermann c655f804a9 music_pipe: moved struct music_chunk to chunk.h 2009-03-03 22:23:25 +01:00
Max Kellermann b7bfa24f22 pcm_volume: return bool
Don't abort MPD when a sample format is not supported by pcm_volume().
2009-03-02 09:42:16 +01:00
Max Kellermann bcdf947afc player_thread: removed meaningless warning on output failure
The warning message "problems opening audio device while playing ..."
does not help at all, and should be removed.  At this point, the real
error message has already been logged by the output thread.
2009-02-26 22:21:35 +01:00
Max Kellermann 9d2f16d827 player_thread: don't drop audio buffers when not seekable
When a file is not seekable, MPD dropped the audio buffers before even
attempting to seek.  This caused noticable sound corruption.  Fix:
first attempt to seek, and only if that succeeds, call
audio_output_all_cancel().
2009-02-17 23:57:10 +01:00
Max Kellermann 900784bb4e decoder_api: moved enum decoder_command to decoder_command.h
Minimize header dependencies, again.
2009-02-15 18:33:31 +01:00
Max Kellermann 4493a96425 output_all: no CamelCase
Renamed functions and variables.
2009-02-10 18:51:51 +01:00
Max Kellermann a3a6eefcfe audio: moved code to output_all.c
Moved code which deals with all audio outputs at once into a separate
library.
2009-02-10 18:51:49 +01:00
Max Kellermann 2a388c2aa7 crossfade: don't use isCurrentAudioFormat()
The crossfading code shouldn't depend on the audio output code.  Pass
the current audio format to cross_fade_calc() and let it compare
directly, instead of using isCurrentAudioFormat().
2009-02-10 18:51:29 +01:00
Max Kellermann c2bbf876fb player: added some more assertions
Assertions on pc.command and pc.next_song.
2009-02-10 08:18:28 +01:00
Max Kellermann 799d1c9dc2 player_thread: reset pc.next_song only if queued
When we reset pc.next_song if there is no song queued, this might
cause a race condition: the next song to be played is cleared, while
pc.command was already set.  Clear the "next_song" only if there is a
song queued for the current do_play() invocation.
2009-02-10 08:18:01 +01:00
Max Kellermann 2274434e53 player_thread: reset pc.next_song
After a player command (successful or not), reset pc.next_song,
because the queue is supposed to be empty then.  Otherwise,
playlist.queued and pc.next_song may disagree, which triggers an
assertion failure.
2009-02-10 00:17:34 +01:00
Max Kellermann 4b7c28f98e player_thread: set player error when output device fails
When the output device fails to play a chunk, set pc.error to
PLAYER_ERROR_AUDIO.  This way, the playlist knows that it should not
queue the next song.
2009-02-02 18:22:41 +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 d628eb3e8b player_control: added player_control.thread
player_control.thread contains the handle of the player thread, or
NULL if the player thread isn't running.
2009-01-25 13:44:33 +01:00
Max Kellermann ac0e799965 decoder_control: added decoder_control.thread
decoder_control.thread contains the handle of the decoder thread, or
NULL if the decoder thread isn't running.
2009-01-25 13:44:27 +01:00
Max Kellermann 1d02318d21 player_thread: emit PLAYLIST event when new song fails
Break from the loop instead of returning the function.  This calls
player_stop_decoder(), which in turn emits the PLAYLIST event.  This
allows the playlist to re-start the player.
2009-01-21 16:44:32 +01:00
Max Kellermann a088d9f851 player_thread: check for decoder failure before seeking
The function player_seek_decoder() starts the decoder, but does not
check the return value of player_wait_for_decoder().
2009-01-21 16:36:30 +01:00
Max Kellermann 38a9ad011a player_thread: use bool instead of int
Make player_wait_for_decoder() and play_chunk() return a bool instead
of 0/-1.
2009-01-21 16:31:15 +01:00
Max Kellermann b14e48f930 player_thread: request next song only if new one starts playing
The player_thread loop requests the next song from the playlist as
soon as the decoder finishes the song which is currently being played.
This is superfluous, and can lead to synchronization errors and wrong
results.  The playlist already knows when the player starts playing
the next song (player_wait_for_decoder() triggers the PLAYLIST event),
and will then trigger the scheduler to provide the next song.
2009-01-21 16:17:57 +01:00
Max Kellermann 1379db379d player_thread: eliminated duplicate PLAYLIST event
player_wait_for_decoder() emits the PLAYLIST event on success, remove
the duplicate PLAYLIST event in its caller.
2009-01-20 23:11:01 +01:00
Max Kellermann 06bd9ad88f event_pipe: added "TAG" event
The "TAG" event is emitted by the player thread when the current
song's tag has changed.  Split this event from "PLAYLIST" and make it
a separate callback, which is more efficient.
2009-01-20 22:49:19 +01:00
Max Kellermann 9d0579996c pcm_utils: moved code to pcm_volume.c
Moved the software volume code to a separate library.
2009-01-07 18:05:38 +01:00
Max Kellermann 5e6ac50583 initialize GError pointers
GLib mandates that you initialize all GError objects with NULL prior
to passing it.
2009-01-04 19:51:54 +01:00
Max Kellermann fed719197c song: allocate the result of song_get_url() 2009-01-04 19:09:34 +01:00
Max Kellermann 55b6fd2f0c player_thread: fix cross-fading duplicate chunk bug
When the decoder of the new song is not fast enough, the player thread
has to wait for it for a moment.  However the variable "nextChunk" was
reset to -1 during that, making the next loop iteration assume that
cross-fading has not begun yet.  This patch overwrites it with "0"
while waiting.
2009-01-04 14:55:02 +01:00
Max Kellermann 6d2e4f4e72 player: emit PLAYLIST event when stream tag changes
Commit b3e2635a introduced a regression: when a stream tag was
changed, the playlist version had to be updated.  This was done in
syncCurrentPlayerDecodeMetadata(), called by syncPlayerAndPlaylist().
After b3e2635a, this was not called anymore.  Fix this by emitting
PIPE_EVENT_PLAYLIST.
2009-01-03 20:49:51 +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
Max Kellermann e9b96c6e56 player_thread: use GLib logging 2008-12-29 17:29:14 +01:00
Thomas Jansen 195cec505e player_thread: migrate from pthread to glib threads 2008-12-28 22:09:38 +01:00
Max Kellermann 8fe03b8bce decoder: terminate decoder thread before MPD cleanup
When MPD exits, it should manually free all resources in use, to allow
easy memory leak debugging.  Make the decoder thread terminate during
that.
2008-12-28 19:48:53 +01:00
Marc Pavot fd1144145c player: set elapsed=0 at song change
I have found something that looks like a bug in MPD:
- When a song is finished, the next one is played and the 'player'
  event is emitted.
- When the client sends the status command just after this event, the
  songid is the new one but the 'elapsed' time is not reseted to 0.

This is problem because I have implemented the solution using a timer
on client side to compute the elapsed time but with this bug the
elapsed time continues to be incremented on a new song.
2008-11-25 16:19:53 +01:00
Thomas Jansen b9fefc4564 player_thread.c: replaced mpd_unused by G_GNUC_UNUSED 2008-11-24 14:47:44 +01:00
Max Kellermann acbfba0698 player: disable music_pipe_check_format()
The music pipe audio format bugs seem to be fixed (hopefully).
Disable music_pipe_check_format() for now, since it consumes a lot of
CPU cycles.
2008-11-24 09:25:48 +01:00
Max Kellermann eb199ca207 player: don't queue song when there are 2 songs in the pipe
Don't send a "next song" request to the main thread when the current
song hasn't started playing yet, i.e. there are already two different
songs in the music pipe.  This would erase information about the song
boundary within the music pipe, and thus triggered an assertion
failure.  The bug could occur when playing very short songs which fit
into the pipe as a whole.
2008-11-14 17:55:51 +01:00
Max Kellermann 418dac6f94 player: wake up decoder before waiting for xfade chunks
Fix a deadlock: when the decoder waited for buffer space, the player
could enter a deadlock situation because it waits for more chunks for
crossfading chunks.  Signal the decoder before entering notify_wait().
2008-11-14 17:55:45 +01:00
Max Kellermann 709640422c player: chop the tail of the music pipe after CANCEL
When a CANCEL command is received, the player should drop all chunks
of the next song.  Added new funciton music_pipe_chop() which is used
for that.
2008-11-13 02:09:33 +01:00
Max Kellermann 66ce1495f0 music_pipe: continuously check the sample format of all chunks
Provide a debug function which asserts on the sample format of all
chunks.  Call this function in each iteration of the player main loop.
2008-11-13 02:06:58 +01:00
Max Kellermann df09075afc player: assert that there was no previous "next song chunk"
When assigning the next_song_chunk variable, it must have been empty.
If not, there may be 3 songs overlapping in the music pipe.
2008-11-13 01:57:15 +01:00
Max Kellermann 1bfa6a94e2 player: fix race condition during tag update
When a tag is updated, the old tag was freed before the new one was
created.  Reverse the order to be sure that other threads always see a
valid pointer.

This still leaves a possible race condition, but it will be addressed
later.
2008-11-11 20:46:55 +01:00
Max Kellermann 72eba30cf4 decoder: converted dc.error to a dc.state value
The player did not care about the exact error value, it only checked
whether an error has occured.  This could fit well into
decoder_control.state - introduce a new state "DECODE_STATE_ERROR".
2008-11-08 15:48:00 +01:00
Max Kellermann 862bbc21a1 player: no CamelCase
Renamed variables and internal functions.  Most of the
player_control.h API remains in CamelCase for now.
2008-11-03 21:49:29 +01:00
Max Kellermann 863badd91e decoder: no CamelCase
Renamed variables and functions.
2008-11-03 21:43:02 +01:00
Max Kellermann cc164cc884 player: don't play empty chunks
An empty chunk may happen when it only contains a tag, but no PCM
data.  Don't call playAudio() then.
2008-11-02 20:14:55 +01:00