2016-04-14 00:53:34 +03:00
|
|
|
/*
|
2016-09-28 21:33:20 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2016-04-14 00:53:34 +03:00
|
|
|
*
|
2016-09-28 21:33:20 +03:00
|
|
|
* This source code is subject to the terms of the BSD 2 Clause License and
|
|
|
|
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
|
|
|
|
* was not distributed with this source code in the LICENSE file, you can
|
|
|
|
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
|
|
|
|
* Media Patent License 1.0 was not distributed with this source code in the
|
|
|
|
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
2016-04-14 00:53:34 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-09-18 01:11:16 +03:00
|
|
|
#include "aom_dsp/buf_ans.h"
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "aom_mem/aom_mem.h"
|
2016-09-18 01:11:16 +03:00
|
|
|
#include "aom/internal/aom_codec_internal.h"
|
2016-04-14 00:53:34 +03:00
|
|
|
|
2016-09-18 01:11:16 +03:00
|
|
|
void aom_buf_ans_alloc(struct BufAnsCoder *c,
|
|
|
|
struct aom_internal_error_info *error, int size_hint) {
|
|
|
|
c->error = error;
|
2016-04-14 00:53:34 +03:00
|
|
|
c->size = size_hint;
|
2016-09-18 01:11:16 +03:00
|
|
|
AOM_CHECK_MEM_ERROR(error, c->buf, aom_malloc(c->size * sizeof(*c->buf)));
|
2016-04-14 00:53:34 +03:00
|
|
|
// Initialize to overfull to trigger the assert in write.
|
|
|
|
c->offset = c->size + 1;
|
|
|
|
}
|
|
|
|
|
2016-09-18 01:11:16 +03:00
|
|
|
void aom_buf_ans_free(struct BufAnsCoder *c) {
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_free(c->buf);
|
2016-04-14 00:53:34 +03:00
|
|
|
c->buf = NULL;
|
|
|
|
c->size = 0;
|
|
|
|
}
|
|
|
|
|
2016-09-18 01:11:16 +03:00
|
|
|
void aom_buf_ans_grow(struct BufAnsCoder *c) {
|
2016-04-14 00:53:34 +03:00
|
|
|
struct buffered_ans_symbol *new_buf = NULL;
|
|
|
|
int new_size = c->size * 2;
|
2016-09-18 01:11:16 +03:00
|
|
|
AOM_CHECK_MEM_ERROR(c->error, new_buf,
|
|
|
|
aom_malloc(new_size * sizeof(*new_buf)));
|
2016-04-14 00:53:34 +03:00
|
|
|
memcpy(new_buf, c->buf, c->size * sizeof(*c->buf));
|
2016-08-31 00:01:10 +03:00
|
|
|
aom_free(c->buf);
|
2016-04-14 00:53:34 +03:00
|
|
|
c->buf = new_buf;
|
|
|
|
c->size = new_size;
|
|
|
|
}
|