summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2015-10-14 00:32:11 +0300
committerSebastian Dröge <sebastian@centricular.com>2015-10-17 11:02:44 +0300
commit18abd0295f09f1630ba52d820e83fce279984f3a (patch)
tree82367fb32ef5b654260d32e9d01ef28438dd8111
parent7037f25bba7aebfa16dced3a115952ef2b444b10 (diff)
downloadgstreamer-plugins-base-18abd0295f09f1630ba52d820e83fce279984f3a.tar.gz
alsa: Use 8 bit pointer type for byte-based pointer arithmetic
Usually these loops only run once, so there's no problem here. But sometimes they run twice, and by adding the number of bytes to a 16 bit pointer type we would advance twice as much as we should. Also use snd_pcm_frames_to_bytes() in alsasrc to calculate the number of bytes to skip, same as we do in alsasink. Thanks to Lucio A. Hernandez <lucio.a.hernandez@gmail.com> for reporting.
-rw-r--r--ext/alsa/gstalsasink.c5
-rw-r--r--ext/alsa/gstalsasrc.c5
2 files changed, 5 insertions, 5 deletions
diff --git a/ext/alsa/gstalsasink.c b/ext/alsa/gstalsasink.c
index cc7230475..c8989ced1 100644
--- a/ext/alsa/gstalsasink.c
+++ b/ext/alsa/gstalsasink.c
@@ -1020,16 +1020,17 @@ gst_alsasink_write (GstAudioSink * asink, gpointer data, guint length)
GstAlsaSink *alsa;
gint err;
gint cptr;
- gint16 *ptr = data;
+ guint8 *ptr = data;
alsa = GST_ALSA_SINK (asink);
if (alsa->iec958 && alsa->need_swap) {
guint i;
+ guint16 *ptr_tmp = (guint16 *) ptr;
GST_DEBUG_OBJECT (asink, "swapping bytes");
for (i = 0; i < length / 2; i++) {
- ptr[i] = GUINT16_SWAP_LE_BE (ptr[i]);
+ ptr_tmp[i] = GUINT16_SWAP_LE_BE (ptr_tmp[i]);
}
}
diff --git a/ext/alsa/gstalsasrc.c b/ext/alsa/gstalsasrc.c
index 0233748b2..a359cc351 100644
--- a/ext/alsa/gstalsasrc.c
+++ b/ext/alsa/gstalsasrc.c
@@ -954,12 +954,11 @@ gst_alsasrc_read (GstAudioSrc * asrc, gpointer data, guint length,
GstAlsaSrc *alsa;
gint err;
gint cptr;
- gint16 *ptr;
+ guint8 *ptr = data;
alsa = GST_ALSA_SRC (asrc);
cptr = length / alsa->bpf;
- ptr = data;
GST_ALSA_SRC_LOCK (asrc);
while (cptr > 0) {
@@ -975,7 +974,7 @@ gst_alsasrc_read (GstAudioSrc * asrc, gpointer data, guint length,
continue;
}
- ptr += err * alsa->channels;
+ ptr += snd_pcm_frames_to_bytes (alsa->handle, err);
cptr -= err;
}
GST_ALSA_SRC_UNLOCK (asrc);