Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jami-libclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
savoirfairelinux
jami-libclient
Commits
96a01310
Commit
96a01310
authored
10 years ago
by
Guillaume Roguez
Browse files
Options
Downloads
Patches
Plain Diff
video: decrease renderer overhead
Refs #70057
parent
e7793429
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/private/shmrenderer.cpp
+43
-40
43 additions, 40 deletions
src/private/shmrenderer.cpp
src/private/shmrenderer.h
+0
-1
0 additions, 1 deletion
src/private/shmrenderer.h
with
43 additions
and
41 deletions
src/private/shmrenderer.cpp
+
43
−
40
View file @
96a01310
...
...
@@ -77,7 +77,7 @@ public:
//Attributes
QString
m_ShmPath
;
int
fd
;
int
m_
fd
;
SHMHeader
*
m_pShmArea
;
unsigned
m_ShmAreaLen
;
uint
m_BufferGen
;
...
...
@@ -99,6 +99,7 @@ public:
bool
shmLock
();
void
shmUnlock
();
bool
renderToBitmap
();
bool
resizeShm
();
private:
Video
::
ShmRenderer
*
q_ptr
;
...
...
@@ -110,7 +111,7 @@ private Q_SLOTS:
}
Video
::
ShmRendererPrivate
::
ShmRendererPrivate
(
Video
::
ShmRenderer
*
parent
)
:
QObject
(
parent
),
q_ptr
(
parent
),
fd
(
-
1
),
m_fpsC
(
0
),
m_Fps
(
0
),
m_
fd
(
-
1
),
m_fpsC
(
0
),
m_Fps
(
0
),
m_pShmArea
((
SHMHeader
*
)
MAP_FAILED
),
m_ShmAreaLen
(
0
),
m_BufferGen
(
0
),
m_pTimer
(
nullptr
)
#ifdef DEBUG_FPS
...
...
@@ -134,12 +135,15 @@ Video::ShmRenderer::~ShmRenderer()
}
///Get the data from shared memory and transform it into a QByteArray
bool
Video
::
ShmRendererPrivate
::
renderToBitmap
()
bool
Video
::
ShmRendererPrivate
::
renderToBitmap
()
{
QMutexLocker
locker
{
q_ptr
->
mutex
()};
#ifdef Q_OS_LINUX
if
(
!
q_ptr
->
isRendering
())
auto
&
renderer
=
static_cast
<
Video
::
Renderer
*>
(
q_ptr
)
->
d_ptr
;
auto
&
frame
=
renderer
->
otherFrame
();
if
(
frame
.
isEmpty
())
return
false
;
if
(
!
shmLock
())
...
...
@@ -161,13 +165,11 @@ bool Video::ShmRendererPrivate::renderToBitmap()
if
(
not
m_pShmArea
->
frameSize
)
return
false
;
if
(
!
q_ptr
->
resizeShm
())
{
if
(
!
resizeShm
())
{
qDebug
()
<<
"Could not resize shared memory"
;
return
false
;
}
auto
&
renderer
=
static_cast
<
Video
::
Renderer
*>
(
q_ptr
)
->
d_ptr
;
auto
&
frame
=
renderer
->
otherFrame
();
if
((
unsigned
)
frame
.
size
()
!=
m_pShmArea
->
frameSize
)
frame
.
resize
(
m_pShmArea
->
frameSize
);
std
::
copy_n
(
m_pShmArea
->
data
+
m_pShmArea
->
readOffset
,
m_pShmArea
->
frameSize
,
frame
.
data
());
...
...
@@ -192,16 +194,42 @@ bool Video::ShmRendererPrivate::renderToBitmap()
#endif
}
///Resize the shared memory
bool
Video
::
ShmRendererPrivate
::
resizeShm
()
{
const
auto
areaSize
=
sizeof
(
SHMHeader
)
+
2
*
m_pShmArea
->
frameSize
+
15
;
if
(
m_ShmAreaLen
==
areaSize
)
return
true
;
shmUnlock
();
if
(
::
munmap
(
m_pShmArea
,
m_ShmAreaLen
))
{
qDebug
()
<<
"Could not unmap shared area:"
<<
strerror
(
errno
);
return
false
;
}
m_pShmArea
=
(
SHMHeader
*
)
::
mmap
(
nullptr
,
areaSize
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
m_fd
,
0
);
if
(
m_pShmArea
==
MAP_FAILED
)
{
qDebug
()
<<
"Could not remap shared area"
;
return
false
;
}
m_ShmAreaLen
=
areaSize
;
return
shmLock
();
}
///Connect to the shared memory
bool
Video
::
ShmRenderer
::
startShm
()
{
if
(
d_ptr
->
fd
!=
-
1
)
{
if
(
d_ptr
->
m_
fd
!=
-
1
)
{
qDebug
()
<<
"fd must be -1"
;
return
false
;
}
d_ptr
->
fd
=
::
shm_open
(
d_ptr
->
m_ShmPath
.
toLatin1
(),
O_RDWR
,
0
);
if
(
d_ptr
->
fd
<
0
)
{
d_ptr
->
m_
fd
=
::
shm_open
(
d_ptr
->
m_ShmPath
.
toLatin1
(),
O_RDWR
,
0
);
if
(
d_ptr
->
m_
fd
<
0
)
{
qDebug
()
<<
"could not open shm area "
<<
d_ptr
->
m_ShmPath
<<
", shm_open failed:"
<<
strerror
(
errno
);
return
false
;
...
...
@@ -210,7 +238,7 @@ bool Video::ShmRenderer::startShm()
const
auto
areaSize
=
sizeof
(
SHMHeader
);
d_ptr
->
m_pShmArea
=
(
SHMHeader
*
)
::
mmap
(
nullptr
,
areaSize
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
d_ptr
->
fd
,
0
);
MAP_SHARED
,
d_ptr
->
m_
fd
,
0
);
if
(
d_ptr
->
m_pShmArea
==
MAP_FAILED
)
{
qDebug
()
<<
"Could not remap shared area"
;
return
false
;
...
...
@@ -225,11 +253,11 @@ bool Video::ShmRenderer::startShm()
///Disconnect from the shared memory
void
Video
::
ShmRenderer
::
stopShm
()
{
if
(
d_ptr
->
fd
<
0
)
if
(
d_ptr
->
m_
fd
<
0
)
return
;
::
close
(
d_ptr
->
fd
);
d_ptr
->
fd
=
-
1
;
::
close
(
d_ptr
->
m_
fd
);
d_ptr
->
m_
fd
=
-
1
;
if
(
d_ptr
->
m_pShmArea
==
MAP_FAILED
)
return
;
...
...
@@ -239,31 +267,6 @@ void Video::ShmRenderer::stopShm()
d_ptr
->
m_pShmArea
=
(
SHMHeader
*
)
MAP_FAILED
;
}
///Resize the shared memory
bool
Video
::
ShmRenderer
::
resizeShm
()
{
const
auto
areaSize
=
sizeof
(
SHMHeader
)
+
2
*
d_ptr
->
m_pShmArea
->
frameSize
+
15
;
if
(
d_ptr
->
m_ShmAreaLen
==
areaSize
)
return
true
;
d_ptr
->
shmUnlock
();
if
(
::
munmap
(
d_ptr
->
m_pShmArea
,
d_ptr
->
m_ShmAreaLen
))
{
qDebug
()
<<
"Could not unmap shared area:"
<<
strerror
(
errno
);
return
false
;
}
d_ptr
->
m_pShmArea
=
(
SHMHeader
*
)
::
mmap
(
nullptr
,
areaSize
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
d_ptr
->
fd
,
0
);
if
(
d_ptr
->
m_pShmArea
==
MAP_FAILED
)
{
qDebug
()
<<
"Could not remap shared area"
;
return
false
;
}
d_ptr
->
m_ShmAreaLen
=
areaSize
;
return
d_ptr
->
shmLock
();
}
///Lock the memory while the copy is being made
bool
Video
::
ShmRendererPrivate
::
shmLock
()
{
...
...
@@ -301,7 +304,7 @@ void Video::ShmRendererPrivate::timedEvents()
}
m_fpsC
++
;
emit
q_ptr
->
frameUpdated
();
//
emit q_ptr->frameUpdated();
}
/*else {
qDebug() << "Frame dropped";
...
...
This diff is collapsed.
Click to expand it.
src/private/shmrenderer.h
+
0
−
1
View file @
96a01310
...
...
@@ -48,7 +48,6 @@ class LIB_EXPORT ShmRenderer : public Renderer {
virtual
~
ShmRenderer
();
//Mutators
bool
resizeShm
();
void
stopShm
();
bool
startShm
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment