Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
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
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
bd383806
Commit
bd383806
authored
7 years ago
by
Philippe Gorley
Committed by
Philippe Gorley
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
encoder: fix segfault if key isn't in dictionary
Change-Id: If32273538b24853b7aba236efd8db730faa5b954
parent
a3ad4e9f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/media/libav_utils.cpp
+10
-0
10 additions, 0 deletions
src/media/libav_utils.cpp
src/media/libav_utils.h
+3
-0
3 additions, 0 deletions
src/media/libav_utils.h
src/media/media_encoder.cpp
+6
-6
6 additions, 6 deletions
src/media/media_encoder.cpp
with
19 additions
and
6 deletions
src/media/libav_utils.cpp
+
10
−
0
View file @
bd383806
...
@@ -216,4 +216,14 @@ getError(int err)
...
@@ -216,4 +216,14 @@ getError(int err)
return
ret
;
return
ret
;
}
}
const
char
*
getDictValue
(
const
AVDictionary
*
d
,
const
std
::
string
&
key
,
int
flags
)
{
auto
kv
=
av_dict_get
(
d
,
key
.
c_str
(),
nullptr
,
flags
);
if
(
kv
)
return
kv
->
value
;
else
return
""
;
}
}}
// namespace ring::libav_utils
}}
// namespace ring::libav_utils
This diff is collapsed.
Click to expand it.
src/media/libav_utils.h
+
3
−
0
View file @
bd383806
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include
<map>
#include
<map>
#include
<string>
#include
<string>
struct
AVDictionary
;
struct
AVPixFmtDescriptor
;
struct
AVPixFmtDescriptor
;
namespace
ring
{
namespace
libav_utils
{
namespace
ring
{
namespace
libav_utils
{
...
@@ -44,4 +45,6 @@ namespace ring { namespace libav_utils {
...
@@ -44,4 +45,6 @@ namespace ring { namespace libav_utils {
std
::
string
getError
(
int
err
);
std
::
string
getError
(
int
err
);
const
char
*
getDictValue
(
const
AVDictionary
*
d
,
const
std
::
string
&
key
,
int
flags
=
0
);
}}
// namespace ring::libav_utils
}}
// namespace ring::libav_utils
This diff is collapsed.
Click to expand it.
src/media/media_encoder.cpp
+
6
−
6
View file @
bd383806
...
@@ -203,9 +203,9 @@ MediaEncoder::addStream(const SystemCodecInfo& systemCodecInfo, std::string para
...
@@ -203,9 +203,9 @@ MediaEncoder::addStream(const SystemCodecInfo& systemCodecInfo, std::string para
encoderCtx
=
prepareEncoderContext
(
outputCodec
,
systemCodecInfo
.
mediaType
==
MEDIA_VIDEO
);
encoderCtx
=
prepareEncoderContext
(
outputCodec
,
systemCodecInfo
.
mediaType
==
MEDIA_VIDEO
);
encoders_
.
push_back
(
encoderCtx
);
encoders_
.
push_back
(
encoderCtx
);
auto
maxBitrate
=
1000
*
atoi
(
av_dict_get
(
options_
,
"max_rate"
,
nullptr
,
0
)
->
value
);
auto
maxBitrate
=
1000
*
std
::
atoi
(
libav_utils
::
getDictValue
(
options_
,
"max_rate"
)
);
auto
bufSize
=
2
*
maxBitrate
;
// as recommended (TODO: make it customizable)
auto
bufSize
=
2
*
maxBitrate
;
// as recommended (TODO: make it customizable)
auto
crf
=
atoi
(
av_dict_get
(
options_
,
"crf"
,
nullptr
,
0
)
->
value
);
auto
crf
=
std
::
atoi
(
libav_utils
::
getDictValue
(
options_
,
"crf"
)
);
/* let x264 preset override our encoder settings */
/* let x264 preset override our encoder settings */
if
(
systemCodecInfo
.
avcodecId
==
AV_CODEC_ID_H264
)
{
if
(
systemCodecInfo
.
avcodecId
==
AV_CODEC_ID_H264
)
{
...
@@ -217,7 +217,7 @@ MediaEncoder::addStream(const SystemCodecInfo& systemCodecInfo, std::string para
...
@@ -217,7 +217,7 @@ MediaEncoder::addStream(const SystemCodecInfo& systemCodecInfo, std::string para
crf
=
30
;
// good value for H264-720p@30
crf
=
30
;
// good value for H264-720p@30
RING_DBG
(
"H264 encoder setup: crf=%u, maxrate=%u, bufsize=%u"
,
crf
,
maxBitrate
,
bufSize
);
RING_DBG
(
"H264 encoder setup: crf=%u, maxrate=%u, bufsize=%u"
,
crf
,
maxBitrate
,
bufSize
);
av_opt_set
(
encoderCtx
->
priv_data
,
"crf"
,
av_dict_get
(
options_
,
"crf"
,
nullptr
,
0
)
->
value
,
0
);
av_opt_set
_int
(
encoderCtx
->
priv_data
,
"crf"
,
crf
,
0
);
encoderCtx
->
rc_buffer_size
=
bufSize
;
encoderCtx
->
rc_buffer_size
=
bufSize
;
encoderCtx
->
rc_max_rate
=
maxBitrate
;
encoderCtx
->
rc_max_rate
=
maxBitrate
;
}
else
if
(
systemCodecInfo
.
avcodecId
==
AV_CODEC_ID_VP8
)
{
}
else
if
(
systemCodecInfo
.
avcodecId
==
AV_CODEC_ID_VP8
)
{
...
@@ -242,7 +242,7 @@ MediaEncoder::addStream(const SystemCodecInfo& systemCodecInfo, std::string para
...
@@ -242,7 +242,7 @@ MediaEncoder::addStream(const SystemCodecInfo& systemCodecInfo, std::string para
encoderCtx
->
rc_buffer_size
=
maxBitrate
;
encoderCtx
->
rc_buffer_size
=
maxBitrate
;
encoderCtx
->
bit_rate
=
maxBitrate
;
encoderCtx
->
bit_rate
=
maxBitrate
;
if
(
crf
!=
SystemCodecInfo
::
DEFAULT_NO_QUALITY
)
{
if
(
crf
!=
SystemCodecInfo
::
DEFAULT_NO_QUALITY
)
{
av_opt_set
(
encoderCtx
->
priv_data
,
"crf"
,
av_dict_get
(
options_
,
"crf"
,
nullptr
,
0
)
->
value
,
0
);
av_opt_set
_int
(
encoderCtx
->
priv_data
,
"crf"
,
crf
,
0
);
RING_DBG
(
"Using quality factor %d"
,
crf
);
RING_DBG
(
"Using quality factor %d"
,
crf
);
}
else
{
}
else
{
RING_DBG
(
"Using Max bitrate %d"
,
maxBitrate
);
RING_DBG
(
"Using Max bitrate %d"
,
maxBitrate
);
...
@@ -554,8 +554,8 @@ AVCodecContext* MediaEncoder::prepareEncoderContext(AVCodec* outputCodec, bool i
...
@@ -554,8 +554,8 @@ AVCodecContext* MediaEncoder::prepareEncoderContext(AVCodec* outputCodec, bool i
encoderCtx
->
width
=
device_
.
width
;
encoderCtx
->
width
=
device_
.
width
;
encoderCtx
->
height
=
device_
.
height
;
encoderCtx
->
height
=
device_
.
height
;
}
else
{
}
else
{
encoderCtx
->
width
=
atoi
(
av_dict_get
(
options_
,
"width"
,
nullptr
,
0
)
->
value
);
encoderCtx
->
width
=
std
::
atoi
(
libav_utils
::
getDictValue
(
options_
,
"width"
)
);
encoderCtx
->
height
=
atoi
(
av_dict_get
(
options_
,
"height"
,
nullptr
,
0
)
->
value
);
encoderCtx
->
height
=
std
::
atoi
(
libav_utils
::
getDictValue
(
options_
,
"height"
)
);
}
}
// satisfy ffmpeg: denominator must be 16bit or less value
// satisfy ffmpeg: denominator must be 16bit or less value
...
...
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