void IsoFilesystem::visitDirectoryFiles(const char* sPath, void (*fnCallback)(void*, const char*), void* pCallbackData) const { size_t iLen = strlen(sPath) + 1; char *sNormedPath = (char*)alloca(iLen); for(size_t i = 0; i < iLen; ++i) sNormedPath[i] = _normalise(sPath[i]); // Inefficient (better would be to binary search for first and last files // which begin with sPath), but who cares - this isn't called often for(size_t i = 0; i < m_iNumFiles; ++i) { const char *sName = m_pFiles[i].sPath; if(strlen(sName) >= iLen && memcmp(sNormedPath, sName, iLen - 1) == 0) { sName += iLen - 1; if(*sName == m_cPathSeparator) ++sName; if(strchr(sName, m_cPathSeparator) == NULL) fnCallback(pCallbackData, sName); } } }
// the decode work thread void CVideoDecoder2::Decode(void) { while(!bStop){ int ret; uv_mutex_lock(pQueueMutex); if(packetQueue.size() == 0){ ret = uv_cond_timedwait(pQueueNotEmpty, pQueueMutex, (uint64_t)(1000 * 1e6)); if(ret == UV_ETIMEDOUT){ uv_mutex_unlock(pQueueMutex); continue; } } AVPacket* pkt = packetQueue.front(); packetQueue.pop_front(); uv_mutex_unlock(pQueueMutex); if(pkt->data == NULL){ // done, no more packet bStop = true; av_freep(pkt); continue; } int gotPicture; AVFrame* frame = av_frame_alloc(); if(frame){ ret = avcodec_decode_video2(pCodecCtx, frame, &gotPicture, pkt); if(ret < 0){ bStop = true; av_frame_free(&frame); frame = NULL; if(fnCallback){ fnCallback(frame, ret, pUserData); } av_free_packet(pkt); av_freep(pkt); continue; } if(gotPicture && fnCallback){ fnCallback(frame, ret, pUserData); av_free_packet(pkt); av_freep(pkt); continue; } } else{ bStop = true; if(fnCallback){ fnCallback(frame, ret, pUserData); } av_free_packet(pkt); av_freep(pkt); continue; } } // flush AVPacket pkt; av_init_packet(&pkt); pkt.data = NULL; pkt.size = 0; int ret; do{ int gotPicture; AVFrame* frame = av_frame_alloc(); if(frame){ ret = avcodec_decode_video2(pCodecCtx, frame, &gotPicture, &pkt); if(ret < 0 || !gotPicture){ av_frame_free(&frame); frame = NULL; if(ret == 0){ ret = -1; } } } else{ ret = -1; } if(fnCallback){ fnCallback(frame, ret, pUserData); } } while(ret >= 0); }