FFmpeg
Loading...
Searching...
No Matches
base64_internal.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 Ryan Martell. (rdm4@martellventures.com)
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVUTIL_BASE64_INTERNAL_H
22#define AVUTIL_BASE64_INTERNAL_H
23
24#include <stdint.h>
25#include "intreadwrite.h"
26
27/*****************************************************************************
28* b64_encode: Stolen from VLC's http.c.
29* Simplified by Michael.
30* Fixed edge cases and made it work from data (vs. strings) by Ryan.
31*****************************************************************************/
32
33static inline char *ff_base64_encode_c(char *out, const uint8_t *in, int in_size, const char *b64)
34{
35 char *ret, *dst;
36 unsigned i_bits = 0;
37 int i_shift = 0;
38 int bytes_remaining = in_size;
39
40 ret = dst = out;
41 while (bytes_remaining > 3) {
42 i_bits = AV_RB32(in);
43 in += 3; bytes_remaining -= 3;
44 *dst++ = b64[ i_bits>>26 ];
45 *dst++ = b64[(i_bits>>20) & 0x3F];
46 *dst++ = b64[(i_bits>>14) & 0x3F];
47 *dst++ = b64[(i_bits>>8 ) & 0x3F];
48 }
49 i_bits = 0;
50 while (bytes_remaining) {
51 i_bits = (i_bits << 8) + *in++;
52 bytes_remaining--;
53 i_shift += 8;
54 }
55 while (i_shift > 0) {
56 *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f];
57 i_shift -= 6;
58 }
59 while ((dst - ret) & 3)
60 *dst++ = '=';
61 *dst = '\0';
62
63 return ret;
64}
65
66#endif /* AVUTIL_BASE64_INTERNAL_H */
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static FILE * out
static char * ff_base64_encode_c(char *out, const uint8_t *in, int in_size, const char *b64)
#define AV_RB32(p)