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
67659016
Commit
67659016
authored
Sep 27, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DecoderControl: convert "enum decoder_state" to strictly-typed enum
parent
c5d05ac0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
47 deletions
+53
-47
DecoderAPI.cxx
src/DecoderAPI.cxx
+8
-8
DecoderControl.cxx
src/DecoderControl.cxx
+9
-9
DecoderControl.hxx
src/DecoderControl.hxx
+22
-16
DecoderThread.cxx
src/DecoderThread.cxx
+14
-14
No files found.
src/DecoderAPI.cxx
View file @
67659016
...
...
@@ -47,7 +47,7 @@ decoder_initialized(struct decoder *decoder,
struct
decoder_control
*
dc
=
decoder
->
dc
;
struct
audio_format_string
af_string
;
assert
(
dc
->
state
==
D
ECODE_STATE_
START
);
assert
(
dc
->
state
==
D
ecoderState
::
START
);
assert
(
dc
->
pipe
!=
NULL
);
assert
(
decoder
!=
NULL
);
assert
(
decoder
->
stream_tag
==
NULL
);
...
...
@@ -63,7 +63,7 @@ decoder_initialized(struct decoder *decoder,
dc
->
total_time
=
total_time
;
dc
->
Lock
();
dc
->
state
=
D
ECODE_STATE_
DECODE
;
dc
->
state
=
D
ecoderState
::
DECODE
;
dc
->
client_cond
.
signal
();
dc
->
Unlock
();
...
...
@@ -88,7 +88,7 @@ decoder_prepare_initial_seek(struct decoder *decoder)
const
struct
decoder_control
*
dc
=
decoder
->
dc
;
assert
(
dc
->
pipe
!=
NULL
);
if
(
dc
->
state
!=
D
ECODE_STATE_
DECODE
)
if
(
dc
->
state
!=
D
ecoderState
::
DECODE
)
/* wait until the decoder has finished initialisation
(reading file headers etc.) before emitting the
virtual "SEEK" command */
...
...
@@ -247,7 +247,7 @@ decoder_check_cancel_read(const struct decoder *decoder)
/* ignore the SEEK command during initialization, the plugin
should handle that after it has initialized successfully */
if
(
dc
->
command
==
DecoderCommand
::
SEEK
&&
(
dc
->
state
==
D
ECODE_STATE_
START
||
decoder
->
seeking
))
(
dc
->
state
==
D
ecoderState
::
START
||
decoder
->
seeking
))
return
false
;
return
true
;
...
...
@@ -260,8 +260,8 @@ size_t decoder_read(struct decoder *decoder,
/* XXX don't allow decoder==NULL */
assert
(
decoder
==
NULL
||
decoder
->
dc
->
state
==
D
ECODE_STATE_
START
||
decoder
->
dc
->
state
==
D
ECODE_STATE_
DECODE
);
decoder
->
dc
->
state
==
D
ecoderState
::
START
||
decoder
->
dc
->
state
==
D
ecoderState
::
DECODE
);
assert
(
is
!=
NULL
);
assert
(
buffer
!=
NULL
);
...
...
@@ -364,7 +364,7 @@ decoder_data(struct decoder *decoder,
struct
decoder_control
*
dc
=
decoder
->
dc
;
DecoderCommand
cmd
;
assert
(
dc
->
state
==
D
ECODE_STATE_
DECODE
);
assert
(
dc
->
state
==
D
ecoderState
::
DECODE
);
assert
(
dc
->
pipe
!=
NULL
);
assert
(
length
%
dc
->
in_audio_format
.
GetFrameSize
()
==
0
);
...
...
@@ -472,7 +472,7 @@ decoder_tag(gcc_unused struct decoder *decoder, struct input_stream *is,
gcc_unused
const
struct
decoder_control
*
dc
=
decoder
->
dc
;
DecoderCommand
cmd
;
assert
(
dc
->
state
==
D
ECODE_STATE_
DECODE
);
assert
(
dc
->
state
==
D
ecoderState
::
DECODE
);
assert
(
dc
->
pipe
!=
NULL
);
/* save the tag */
...
...
src/DecoderControl.cxx
View file @
67659016
...
...
@@ -29,7 +29,7 @@
decoder_control
::
decoder_control
()
:
thread
(
nullptr
),
state
(
D
ECODE_STATE_
STOP
),
state
(
D
ecoderState
::
STOP
),
command
(
DecoderCommand
::
NONE
),
song
(
nullptr
),
replay_gain_db
(
0
),
replay_gain_prev_db
(
0
),
...
...
@@ -54,12 +54,12 @@ decoder_control::IsCurrentSong(const Song *_song) const
assert
(
_song
!=
NULL
);
switch
(
state
)
{
case
D
ECODE_STATE_
STOP
:
case
D
ECODE_STATE_
ERROR
:
case
D
ecoderState
:
:
STOP
:
case
D
ecoderState
:
:
ERROR
:
return
false
;
case
D
ECODE_STATE_
START
:
case
D
ECODE_STATE_
DECODE
:
case
D
ecoderState
:
:
START
:
case
D
ecoderState
:
:
DECODE
:
return
song_equals
(
song
,
_song
);
}
...
...
@@ -99,7 +99,7 @@ decoder_control::Stop()
function (see below). */
SynchronousCommandLocked
(
DecoderCommand
::
STOP
);
if
(
state
!=
D
ECODE_STATE_STOP
&&
state
!=
DECODE_STATE_
ERROR
)
if
(
state
!=
D
ecoderState
::
STOP
&&
state
!=
DecoderState
::
ERROR
)
SynchronousCommandLocked
(
DecoderCommand
::
STOP
);
Unlock
();
...
...
@@ -108,11 +108,11 @@ decoder_control::Stop()
bool
decoder_control
::
Seek
(
double
where
)
{
assert
(
state
!=
D
ECODE_STATE_
START
);
assert
(
state
!=
D
ecoderState
::
START
);
assert
(
where
>=
0.0
);
if
(
state
==
D
ECODE_STATE_
STOP
||
state
==
D
ECODE_STATE_
ERROR
||
!
seekable
)
if
(
state
==
D
ecoderState
::
STOP
||
state
==
D
ecoderState
::
ERROR
||
!
seekable
)
return
false
;
seek_where
=
where
;
...
...
src/DecoderControl.hxx
View file @
67659016
...
...
@@ -29,15 +29,21 @@
#include <glib.h>
#include <assert.h>
#include <stdint.h>
/* damn you, windows.h! */
#ifdef ERROR
#undef ERROR
#endif
struct
Song
;
class
MusicBuffer
;
class
MusicPipe
;
enum
decoder_state
{
DECODE_STATE_
STOP
=
0
,
DECODE_STATE_
START
,
DECODE
_STATE_DECODE
,
enum
class
DecoderState
:
uint8_t
{
STOP
=
0
,
START
,
DECODE
,
/**
* The last "START" command failed, because there was an I/O
...
...
@@ -45,7 +51,7 @@ enum decoder_state {
* This state will only come after START; once the state has
* turned to DECODE, by definition no such error can occur.
*/
DECODE_STATE_
ERROR
,
ERROR
,
};
struct
decoder_control
{
...
...
@@ -71,14 +77,14 @@ struct decoder_control {
*/
Cond
client_cond
;
enum
decoder_s
tate
state
;
DecoderS
tate
state
;
DecoderCommand
command
;
/**
* The error that occurred in the decoder thread. This
* attribute is only valid if #state is #D
ECODE_STATE_
ERROR.
* attribute is only valid if #state is #D
ecoderState::
ERROR.
* The object must be freed when this object transitions to
* any other state (usually #D
ECODE_STATE_
START).
* any other state (usually #D
ecoderState::
START).
*/
Error
error
;
...
...
@@ -182,8 +188,8 @@ struct decoder_control {
}
bool
IsIdle
()
const
{
return
state
==
D
ECODE_STATE_
STOP
||
state
==
D
ECODE_STATE_
ERROR
;
return
state
==
D
ecoderState
::
STOP
||
state
==
D
ecoderState
::
ERROR
;
}
gcc_pure
...
...
@@ -195,7 +201,7 @@ struct decoder_control {
}
bool
IsStarting
()
const
{
return
state
==
D
ECODE_STATE_
START
;
return
state
==
D
ecoderState
::
START
;
}
gcc_pure
...
...
@@ -209,7 +215,7 @@ struct decoder_control {
bool
HasFailed
()
const
{
assert
(
command
==
DecoderCommand
::
NONE
);
return
state
==
D
ECODE_STATE_
ERROR
;
return
state
==
D
ecoderState
::
ERROR
;
}
gcc_pure
...
...
@@ -229,10 +235,10 @@ struct decoder_control {
gcc_pure
Error
GetError
()
const
{
assert
(
command
==
DecoderCommand
::
NONE
);
assert
(
state
!=
D
ECODE_STATE_
ERROR
||
error
.
IsDefined
());
assert
(
state
!=
D
ecoderState
::
ERROR
||
error
.
IsDefined
());
Error
result
;
if
(
state
==
D
ECODE_STATE_
ERROR
)
if
(
state
==
D
ecoderState
::
ERROR
)
result
.
Set
(
error
);
return
result
;
}
...
...
@@ -254,9 +260,9 @@ struct decoder_control {
* Caller must lock the object.
*/
void
ClearError
()
{
if
(
state
==
D
ECODE_STATE_
ERROR
)
{
if
(
state
==
D
ecoderState
::
ERROR
)
{
error
.
Clear
();
state
=
D
ECODE_STATE_
STOP
;
state
=
D
ecoderState
::
STOP
;
}
}
...
...
src/DecoderThread.cxx
View file @
67659016
...
...
@@ -120,7 +120,7 @@ decoder_stream_decode(const struct decoder_plugin *plugin,
assert
(
decoder
->
decoder_tag
==
NULL
);
assert
(
input_stream
!=
NULL
);
assert
(
input_stream
->
ready
);
assert
(
decoder
->
dc
->
state
==
D
ECODE_STATE_
START
);
assert
(
decoder
->
dc
->
state
==
D
ecoderState
::
START
);
g_debug
(
"probing plugin %s"
,
plugin
->
name
);
...
...
@@ -136,10 +136,10 @@ decoder_stream_decode(const struct decoder_plugin *plugin,
decoder
->
dc
->
Lock
();
assert
(
decoder
->
dc
->
state
==
D
ECODE_STATE_
START
||
decoder
->
dc
->
state
==
D
ECODE_STATE_
DECODE
);
assert
(
decoder
->
dc
->
state
==
D
ecoderState
::
START
||
decoder
->
dc
->
state
==
D
ecoderState
::
DECODE
);
return
decoder
->
dc
->
state
!=
D
ECODE_STATE_
START
;
return
decoder
->
dc
->
state
!=
D
ecoderState
::
START
;
}
static
bool
...
...
@@ -153,7 +153,7 @@ decoder_file_decode(const struct decoder_plugin *plugin,
assert
(
decoder
->
decoder_tag
==
NULL
);
assert
(
path
!=
NULL
);
assert
(
g_path_is_absolute
(
path
));
assert
(
decoder
->
dc
->
state
==
D
ECODE_STATE_
START
);
assert
(
decoder
->
dc
->
state
==
D
ecoderState
::
START
);
g_debug
(
"probing plugin %s"
,
plugin
->
name
);
...
...
@@ -166,10 +166,10 @@ decoder_file_decode(const struct decoder_plugin *plugin,
decoder
->
dc
->
Lock
();
assert
(
decoder
->
dc
->
state
==
D
ECODE_STATE_
START
||
decoder
->
dc
->
state
==
D
ECODE_STATE_
DECODE
);
assert
(
decoder
->
dc
->
state
==
D
ecoderState
::
START
||
decoder
->
dc
->
state
==
D
ecoderState
::
DECODE
);
return
decoder
->
dc
->
state
!=
D
ECODE_STATE_
START
;
return
decoder
->
dc
->
state
!=
D
ecoderState
::
START
;
}
/**
...
...
@@ -380,7 +380,7 @@ decoder_run_song(struct decoder_control *dc,
?
new
Tag
(
*
song
->
tag
)
:
nullptr
);
int
ret
;
dc
->
state
=
D
ECODE_STATE_
START
;
dc
->
state
=
D
ecoderState
::
START
;
decoder_command_finished_locked
(
dc
);
...
...
@@ -398,9 +398,9 @@ decoder_run_song(struct decoder_control *dc,
dc
->
Lock
();
if
(
ret
)
dc
->
state
=
D
ECODE_STATE_
STOP
;
dc
->
state
=
D
ecoderState
::
STOP
;
else
{
dc
->
state
=
D
ECODE_STATE_
ERROR
;
dc
->
state
=
D
ecoderState
::
ERROR
;
const
char
*
error_uri
=
song
->
uri
;
char
*
allocated
=
uri_remove_auth
(
error_uri
);
...
...
@@ -431,7 +431,7 @@ decoder_run(struct decoder_control *dc)
uri
=
song
->
GetURI
();
if
(
uri
==
NULL
)
{
dc
->
state
=
D
ECODE_STATE_
ERROR
;
dc
->
state
=
D
ecoderState
::
ERROR
;
dc
->
error
.
Set
(
decoder_domain
,
"Failed to map song"
);
decoder_command_finished_locked
(
dc
);
...
...
@@ -451,8 +451,8 @@ decoder_task(gpointer arg)
dc
->
Lock
();
do
{
assert
(
dc
->
state
==
D
ECODE_STATE_
STOP
||
dc
->
state
==
D
ECODE_STATE_
ERROR
);
assert
(
dc
->
state
==
D
ecoderState
::
STOP
||
dc
->
state
==
D
ecoderState
::
ERROR
);
switch
(
dc
->
command
)
{
case
DecoderCommand
:
:
START
:
...
...
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