Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
c06ba2ca
提交
c06ba2ca
authored
10月 01, 2018
作者:
Seven Du
提交者:
Andrey Volk
7月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-11425 parse codec specific profiles
上级
bd34650f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
96 行增加
和
21 行删除
+96
-21
avcodec.c
src/mod/applications/mod_av/avcodec.c
+96
-21
没有找到文件。
src/mod/applications/mod_av/avcodec.c
浏览文件 @
c06ba2ca
...
...
@@ -413,6 +413,7 @@ typedef struct avcodec_profile_s {
int
decoder_thread_count
;
AVCodecContext
ctx
;
switch_event_t
*
options
;
switch_event_t
*
codecs
;
}
avcodec_profile_t
;
struct
avcodec_globals
{
...
...
@@ -440,6 +441,36 @@ const char *get_profile_name(int codec_id)
return
"NONE"
;
}
static
void
parse_profile
(
avcodec_profile_t
*
aprofile
,
switch_xml_t
profile
);
static
void
parse_codec_specific_profile
(
avcodec_profile_t
*
aprofile
,
const
char
*
codec_name
)
{
switch_xml_t
cfg
=
NULL
;
switch_xml_t
xml
=
switch_xml_open_cfg
(
"avcodec.conf"
,
&
cfg
,
NULL
);
switch_xml_t
profiles
=
cfg
?
switch_xml_child
(
cfg
,
"profiles"
)
:
NULL
;
// open config and find the profile to parse
if
(
profiles
)
{
switch_event_header_t
*
hp
;
for
(
hp
=
aprofile
->
codecs
->
headers
;
hp
;
hp
=
hp
->
next
)
{
// switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s: %s\n", hp->name, hp->value);
if
(
!
strcmp
(
hp
->
name
,
codec_name
))
{
switch_xml_t
profile
;
for
(
profile
=
switch_xml_child
(
profiles
,
"profile"
);
profile
;
profile
=
profile
->
next
)
{
const
char
*
name
=
switch_xml_attr
(
profile
,
"name"
);
if
(
!
strcmp
(
hp
->
value
,
name
))
{
parse_profile
(
aprofile
,
profile
);
}
}
}
}
}
if
(
xml
)
switch_xml_free
(
xml
);
}
static
void
init_profile
(
avcodec_profile_t
*
aprofile
,
const
char
*
name
);
static
avcodec_profile_t
*
find_profile
(
const
char
*
name
,
switch_bool_t
reconfig
)
...
...
@@ -1183,7 +1214,7 @@ static void set_h264_private_data(h264_codec_context_t *context, avcodec_profile
static
switch_status_t
open_encoder
(
h264_codec_context_t
*
context
,
uint32_t
width
,
uint32_t
height
)
{
int
fps
=
15
;
avcodec_profile_t
*
profile
=
NULL
;
avcodec_profile_t
*
a
profile
=
NULL
;
char
codec_string
[
1024
];
if
(
!
context
->
encoder
)
{
...
...
@@ -1212,16 +1243,20 @@ static switch_status_t open_encoder(h264_codec_context_t *context, uint32_t widt
}
if
(
!
zstr
(
context
->
codec_settings
.
video
.
config_profile_name
))
{
profile
=
find_profile
(
context
->
codec_settings
.
video
.
config_profile_name
,
SWITCH_FALSE
);
a
profile
=
find_profile
(
context
->
codec_settings
.
video
.
config_profile_name
,
SWITCH_FALSE
);
}
if
(
!
profile
)
{
profile
=
find_profile
(
get_profile_name
(
context
->
av_codec_id
),
SWITCH_FALSE
);
if
(
!
a
profile
)
{
a
profile
=
find_profile
(
get_profile_name
(
context
->
av_codec_id
),
SWITCH_FALSE
);
}
if
(
!
profile
)
return
SWITCH_STATUS_FALSE
;
if
(
!
a
profile
)
return
SWITCH_STATUS_FALSE
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Using config profile: [%s]
\n
"
,
profile
->
name
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Using config profile: [%s]
\n
"
,
aprofile
->
name
);
if
(
aprofile
->
codecs
)
{
parse_codec_specific_profile
(
aprofile
,
get_profile_name
(
context
->
av_codec_id
));
}
if
(
context
->
encoder_ctx
)
{
if
(
avcodec_is_open
(
context
->
encoder_ctx
))
{
...
...
@@ -1281,9 +1316,9 @@ static switch_status_t open_encoder(h264_codec_context_t *context, uint32_t widt
context
->
encoder_ctx
->
width
=
context
->
codec_settings
.
video
.
width
;
context
->
encoder_ctx
->
height
=
context
->
codec_settings
.
video
.
height
;
context
->
encoder_ctx
->
time_base
=
(
AVRational
){
1
,
90
};
context
->
encoder_ctx
->
max_b_frames
=
profile
->
ctx
.
max_b_frames
;
context
->
encoder_ctx
->
max_b_frames
=
a
profile
->
ctx
.
max_b_frames
;
context
->
encoder_ctx
->
pix_fmt
=
AV_PIX_FMT_YUV420P
;
context
->
encoder_ctx
->
thread_count
=
profile
->
ctx
.
thread_count
;
context
->
encoder_ctx
->
thread_count
=
a
profile
->
ctx
.
thread_count
;
if
(
context
->
av_codec_id
==
AV_CODEC_ID_H263
||
context
->
av_codec_id
==
AV_CODEC_ID_H263P
)
{
#ifndef H263_MODE_B
...
...
@@ -1304,10 +1339,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
context
->
encoder_ctx
->
opaque
=
context
;
av_opt_set_int
(
context
->
encoder_ctx
->
priv_data
,
"mb_info"
,
SLICE_SIZE
-
8
,
0
);
}
else
if
(
context
->
av_codec_id
==
AV_CODEC_ID_H264
)
{
context
->
encoder_ctx
->
profile
=
profile
->
ctx
.
profile
;
context
->
encoder_ctx
->
level
=
profile
->
ctx
.
level
;
context
->
encoder_ctx
->
profile
=
a
profile
->
ctx
.
profile
;
context
->
encoder_ctx
->
level
=
a
profile
->
ctx
.
level
;
set_h264_private_data
(
context
,
profile
);
set_h264_private_data
(
context
,
a
profile
);
}
GCC_DIAG_OFF
(
deprecated
-
declarations
)
...
...
@@ -1919,23 +1954,15 @@ void show_codecs(switch_stream_handle_t *stream)
av_free
(
codecs
);
}
static
void
parse_profile
(
switch_xml_t
profile
)
static
void
parse_profile
(
avcodec_profile_t
*
aprofile
,
switch_xml_t
profile
)
{
switch_xml_t
options
=
switch_xml_child
(
profile
,
"options"
);
switch_xml_t
param
=
NULL
;
const
char
*
profile_name
=
switch_xml_attr
(
profile
,
"name"
);
avcodec_profile_t
*
aprofile
=
NULL
;
AVCodecContext
*
ctx
=
NULL
;
if
(
zstr
(
profile_name
))
return
;
aprofile
=
find_profile
(
profile_name
,
SWITCH_TRUE
);
if
(
!
aprofile
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot find profile %s
\n
"
,
profile_name
);
return
;
}
ctx
=
&
aprofile
->
ctx
;
if
(
!
ctx
)
return
;
...
...
@@ -2142,6 +2169,36 @@ static void parse_profile(switch_xml_t profile)
}
// for options
}
static
void
parse_codecs
(
avcodec_profile_t
*
aprofile
,
switch_xml_t
codecs
)
{
switch_xml_t
codec
=
NULL
;
if
(
!
codecs
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"no codecs in %s
\n
"
,
aprofile
->
name
);
return
;
}
codec
=
switch_xml_child
(
codecs
,
"codec"
);
if
(
aprofile
->
codecs
)
{
switch_event_destroy
(
&
aprofile
->
codecs
);
}
switch_event_create
(
&
aprofile
->
codecs
,
SWITCH_EVENT_CLONE
);
for
(;
codec
;
codec
=
codec
->
next
)
{
const
char
*
codec_name
=
switch_xml_attr
(
codec
,
"name"
);
const
char
*
profile_name
=
switch_xml_attr
(
codec
,
"profile"
);
if
(
zstr
(
codec_name
)
||
zstr
(
profile_name
))
continue
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"codec: %s, profile: %s
\n
"
,
codec_name
,
profile_name
);
switch_event_add_header_string
(
aprofile
->
codecs
,
SWITCH_STACK_BOTTOM
,
codec_name
,
profile_name
);
}
}
static
void
load_config
()
{
switch_xml_t
cfg
=
NULL
,
xml
=
NULL
;
...
...
@@ -2186,7 +2243,21 @@ static void load_config()
switch_xml_t
profile
=
switch_xml_child
(
profiles
,
"profile"
);
for
(;
profile
;
profile
=
profile
->
next
)
{
parse_profile
(
profile
);
switch_xml_t
codecs
=
switch_xml_child
(
profile
,
"codecs"
);
const
char
*
profile_name
=
switch_xml_attr
(
profile
,
"name"
);
avcodec_profile_t
*
aprofile
=
NULL
;
if
(
zstr
(
profile_name
))
continue
;
aprofile
=
find_profile
(
profile_name
,
SWITCH_TRUE
);
if
(
!
aprofile
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot find profile %s
\n
"
,
profile_name
);
continue
;
}
parse_profile
(
aprofile
,
profile
);
parse_codecs
(
aprofile
,
codecs
);
}
// for profile
}
// profiles
...
...
@@ -2250,6 +2321,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avcodec_shutdown)
switch_event_destroy
(
&
profile
->
options
);
}
if
(
profile
->
codecs
)
{
switch_event_destroy
(
&
profile
->
codecs
);
}
free
(
profile
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论