mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-02-16 02:30:52 +00:00
Use EOS to force decoder test frame output
This commit is contained in:
@@ -664,6 +664,27 @@ bool FFmpegVideoDecoder::completeInitialization(const AVCodec* decoder, enum AVP
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Most FFmpeg decoders process input using a "push" model.
|
||||||
|
// We'll see those fail here if the format is not supported.
|
||||||
|
err = avcodec_send_packet(m_VideoDecoderCtx, m_Pkt);
|
||||||
|
if (err < 0) {
|
||||||
|
char errorstring[512];
|
||||||
|
av_strerror(err, errorstring, sizeof(errorstring));
|
||||||
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Test decode failed (avcodec_send_packet): %s", errorstring);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signal EOS to force the decoder to immediately output the frame
|
||||||
|
err = avcodec_send_packet(m_VideoDecoderCtx, nullptr);
|
||||||
|
if (err < 0) {
|
||||||
|
char errorstring[512];
|
||||||
|
av_strerror(err, errorstring, sizeof(errorstring));
|
||||||
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Test flush failed (avcodec_send_packet): %s", errorstring);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
AVFrame* frame = av_frame_alloc();
|
AVFrame* frame = av_frame_alloc();
|
||||||
if (!frame) {
|
if (!frame) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
@@ -671,35 +692,17 @@ bool FFmpegVideoDecoder::completeInitialization(const AVCodec* decoder, enum AVP
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some decoders won't output on the first frame, so we'll submit
|
err = avcodec_receive_frame(m_VideoDecoderCtx, frame);
|
||||||
// a few test frames if we get an EAGAIN error.
|
if (err == 0) {
|
||||||
for (int retries = 0; retries < 5; retries++) {
|
// Allow the renderer to do any validation it wants on this frame
|
||||||
// Most FFmpeg decoders process input using a "push" model.
|
if (!m_FrontendRenderer->testRenderFrame(frame)) {
|
||||||
// We'll see those fail here if the format is not supported.
|
|
||||||
err = avcodec_send_packet(m_VideoDecoderCtx, m_Pkt);
|
|
||||||
if (err < 0) {
|
|
||||||
av_frame_free(&frame);
|
|
||||||
char errorstring[512];
|
|
||||||
av_strerror(err, errorstring, sizeof(errorstring));
|
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"Test decode failed (avcodec_send_packet): %s", errorstring);
|
"Test decode failed (testRenderFrame)");
|
||||||
|
av_frame_free(&frame);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A few FFmpeg decoders (h264_mmal) process here using a "pull" model.
|
|
||||||
// Those decoders will fail here if the format is not supported.
|
|
||||||
err = avcodec_receive_frame(m_VideoDecoderCtx, frame);
|
|
||||||
if (err == AVERROR(EAGAIN)) {
|
|
||||||
// Wait a little while to let the hardware work
|
|
||||||
SDL_Delay(100);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Done!
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (err < 0) {
|
||||||
if (err < 0) {
|
|
||||||
char errorstring[512];
|
char errorstring[512];
|
||||||
av_strerror(err, errorstring, sizeof(errorstring));
|
av_strerror(err, errorstring, sizeof(errorstring));
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
@@ -708,14 +711,6 @@ bool FFmpegVideoDecoder::completeInitialization(const AVCodec* decoder, enum AVP
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow the renderer to do any validation it wants on this frame
|
|
||||||
if (!m_FrontendRenderer->testRenderFrame(frame)) {
|
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"Test decode failed (testRenderFrame)");
|
|
||||||
av_frame_free(&frame);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
av_frame_free(&frame);
|
av_frame_free(&frame);
|
||||||
|
|
||||||
// Flush the codec to prepare for the real stream if we're
|
// Flush the codec to prepare for the real stream if we're
|
||||||
|
|||||||
Reference in New Issue
Block a user