Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
93e401e7
提交
93e401e7
authored
5月 24, 2016
作者:
Seven Du
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-8979 #resolve #comment please test
上级
d8164a95
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
87 行增加
和
2 行删除
+87
-2
mod_imagick.c
src/mod/formats/mod_imagick/mod_imagick.c
+87
-2
没有找到文件。
src/mod/formats/mod_imagick/mod_imagick.c
浏览文件 @
93e401e7
...
@@ -61,8 +61,15 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_imagick_load);
...
@@ -61,8 +61,15 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_imagick_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_imagick_shutdown
);
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_imagick_shutdown
);
SWITCH_MODULE_DEFINITION
(
mod_imagick
,
mod_imagick_load
,
mod_imagick_shutdown
,
NULL
);
SWITCH_MODULE_DEFINITION
(
mod_imagick
,
mod_imagick_load
,
mod_imagick_shutdown
,
NULL
);
typedef
enum
pdf_loading_state_s
{
PLS_LOADING
,
PLS_BREAK
,
PLS_DONE
}
pdf_loading_state_t
;
struct
pdf_file_context
{
struct
pdf_file_context
{
switch_memory_pool_t
*
pool
;
switch_memory_pool_t
*
pool
;
switch_mutex_t
*
mutex
;
switch_image_t
*
img
;
switch_image_t
*
img
;
int
reads
;
int
reads
;
int
sent
;
int
sent
;
...
@@ -75,16 +82,51 @@ struct pdf_file_context {
...
@@ -75,16 +82,51 @@ struct pdf_file_context {
Image
*
images
;
Image
*
images
;
ExceptionInfo
*
exception
;
ExceptionInfo
*
exception
;
int
autoplay
;
int
autoplay
;
const
char
*
path
;
int
lazy
;
pdf_loading_state_t
loading_state
;
switch_time_t
next_play_time
;
switch_time_t
next_play_time
;
};
};
typedef
struct
pdf_file_context
pdf_file_context_t
;
typedef
struct
pdf_file_context
pdf_file_context_t
;
static
void
*
SWITCH_THREAD_FUNC
open_pdf_thread_run
(
switch_thread_t
*
thread
,
void
*
obj
)
{
pdf_file_context_t
*
context
=
(
pdf_file_context_t
*
)
obj
;
int
pagenumber
=
context
->
lazy
;
char
path
[
1024
];
while
(
context
->
loading_state
==
PLS_LOADING
)
{
Image
*
tmp_images
;
switch_snprintf
(
path
,
sizeof
(
path
),
"%s[%d]"
,
context
->
path
,
pagenumber
);
switch_set_string
(
context
->
image_info
->
filename
,
path
);
if
((
tmp_images
=
ReadImages
(
context
->
image_info
,
context
->
exception
)))
{
pagenumber
++
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"%s page %d loaded
\n
"
,
context
->
path
,
pagenumber
);
AppendImageToList
(
&
context
->
images
,
tmp_images
);
context
->
pagecount
=
pagenumber
;
}
else
{
break
;
}
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"read file: %s %s, pagecount: %d
\n
"
,
context
->
path
,
context
->
loading_state
==
PLS_BREAK
?
"break"
:
"done"
,
pagenumber
);
switch_mutex_lock
(
context
->
mutex
);
context
->
loading_state
=
PLS_DONE
;
switch_mutex_unlock
(
context
->
mutex
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Read Images Thread Ended.
\n
"
);
return
NULL
;
}
static
switch_status_t
imagick_file_open
(
switch_file_handle_t
*
handle
,
const
char
*
path
)
static
switch_status_t
imagick_file_open
(
switch_file_handle_t
*
handle
,
const
char
*
path
)
{
{
pdf_file_context_t
*
context
;
pdf_file_context_t
*
context
;
char
*
ext
;
char
*
ext
;
unsigned
int
flags
=
0
;
unsigned
int
flags
=
0
;
char
range_path
[
1024
];
if
((
ext
=
strrchr
((
char
*
)
path
,
'.'
))
==
0
)
{
if
((
ext
=
strrchr
((
char
*
)
path
,
'.'
))
==
0
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid Format
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid Format
\n
"
);
...
@@ -121,13 +163,14 @@ static switch_status_t imagick_file_open(switch_file_handle_t *handle, const cha
...
@@ -121,13 +163,14 @@ static switch_status_t imagick_file_open(switch_file_handle_t *handle, const cha
context
->
exception
=
AcquireExceptionInfo
();
context
->
exception
=
AcquireExceptionInfo
();
context
->
image_info
=
AcquireImageInfo
();
context
->
image_info
=
AcquireImageInfo
();
switch_set_string
(
context
->
image_info
->
filename
,
path
);
context
->
path
=
switch_core_strdup
(
handle
->
memory_pool
,
path
);
if
(
handle
->
params
)
{
if
(
handle
->
params
)
{
const
char
*
max
=
switch_event_get_header
(
handle
->
params
,
"img_ms"
);
const
char
*
max
=
switch_event_get_header
(
handle
->
params
,
"img_ms"
);
const
char
*
autoplay
=
switch_event_get_header
(
handle
->
params
,
"autoplay"
);
const
char
*
autoplay
=
switch_event_get_header
(
handle
->
params
,
"autoplay"
);
const
char
*
density
=
switch_event_get_header
(
handle
->
params
,
"density"
);
const
char
*
density
=
switch_event_get_header
(
handle
->
params
,
"density"
);
const
char
*
quality
=
switch_event_get_header
(
handle
->
params
,
"quality"
);
const
char
*
quality
=
switch_event_get_header
(
handle
->
params
,
"quality"
);
const
char
*
lazy
=
switch_event_get_header
(
handle
->
params
,
"lazy"
);
int
tmp
;
int
tmp
;
if
(
max
)
{
if
(
max
)
{
...
@@ -148,6 +191,23 @@ static switch_status_t imagick_file_open(switch_file_handle_t *handle, const cha
...
@@ -148,6 +191,23 @@ static switch_status_t imagick_file_open(switch_file_handle_t *handle, const cha
if
(
tmp
>
0
)
context
->
image_info
->
quality
=
tmp
;
if
(
tmp
>
0
)
context
->
image_info
->
quality
=
tmp
;
}
}
if
(
lazy
)
{
int
tmp
=
atoi
(
lazy
);
if
(
tmp
>=
0
)
{
context
->
lazy
=
tmp
;
}
else
{
context
->
lazy
=
1
;
}
}
}
if
(
context
->
lazy
)
{
switch_snprintf
(
range_path
,
sizeof
(
range_path
),
"%s[0-%d]"
,
path
,
context
->
lazy
-
1
);
switch_set_string
(
context
->
image_info
->
filename
,
range_path
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"loading first %d page%s
\n
"
,
context
->
lazy
,
context
->
lazy
>
1
?
"s"
:
""
);
}
else
{
switch_set_string
(
context
->
image_info
->
filename
,
path
);
}
}
context
->
images
=
ReadImages
(
context
->
image_info
,
context
->
exception
);
context
->
images
=
ReadImages
(
context
->
image_info
,
context
->
exception
);
...
@@ -175,7 +235,20 @@ static switch_status_t imagick_file_open(switch_file_handle_t *handle, const cha
...
@@ -175,7 +235,20 @@ static switch_status_t imagick_file_open(switch_file_handle_t *handle, const cha
handle
->
private_info
=
context
;
handle
->
private_info
=
context
;
context
->
pool
=
handle
->
memory_pool
;
context
->
pool
=
handle
->
memory_pool
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Opening File [%s], pagecount: %d
\n
"
,
path
,
context
->
pagecount
);
if
(
context
->
lazy
)
{
switch_thread_t
*
thread
;
switch_threadattr_t
*
thd_attr
=
NULL
;
switch_mutex_init
(
&
context
->
mutex
,
SWITCH_MUTEX_NESTED
,
context
->
pool
);
context
->
loading_state
=
PLS_LOADING
;
switch_thread_create
(
&
thread
,
thd_attr
,
open_pdf_thread_run
,
context
,
context
->
pool
);
}
if
(
context
->
lazy
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Opening File %s, read the first %d page(s)"
,
path
,
context
->
lazy
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Opening File %s"
,
path
);
}
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
...
@@ -184,6 +257,18 @@ static switch_status_t imagick_file_close(switch_file_handle_t *handle)
...
@@ -184,6 +257,18 @@ static switch_status_t imagick_file_close(switch_file_handle_t *handle)
{
{
pdf_file_context_t
*
context
=
(
pdf_file_context_t
*
)
handle
->
private_info
;
pdf_file_context_t
*
context
=
(
pdf_file_context_t
*
)
handle
->
private_info
;
if
(
context
->
lazy
)
{
switch_mutex_lock
(
context
->
mutex
);
if
(
context
->
loading_state
==
PLS_LOADING
)
context
->
loading_state
=
PLS_BREAK
;
switch_mutex_unlock
(
context
->
mutex
);
while
(
context
->
loading_state
!=
PLS_DONE
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"waiting for pdf loading thread done, loading_state: %d
\n
"
,
context
->
loading_state
);
switch_yield
(
1000000
);
switch_cond_next
();
}
}
switch_img_free
(
&
context
->
img
);
switch_img_free
(
&
context
->
img
);
if
(
context
->
images
)
DestroyImageList
(
context
->
images
);
if
(
context
->
images
)
DestroyImageList
(
context
->
images
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论