emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.75k stars 3.3k forks source link

Compile ffmpeg, use av_dict_set_js(&avcodeoptions, "threads", "auto", 0) for multi-thread decoding; when closing and enabling video playback on the same page, the decoder cannot be opened on the 65th, and no error is reported. #9191

Closed Y0QIN closed 4 years ago

Y0QIN commented 5 years ago

Compile ffmpeg, use av_dict_set_js(&avcodeoptions, "threads", "auto", 0) for multi-thread decoding; when closing and enabling video playback on the same page, the decoder cannot be opened on the 65th, and no error is reported.

C function: int FFMpegCreate(int iChannelId, int bYUVShow, int bOptimizeDecode, int codec_type,int iPlayId) { if(iChannelId < 0 || iChannelId > MAX_CHAN_NUM) return -1; int i; int ret; struct _ffmpeg_context_t _context = &g_context[iChannelId]; if(_context == NULL){ printf("_context NULL ,error !\n"); return -1; } EM_ASM_ARGS({g_iChannelId=$0;},iPlayId); memset(_context, 0, sizeof(_ffmpeg_context_t)); FFMpegRegister(); _context->nInBestAudioId = -1; AVCodec codec; AVDictionary avcodeoptions = NULL; _context->nInVideoCodecId = getDecodeVideotype(codec_type); codec = avcodec_find_decoder_js(_context->nInVideoCodecId); _context->inDecCodecCtx = avcodec_alloc_context3_js(codec); av_dict_set_js(&avcodeoptions, "threads", "auto", 0); if ((ret = avcodec_open2_js(_context->inDecCodecCtx, codec, &avcodeoptions)) < 0) { goto ERR_FREE_CODEC_CONTEXT; } _context->pListAVPkt = (ys_list_t)ys_malloc(sizeof(ys_list_t)); if (_context->nVideoWidth*_context->nVideoHeight == 0) { _context->nVideoWidth = 1280; _context->nVideoHeight = 720; } _context->dwUser = _context; _context->bRun = 1; _context->bDecode=1; _context->bPause=0; _context->nInBestStreamId =0; _context->hMutexListAVPkt = ys_mutex_init(); printf("start create threads\n"); _context->hThreadAVPktDecode = ys_thread_create(2000, ThreadAVPktDecode, _context);

if(_context->hThreadAVPktDecode==NULL) printf("create threads Failed\n");
if(avcodeoptions){
    //ys_print("free options");
    av_dict_free_js(&avcodeoptions);
    avcodeoptions = NULL;
}
printf("FFMpegContextCreate end \n");

return 0;

ERR_FREE_CODEC_CONTEXT: if(avcodeoptions){ av_dict_free_js(&avcodeoptions); avcodeoptions = NULL; } avcodec_close_js(_context->inDecCodecCtx); _context->inDecCodecCtx = NULL; ERR_FREE_FMT_CONTEXT: return -1; }

Y0QIN commented 5 years ago

Is it due to the limitation of MAX_ENV_VALUES = 64?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.