/*
 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
 *
 * This source code is subject to the terms of the BSD 3-Clause Clear License
 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
 * License was not distributed with this source code in the LICENSE file, you
 * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  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
 * aomedia.org/license/patent-license/.
 */

#ifndef AVM_AVM_UTIL_DEBUG_UTIL_H_
#define AVM_AVM_UTIL_DEBUG_UTIL_H_

#include "config/avm_config.h"

#include "avm_dsp/prob.h"

#ifdef __cplusplus
extern "C" {
#endif

void avm_bitstream_queue_set_frame_write(int frame_idx);
int avm_bitstream_queue_get_frame_writee(void);
void avm_bitstream_queue_set_frame_read(int frame_idx);
int avm_bitstream_queue_get_frame_read(void);

#if CONFIG_BITSTREAM_DEBUG
/* This is a debug tool used to detect bitstream error. On encoder side, it
 * pushes each bit and probability into a queue before the bit is written into
 * the Arithmetic coder. On decoder side, whenever a bit is read out from the
 * Arithmetic coder, it pops out the reference bit and probability from the
 * queue as well. If the two results do not match, this debug tool will report
 * an error.  This tool can be used to pin down the bitstream error precisely.
 * By combining gdb's backtrace method, we can detect which module causes the
 * bitstream error. */
int bitstream_queue_get_write(void);
int bitstream_queue_get_read(void);
void bitstream_queue_record_write(void);
void bitstream_queue_reset_write(void);
void bitstream_queue_pop(int *result, avm_cdf_prob *cdf, int *nsymbs);
void bitstream_queue_push(int result, const avm_cdf_prob *cdf, int nsymbs);
void bitstream_queue_set_skip_write(int skip);
void bitstream_queue_set_skip_read(int skip);
#endif  // CONFIG_BITSTREAM_DEBUG

#if CONFIG_MISMATCH_DEBUG
struct yv12_buffer_config;
void mismatch_move_frame_idx_w(int check_overflow);
void mismatch_move_frame_idx_r(int check_underflow);
void mismatch_reset_frame(int num_planes);
void mismatch_record_block_pre(const uint16_t *src, int src_stride,
                               int frame_offset, int plane, int pixel_c,
                               int pixel_r, int blk_w, int blk_h);
void mismatch_record_block_tx(const uint16_t *src, int src_stride,
                              int frame_offset, int plane, int pixel_c,
                              int pixel_r, int blk_w, int blk_h);
void mismatch_check_block_pre(const uint16_t *src, int src_stride,
                              int frame_offset, int pixels_c, int pixels_r,
                              int plane, int pixel_c, int pixel_r, int blk_w,
                              int blk_h);
void mismatch_check_block_tx(const uint16_t *src, int src_stride,
                             int frame_offset, int pixels_c, int pixels_r,
                             int plane, int pixel_c, int pixel_r, int blk_w,
                             int blk_h);
void mismatch_record_block_deblocking(const uint16_t *src, int src_stride,
                                      int frame_offset, int plane, int pixel_c,
                                      int pixel_r, int blk_w, int blk_h);
void mismatch_check_block_deblocking(const uint16_t *src, int src_stride,
                                     int frame_offset, int pixels_c,
                                     int pixels_r, int plane, int pixel_c,
                                     int pixel_r, int blk_w, int blk_h);
void mismatch_record_block_cdef(const uint16_t *src, int src_stride,
                                int frame_offset, int plane, int pixel_c,
                                int pixel_r, int blk_w, int blk_h);
void mismatch_check_block_cdef(const uint16_t *src, int src_stride,
                               int frame_offset, int pixels_c, int pixels_r,
                               int plane, int pixel_c, int pixel_r, int blk_w,
                               int blk_h);
void mismatch_record_block_ccso(const uint16_t *src, int src_stride,
                                int frame_offset, int plane, int pixel_c,
                                int pixel_r, int blk_w, int blk_h);
void mismatch_check_block_ccso(const uint16_t *src, int src_stride,
                               int frame_offset, int pixels_c, int pixels_r,
                               int plane, int pixel_c, int pixel_r, int blk_w,
                               int blk_h);
void mismatch_record_block_restoration(const uint16_t *src, int src_stride,
                                       int frame_offset, int plane, int pixel_c,
                                       int pixel_r, int blk_w, int blk_h);
void mismatch_check_block_restoration(const uint16_t *src, int src_stride,
                                      int frame_offset, int pixels_c,
                                      int pixels_r, int plane, int pixel_c,
                                      int pixel_r, int blk_w, int blk_h);
void mismatch_record_block_gdf(const uint16_t *src, int src_stride,
                               int frame_offset, int plane, int pixel_c,
                               int pixel_r, int blk_w, int blk_h);
void mismatch_check_block_gdf(const uint16_t *src, int src_stride,
                              int frame_offset, int pixels_c, int pixels_r,
                              int plane, int pixel_c, int pixel_r, int blk_w,
                              int blk_h);
void mismatch_record_frame(const struct yv12_buffer_config *buf, int num_planes,
                           int stage);
void mismatch_check_frame(const struct yv12_buffer_config *buf,
                          int display_order_hint, int num_planes, int stage);
#endif  // CONFIG_MISMATCH_DEBUG

#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // AVM_AVM_UTIL_DEBUG_UTIL_H_
