Also change synchronize_audio to only calculate the wanted number of samples
instead of doing the actual synchronization, and make swr_convert handle the
sample addition or deletion.
This new method replaces the old buggy way which simply deleted or
multiplied samples.
Signed-off-by: Marton Balint <cus@passwd.hu>
This allows to get out of ffplay if it or SDL got stuck.
This for example happens when the audio driver is playing something
else and doesnt support mixing multiple sources.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Marton Balint <cus@passwd.hu>
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>