Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
67284236
提交
67284236
authored
10月 09, 2006
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
git-svn-id:
http://svn.freeswitch.org/svn/freeswitch/trunk@3017
d0543943-73ff-0310-b7d9-9358b9ac24b2
上级
514a73bc
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
136 行增加
和
34 行删除
+136
-34
mod_amr.c
src/mod/codecs/mod_amr/mod_amr.c
+125
-30
switch_core.c
src/switch_core.c
+11
-4
没有找到文件。
src/mod/codecs/mod_amr/mod_amr.c
浏览文件 @
67284236
...
@@ -61,24 +61,25 @@
...
@@ -61,24 +61,25 @@
static
const
char
modname
[]
=
"mod_amr"
;
static
const
char
modname
[]
=
"mod_amr"
;
struct
amr_context
{
typedef
enum
{
void
*
encoder_state
;
AMR_OPT_OCTET_ALIGN
=
(
1
<<
0
),
void
*
decoder_state
;
AMR_OPT_CRC
=
(
1
<<
1
),
int
enc_mode
;
AMR_OPT_MODE_CHANGE_NEIGHBOR
=
(
1
<<
2
),
};
AMR_OPT_ROBUST_SORTING
=
(
1
<<
3
),
AMR_OPT_INTERLEAVING
=
(
1
<<
4
)
}
amr_flag_t
;
enum
typedef
enum
{
{
GENERIC_PARAMETER_AMR_MAXAL_SDUFRAMES
=
0
,
GENERIC_PARAMETER_AMR_MAXAL_SDUFRAMES
=
0
,
GENERIC_PARAMETER_AMR_BITRATE
,
GENERIC_PARAMETER_AMR_BITRATE
,
GENERIC_PARAMETER_AMR_GSMAMRCOMFORTNOISE
,
GENERIC_PARAMETER_AMR_GSMAMRCOMFORTNOISE
,
GENERIC_PARAMETER_AMR_GSMEFRCOMFORTNOISE
,
GENERIC_PARAMETER_AMR_GSMEFRCOMFORTNOISE
,
GENERIC_PARAMETER_AMR_IS_641COMFORTNOISE
,
GENERIC_PARAMETER_AMR_IS_641COMFORTNOISE
,
GENERIC_PARAMETER_AMR_PDCEFRCOMFORTNOISE
GENERIC_PARAMETER_AMR_PDCEFRCOMFORTNOISE
}
;
}
amr_param_t
;
enum
typedef
enum
{
{
AMR_BITRATE_475
=
0
,
AMR_BITRATE_475
=
0
,
AMR_BITRATE_515
,
AMR_BITRATE_515
,
AMR_BITRATE_590
,
AMR_BITRATE_590
,
...
@@ -87,17 +88,37 @@ enum
...
@@ -87,17 +88,37 @@ enum
AMR_BITRATE_795
,
AMR_BITRATE_795
,
AMR_BITRATE_1020
,
AMR_BITRATE_1020
,
AMR_BITRATE_1220
AMR_BITRATE_1220
};
}
amr_bitrate_t
;
struct
amr_context
{
void
*
encoder_state
;
void
*
decoder_state
;
switch_byte_t
enc_modes
;
switch_byte_t
enc_mode
;
uint32_t
change_period
;
switch_byte_t
max_ptime
;
switch_byte_t
ptime
;
switch_byte_t
channels
;
switch_byte_t
flags
;
};
#define AMR_DEFAULT_BITRATE AMR_BITRATE_1220
static
struct
{
switch_byte_t
default_bitrate
;
}
globals
;
#define AMR_Mode 7
static
switch_status_t
switch_amr_init
(
switch_codec_t
*
codec
,
switch_codec_flag_t
flags
,
static
switch_status_t
switch_amr_init
(
switch_codec_t
*
codec
,
switch_codec_flag_t
flags
,
const
switch_codec_settings_t
*
codec_settings
)
const
switch_codec_settings_t
*
codec_settings
)
{
{
struct
amr_context
*
context
=
NULL
;
struct
amr_context
*
context
=
NULL
;
int
encoding
,
decoding
;
int
encoding
,
decoding
;
int
x
,
argc
;
int
x
,
i
,
argc
;
char
*
argv
[
10
];
char
*
argv
[
10
];
char
fmtptmp
[
128
];
encoding
=
(
flags
&
SWITCH_CODEC_FLAG_ENCODE
);
encoding
=
(
flags
&
SWITCH_CODEC_FLAG_ENCODE
);
decoding
=
(
flags
&
SWITCH_CODEC_FLAG_DECODE
);
decoding
=
(
flags
&
SWITCH_CODEC_FLAG_DECODE
);
...
@@ -117,14 +138,64 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
...
@@ -117,14 +138,64 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
if
((
arg
=
strchr
(
data
,
'='
)))
{
if
((
arg
=
strchr
(
data
,
'='
)))
{
*
arg
++
=
'\0'
;
*
arg
++
=
'\0'
;
//printf("Codec arg %d [%s]=[%s]\n", x, data, arg);
//printf("Codec arg %d [%s]=[%s]\n", x, data, arg);
if
(
!
strcasecmp
(
data
,
"octet-align"
))
{
if
(
atoi
(
arg
))
{
switch_set_flag
(
context
,
AMR_OPT_OCTET_ALIGN
);
}
}
else
if
(
!
strcasecmp
(
data
,
"mode-change-neighbor"
))
{
if
(
atoi
(
arg
))
{
switch_set_flag
(
context
,
AMR_OPT_MODE_CHANGE_NEIGHBOR
);
}
}
else
if
(
!
strcasecmp
(
data
,
"crc"
))
{
if
(
atoi
(
arg
))
{
switch_set_flag
(
context
,
AMR_OPT_CRC
);
}
}
else
if
(
!
strcasecmp
(
data
,
"robust-sorting"
))
{
if
(
atoi
(
arg
))
{
switch_set_flag
(
context
,
AMR_OPT_ROBUST_SORTING
);
}
}
else
if
(
!
strcasecmp
(
data
,
"interveaving"
))
{
if
(
atoi
(
arg
))
{
switch_set_flag
(
context
,
AMR_OPT_INTERLEAVING
);
}
}
else
if
(
!
strcasecmp
(
data
,
"mode-change-period"
))
{
context
->
change_period
=
atoi
(
arg
);
}
else
if
(
!
strcasecmp
(
data
,
"ptime"
))
{
context
->
ptime
=
atoi
(
arg
);
}
else
if
(
!
strcasecmp
(
data
,
"channels"
))
{
context
->
channels
=
atoi
(
arg
);
}
else
if
(
!
strcasecmp
(
data
,
"maxptime"
))
{
context
->
max_ptime
=
atoi
(
arg
);
}
else
if
(
!
strcasecmp
(
data
,
"mode-set"
))
{
int
y
,
m_argc
;
char
*
m_argv
[
7
];
m_argc
=
switch_separate_string
(
arg
,
','
,
m_argv
,
(
sizeof
(
m_argv
)
/
sizeof
(
m_argv
[
0
])));
for
(
y
=
0
;
y
<
m_argc
;
y
++
)
{
context
->
enc_modes
|=
(
1
<<
atoi
(
m_argv
[
y
]));
}
}
}
}
}
}
}
}
codec
->
fmtp_out
=
"octet-align=0; mode-set=7"
;
if
(
context
->
enc_modes
)
{
for
(
i
=
7
;
i
>
-
1
;
i
++
)
{
if
(
context
->
enc_modes
&
(
1
<<
i
))
{
context
->
enc_mode
=
i
;
break
;
}
}
}
if
(
!
context
->
enc_mode
)
{
context
->
enc_mode
=
globals
.
default_bitrate
;
}
snprintf
(
fmtptmp
,
sizeof
(
fmtptmp
),
"octet-align=0; mode-set=%d"
,
context
->
enc_mode
);
codec
->
fmtp_out
=
switch_core_strdup
(
codec
->
memory_pool
,
fmtptmp
);
context
->
enc_mode
=
AMR_
Mode
;
/* start in mode 7 */
context
->
enc_mode
=
AMR_
DEFAULT_BITRATE
;
context
->
encoder_state
=
NULL
;
context
->
encoder_state
=
NULL
;
context
->
decoder_state
=
NULL
;
context
->
decoder_state
=
NULL
;
...
@@ -174,7 +245,7 @@ static switch_status_t switch_amr_encode(switch_codec_t *codec,
...
@@ -174,7 +245,7 @@ static switch_status_t switch_amr_encode(switch_codec_t *codec,
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
}
}
*
encoded_data_len
=
Encoder_Interface_Encode
(
context
->
encoder_state
,
context
->
enc_mode
,
(
int16_t
*
)
decoded_data
,
(
uint8
_t
*
)
encoded_data
,
0
);
*
encoded_data_len
=
Encoder_Interface_Encode
(
context
->
encoder_state
,
context
->
enc_mode
,
(
int16_t
*
)
decoded_data
,
(
switch_byte
_t
*
)
encoded_data
,
0
);
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
...
@@ -197,9 +268,15 @@ static switch_status_t switch_amr_decode(switch_codec_t *codec,
...
@@ -197,9 +268,15 @@ static switch_status_t switch_amr_decode(switch_codec_t *codec,
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
}
}
Decoder_Interface_Decode
(
context
->
decoder_state
,
(
void
*
)
encoded_data
,
(
void
*
)
decoded_data
,
0
);
if
(
encoded_data_len
==
1
)
{
memset
(
decoded_data
,
255
,
codec
->
implementation
->
bytes_per_frame
);
*
flag
|=
SFF_CNG
;
}
else
{
Decoder_Interface_Decode
(
context
->
decoder_state
,
(
unsigned
char
*
)
encoded_data
,
(
int16_t
*
)
decoded_data
,
0
);
}
*
decoded_data_len
=
codec
->
implementation
->
bytes_per_frame
;
*
decoded_data_len
=
codec
->
implementation
->
bytes_per_frame
;
//printf("D %d/%d\n", encoded_data_len, *decoded_data_len);
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
...
@@ -242,6 +319,24 @@ static switch_loadable_module_interface_t amr_module_interface = {
...
@@ -242,6 +319,24 @@ static switch_loadable_module_interface_t amr_module_interface = {
SWITCH_MOD_DECLARE
(
switch_status_t
)
switch_module_load
(
const
switch_loadable_module_interface_t
**
module_interface
,
SWITCH_MOD_DECLARE
(
switch_status_t
)
switch_module_load
(
const
switch_loadable_module_interface_t
**
module_interface
,
char
*
filename
)
char
*
filename
)
{
{
char
*
cf
=
"amr.conf"
;
switch_xml_t
cfg
,
xml
,
settings
,
param
;
memset
(
&
globals
,
0
,
sizeof
(
globals
));
globals
.
default_bitrate
=
AMR_DEFAULT_BITRATE
;
if
((
xml
=
switch_xml_open_cfg
(
cf
,
&
cfg
,
NULL
)))
{
if
((
settings
=
switch_xml_child
(
cfg
,
"settings"
)))
{
for
(
param
=
switch_xml_child
(
settings
,
"param"
);
param
;
param
=
param
->
next
)
{
char
*
var
=
(
char
*
)
switch_xml_attr_soft
(
param
,
"name"
);
char
*
val
=
(
char
*
)
switch_xml_attr_soft
(
param
,
"value"
);
if
(
!
strcasecmp
(
var
,
"default-bitrate"
))
{
globals
.
default_bitrate
=
atoi
(
val
);
}
}
}
}
/* connect my internal structure to the blank pointer passed to me */
/* connect my internal structure to the blank pointer passed to me */
*
module_interface
=
&
amr_module_interface
;
*
module_interface
=
&
amr_module_interface
;
...
...
src/switch_core.c
浏览文件 @
67284236
...
@@ -1570,6 +1570,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
...
@@ -1570,6 +1570,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
switch_io_event_hook_read_frame_t
*
ptr
;
switch_io_event_hook_read_frame_t
*
ptr
;
switch_status_t
status
;
switch_status_t
status
;
int
need_codec
,
perfect
,
do_bugs
=
0
;
int
need_codec
,
perfect
,
do_bugs
=
0
;
unsigned
int
flag
=
0
;
top
:
top
:
status
=
SWITCH_STATUS_FALSE
;
status
=
SWITCH_STATUS_FALSE
;
...
@@ -1636,7 +1637,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
...
@@ -1636,7 +1637,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
switch_frame_t
*
enc_frame
,
*
read_frame
=
*
frame
;
switch_frame_t
*
enc_frame
,
*
read_frame
=
*
frame
;
if
(
read_frame
->
codec
)
{
if
(
read_frame
->
codec
)
{
unsigned
int
flag
=
0
;
session
->
raw_read_frame
.
datalen
=
session
->
raw_read_frame
.
buflen
;
session
->
raw_read_frame
.
datalen
=
session
->
raw_read_frame
.
buflen
;
status
=
switch_core_codec_decode
(
read_frame
->
codec
,
status
=
switch_core_codec_decode
(
read_frame
->
codec
,
session
->
read_codec
,
session
->
read_codec
,
...
@@ -1718,8 +1718,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
...
@@ -1718,8 +1718,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
}
}
if
(
perfect
||
switch_buffer_inuse
(
session
->
raw_read_buffer
)
>=
session
->
read_codec
->
implementation
->
bytes_per_frame
)
{
if
(
perfect
||
switch_buffer_inuse
(
session
->
raw_read_buffer
)
>=
session
->
read_codec
->
implementation
->
bytes_per_frame
)
{
unsigned
int
flag
=
0
;
if
(
perfect
)
{
if
(
perfect
)
{
enc_frame
=
*
frame
;
enc_frame
=
*
frame
;
session
->
raw_read_frame
.
rate
=
(
*
frame
)
->
rate
;
session
->
raw_read_frame
.
rate
=
(
*
frame
)
->
rate
;
...
@@ -1773,6 +1771,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
...
@@ -1773,6 +1771,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
done
:
done
:
if
(
!
(
*
frame
))
{
if
(
!
(
*
frame
))
{
status
=
SWITCH_STATUS_FALSE
;
status
=
SWITCH_STATUS_FALSE
;
}
else
{
if
(
flag
&
SFF_CNG
)
{
switch_set_flag
((
*
frame
),
SFF_CNG
);
}
}
}
return
status
;
return
status
;
...
@@ -1988,7 +1990,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
...
@@ -1988,7 +1990,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
write_frame
=
NULL
;
write_frame
=
NULL
;
return
status
;
return
status
;
}
}
if
(
flag
&
SFF_CNG
)
{
switch_set_flag
(
write_frame
,
SFF_CNG
);
}
status
=
perform_write
(
session
,
write_frame
,
timeout
,
io_flag
,
stream_id
);
status
=
perform_write
(
session
,
write_frame
,
timeout
,
io_flag
,
stream_id
);
return
status
;
return
status
;
}
else
{
}
else
{
...
@@ -2063,6 +2067,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
...
@@ -2063,6 +2067,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
write_frame
->
datalen
=
session
->
read_resampler
->
to_len
*
2
;
write_frame
->
datalen
=
session
->
read_resampler
->
to_len
*
2
;
write_frame
->
rate
=
session
->
read_resampler
->
to_rate
;
write_frame
->
rate
=
session
->
read_resampler
->
to_rate
;
}
}
if
(
flag
&
SFF_CNG
)
{
switch_set_flag
(
write_frame
,
SFF_CNG
);
}
if
((
status
=
perform_write
(
session
,
write_frame
,
timeout
,
io_flag
,
stream_id
))
!=
SWITCH_STATUS_SUCCESS
)
{
if
((
status
=
perform_write
(
session
,
write_frame
,
timeout
,
io_flag
,
stream_id
))
!=
SWITCH_STATUS_SUCCESS
)
{
break
;
break
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论