天天看点

全网首发:FreeSwitch硬解失败后切换到软解

  给FreeSwitch集成了NV硬解。前几天突然报告说,登录A服务器,转发会议命令到B服务器后,一直没画面。跟踪了一下,是硬解一直失败。怎么办?先切换到软解,有时间再研究怎么回事。

  • 正常来说,开始的时候,硬解返回数据都是空(因为是异步的)。所以,吾设定失败16次后切换。
  • 切换代码如下:
static int init_decoder(h264_codec_context_t *context, final int hw, final int release)
{
    avcodec_profile_t *profile = NULL;
    profile = find_profile(get_profile_name(context->av_codec_id), SWITCH_FALSE);
    if (!profile) {
        return -1;
    }
 
    if (context->decoder_ctx && release)
    {
        if (context->decoder_ctx) {
            LOG_TEXT("avcodec_close()");
            if (avcodec_is_open(context->decoder_ctx)) avcodec_close(context->decoder_ctx);
            av_free(context->decoder_ctx);
            context->decoder_ctx = NULL;
        }
        context->decoder = NULL;
            
#ifdef NVIDIA_H264_DECODER
        if (context->hw_decoder)
        {
            LOG_TEXT("nv_decoder_release()");
            nv_decoder_release(&(context->nv_context));
            memset(&(context->nv_context), 0, sizeof(h264_nv_decode_context_t));
            context->hw_decoder = 0;
            context->nv_error_count = 0;
        }
#endif
        
    }
    
#ifdef NVIDIA_H264_DECODER
    if (hw && !context->decoder)
    {
        LOG_TEXT("get_nv_decoder()");
        get_nv_decoder(context->av_codec_id, &(context->decoder), &(context->hw_decoder));
    }
#endif
 
    if (!context->decoder)
    {
        LOG_TEXT("avcodec_find_decoder()");
        context->decoder = avcodec_find_decoder(context->av_codec_id);
 
        if (!context->decoder && context->av_codec_id == AV_CODEC_ID_H263P) {
            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Cannot find AV_CODEC_ID_H263P decoder, trying AV_CODEC_ID_H263 instead\n");
            context->decoder = avcodec_find_decoder(AV_CODEC_ID_H263);
        }
 
        if (!context->decoder) {
            return -1;
        }
    }
 
    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "DECODER: id=%d %s\n", context->decoder->id, context->decoder->long_name);
        
    context->decoder_ctx = avcodec_alloc_context3(context->decoder);
    context->decoder_ctx->thread_count = profile->decoder_thread_count;
    if (avcodec_open2(context->decoder_ctx, context->decoder, NULL) < 0) {
        return -1;
    }
    return 0;
}
       

继续阅读