Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
65fd0792
提交
65fd0792
authored
10月 07, 2015
作者:
Dragos Oancea
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-8319: mod_opus: fix and cleanup of switch_opus_has_fec() and switch_opus_info().
上级
3e23ff7d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
55 行删除
+21
-55
mod_opus.c
src/mod/codecs/mod_opus/mod_opus.c
+21
-55
没有找到文件。
src/mod/codecs/mod_opus/mod_opus.c
浏览文件 @
65fd0792
...
@@ -328,10 +328,17 @@ static char *gen_fmtp(opus_codec_settings_t *settings, switch_memory_pool_t *poo
...
@@ -328,10 +328,17 @@ static char *gen_fmtp(opus_codec_settings_t *settings, switch_memory_pool_t *poo
static
switch_bool_t
switch_opus_has_fec
(
const
uint8_t
*
payload
,
int
payload_length_bytes
)
static
switch_bool_t
switch_opus_has_fec
(
const
uint8_t
*
payload
,
int
payload_length_bytes
)
{
{
/* nb_silk_frames: number of silk-frames (10 or 20 ms) in an opus frame: 0, 1, 2 or 3 */
/* computed from the 5 MSB (configuration) of the TOC byte (payload[0]) */
/* nb_opus_frames: number of opus frames in the packet */
/* computed from the 2 LSB (p0p1) of the TOC byte */
/* p0p1 = 0 => nb_opus_frames = 1 */
/* p0p1 = 1 or 2 => nb_opus_frames = 2 */
/* p0p1 = 3 => given by the 6 LSB of payload[1] */
int
nb_silk_frames
,
nb_opus_frames
,
n
,
i
;
int
nb_silk_frames
,
nb_opus_frames
,
n
,
i
;
opus_int16
frame_sizes
[
48
];
opus_int16
frame_sizes
[
48
];
const
unsigned
char
*
frame_data
[
48
];
const
unsigned
char
*
frame_data
[
48
];
int
frames
;
if
(
payload
==
NULL
||
payload_length_bytes
<=
0
)
{
if
(
payload
==
NULL
||
payload_length_bytes
<=
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"corrupted packet (invalid size)
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"corrupted packet (invalid size)
\n
"
);
...
@@ -343,7 +350,7 @@ static switch_bool_t switch_opus_has_fec(const uint8_t* payload,int payload_leng
...
@@ -343,7 +350,7 @@ static switch_bool_t switch_opus_has_fec(const uint8_t* payload,int payload_leng
return
SWITCH_FALSE
;
return
SWITCH_FALSE
;
}
}
if
((
nb_opus_frames
=
opus_packet_parse
(
payload
,
payload_length_bytes
,
NULL
,
frame_data
,
frame_sizes
,
NULL
))
<
0
)
{
if
((
nb_opus_frames
=
opus_packet_parse
(
payload
,
payload_length_bytes
,
NULL
,
frame_data
,
frame_sizes
,
NULL
))
<
=
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"OPUS_INVALID_PACKET ! nb_opus_frames: %d
\n
"
,
nb_opus_frames
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"OPUS_INVALID_PACKET ! nb_opus_frames: %d
\n
"
,
nb_opus_frames
);
return
SWITCH_FALSE
;
return
SWITCH_FALSE
;
}
}
...
@@ -355,38 +362,24 @@ static switch_bool_t switch_opus_has_fec(const uint8_t* payload,int payload_leng
...
@@ -355,38 +362,24 @@ static switch_bool_t switch_opus_has_fec(const uint8_t* payload,int payload_leng
if
(
nb_silk_frames
==
0
)
{
if
(
nb_silk_frames
==
0
)
{
nb_silk_frames
=
1
;
nb_silk_frames
=
1
;
}
}
if
(
nb_silk_frames
==
1
)
{
if
(
(
nb_silk_frames
==
1
)
&&
(
nb_opus_frames
==
1
))
{
for
(
n
=
0
;
n
<=
(
payload
[
0
]
&
0x4
)
;
n
++
)
{
/* mono or stereo */
for
(
n
=
0
;
n
<=
(
payload
[
0
]
&
0x4
)
;
n
++
)
{
/* mono or stereo
: 10,20 ms
*/
if
(
frame_data
[
0
][
0
]
&
(
0x80
>>
((
n
+
1
)
*
(
nb_silk_frames
+
1
)
-
1
)))
{
if
(
frame_data
[
0
][
0
]
&
(
0x80
>>
((
n
+
1
)
*
(
nb_silk_frames
+
1
)
-
1
)))
{
return
SWITCH_TRUE
;
/*
1st 20ms (or 10 ms) frame has FEC */
return
SWITCH_TRUE
;
/*
frame has FEC */
}
}
}
}
}
else
{
}
else
{
opus_int16
LBRR_flag
=
0
;
opus_int16
LBRR_flag
=
0
;
for
(
i
=
0
;
i
<
nb_opus_frames
;
i
++
)
{
/* only mono */
for
(
i
=
0
;
i
<
nb_opus_frames
;
i
++
)
{
/* only mono
Opus frames
*/
LBRR_flag
=
(
frame_data
[
i
][
0
]
>>
(
7
-
nb_silk_frames
))
&
0x1
;
LBRR_flag
=
(
frame_data
[
i
][
0
]
>>
(
7
-
nb_silk_frames
))
&
0x1
;
if
(
LBRR_flag
)
{
if
(
LBRR_flag
)
{
return
SWITCH_TRUE
;
/* one of the silk frames has FEC */
return
SWITCH_TRUE
;
/* one of the silk frames has FEC */
}
}
}
}
}
}
}
frames
=
opus_packet_parse
(
payload
,
payload_length_bytes
,
NULL
,
frame_data
,
frame_sizes
,
NULL
);
if
(
frames
<
0
)
{
return
SWITCH_FALSE
;
}
if
(
frame_sizes
[
0
]
<=
1
)
{
return
SWITCH_FALSE
;
return
SWITCH_FALSE
;
}
}
for
(
n
=
0
;
n
<=
(
payload
[
0
]
&
0x4
);
n
++
)
{
if
(
frame_data
[
0
][
0
]
&
(
0x80
>>
((
n
+
1
)
*
(
frames
+
1
)
-
1
)))
{
return
SWITCH_TRUE
;
/*this works only for 20 ms frames now, it will return VAD for 40 ms or 60 ms*/
}
}
return
SWITCH_FALSE
;
return
SWITCH_FALSE
;
}
}
...
@@ -420,21 +413,13 @@ static int switch_opus_get_fec_bitrate(int fs, int loss)
...
@@ -420,21 +413,13 @@ static int switch_opus_get_fec_bitrate(int fs, int loss)
static
switch_status_t
switch_opus_info
(
void
*
encoded_data
,
uint32_t
len
,
uint32_t
samples_per_second
,
char
*
print_text
)
static
switch_status_t
switch_opus_info
(
void
*
encoded_data
,
uint32_t
len
,
uint32_t
samples_per_second
,
char
*
print_text
)
{
{
/* nb_silk_frames: number of silk-frames (10 or 20 ms) in an opus frame: 0, 1, 2 or 3 */
int
nb_samples
,
nb_opus_frames
,
nb_channels
;
/* computed from the 5 MSB (configuration) of the TOC byte (encoded_data[0]) */
/* nb_opus_frames: number of opus frames in the packet */
/* computed from the 2 LSB (p0p1) of the TOC byte */
/* p0p1 = 0 => nb_opus_frames= 1 */
/* p0p1 = 1 or 2 => nb_opus_frames= 2 */
/* p0p1 = 3 => given by the 6 LSB of encoded_data[1] */
int
nb_samples
,
nb_silk_frames
,
nb_opus_frames
,
n
,
i
;
int
audiobandwidth
;
int
audiobandwidth
;
char
audiobandwidth_str
[
32
]
=
{
0
};
char
audiobandwidth_str
[
32
]
=
{
0
};
opus_int16
frame_sizes
[
48
];
opus_int16
frame_sizes
[
48
];
const
unsigned
char
*
frame_data
[
48
];
const
unsigned
char
*
frame_data
[
48
];
char
has_fec
=
0
;
char
has_fec
=
0
;
uint8_t
*
payload
=
encoded_data
;
uint8_t
*
payload
=
encoded_data
;
if
(
!
encoded_data
)
{
if
(
!
encoded_data
)
{
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
...
@@ -446,38 +431,19 @@ static switch_status_t switch_opus_info(void * encoded_data, uint32_t len, uint3
...
@@ -446,38 +431,19 @@ static switch_status_t switch_opus_info(void * encoded_data, uint32_t len, uint3
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"%s: OPUS_INVALID_PACKET !
\n
"
,
print_text
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"%s: OPUS_INVALID_PACKET !
\n
"
,
print_text
);
}
}
if
((
nb_opus_frames
=
opus_packet_parse
(
encoded_data
,
len
,
NULL
,
frame_data
,
frame_sizes
,
NULL
))
<
0
)
{
if
((
nb_opus_frames
=
opus_packet_parse
(
encoded_data
,
len
,
NULL
,
frame_data
,
frame_sizes
,
NULL
))
<
=
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"%s: OPUS_INVALID_PACKET ! frames: %d
\n
"
,
print_text
,
nb_opus_frames
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"%s: OPUS_INVALID_PACKET ! frames: %d
\n
"
,
print_text
,
nb_opus_frames
);
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
}
}
nb_samples
=
opus_packet_get_samples_per_frame
(
encoded_data
,
samples_per_second
)
*
nb_opus_frames
;
nb_samples
=
opus_packet_get_samples_per_frame
(
encoded_data
,
samples_per_second
)
*
nb_opus_frames
;
nb_silk_frames
=
0
;
if
((
payload
[
0
]
>>
3
)
<
12
)
{
/* config in silk-only : NB,MB,WB */
has_fec
=
switch_opus_has_fec
(
payload
,
len
);
nb_silk_frames
=
(
payload
[
0
]
>>
3
)
&
0x3
;
if
(
nb_silk_frames
==
0
)
{
nb_channels
=
opus_packet_get_nb_channels
(
payload
);
nb_silk_frames
=
1
;
}
if
(
nb_silk_frames
==
1
)
{
for
(
n
=
0
;
n
<=
(
payload
[
0
]
&
0x4
)
;
n
++
)
{
/* mono or stereo */
if
(
frame_data
[
0
][
0
]
&
(
0x80
>>
((
n
+
1
)
*
(
nb_silk_frames
+
1
)
-
1
))){
has_fec
=
1
;
/* 1st 20ms (or 10 ms) frame has fec */
}
}
}
else
{
opus_int16
LBRR_flag
=
0
;
for
(
i
=
0
;
i
<
nb_opus_frames
;
i
++
)
{
/* only mono */
LBRR_flag
=
(
frame_data
[
i
][
0
]
>>
(
7
-
nb_silk_frames
))
&
0x1
;
if
(
LBRR_flag
)
{
has_fec
=
1
;
}
}
}
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"%s:
nb_opus_frames [%d] nb_silk_frames [%d] samples [%d] audio bandwidth [%s] bytes [%d] FEC[%s
]
\n
"
,
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"%s:
opus_frames [%d] samples [%d] audio bandwidth [%s] bytes [%d] FEC[%s] channels[%d
]
\n
"
,
print_text
,
nb_opus_frames
,
nb_s
ilk_frames
,
nb_samples
,
audiobandwidth_str
,
len
,
has_fec
?
"yes"
:
"no"
);
print_text
,
nb_opus_frames
,
nb_s
amples
,
audiobandwidth_str
,
len
,
has_fec
?
"yes"
:
"no"
,
nb_channels
);
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论