/src/libvpx/vpx_dsp/bitwriter.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license |
5 | | * that can be found in the LICENSE file in the root of the source |
6 | | * tree. An additional intellectual property rights grant can be found |
7 | | * in the file PATENTS. All contributing project authors may |
8 | | * be found in the AUTHORS file in the root of the source tree. |
9 | | */ |
10 | | |
11 | | #include <assert.h> |
12 | | #include <limits.h> |
13 | | |
14 | | #include "./bitwriter.h" |
15 | | |
16 | | #if CONFIG_BITSTREAM_DEBUG |
17 | | #include "vpx_util/vpx_debug_util.h" |
18 | | #endif |
19 | | |
20 | 86.9k | void vpx_start_encode(vpx_writer *br, uint8_t *source, size_t size) { |
21 | 86.9k | br->lowvalue = 0; |
22 | 86.9k | br->range = 255; |
23 | 86.9k | br->count = -24; |
24 | 86.9k | br->error = 0; |
25 | 86.9k | br->pos = 0; |
26 | | // Make sure it is safe to cast br->pos to int in vpx_write(). |
27 | 86.9k | if (size > INT_MAX) size = INT_MAX; |
28 | 86.9k | br->size = (unsigned int)size; |
29 | 86.9k | br->buffer = source; |
30 | 86.9k | vpx_write_bit(br, 0); |
31 | 86.9k | } |
32 | | |
33 | 86.9k | int vpx_stop_encode(vpx_writer *br) { |
34 | 86.9k | int i; |
35 | | |
36 | | #if CONFIG_BITSTREAM_DEBUG |
37 | | bitstream_queue_set_skip_write(1); |
38 | | #endif |
39 | 2.87M | for (i = 0; i < 32; i++) vpx_write_bit(br, 0); |
40 | | |
41 | | // Ensure there's no ambigous collision with any index marker bytes |
42 | 86.9k | if (!br->error && (br->buffer[br->pos - 1] & 0xe0) == 0xc0) { |
43 | 2.52k | if (br->pos < br->size) { |
44 | 2.52k | br->buffer[br->pos++] = 0; |
45 | 2.52k | } else { |
46 | 0 | br->error = 1; |
47 | 0 | } |
48 | 2.52k | } |
49 | | |
50 | | #if CONFIG_BITSTREAM_DEBUG |
51 | | bitstream_queue_set_skip_write(0); |
52 | | #endif |
53 | | |
54 | 86.9k | return br->error ? -1 : 0; |
55 | 86.9k | } |