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
140d8547
Commit
140d8547
authored
Feb 04, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/run_decoder: add option --seek
parent
6f579ddc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
5 deletions
+89
-5
run_decoder.cxx
test/run_decoder.cxx
+89
-5
No files found.
test/run_decoder.cxx
View file @
140d8547
...
...
@@ -47,16 +47,20 @@ struct CommandLine {
Path
config_path
=
nullptr
;
bool
verbose
=
false
;
SongTime
seek_where
{};
};
enum
Option
{
OPTION_CONFIG
,
OPTION_VERBOSE
,
OPTION_SEEK
,
};
static
constexpr
OptionDef
option_defs
[]
=
{
{
"config"
,
0
,
true
,
"Load a MPD configuration file"
},
{
"verbose"
,
'v'
,
false
,
"Verbose logging"
},
{
"seek"
,
0
,
true
,
"Seek to this position"
},
};
static
CommandLine
...
...
@@ -74,6 +78,10 @@ ParseCommandLine(int argc, char **argv)
case
OPTION_VERBOSE
:
c
.
verbose
=
true
;
break
;
case
OPTION_SEEK
:
c
.
seek_where
=
SongTime
::
FromS
(
strtod
(
o
.
value
,
nullptr
));
break
;
}
}
...
...
@@ -102,6 +110,85 @@ public:
}
};
class
MyDecoderClient
final
:
public
DumpDecoderClient
{
SongTime
seek_where
;
unsigned
sample_rate
;
bool
seekable
,
seek_error
=
false
;
public
:
explicit
MyDecoderClient
(
SongTime
_seek_where
)
noexcept
:
seek_where
(
_seek_where
)
{}
void
Finish
()
{
if
(
!
IsInitialized
())
throw
"Unrecognized file"
;
if
(
seek_error
)
throw
"Seek error"
;
if
(
seek_where
!=
SongTime
{})
{
if
(
!
seekable
)
throw
"Not seekable"
;
throw
"Did not seek"
;
}
}
/* virtual methods from DecoderClient */
void
Ready
(
AudioFormat
audio_format
,
bool
_seekable
,
SignedSongTime
duration
)
noexcept
override
{
assert
(
!
IsInitialized
());
DumpDecoderClient
::
Ready
(
audio_format
,
_seekable
,
duration
);
sample_rate
=
audio_format
.
sample_rate
;
seekable
=
_seekable
;
}
DecoderCommand
GetCommand
()
noexcept
override
{
assert
(
IsInitialized
());
if
(
seek_where
!=
SongTime
{})
{
if
(
!
seekable
)
return
DecoderCommand
::
STOP
;
return
DecoderCommand
::
SEEK
;
}
else
if
(
seek_error
)
return
DecoderCommand
::
STOP
;
else
return
DumpDecoderClient
::
GetCommand
();
}
void
CommandFinished
()
noexcept
override
{
assert
(
!
seek_error
);
if
(
seek_where
!=
SongTime
{})
seek_where
=
{};
else
DumpDecoderClient
::
CommandFinished
();
}
SongTime
GetSeekTime
()
noexcept
override
{
assert
(
seek_where
!=
SongTime
{});
return
seek_where
;
}
uint64_t
GetSeekFrame
()
noexcept
override
{
assert
(
seek_where
!=
SongTime
{});
return
GetSeekTime
().
ToScale
<
uint64_t
>
(
sample_rate
);
}
void
SeekError
()
noexcept
override
{
assert
(
seek_where
!=
SongTime
{});
seek_error
=
true
;
seek_where
=
{};
}
};
int
main
(
int
argc
,
char
**
argv
)
try
{
const
auto
c
=
ParseCommandLine
(
argc
,
argv
);
...
...
@@ -115,7 +202,7 @@ try {
return
EXIT_FAILURE
;
}
DumpDecoderClient
client
;
MyDecoderClient
client
(
c
.
seek_where
)
;
if
(
plugin
->
file_decode
!=
nullptr
)
{
try
{
plugin
->
FileDecode
(
client
,
Path
::
FromFS
(
c
.
uri
));
...
...
@@ -132,10 +219,7 @@ try {
return
EXIT_FAILURE
;
}
if
(
!
client
.
IsInitialized
())
{
fprintf
(
stderr
,
"Decoding failed
\n
"
);
return
EXIT_FAILURE
;
}
client
.
Finish
();
return
EXIT_SUCCESS
;
}
catch
(...)
{
...
...
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