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
96b70835
Commit
96b70835
authored
Sep 26, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PlayerThread: move global MusicBuffer variable into the player object
parent
7fa3b7a2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
24 deletions
+27
-24
PlayerThread.cxx
src/PlayerThread.cxx
+27
-24
No files found.
src/PlayerThread.cxx
View file @
96b70835
...
...
@@ -54,6 +54,8 @@ struct player {
struct
decoder_control
*
dc
;
MusicBuffer
&
buffer
;
MusicPipe
*
pipe
;
/**
...
...
@@ -126,8 +128,9 @@ struct player {
*/
float
elapsed_time
;
player
(
player_control
*
_pc
,
decoder_control
*
_dc
)
:
pc
(
_pc
),
dc
(
_dc
),
player
(
player_control
*
_pc
,
decoder_control
*
_dc
,
MusicBuffer
&
_buffer
)
:
pc
(
_pc
),
dc
(
_dc
),
buffer
(
_buffer
),
buffering
(
false
),
decoder_starting
(
false
),
paused
(
false
),
...
...
@@ -141,8 +144,6 @@ struct player {
elapsed_time
(
0.0
)
{}
};
static
MusicBuffer
*
player_buffer
;
static
void
player_command_finished_locked
(
struct
player_control
*
pc
)
{
...
...
@@ -180,7 +181,7 @@ player_dc_start(struct player *player, MusicPipe &pipe)
dc
->
Start
(
pc
->
next_song
->
DupDetached
(),
start_ms
,
pc
->
next_song
->
end_ms
,
*
player_
buffer
,
pipe
);
player
->
buffer
,
pipe
);
}
/**
...
...
@@ -224,7 +225,7 @@ player_dc_stop(struct player *player)
if
(
dc
->
pipe
!=
NULL
)
{
/* clear and free the decoder pipe */
dc
->
pipe
->
Clear
(
*
player_
buffer
);
dc
->
pipe
->
Clear
(
player
->
buffer
);
if
(
dc
->
pipe
!=
player
->
pipe
)
delete
dc
->
pipe
;
...
...
@@ -328,7 +329,7 @@ player_open_output(struct player *player)
pc
->
state
==
PLAYER_STATE_PAUSE
);
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
))
{
player
->
output_open
=
true
;
player
->
paused
=
false
;
...
...
@@ -441,7 +442,7 @@ player_send_silence(struct player *player)
assert
(
player
->
output_open
);
assert
(
player
->
play_audio_format
.
IsDefined
());
struct
music_chunk
*
chunk
=
player
_buffer
->
Allocate
();
struct
music_chunk
*
chunk
=
player
->
buffer
.
Allocate
();
if
(
chunk
==
NULL
)
{
g_warning
(
"Failed to allocate silence buffer"
);
return
false
;
...
...
@@ -463,7 +464,7 @@ player_send_silence(struct player *player)
Error
error
;
if
(
!
audio_output_all_play
(
chunk
,
error
))
{
g_warning
(
"%s"
,
error
.
GetMessage
());
player
_buffer
->
Return
(
chunk
);
player
->
buffer
.
Return
(
chunk
);
return
false
;
}
...
...
@@ -493,7 +494,7 @@ static bool player_seek_decoder(struct player *player)
/* clear music chunks which might still reside in the
pipe */
player
->
pipe
->
Clear
(
*
player_
buffer
);
player
->
pipe
->
Clear
(
player
->
buffer
);
/* re-start the decoder */
player_dc_start
(
player
,
*
player
->
pipe
);
...
...
@@ -506,7 +507,7 @@ static bool player_seek_decoder(struct player *player)
if
(
!
player_dc_at_current_song
(
player
))
{
/* the decoder is already decoding the "next" song,
but it is the same song file; exchange the pipe */
player
->
pipe
->
Clear
(
*
player_
buffer
);
player
->
pipe
->
Clear
(
player
->
buffer
);
delete
player
->
pipe
;
player
->
pipe
=
dc
->
pipe
;
}
...
...
@@ -686,6 +687,7 @@ update_song_tag(Song *song, const Tag &new_tag)
static
bool
play_chunk
(
struct
player_control
*
pc
,
Song
*
song
,
struct
music_chunk
*
chunk
,
MusicBuffer
&
buffer
,
const
AudioFormat
format
,
Error
&
error
)
{
...
...
@@ -695,7 +697,7 @@ play_chunk(struct player_control *pc,
update_song_tag
(
song
,
*
chunk
->
tag
);
if
(
chunk
->
length
==
0
)
{
player_buffer
->
Return
(
chunk
);
buffer
.
Return
(
chunk
);
return
true
;
}
...
...
@@ -776,7 +778,7 @@ play_next_chunk(struct player *player)
beginning of the new song, we can
easily recover by throwing it away
now */
player
_buffer
->
Return
(
other_chunk
);
player
->
buffer
.
Return
(
other_chunk
);
other_chunk
=
NULL
;
}
...
...
@@ -819,11 +821,11 @@ play_next_chunk(struct player *player)
/* play the current chunk */
Error
error
;
if
(
!
play_chunk
(
player
->
pc
,
player
->
song
,
chunk
,
if
(
!
play_chunk
(
player
->
pc
,
player
->
song
,
chunk
,
player
->
buffer
,
player
->
play_audio_format
,
error
))
{
g_warning
(
"%s"
,
error
.
GetMessage
());
player
_buffer
->
Return
(
chunk
);
player
->
buffer
.
Return
(
chunk
);
pc
->
Lock
();
...
...
@@ -847,7 +849,7 @@ play_next_chunk(struct player *player)
dc
->
Lock
();
if
(
!
dc
->
IsIdle
()
&&
dc
->
pipe
->
GetSize
()
<=
(
pc
->
buffered_before_play
+
player
_buffer
->
GetSize
()
*
3
)
/
4
)
player
->
buffer
.
GetSize
()
*
3
)
/
4
)
dc
->
Signal
();
dc
->
Unlock
();
...
...
@@ -902,9 +904,11 @@ player_song_border(struct player *player)
* basically a state machine, which multiplexes data between the
* decoder thread and the output threads.
*/
static
void
do_play
(
struct
player_control
*
pc
,
struct
decoder_control
*
dc
)
static
void
do_play
(
struct
player_control
*
pc
,
struct
decoder_control
*
dc
,
MusicBuffer
&
buffer
)
{
player
player
(
pc
,
dc
);
player
player
(
pc
,
dc
,
buffer
);
pc
->
Unlock
();
...
...
@@ -1016,7 +1020,7 @@ static void do_play(struct player_control *pc, struct decoder_control *dc)
dc
->
mixramp_prev_end
,
dc
->
out_audio_format
,
player
.
play_audio_format
,
player
_buffer
->
GetSize
()
-
player
.
buffer
.
GetSize
()
-
pc
->
buffered_before_play
);
if
(
player
.
cross_fade_chunks
>
0
)
{
player
.
xfade
=
XFADE_ENABLED
;
...
...
@@ -1073,7 +1077,7 @@ static void do_play(struct player_control *pc, struct decoder_control *dc)
player_dc_stop
(
&
player
);
player
.
pipe
->
Clear
(
*
player_
buffer
);
player
.
pipe
->
Clear
(
player
.
buffer
);
delete
player
.
pipe
;
delete
player
.
cross_fade_tag
;
...
...
@@ -1106,7 +1110,7 @@ player_task(gpointer arg)
struct
decoder_control
*
dc
=
new
decoder_control
();
decoder_thread_start
(
dc
);
player_buffer
=
new
MusicB
uffer
(
pc
->
buffer_chunks
);
MusicBuffer
b
uffer
(
pc
->
buffer_chunks
);
pc
->
Lock
();
...
...
@@ -1116,7 +1120,7 @@ player_task(gpointer arg)
case
PLAYER_COMMAND_QUEUE
:
assert
(
pc
->
next_song
!=
NULL
);
do_play
(
pc
,
dc
);
do_play
(
pc
,
dc
,
buffer
);
break
;
case
PLAYER_COMMAND_STOP
:
...
...
@@ -1143,7 +1147,7 @@ player_task(gpointer arg)
pc
->
Lock
();
player_command_finished_locked
(
pc
);
assert
(
player_buffer
->
IsEmptyUnsafe
());
assert
(
buffer
.
IsEmptyUnsafe
());
break
;
...
...
@@ -1160,7 +1164,6 @@ player_task(gpointer arg)
dc
->
Quit
();
delete
dc
;
audio_output_all_close
();
delete
player_buffer
;
player_command_finished
(
pc
);
return
NULL
;
...
...
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