| Line | Branch | Exec | 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 | 504 | static inline char *ff_base64_encode_c(char *out, const uint8_t *in, int in_size, const char *b64) | |
| 34 | { | ||
| 35 | char *ret, *dst; | ||
| 36 | 504 | unsigned i_bits = 0; | |
| 37 | 504 | int i_shift = 0; | |
| 38 | 504 | int bytes_remaining = in_size; | |
| 39 | |||
| 40 | 504 | ret = dst = out; | |
| 41 |
2/2✓ Branch 0 taken 19274 times.
✓ Branch 1 taken 504 times.
|
19778 | while (bytes_remaining > 3) { |
| 42 | 19274 | i_bits = AV_RB32(in); | |
| 43 | 19274 | in += 3; bytes_remaining -= 3; | |
| 44 | 19274 | *dst++ = b64[ i_bits>>26 ]; | |
| 45 | 19274 | *dst++ = b64[(i_bits>>20) & 0x3F]; | |
| 46 | 19274 | *dst++ = b64[(i_bits>>14) & 0x3F]; | |
| 47 | 19274 | *dst++ = b64[(i_bits>>8 ) & 0x3F]; | |
| 48 | } | ||
| 49 | 504 | i_bits = 0; | |
| 50 |
2/2✓ Branch 0 taken 990 times.
✓ Branch 1 taken 504 times.
|
1494 | while (bytes_remaining) { |
| 51 | 990 | i_bits = (i_bits << 8) + *in++; | |
| 52 | 990 | bytes_remaining--; | |
| 53 | 990 | i_shift += 8; | |
| 54 | } | ||
| 55 |
2/2✓ Branch 0 taken 1491 times.
✓ Branch 1 taken 504 times.
|
1995 | while (i_shift > 0) { |
| 56 | 1491 | *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; | |
| 57 | 1491 | i_shift -= 6; | |
| 58 | } | ||
| 59 |
2/2✓ Branch 0 taken 513 times.
✓ Branch 1 taken 504 times.
|
1017 | while ((dst - ret) & 3) |
| 60 | 513 | *dst++ = '='; | |
| 61 | 504 | *dst = '\0'; | |
| 62 | |||
| 63 | 504 | return ret; | |
| 64 | } | ||
| 65 | |||
| 66 | #endif /* AVUTIL_BASE64_INTERNAL_H */ | ||
| 67 |