Freeswitch 如何提升性能减少编码次数

本文探讨了如何通过修改video_bridge_thread逻辑,使用switch_core_session_read_write_video_frame来合并读写操作,避免不必要的编解码,从而提升Freeswitch的性能。这种方法使相同配置的机器能够支持翻倍的对讲录像数。文章提供了关键代码片段以展示如何实现这一优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

接上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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值