/src/ffmpeg/libavutil/base64_internal.h
Line | Count | Source |
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 | | |
33 | | static inline char *ff_base64_encode_c(char *out, const uint8_t *in, int in_size, const char *b64) |
34 | 0 | { |
35 | 0 | char *ret, *dst; |
36 | 0 | unsigned i_bits = 0; |
37 | 0 | int i_shift = 0; |
38 | 0 | int bytes_remaining = in_size; |
39 | |
|
40 | 0 | ret = dst = out; |
41 | 0 | while (bytes_remaining > 3) { |
42 | 0 | i_bits = AV_RB32(in); |
43 | 0 | in += 3; bytes_remaining -= 3; |
44 | 0 | *dst++ = b64[ i_bits>>26 ]; |
45 | 0 | *dst++ = b64[(i_bits>>20) & 0x3F]; |
46 | 0 | *dst++ = b64[(i_bits>>14) & 0x3F]; |
47 | 0 | *dst++ = b64[(i_bits>>8 ) & 0x3F]; |
48 | 0 | } |
49 | 0 | i_bits = 0; |
50 | 0 | while (bytes_remaining) { |
51 | 0 | i_bits = (i_bits << 8) + *in++; |
52 | 0 | bytes_remaining--; |
53 | 0 | i_shift += 8; |
54 | 0 | } |
55 | 0 | while (i_shift > 0) { |
56 | 0 | *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; |
57 | 0 | i_shift -= 6; |
58 | 0 | } |
59 | 0 | while ((dst - ret) & 3) |
60 | 0 | *dst++ = '='; |
61 | 0 | *dst = '\0'; |
62 | |
|
63 | 0 | return ret; |
64 | 0 | } |
65 | | |
66 | | #endif /* AVUTIL_BASE64_INTERNAL_H */ |