blob: fc98e7c9be6de0db9b1844d09ee65ff5f97fa281 [file] [log] [blame]
John Koleszar0ea50ce2010-05-18 11:58:33 -04001/*
Yaowu Xub695b1c2016-10-25 10:32:33 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar0ea50ce2010-05-18 11:58:33 -04003 *
Yaowu Xub695b1c2016-10-25 10:32:33 -07004 * 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 Koleszar0ea50ce2010-05-18 11:58:33 -040010 */
11
John Koleszara1f15812012-11-27 11:16:15 -080012#include <assert.h>
Yaowu Xuc5ad31e2015-07-20 11:05:04 -070013
Alex Converseeb00cb22016-06-06 15:12:06 -070014#include "./dkboolwriter.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -040015
Nathan E. Eggee691a242016-06-16 09:00:39 -040016static 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 Converseeb00cb22016-06-06 15:12:06 -070020void aom_dk_start_encode(aom_dk_writer *br, uint8_t *source) {
John Koleszarc6b90392012-07-13 15:21:29 -070021 br->lowvalue = 0;
clang-format1214cee2016-08-08 22:59:08 -070022 br->range = 255;
23 br->count = -24;
24 br->buffer = source;
25 br->pos = 0;
Alex Converseeb00cb22016-06-06 15:12:06 -070026 aom_dk_write_bit(br, 0);
John Koleszar0ea50ce2010-05-18 11:58:33 -040027}
28
Alex Converseeb00cb22016-06-06 15:12:06 -070029void aom_dk_stop_encode(aom_dk_writer *br) {
John Koleszarc6b90392012-07-13 15:21:29 -070030 int i;
John Koleszar0ea50ce2010-05-18 11:58:33 -040031
Angie Chiang4de81ee2016-07-26 14:14:20 -070032#if CONFIG_BITSTREAM_DEBUG
33 bitstream_queue_set_skip_write(1);
34#endif // CONFIG_BITSTREAM_DEBUG
35
Alex Converseeb00cb22016-06-06 15:12:06 -070036 for (i = 0; i < 32; i++) aom_dk_write_bit(br, 0);
John Koleszar872fc3d2013-03-12 14:30:18 -070037
Angie Chiang4de81ee2016-07-26 14:14:20 -070038#if CONFIG_BITSTREAM_DEBUG
39 bitstream_queue_set_skip_write(0);
40#endif // CONFIG_BITSTREAM_DEBUG
41
John Koleszar872fc3d2013-03-12 14:30:18 -070042 // Ensure there's no ambigous collision with any index marker bytes
clang-format1214cee2016-08-08 22:59:08 -070043 if ((br->buffer[br->pos - 1] & 0xe0) == 0xc0) br->buffer[br->pos++] = 0;
John Koleszar0ea50ce2010-05-18 11:58:33 -040044}