in FFmpegInterop/Source/UncompressedSampleProvider.cpp [36:86]
HRESULT UncompressedSampleProvider::GetFrameFromFFmpegDecoder(AVPacket* avPacket)
{
HRESULT hr = S_OK;
int decodeFrame = 0;
if (avPacket != nullptr)
{
int sendPacketResult = avcodec_send_packet(m_pAvCodecCtx, avPacket);
if (sendPacketResult == AVERROR(EAGAIN))
{
// The decoder should have been drained and always ready to access input
_ASSERT(FALSE);
hr = E_UNEXPECTED;
}
else if (sendPacketResult < 0)
{
// We failed to send the packet
hr = E_FAIL;
DebugMessage(L"Decoder failed on the sample\n");
}
}
if (SUCCEEDED(hr))
{
AVFrame *pFrame = av_frame_alloc();
// Try to get a frame from the decoder.
decodeFrame = avcodec_receive_frame(m_pAvCodecCtx, pFrame);
// The decoder is empty, send a packet to it.
if (decodeFrame == AVERROR(EAGAIN))
{
// The decoder doesn't have enough data to produce a frame,
// return S_FALSE to indicate a partial frame
hr = S_FALSE;
av_frame_unref(pFrame);
av_frame_free(&pFrame);
}
else if (decodeFrame < 0)
{
hr = E_FAIL;
av_frame_unref(pFrame);
av_frame_free(&pFrame);
DebugMessage(L"Failed to get a frame from the decoder\n");
}
else
{
m_pAvFrame = pFrame;
}
}
return hr;
}