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
760238fe
Commit
760238fe
authored
Jul 01, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/opus: apply pre-skip (RFC7845 4.2)
Fixes the first part of
https://github.com/MusicPlayerDaemon/MPD/issues/867
parent
a99b4aba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
10 deletions
+27
-10
NEWS
NEWS
+2
-0
OpusDecoderPlugin.cxx
src/decoder/plugins/OpusDecoderPlugin.cxx
+25
-10
No files found.
NEWS
View file @
760238fe
...
...
@@ -4,6 +4,8 @@ ver 0.21.25 (not yet released)
* input
- file: detect premature end of file
- smbclient: don't send credentials to MPD clients
* decoder
- opus: apply pre-skip
* output
- osx: improve sample rate selection
* Windows/Android:
...
...
src/decoder/plugins/OpusDecoderPlugin.cxx
View file @
760238fe
...
...
@@ -75,6 +75,8 @@ class MPDOpusDecoder final : public OggDecoder {
OpusDecoder
*
opus_decoder
=
nullptr
;
opus_int16
*
output_buffer
=
nullptr
;
unsigned
pre_skip
,
skip
;
/**
* If non-zero, then a previous Opus stream has been found
* already with this number of channels. If opus_decoder is
...
...
@@ -136,11 +138,13 @@ MPDOpusDecoder::OnOggBeginning(const ogg_packet &packet)
if
(
opus_decoder
!=
nullptr
||
!
IsOpusHead
(
packet
))
throw
std
::
runtime_error
(
"BOS packet must be OpusHead"
);
unsigned
channels
,
pre_skip
;
unsigned
channels
;
if
(
!
ScanOpusHeader
(
packet
.
packet
,
packet
.
bytes
,
channels
,
pre_skip
)
||
!
audio_valid_channel_count
(
channels
))
throw
std
::
runtime_error
(
"Malformed BOS packet"
);
skip
=
pre_skip
;
assert
(
opus_decoder
==
nullptr
);
assert
(
IsInitialized
()
==
(
output_buffer
!=
nullptr
));
...
...
@@ -236,15 +240,25 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
opus_strerror
(
nframes
));
if
(
nframes
>
0
)
{
if
(
skip
>=
(
unsigned
)
nframes
)
{
skip
-=
nframes
;
return
;
}
const
opus_int16
*
data
=
output_buffer
;
data
+=
skip
*
previous_channels
;
nframes
-=
skip
;
skip
=
0
;
const
size_t
nbytes
=
nframes
*
frame_size
;
auto
cmd
=
client
.
SubmitData
(
input_stream
,
output_buffer
,
nbytes
,
data
,
nbytes
,
0
);
if
(
cmd
!=
DecoderCommand
::
NONE
)
throw
cmd
;
if
(
packet
.
granulepos
>
0
)
client
.
SubmitTimestamp
(
FloatDuration
(
packet
.
granulepos
)
client
.
SubmitTimestamp
(
FloatDuration
(
packet
.
granulepos
-
pre_skip
)
/
opus_sample_rate
);
}
}
...
...
@@ -260,6 +274,7 @@ MPDOpusDecoder::Seek(uint64_t where_frame)
try
{
SeekGranulePos
(
where_granulepos
);
skip
=
pre_skip
;
return
true
;
}
catch
(...)
{
return
false
;
...
...
@@ -302,10 +317,9 @@ mpd_opus_stream_decode(DecoderClient &client,
static
bool
ReadAndParseOpusHead
(
OggSyncState
&
sync
,
OggStreamState
&
stream
,
unsigned
&
channels
)
unsigned
&
channels
,
unsigned
&
pre_skip
)
{
ogg_packet
packet
;
unsigned
pre_skip
;
return
OggReadPacket
(
sync
,
stream
,
packet
)
&&
packet
.
b_o_s
&&
IsOpusHead
(
packet
)
&&
...
...
@@ -329,11 +343,12 @@ ReadAndVisitOpusTags(OggSyncState &sync, OggStreamState &stream,
static
void
VisitOpusDuration
(
InputStream
&
is
,
OggSyncState
&
sync
,
OggStreamState
&
stream
,
TagHandler
&
handler
)
ogg_int64_t
pre_skip
,
TagHandler
&
handler
)
{
ogg_packet
packet
;
if
(
OggSeekFindEOS
(
sync
,
stream
,
packet
,
is
))
{
if
(
OggSeekFindEOS
(
sync
,
stream
,
packet
,
is
)
&&
packet
.
granulepos
>=
pre_skip
)
{
const
auto
duration
=
SongTime
::
FromScale
<
uint64_t
>
(
packet
.
granulepos
,
opus_sample_rate
);
...
...
@@ -353,15 +368,15 @@ mpd_opus_scan_stream(InputStream &is, TagHandler &handler) noexcept
OggStreamState
os
(
first_page
);
unsigned
channels
;
if
(
!
ReadAndParseOpusHead
(
oy
,
os
,
channels
)
||
unsigned
channels
,
pre_skip
;
if
(
!
ReadAndParseOpusHead
(
oy
,
os
,
channels
,
pre_skip
)
||
!
ReadAndVisitOpusTags
(
oy
,
os
,
handler
))
return
false
;
handler
.
OnAudioFormat
(
AudioFormat
(
opus_sample_rate
,
SampleFormat
::
S16
,
channels
));
VisitOpusDuration
(
is
,
oy
,
os
,
handler
);
VisitOpusDuration
(
is
,
oy
,
os
,
pre_skip
,
handler
);
return
true
;
}
...
...
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