Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
c70f06aa
提交
c70f06aa
authored
9月 20, 2016
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-9553 #resolve [Refactor video-on-hold]
上级
93591e2f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
81 行增加
和
73 行删除
+81
-73
switch_core_media.c
src/switch_core_media.c
+79
-4
switch_ivr_bridge.c
src/switch_ivr_bridge.c
+2
-69
没有找到文件。
src/switch_core_media.c
浏览文件 @
c70f06aa
...
...
@@ -5187,6 +5187,59 @@ SWITCH_DECLARE(switch_file_handle_t *) switch_core_media_get_video_file(switch_c
return fh;
}
static void switch_core_session_write_blank_video(switch_core_session_t *session, uint32_t ms)
{
switch_frame_t fr = { 0 };
int i = 0;
switch_rgb_color_t bgcolor = { 0 };
int buflen = SWITCH_RTP_MAX_BUF_LEN;
unsigned char buf[SWITCH_RTP_MAX_BUF_LEN];
switch_media_handle_t *smh;
switch_image_t *blank_img = NULL;
uint32_t frames = 0, frame_ms = 0;
uint32_t fps, width, height;
switch_assert(session != NULL);
if (!(smh = session->media_handle)) {
return;
}
fps = smh->vid_params.fps;
width = smh->vid_params.width;
height = smh->vid_params.height;
if (!width) width = 640;
if (!height) height = 480;
if (!fps) fps = 15;
if (!(width && height && fps)) {
return;
}
fr.packet = buf;
fr.packetlen = buflen;
fr.data = buf + 12;
fr.buflen = buflen - 12;
blank_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, height, 1);
switch_color_set_rgb(&bgcolor, "#000000");
switch_img_fill(blank_img, 0, 0, blank_img->d_w, blank_img->d_h, &bgcolor);
frame_ms = (uint32_t) 1000 / fps;
frames = (uint32_t) ms / frame_ms;
switch_core_media_gen_key_frame(session);
for (i = 0; i < frames; i++) {
switch_core_session_write_video_frame(session, &fr, SWITCH_IO_FLAG_NONE, 0);
switch_yield(frame_ms * 1000);
}
switch_core_media_gen_key_frame(session);
switch_img_free(&blank_img);
}
static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void *obj)
{
...
...
@@ -5199,6 +5252,7 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void
switch_timer_t timer = { 0 };
int fps;
switch_video_read_flag_t read_flags = SVR_FLUSH|SVR_BLOCK;
switch_core_session_t *b_session = NULL;
if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
return NULL;
...
...
@@ -5208,7 +5262,15 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void
return NULL;
}
switch_core_session_get_partner(session, &b_session);
switch_channel_set_flag(session->channel, CF_VIDEO_WRITING);
switch_channel_set_flag(session->channel, CF_VIDEO_PAUSE_READ);
if (b_session) {
switch_channel_set_flag(b_session->channel, CF_VIDEO_PAUSE_READ);
switch_channel_set_flag(b_session->channel, CF_VIDEO_BLANK);
}
v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
...
...
@@ -5241,7 +5303,7 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void
switch_core_timer_next(&timer);
switch_mutex_lock(v_engine->mh.file_write_mutex);
if (smh->video_write_fh->mm.source_fps && smh->video_write_fh->mm.source_fps != fps) {
if (smh->video_write_fh
&& smh->video_write_fh
->mm.source_fps && smh->video_write_fh->mm.source_fps != fps) {
switch_core_timer_destroy(&timer);
switch_core_timer_init(&timer, "soft", (int)(1000 / fps) , 1, switch_core_session_get_pool(session));
}
...
...
@@ -5250,7 +5312,7 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void
wstatus = switch_core_file_read_video(smh->video_write_fh, &fr, read_flags);
if (wstatus == SWITCH_STATUS_SUCCESS) {
switch_core_session_write_video_frame(session, &fr, SWITCH_IO_FLAG_
NON
E, SVR_FLUSH);
switch_core_session_write_video_frame(session, &fr, SWITCH_IO_FLAG_
FORC
E, SVR_FLUSH);
switch_img_free(&fr.img);
} else if (wstatus != SWITCH_STATUS_BREAK && wstatus != SWITCH_STATUS_IGNORE) {
switch_set_flag_locked(smh->video_write_fh, SWITCH_FILE_FLAG_VIDEO_EOF);
...
...
@@ -5263,6 +5325,13 @@ static void *SWITCH_THREAD_FUNC video_write_thread(switch_thread_t *thread, void
switch_core_session_rwunlock(session);
if (b_session) {
switch_channel_clear_flag(b_session->channel, CF_VIDEO_PAUSE_READ);
switch_channel_clear_flag(b_session->channel, CF_VIDEO_BLANK);
switch_core_session_rwunlock(b_session);
}
switch_channel_clear_flag(session->channel, CF_VIDEO_PAUSE_READ);
switch_channel_clear_flag(session->channel, CF_VIDEO_WRITING);
smh->video_write_thread_running = 0;
...
...
@@ -5396,7 +5465,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_ses
if (fh) {
switch_threadattr_t *thd_attr = NULL;
switch_core_session_write_blank_video(session, 200);
switch_threadattr_create(&thd_attr, switch_core_session_get_pool(session));
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
smh->video_write_thread_running = 1;
...
...
@@ -5413,6 +5482,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_set_video_file(switch_core_ses
switch_thread_join(&st, smh->video_write_thread);
switch_mutex_lock(v_engine->mh.file_write_mutex);
smh->video_write_thread = NULL;
switch_core_session_write_blank_video(session, 200);
}
smh->video_write_fh = fh;
...
...
@@ -5581,7 +5651,7 @@ static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, voi
switch_mutex_unlock(mh->file_read_mutex);
}
if (
switch_channel_test_flag(channel, CF_VIDEO_WRITING) || session->video_read_callback
) {
if (
(switch_channel_test_flag(channel, CF_VIDEO_WRITING) || session->video_read_callback) && !switch_channel_test_flag(channel, CF_VIDEO_BLANK)
) {
send_blank = 0;
}
...
...
@@ -11326,6 +11396,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_video_frame(switch_cor
return SWITCH_STATUS_FALSE;
}
if (switch_channel_test_flag(session->channel, CF_VIDEO_WRITING) && !(flags & SWITCH_IO_FLAG_FORCE)) {
return SWITCH_STATUS_SUCCESS;
}
if (switch_core_session_media_flow(session, SWITCH_MEDIA_TYPE_VIDEO) == SWITCH_MEDIA_FLOW_RECVONLY || switch_core_session_media_flow(session, SWITCH_MEDIA_TYPE_VIDEO) == SWITCH_MEDIA_FLOW_INACTIVE) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG3, "Writing video to RECVONLY/INACTIVE session\n");
return SWITCH_STATUS_SUCCESS;
...
...
@@ -11585,6 +11659,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_video_frame(switch_core
if (switch_channel_test_flag(session->channel, CF_VIDEO_PAUSE_READ)) {
*frame = &runtime.dummy_cng_frame;
switch_channel_video_sync(session->channel);
switch_cond_next();
return SWITCH_STATUS_SUCCESS;
}
...
...
src/switch_ivr_bridge.c
浏览文件 @
c70f06aa
...
...
@@ -53,13 +53,8 @@ static void video_bridge_thread(switch_core_session_t *session, void *obj)
switch_channel_t
*
b_channel
=
switch_core_session_get_channel
(
vh
->
session_b
);
switch_status_t
status
;
switch_frame_t
*
read_frame
=
0
;
int
set_decoded_read
=
0
,
refresh_timer
=
0
,
playing_file
=
0
;
switch_frame_t
fr
=
{
0
};
unsigned
char
*
buf
=
NULL
;
int
send_blank
=
0
;
int
set_decoded_read
=
0
,
refresh_timer
=
0
;
int
refresh_cnt
=
300
;
int
blank_cnt
=
30
;
switch_image_t
*
blank_img
=
NULL
;
vh
->
up
=
1
;
...
...
@@ -75,7 +70,7 @@ static void video_bridge_thread(switch_core_session_t *session, void *obj)
if
(
switch_channel_media_up
(
channel
))
{
switch_codec_t
*
a_codec
=
switch_core_session_get_video_read_codec
(
vh
->
session_a
);
switch_codec_t
*
b_codec
=
switch_core_session_get_video_write_codec
(
vh
->
session_b
);
switch_file_handle_t
*
fh
;
if
(
switch_channel_test_flag
(
channel
,
CF_VIDEO_REFRESH_REQ
))
{
refresh_timer
=
refresh_cnt
;
...
...
@@ -113,66 +108,6 @@ static void video_bridge_thread(switch_core_session_t *session, void *obj)
refresh_timer
--
;
}
if
(
send_blank
)
{
send_blank
--
;
fr
.
img
=
blank_img
;
switch_core_media_gen_key_frame
(
session
);
switch_core_session_write_video_frame
(
session
,
&
fr
,
SWITCH_IO_FLAG_NONE
,
0
);
switch_yield
(
30000
);
continue
;
}
if
((
fh
=
switch_core_media_get_video_file
(
session
,
SWITCH_RW_WRITE
))
&&
switch_test_flag
(
fh
,
SWITCH_FILE_OPEN
))
{
switch_status_t
wstatus
;
if
(
!
buf
)
{
int
buflen
=
SWITCH_RTP_MAX_BUF_LEN
;
buf
=
switch_core_session_alloc
(
session
,
buflen
);
fr
.
packet
=
buf
;
fr
.
packetlen
=
buflen
;
fr
.
data
=
buf
+
12
;
fr
.
buflen
=
buflen
-
12
;
}
wstatus
=
switch_core_file_read_video
(
fh
,
&
fr
,
SVR_FLUSH
|
SVR_BLOCK
);
if
(
!
blank_img
&&
fr
.
img
)
{
switch_rgb_color_t
bgcolor
=
{
0
};
blank_img
=
switch_img_alloc
(
NULL
,
SWITCH_IMG_FMT_I420
,
fr
.
img
->
d_w
,
fr
.
img
->
d_h
,
1
);
switch_color_set_rgb
(
&
bgcolor
,
"#000000"
);
switch_img_fill
(
blank_img
,
0
,
0
,
blank_img
->
d_w
,
blank_img
->
d_h
,
&
bgcolor
);
}
if
(
!
playing_file
)
{
playing_file
=
1
;
switch_core_media_gen_key_frame
(
session
);
send_blank
=
blank_cnt
;
refresh_timer
=
refresh_cnt
;
switch_channel_video_sync
(
channel
);
switch_channel_video_sync
(
b_channel
);
continue
;
}
if
(
wstatus
==
SWITCH_STATUS_SUCCESS
)
{
switch_core_session_write_video_frame
(
session
,
&
fr
,
SWITCH_IO_FLAG_NONE
,
0
);
switch_img_free
(
&
fr
.
img
);
}
else
if
(
wstatus
!=
SWITCH_STATUS_BREAK
)
{
switch_core_media_set_video_file
(
session
,
NULL
,
SWITCH_RW_WRITE
);
}
continue
;
}
if
(
playing_file
)
{
playing_file
=
0
;
send_blank
=
blank_cnt
;
refresh_timer
=
refresh_cnt
;
switch_channel_video_sync
(
channel
);
switch_channel_video_sync
(
b_channel
);
}
status
=
switch_core_session_read_video_frame
(
vh
->
session_a
,
&
read_frame
,
SWITCH_IO_FLAG_NONE
,
0
);
if
(
!
SWITCH_READ_ACCEPTABLE
(
status
))
{
...
...
@@ -202,8 +137,6 @@ static void video_bridge_thread(switch_core_session_t *session, void *obj)
}
}
switch_img_free
(
&
blank_img
);
if
(
set_decoded_read
)
{
switch_channel_clear_flag_recursive
(
channel
,
CF_VIDEO_DECODED_READ
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论