Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.WithCustomProto
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.WithCustomProto
Commits
2c730355
Commit
2c730355
authored
Apr 29, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add MovMem Protocol.
parent
22f6a543
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
2 deletions
+126
-2
movMemProto.cc
src/proto/movMemProto.cc
+70
-0
movMemProto.h
src/proto/movMemProto.h
+54
-0
ioctxTestCases.cc
tests/ioctxTestCases.cc
+2
-2
No files found.
src/proto/movMemProto.cc
0 → 100644
View file @
2c730355
#include "movMemProto.h"
#include <algorithm>
#include <stdexcept>
namespace
IOProto
{
namespace
MovMemProto
{
int
MovMemProto
::
read_packet_internal
(
void
*
priv
,
uint8_t
*
buf
,
int
bufSize
)
{
if
(
flag
==
write
||
bufSize
<
0
||
buf
==
nullptr
)
{
return
AVERROR
(
EINVAL
);
}
// No Datas
if
(
trans
.
mem
.
data
==
nullptr
&&
s
.
empty
())
{
return
AVERROR
(
EAGAIN
);
}
if
(
trans
.
mem
.
data
==
nullptr
)
{
trans
.
mem
=
s
.
front
();
// EOF arrive
if
(
trans
.
mem
.
data
==
nullptr
)
{
return
AVERROR_EOF
;
}
trans
.
pos
=
trans
.
mem
.
data
.
get
();
trans
.
remain
=
trans
.
mem
.
size
;
s
.
pop
();
}
size_t
sizeToRead
=
std
::
min
((
size_t
)
bufSize
,
trans
.
remain
);
memcpy
(
buf
,
trans
.
pos
,
sizeToRead
);
// Update TransContext
trans
.
pos
+=
sizeToRead
;
trans
.
remain
-=
sizeToRead
;
// Datas of current memory piece is all
// readed, do cleaning.
if
(
trans
.
remain
==
0
)
{
trans
.
mem
.
data
=
nullptr
;
trans
.
pos
=
nullptr
;
trans
.
remain
=
0
;
}
return
sizeToRead
;
}
int
MovMemProto
::
write_packet_internal
(
void
*
priv
,
uint8_t
*
buf
,
int
bufSize
)
{
throw
std
::
runtime_error
(
"MovMemProto not support write"
);
}
int64_t
MovMemProto
::
seek_packet_internal
(
void
*
opaque
,
int64_t
offset
,
int
whence
)
{
throw
std
::
runtime_error
(
"MovMemProto not support seek"
);
}
void
MovMemProto
::
close_internal
()
{
trans
.
mem
.
data
=
nullptr
;
while
(
!
s
.
empty
())
{
auto
mem
=
s
.
front
();
s
.
pop
();
}
}
}
}
src/proto/movMemProto.h
0 → 100644
View file @
2c730355
#include "proto.h"
#include <memory>
#include <queue>
#ifndef MOVMEMPROTO_H
#define MOVMEMPROTO_H
namespace
IOProto
{
namespace
MovMemProto
{
struct
PacketMem
{
std
::
shared_ptr
<
uint8_t
>
data
;
size_t
size
;
};
using
MemPiece
=
PacketMem
;
using
Stream
=
std
::
queue
<
MemPiece
>
;
struct
TransContext
{
MemPiece
mem
;
uint8_t
*
pos
;
size_t
remain
;
};
class
MovMemProto
:
public
IOProtocol
<
MovMemProto
>
{
public
:
static
constexpr
char
protoName
[]
=
"MovMemProto"
;
MovMemProto
(
void
*
priv
,
RW_FLAG
flag
)
:
IOProtocol
(
protoName
,
flag
,
priv
)
{}
int
read_packet_internal
(
void
*
priv
,
uint8_t
*
buf
,
int
bufSize
);
int
write_packet_internal
(
void
*
priv
,
uint8_t
*
buf
,
int
bufSize
);
/* MovMemProto temporarily only support Stream so seek function
* is ignored. */
int64_t
seek_packet_internal
(
void
*
opaque
,
int64_t
offset
,
int
whence
);
void
close_internal
();
void
push
(
MemPiece
data
)
{
s
.
push
(
data
);
}
private
:
Stream
s
;
TransContext
trans
;
};
}}
#endif
/* MOVMEMPROTO_H */
tests/ioctxTestCases.cc
View file @
2c730355
...
...
@@ -27,8 +27,8 @@ protected:
}
void
TearDown
()
override
{
//
std::string cmd = "rm -f " + outFilePath;
//
system(cmd.c_str());
std
::
string
cmd
=
"rm -f "
+
outFilePath
;
system
(
cmd
.
c_str
());
}
std
::
string
inFilePath
=
"./resources/small_bunny_1080p_60fps.mp4"
;
...
...
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