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
7befab7e
Commit
7befab7e
authored
Jul 01, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/opus: keep track of the granulepos
Will be needed for End Trimming (RFC7845 4.4,
https://github.com/MusicPlayerDaemon/MPD/issues/867
).
parent
4244e612
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
2 deletions
+27
-2
OpusDecoderPlugin.cxx
src/decoder/plugins/OpusDecoderPlugin.cxx
+27
-2
No files found.
src/decoder/plugins/OpusDecoderPlugin.cxx
View file @
7befab7e
...
...
@@ -98,6 +98,13 @@ class MPDOpusDecoder final : public OggDecoder {
size_t
frame_size
;
/**
* The granulepos of the next sample to be submitted to
* DecoderClient::SubmitData(). Negative if unkown.
* Initialized by OnOggBeginning().
*/
ogg_int64_t
granulepos
;
public
:
explicit
MPDOpusDecoder
(
DecoderReader
&
reader
)
:
OggDecoder
(
reader
)
{}
...
...
@@ -114,6 +121,13 @@ public:
bool
Seek
(
uint64_t
where_frame
);
private
:
void
AddGranulepos
(
ogg_int64_t
n
)
noexcept
{
assert
(
n
>=
0
);
if
(
granulepos
>=
0
)
granulepos
+=
n
;
}
void
HandleTags
(
const
ogg_packet
&
packet
);
void
HandleAudio
(
const
ogg_packet
&
packet
);
...
...
@@ -154,6 +168,7 @@ MPDOpusDecoder::OnOggBeginning(const ogg_packet &packet)
!
audio_valid_channel_count
(
channels
))
throw
std
::
runtime_error
(
"Malformed BOS packet"
);
granulepos
=
0
;
skip
=
pre_skip
;
assert
(
opus_decoder
==
nullptr
);
...
...
@@ -261,12 +276,14 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
/* apply the "skip" value */
if
(
skip
>=
(
unsigned
)
nframes
)
{
skip
-=
nframes
;
AddGranulepos
(
nframes
);
return
;
}
const
opus_int16
*
data
=
output_buffer
;
data
+=
skip
*
previous_channels
;
nframes
-=
skip
;
AddGranulepos
(
skip
);
skip
=
0
;
/* submit decoded samples to the DecoderClient */
...
...
@@ -277,9 +294,12 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
if
(
cmd
!=
DecoderCommand
::
NONE
)
throw
cmd
;
if
(
packet
.
granulepos
>
0
)
client
.
SubmitTimestamp
(
FloatDuration
(
packet
.
granulepos
-
pre_skip
)
if
(
packet
.
granulepos
>
0
)
{
granulepos
=
packet
.
granulepos
;
client
.
SubmitTimestamp
(
FloatDuration
(
granulepos
-
pre_skip
)
/
opus_sample_rate
);
}
else
AddGranulepos
(
nframes
);
}
bool
...
...
@@ -291,6 +311,11 @@ MPDOpusDecoder::Seek(uint64_t where_frame)
const
ogg_int64_t
where_granulepos
(
where_frame
);
/* we don't know the exact granulepos after seeking, so let's
set it to -1 - it will be set after the next packet which
declares its granulepos */
granulepos
=
-
1
;
try
{
SeekGranulePos
(
where_granulepos
);
...
...
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