ffplay: use precalculated frame size and bytes per sec values
Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
parent
e98cd24a89
commit
e37d4920c1
9
ffplay.c
9
ffplay.c
@ -2380,8 +2380,6 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
|
||||
{
|
||||
VideoState *is = opaque;
|
||||
int audio_size, len1;
|
||||
int bytes_per_sec;
|
||||
int frame_size = av_samples_get_buffer_size(NULL, is->audio_tgt.channels, 1, is->audio_tgt.fmt, 1);
|
||||
|
||||
audio_callback_time = av_gettime();
|
||||
|
||||
@ -2391,7 +2389,7 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
|
||||
if (audio_size < 0) {
|
||||
/* if error, just output silence */
|
||||
is->audio_buf = is->silence_buf;
|
||||
is->audio_buf_size = sizeof(is->silence_buf) / frame_size * frame_size;
|
||||
is->audio_buf_size = sizeof(is->silence_buf) / is->audio_tgt.frame_size * is->audio_tgt.frame_size;
|
||||
} else {
|
||||
if (is->show_mode != SHOW_MODE_VIDEO)
|
||||
update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
|
||||
@ -2407,11 +2405,10 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
|
||||
stream += len1;
|
||||
is->audio_buf_index += len1;
|
||||
}
|
||||
bytes_per_sec = is->audio_tgt.freq * is->audio_tgt.channels * av_get_bytes_per_sample(is->audio_tgt.fmt);
|
||||
is->audio_write_buf_size = is->audio_buf_size - is->audio_buf_index;
|
||||
/* Let's assume the audio driver that is used by SDL has two periods. */
|
||||
if (!isnan(is->audio_clock)) {
|
||||
set_clock_at(&is->audclk, is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_buf_size) / bytes_per_sec, is->audio_clock_serial, audio_callback_time / 1000000.0);
|
||||
set_clock_at(&is->audclk, is->audio_clock - (double)(2 * is->audio_hw_buf_size + is->audio_write_buf_size) / is->audio_tgt.bytes_per_sec, is->audio_clock_serial, audio_callback_time / 1000000.0);
|
||||
sync_clock_to_slave(&is->extclk, &is->audclk);
|
||||
}
|
||||
}
|
||||
@ -2580,7 +2577,7 @@ static int stream_component_open(VideoState *is, int stream_index)
|
||||
is->audio_diff_avg_count = 0;
|
||||
/* since we do not have a precise anough audio fifo fullness,
|
||||
we correct audio sync only if larger than this threshold */
|
||||
is->audio_diff_threshold = 2.0 * is->audio_hw_buf_size / av_samples_get_buffer_size(NULL, is->audio_tgt.channels, is->audio_tgt.freq, is->audio_tgt.fmt, 1);
|
||||
is->audio_diff_threshold = 2.0 * is->audio_hw_buf_size / is->audio_tgt.bytes_per_sec;
|
||||
|
||||
memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
|
||||
memset(&is->audio_pkt_temp, 0, sizeof(is->audio_pkt_temp));
|
||||
|
Loading…
x
Reference in New Issue
Block a user