天天看點

全網首發: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;
}
       

繼續閱讀