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
7019f6be
Commit
7019f6be
authored
Nov 17, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decoder/pcm: round buffer size down to nearest frame size
https://bugs.musicpd.org/view.php?id=4599
parent
8bde4728
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
12 deletions
+34
-12
NEWS
NEWS
+1
-0
PcmDecoderPlugin.cxx
src/decoder/plugins/PcmDecoderPlugin.cxx
+33
-12
No files found.
NEWS
View file @
7019f6be
ver 0.19.20 (not yet released)
* decoder
- ffmpeg: ignore empty packets
- pcm: fix corruption bug with partial frames (after short read)
- sidplay: fix playback speed with libsidplayfp
* output
- winmm: fix 8 bit playback
...
...
src/decoder/plugins/PcmDecoderPlugin.cxx
View file @
7019f6be
...
...
@@ -23,10 +23,28 @@
#include "input/InputStream.hxx"
#include "util/Error.hxx"
#include "util/ByteReverse.hxx"
#include "util/StaticFifoBuffer.hxx"
#include "Log.hxx"
#include <assert.h>
#include <string.h>
template
<
typename
B
>
static
bool
FillBuffer
(
Decoder
&
decoder
,
InputStream
&
is
,
B
&
buffer
)
{
buffer
.
Shift
();
auto
w
=
buffer
.
Write
();
assert
(
!
w
.
IsEmpty
());
size_t
nbytes
=
decoder_read
(
decoder
,
is
,
w
.
data
,
w
.
size
);
if
(
nbytes
==
0
&&
is
.
LockIsEOF
())
return
false
;
buffer
.
Append
(
nbytes
);
return
true
;
}
static
void
pcm_stream_decode
(
Decoder
&
decoder
,
InputStream
&
is
)
{
...
...
@@ -50,25 +68,27 @@ pcm_stream_decode(Decoder &decoder, InputStream &is)
decoder_initialized
(
decoder
,
audio_format
,
is
.
IsSeekable
(),
total_time
);
StaticFifoBuffer
<
uint8_t
,
4096
>
buffer
;
DecoderCommand
cmd
;
do
{
char
buffer
[
4096
];
size_t
nbytes
=
decoder_read
(
decoder
,
is
,
buffer
,
sizeof
(
buffer
));
if
(
nbytes
==
0
&&
is
.
LockIsEOF
())
if
(
!
FillBuffer
(
decoder
,
is
,
buffer
))
break
;
auto
r
=
buffer
.
Read
();
/* round down to the nearest frame size, because we
must not pass partial frames to decoder_data() */
r
.
size
-=
r
.
size
%
frame_size
;
buffer
.
Consume
(
r
.
size
);
if
(
reverse_endian
)
/* make sure we deliver samples in host byte order */
reverse_bytes_16
((
uint16_t
*
)
buffer
,
(
uint16_t
*
)
buffer
,
(
uint16_t
*
)(
buffer
+
nbytes
));
reverse_bytes_16
((
uint16_t
*
)
r
.
data
,
(
uint16_t
*
)
r
.
data
,
(
uint16_t
*
)(
r
.
data
+
r
.
size
));
cmd
=
nbytes
>
0
?
decoder_data
(
decoder
,
is
,
buffer
,
nbytes
,
0
)
cmd
=
!
r
.
IsEmpty
()
?
decoder_data
(
decoder
,
is
,
r
.
data
,
r
.
size
,
0
)
:
decoder_get_command
(
decoder
);
if
(
cmd
==
DecoderCommand
::
SEEK
)
{
uint64_t
frame
=
decoder_seek_where_frame
(
decoder
);
...
...
@@ -76,6 +96,7 @@ pcm_stream_decode(Decoder &decoder, InputStream &is)
Error
error
;
if
(
is
.
LockSeek
(
offset
,
error
))
{
buffer
.
Clear
();
decoder_command_finished
(
decoder
);
}
else
{
LogError
(
error
);
...
...
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