Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
bbfd9f7e
提交
bbfd9f7e
authored
3月 14, 2015
作者:
Seven Du
提交者:
Michael Jerris
5月 28, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
got webm working with mono, todo: stereo, syncing
上级
29bddbd3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
61 行增加
和
12 行删除
+61
-12
mod_vorbis.c
src/mod/formats/mod_webm/mod_vorbis.c
+61
-12
没有找到文件。
src/mod/formats/mod_webm/mod_vorbis.c
浏览文件 @
bbfd9f7e
...
@@ -37,6 +37,7 @@
...
@@ -37,6 +37,7 @@
// SWITCH_MODULE_DEFINITION(mod_vorbis, mod_vorbis_load, NULL, NULL);
// SWITCH_MODULE_DEFINITION(mod_vorbis, mod_vorbis_load, NULL, NULL);
#define SCC_GET_CODEC_PRIVATE SCC_VIDEO_BANDWIDTH
#define SCC_GET_CODEC_PRIVATE SCC_VIDEO_BANDWIDTH
// #define OGG_DEBUG // dump to a file
typedef
struct
vorbis_context_s
{
typedef
struct
vorbis_context_s
{
ogg_stream_state
os
;
/* take physical pages, weld into a logical stream of packets */
ogg_stream_state
os
;
/* take physical pages, weld into a logical stream of packets */
...
@@ -53,6 +54,11 @@ typedef struct vorbis_context_s {
...
@@ -53,6 +54,11 @@ typedef struct vorbis_context_s {
uint8_t
*
codec_private_data
;
uint8_t
*
codec_private_data
;
uint16_t
codec_private_data_len
;
uint16_t
codec_private_data_len
;
#ifdef OGG_DEBUG
int
fd
;
#endif
}
vorbis_context_t
;
}
vorbis_context_t
;
static
void
xiph_lacing
(
uint
x
,
uint8_t
**
buffer
)
static
void
xiph_lacing
(
uint
x
,
uint8_t
**
buffer
)
...
@@ -202,13 +208,38 @@ static switch_status_t switch_vorbis_init(switch_codec_t *codec, switch_codec_fl
...
@@ -202,13 +208,38 @@ static switch_status_t switch_vorbis_init(switch_codec_t *codec, switch_codec_fl
// headers
// headers
vorbis_analysis_headerout
(
&
context
->
vd
,
&
context
->
vc
,
&
context
->
header
,
&
context
->
header_comm
,
&
context
->
header_code
);
vorbis_analysis_headerout
(
&
context
->
vd
,
&
context
->
vc
,
&
context
->
header
,
&
context
->
header_comm
,
&
context
->
header_code
);
ogg_stream_init
(
&
context
->
os
,
rand
());
{
//hack so we can use the codec control
{
//hack so we can use the codec control
switch_codec_implementation_t
**
impl
=
(
switch_codec_implementation_t
**
)
&
codec
->
implementation
;
switch_codec_implementation_t
**
impl
=
(
switch_codec_implementation_t
**
)
&
codec
->
implementation
;
(
*
impl
)
->
codec_control
=
switch_vorbis_control
;
(
*
impl
)
->
codec_control
=
switch_vorbis_control
;
}
}
#ifdef OGG_DEBUG
ogg_stream_init
(
&
context
->
os
,
rand
());
context
->
fd
=
open
(
"/tmp/test.ogg"
,
O_CREAT
|
O_RDWR
|
O_TRUNC
,
0644
);
if
(
context
->
fd
<
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Error open file to write
\n
"
);
goto
error
;
}
ogg_stream_packetin
(
&
context
->
os
,
&
context
->
header
);
/* automatically placed in its own page */
ogg_stream_packetin
(
&
context
->
os
,
&
context
->
header_comm
);
ogg_stream_packetin
(
&
context
->
os
,
&
context
->
header_code
);
/* This ensures the actual
* audio data will start on a new page, as per spec
*/
while
(
1
){
int
result
=
ogg_stream_flush
(
&
context
->
os
,
&
context
->
og
);
if
(
result
==
0
)
break
;
write
(
context
->
fd
,
context
->
og
.
header
,
context
->
og
.
header_len
);
write
(
context
->
fd
,
context
->
og
.
body
,
context
->
og
.
body_len
);
}
#endif
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
error:
error:
...
@@ -228,22 +259,23 @@ static switch_status_t switch_vorbis_encode(switch_codec_t *codec,
...
@@ -228,22 +259,23 @@ static switch_status_t switch_vorbis_encode(switch_codec_t *codec,
unsigned
int
*
flag
)
unsigned
int
*
flag
)
{
{
vorbis_context_t
*
context
=
(
vorbis_context_t
*
)
codec
->
private_info
;
vorbis_context_t
*
context
=
(
vorbis_context_t
*
)
codec
->
private_info
;
int
i
;
int
i
,
j
;
uint32_t
len
=
0
;
uint32_t
len
=
0
;
uint16_t
*
data
=
(
u
int16_t
*
)
decoded_data
;
int16_t
*
data
=
(
int16_t
*
)
decoded_data
;
int
channels
=
codec
->
implementation
->
number_of_channels
;
int
channels
=
codec
->
implementation
->
number_of_channels
;
float
**
buffer
=
vorbis_analysis_buffer
(
&
context
->
vd
,
decoded_data_len
);
uint32_t
samples
=
decoded_data_len
/
2
/
channels
;
float
**
buffer
=
vorbis_analysis_buffer
(
&
context
->
vd
,
samples
);
// switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", decoded_data_len);
// switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", decoded_data_len);
for
(
i
=
0
;
i
<
decoded_data_len
*
channels
;
i
+=
channels
)
{
/* uninterleave samples */
buffer
[
0
][
i
]
=
*
(
data
+
i
)
/
32768
.
f
;
for
(
i
=
0
;
i
<
samples
;
i
++
)
{
if
(
channels
>
1
)
{
for
(
j
=
0
;
j
<
channels
;
j
++
)
{
buffer
[
1
][
i
]
=
*
(
data
+
i
+
1
)
/
32768
.
f
;
buffer
[
j
][
i
]
=
*
(
data
+
i
)
/
32768
.
f
;
}
}
}
}
vorbis_analysis_wrote
(
&
context
->
vd
,
decoded_data_len
);
vorbis_analysis_wrote
(
&
context
->
vd
,
samples
);
while
(
vorbis_analysis_blockout
(
&
context
->
vd
,
&
context
->
vb
)
==
1
)
{
while
(
vorbis_analysis_blockout
(
&
context
->
vd
,
&
context
->
vb
)
==
1
)
{
/* analysis, assume we want to use bitrate management */
/* analysis, assume we want to use bitrate management */
...
@@ -251,14 +283,27 @@ static switch_status_t switch_vorbis_encode(switch_codec_t *codec,
...
@@ -251,14 +283,27 @@ static switch_status_t switch_vorbis_encode(switch_codec_t *codec,
vorbis_bitrate_addblock
(
&
context
->
vb
);
vorbis_bitrate_addblock
(
&
context
->
vb
);
while
(
vorbis_bitrate_flushpacket
(
&
context
->
vd
,
&
context
->
op
)){
while
(
vorbis_bitrate_flushpacket
(
&
context
->
vd
,
&
context
->
op
)){
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"got %ld bytes pts: %lld
\n
"
,
context
->
op
.
bytes
,
context
->
op
.
granulepos
);
// switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "got %ld bytes pts: %lld\n", context->op.bytes, context->op.granulepos);
#ifdef OGG_DEBUG
ogg_stream_packetin
(
&
context
->
os
,
&
context
->
op
);
/* write out pages (if any) */
while
(
1
){
int
result
=
ogg_stream_pageout
(
&
context
->
os
,
&
context
->
og
);
if
(
result
==
0
)
break
;
write
(
context
->
fd
,
context
->
og
.
header
,
context
->
og
.
header_len
);
write
(
context
->
fd
,
context
->
og
.
body
,
context
->
og
.
body_len
);
}
#endif
if
(
len
+
context
->
op
.
bytes
>
*
encoded_data_len
)
{
if
(
len
+
context
->
op
.
bytes
>
*
encoded_data_len
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"buffer overflow %u
\n
"
,
*
encoded_data_len
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"buffer overflow %u
\n
"
,
*
encoded_data_len
);
break
;
break
;
}
}
memcpy
((
uint8_t
*
)
de
coded_data
+
len
,
context
->
op
.
packet
,
context
->
op
.
bytes
);
memcpy
((
uint8_t
*
)
en
coded_data
+
len
,
context
->
op
.
packet
,
context
->
op
.
bytes
);
len
+=
context
->
op
.
bytes
;
len
+=
context
->
op
.
bytes
;
}
}
}
}
...
@@ -287,6 +332,10 @@ static switch_status_t switch_vorbis_destroy(switch_codec_t *codec)
...
@@ -287,6 +332,10 @@ static switch_status_t switch_vorbis_destroy(switch_codec_t *codec)
vorbis_comment_clear
(
&
context
->
vc
);
vorbis_comment_clear
(
&
context
->
vc
);
vorbis_info_clear
(
&
context
->
vi
);
vorbis_info_clear
(
&
context
->
vi
);
#ifdef OGG_DEBUG
if
(
context
->
fd
>
-
1
)
close
(
context
->
fd
);
#endif
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论