Wan-Teh Chang | d9a824f | 2020-03-23 20:18:33 -0700 | [diff] [blame] | 1 | /* |
James Zern | b7c05bd | 2024-06-11 19:15:10 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved. |
Wan-Teh Chang | d9a824f | 2020-03-23 20:18:33 -0700 | [diff] [blame] | 3 | * |
| 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 10 | */ |
| 11 | |
| 12 | #include <string.h> |
| 13 | #include "aom_dsp/bitwriter.h" |
| 14 | |
| 15 | void aom_start_encode(aom_writer *w, uint8_t *source) { |
| 16 | w->buffer = source; |
| 17 | w->pos = 0; |
| 18 | od_ec_enc_init(&w->ec, 62025); |
| 19 | } |
| 20 | |
| 21 | int aom_stop_encode(aom_writer *w) { |
| 22 | int nb_bits; |
| 23 | uint32_t bytes; |
| 24 | unsigned char *data; |
| 25 | data = od_ec_enc_done(&w->ec, &bytes); |
Satheesh Kumar | 173c140 | 2023-12-11 15:44:04 +0530 | [diff] [blame] | 26 | if (!data) { |
| 27 | od_ec_enc_clear(&w->ec); |
| 28 | return -1; |
| 29 | } |
Wan-Teh Chang | d9a824f | 2020-03-23 20:18:33 -0700 | [diff] [blame] | 30 | nb_bits = od_ec_enc_tell(&w->ec); |
| 31 | memcpy(w->buffer, data, bytes); |
| 32 | w->pos = bytes; |
| 33 | od_ec_enc_clear(&w->ec); |
| 34 | return nb_bits; |
| 35 | } |
Cheng Chen | 8e74aaf | 2020-08-24 21:07:12 -0700 | [diff] [blame] | 36 | |
| 37 | int aom_tell_size(aom_writer *w) { |
| 38 | const int nb_bits = od_ec_enc_tell(&w->ec); |
| 39 | return nb_bits; |
| 40 | } |