Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
2a6fb572
提交
2a6fb572
authored
10月 01, 2018
作者:
Seven Du
提交者:
Andrey Volk
7月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-11425 refactor to parse profiles dynamicly to possible to support more profiles
上级
807efbd0
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
97 行增加
和
106 行删除
+97
-106
av.conf.xml
src/mod/applications/mod_av/autoload_configs/av.conf.xml
+1
-5
avcodec.c
src/mod/applications/mod_av/avcodec.c
+96
-101
没有找到文件。
src/mod/applications/mod_av/autoload_configs/av.conf.xml
浏览文件 @
2a6fb572
...
@@ -11,10 +11,6 @@
...
@@ -11,10 +11,6 @@
<!-- integer of cpus, or 'auto', or 'cpu/<divisor>/<max> -->
<!-- integer of cpus, or 'auto', or 'cpu/<divisor>/<max> -->
<param
name=
"dec-threads"
value=
"1"
/>
<param
name=
"dec-threads"
value=
"1"
/>
<param
name=
"enc-threads"
value=
"cpu/2/4"
/>
<param
name=
"enc-threads"
value=
"cpu/2/4"
/>
<param
name=
"h263-profile"
value=
"H263"
/>
<param
name=
"h263+-profile"
value=
"H263+"
/>
<param
name=
"h264-profile"
value=
"H264"
/>
<param
name=
"h265-profile"
value=
"H265"
/>
</settings>
</settings>
<profiles>
<profiles>
...
@@ -28,7 +24,7 @@
...
@@ -28,7 +24,7 @@
<!-- <param name="dec-threads" value="cpu/2/4"/> -->
<!-- <param name="dec-threads" value="cpu/2/4"/> -->
<!-- <param name="enc-threads" value="1"/> -->
<!-- <param name="enc-threads" value="1"/> -->
<!-- <param name="profile" value="
2
"/> -->
<!-- <param name="profile" value="
baseline
"/> -->
<!-- <param name="level" value="41"/> -->
<!-- <param name="level" value="41"/> -->
<!-- <param name="timebase" value="1/90"/> -->
<!-- <param name="timebase" value="1/90"/> -->
...
...
src/mod/applications/mod_av/avcodec.c
浏览文件 @
2a6fb572
...
@@ -406,7 +406,7 @@ typedef struct h264_codec_context_s {
...
@@ -406,7 +406,7 @@ typedef struct h264_codec_context_s {
static
uint8_t
ff_input_buffer_padding
[
AV_INPUT_BUFFER_PADDING_SIZE
]
=
{
0
};
static
uint8_t
ff_input_buffer_padding
[
AV_INPUT_BUFFER_PADDING_SIZE
]
=
{
0
};
#define MAX_
CODECS 4
#define MAX_
PROFILES 100
typedef
struct
avcodec_profile_s
{
typedef
struct
avcodec_profile_s
{
char
name
[
20
];
char
name
[
20
];
...
@@ -420,32 +420,83 @@ struct avcodec_globals {
...
@@ -420,32 +420,83 @@ struct avcodec_globals {
uint32_t
max_bitrate
;
uint32_t
max_bitrate
;
uint32_t
rtp_slice_size
;
uint32_t
rtp_slice_size
;
uint32_t
key_frame_min_freq
;
uint32_t
key_frame_min_freq
;
uint32_t
enc_threads
;
uint32_t
dec_threads
;
avcodec_profile_t
profiles
[
MAX_CODEC
S
];
avcodec_profile_t
*
profiles
[
MAX_PROFILE
S
];
};
};
struct
avcodec_globals
avcodec_globals
=
{
0
};
struct
avcodec_globals
avcodec_globals
=
{
0
};
char
*
CODEC_MAPS
[]
=
{
const
char
*
get_profile_name
(
int
codec_id
)
"H263"
,
{
"H263+"
,
switch
(
codec_id
)
{
"H264"
,
case
AV_CODEC_ID_H263
:
return
"H263"
;
"H265"
,
case
AV_CODEC_ID_H263P
:
return
"H263+"
;
NULL
case
AV_CODEC_ID_H264
:
return
"H264"
;
};
case
AV_CODEC_ID_H265
:
return
"H265"
;
}
return
"NONE"
;
}
static
void
init_profile
(
avcodec_profile_t
*
aprofile
,
const
char
*
name
);
static
int
get_codec_index
(
const
char
*
cstr
)
static
avcodec_profile_t
*
find_profile
(
const
char
*
name
,
switch_bool_t
reconfig
)
{
{
int
i
;
int
i
;
for
(
i
=
0
;
;
i
++
)
{
for
(
i
=
0
;
i
<
MAX_PROFILES
;
i
++
)
{
if
(
!
strcasecmp
(
cstr
,
CODEC_MAPS
[
i
]))
{
if
(
!
avcodec_globals
.
profiles
[
i
])
{
return
i
;
avcodec_globals
.
profiles
[
i
]
=
malloc
(
sizeof
(
avcodec_profile_t
));
switch_assert
(
avcodec_globals
.
profiles
[
i
]);
memset
(
avcodec_globals
.
profiles
[
i
],
0
,
sizeof
(
avcodec_profile_t
));
init_profile
(
avcodec_globals
.
profiles
[
i
],
name
);
return
avcodec_globals
.
profiles
[
i
];
}
if
(
!
strcmp
(
name
,
avcodec_globals
.
profiles
[
i
]
->
name
))
{
if
(
reconfig
)
init_profile
(
avcodec_globals
.
profiles
[
i
],
name
);
return
avcodec_globals
.
profiles
[
i
];
}
}
}
}
abort
();
return
NULL
;
return
-
1
;
}
#define UINTVAL(v) (v > 0 ? v : 0);
static
void
init_profile
(
avcodec_profile_t
*
aprofile
,
const
char
*
name
)
{
switch_set_string
(
aprofile
->
name
,
name
);
aprofile
->
ctx
.
colorspace
=
AVCOL_SPC_RGB
;
aprofile
->
ctx
.
color_range
=
AVCOL_RANGE_JPEG
;
aprofile
->
ctx
.
flags
=
0
;
aprofile
->
ctx
.
me_cmp
=
-
1
;
aprofile
->
ctx
.
me_range
=
-
1
;
aprofile
->
ctx
.
max_b_frames
=
-
1
;
aprofile
->
ctx
.
refs
=
-
1
;
aprofile
->
ctx
.
gop_size
=
-
1
;
aprofile
->
ctx
.
keyint_min
=
-
1
;
aprofile
->
ctx
.
i_quant_factor
=
-
1
;
aprofile
->
ctx
.
b_quant_factor
=
-
1
;
aprofile
->
ctx
.
qcompress
=
-
1
;
aprofile
->
ctx
.
qmin
=
-
1
;
aprofile
->
ctx
.
qmax
=
-
1
;
aprofile
->
ctx
.
max_qdiff
=
-
1
;
aprofile
->
ctx
.
thread_count
=
avcodec_globals
.
enc_threads
;
aprofile
->
decoder_thread_count
=
avcodec_globals
.
dec_threads
;
if
(
!
strcasecmp
(
name
,
"H264"
))
{
aprofile
->
ctx
.
profile
=
FF_PROFILE_H264_BASELINE
;
aprofile
->
ctx
.
level
=
41
;
#ifdef AV_CODEC_FLAG_PSNR
aprofile
->
ctx
.
flags
|=
AV_CODEC_FLAG_PSNR
;
#endif
#ifdef CODEC_FLAG_LOOP_FILTER
aprofile
->
ctx
.
flags
|=
CODEC_FLAG_LOOP_FILTER
;
#endif
}
}
}
static
switch_status_t
buffer_h264_nalu
(
h264_codec_context_t
*
context
,
switch_frame_t
*
frame
)
static
switch_status_t
buffer_h264_nalu
(
h264_codec_context_t
*
context
,
switch_frame_t
*
frame
)
...
@@ -1160,17 +1211,7 @@ static switch_status_t open_encoder(h264_codec_context_t *context, uint32_t widt
...
@@ -1160,17 +1211,7 @@ static switch_status_t open_encoder(h264_codec_context_t *context, uint32_t widt
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
}
}
if
(
context
->
av_codec_id
==
AV_CODEC_ID_H263
)
{
profile
=
find_profile
(
get_profile_name
(
context
->
av_codec_id
),
SWITCH_FALSE
);
profile
=
&
avcodec_globals
.
profiles
[
get_codec_index
(
"H263"
)];
}
else
if
(
context
->
av_codec_id
==
AV_CODEC_ID_H263P
)
{
profile
=
&
avcodec_globals
.
profiles
[
get_codec_index
(
"H263+"
)];
}
else
if
(
context
->
av_codec_id
==
AV_CODEC_ID_H264
)
{
profile
=
&
avcodec_globals
.
profiles
[
get_codec_index
(
"H264"
)];
#ifdef AV_CODEC_ID_H265
}
else
if
(
context
->
av_codec_id
==
AV_CODEC_ID_H265
)
{
profile
=
&
avcodec_globals
.
profiles
[
get_codec_index
(
"H265"
)];
#endif
}
if
(
!
profile
)
return
SWITCH_STATUS_FALSE
;
if
(
!
profile
)
return
SWITCH_STATUS_FALSE
;
...
@@ -1320,16 +1361,17 @@ static switch_status_t switch_h264_init(switch_codec_t *codec, switch_codec_flag
...
@@ -1320,16 +1361,17 @@ static switch_status_t switch_h264_init(switch_codec_t *codec, switch_codec_flag
if
(
!
strcmp
(
codec
->
implementation
->
iananame
,
"H263"
))
{
if
(
!
strcmp
(
codec
->
implementation
->
iananame
,
"H263"
))
{
context
->
av_codec_id
=
AV_CODEC_ID_H263
;
context
->
av_codec_id
=
AV_CODEC_ID_H263
;
profile
=
&
avcodec_globals
.
profiles
[
get_codec_index
(
"H263"
)];
}
else
if
(
!
strcmp
(
codec
->
implementation
->
iananame
,
"H263-1998"
))
{
}
else
if
(
!
strcmp
(
codec
->
implementation
->
iananame
,
"H263-1998"
))
{
context
->
av_codec_id
=
AV_CODEC_ID_H263P
;
context
->
av_codec_id
=
AV_CODEC_ID_H263P
;
profile
=
&
avcodec_globals
.
profiles
[
get_codec_index
(
"H263+"
)];
}
else
{
}
else
{
context
->
av_codec_id
=
AV_CODEC_ID_H264
;
context
->
av_codec_id
=
AV_CODEC_ID_H264
;
profile
=
&
avcodec_globals
.
profiles
[
get_codec_index
(
"H264"
)];
}
}
switch_assert
(
profile
);
profile
=
find_profile
(
get_profile_name
(
context
->
av_codec_id
),
SWITCH_FALSE
);
if
(
!
profile
)
{
goto
error
;
}
if
(
decoding
)
{
if
(
decoding
)
{
context
->
decoder
=
avcodec_find_decoder
(
context
->
av_codec_id
);
context
->
decoder
=
avcodec_find_decoder
(
context
->
av_codec_id
);
...
@@ -1869,8 +1911,6 @@ void show_codecs(switch_stream_handle_t *stream)
...
@@ -1869,8 +1911,6 @@ void show_codecs(switch_stream_handle_t *stream)
av_free
(
codecs
);
av_free
(
codecs
);
}
}
#define UINTVAL(v) (v > 0 ? v : 0);
static
void
parse_profile
(
switch_xml_t
profile
)
static
void
parse_profile
(
switch_xml_t
profile
)
{
{
switch_xml_t
options
=
switch_xml_child
(
profile
,
"options"
);
switch_xml_t
options
=
switch_xml_child
(
profile
,
"options"
);
...
@@ -1878,18 +1918,18 @@ static void parse_profile(switch_xml_t profile)
...
@@ -1878,18 +1918,18 @@ static void parse_profile(switch_xml_t profile)
const
char
*
profile_name
=
switch_xml_attr
(
profile
,
"name"
);
const
char
*
profile_name
=
switch_xml_attr
(
profile
,
"name"
);
avcodec_profile_t
*
aprofile
=
NULL
;
avcodec_profile_t
*
aprofile
=
NULL
;
AVCodecContext
*
ctx
=
NULL
;
AVCodecContext
*
ctx
=
NULL
;
int
i
;
if
(
zstr
(
profile_name
))
return
;
if
(
zstr
(
profile_name
))
return
;
for
(
i
=
0
;
i
<
MAX_CODECS
;
i
++
)
{
aprofile
=
find_profile
(
profile_name
,
SWITCH_TRUE
);
if
(
!
strcmp
(
profile_name
,
avcodec_globals
.
profiles
[
i
].
name
))
{
aprofile
=
&
avcodec_globals
.
profiles
[
i
];
if
(
!
aprofile
)
{
ctx
=
&
aprofile
->
ctx
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot find profile %s
\n
"
,
profile_name
);
break
;
return
;
}
}
}
ctx
=
&
aprofile
->
ctx
;
if
(
!
ctx
)
return
;
if
(
!
ctx
)
return
;
for
(
param
=
switch_xml_child
(
profile
,
"param"
);
param
;
param
=
param
->
next
)
{
for
(
param
=
switch_xml_child
(
profile
,
"param"
);
param
;
param
=
param
->
next
)
{
...
@@ -1913,7 +1953,7 @@ static void parse_profile(switch_xml_t profile)
...
@@ -1913,7 +1953,7 @@ static void parse_profile(switch_xml_t profile)
}
else
if
(
!
strcmp
(
name
,
"profile"
))
{
}
else
if
(
!
strcmp
(
name
,
"profile"
))
{
ctx
->
profile
=
UINTVAL
(
val
);
ctx
->
profile
=
UINTVAL
(
val
);
if
(
ctx
->
profile
==
0
&&
!
strcasecmp
(
CODEC_MAPS
[
i
]
,
"H264"
))
{
if
(
ctx
->
profile
==
0
&&
!
strcasecmp
(
aprofile
->
name
,
"H264"
))
{
if
(
!
strcasecmp
(
value
,
"baseline"
))
{
if
(
!
strcasecmp
(
value
,
"baseline"
))
{
ctx
->
profile
=
FF_PROFILE_H264_BASELINE
;
ctx
->
profile
=
FF_PROFILE_H264_BASELINE
;
}
else
if
(
!
strcasecmp
(
value
,
"main"
))
{
}
else
if
(
!
strcasecmp
(
value
,
"main"
))
{
...
@@ -2097,47 +2137,10 @@ static void parse_profile(switch_xml_t profile)
...
@@ -2097,47 +2137,10 @@ static void parse_profile(switch_xml_t profile)
static
void
load_config
()
static
void
load_config
()
{
{
switch_xml_t
cfg
=
NULL
,
xml
=
NULL
;
switch_xml_t
cfg
=
NULL
,
xml
=
NULL
;
int
i
;
switch_set_string
(
avcodec_globals
.
profiles
[
get_codec_index
(
"H263"
)].
name
,
"H263"
);
switch_set_string
(
avcodec_globals
.
profiles
[
get_codec_index
(
"H263+"
)].
name
,
"H263+"
);
switch_set_string
(
avcodec_globals
.
profiles
[
get_codec_index
(
"H264"
)].
name
,
"H264"
);
switch_set_string
(
avcodec_globals
.
profiles
[
get_codec_index
(
"H265"
)].
name
,
"H265"
);
for
(
i
=
0
;
i
<
MAX_CODECS
;
i
++
)
{
avcodec_profile_t
*
profile
=
&
avcodec_globals
.
profiles
[
i
];
profile
->
ctx
.
colorspace
=
AVCOL_SPC_RGB
;
profile
->
ctx
.
color_range
=
AVCOL_RANGE_JPEG
;
profile
->
ctx
.
flags
=
0
;
profile
->
ctx
.
me_cmp
=
-
1
;
profile
->
ctx
.
me_range
=
-
1
;
profile
->
ctx
.
max_b_frames
=
-
1
;
profile
->
ctx
.
refs
=
-
1
;
profile
->
ctx
.
gop_size
=
-
1
;
profile
->
ctx
.
keyint_min
=
-
1
;
profile
->
ctx
.
i_quant_factor
=
-
1
;
profile
->
ctx
.
b_quant_factor
=
-
1
;
profile
->
ctx
.
qcompress
=
-
1
;
profile
->
ctx
.
qmin
=
-
1
;
profile
->
ctx
.
qmax
=
-
1
;
profile
->
ctx
.
max_qdiff
=
-
1
;
profile
->
ctx
.
thread_count
=
switch_parse_cpu_string
(
"cpu/2/4"
);
profile
->
decoder_thread_count
=
switch_parse_cpu_string
(
"cpu/2/4"
);
if
(
!
strcasecmp
(
CODEC_MAPS
[
i
],
"H264"
))
{
profile
->
ctx
.
profile
=
FF_PROFILE_H264_BASELINE
;
profile
->
ctx
.
level
=
41
;
#ifdef AV_CODEC_FLAG_PSNR
profile
->
ctx
.
flags
|=
AV_CODEC_FLAG_PSNR
;
#endif
#ifdef CODEC_FLAG_LOOP_FILTER
profile
->
ctx
.
flags
|=
CODEC_FLAG_LOOP_FILTER
;
#endif
}
}
avcodec_globals
.
max_bitrate
=
0
;
avcodec_globals
.
max_bitrate
=
0
;
avcodec_globals
.
dec_threads
=
1
;
avcodec_globals
.
enc_threads
=
switch_parse_cpu_string
(
"cpu/2/4"
);
xml
=
switch_xml_open_cfg
(
"avcodec.conf"
,
&
cfg
,
NULL
);
xml
=
switch_xml_open_cfg
(
"avcodec.conf"
,
&
cfg
,
NULL
);
...
@@ -2164,27 +2167,9 @@ static void load_config()
...
@@ -2164,27 +2167,9 @@ static void load_config()
avcodec_globals
.
key_frame_min_freq
=
UINTVAL
(
val
);
avcodec_globals
.
key_frame_min_freq
=
UINTVAL
(
val
);
avcodec_globals
.
key_frame_min_freq
*=
1000
;
avcodec_globals
.
key_frame_min_freq
*=
1000
;
}
else
if
(
!
strcmp
(
name
,
"dec-threads"
))
{
}
else
if
(
!
strcmp
(
name
,
"dec-threads"
))
{
int
i
;
avcodec_globals
.
dec_threads
=
switch_parse_cpu_string
(
value
);
unsigned
int
threads
=
switch_parse_cpu_string
(
value
);
for
(
i
=
0
;
i
<
MAX_CODECS
;
i
++
)
{
avcodec_globals
.
profiles
[
i
].
decoder_thread_count
=
threads
;
}
}
else
if
(
!
strcmp
(
name
,
"enc-threads"
))
{
}
else
if
(
!
strcmp
(
name
,
"enc-threads"
))
{
int
i
;
avcodec_globals
.
enc_threads
=
switch_parse_cpu_string
(
value
);
unsigned
int
threads
=
switch_parse_cpu_string
(
value
);
for
(
i
=
0
;
i
<
MAX_CODECS
;
i
++
)
{
avcodec_globals
.
profiles
[
i
].
ctx
.
thread_count
=
threads
;
}
}
else
if
(
!
strcasecmp
(
name
,
"h263-profile"
))
{
switch_set_string
(
avcodec_globals
.
profiles
[
get_codec_index
(
"H263"
)].
name
,
value
);
}
else
if
(
!
strcasecmp
(
name
,
"h263+-profile"
))
{
switch_set_string
(
avcodec_globals
.
profiles
[
get_codec_index
(
"H263+"
)].
name
,
value
);
}
else
if
(
!
strcasecmp
(
name
,
"h264-profile"
))
{
switch_set_string
(
avcodec_globals
.
profiles
[
get_codec_index
(
"H264"
)].
name
,
value
);
}
else
if
(
!
strcasecmp
(
name
,
"h265-profile"
))
{
switch_set_string
(
avcodec_globals
.
profiles
[
get_codec_index
(
"H265"
)].
name
,
value
);
}
}
}
}
}
}
...
@@ -2213,6 +2198,12 @@ static void load_config()
...
@@ -2213,6 +2198,12 @@ static void load_config()
if
(
avcodec_globals
.
key_frame_min_freq
<
10000
||
avcodec_globals
.
key_frame_min_freq
>
3
*
1000000
)
{
if
(
avcodec_globals
.
key_frame_min_freq
<
10000
||
avcodec_globals
.
key_frame_min_freq
>
3
*
1000000
)
{
avcodec_globals
.
key_frame_min_freq
=
KEY_FRAME_MIN_FREQ
;
avcodec_globals
.
key_frame_min_freq
=
KEY_FRAME_MIN_FREQ
;
}
}
// make sure profiles created
find_profile
(
"H263"
,
SWITCH_FALSE
);
find_profile
(
"H263+"
,
SWITCH_FALSE
);
find_profile
(
"H264"
,
SWITCH_FALSE
);
find_profile
(
"H265"
,
SWITCH_FALSE
);
}
}
SWITCH_MODULE_LOAD_FUNCTION
(
mod_avcodec_load
)
SWITCH_MODULE_LOAD_FUNCTION
(
mod_avcodec_load
)
...
@@ -2242,12 +2233,16 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avcodec_shutdown)
...
@@ -2242,12 +2233,16 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avcodec_shutdown)
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
MAX_CODECS
;
i
++
)
{
for
(
i
=
0
;
i
<
MAX_PROFILES
;
i
++
)
{
avcodec_profile_t
*
profile
=
&
avcodec_globals
.
profiles
[
i
];
avcodec_profile_t
*
profile
=
avcodec_globals
.
profiles
[
i
];
if
(
!
profile
)
break
;
if
(
profile
->
options
)
{
if
(
profile
->
options
)
{
switch_event_destroy
(
&
profile
->
options
);
switch_event_destroy
(
&
profile
->
options
);
}
}
free
(
profile
);
}
}
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论