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
a68e52c2
Commit
a68e52c2
authored
Sep 21, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DecoderBuffer: use class DynamicFifoBuffer
parent
ea37b897
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
69 deletions
+23
-69
DecoderBuffer.cxx
src/decoder/DecoderBuffer.cxx
+23
-69
No files found.
src/decoder/DecoderBuffer.cxx
View file @
a68e52c2
...
...
@@ -21,33 +21,19 @@
#include "DecoderBuffer.hxx"
#include "DecoderAPI.hxx"
#include "util/ConstBuffer.hxx"
#include "util/
VarSize
.hxx"
#include "util/
DynamicFifoBuffer
.hxx"
#include <assert.h>
#include <string.h>
#include <stdlib.h>
struct
DecoderBuffer
{
Decoder
*
decoder
;
InputStream
*
is
;
/** the allocated size of the buffer */
size_t
size
;
/** the current length of the buffer */
size_t
length
;
/** number of bytes already consumed at the beginning of the
buffer */
size_t
consumed
;
/** the actual buffer (dynamic size) */
unsigned
char
data
[
sizeof
(
size_t
)];
DynamicFifoBuffer
<
uint8_t
>
buffer
;
DecoderBuffer
(
Decoder
*
_decoder
,
InputStream
&
_is
,
size_t
_size
)
:
decoder
(
_decoder
),
is
(
&
_is
),
size
(
_size
),
length
(
0
),
consumed
(
0
)
{}
:
decoder
(
_decoder
),
is
(
&
_is
),
buffer
(
_size
)
{}
};
DecoderBuffer
*
...
...
@@ -56,9 +42,7 @@ decoder_buffer_new(Decoder *decoder, InputStream &is,
{
assert
(
size
>
0
);
return
NewVarSize
<
DecoderBuffer
>
(
sizeof
(
DecoderBuffer
::
data
),
size
,
decoder
,
is
,
size
);
return
new
DecoderBuffer
(
decoder
,
is
,
size
);
}
void
...
...
@@ -66,7 +50,7 @@ decoder_buffer_free(DecoderBuffer *buffer)
{
assert
(
buffer
!=
nullptr
);
DeleteVarSize
(
buffer
)
;
delete
buffer
;
}
const
InputStream
&
...
...
@@ -78,73 +62,48 @@ decoder_buffer_get_stream(const DecoderBuffer *buffer)
void
decoder_buffer_clear
(
DecoderBuffer
*
buffer
)
{
buffer
->
length
=
buffer
->
consumed
=
0
;
}
static
void
decoder_buffer_shift
(
DecoderBuffer
*
buffer
)
{
assert
(
buffer
->
consumed
>
0
);
buffer
->
length
-=
buffer
->
consumed
;
memmove
(
buffer
->
data
,
buffer
->
data
+
buffer
->
consumed
,
buffer
->
length
);
buffer
->
consumed
=
0
;
buffer
->
buffer
.
Clear
();
}
bool
decoder_buffer_fill
(
DecoderBuffer
*
buffer
)
{
size_t
nbytes
;
if
(
buffer
->
consumed
>
0
)
decoder_buffer_shift
(
buffer
);
if
(
buffer
->
length
>=
buffer
->
size
)
auto
w
=
buffer
->
buffer
.
Write
();
if
(
w
.
IsEmpty
())
/* buffer is full */
return
false
;
nbytes
=
decoder_read
(
buffer
->
decoder
,
*
buffer
->
is
,
buffer
->
data
+
buffer
->
length
,
buffer
->
size
-
buffer
->
length
);
size_t
nbytes
=
decoder_read
(
buffer
->
decoder
,
*
buffer
->
is
,
w
.
data
,
w
.
size
);
if
(
nbytes
==
0
)
/* end of file, I/O error or decoder command
received */
return
false
;
buffer
->
length
+=
nbytes
;
assert
(
buffer
->
length
<=
buffer
->
size
);
buffer
->
buffer
.
Append
(
nbytes
);
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
->
buffer
.
GetAvailable
()
;
}
ConstBuffer
<
void
>
decoder_buffer_read
(
const
DecoderBuffer
*
buffer
)
{
return
{
decoder_buffer_head
(
buffer
),
decoder_buffer_available
(
buffer
),
};
auto
r
=
buffer
->
buffer
.
Read
();
return
{
r
.
data
,
r
.
size
};
}
ConstBuffer
<
void
>
decoder_buffer_need
(
DecoderBuffer
*
buffer
,
size_t
min_size
)
{
while
(
true
)
{
const
auto
available
=
decoder_buffer_available
(
buffer
);
if
(
availabl
e
>=
min_size
)
return
{
decoder_buffer_head
(
buffer
),
available
}
;
const
auto
r
=
decoder_buffer_read
(
buffer
);
if
(
r
.
siz
e
>=
min_size
)
return
r
;
if
(
!
decoder_buffer_fill
(
buffer
))
return
nullptr
;
...
...
@@ -154,25 +113,20 @@ decoder_buffer_need(DecoderBuffer *buffer, size_t min_size)
void
decoder_buffer_consume
(
DecoderBuffer
*
buffer
,
size_t
nbytes
)
{
/* just move the "consumed" pointer - decoder_buffer_shift()
will do the real work later (called by
decoder_buffer_fill()) */
buffer
->
consumed
+=
nbytes
;
assert
(
buffer
->
consumed
<=
buffer
->
length
);
buffer
->
buffer
.
Consume
(
nbytes
);
}
bool
decoder_buffer_skip
(
DecoderBuffer
*
buffer
,
size_t
nbytes
)
{
const
size_t
available
=
decoder_buffer_available
(
buffer
);
if
(
availabl
e
>=
nbytes
)
{
decoder_buffer_consume
(
buffer
,
nbytes
);
const
auto
r
=
buffer
->
buffer
.
Read
(
);
if
(
r
.
siz
e
>=
nbytes
)
{
buffer
->
buffer
.
Consume
(
nbytes
);
return
true
;
}
decoder_buffer_clear
(
buffer
);
nbytes
-=
availabl
e
;
buffer
->
buffer
.
Clear
(
);
nbytes
-=
r
.
siz
e
;
return
decoder_skip
(
buffer
->
decoder
,
*
buffer
->
is
,
nbytes
);
}
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