rtsp: keep track of amount of decoded bytes

Keep track of the actual amount of decoded bytes, which can be less than 3 when
we decode the last bits of a base64 message.
This commit is contained in:
Wim Taymans 2009-03-11 14:07:05 +01:00
parent e633c46e95
commit 16225d45be

View file

@ -103,6 +103,7 @@ typedef struct
guint cin; guint cin;
gchar out[3]; gchar out[3];
guint cout; guint cout;
guint coutl;
} DecodeCtx; } DecodeCtx;
static GstRTSPResult read_line (gint fd, guint8 * buffer, guint * idx, static GstRTSPResult read_line (gint fd, guint8 * buffer, guint * idx,
@ -976,7 +977,7 @@ fill_bytes (gint fd, guint8 * buffer, guint size, DecodeCtx * ctx)
gint r; gint r;
while (size > 0) { while (size > 0) {
while (size > 0 && ctx->cout < 3) { while (size > 0 && ctx->cout < ctx->coutl) {
/* we have some leftover bytes */ /* we have some leftover bytes */
*buffer++ = ctx->out[ctx->cout]; *buffer++ = ctx->out[ctx->cout];
ctx->cout++; ctx->cout++;
@ -1000,6 +1001,7 @@ fill_bytes (gint fd, guint8 * buffer, guint size, DecodeCtx * ctx)
r = g_base64_decode_step ((const gchar *) ctx->in, 4, r = g_base64_decode_step ((const gchar *) ctx->in, 4,
(guchar *) ctx->out, &ctx->state, &ctx->save); (guchar *) ctx->out, &ctx->state, &ctx->save);
ctx->cout = 0; ctx->cout = 0;
ctx->coutl = r;
ctx->cin = 0; ctx->cin = 0;
} }
} }