audio: Explicitly specify endianness for IEC 61937 payloading
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Wed, 19 Sep 2012 03:22:45 +0000 (08:52 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Wed, 19 Sep 2012 03:45:16 +0000 (09:15 +0530)
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
gst-libs/gst/audio/gstaudioiec61937.c
gst-libs/gst/audio/gstaudioiec61937.h

index 2749b4c..3a7957c 100644 (file)
@@ -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;
     }
index d665474..cdd9805 100644 (file)
@@ -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;
 
index 79b8728..1cdc646 100644 (file)
@@ -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__ */