John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
Yaowu Xu | b695b1c | 2016-10-25 10:32:33 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
Yaowu Xu | b695b1c | 2016-10-25 10:32:33 -0700 | [diff] [blame] | 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. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 10 | */ |
| 11 | |
John Koleszar | a1f1581 | 2012-11-27 11:16:15 -0800 | [diff] [blame] | 12 | #include <assert.h> |
Yaowu Xu | c5ad31e | 2015-07-20 11:05:04 -0700 | [diff] [blame] | 13 | |
Alex Converse | eb00cb2 | 2016-06-06 15:12:06 -0700 | [diff] [blame] | 14 | #include "./dkboolwriter.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 15 | |
Nathan E. Egge | e691a24 | 2016-06-16 09:00:39 -0400 | [diff] [blame] | 16 | static INLINE void aom_dk_write_bit(aom_dk_writer *w, int bit) { |
| 17 | aom_dk_write(w, bit, 128); // aom_prob_half |
| 18 | } |
| 19 | |
Alex Converse | eb00cb2 | 2016-06-06 15:12:06 -0700 | [diff] [blame] | 20 | void aom_dk_start_encode(aom_dk_writer *br, uint8_t *source) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 21 | br->lowvalue = 0; |
clang-format | 1214cee | 2016-08-08 22:59:08 -0700 | [diff] [blame] | 22 | br->range = 255; |
| 23 | br->count = -24; |
| 24 | br->buffer = source; |
| 25 | br->pos = 0; |
Alex Converse | eb00cb2 | 2016-06-06 15:12:06 -0700 | [diff] [blame] | 26 | aom_dk_write_bit(br, 0); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 27 | } |
| 28 | |
Alex Converse | eb00cb2 | 2016-06-06 15:12:06 -0700 | [diff] [blame] | 29 | void aom_dk_stop_encode(aom_dk_writer *br) { |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 30 | int i; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 31 | |
Angie Chiang | 4de81ee | 2016-07-26 14:14:20 -0700 | [diff] [blame] | 32 | #if CONFIG_BITSTREAM_DEBUG |
| 33 | bitstream_queue_set_skip_write(1); |
| 34 | #endif // CONFIG_BITSTREAM_DEBUG |
| 35 | |
Alex Converse | eb00cb2 | 2016-06-06 15:12:06 -0700 | [diff] [blame] | 36 | for (i = 0; i < 32; i++) aom_dk_write_bit(br, 0); |
John Koleszar | 872fc3d | 2013-03-12 14:30:18 -0700 | [diff] [blame] | 37 | |
Angie Chiang | 4de81ee | 2016-07-26 14:14:20 -0700 | [diff] [blame] | 38 | #if CONFIG_BITSTREAM_DEBUG |
| 39 | bitstream_queue_set_skip_write(0); |
| 40 | #endif // CONFIG_BITSTREAM_DEBUG |
| 41 | |
John Koleszar | 872fc3d | 2013-03-12 14:30:18 -0700 | [diff] [blame] | 42 | // Ensure there's no ambigous collision with any index marker bytes |
clang-format | 1214cee | 2016-08-08 22:59:08 -0700 | [diff] [blame] | 43 | if ((br->buffer[br->pos - 1] & 0xe0) == 0xc0) br->buffer[br->pos++] = 0; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 44 | } |