aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-07-30 13:13:10 +0200
committerEvan Huus <eapache@gmail.com>2014-08-24 16:44:33 +0000
commita68eab6ab57e2ba3dff5f49a90cdf9bd81a45f0a (patch)
treea9ee9ea2c526154238ac2dfbe9b09c022c6c20ae /ui
parented090dda9ba93da6ae532beea793aa08b781c2b1 (diff)
Hack to fix RTP player progress line position
PortAudio seems to return 0 as value for Pa_GetStreamTime() on a PulseAudio system using the ALSA host API. This is known for 3 years, but still has not been fixed. As this function basically gives us a monotonically increasing clock in seconds as double, just use the Glib library function for that. I don't know whether this adds much latency, but it is certainly better than breaking the progress line (and also the related auto-scroll). While at it, split the idx calculation and explain what each part does and add modelines. Remove invalid _U_ annotations. [1]: http://music.columbia.edu/pipermail/portaudio/2011-June/012452.html Bug: 10307 Change-Id: I67fff531e0577add4b9b76052e286fb3fd5d01ff Reviewed-on: https://code.wireshark.org/review/3260 Petri-Dish: Evan Huus <eapache@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Evan Huus <eapache@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r--ui/gtk/rtp_player.c57
1 files changed, 52 insertions, 5 deletions
diff --git a/ui/gtk/rtp_player.c b/ui/gtk/rtp_player.c
index 1b062c62d1..ad96bfeee8 100644
--- a/ui/gtk/rtp_player.c
+++ b/ui/gtk/rtp_player.c
@@ -830,6 +830,23 @@ decode_rtp_stream(rtp_stream_info_t *rsi, gpointer ptr)
g_hash_table_destroy(decoders_hash);
}
+#if !PORTAUDIO_API_1
+/* returns monotonically increasing clock in seconds */
+static PaTime
+getMonoTime(PaStream *stream _U_)
+{
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ return g_get_monotonic_time() * 1e-6;
+#else
+ /* TODO: this is broken for sure, but maybe such old glibs do not even
+ * use pulseaudio so we do not have to care? */
+ return Pa_GetStreamTime(stream);
+#endif
+}
+
+static PaTime (*getCurrentTime)(PaStream *stream);
+#endif
+
/****************************************************************************/
static gint
h_scrollbar_changed(GtkWidget *widget _U_, gpointer user_data)
@@ -916,7 +933,14 @@ draw_channel_cursor(rtp_channel_info_t *rci, guint32 start_index)
#if PORTAUDIO_API_1
idx = Pa_StreamTime( pa_stream ) - rtp_channels->pause_duration - rtp_channels->out_diff_time - start_index;
#else /* PORTAUDIO_API_1 */
- idx = ((guint32)(sample_rate) * (Pa_GetStreamTime(pa_stream)-rtp_channels->pa_start_time))- rtp_channels->pause_duration - rtp_channels->out_diff_time - start_index;
+ /* frames since start button was pressed minus latency, from time */
+ idx = (guint32) sample_rate
+ * (getCurrentTime(pa_stream) - rtp_channels->pa_start_time
+ - rtp_channels->out_diff_time);
+ /* frames spent in pause state or seek correction */
+ idx -= rtp_channels->pause_duration;
+ /* frame where the bar starts getting drawn */
+ idx -= start_index;
#endif /* PORTAUDIO_API_1 */
@@ -1122,12 +1146,12 @@ init_rtp_channels_vals(void)
static int paCallback( void *inputBuffer _U_, void *outputBuffer,
unsigned long framesPerBuffer,
- PaTimestamp outTime _U_, void *userData)
+ PaTimestamp outTime, void *userData)
{
#else /* PORTAUDIO_API_1 */
static int paCallback( const void *inputBuffer _U_, void *outputBuffer,
unsigned long framesPerBuffer,
- const PaStreamCallbackTimeInfo* outTime _U_,
+ const PaStreamCallbackTimeInfo* outTime,
PaStreamCallbackFlags statusFlags _U_,
void *userData)
{
@@ -1151,9 +1175,9 @@ static int paCallback( const void *inputBuffer _U_, void *outputBuffer,
}
#if PORTAUDIO_API_1
- rpci->out_diff_time = outTime - Pa_StreamTime(pa_stream) ;
+ rpci->out_diff_time = outTime - Pa_StreamTime(pa_stream);
#else /* PORTAUDIO_API_1 */
- rpci->out_diff_time = (guint32)(sample_rate) * (outTime->outputBufferDacTime - Pa_GetStreamTime(pa_stream)) ;
+ rpci->out_diff_time = outTime->outputBufferDacTime - outTime->currentTime;
#endif /* PORTAUDIO_API_1 */
@@ -2039,6 +2063,16 @@ play_channels(void)
}
#if !PORTAUDIO_API_1
rtp_channels->pa_start_time = Pa_GetStreamTime(pa_stream);
+ if (rtp_channels->pa_start_time == 0) {
+ /* PortAudio has a broken Pa_GetStreamTime
+ * implementation for ALSA on top of PulseAudio.
+ * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10307
+ */
+ getCurrentTime = getMonoTime;
+ rtp_channels->pa_start_time = getCurrentTime(pa_stream);
+ } else {
+ getCurrentTime = Pa_GetStreamTime;
+ }
#endif /* PORTAUDIO_API_1 */
rtp_channels->stop = FALSE;
@@ -2528,3 +2562,16 @@ rtp_player_init(voip_calls_tapinfo_t *voip_calls_tap)
}
#endif /* HAVE_LIBPORTAUDIO */
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 noexpandtab:
+ * :indentSize=4:tabSize=8:noTabs=false:
+ */