From 9f9718715ab33744b67cc2e817bf90b166df4f90 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 19 Sep 2012 08:52:45 +0530 Subject: [PATCH] audio: Explicitly specify endianness for IEC 61937 payloading This is required since some systems (DirectSound and OS X) manage the final byte order themselves. https://bugzilla.gnome.org/show_bug.cgi?id=678021 --- ext/alsa/gstalsasink.c | 2 +- gst-libs/gst/audio/gstaudioiec61937.c | 33 +++++++++++++++++---------------- gst-libs/gst/audio/gstaudioiec61937.h | 3 ++- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ext/alsa/gstalsasink.c b/ext/alsa/gstalsasink.c index 2749b4c..3a7957c 100644 --- a/ext/alsa/gstalsasink.c +++ b/ext/alsa/gstalsasink.c @@ -1113,7 +1113,7 @@ gst_alsasink_payload (GstAudioBaseSink * sink, GstBuffer * buf) gst_buffer_map (out, &oinfo, GST_MAP_WRITE); if (!gst_audio_iec61937_payload (iinfo.data, iinfo.size, - oinfo.data, oinfo.size, &sink->ringbuffer->spec)) { + oinfo.data, oinfo.size, &sink->ringbuffer->spec, G_BIG_ENDIAN)) { gst_buffer_unref (out); return NULL; } diff --git a/gst-libs/gst/audio/gstaudioiec61937.c b/gst-libs/gst/audio/gstaudioiec61937.c index d665474..cdd9805 100644 --- a/gst-libs/gst/audio/gstaudioiec61937.c +++ b/gst-libs/gst/audio/gstaudioiec61937.c @@ -134,6 +134,7 @@ gst_audio_iec61937_frame_size (const GstAudioRingBufferSpec * spec) * payloaded contents in. Should not overlap with @src * @dst_n: size of @dst in bytes * @spec: the ringbufer spec for @src + * @endianness: the expected byte order of the payloaded data * * Payloads @src in the form specified by IEC 61937 for the type from @spec and * stores the result in @dst. @src must contain exactly one frame of data and @@ -144,7 +145,7 @@ gst_audio_iec61937_frame_size (const GstAudioRingBufferSpec * spec) */ gboolean gst_audio_iec61937_payload (const guint8 * src, guint src_n, guint8 * dst, - guint dst_n, const GstAudioRingBufferSpec * spec) + guint dst_n, const GstAudioRingBufferSpec * spec, gint endianness) { guint i, tmp; #if G_BYTE_ORDER == G_BIG_ENDIAN @@ -291,22 +292,22 @@ gst_audio_iec61937_payload (const guint8 * src, guint src_n, guint8 * dst, /* Copy the payload */ i = 8; -#if G_BYTE_ORDER == G_BIG_ENDIAN - memcpy (dst + i, src, src_n); -#else - /* Byte-swapped again */ - /* FIXME: orc-ify this */ - for (tmp = 1; tmp < src_n; tmp += 2) { - dst[i + tmp - 1] = src[tmp]; - dst[i + tmp] = src[tmp - 1]; - } - /* Do we have 1 byte remaining? */ - if (src_n % 2) { - dst[i + src_n - 1] = 0; - dst[i + src_n] = src[src_n - 1]; - i++; + if (G_BYTE_ORDER == endianness) { + memcpy (dst + i, src, src_n); + } else { + /* Byte-swapped again */ + /* FIXME: orc-ify this */ + for (tmp = 1; tmp < src_n; tmp += 2) { + dst[i + tmp - 1] = src[tmp]; + dst[i + tmp] = src[tmp - 1]; + } + /* Do we have 1 byte remaining? */ + if (src_n % 2) { + dst[i + src_n - 1] = 0; + dst[i + src_n] = src[src_n - 1]; + i++; + } } -#endif i += src_n; diff --git a/gst-libs/gst/audio/gstaudioiec61937.h b/gst-libs/gst/audio/gstaudioiec61937.h index 79b8728..1cdc646 100644 --- a/gst-libs/gst/audio/gstaudioiec61937.h +++ b/gst-libs/gst/audio/gstaudioiec61937.h @@ -27,6 +27,7 @@ guint gst_audio_iec61937_frame_size (const GstAudioRingBufferSpec * spec); gboolean gst_audio_iec61937_payload (const guint8 * src, guint src_n, guint8 * dst, guint dst_n, - const GstAudioRingBufferSpec * spec); + const GstAudioRingBufferSpec * spec, + gint endianness); #endif /* __GST_AUDIO_IEC61937_H__ */ -- 2.7.4