Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
87ff61b9
Commit
87ff61b9
authored
Oct 14, 2015
by
Zhang Rui
Committed by
Michael Niedermayer
Oct 14, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avutil/fifo: add function av_fifo_generic_peek_at()
Signed-off-by:
Michael Niedermayer
<
michael@niedermayer.cc
>
parent
55d3e979
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
0 deletions
+99
-0
fifo.c
libavutil/fifo.c
+61
-0
fifo.h
libavutil/fifo.h
+11
-0
fifo
tests/ref/fate/fifo
+27
-0
No files found.
libavutil/fifo.c
View file @
87ff61b9
...
...
@@ -148,6 +148,44 @@ int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size,
return
total
-
size
;
}
int
av_fifo_generic_peek_at
(
AVFifoBuffer
*
f
,
void
*
dest
,
int
offset
,
int
buf_size
,
void
(
*
func
)(
void
*
,
void
*
,
int
))
{
uint8_t
*
rptr
=
f
->
rptr
;
av_assert2
(
offset
>=
0
);
/*
* *ndx are indexes modulo 2^32, they are intended to overflow,
* to handle *ndx greater than 4gb.
*/
av_assert2
(
buf_size
+
(
unsigned
)
offset
<=
f
->
wndx
-
f
->
rndx
);
if
(
offset
>=
f
->
end
-
rptr
)
rptr
+=
offset
-
(
f
->
end
-
f
->
buffer
);
else
rptr
+=
offset
;
while
(
buf_size
>
0
)
{
int
len
;
if
(
rptr
>=
f
->
end
)
rptr
-=
f
->
end
-
f
->
buffer
;
len
=
FFMIN
(
f
->
end
-
rptr
,
buf_size
);
if
(
func
)
func
(
dest
,
rptr
,
len
);
else
{
memcpy
(
dest
,
rptr
,
len
);
dest
=
(
uint8_t
*
)
dest
+
len
;
}
buf_size
-=
len
;
rptr
+=
len
;
}
return
0
;
}
int
av_fifo_generic_peek
(
AVFifoBuffer
*
f
,
void
*
dest
,
int
buf_size
,
void
(
*
func
)(
void
*
,
void
*
,
int
))
{
...
...
@@ -221,6 +259,14 @@ int main(void)
}
printf
(
"
\n
"
);
/* peek_at at FIFO */
n
=
av_fifo_size
(
fifo
)
/
sizeof
(
int
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
av_fifo_generic_peek_at
(
fifo
,
&
j
,
i
*
sizeof
(
int
),
sizeof
(
j
),
NULL
);
printf
(
"%d: %d
\n
"
,
i
,
j
);
}
printf
(
"
\n
"
);
/* read data */
for
(
i
=
0
;
av_fifo_size
(
fifo
)
>=
sizeof
(
int
);
i
++
)
{
av_fifo_generic_read
(
fifo
,
&
j
,
sizeof
(
int
),
NULL
);
...
...
@@ -228,6 +274,21 @@ int main(void)
}
printf
(
"
\n
"
);
/* test *ndx overflow */
av_fifo_reset
(
fifo
);
fifo
->
rndx
=
fifo
->
wndx
=
~
(
uint32_t
)
0
-
5
;
/* fill data */
for
(
i
=
0
;
av_fifo_space
(
fifo
)
>=
sizeof
(
int
);
i
++
)
av_fifo_generic_write
(
fifo
,
&
i
,
sizeof
(
int
),
NULL
);
/* peek_at at FIFO */
n
=
av_fifo_size
(
fifo
)
/
sizeof
(
int
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
av_fifo_generic_peek_at
(
fifo
,
&
j
,
i
*
sizeof
(
int
),
sizeof
(
j
),
NULL
);
printf
(
"%d: %d
\n
"
,
i
,
j
);
}
av_fifo_free
(
fifo
);
return
0
;
...
...
libavutil/fifo.h
View file @
87ff61b9
...
...
@@ -83,6 +83,17 @@ int av_fifo_size(const AVFifoBuffer *f);
*/
int
av_fifo_space
(
const
AVFifoBuffer
*
f
);
/**
* Feed data at specific position from an AVFifoBuffer to a user-supplied callback.
* Similar as av_fifo_gereric_read but without discarding data.
* @param f AVFifoBuffer to read from
* @param offset offset from current read position
* @param buf_size number of bytes to read
* @param func generic read function
* @param dest data destination
*/
int
av_fifo_generic_peek_at
(
AVFifoBuffer
*
f
,
void
*
dest
,
int
offset
,
int
buf_size
,
void
(
*
func
)(
void
*
,
void
*
,
int
));
/**
* Feed data from an AVFifoBuffer to a user-supplied callback.
* Similar as av_fifo_gereric_read but without discarding data.
...
...
tests/ref/fate/fifo
View file @
87ff61b9
...
...
@@ -24,4 +24,31 @@
11: 11
12: 12
0: 0
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
11: 11
12: 12
0 1 2 3 4 5 6 7 8 9 10 11 12
0: 0
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
11: 11
12: 12
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