接上2篇文章,我们已经理解了,对讲开启录像后,我们有哪些地方使用了编解码。
那么接下来,我们如何提升性能呢?使同样配置的机器支持对讲录像数翻倍呢?
解题思路:
修改video_bridge_thread逻辑,通过switch_core_session_read_video_frame读取原始帧,不做编解码,直接switch_core_session_write_video_frame发送给终端,然后解码,写入bugs。
效果:
1.录像线程使用软编码将视频帧生成录像文件。(1路编码,用于合成2个终端画面)
2.视频桥线程,由于开启了通道(bugs),会将视频帧软编码后,再发送给其他终端。(2路减为0路,因为直接透传的)
直接上部分代码:
static void video_bridge_thread(switch_core_session_t *session, void *obj) 将读写合并成一个方法switch_core_session_read_write_video_frame
while (switch_channel_up_nosig(channel) && switch_channel_up_nosig(b_channel) && vh->up == 1) {
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);
if (switch_core_session_transcoding(vh->session_a, vh->session_b, SWITCH_MEDIA_TYPE_VIDEO)) {
pass_val = 1;
} else {
pass_val = 2;
}
if (pass_val != last_pass_val) {
switch_core_session_passthru(session, SWITCH_MEDIA_TYPE_VIDEO, pass_val == 2 ? SWITCH_TRUE : SWITCH_FALSE);
last_pass_val = pass_val;
}
if (switch_channel_test_flag(channel, CF_VIDEO_REFRESH_REQ)) {
switch_channel_clear_flag(channel, CF_VIDEO_REFRESH_REQ);
refresh_timer = refresh_cnt;
}
if (!switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
switch_assert(a_codec);
switch_assert(b_codec);
if (switch_channel_test_flag(channel, CF_VIDEO_DECODED_READ)) {
if (a_codec->implementation->impl_id == b_codec->implementation->impl_id && !switch_channel_test_flag(b_channel, CF_VIDEO_DECODED_READ)) {
if (set_decoded_read) {
switch_channel_clear_flag_recursive(channel, CF_VIDEO_DECODED_READ);
set_decoded_read = 0;
refresh_timer = refresh_cnt;
}
}
} else {
if (a_codec->implementation->impl_id != b_codec->implementation->impl_id ||
switch_channel_test_flag(b_channel, C