This patch reimplements early frame drop, it is now based on the current
difference between the master clock and the video clock, and the pts of the
current and the last displayed (or skipped) frame. If the frame to be added to
the queue is late after decoding, then we drop it early because later we would
drop it anyway (unless it is the only frame in the picture queue).
The current approach has only one downside that I know of, it does not handle
well when the filters are changing significantly the pts of the frames, because
we compare pts values from filtered and unfiltered frames.
We also start using the pictq_mutex to ensure consistent video_current_pts,
video_current_pts_drift, frame_last_pts, frame_last_dropped_pts and
frame_last_dropped_pos values.
Signed-off-by: Marton Balint <cus@passwd.hu>
Fixes missing blue channel when switching from/to fullscren on OSX and libsdl
1.2.14. Fixes issue 548. Thanks for Jean First for the original patch and
for testing.
Signed-off-by: Marton Balint <cus@passwd.hu>
If the picture queue is empty, or when the calculated delay is 0, frame_timer
is not increased but we are still displaying the old frame. When we eventually
get a frame, where the computed delay is positive, so we don't need to drop any
more frames, then it is best to update frame_timer to be as near as the current
time as it can.
This way we dont't have to wait several frames to add the necesarry delays to
frame_timer to reach current time, therefore there are no extra frame drops
after reaching a positive delay.
Signed-off-by: Marton Balint <cus@passwd.hu>
The current impementation of early frame drops (dropping frames before adding
them to the picture queue) has multiple problems:
Even after gettin A-V sync, the frame droping continues until
VideoState->skip_frames reaches 1, which can take a lot of time causing useless
additional frame drops and bad AV-sync. This issue can be easily triggered with
for example changing the audio stream.
Also video_refresh currenly does not handle early skipped frames in every case,
for example if we skip a frame, then the last frame duration calculation will
compute the duration of the sum of the skipped frame and the duration of the
frame before that, and in compute_target_delay we may multiply this unusually
big delay.
Signed-off-by: Marton Balint <cus@passwd.hu>
Since target clock is based on the current A-V delay, it is better calculate it
when we actually need it rather than when we put a picture in the picture
queue.
The patch also makes a code a bit more readable by renaming some delay
variables to duration, and converting compute_target_time to a delay
calculating function which does not modify the state. Factoring out the
iteration of the pictq to standalone function is also done in this patch.
Signed-off-by: Marton Balint <cus@passwd.hu>
Previously ffplay expected SDL_AudioOpen to provide the requested sample rate
and channel number. This is no longer a requirement because this patch replaces
the audio convert function with libswresample's swr_convert which is capable of
handling different sample formats, sample rates and different number of
channels and different channel layouts.
The patch also removes the hardcoded 16bit samples assumption and uses
av_get_bytes_per_sample almost everywhere. The only exceptions are
the update_sample_display and video_audio_display functions, it
seemed too much of a headache to make them generic.
We also fix a tiny bug in sdl_audio_callback, we ensure that the number of
bytes when we put silence in the buffer is a multiple of the frame size.
This is done in order to clarify the non-video-specific nature of the
buffersink code, as the result of the video/audio API unification of
the previous commit, and for improving overall consistency.
The new API is more generic (no distinction between audio/video for
pulling frames), and avoids code duplication.
A backward compatibility layer is kept for avoiding tools ABI breaks
(only for the video binary interface, audio interface was never used
in the tools).
If the video queue is aborted, we have to pop the pending ALLOC event or wait
for the allocation to complete, because the current code assumes that
VideoState->pictq_windex does not change until the allocation is complete.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Altough ffplay is working pretty well without using a lock manager, it is still
a multithreaded application calling libavcodec functions from multiple threads,
so using a lock manager is probably a good idea.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Getting rid of globals are generally a good thing. The patch also makes
toggle_pause and step_to_next_frame use a function parameter instead of
the global cur_stream variable.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This way the content of "vfilters" can be reused.
For example when the frame size changes, the filterchain is
reconfigured reusing again the vfilters value.
Use av_log(AV_LOG_LEVEL...) rather than av_dlog, the log is useful
even for "normal" debugging, and consistent with what is done in
ffmpeg.
Also change the message to achieve better consistency with the
corresponding ffmpeg message.
Use the value specified in the codec context for setting the
filterchain sample aspect ratio, when it is not specified in the
stream context.
Consistent with the ffmpeg behavior.
Fix trac issue #398.