Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.protos
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.protos
Commits
6761d9b9
Commit
6761d9b9
authored
May 09, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
7f1f647b
Pipeline
#19327
failed with stages
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
198 additions
and
10 deletions
+198
-10
CMakeLists.txt
CMakeLists.txt
+7
-2
mm.c
src/MovMem/mm.c
+59
-3
mm.h
src/MovMem/mm.h
+32
-1
list.c
src/basic/container/list.c
+0
-0
list.h
src/basic/container/list.h
+0
-0
utils.h
src/basic/utils.h
+9
-0
proto.h
src/proto.h
+6
-3
listTestCases.c
tests/listTestCases.c
+1
-1
mmTestCases.c
tests/mmTestCases.c
+3
-0
protoTestCases.c
tests/protoTestCases.c
+81
-0
No files found.
CMakeLists.txt
View file @
6761d9b9
...
...
@@ -15,7 +15,7 @@ include_directories(${CMAKE_SOURCE_DIR}/src)
set
(
SRC_FILES
${
SRCs
}
/proto.c
${
SRCs
}
/basic/
list
/list.c
${
SRCs
}
/basic/
container
/list.c
${
SRCs
}
/MovMem/mm.c
)
if
(
STATICLIB
)
...
...
@@ -32,6 +32,7 @@ install(TARGETS ffmpegprotos
if
(
DEBUG
)
set
(
LIBAV libav
)
ExternalProject_Add
(
libav
GIT_REPOSITORY https://github.com/FFmpeg/FFmpeg.git
...
...
@@ -49,8 +50,10 @@ ExternalProject_Add(
# Tests
set
(
Tests
${
CMAKE_SOURCE_DIR
}
/tests
)
set
(
TestCases
${
SRCs
}
/basic/list/list.c
${
SRCs
}
/basic/container/list.c
${
SRCs
}
/proto.c
${
Tests
}
/main.c
${
Tests
}
/protoTestCases.c
${
Tests
}
/listTestCases.c
)
add_executable
(
unittest
${
TestCases
}
${
SRC_Files
}
)
add_dependencies
(
unittest libav
)
...
...
@@ -76,6 +79,8 @@ target_link_libraries(unittest
target_link_libraries
(
unittest z
)
target_link_libraries
(
unittest x264
)
target_link_libraries
(
unittest lzma
)
target_link_libraries
(
unittest m
)
target_link_libraries
(
unittest pthread
)
endif
()
src/MovMem/mm.c
View file @
6761d9b9
#include "mm.h"
#include "../basic/utils.h"
static
int
mmRead
(
void
*
priv
,
uint8_t
*
buf
,
int
size
)
{
return
0
;
}
MMProto
*
proto
=
priv
;
MemMovContext
*
context
=
mmContext
(
proto
);
List
*
buffers
=
mmprotoBuffer
(
proto
);
static
int
mmWrite
(
void
*
priv
,
uint8_t
*
buf
,
int
size
)
{
if
((
priv
==
NULL
||
buf
==
NULL
||
size
<
0
))
{
return
AVERROR
(
EINVAL
);
}
// No Datas
if
(
mmContextEmpty
(
context
)
&&
listEmpty
(
buffers
))
{
return
AVERROR
(
EAGAIN
);
}
if
(
mmContextEmpty
(
context
))
{
BufferInfo
*
info
=
listPop
(
buffers
);
assignBufferMMContext
(
context
,
info
->
buffer
,
info
->
size
);
}
if
(
mmContextIsEOF
(
context
))
{
return
AVERROR_EOF
;
}
int
sizeToRead
=
MIN
(
mmContextRemain
(
context
),
size
);
memcpy
(
buf
,
mmContextBuffer
(
context
),
sizeToRead
);
// Update MemMovContext
mmContextSetPos
(
context
,
mmContextPos
(
context
)
+
sizeToRead
);
mmContextSetRemain
(
context
,
mmContextRemain
(
context
)
-
sizeToRead
);
// Do cleanning
if
(
mmContextEmpty
(
context
))
resetMMContext
(
context
);
return
sizeToRead
==
0
?
AVERROR
(
EAGAIN
)
:
sizeToRead
;
}
static
int
mmWrite
(
void
*
priv
,
uint8_t
*
buf
,
int
size
)
{
fprintf
(
stderr
,
"MMProto not support for write
\n
"
);
abort
();
}
MMProto
*
createMMProto
(
void
)
{
MMProto
*
p
=
(
MMProto
*
)
malloc
(
sizeof
(
MMProto
));
memset
(
p
,
0
,
sizeof
(
MMProto
));
p
->
Base
=
createProto_
(
mmRead
,
mmWrite
,
NULL
,
p
);
setReadMethod
(
&
p
->
Base
,
mmRead
);
setWriteMethod
(
&
p
->
Base
,
NULL
);
setSeekMethod
(
&
p
->
Base
,
NULL
);
p
->
buffer
=
createList
();
return
p
;
}
void
assignBufferMMContext
(
MemMovContext
*
mmc
,
uint8_t
*
buffer
,
int
size
)
{
mmc
->
buffer
=
buffer
;
mmc
->
pos
=
buffer
;
mmc
->
remain
=
size
;
}
void
resetMMContext
(
MemMovContext
*
mm
)
{
free
(
mm
->
buffer
);
mm
->
buffer
=
NULL
;
mm
->
pos
=
NULL
;
mm
->
remain
=
0
;
}
src/MovMem/mm.h
View file @
6761d9b9
#include "../proto.h"
#include "basic/container/list.h"
#include <libavformat/avformat.h>
#ifndef MM_H
#define MM_H
typedef
struct
MemMovContext
{
uint8_t
*
buffer
;
uint8_t
*
pos
;
int
remain
;
}
MemMovContext
;
typedef
struct
BufferInfo
{
uint8_t
*
buffer
;
int
size
;
}
BufferInfo
;
typedef
struct
MMProto
{
Proto
Base
;
List
*
buffer
;
MemMovContext
context
;
}
MMProto
;
/* Member function implement as macros */
#define mmprotoBuffer(MM) ((MM)->buffer)
#define mmContext(MM) (&(MM)->context)
#define mmContextEmpty(MMC) ((MMC)->remain == 0)
#define mmContextIsEOF(MMC) ((MMC)->buffer == NULL)
#define mmContextRemain(MMC) ((MMC)->remain)
#define mmContextBuffer(MMC) ((MMC)->buffer)
#define mmContextPos(MMC) ((MMC)->pos)
#define mmContextSetPos(MMC, POS) ((MMC)->pos = (POS))
#define mmContextRemain(MMC) ((MMC)->remain)
#define mmContextSetRemain(MMC, REMAIN) ((MMC)->remain = (REMAIN))
/* Prototypes */
MMProto
*
createMMProto
(
void
);
void
pushMMProto
(
MMProto
*
mm
,
uint8_t
*
packets
);
uint8_t
*
popMMProto
(
MMProto
*
mm
);
void
assignBufferMMContext
(
MemMovContext
*
mm
,
uint8_t
*
buffer
,
int
size
);
void
resetMMContext
(
MemMovContext
*
mm
);
#endif
/* MM_H */
src/basic/
list
/list.c
→
src/basic/
container
/list.c
View file @
6761d9b9
File moved
src/basic/
list
/list.h
→
src/basic/
container
/list.h
View file @
6761d9b9
File moved
src/basic/utils.h
0 → 100644
View file @
6761d9b9
#include <stdio.h>
#ifndef UTILS_H
#define UTILS_H
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
#endif
/* UTILS_H */
src/proto.h
View file @
6761d9b9
...
...
@@ -17,9 +17,12 @@ typedef struct Proto {
}
Proto
;
/* Member function implement as macros */
#define read(P, priv, buf, size) ((P)->read((priv), (buf), (size)))
#define write(P, priv, buf, size) ((P)->write((priv), (buf), (size)))
#define seek(P, opaque, offset, whence) ((P)->seek((opaque), (offset), (whence)))
#define setReadMethod(P, R) ((P)->read = (R))
#define setWriteMethod(P, W) ((P)->write = (W))
#define setSeekMethod(P, S) ((P)->seek = (S))
#define read(P, buf, size) ((P)->read((P)->priv, (buf), (size)))
#define write(P, buf, size) ((P)->write((P)->priv, (buf), (size)))
#define seek(P, offset, whence) ((P)->seek((P)->priv, (offset), (whence)))
/* Prototypes */
Proto
*
createProto
(
ReadFunc
rf
,
WriteFunc
wr
,
SeekFunc
sf
,
void
*
priv
);
...
...
tests/listTestCases.c
View file @
6761d9b9
#include "ctest.h"
#include "basic/
list
/list.h"
#include "basic/
container
/list.h"
#include <malloc.h>
...
...
tests/mmTestCases.c
View file @
6761d9b9
#include "ctest.h"
#include "MovMem/mm.h"
#include "basic/container/list.h"
tests/protoTestCases.c
0 → 100644
View file @
6761d9b9
#include "ctest.h"
#include "proto.h"
#include "basic/utils.h"
#include "basic/container/list.h"
/*****************************************************************************/
/* Helper Functions */
/*****************************************************************************/
typedef
struct
CONT
{
uint8_t
*
buf
;
int
size
;
}
CONT
;
static
int
readFake
(
void
*
priv
,
uint8_t
*
buf
,
int
size
)
{
List
*
l
=
priv
;
CONT
*
c
=
listPop
(
l
);
int
sizeToRead
=
MIN
(
c
->
size
,
size
);
memcpy
(
buf
,
c
->
buf
,
sizeToRead
);
free
(
c
->
buf
);
free
(
c
);
return
sizeToRead
;
}
static
int
writeFake
(
void
*
priv
,
uint8_t
*
buf
,
int
size
)
{
uint8_t
*
mem
=
(
uint8_t
*
)
malloc
(
size
);
memcpy
(
mem
,
buf
,
size
);
CONT
*
c
=
(
CONT
*
)
malloc
(
sizeof
(
CONT
));
c
->
buf
=
mem
;
c
->
size
=
size
;
listPush
((
List
*
)
priv
,
c
);
return
size
;
}
static
int64_t
seekFake
(
void
*
opaque
,
int64_t
offset
,
int
whence
)
{
return
0
;
}
CTEST_DATA
(
PROTO_TEST
)
{
Proto
*
proto
;
List
*
datas
;
};
CTEST_SETUP
(
PROTO_TEST
)
{
data
->
datas
=
createList
();
data
->
proto
=
createProto
(
readFake
,
writeFake
,
seekFake
,
data
->
datas
);
}
CTEST2
(
PROTO_TEST
,
READ_WRITE
)
{
uint8_t
*
rBuf
,
*
wBuf
;
rBuf
=
(
uint8_t
*
)
malloc
(
1024
);
memset
(
rBuf
,
0
,
1024
);
wBuf
=
(
uint8_t
*
)
malloc
(
1024
);
memset
(
wBuf
,
0
,
1024
);
for
(
int
i
=
0
;
i
<
256
;
i
++
)
{
wBuf
[
i
]
=
i
;
write
(
data
->
proto
,
wBuf
,
1024
);
wBuf
[
i
]
=
0
;
}
for
(
int
i
=
0
;
i
<
256
;
i
++
)
{
read
(
data
->
proto
,
rBuf
,
1024
);
ASSERT_EQUAL
(
rBuf
[
i
],
i
);
rBuf
[
i
]
=
0
;
}
}
CTEST2
(
PROTO_TEST
,
SEEK
)
{
}
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