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
33b921e8
Commit
33b921e8
authored
May 07, 2022
by
Linshizhi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.ilaihua.com:linshizhi/ffmpeg.sharedmemoryproto
parents
247664af
14e8b4f7
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
6 deletions
+36
-6
movMemProto.cc
src/proto/movMemProto.cc
+2
-0
movMemProto.h
src/proto/movMemProto.h
+7
-1
utils.cc
src/utils.cc
+26
-4
ioctxTestCases.cc
tests/ioctxTestCases.cc
+1
-1
No files found.
src/proto/movMemProto.cc
View file @
33b921e8
...
@@ -38,6 +38,7 @@ int MovMemProto::read_packet_internal(void *priv, uint8_t *buf, int bufSize) {
...
@@ -38,6 +38,7 @@ int MovMemProto::read_packet_internal(void *priv, uint8_t *buf, int bufSize) {
// Update TransContext
// Update TransContext
trans
.
pos
+=
sizeToRead
;
trans
.
pos
+=
sizeToRead
;
trans
.
remain
-=
sizeToRead
;
trans
.
remain
-=
sizeToRead
;
sizeOfBuffer
-=
sizeToRead
;
// Datas of current memory piece is all
// Datas of current memory piece is all
// readed, do cleaning.
// readed, do cleaning.
...
@@ -64,6 +65,7 @@ void MovMemProto::close_internal() {
...
@@ -64,6 +65,7 @@ void MovMemProto::close_internal() {
while
(
!
s
.
empty
())
{
while
(
!
s
.
empty
())
{
auto
mem
=
s
.
front
();
auto
mem
=
s
.
front
();
mem
.
data
=
nullptr
;
s
.
pop
();
s
.
pop
();
}
}
}
}
...
...
src/proto/movMemProto.h
View file @
33b921e8
...
@@ -28,7 +28,7 @@ public:
...
@@ -28,7 +28,7 @@ public:
static
constexpr
char
protoName
[]
=
"MovMemProto"
;
static
constexpr
char
protoName
[]
=
"MovMemProto"
;
MovMemProto
(
void
*
priv
,
RW_FLAG
flag
)
:
MovMemProto
(
void
*
priv
,
RW_FLAG
flag
)
:
IOProtocol
(
protoName
,
flag
,
priv
)
{}
IOProtocol
(
protoName
,
flag
,
priv
)
,
sizeOfBuffer
(
0
)
{}
int
read_packet_internal
(
void
*
priv
,
uint8_t
*
buf
,
int
bufSize
);
int
read_packet_internal
(
void
*
priv
,
uint8_t
*
buf
,
int
bufSize
);
...
@@ -42,15 +42,21 @@ public:
...
@@ -42,15 +42,21 @@ public:
void
push
(
uint8_t
data
[],
size_t
size
)
{
void
push
(
uint8_t
data
[],
size_t
size
)
{
s
.
push
(
MemPiece
{
std
::
shared_ptr
<
uint8_t
[]
>
(
data
),
size
});
s
.
push
(
MemPiece
{
std
::
shared_ptr
<
uint8_t
[]
>
(
data
),
size
});
sizeOfBuffer
+=
size
;
}
}
void
eof
()
{
void
eof
()
{
s
.
push
(
MemPiece
{
nullptr
,
0
});
s
.
push
(
MemPiece
{
nullptr
,
0
});
}
}
size_t
size
()
const
{
return
sizeOfBuffer
;
}
private
:
private
:
Stream
s
;
Stream
s
;
TransContext
trans
;
TransContext
trans
;
size_t
sizeOfBuffer
;
};
};
}}
}}
...
...
src/utils.cc
View file @
33b921e8
...
@@ -3,22 +3,38 @@
...
@@ -3,22 +3,38 @@
namespace
Utils
{
namespace
Utils
{
static
void
close_input_file
(
AVFormatContext
**
ctx_ptr
)
{
int
i
;
AVFormatContext
*
fmt_ctx
=
*
ctx_ptr
;
/* close decoder for each stream */
for
(
i
=
0
;
i
<
fmt_ctx
->
nb_streams
;
i
++
)
{
AVStream
*
stream
=
fmt_ctx
->
streams
[
i
];
avcodec_close
(
stream
->
codec
);
}
avformat_close_input
(
ctx_ptr
);
}
static
AVFormatContext
*
AVFormatInputContextConstructor
(
static
AVFormatContext
*
AVFormatInputContextConstructor
(
std
::
string
path
,
AVIOContext
*
customIO
)
{
std
::
string
path
,
AVIOContext
*
customIO
)
{
const
char
*
filename
=
path
.
c_str
();
AVFormatContext
*
ctx
=
nullptr
;
AVFormatContext
*
ctx
=
nullptr
;
if
(
customIO
!=
nullptr
)
{
if
(
customIO
!=
nullptr
)
{
ctx
=
avformat_alloc_context
();
ctx
=
avformat_alloc_context
();
ctx
->
pb
=
customIO
;
ctx
->
pb
=
customIO
;
filename
=
nullptr
;
}
}
if
(
avformat_open_input
(
&
ctx
,
path
.
c_str
()
,
nullptr
,
nullptr
)
<
0
)
{
if
(
avformat_open_input
(
&
ctx
,
filename
,
nullptr
,
nullptr
)
<
0
)
{
return
nullptr
;
return
nullptr
;
}
}
if
(
avformat_find_stream_info
(
ctx
,
nullptr
)
<
0
)
{
if
(
avformat_find_stream_info
(
ctx
,
nullptr
)
<
0
)
{
avformat_close_input
(
&
ctx
);
close_input_file
(
&
ctx
);
return
nullptr
;
return
nullptr
;
}
}
...
@@ -26,7 +42,9 @@ static AVFormatContext* AVFormatInputContextConstructor(
...
@@ -26,7 +42,9 @@ static AVFormatContext* AVFormatInputContextConstructor(
}
}
static
void
AVFormatInputContextDestructor
(
AVFormatContext
*
ctx
)
{
static
void
AVFormatInputContextDestructor
(
AVFormatContext
*
ctx
)
{
if
(
ctx
!=
nullptr
)
{
avformat_close_input
(
&
ctx
);
avformat_close_input
(
&
ctx
);
}
}
}
AVFormatContextShared
makeInAVFormat
(
std
::
string
path
,
AVIOContext
*
customIO
)
{
AVFormatContextShared
makeInAVFormat
(
std
::
string
path
,
AVIOContext
*
customIO
)
{
...
@@ -57,7 +75,11 @@ static AVFormatContext* AVFormatOutputContextConstructor(
...
@@ -57,7 +75,11 @@ static AVFormatContext* AVFormatOutputContextConstructor(
}
}
static
void
AVFormatOutputContextDestructor
(
AVFormatContext
*
ctx
)
{
static
void
AVFormatOutputContextDestructor
(
AVFormatContext
*
ctx
)
{
avformat_close_input
(
&
ctx
);
if
(
ctx
!=
nullptr
)
{
if
(
ctx
->
pb
&&
strnlen
(
ctx
->
filename
,
1024
)
>
0
)
avio_close
(
ctx
->
pb
);
avformat_free_context
(
ctx
);
}
}
}
AVFormatContextShared
makeOutAVFormat
(
AVFormatContextShared
makeOutAVFormat
(
...
...
tests/ioctxTestCases.cc
View file @
33b921e8
...
@@ -373,7 +373,7 @@ TEST_F(IOCTX_With_MovMem_Proto_Fixture, Initialize) {
...
@@ -373,7 +373,7 @@ TEST_F(IOCTX_With_MovMem_Proto_Fixture, Initialize) {
t1
.
detach
();
t1
.
detach
();
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
1
00
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
5
00
));
inCtxMM
=
new
IOCtx
::
InCtx
(
""
,
mmProto
);
inCtxMM
=
new
IOCtx
::
InCtx
(
""
,
mmProto
);
AVStream
*
s
=
inCtxMM
->
getStream
([](
AVStream
*
s
)
{
AVStream
*
s
=
inCtxMM
->
getStream
([](
AVStream
*
s
)
{
...
...
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