| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Common bit i/o utils | ||
| 3 | * Copyright (c) 2000, 2001 Fabrice Bellard | ||
| 4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
| 5 | * Copyright (c) 2010 Loren Merritt | ||
| 6 | * | ||
| 7 | * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at> | ||
| 8 | * | ||
| 9 | * This file is part of FFmpeg. | ||
| 10 | * | ||
| 11 | * FFmpeg is free software; you can redistribute it and/or | ||
| 12 | * modify it under the terms of the GNU Lesser General Public | ||
| 13 | * License as published by the Free Software Foundation; either | ||
| 14 | * version 2.1 of the License, or (at your option) any later version. | ||
| 15 | * | ||
| 16 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 19 | * Lesser General Public License for more details. | ||
| 20 | * | ||
| 21 | * You should have received a copy of the GNU Lesser General Public | ||
| 22 | * License along with FFmpeg; if not, write to the Free Software | ||
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 24 | */ | ||
| 25 | |||
| 26 | /** | ||
| 27 | * @file | ||
| 28 | * bitstream api. | ||
| 29 | */ | ||
| 30 | |||
| 31 | #include <stdint.h> | ||
| 32 | #include <string.h> | ||
| 33 | |||
| 34 | #include "config.h" | ||
| 35 | #include "libavutil/avassert.h" | ||
| 36 | #include "libavutil/intreadwrite.h" | ||
| 37 | #include "put_bits.h" | ||
| 38 | |||
| 39 | 1026 | void ff_put_string(PutBitContext *pb, const char *string, int terminate_string) | |
| 40 | { | ||
| 41 |
2/2✓ Branch 0 taken 5104 times.
✓ Branch 1 taken 1026 times.
|
6130 | while (*string) { |
| 42 | 5104 | put_bits(pb, 8, *string); | |
| 43 | 5104 | string++; | |
| 44 | } | ||
| 45 |
2/2✓ Branch 0 taken 366 times.
✓ Branch 1 taken 660 times.
|
1026 | if (terminate_string) |
| 46 | 366 | put_bits(pb, 8, 0); | |
| 47 | 1026 | } | |
| 48 | |||
| 49 | 1234015 | void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) | |
| 50 | { | ||
| 51 | 1234015 | int words = length >> 4; | |
| 52 | 1234015 | int bits = length & 15; | |
| 53 | int i; | ||
| 54 | |||
| 55 |
2/2✓ Branch 0 taken 113905 times.
✓ Branch 1 taken 1120110 times.
|
1234015 | if (length == 0) |
| 56 | 113905 | return; | |
| 57 | |||
| 58 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1120110 times.
|
1120110 | av_assert0(length <= put_bits_left(pb)); |
| 59 | |||
| 60 |
4/4✓ Branch 0 taken 112615 times.
✓ Branch 1 taken 1007495 times.
✓ Branch 3 taken 96335 times.
✓ Branch 4 taken 16280 times.
|
1120110 | if (CONFIG_SMALL || words < 16 || put_bits_count(pb) & 7) { |
| 61 |
2/2✓ Branch 0 taken 6637410 times.
✓ Branch 1 taken 1103830 times.
|
7741240 | for (i = 0; i < words; i++) |
| 62 | 6637410 | put_bits(pb, 16, AV_RB16(src + 2 * i)); | |
| 63 | } else { | ||
| 64 |
2/2✓ Branch 1 taken 23447 times.
✓ Branch 2 taken 16280 times.
|
39727 | for (i = 0; put_bits_count(pb) & 31; i++) |
| 65 | 23447 | put_bits(pb, 8, src[i]); | |
| 66 | 16280 | flush_put_bits(pb); | |
| 67 | 16280 | memcpy(put_bits_ptr(pb), src + i, 2 * words - i); | |
| 68 | 16280 | skip_put_bytes(pb, 2 * words - i); | |
| 69 | } | ||
| 70 | |||
| 71 | 1120110 | put_bits(pb, bits, AV_RB16(src + 2 * words) >> (16 - bits)); | |
| 72 | } | ||
| 73 |