blob: ea73df8dac15b80b6a78ffaee15a94c8c03b1134 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu6e0d64c2016-10-10 16:21:45 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu6e0d64c2016-10-10 16:21:45 -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.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuc27fc142016-08-22 16:08:15 -070012#include <assert.h>
13#include <stdio.h>
David Barkerfa2865b2016-11-11 09:25:56 +000014#include <string.h>
Angie Chiang6062a8b2016-09-21 16:01:04 -070015#include "aom_util/debug_util.h"
David Barkerfa2865b2016-11-11 09:25:56 +000016
Yaowu Xuc27fc142016-08-22 16:08:15 -070017#define QUEUE_MAX_SIZE 2000000
18static int result_queue[QUEUE_MAX_SIZE];
David Barkerfa2865b2016-11-11 09:25:56 +000019static int nsymbs_queue[QUEUE_MAX_SIZE];
20static aom_cdf_prob cdf_queue[QUEUE_MAX_SIZE][16];
David Barkerfa2865b2016-11-11 09:25:56 +000021
Yaowu Xuc27fc142016-08-22 16:08:15 -070022static int queue_r = 0;
23static int queue_w = 0;
24static int queue_prev_w = -1;
25static int skip_r = 0;
26static int skip_w = 0;
27
Angie Chiangcb9a9eb2016-09-01 16:10:50 -070028static int frame_idx_w = 0;
29
30static int frame_idx_r = 0;
31
32void bitstream_queue_set_frame_write(int frame_idx) { frame_idx_w = frame_idx; }
33
Angie Chiang6062a8b2016-09-21 16:01:04 -070034int bitstream_queue_get_frame_write(void) { return frame_idx_w; }
Angie Chiangcb9a9eb2016-09-01 16:10:50 -070035
36void bitstream_queue_set_frame_read(int frame_idx) { frame_idx_r = frame_idx; }
37
Angie Chiang6062a8b2016-09-21 16:01:04 -070038int bitstream_queue_get_frame_read(void) { return frame_idx_r; }
Angie Chiangcb9a9eb2016-09-01 16:10:50 -070039
Yaowu Xuc27fc142016-08-22 16:08:15 -070040void bitstream_queue_set_skip_write(int skip) { skip_w = skip; }
41
42void bitstream_queue_set_skip_read(int skip) { skip_r = skip; }
43
44void bitstream_queue_record_write(void) { queue_prev_w = queue_w; }
45
46void bitstream_queue_reset_write(void) { queue_w = queue_prev_w; }
47
48int bitstream_queue_get_write(void) { return queue_w; }
49
50int bitstream_queue_get_read(void) { return queue_r; }
51
Nathan E. Egge476c63c2017-05-18 18:35:16 -040052void bitstream_queue_pop(int *result, aom_cdf_prob *cdf, int *nsymbs) {
David Barkerfa2865b2016-11-11 09:25:56 +000053 if (!skip_r) {
54 if (queue_w == queue_r) {
55 printf("buffer underflow queue_w %d queue_r %d\n", queue_w, queue_r);
56 assert(0);
57 }
58 *result = result_queue[queue_r];
59 *nsymbs = nsymbs_queue[queue_r];
60 memcpy(cdf, cdf_queue[queue_r], *nsymbs * sizeof(*cdf));
61 queue_r = (queue_r + 1) % QUEUE_MAX_SIZE;
62 }
63}
64
Nathan E. Egge476c63c2017-05-18 18:35:16 -040065void bitstream_queue_push(int result, const aom_cdf_prob *cdf, int nsymbs) {
David Barkerfa2865b2016-11-11 09:25:56 +000066 if (!skip_w) {
67 result_queue[queue_w] = result;
68 nsymbs_queue[queue_w] = nsymbs;
69 memcpy(cdf_queue[queue_w], cdf, nsymbs * sizeof(*cdf));
Yaowu Xuc27fc142016-08-22 16:08:15 -070070 queue_w = (queue_w + 1) % QUEUE_MAX_SIZE;
71 if (queue_w == queue_r) {
72 printf("buffer overflow queue_w %d queue_r %d\n", queue_w, queue_r);
73 assert(0);
74 }
75 }
76}