Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
079ef931
Commit
079ef931
authored
Sep 26, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PlayerThread: use player references
parent
b2789c59
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
116 deletions
+115
-116
PlayerThread.cxx
src/PlayerThread.cxx
+115
-116
No files found.
src/PlayerThread.cxx
View file @
079ef931
...
@@ -167,12 +167,12 @@ player_command_finished(player_control &pc)
...
@@ -167,12 +167,12 @@ player_command_finished(player_control &pc)
* Player lock is not held.
* Player lock is not held.
*/
*/
static
void
static
void
player_dc_start
(
struct
player
*
player
,
MusicPipe
&
pipe
)
player_dc_start
(
player
&
player
,
MusicPipe
&
pipe
)
{
{
player_control
&
pc
=
player
->
pc
;
player_control
&
pc
=
player
.
pc
;
decoder_control
&
dc
=
player
->
dc
;
decoder_control
&
dc
=
player
.
dc
;
assert
(
player
->
queued
||
pc
.
command
==
PLAYER_COMMAND_SEEK
);
assert
(
player
.
queued
||
pc
.
command
==
PLAYER_COMMAND_SEEK
);
assert
(
pc
.
next_song
!=
NULL
);
assert
(
pc
.
next_song
!=
NULL
);
unsigned
start_ms
=
pc
.
next_song
->
start_ms
;
unsigned
start_ms
=
pc
.
next_song
->
start_ms
;
...
@@ -181,7 +181,7 @@ player_dc_start(struct player *player, MusicPipe &pipe)
...
@@ -181,7 +181,7 @@ player_dc_start(struct player *player, MusicPipe &pipe)
dc
.
Start
(
pc
.
next_song
->
DupDetached
(),
dc
.
Start
(
pc
.
next_song
->
DupDetached
(),
start_ms
,
pc
.
next_song
->
end_ms
,
start_ms
,
pc
.
next_song
->
end_ms
,
player
->
buffer
,
pipe
);
player
.
buffer
,
pipe
);
}
}
/**
/**
...
@@ -191,12 +191,11 @@ player_dc_start(struct player *player, MusicPipe &pipe)
...
@@ -191,12 +191,11 @@ player_dc_start(struct player *player, MusicPipe &pipe)
* finished.
* finished.
*/
*/
static
bool
static
bool
player_dc_at_current_song
(
const
struct
player
*
player
)
player_dc_at_current_song
(
const
player
&
player
)
{
{
assert
(
player
!=
NULL
);
assert
(
player
.
pipe
!=
NULL
);
assert
(
player
->
pipe
!=
NULL
);
return
player
->
dc
.
pipe
==
player
->
pipe
;
return
player
.
dc
.
pipe
==
player
.
pipe
;
}
}
/**
/**
...
@@ -205,9 +204,9 @@ player_dc_at_current_song(const struct player *player)
...
@@ -205,9 +204,9 @@ player_dc_at_current_song(const struct player *player)
* switched to that song yet.
* switched to that song yet.
*/
*/
static
bool
static
bool
player_dc_at_next_song
(
const
struct
player
*
player
)
player_dc_at_next_song
(
const
player
&
player
)
{
{
return
player
->
dc
.
pipe
!=
NULL
&&
!
player_dc_at_current_song
(
player
);
return
player
.
dc
.
pipe
!=
NULL
&&
!
player_dc_at_current_song
(
player
);
}
}
/**
/**
...
@@ -216,18 +215,18 @@ player_dc_at_next_song(const struct player *player)
...
@@ -216,18 +215,18 @@ player_dc_at_next_song(const struct player *player)
* Player lock is not held.
* Player lock is not held.
*/
*/
static
void
static
void
player_dc_stop
(
struct
player
*
player
)
player_dc_stop
(
player
&
player
)
{
{
decoder_control
&
dc
=
player
->
dc
;
decoder_control
&
dc
=
player
.
dc
;
dc
.
Stop
();
dc
.
Stop
();
if
(
dc
.
pipe
!=
NULL
)
{
if
(
dc
.
pipe
!=
NULL
)
{
/* clear and free the decoder pipe */
/* clear and free the decoder pipe */
dc
.
pipe
->
Clear
(
player
->
buffer
);
dc
.
pipe
->
Clear
(
player
.
buffer
);
if
(
dc
.
pipe
!=
player
->
pipe
)
if
(
dc
.
pipe
!=
player
.
pipe
)
delete
dc
.
pipe
;
delete
dc
.
pipe
;
dc
.
pipe
=
NULL
;
dc
.
pipe
=
NULL
;
...
@@ -242,15 +241,15 @@ player_dc_stop(struct player *player)
...
@@ -242,15 +241,15 @@ player_dc_stop(struct player *player)
* The player lock is not held.
* The player lock is not held.
*/
*/
static
bool
static
bool
player_wait_for_decoder
(
struct
player
*
player
)
player_wait_for_decoder
(
player
&
player
)
{
{
player_control
&
pc
=
player
->
pc
;
player_control
&
pc
=
player
.
pc
;
decoder_control
&
dc
=
player
->
dc
;
decoder_control
&
dc
=
player
.
dc
;
assert
(
player
->
queued
||
pc
.
command
==
PLAYER_COMMAND_SEEK
);
assert
(
player
.
queued
||
pc
.
command
==
PLAYER_COMMAND_SEEK
);
assert
(
pc
.
next_song
!=
NULL
);
assert
(
pc
.
next_song
!=
NULL
);
player
->
queued
=
false
;
player
.
queued
=
false
;
Error
error
=
dc
.
LockGetError
();
Error
error
=
dc
.
LockGetError
();
if
(
error
.
IsDefined
())
{
if
(
error
.
IsDefined
())
{
...
@@ -265,15 +264,15 @@ player_wait_for_decoder(struct player *player)
...
@@ -265,15 +264,15 @@ player_wait_for_decoder(struct player *player)
return
false
;
return
false
;
}
}
if
(
player
->
song
!=
NULL
)
if
(
player
.
song
!=
NULL
)
player
->
song
->
Free
();
player
.
song
->
Free
();
player
->
song
=
pc
.
next_song
;
player
.
song
=
pc
.
next_song
;
player
->
elapsed_time
=
0.0
;
player
.
elapsed_time
=
0.0
;
/* set the "starting" flag, which will be cleared by
/* set the "starting" flag, which will be cleared by
player_check_decoder_startup() */
player_check_decoder_startup() */
player
->
decoder_starting
=
true
;
player
.
decoder_starting
=
true
;
pc
.
Lock
();
pc
.
Lock
();
...
@@ -320,19 +319,19 @@ real_song_duration(const Song *song, double decoder_duration)
...
@@ -320,19 +319,19 @@ real_song_duration(const Song *song, double decoder_duration)
* @return true on success
* @return true on success
*/
*/
static
bool
static
bool
player_open_output
(
struct
player
*
player
)
player_open_output
(
player
&
player
)
{
{
player_control
&
pc
=
player
->
pc
;
player_control
&
pc
=
player
.
pc
;
assert
(
player
->
play_audio_format
.
IsDefined
());
assert
(
player
.
play_audio_format
.
IsDefined
());
assert
(
pc
.
state
==
PLAYER_STATE_PLAY
||
assert
(
pc
.
state
==
PLAYER_STATE_PLAY
||
pc
.
state
==
PLAYER_STATE_PAUSE
);
pc
.
state
==
PLAYER_STATE_PAUSE
);
Error
error
;
Error
error
;
if
(
audio_output_all_open
(
player
->
play_audio_format
,
player
->
buffer
,
if
(
audio_output_all_open
(
player
.
play_audio_format
,
player
.
buffer
,
error
))
{
error
))
{
player
->
output_open
=
true
;
player
.
output_open
=
true
;
player
->
paused
=
false
;
player
.
paused
=
false
;
pc
.
Lock
();
pc
.
Lock
();
pc
.
state
=
PLAYER_STATE_PLAY
;
pc
.
state
=
PLAYER_STATE_PLAY
;
...
@@ -344,11 +343,11 @@ player_open_output(struct player *player)
...
@@ -344,11 +343,11 @@ player_open_output(struct player *player)
}
else
{
}
else
{
g_warning
(
"%s"
,
error
.
GetMessage
());
g_warning
(
"%s"
,
error
.
GetMessage
());
player
->
output_open
=
false
;
player
.
output_open
=
false
;
/* pause: the user may resume playback as soon as an
/* pause: the user may resume playback as soon as an
audio output becomes available */
audio output becomes available */
player
->
paused
=
true
;
player
.
paused
=
true
;
pc
.
Lock
();
pc
.
Lock
();
pc
.
SetError
(
PLAYER_ERROR_OUTPUT
,
std
::
move
(
error
));
pc
.
SetError
(
PLAYER_ERROR_OUTPUT
,
std
::
move
(
error
));
...
@@ -369,12 +368,12 @@ player_open_output(struct player *player)
...
@@ -369,12 +368,12 @@ player_open_output(struct player *player)
* The player lock is not held.
* The player lock is not held.
*/
*/
static
bool
static
bool
player_check_decoder_startup
(
struct
player
*
player
)
player_check_decoder_startup
(
player
&
player
)
{
{
player_control
&
pc
=
player
->
pc
;
player_control
&
pc
=
player
.
pc
;
decoder_control
&
dc
=
player
->
dc
;
decoder_control
&
dc
=
player
.
dc
;
assert
(
player
->
decoder_starting
);
assert
(
player
.
decoder_starting
);
dc
.
Lock
();
dc
.
Lock
();
...
@@ -393,7 +392,7 @@ player_check_decoder_startup(struct player *player)
...
@@ -393,7 +392,7 @@ player_check_decoder_startup(struct player *player)
dc
.
Unlock
();
dc
.
Unlock
();
if
(
player
->
output_open
&&
if
(
player
.
output_open
&&
!
audio_output_all_wait
(
&
pc
,
1
))
!
audio_output_all_wait
(
&
pc
,
1
))
/* the output devices havn't finished playing
/* the output devices havn't finished playing
all chunks yet - wait for that */
all chunks yet - wait for that */
...
@@ -406,10 +405,10 @@ player_check_decoder_startup(struct player *player)
...
@@ -406,10 +405,10 @@ player_check_decoder_startup(struct player *player)
idle_add
(
IDLE_PLAYER
);
idle_add
(
IDLE_PLAYER
);
player
->
play_audio_format
=
dc
.
out_audio_format
;
player
.
play_audio_format
=
dc
.
out_audio_format
;
player
->
decoder_starting
=
false
;
player
.
decoder_starting
=
false
;
if
(
!
player
->
paused
&&
!
player_open_output
(
player
))
{
if
(
!
player
.
paused
&&
!
player_open_output
(
player
))
{
char
*
uri
=
dc
.
song
->
GetURI
();
char
*
uri
=
dc
.
song
->
GetURI
();
g_warning
(
"problems opening audio device "
g_warning
(
"problems opening audio device "
"while playing
\"
%s
\"
"
,
uri
);
"while playing
\"
%s
\"
"
,
uri
);
...
@@ -437,22 +436,22 @@ player_check_decoder_startup(struct player *player)
...
@@ -437,22 +436,22 @@ player_check_decoder_startup(struct player *player)
* The player lock is not held.
* The player lock is not held.
*/
*/
static
bool
static
bool
player_send_silence
(
struct
player
*
player
)
player_send_silence
(
player
&
player
)
{
{
assert
(
player
->
output_open
);
assert
(
player
.
output_open
);
assert
(
player
->
play_audio_format
.
IsDefined
());
assert
(
player
.
play_audio_format
.
IsDefined
());
struct
music_chunk
*
chunk
=
player
->
buffer
.
Allocate
();
struct
music_chunk
*
chunk
=
player
.
buffer
.
Allocate
();
if
(
chunk
==
NULL
)
{
if
(
chunk
==
NULL
)
{
g_warning
(
"Failed to allocate silence buffer"
);
g_warning
(
"Failed to allocate silence buffer"
);
return
false
;
return
false
;
}
}
#ifndef NDEBUG
#ifndef NDEBUG
chunk
->
audio_format
=
player
->
play_audio_format
;
chunk
->
audio_format
=
player
.
play_audio_format
;
#endif
#endif
const
size_t
frame_size
=
player
->
play_audio_format
.
GetFrameSize
();
const
size_t
frame_size
=
player
.
play_audio_format
.
GetFrameSize
();
/* this formula ensures that we don't send
/* this formula ensures that we don't send
partial frames */
partial frames */
unsigned
num_frames
=
sizeof
(
chunk
->
data
)
/
frame_size
;
unsigned
num_frames
=
sizeof
(
chunk
->
data
)
/
frame_size
;
...
@@ -464,7 +463,7 @@ player_send_silence(struct player *player)
...
@@ -464,7 +463,7 @@ player_send_silence(struct player *player)
Error
error
;
Error
error
;
if
(
!
audio_output_all_play
(
chunk
,
error
))
{
if
(
!
audio_output_all_play
(
chunk
,
error
))
{
g_warning
(
"%s"
,
error
.
GetMessage
());
g_warning
(
"%s"
,
error
.
GetMessage
());
player
->
buffer
.
Return
(
chunk
);
player
.
buffer
.
Return
(
chunk
);
return
false
;
return
false
;
}
}
...
@@ -476,11 +475,11 @@ player_send_silence(struct player *player)
...
@@ -476,11 +475,11 @@ player_send_silence(struct player *player)
*
*
* The player lock is not held.
* The player lock is not held.
*/
*/
static
bool
player_seek_decoder
(
struct
player
*
player
)
static
bool
player_seek_decoder
(
player
&
player
)
{
{
player_control
&
pc
=
player
->
pc
;
player_control
&
pc
=
player
.
pc
;
Song
*
song
=
pc
.
next_song
;
Song
*
song
=
pc
.
next_song
;
decoder_control
&
dc
=
player
->
dc
;
decoder_control
&
dc
=
player
.
dc
;
assert
(
pc
.
next_song
!=
NULL
);
assert
(
pc
.
next_song
!=
NULL
);
...
@@ -494,10 +493,10 @@ static bool player_seek_decoder(struct player *player)
...
@@ -494,10 +493,10 @@ static bool player_seek_decoder(struct player *player)
/* clear music chunks which might still reside in the
/* clear music chunks which might still reside in the
pipe */
pipe */
player
->
pipe
->
Clear
(
player
->
buffer
);
player
.
pipe
->
Clear
(
player
.
buffer
);
/* re-start the decoder */
/* re-start the decoder */
player_dc_start
(
player
,
*
player
->
pipe
);
player_dc_start
(
player
,
*
player
.
pipe
);
if
(
!
player_wait_for_decoder
(
player
))
{
if
(
!
player_wait_for_decoder
(
player
))
{
/* decoder failure */
/* decoder failure */
player_command_finished
(
pc
);
player_command_finished
(
pc
);
...
@@ -507,19 +506,19 @@ static bool player_seek_decoder(struct player *player)
...
@@ -507,19 +506,19 @@ static bool player_seek_decoder(struct player *player)
if
(
!
player_dc_at_current_song
(
player
))
{
if
(
!
player_dc_at_current_song
(
player
))
{
/* the decoder is already decoding the "next" song,
/* the decoder is already decoding the "next" song,
but it is the same song file; exchange the pipe */
but it is the same song file; exchange the pipe */
player
->
pipe
->
Clear
(
player
->
buffer
);
player
.
pipe
->
Clear
(
player
.
buffer
);
delete
player
->
pipe
;
delete
player
.
pipe
;
player
->
pipe
=
dc
.
pipe
;
player
.
pipe
=
dc
.
pipe
;
}
}
pc
.
next_song
->
Free
();
pc
.
next_song
->
Free
();
pc
.
next_song
=
NULL
;
pc
.
next_song
=
NULL
;
player
->
queued
=
false
;
player
.
queued
=
false
;
}
}
/* wait for the decoder to complete initialization */
/* wait for the decoder to complete initialization */
while
(
player
->
decoder_starting
)
{
while
(
player
.
decoder_starting
)
{
if
(
!
player_check_decoder_startup
(
player
))
{
if
(
!
player_check_decoder_startup
(
player
))
{
/* decoder failure */
/* decoder failure */
player_command_finished
(
pc
);
player_command_finished
(
pc
);
...
@@ -541,14 +540,14 @@ static bool player_seek_decoder(struct player *player)
...
@@ -541,14 +540,14 @@ static bool player_seek_decoder(struct player *player)
return
false
;
return
false
;
}
}
player
->
elapsed_time
=
where
;
player
.
elapsed_time
=
where
;
player_command_finished
(
pc
);
player_command_finished
(
pc
);
player
->
xfade
=
XFADE_UNKNOWN
;
player
.
xfade
=
XFADE_UNKNOWN
;
/* re-fill the buffer after seeking */
/* re-fill the buffer after seeking */
player
->
buffering
=
true
;
player
.
buffering
=
true
;
audio_output_all_cancel
();
audio_output_all_cancel
();
...
@@ -558,10 +557,10 @@ static bool player_seek_decoder(struct player *player)
...
@@ -558,10 +557,10 @@ static bool player_seek_decoder(struct player *player)
/**
/**
* Player lock must be held before calling.
* Player lock must be held before calling.
*/
*/
static
void
player_process_command
(
struct
player
*
player
)
static
void
player_process_command
(
player
&
player
)
{
{
player_control
&
pc
=
player
->
pc
;
player_control
&
pc
=
player
.
pc
;
gcc_unused
decoder_control
&
dc
=
player
->
dc
;
gcc_unused
decoder_control
&
dc
=
player
.
dc
;
switch
(
pc
.
command
)
{
switch
(
pc
.
command
)
{
case
PLAYER_COMMAND_NONE
:
case
PLAYER_COMMAND_NONE
:
...
@@ -579,23 +578,23 @@ static void player_process_command(struct player *player)
...
@@ -579,23 +578,23 @@ static void player_process_command(struct player *player)
case
PLAYER_COMMAND_QUEUE
:
case
PLAYER_COMMAND_QUEUE
:
assert
(
pc
.
next_song
!=
NULL
);
assert
(
pc
.
next_song
!=
NULL
);
assert
(
!
player
->
queued
);
assert
(
!
player
.
queued
);
assert
(
!
player_dc_at_next_song
(
player
));
assert
(
!
player_dc_at_next_song
(
player
));
player
->
queued
=
true
;
player
.
queued
=
true
;
player_command_finished_locked
(
pc
);
player_command_finished_locked
(
pc
);
break
;
break
;
case
PLAYER_COMMAND_PAUSE
:
case
PLAYER_COMMAND_PAUSE
:
pc
.
Unlock
();
pc
.
Unlock
();
player
->
paused
=
!
player
->
paused
;
player
.
paused
=
!
player
.
paused
;
if
(
player
->
paused
)
{
if
(
player
.
paused
)
{
audio_output_all_pause
();
audio_output_all_pause
();
pc
.
Lock
();
pc
.
Lock
();
pc
.
state
=
PLAYER_STATE_PAUSE
;
pc
.
state
=
PLAYER_STATE_PAUSE
;
}
else
if
(
!
player
->
play_audio_format
.
IsDefined
())
{
}
else
if
(
!
player
.
play_audio_format
.
IsDefined
())
{
/* the decoder hasn't provided an audio format
/* the decoder hasn't provided an audio format
yet - don't open the audio device yet */
yet - don't open the audio device yet */
pc
.
Lock
();
pc
.
Lock
();
...
@@ -635,12 +634,12 @@ static void player_process_command(struct player *player)
...
@@ -635,12 +634,12 @@ static void player_process_command(struct player *player)
pc
.
next_song
->
Free
();
pc
.
next_song
->
Free
();
pc
.
next_song
=
NULL
;
pc
.
next_song
=
NULL
;
player
->
queued
=
false
;
player
.
queued
=
false
;
player_command_finished_locked
(
pc
);
player_command_finished_locked
(
pc
);
break
;
break
;
case
PLAYER_COMMAND_REFRESH
:
case
PLAYER_COMMAND_REFRESH
:
if
(
player
->
output_open
&&
!
player
->
paused
)
{
if
(
player
.
output_open
&&
!
player
.
paused
)
{
pc
.
Unlock
();
pc
.
Unlock
();
audio_output_all_check
();
audio_output_all_check
();
pc
.
Lock
();
pc
.
Lock
();
...
@@ -648,7 +647,7 @@ static void player_process_command(struct player *player)
...
@@ -648,7 +647,7 @@ static void player_process_command(struct player *player)
pc
.
elapsed_time
=
audio_output_all_get_elapsed_time
();
pc
.
elapsed_time
=
audio_output_all_get_elapsed_time
();
if
(
pc
.
elapsed_time
<
0.0
)
if
(
pc
.
elapsed_time
<
0.0
)
pc
.
elapsed_time
=
player
->
elapsed_time
;
pc
.
elapsed_time
=
player
.
elapsed_time
;
player_command_finished_locked
(
pc
);
player_command_finished_locked
(
pc
);
break
;
break
;
...
@@ -722,10 +721,10 @@ play_chunk(player_control &pc,
...
@@ -722,10 +721,10 @@ play_chunk(player_control &pc,
* @return true on success, false on error (playback will be stopped)
* @return true on success, false on error (playback will be stopped)
*/
*/
static
bool
static
bool
play_next_chunk
(
struct
player
*
player
)
play_next_chunk
(
player
&
player
)
{
{
player_control
&
pc
=
player
->
pc
;
player_control
&
pc
=
player
.
pc
;
decoder_control
&
dc
=
player
->
dc
;
decoder_control
&
dc
=
player
.
dc
;
if
(
!
audio_output_all_wait
(
&
pc
,
64
))
if
(
!
audio_output_all_wait
(
&
pc
,
64
))
/* the output pipe is still large enough, don't send
/* the output pipe is still large enough, don't send
...
@@ -734,38 +733,38 @@ play_next_chunk(struct player *player)
...
@@ -734,38 +733,38 @@ play_next_chunk(struct player *player)
unsigned
cross_fade_position
;
unsigned
cross_fade_position
;
struct
music_chunk
*
chunk
=
NULL
;
struct
music_chunk
*
chunk
=
NULL
;
if
(
player
->
xfade
==
XFADE_ENABLED
&&
if
(
player
.
xfade
==
XFADE_ENABLED
&&
player_dc_at_next_song
(
player
)
&&
player_dc_at_next_song
(
player
)
&&
(
cross_fade_position
=
player
->
pipe
->
GetSize
())
(
cross_fade_position
=
player
.
pipe
->
GetSize
())
<=
player
->
cross_fade_chunks
)
{
<=
player
.
cross_fade_chunks
)
{
/* perform cross fade */
/* perform cross fade */
music_chunk
*
other_chunk
=
dc
.
pipe
->
Shift
();
music_chunk
*
other_chunk
=
dc
.
pipe
->
Shift
();
if
(
!
player
->
cross_fading
)
{
if
(
!
player
.
cross_fading
)
{
/* beginning of the cross fade - adjust
/* beginning of the cross fade - adjust
crossFadeChunks which might be bigger than
crossFadeChunks which might be bigger than
the remaining number of chunks in the old
the remaining number of chunks in the old
song */
song */
player
->
cross_fade_chunks
=
cross_fade_position
;
player
.
cross_fade_chunks
=
cross_fade_position
;
player
->
cross_fading
=
true
;
player
.
cross_fading
=
true
;
}
}
if
(
other_chunk
!=
NULL
)
{
if
(
other_chunk
!=
NULL
)
{
chunk
=
player
->
pipe
->
Shift
();
chunk
=
player
.
pipe
->
Shift
();
assert
(
chunk
!=
NULL
);
assert
(
chunk
!=
NULL
);
assert
(
chunk
->
other
==
NULL
);
assert
(
chunk
->
other
==
NULL
);
/* don't send the tags of the new song (which
/* don't send the tags of the new song (which
is being faded in) yet; postpone it until
is being faded in) yet; postpone it until
the current song is faded out */
the current song is faded out */
player
->
cross_fade_tag
=
player
.
cross_fade_tag
=
Tag
::
MergeReplace
(
player
->
cross_fade_tag
,
Tag
::
MergeReplace
(
player
.
cross_fade_tag
,
other_chunk
->
tag
);
other_chunk
->
tag
);
other_chunk
->
tag
=
NULL
;
other_chunk
->
tag
=
NULL
;
if
(
std
::
isnan
(
pc
.
mixramp_delay_seconds
))
{
if
(
std
::
isnan
(
pc
.
mixramp_delay_seconds
))
{
chunk
->
mix_ratio
=
((
float
)
cross_fade_position
)
chunk
->
mix_ratio
=
((
float
)
cross_fade_position
)
/
player
->
cross_fade_chunks
;
/
player
.
cross_fade_chunks
;
}
else
{
}
else
{
chunk
->
mix_ratio
=
nan
(
""
);
chunk
->
mix_ratio
=
nan
(
""
);
}
}
...
@@ -778,7 +777,7 @@ play_next_chunk(struct player *player)
...
@@ -778,7 +777,7 @@ play_next_chunk(struct player *player)
beginning of the new song, we can
beginning of the new song, we can
easily recover by throwing it away
easily recover by throwing it away
now */
now */
player
->
buffer
.
Return
(
other_chunk
);
player
.
buffer
.
Return
(
other_chunk
);
other_chunk
=
NULL
;
other_chunk
=
NULL
;
}
}
...
@@ -793,7 +792,7 @@ play_next_chunk(struct player *player)
...
@@ -793,7 +792,7 @@ play_next_chunk(struct player *player)
cross fading */
cross fading */
dc
.
Unlock
();
dc
.
Unlock
();
player
->
xfade
=
XFADE_DISABLED
;
player
.
xfade
=
XFADE_DISABLED
;
}
else
{
}
else
{
/* wait for the decoder */
/* wait for the decoder */
dc
.
Signal
();
dc
.
Signal
();
...
@@ -806,26 +805,26 @@ play_next_chunk(struct player *player)
...
@@ -806,26 +805,26 @@ play_next_chunk(struct player *player)
}
}
if
(
chunk
==
NULL
)
if
(
chunk
==
NULL
)
chunk
=
player
->
pipe
->
Shift
();
chunk
=
player
.
pipe
->
Shift
();
assert
(
chunk
!=
NULL
);
assert
(
chunk
!=
NULL
);
/* insert the postponed tag if cross-fading is finished */
/* insert the postponed tag if cross-fading is finished */
if
(
player
->
xfade
!=
XFADE_ENABLED
&&
player
->
cross_fade_tag
!=
NULL
)
{
if
(
player
.
xfade
!=
XFADE_ENABLED
&&
player
.
cross_fade_tag
!=
NULL
)
{
chunk
->
tag
=
Tag
::
MergeReplace
(
chunk
->
tag
,
chunk
->
tag
=
Tag
::
MergeReplace
(
chunk
->
tag
,
player
->
cross_fade_tag
);
player
.
cross_fade_tag
);
player
->
cross_fade_tag
=
NULL
;
player
.
cross_fade_tag
=
NULL
;
}
}
/* play the current chunk */
/* play the current chunk */
Error
error
;
Error
error
;
if
(
!
play_chunk
(
player
->
pc
,
player
->
song
,
chunk
,
player
->
buffer
,
if
(
!
play_chunk
(
player
.
pc
,
player
.
song
,
chunk
,
player
.
buffer
,
player
->
play_audio_format
,
error
))
{
player
.
play_audio_format
,
error
))
{
g_warning
(
"%s"
,
error
.
GetMessage
());
g_warning
(
"%s"
,
error
.
GetMessage
());
player
->
buffer
.
Return
(
chunk
);
player
.
buffer
.
Return
(
chunk
);
pc
.
Lock
();
pc
.
Lock
();
...
@@ -834,7 +833,7 @@ play_next_chunk(struct player *player)
...
@@ -834,7 +833,7 @@ play_next_chunk(struct player *player)
/* pause: the user may resume playback as soon as an
/* pause: the user may resume playback as soon as an
audio output becomes available */
audio output becomes available */
pc
.
state
=
PLAYER_STATE_PAUSE
;
pc
.
state
=
PLAYER_STATE_PAUSE
;
player
->
paused
=
true
;
player
.
paused
=
true
;
pc
.
Unlock
();
pc
.
Unlock
();
...
@@ -849,7 +848,7 @@ play_next_chunk(struct player *player)
...
@@ -849,7 +848,7 @@ play_next_chunk(struct player *player)
dc
.
Lock
();
dc
.
Lock
();
if
(
!
dc
.
IsIdle
()
&&
if
(
!
dc
.
IsIdle
()
&&
dc
.
pipe
->
GetSize
()
<=
(
pc
.
buffered_before_play
+
dc
.
pipe
->
GetSize
()
<=
(
pc
.
buffered_before_play
+
player
->
buffer
.
GetSize
()
*
3
)
/
4
)
player
.
buffer
.
GetSize
()
*
3
)
/
4
)
dc
.
Signal
();
dc
.
Signal
();
dc
.
Unlock
();
dc
.
Unlock
();
...
@@ -866,28 +865,28 @@ play_next_chunk(struct player *player)
...
@@ -866,28 +865,28 @@ play_next_chunk(struct player *player)
* @return true on success, false on error (playback will be stopped)
* @return true on success, false on error (playback will be stopped)
*/
*/
static
bool
static
bool
player_song_border
(
struct
player
*
player
)
player_song_border
(
player
&
player
)
{
{
player
->
xfade
=
XFADE_UNKNOWN
;
player
.
xfade
=
XFADE_UNKNOWN
;
char
*
uri
=
player
->
song
->
GetURI
();
char
*
uri
=
player
.
song
->
GetURI
();
g_message
(
"played
\"
%s
\"
"
,
uri
);
g_message
(
"played
\"
%s
\"
"
,
uri
);
g_free
(
uri
);
g_free
(
uri
);
delete
player
->
pipe
;
delete
player
.
pipe
;
player
->
pipe
=
player
->
dc
.
pipe
;
player
.
pipe
=
player
.
dc
.
pipe
;
audio_output_all_song_border
();
audio_output_all_song_border
();
if
(
!
player_wait_for_decoder
(
player
))
if
(
!
player_wait_for_decoder
(
player
))
return
false
;
return
false
;
player_control
&
pc
=
player
->
pc
;
player_control
&
pc
=
player
.
pc
;
pc
.
Lock
();
pc
.
Lock
();
const
bool
border_pause
=
pc
.
border_pause
;
const
bool
border_pause
=
pc
.
border_pause
;
if
(
border_pause
)
{
if
(
border_pause
)
{
player
->
paused
=
true
;
player
.
paused
=
true
;
pc
.
state
=
PLAYER_STATE_PAUSE
;
pc
.
state
=
PLAYER_STATE_PAUSE
;
}
}
...
@@ -914,11 +913,11 @@ do_play(player_control &pc, decoder_control &dc,
...
@@ -914,11 +913,11 @@ do_play(player_control &pc, decoder_control &dc,
player
.
pipe
=
new
MusicPipe
();
player
.
pipe
=
new
MusicPipe
();
player_dc_start
(
&
player
,
*
player
.
pipe
);
player_dc_start
(
player
,
*
player
.
pipe
);
if
(
!
player_wait_for_decoder
(
&
player
))
{
if
(
!
player_wait_for_decoder
(
player
))
{
assert
(
player
.
song
==
NULL
);
assert
(
player
.
song
==
NULL
);
player_dc_stop
(
&
player
);
player_dc_stop
(
player
);
player_command_finished
(
pc
);
player_command_finished
(
pc
);
delete
player
.
pipe
;
delete
player
.
pipe
;
GlobalEvents
::
Emit
(
GlobalEvents
::
PLAYLIST
);
GlobalEvents
::
Emit
(
GlobalEvents
::
PLAYLIST
);
...
@@ -935,7 +934,7 @@ do_play(player_control &pc, decoder_control &dc,
...
@@ -935,7 +934,7 @@ do_play(player_control &pc, decoder_control &dc,
player_command_finished_locked
(
pc
);
player_command_finished_locked
(
pc
);
while
(
true
)
{
while
(
true
)
{
player_process_command
(
&
player
);
player_process_command
(
player
);
if
(
pc
.
command
==
PLAYER_COMMAND_STOP
||
if
(
pc
.
command
==
PLAYER_COMMAND_STOP
||
pc
.
command
==
PLAYER_COMMAND_EXIT
||
pc
.
command
==
PLAYER_COMMAND_EXIT
||
pc
.
command
==
PLAYER_COMMAND_CLOSE_AUDIO
)
{
pc
.
command
==
PLAYER_COMMAND_CLOSE_AUDIO
)
{
...
@@ -958,7 +957,7 @@ do_play(player_control &pc, decoder_control &dc,
...
@@ -958,7 +957,7 @@ do_play(player_control &pc, decoder_control &dc,
if
(
!
player
.
paused
&&
if
(
!
player
.
paused
&&
player
.
output_open
&&
player
.
output_open
&&
audio_output_all_check
()
<
4
&&
audio_output_all_check
()
<
4
&&
!
player_send_silence
(
&
player
))
!
player_send_silence
(
player
))
break
;
break
;
dc
.
Lock
();
dc
.
Lock
();
...
@@ -976,7 +975,7 @@ do_play(player_control &pc, decoder_control &dc,
...
@@ -976,7 +975,7 @@ do_play(player_control &pc, decoder_control &dc,
if
(
player
.
decoder_starting
)
{
if
(
player
.
decoder_starting
)
{
/* wait until the decoder is initialized completely */
/* wait until the decoder is initialized completely */
if
(
!
player_check_decoder_startup
(
&
player
))
if
(
!
player_check_decoder_startup
(
player
))
break
;
break
;
pc
.
Lock
();
pc
.
Lock
();
...
@@ -998,13 +997,13 @@ do_play(player_control &pc, decoder_control &dc,
...
@@ -998,13 +997,13 @@ do_play(player_control &pc, decoder_control &dc,
assert
(
dc
.
pipe
==
NULL
||
dc
.
pipe
==
player
.
pipe
);
assert
(
dc
.
pipe
==
NULL
||
dc
.
pipe
==
player
.
pipe
);
player_dc_start
(
&
player
,
*
new
MusicPipe
());
player_dc_start
(
player
,
*
new
MusicPipe
());
}
}
if
(
/* no cross-fading if MPD is going to pause at the
if
(
/* no cross-fading if MPD is going to pause at the
end of the current song */
end of the current song */
!
pc
.
border_pause
&&
!
pc
.
border_pause
&&
player_dc_at_next_song
(
&
player
)
&&
player_dc_at_next_song
(
player
)
&&
player
.
xfade
==
XFADE_UNKNOWN
&&
player
.
xfade
==
XFADE_UNKNOWN
&&
!
dc
.
LockIsStarting
())
{
!
dc
.
LockIsStarting
())
{
/* enable cross fading in this song? if yes,
/* enable cross fading in this song? if yes,
...
@@ -1041,7 +1040,7 @@ do_play(player_control &pc, decoder_control &dc,
...
@@ -1041,7 +1040,7 @@ do_play(player_control &pc, decoder_control &dc,
/* at least one music chunk is ready - send it
/* at least one music chunk is ready - send it
to the audio output */
to the audio output */
play_next_chunk
(
&
player
);
play_next_chunk
(
player
);
}
else
if
(
audio_output_all_check
()
>
0
)
{
}
else
if
(
audio_output_all_check
()
>
0
)
{
/* not enough data from decoder, but the
/* not enough data from decoder, but the
output thread is still busy, so it's
output thread is still busy, so it's
...
@@ -1049,10 +1048,10 @@ do_play(player_control &pc, decoder_control &dc,
...
@@ -1049,10 +1048,10 @@ do_play(player_control &pc, decoder_control &dc,
/* XXX synchronize in a better way */
/* XXX synchronize in a better way */
g_usleep
(
10000
);
g_usleep
(
10000
);
}
else
if
(
player_dc_at_next_song
(
&
player
))
{
}
else
if
(
player_dc_at_next_song
(
player
))
{
/* at the beginning of a new song */
/* at the beginning of a new song */
if
(
!
player_song_border
(
&
player
))
if
(
!
player_song_border
(
player
))
break
;
break
;
}
else
if
(
dc
.
LockIsIdle
())
{
}
else
if
(
dc
.
LockIsIdle
())
{
/* check the size of the pipe again, because
/* check the size of the pipe again, because
...
@@ -1068,14 +1067,14 @@ do_play(player_control &pc, decoder_control &dc,
...
@@ -1068,14 +1067,14 @@ do_play(player_control &pc, decoder_control &dc,
/* the decoder is too busy and hasn't provided
/* the decoder is too busy and hasn't provided
new PCM data in time: send silence (if the
new PCM data in time: send silence (if the
output pipe is empty) */
output pipe is empty) */
if
(
!
player_send_silence
(
&
player
))
if
(
!
player_send_silence
(
player
))
break
;
break
;
}
}
pc
.
Lock
();
pc
.
Lock
();
}
}
player_dc_stop
(
&
player
);
player_dc_stop
(
player
);
player
.
pipe
->
Clear
(
player
.
buffer
);
player
.
pipe
->
Clear
(
player
.
buffer
);
delete
player
.
pipe
;
delete
player
.
pipe
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment