[vlc-commits] [Git][videolan/vlc][master] 4 commits: aaudio: simplify silence calculation
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sat Nov 26 13:06:14 UTC 2022
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
44df0486 by Thomas Guillem at 2022-11-26T11:45:56+00:00
aaudio: simplify silence calculation
- - - - -
1de63445 by Thomas Guillem at 2022-11-26T11:45:56+00:00
aaudio: reset timing counter only in case of success
That way, GetFrameTimestampLocked() will be called again just after a
failure (until it succeed, then every 1 seconds).
- - - - -
5d809b36 by Thomas Guillem at 2022-11-26T11:45:56+00:00
aaudio: handle 0 pos_frames
0 is possible and will happen with the next commit.
Never seen a negative value though.
- - - - -
84140d6b by Thomas Guillem at 2022-11-26T11:45:56+00:00
aaudio: fetch timestamp immediately
And not after 1 second of playback.
- - - - -
1 changed file:
- modules/audio_output/android/aaudio.c
Changes:
=====================================
modules/audio_output/android/aaudio.c
=====================================
@@ -329,11 +329,9 @@ GetFrameTimestampLocked(aout_stream_t *stream, int64_t *pos_frames,
aaudio_result_t result =
vt.AAudioStream_getTimestamp(sys->as, CLOCK_MONOTONIC,
pos_frames, &time_ns);
- if (result != AAUDIO_OK)
+ if (result != AAUDIO_OK || *pos_frames <= 0)
return VLC_EGENERIC;
- assert(*pos_frames > 0);
-
*frame_time_us = VLC_TICK_FROM_NS(time_ns);
return VLC_SUCCESS;
}
@@ -359,11 +357,9 @@ DataCallback(AAudioStream *as, void *user, void *data_, int32_t num_frames)
else
{
vlc_tick_t now = vlc_tick_now();
- vlc_tick_t data_ticks = FramesToTicks(sys, num_frames);
- vlc_tick_t silence_ticks = now + data_ticks - sys->first_play_date;
/* Write silence to reach the first play date */
- silence_ticks = data_ticks - silence_ticks;
+ vlc_tick_t silence_ticks = sys->first_play_date - now;
if (silence_ticks > 0)
{
tocopy = TicksToBytes(sys, silence_ticks);
@@ -416,23 +412,25 @@ DataCallback(AAudioStream *as, void *user, void *data_, int32_t num_frames)
sys->frames_total_bytes -= tocopy;
sys->timing_report_last_written_bytes += tocopy;
- if (sys->timing_report_last_written_bytes >= sys->timing_report_delay_bytes)
+ int64_t pos_frames;
+ vlc_tick_t system_ts;
+ if (sys->timing_report_last_written_bytes >= sys->timing_report_delay_bytes
+ && GetFrameTimestampLocked(stream, &pos_frames, &system_ts) == VLC_SUCCESS)
{
sys->timing_report_last_written_bytes = 0;
- int64_t pos_frames;
- vlc_tick_t system_ts;
- if (GetFrameTimestampLocked(stream, &pos_frames, &system_ts) == VLC_SUCCESS)
- {
- pos_frames -= sys->frames_flush_pos;
- assert(pos_frames > 0);
- vlc_tick_t pos_ticks = FramesToTicks(sys, pos_frames);
-
- /* Add the start silence to the system time and don't subtract
- * it from pos_ticks to avoid (unlikely) negatives ts */
- system_ts += BytesToTicks(sys, sys->start_silence_bytes);
- aout_stream_TimingReport(stream, system_ts, pos_ticks);
- }
+ /* From now on, fetch the timestamp every 1 seconds */
+ sys->timing_report_delay_bytes =
+ TicksToBytes(sys, TIMING_REPORT_DELAY_TICKS);
+
+ pos_frames -= sys->frames_flush_pos;
+ assert(pos_frames > 0);
+ vlc_tick_t pos_ticks = FramesToTicks(sys, pos_frames);
+
+ /* Add the start silence to the system time and don't subtract
+ * it from pos_ticks to avoid (unlikely) negatives ts */
+ system_ts += BytesToTicks(sys, sys->start_silence_bytes);
+ aout_stream_TimingReport(stream, system_ts, pos_ticks);
}
memcpy(data, f->p_buffer, tocopy);
@@ -584,6 +582,7 @@ Flush(aout_stream_t *stream)
sys->first_play_date = VLC_TICK_INVALID;
sys->start_silence_bytes = 0;
sys->timing_report_last_written_bytes = 0;
+ sys->timing_report_delay_bytes = 0;
sys->underrun_bytes = 0;
vlc_tick_t unused;
@@ -729,8 +728,6 @@ static int OpenAAudioStream(aout_stream_t *stream, audio_sample_format_t *fmt)
sys->as = as;
sys->fmt = *fmt;
- sys->timing_report_delay_bytes = TicksToBytes(sys, TIMING_REPORT_DELAY_TICKS);
-
return VLC_SUCCESS;
}
@@ -785,6 +782,7 @@ Start(aout_stream_t *stream, audio_sample_format_t *fmt,
sys->draining = false;
sys->first_play_date = VLC_TICK_INVALID;
sys->timing_report_last_written_bytes = 0;
+ sys->timing_report_delay_bytes = 0;
int ret = OpenAAudioStream(stream, fmt);
if (ret != VLC_SUCCESS)
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ca6417bc9f07231563f023e84bce0c2a682a9acf...84140d6bde72fe989b168fd12f011bd76b22cbc4
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ca6417bc9f07231563f023e84bce0c2a682a9acf...84140d6bde72fe989b168fd12f011bd76b22cbc4
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list