Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
b3d2c921
提交
b3d2c921
authored
6月 08, 2015
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-7621
上级
f8853ac6
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
49 行增加
和
36 行删除
+49
-36
mod_shout.c
src/mod/formats/mod_shout/mod_shout.c
+49
-36
没有找到文件。
src/mod/formats/mod_shout/mod_shout.c
浏览文件 @
b3d2c921
...
...
@@ -117,7 +117,6 @@ struct shout_context {
int
dlen
;
FILE
*
fp
;
size_t
samplerate
;
uint8_t
thread_running
;
uint8_t
shout_init
;
uint32_t
prebuf
;
int
lame_ready
;
...
...
@@ -128,6 +127,9 @@ struct shout_context {
switch_size_t
mp3buflen
;
switch_thread_rwlock_t
*
rwlock
;
int
buffer_seconds
;
switch_thread_t
*
read_stream_thread
;
switch_thread_t
*
write_stream_thread
;
curl_socket_t
curlfd
;
};
typedef
struct
shout_context
shout_context_t
;
...
...
@@ -137,6 +139,7 @@ static void decode_fd(shout_context_t *context, void *data, size_t bytes);
static
inline
void
free_context
(
shout_context_t
*
context
)
{
size_t
ret
;
switch_status_t
st
;
if
(
context
)
{
switch_mutex_lock
(
context
->
audio_mutex
);
...
...
@@ -144,18 +147,19 @@ static inline void free_context(shout_context_t *context)
switch_mutex_unlock
(
context
->
audio_mutex
);
if
(
context
->
stream_url
)
{
int
sanity
=
0
;
while
(
context
->
thread_running
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Waiting for stream to terminate: %s
\n
"
,
context
->
stream_url
);
switch_yield
(
500000
);
if
(
++
sanity
>
10
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Giving up waiting for stream to terminate: %s
\n
"
,
context
->
stream_url
);
break
;
}
if
(
context
->
curlfd
>
-
1
)
{
shutdown
(
context
->
curlfd
,
2
);
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Waiting for stream to terminate: %s
\n
"
,
context
->
stream_url
);
if
(
context
->
read_stream_thread
)
{
switch_thread_join
(
&
st
,
context
->
read_stream_thread
);
}
}
if
(
context
->
write_stream_thread
)
{
switch_thread_join
(
&
st
,
context
->
write_stream_thread
);
}
switch_thread_rwlock_wrlock
(
context
->
rwlock
);
if
(
context
->
mh
)
{
...
...
@@ -368,6 +372,10 @@ static size_t stream_callback(void *ptr, size_t size, size_t nmemb, void *data)
uint32_t
buf_size
=
1024
*
128
;
/* do not make this 64 or less, stutter will ensue after first 64k buffer is dry */
switch_size_t
used
;
if
(
context
->
err
)
{
goto
error
;
}
if
(
!
context
->
stream_channels
)
{
long
rate
=
0
;
int
channels
=
0
;
...
...
@@ -398,6 +406,10 @@ static size_t stream_callback(void *ptr, size_t size, size_t nmemb, void *data)
switch_yield
(
500000
);
}
if
(
context
->
err
)
{
goto
error
;
}
if
(
mpg123_feed
(
context
->
mh
,
ptr
,
realsize
)
!=
MPG123_OK
)
{
goto
error
;
}
...
...
@@ -442,6 +454,22 @@ static size_t stream_callback(void *ptr, size_t size, size_t nmemb, void *data)
return
0
;
}
static
int
progress_callback
(
void
*
clientp
,
double
dltotal
,
double
dlnow
,
double
ultotal
,
double
ulnow
)
{
shout_context_t
*
context
=
(
shout_context_t
*
)
clientp
;
return
context
->
err
;
}
static
int
sockopt_callback
(
void
*
clientp
,
curl_socket_t
curlfd
,
curlsocktype
purpose
)
{
shout_context_t
*
context
=
(
shout_context_t
*
)
clientp
;
context
->
curlfd
=
curlfd
;
return
CURL_SOCKOPT_OK
;
}
#define MY_BUF_LEN 1024 * 32
#define MY_BLOCK_SIZE MY_BUF_LEN
...
...
@@ -452,9 +480,11 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
shout_context_t
*
context
=
(
shout_context_t
*
)
obj
;
switch_thread_rwlock_rdlock
(
context
->
rwlock
);
context
->
curlfd
=
-
1
;
curl_handle
=
switch_curl_easy_init
();
switch_curl_easy_setopt
(
curl_handle
,
CURLOPT_URL
,
context
->
stream_url
);
curl_easy_setopt
(
curl_handle
,
CURLOPT_PROGRESSFUNCTION
,
progress_callback
);
curl_easy_setopt
(
curl_handle
,
CURLOPT_PROGRESSDATA
,
(
void
*
)
context
);
switch_curl_easy_setopt
(
curl_handle
,
CURLOPT_FOLLOWLOCATION
,
1
);
switch_curl_easy_setopt
(
curl_handle
,
CURLOPT_MAXREDIRS
,
10
);
switch_curl_easy_setopt
(
curl_handle
,
CURLOPT_WRITEFUNCTION
,
stream_callback
);
...
...
@@ -465,7 +495,11 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
switch_curl_easy_setopt
(
curl_handle
,
CURLOPT_LOW_SPEED_LIMIT
,
100
);
/* handle trickle connections */
switch_curl_easy_setopt
(
curl_handle
,
CURLOPT_LOW_SPEED_TIME
,
30
);
switch_curl_easy_setopt
(
curl_handle
,
CURLOPT_ERRORBUFFER
,
context
->
curl_error_buff
);
curl_easy_setopt
(
curl_handle
,
CURLOPT_SOCKOPTFUNCTION
,
sockopt_callback
);
curl_easy_setopt
(
curl_handle
,
CURLOPT_SOCKOPTDATA
,
(
void
*
)
context
);
cc
=
switch_curl_easy_perform
(
curl_handle
);
if
(
cc
&&
cc
!=
CURLE_WRITE_ERROR
)
{
/* write error is ok, we just exited from callback early */
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"CURL returned error:[%d] %s : %s [%s]
\n
"
,
cc
,
switch_curl_easy_strerror
(
cc
),
context
->
curl_error_buff
,
context
->
stream_url
);
...
...
@@ -474,21 +508,17 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Read Thread Done
\n
"
);
context
->
eof
++
;
context
->
thread_running
=
0
;
switch_thread_rwlock_unlock
(
context
->
rwlock
);
return
NULL
;
}
static
void
launch_read_stream_thread
(
shout_context_t
*
context
)
{
switch_thread_t
*
thread
;
switch_threadattr_t
*
thd_attr
=
NULL
;
context
->
thread_running
=
1
;
switch_threadattr_create
(
&
thd_attr
,
context
->
memory_pool
);
switch_threadattr_detach_set
(
thd_attr
,
1
);
switch_threadattr_stacksize_set
(
thd_attr
,
SWITCH_THREAD_STACKSIZE
);
switch_thread_create
(
&
thread
,
thd_attr
,
read_stream_thread
,
context
,
context
->
memory_pool
);
switch_thread_create
(
&
context
->
read_stream_
thread
,
thd_attr
,
read_stream_thread
,
context
,
context
->
memory_pool
);
}
#define error_check() if (context->err) goto error;
...
...
@@ -499,20 +529,13 @@ static void *SWITCH_THREAD_FUNC write_stream_thread(switch_thread_t *thread, voi
switch_thread_rwlock_rdlock
(
context
->
rwlock
);
if
(
context
->
thread_running
)
{
context
->
thread_running
++
;
}
else
{
switch_thread_rwlock_unlock
(
context
->
rwlock
);
return
NULL
;
}
if
(
!
context
->
lame_ready
)
{
lame_init_params
(
context
->
gfp
);
lame_print_config
(
context
->
gfp
);
context
->
lame_ready
=
1
;
}
while
(
!
context
->
err
&&
context
->
thread_running
)
{
while
(
!
context
->
err
)
{
unsigned
char
mp3buf
[
20480
]
=
""
;
int16_t
audio
[
9600
]
=
{
0
};
switch_size_t
audio_read
=
0
;
...
...
@@ -575,31 +598,21 @@ static void *SWITCH_THREAD_FUNC write_stream_thread(switch_thread_t *thread, voi
error:
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Write Thread Done
\n
"
);
switch_thread_rwlock_unlock
(
context
->
rwlock
);
context
->
thread_running
=
0
;
return
NULL
;
}
static
void
launch_write_stream_thread
(
shout_context_t
*
context
)
{
switch_thread_t
*
thread
;
switch_threadattr_t
*
thd_attr
=
NULL
;
int
sanity
=
10
;
if
(
context
->
err
)
{
return
;
}
context
->
thread_running
=
1
;
switch_threadattr_create
(
&
thd_attr
,
context
->
memory_pool
);
switch_threadattr_detach_set
(
thd_attr
,
1
);
switch_threadattr_stacksize_set
(
thd_attr
,
SWITCH_THREAD_STACKSIZE
);
switch_thread_create
(
&
thread
,
thd_attr
,
write_stream_thread
,
context
,
context
->
memory_pool
);
while
(
context
->
thread_running
&&
context
->
thread_running
!=
2
)
{
switch_yield
(
100000
);
if
(
!--
sanity
)
break
;
}
switch_thread_create
(
&
context
->
write_stream_thread
,
thd_attr
,
write_stream_thread
,
context
,
context
->
memory_pool
);
}
#define TC_BUFFER_SIZE 1024 * 32
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论