bitwriter.c 885 Bytes
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5 6
 *  that can be found in the LICENSE file in the root of the source
 *  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.
John Koleszar's avatar
John Koleszar committed
9 10
 */

John Koleszar's avatar
John Koleszar committed
11
#include <assert.h>
Yaowu Xu's avatar
Yaowu Xu committed
12

13
#include "./bitwriter.h"
John Koleszar's avatar
John Koleszar committed
14

Yaowu Xu's avatar
Yaowu Xu committed
15
void vpx_start_encode(vpx_writer *br, uint8_t *source) {
John Koleszar's avatar
John Koleszar committed
16
  br->lowvalue = 0;
clang-format's avatar
clang-format committed
17 18 19 20
  br->range = 255;
  br->count = -24;
  br->buffer = source;
  br->pos = 0;
Yaowu Xu's avatar
Yaowu Xu committed
21
  vpx_write_bit(br, 0);
John Koleszar's avatar
John Koleszar committed
22 23
}

Yaowu Xu's avatar
Yaowu Xu committed
24
void vpx_stop_encode(vpx_writer *br) {
John Koleszar's avatar
John Koleszar committed
25
  int i;
John Koleszar's avatar
John Koleszar committed
26

clang-format's avatar
clang-format committed
27
  for (i = 0; i < 32; i++) vpx_write_bit(br, 0);
28 29

  // Ensure there's no ambigous collision with any index marker bytes
clang-format's avatar
clang-format committed
30
  if ((br->buffer[br->pos - 1] & 0xe0) == 0xc0) br->buffer[br->pos++] = 0;
John Koleszar's avatar
John Koleszar committed
31
}