virtual void RequestBuffers(LPVOID buffers) { if(!buffers) return; mfxFrameData& buff = *(mfxFrameData*)buffers; auto lock = lock_mutex(frame_buff_status); if(buff.MemId && !frame_buff_status[(unsigned)buff.MemId-1]) //Reuse buffer if not in use return; for(unsigned i = 0; i < frames.Num(); i++) { if(frame_buff_status[i] || frames[i].MemId) continue; mfxFrameData& data = frames[i]; buff.Y = data.Y; buff.UV = data.UV; buff.Pitch = data.Pitch; if(buff.MemId) frames[(unsigned)buff.MemId-1].MemId = nullptr; buff.MemId = mfxMemId(i+1); data.MemId = mfxMemId(i+1); return; } Log(TEXT("Error: all frames are in use")); }
void NVENCEncoder::RequestBuffers(LPVOID buffers) { if (!buffers) return; OSMutexLocker locker(frameMutex); mfxFrameData *buff = (mfxFrameData*)buffers; if (buff->MemId && inputSurfaces[(unsigned int)buff->MemId - 1].locked) return; for (int i = 0; i < maxSurfaceCount; ++i) { if (inputSurfaces[i].locked || inputSurfaces[i].useCount > 0) continue; NV_ENC_LOCK_INPUT_BUFFER lockBufferParams = { 0 }; lockBufferParams.version = NV_ENC_LOCK_INPUT_BUFFER_VER; lockBufferParams.inputBuffer = inputSurfaces[i].inputSurface; NVENCSTATUS nvStatus = pNvEnc->nvEncLockInputBuffer(encoder, &lockBufferParams); if (nvStatus != NV_ENC_SUCCESS) { NvLog(TEXT("nvEncLockInputBuffer failed for surface #%d with 0x%x"), i, nvStatus); return; } buff->Pitch = lockBufferParams.pitch; buff->Y = (mfxU8*)lockBufferParams.bufferDataPtr; buff->UV = buff->Y + (inputSurfaces[i].height * buff->Pitch); buff->MemId = mfxMemId(i + 1); inputSurfaces[i].locked = true; return; } NvLog(TEXT("No unlocked frame found")); }