summaryrefslogtreecommitdiffstats
path: root/gst/rtp/gstrtph264depay.c
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2009-03-18 14:50:17 +0100
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2009-03-18 14:50:17 +0100
commit77e2637590e8c08a7a934982900fcd2a77769e0e (patch)
tree0a678956b046c1dd6b3637aae3fc2278c359c97c /gst/rtp/gstrtph264depay.c
parent8cf0e9ff87bb8fbc5200caee5154d64501a33191 (diff)
rtp: Use GLib functions for encoding/decoding base64
Diffstat (limited to 'gst/rtp/gstrtph264depay.c')
-rw-r--r--gst/rtp/gstrtph264depay.c61
1 files changed, 10 insertions, 51 deletions
diff --git a/gst/rtp/gstrtph264depay.c b/gst/rtp/gstrtph264depay.c
index e8028f40..54cdbd7a 100644
--- a/gst/rtp/gstrtph264depay.c
+++ b/gst/rtp/gstrtph264depay.c
@@ -202,54 +202,6 @@ gst_rtp_h264_depay_get_property (GObject * object, guint prop_id,
}
}
-static const guint8 a2bin[256] = {
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
- 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
- 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
-};
-
-static guint
-decode_base64 (gchar * in, guint8 * out)
-{
- guint8 v1, v2;
- guint len = 0;
-
- v1 = a2bin[(gint) * in];
- while (v1 <= 63) {
- /* read 4 bytes, write 3 bytes, invalid base64 are zeroes */
- v2 = a2bin[(gint) * ++in];
- *out++ = (v1 << 2) | ((v2 & 0x3f) >> 4);
- v1 = (v2 > 63 ? 64 : a2bin[(gint) * ++in]);
- *out++ = (v2 << 4) | ((v1 & 0x3f) >> 2);
- v2 = (v1 > 63 ? 64 : a2bin[(gint) * ++in]);
- *out++ = (v1 << 6) | (v2 & 0x3f);
- v1 = (v2 > 63 ? 64 : a2bin[(gint) * ++in]);
- len += 3;
- }
- /* move to '\0' */
- while (*in != '\0')
- in++;
-
- /* subtract padding */
- while (len > 0 && *--in == '=')
- len--;
-
- return len;
-}
-
static gboolean
gst_rtp_h264_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
{
@@ -296,10 +248,13 @@ gst_rtp_h264_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
b64 = GST_BUFFER_DATA (codec_data);
total = 0;
for (i = 0; params[i]; i++) {
+ guint save = 0;
+ gint state = 0;
+
GST_DEBUG_OBJECT (depayload, "decoding param %d", i);
memcpy (b64, sync_bytes, sizeof (sync_bytes));
b64 += sizeof (sync_bytes);
- len = decode_base64 (params[i], b64);
+ len = g_base64_decode_step (params[i], -1, b64, &state, &save);
total += len + sizeof (sync_bytes);
b64 += len;
}
@@ -335,12 +290,16 @@ gst_rtp_h264_depay_setcaps (GstBaseRTPDepayload * depayload, GstCaps * caps)
/* start with 7 bytes header */
len = 7;
for (i = 0; params[i]; i++) {
- gint nal_len;
+ gsize nal_len;
guint8 *nalp;
+ guint save = 0;
+ gint state = 0;
nal_len = strlen (params[i]);
nalp = g_malloc (nal_len + 2);
- nal_len = decode_base64 (params[i], nalp + 2);
+
+ nal_len =
+ g_base64_decode_step (params[i], nal_len, nalp + 2, &state, &save);
nalp[0] = (nal_len >> 8) & 0xff;
nalp[1] = nal_len & 0xff;
len += nal_len + 2;