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
b2b95cad
Commit
b2b95cad
authored
Jul 12, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DecoderBuffer: add method _need()
Move code from the FAAD decoder plugin.
parent
eabec967
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
31 deletions
+42
-31
DecoderBuffer.cxx
src/decoder/DecoderBuffer.cxx
+22
-3
DecoderBuffer.hxx
src/decoder/DecoderBuffer.hxx
+7
-0
FaadDecoderPlugin.cxx
src/decoder/plugins/FaadDecoderPlugin.cxx
+13
-28
No files found.
src/decoder/DecoderBuffer.cxx
View file @
b2b95cad
...
...
@@ -117,21 +117,40 @@ decoder_buffer_fill(DecoderBuffer *buffer)
return
true
;
}
static
const
void
*
decoder_buffer_head
(
const
DecoderBuffer
*
buffer
)
{
return
buffer
->
data
+
buffer
->
consumed
;
}
size_t
decoder_buffer_available
(
const
DecoderBuffer
*
buffer
)
{
return
buffer
->
length
-
buffer
->
consumed
;
;
return
buffer
->
length
-
buffer
->
consumed
;
}
ConstBuffer
<
void
>
decoder_buffer_read
(
const
DecoderBuffer
*
buffer
)
{
return
{
buffer
->
data
+
buffer
->
consumed
,
buffer
->
length
-
buffer
->
consumed
decoder_buffer_head
(
buffer
)
,
decoder_buffer_available
(
buffer
),
};
}
ConstBuffer
<
void
>
decoder_buffer_need
(
DecoderBuffer
*
buffer
,
size_t
min_size
)
{
while
(
true
)
{
const
auto
available
=
decoder_buffer_available
(
buffer
);
if
(
available
>=
min_size
)
return
{
decoder_buffer_head
(
buffer
),
available
};
if
(
!
decoder_buffer_fill
(
buffer
))
return
nullptr
;
}
}
void
decoder_buffer_consume
(
DecoderBuffer
*
buffer
,
size_t
nbytes
)
{
...
...
src/decoder/DecoderBuffer.hxx
View file @
b2b95cad
...
...
@@ -91,6 +91,13 @@ ConstBuffer<void>
decoder_buffer_read
(
const
DecoderBuffer
*
buffer
);
/**
* Wait until this number of bytes are available. Returns nullptr on
* error.
*/
ConstBuffer
<
void
>
decoder_buffer_need
(
DecoderBuffer
*
buffer
,
size_t
min_size
);
/**
* Consume (delete, invalidate) a part of the buffer. The "nbytes"
* parameter must not be larger than the length returned by
* decoder_buffer_read().
...
...
src/decoder/plugins/FaadDecoderPlugin.cxx
View file @
b2b95cad
...
...
@@ -66,15 +66,10 @@ static size_t
adts_find_frame
(
DecoderBuffer
*
buffer
)
{
while
(
true
)
{
auto
data
=
ConstBuffer
<
uint8_t
>::
FromVoid
(
decoder_buffer_read
(
buffer
));
if
(
data
.
size
<
8
)
{
/* not enough data yet */
if
(
!
decoder_buffer_fill
(
buffer
))
/* failed */
return
0
;
continue
;
}
auto
data
=
ConstBuffer
<
uint8_t
>::
FromVoid
(
decoder_buffer_need
(
buffer
,
8
));
if
(
data
.
IsNull
())
/* failed */
return
0
;
/* find the 0xff marker */
const
uint8_t
*
p
=
(
const
uint8_t
*
)
...
...
@@ -100,17 +95,10 @@ adts_find_frame(DecoderBuffer *buffer)
continue
;
}
if
(
data
.
size
<
frame_length
)
{
/* available buffer size is smaller than the
frame will be - attempt to read more
data */
if
(
!
decoder_buffer_fill
(
buffer
))
{
/* not enough data; discard this frame
to prevent a possible buffer
overflow */
decoder_buffer_clear
(
buffer
);
}
if
(
decoder_buffer_need
(
buffer
,
frame_length
).
IsNull
())
{
/* not enough data; discard this frame to
prevent a possible buffer overflow */
decoder_buffer_clear
(
buffer
);
continue
;
}
...
...
@@ -181,9 +169,8 @@ faad_song_duration(DecoderBuffer *buffer, InputStream &is)
const
auto
size
=
is
.
GetSize
();
const
size_t
fileread
=
size
>=
0
?
size
:
0
;
decoder_buffer_fill
(
buffer
);
auto
data
=
ConstBuffer
<
uint8_t
>::
FromVoid
(
decoder_buffer_read
(
buffer
));
if
(
data
.
IsEmpty
())
auto
data
=
ConstBuffer
<
uint8_t
>::
FromVoid
(
decoder_buffer_need
(
buffer
,
5
));
if
(
data
.
IsNull
())
return
-
1
;
size_t
tagsize
=
0
;
...
...
@@ -195,13 +182,11 @@ faad_song_duration(DecoderBuffer *buffer, InputStream &is)
tagsize
+=
10
;
const
bool
success
=
decoder_buffer_skip
(
buffer
,
tagsize
)
&&
decoder_buffer_fill
(
buffer
);
if
(
!
success
)
if
(
!
decoder_buffer_skip
(
buffer
,
tagsize
))
return
-
1
;
data
=
ConstBuffer
<
uint8_t
>::
FromVoid
(
decoder_buffer_
read
(
buffer
));
if
(
data
.
Is
Empty
())
data
=
ConstBuffer
<
uint8_t
>::
FromVoid
(
decoder_buffer_
need
(
buffer
,
5
));
if
(
data
.
Is
Null
())
return
-
1
;
}
...
...
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