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
This commit is contained in:
Arun Raghavan 2012-09-19 08:52:45 +05:30
parent 17e3dc3357
commit 9f9718715a
3 changed files with 20 additions and 18 deletions

View File

@ -1113,7 +1113,7 @@ gst_alsasink_payload (GstAudioBaseSink * sink, GstBuffer * buf)
gst_buffer_map (out, &oinfo, GST_MAP_WRITE); gst_buffer_map (out, &oinfo, GST_MAP_WRITE);
if (!gst_audio_iec61937_payload (iinfo.data, iinfo.size, 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); gst_buffer_unref (out);
return NULL; return NULL;
} }

View File

@ -134,6 +134,7 @@ gst_audio_iec61937_frame_size (const GstAudioRingBufferSpec * spec)
* payloaded contents in. Should not overlap with @src * payloaded contents in. Should not overlap with @src
* @dst_n: size of @dst in bytes * @dst_n: size of @dst in bytes
* @spec: the ringbufer spec for @src * @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 * 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 * 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 gboolean
gst_audio_iec61937_payload (const guint8 * src, guint src_n, guint8 * dst, 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; guint i, tmp;
#if G_BYTE_ORDER == G_BIG_ENDIAN #if G_BYTE_ORDER == G_BIG_ENDIAN
@ -291,9 +292,9 @@ gst_audio_iec61937_payload (const guint8 * src, guint src_n, guint8 * dst,
/* Copy the payload */ /* Copy the payload */
i = 8; i = 8;
#if G_BYTE_ORDER == G_BIG_ENDIAN if (G_BYTE_ORDER == endianness) {
memcpy (dst + i, src, src_n); memcpy (dst + i, src, src_n);
#else } else {
/* Byte-swapped again */ /* Byte-swapped again */
/* FIXME: orc-ify this */ /* FIXME: orc-ify this */
for (tmp = 1; tmp < src_n; tmp += 2) { for (tmp = 1; tmp < src_n; tmp += 2) {
@ -306,7 +307,7 @@ gst_audio_iec61937_payload (const guint8 * src, guint src_n, guint8 * dst,
dst[i + src_n] = src[src_n - 1]; dst[i + src_n] = src[src_n - 1];
i++; i++;
} }
#endif }
i += src_n; i += src_n;

View File

@ -27,6 +27,7 @@
guint gst_audio_iec61937_frame_size (const GstAudioRingBufferSpec * spec); guint gst_audio_iec61937_frame_size (const GstAudioRingBufferSpec * spec);
gboolean gst_audio_iec61937_payload (const guint8 * src, guint src_n, gboolean gst_audio_iec61937_payload (const guint8 * src, guint src_n,
guint8 * dst, guint dst_n, guint8 * dst, guint dst_n,
const GstAudioRingBufferSpec * spec); const GstAudioRingBufferSpec * spec,
gint endianness);
#endif /* __GST_AUDIO_IEC61937_H__ */ #endif /* __GST_AUDIO_IEC61937_H__ */