mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 23:55:38 +00:00
VideoFFmpegComponent now prioritizes audio by dropping video frames if the computer can't keep up.
This commit is contained in:
parent
e4ee4855df
commit
3b4bb74ac0
|
@ -239,8 +239,8 @@ void VideoFFmpegComponent::frameProcessing()
|
||||||
{
|
{
|
||||||
mWindow->increaseVideoPlayerCount();
|
mWindow->increaseVideoPlayerCount();
|
||||||
|
|
||||||
bool videoFilter;
|
bool videoFilter = false;
|
||||||
bool audioFilter;
|
bool audioFilter = false;
|
||||||
|
|
||||||
videoFilter = setupVideoFilters();
|
videoFilter = setupVideoFilters();
|
||||||
|
|
||||||
|
@ -527,9 +527,22 @@ void VideoFFmpegComponent::readFrames()
|
||||||
if (!avcodec_send_packet(mVideoCodecContext, mPacket) &&
|
if (!avcodec_send_packet(mVideoCodecContext, mPacket) &&
|
||||||
!avcodec_receive_frame(mVideoCodecContext, mVideoFrame)) {
|
!avcodec_receive_frame(mVideoCodecContext, mVideoFrame)) {
|
||||||
|
|
||||||
|
int returnValue = 0;
|
||||||
|
|
||||||
// We have a video frame that needs conversion to RGBA format.
|
// We have a video frame that needs conversion to RGBA format.
|
||||||
int returnValue = av_buffersrc_add_frame_flags(
|
// Prioritize audio by dropping video frames if the audio frame queue
|
||||||
|
// gets too small, i.e. if the computer can't keep up the processing.
|
||||||
|
if ((!mAudioCodecContext || !mDecodedFrame ||
|
||||||
|
mAudioFrameCount < mAudioTargetQueueSize) ||
|
||||||
|
mAudioFrameQueue.size() > 3) {
|
||||||
|
returnValue = av_buffersrc_add_frame_flags(
|
||||||
mVBufferSrcContext, mVideoFrame, AV_BUFFERSRC_FLAG_KEEP_REF);
|
mVBufferSrcContext, mVideoFrame, AV_BUFFERSRC_FLAG_KEEP_REF);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG(LogDebug)
|
||||||
|
<< "VideoFFmpegComponent::readFrames(): Dropped video frame as "
|
||||||
|
"the audio buffer was too small";
|
||||||
|
}
|
||||||
|
|
||||||
if (returnValue < 0) {
|
if (returnValue < 0) {
|
||||||
LOG(LogError) << "VideoFFmpegComponent::readFrames(): "
|
LOG(LogError) << "VideoFFmpegComponent::readFrames(): "
|
||||||
|
|
|
@ -145,14 +145,13 @@ private:
|
||||||
// Used for audio and video synchronization.
|
// Used for audio and video synchronization.
|
||||||
std::chrono::high_resolution_clock::time_point mTimeReference;
|
std::chrono::high_resolution_clock::time_point mTimeReference;
|
||||||
|
|
||||||
|
int mAudioFrameCount;
|
||||||
|
int mVideoFrameCount;
|
||||||
|
|
||||||
double mAccumulatedTime;
|
double mAccumulatedTime;
|
||||||
bool mStartTimeAccumulation;
|
bool mStartTimeAccumulation;
|
||||||
bool mDecodedFrame;
|
bool mDecodedFrame;
|
||||||
bool mEndOfVideo;
|
bool mEndOfVideo;
|
||||||
|
|
||||||
// These are only used for debugging.
|
|
||||||
int mAudioFrameCount;
|
|
||||||
int mVideoFrameCount;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ES_CORE_COMPONENTS_VIDEO_FFMPEG_COMPONENT_H
|
#endif // ES_CORE_COMPONENTS_VIDEO_FFMPEG_COMPONENT_H
|
||||||
|
|
Loading…
Reference in a new issue