mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-09 00:37:32 +09:00
Update aom to v1.0.0
Update aom to commit id d14c5bb4f336ef1842046089849dee4a301fbbf0.
This commit is contained in:
parent
bb61121b44
commit
48f6d2e034
1087 changed files with 154333 additions and 265310 deletions
4
third_party/aom/av1/decoder/accounting.c
vendored
4
third_party/aom/av1/decoder/accounting.c
vendored
|
|
@ -15,7 +15,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "aom/aom_integer.h"
|
||||
#include "./accounting.h"
|
||||
#include "av1/decoder/accounting.h"
|
||||
|
||||
static int aom_accounting_hash(const char *str) {
|
||||
uint32_t val;
|
||||
|
|
@ -31,7 +31,7 @@ static int aom_accounting_hash(const char *str) {
|
|||
/* Dictionary lookup based on an open-addressing hash table. */
|
||||
int aom_accounting_dictionary_lookup(Accounting *accounting, const char *str) {
|
||||
int hash;
|
||||
int len;
|
||||
size_t len;
|
||||
AccountingDictionary *dictionary;
|
||||
dictionary = &accounting->syms.dictionary;
|
||||
hash = aom_accounting_hash(str);
|
||||
|
|
|
|||
3
third_party/aom/av1/decoder/accounting.h
vendored
3
third_party/aom/av1/decoder/accounting.h
vendored
|
|
@ -11,6 +11,7 @@
|
|||
#ifndef AOM_ACCOUNTING_H_
|
||||
#define AOM_ACCOUNTING_H_
|
||||
#include <stdlib.h>
|
||||
#include "aom/aomdx.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -58,8 +59,6 @@ typedef struct {
|
|||
AccountingDictionary dictionary;
|
||||
} AccountingSymbols;
|
||||
|
||||
typedef struct Accounting Accounting;
|
||||
|
||||
struct Accounting {
|
||||
AccountingSymbols syms;
|
||||
/** Size allocated for symbols (not all may be used). */
|
||||
|
|
|
|||
35
third_party/aom/av1/decoder/decint.h
vendored
35
third_party/aom/av1/decoder/decint.h
vendored
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#if !defined(_decint_H)
|
||||
# define _decint_H (1)
|
||||
# include "av1/common/pvq_state.h"
|
||||
# include "aom_dsp/bitreader.h"
|
||||
# include "aom_dsp/entdec.h"
|
||||
|
||||
typedef struct daala_dec_ctx daala_dec_ctx;
|
||||
|
||||
typedef struct daala_dec_ctx od_dec_ctx;
|
||||
|
||||
|
||||
struct daala_dec_ctx {
|
||||
/* Stores context-adaptive CDFs for PVQ. */
|
||||
od_state state;
|
||||
/* AOM entropy decoder. */
|
||||
aom_reader *r;
|
||||
int use_activity_masking;
|
||||
/* Mode of quantization matrice : FLAT (0) or HVS (1) */
|
||||
int qm;
|
||||
};
|
||||
|
||||
#endif
|
||||
7752
third_party/aom/av1/decoder/decodeframe.c
vendored
7752
third_party/aom/av1/decoder/decodeframe.c
vendored
File diff suppressed because it is too large
Load diff
64
third_party/aom/av1/decoder/decodeframe.h
vendored
64
third_party/aom/av1/decoder/decodeframe.h
vendored
|
|
@ -19,35 +19,59 @@ extern "C" {
|
|||
struct AV1Decoder;
|
||||
struct aom_read_bit_buffer;
|
||||
|
||||
#if CONFIG_REFERENCE_BUFFER
|
||||
/* Placeholder for now */
|
||||
void read_sequence_header(SequenceHeader *seq_params,
|
||||
struct aom_read_bit_buffer *rb);
|
||||
#endif
|
||||
// Reads the middle part of the sequence header OBU (from
|
||||
// frame_width_bits_minus_1 to enable_restoration) into cm->seq_params (a
|
||||
// SequenceHeader). Reports errors by calling rb->error_handler() or
|
||||
// aom_internal_error().
|
||||
void read_sequence_header(AV1_COMMON *cm, struct aom_read_bit_buffer *rb);
|
||||
|
||||
void av1_read_frame_size(struct aom_read_bit_buffer *rb, int *width,
|
||||
int *height);
|
||||
void av1_read_frame_size(struct aom_read_bit_buffer *rb, int num_bits_width,
|
||||
int num_bits_height, int *width, int *height);
|
||||
BITSTREAM_PROFILE av1_read_profile(struct aom_read_bit_buffer *rb);
|
||||
|
||||
// This function is now obsolete
|
||||
void av1_decode_frame(struct AV1Decoder *pbi, const uint8_t *data,
|
||||
const uint8_t *data_end, const uint8_t **p_data_end);
|
||||
size_t av1_decode_frame_headers_and_setup(struct AV1Decoder *pbi,
|
||||
const uint8_t *data,
|
||||
const uint8_t *data_end,
|
||||
const uint8_t **p_data_end);
|
||||
// Returns 0 on success. Sets pbi->common.error.error_code and returns -1 on
|
||||
// failure.
|
||||
int av1_check_trailing_bits(struct AV1Decoder *pbi,
|
||||
struct aom_read_bit_buffer *rb);
|
||||
|
||||
int av1_decode_frame_headers_and_setup(struct AV1Decoder *pbi,
|
||||
struct aom_read_bit_buffer *rb,
|
||||
const uint8_t *data,
|
||||
const uint8_t **p_data_end,
|
||||
int trailing_bits_present);
|
||||
|
||||
void av1_decode_tg_tiles_and_wrapup(struct AV1Decoder *pbi, const uint8_t *data,
|
||||
const uint8_t *data_end,
|
||||
const uint8_t **p_data_end, int startTile,
|
||||
int endTile, int initialize_flag);
|
||||
|
||||
#if CONFIG_OBU
|
||||
// replaces av1_decode_frame
|
||||
void av1_decode_frame_from_obus(struct AV1Decoder *pbi, const uint8_t *data,
|
||||
const uint8_t *data_end,
|
||||
const uint8_t **p_data_end);
|
||||
#endif
|
||||
// Implements the color_config() function in the spec. Reports errors by
|
||||
// calling rb->error_handler() or aom_internal_error().
|
||||
void av1_read_color_config(AV1_COMMON *cm, struct aom_read_bit_buffer *rb,
|
||||
int allow_lowbitdepth);
|
||||
|
||||
// Implements the timing_info() function in the spec. Reports errors by calling
|
||||
// rb->error_handler().
|
||||
void av1_read_timing_info_header(AV1_COMMON *cm,
|
||||
struct aom_read_bit_buffer *rb);
|
||||
|
||||
// Implements the decoder_model_info() function in the spec. Reports errors by
|
||||
// calling rb->error_handler().
|
||||
void av1_read_decoder_model_info(AV1_COMMON *cm,
|
||||
struct aom_read_bit_buffer *rb);
|
||||
|
||||
// Implements the operating_parameters_info() function in the spec. Reports
|
||||
// errors by calling rb->error_handler() or aom_internal_error().
|
||||
void av1_read_op_parameters_info(AV1_COMMON *const cm,
|
||||
struct aom_read_bit_buffer *rb, int op_num);
|
||||
|
||||
struct aom_read_bit_buffer *av1_init_read_bit_buffer(
|
||||
struct AV1Decoder *pbi, struct aom_read_bit_buffer *rb, const uint8_t *data,
|
||||
const uint8_t *data_end);
|
||||
|
||||
void av1_free_mc_tmp_buf(void *td, int use_highbd);
|
||||
|
||||
void av1_set_single_tile_decoding_mode(AV1_COMMON *const cm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
|
|
|||
2891
third_party/aom/av1/decoder/decodemv.c
vendored
2891
third_party/aom/av1/decoder/decodemv.c
vendored
File diff suppressed because it is too large
Load diff
14
third_party/aom/av1/decoder/decodemv.h
vendored
14
third_party/aom/av1/decoder/decodemv.h
vendored
|
|
@ -21,9 +21,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
void av1_read_mode_info(AV1Decoder *const pbi, MACROBLOCKD *xd,
|
||||
#if CONFIG_SUPERTX
|
||||
int supertx_enabled,
|
||||
#endif
|
||||
|
||||
int mi_row, int mi_col, aom_reader *r, int x_mis,
|
||||
int y_mis);
|
||||
|
|
@ -32,14 +29,7 @@ void av1_read_mode_info(AV1Decoder *const pbi, MACROBLOCKD *xd,
|
|||
} // extern "C"
|
||||
#endif
|
||||
|
||||
void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd,
|
||||
#if CONFIG_SUPERTX
|
||||
int supertx_enabled,
|
||||
#endif
|
||||
#if CONFIG_TXK_SEL
|
||||
int blk_row, int blk_col, int block, int plane,
|
||||
TX_SIZE tx_size,
|
||||
#endif
|
||||
aom_reader *r);
|
||||
void av1_read_tx_type(const AV1_COMMON *const cm, MACROBLOCKD *xd, int blk_row,
|
||||
int blk_col, TX_SIZE tx_size, aom_reader *r);
|
||||
|
||||
#endif // AV1_DECODER_DECODEMV_H_
|
||||
|
|
|
|||
488
third_party/aom/av1/decoder/decoder.c
vendored
488
third_party/aom/av1/decoder/decoder.c
vendored
|
|
@ -13,9 +13,9 @@
|
|||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "./av1_rtcd.h"
|
||||
#include "./aom_dsp_rtcd.h"
|
||||
#include "./aom_scale_rtcd.h"
|
||||
#include "config/av1_rtcd.h"
|
||||
#include "config/aom_dsp_rtcd.h"
|
||||
#include "config/aom_scale_rtcd.h"
|
||||
|
||||
#include "aom_mem/aom_mem.h"
|
||||
#include "aom_ports/system_state.h"
|
||||
|
|
@ -33,12 +33,8 @@
|
|||
|
||||
#include "av1/decoder/decodeframe.h"
|
||||
#include "av1/decoder/decoder.h"
|
||||
#if CONFIG_NCOBMC_ADAPT_WEIGHT
|
||||
#include "av1/common/ncobmc_kernels.h"
|
||||
#endif // CONFIG_NCOBMC_ADAPT_WEIGHT
|
||||
#if !CONFIG_PVQ
|
||||
#include "av1/decoder/detokenize.h"
|
||||
#endif
|
||||
#include "av1/decoder/obu.h"
|
||||
|
||||
static void initialize_dec(void) {
|
||||
static volatile int init_done = 0;
|
||||
|
|
@ -53,23 +49,24 @@ static void initialize_dec(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static void av1_dec_setup_mi(AV1_COMMON *cm) {
|
||||
cm->mi = cm->mip + cm->mi_stride + 1;
|
||||
cm->mi_grid_visible = cm->mi_grid_base + cm->mi_stride + 1;
|
||||
static void dec_setup_mi(AV1_COMMON *cm) {
|
||||
cm->mi = cm->mip;
|
||||
cm->mi_grid_visible = cm->mi_grid_base;
|
||||
memset(cm->mi_grid_base, 0,
|
||||
cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mi_grid_base));
|
||||
cm->mi_stride * cm->mi_rows * sizeof(*cm->mi_grid_base));
|
||||
}
|
||||
|
||||
static int av1_dec_alloc_mi(AV1_COMMON *cm, int mi_size) {
|
||||
cm->mip = aom_calloc(mi_size, sizeof(*cm->mip));
|
||||
if (!cm->mip) return 1;
|
||||
cm->mi_alloc_size = mi_size;
|
||||
cm->mi_grid_base = (MODE_INFO **)aom_calloc(mi_size, sizeof(MODE_INFO *));
|
||||
cm->mi_grid_base =
|
||||
(MB_MODE_INFO **)aom_calloc(mi_size, sizeof(MB_MODE_INFO *));
|
||||
if (!cm->mi_grid_base) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void av1_dec_free_mi(AV1_COMMON *cm) {
|
||||
static void dec_free_mi(AV1_COMMON *cm) {
|
||||
aom_free(cm->mip);
|
||||
cm->mip = NULL;
|
||||
aom_free(cm->mi_grid_base);
|
||||
|
|
@ -108,28 +105,20 @@ AV1Decoder *av1_decoder_create(BufferPool *const pool) {
|
|||
memset(&cm->next_ref_frame_map, -1, sizeof(cm->next_ref_frame_map));
|
||||
|
||||
cm->current_video_frame = 0;
|
||||
pbi->ready_for_new_data = 1;
|
||||
pbi->decoding_first_frame = 1;
|
||||
pbi->common.buffer_pool = pool;
|
||||
|
||||
cm->bit_depth = AOM_BITS_8;
|
||||
cm->dequant_bit_depth = AOM_BITS_8;
|
||||
|
||||
cm->alloc_mi = av1_dec_alloc_mi;
|
||||
cm->free_mi = av1_dec_free_mi;
|
||||
cm->setup_mi = av1_dec_setup_mi;
|
||||
cm->free_mi = dec_free_mi;
|
||||
cm->setup_mi = dec_setup_mi;
|
||||
|
||||
av1_loop_filter_init(cm);
|
||||
|
||||
#if CONFIG_NCOBMC_ADAPT_WEIGHT
|
||||
get_default_ncobmc_kernels(cm);
|
||||
#endif // CONFIG_NCOBMC_ADAPT_WEIGHT
|
||||
|
||||
#if CONFIG_AOM_QM
|
||||
aom_qm_init(cm);
|
||||
#endif
|
||||
#if CONFIG_LOOP_RESTORATION
|
||||
av1_qm_init(cm);
|
||||
av1_loop_restoration_precal();
|
||||
#endif // CONFIG_LOOP_RESTORATION
|
||||
#if CONFIG_ACCOUNTING
|
||||
pbi->acct_enabled = 1;
|
||||
aom_accounting_init(&pbi->accounting);
|
||||
|
|
@ -142,33 +131,83 @@ AV1Decoder *av1_decoder_create(BufferPool *const pool) {
|
|||
return pbi;
|
||||
}
|
||||
|
||||
void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_mt_info) {
|
||||
if (tile_mt_info != NULL) {
|
||||
#if CONFIG_MULTITHREAD
|
||||
if (tile_mt_info->job_mutex != NULL) {
|
||||
pthread_mutex_destroy(tile_mt_info->job_mutex);
|
||||
aom_free(tile_mt_info->job_mutex);
|
||||
}
|
||||
#endif
|
||||
aom_free(tile_mt_info->job_queue);
|
||||
// clear the structure as the source of this call may be a resize in which
|
||||
// case this call will be followed by an _alloc() which may fail.
|
||||
av1_zero(*tile_mt_info);
|
||||
}
|
||||
}
|
||||
|
||||
void av1_decoder_remove(AV1Decoder *pbi) {
|
||||
int i;
|
||||
|
||||
if (!pbi) return;
|
||||
|
||||
// Free the tile list output buffer.
|
||||
if (pbi->tile_list_output != NULL) aom_free(pbi->tile_list_output);
|
||||
pbi->tile_list_output = NULL;
|
||||
|
||||
aom_get_worker_interface()->end(&pbi->lf_worker);
|
||||
aom_free(pbi->lf_worker.data1);
|
||||
aom_free(pbi->tile_data);
|
||||
for (i = 0; i < pbi->num_tile_workers; ++i) {
|
||||
|
||||
if (pbi->thread_data) {
|
||||
for (int worker_idx = 0; worker_idx < pbi->max_threads - 1; worker_idx++) {
|
||||
DecWorkerData *const thread_data = pbi->thread_data + worker_idx;
|
||||
const int use_highbd = pbi->common.use_highbitdepth ? 1 : 0;
|
||||
av1_free_mc_tmp_buf(thread_data->td, use_highbd);
|
||||
aom_free(thread_data->td);
|
||||
}
|
||||
aom_free(pbi->thread_data);
|
||||
}
|
||||
|
||||
for (i = 0; i < pbi->num_workers; ++i) {
|
||||
AVxWorker *const worker = &pbi->tile_workers[i];
|
||||
aom_get_worker_interface()->end(worker);
|
||||
}
|
||||
aom_free(pbi->tile_worker_data);
|
||||
aom_free(pbi->tile_worker_info);
|
||||
aom_free(pbi->tile_data);
|
||||
aom_free(pbi->tile_workers);
|
||||
|
||||
if (pbi->num_tile_workers > 0) {
|
||||
if (pbi->num_workers > 0) {
|
||||
av1_loop_filter_dealloc(&pbi->lf_row_sync);
|
||||
av1_loop_restoration_dealloc(&pbi->lr_row_sync, pbi->num_workers);
|
||||
av1_dealloc_dec_jobs(&pbi->tile_mt_info);
|
||||
}
|
||||
|
||||
#if CONFIG_ACCOUNTING
|
||||
aom_accounting_clear(&pbi->accounting);
|
||||
#endif
|
||||
const int use_highbd = pbi->common.use_highbitdepth ? 1 : 0;
|
||||
av1_free_mc_tmp_buf(&pbi->td, use_highbd);
|
||||
|
||||
aom_free(pbi);
|
||||
}
|
||||
|
||||
void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd, int mi_row,
|
||||
int mi_col, aom_reader *r, BLOCK_SIZE bsize,
|
||||
palette_visitor_fn_t visit) {
|
||||
if (!is_inter_block(xd->mi[0])) {
|
||||
for (int plane = 0; plane < AOMMIN(2, av1_num_planes(&pbi->common));
|
||||
++plane) {
|
||||
const struct macroblockd_plane *const pd = &xd->plane[plane];
|
||||
if (is_chroma_reference(mi_row, mi_col, bsize, pd->subsampling_x,
|
||||
pd->subsampling_y)) {
|
||||
if (xd->mi[0]->palette_mode_info.palette_size[plane])
|
||||
visit(xd, plane, r);
|
||||
} else {
|
||||
assert(xd->mi[0]->palette_mode_info.palette_size[plane] == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int equal_dimensions(const YV12_BUFFER_CONFIG *a,
|
||||
const YV12_BUFFER_CONFIG *b) {
|
||||
return a->y_height == b->y_height && a->y_width == b->y_width &&
|
||||
|
|
@ -178,6 +217,7 @@ static int equal_dimensions(const YV12_BUFFER_CONFIG *a,
|
|||
aom_codec_err_t av1_copy_reference_dec(AV1Decoder *pbi, int idx,
|
||||
YV12_BUFFER_CONFIG *sd) {
|
||||
AV1_COMMON *cm = &pbi->common;
|
||||
const int num_planes = av1_num_planes(cm);
|
||||
|
||||
const YV12_BUFFER_CONFIG *const cfg = get_ref_frame(cm, idx);
|
||||
if (cfg == NULL) {
|
||||
|
|
@ -188,13 +228,25 @@ aom_codec_err_t av1_copy_reference_dec(AV1Decoder *pbi, int idx,
|
|||
aom_internal_error(&cm->error, AOM_CODEC_ERROR,
|
||||
"Incorrect buffer dimensions");
|
||||
else
|
||||
aom_yv12_copy_frame(cfg, sd);
|
||||
aom_yv12_copy_frame(cfg, sd, num_planes);
|
||||
|
||||
return cm->error.error_code;
|
||||
}
|
||||
|
||||
static int equal_dimensions_and_border(const YV12_BUFFER_CONFIG *a,
|
||||
const YV12_BUFFER_CONFIG *b) {
|
||||
return a->y_height == b->y_height && a->y_width == b->y_width &&
|
||||
a->uv_height == b->uv_height && a->uv_width == b->uv_width &&
|
||||
a->y_stride == b->y_stride && a->uv_stride == b->uv_stride &&
|
||||
a->border == b->border &&
|
||||
(a->flags & YV12_FLAG_HIGHBITDEPTH) ==
|
||||
(b->flags & YV12_FLAG_HIGHBITDEPTH);
|
||||
}
|
||||
|
||||
aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx,
|
||||
int use_external_ref,
|
||||
YV12_BUFFER_CONFIG *sd) {
|
||||
const int num_planes = av1_num_planes(cm);
|
||||
YV12_BUFFER_CONFIG *ref_buf = NULL;
|
||||
|
||||
// Get the destination reference buffer.
|
||||
|
|
@ -205,60 +257,132 @@ aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx,
|
|||
return AOM_CODEC_ERROR;
|
||||
}
|
||||
|
||||
if (!equal_dimensions(ref_buf, sd)) {
|
||||
aom_internal_error(&cm->error, AOM_CODEC_ERROR,
|
||||
"Incorrect buffer dimensions");
|
||||
if (!use_external_ref) {
|
||||
if (!equal_dimensions(ref_buf, sd)) {
|
||||
aom_internal_error(&cm->error, AOM_CODEC_ERROR,
|
||||
"Incorrect buffer dimensions");
|
||||
} else {
|
||||
// Overwrite the reference frame buffer.
|
||||
aom_yv12_copy_frame(sd, ref_buf, num_planes);
|
||||
}
|
||||
} else {
|
||||
// Overwrite the reference frame buffer.
|
||||
aom_yv12_copy_frame(sd, ref_buf);
|
||||
if (!equal_dimensions_and_border(ref_buf, sd)) {
|
||||
aom_internal_error(&cm->error, AOM_CODEC_ERROR,
|
||||
"Incorrect buffer dimensions");
|
||||
} else {
|
||||
// Overwrite the reference frame buffer pointers.
|
||||
// Once we no longer need the external reference buffer, these pointers
|
||||
// are restored.
|
||||
ref_buf->store_buf_adr[0] = ref_buf->y_buffer;
|
||||
ref_buf->store_buf_adr[1] = ref_buf->u_buffer;
|
||||
ref_buf->store_buf_adr[2] = ref_buf->v_buffer;
|
||||
ref_buf->y_buffer = sd->y_buffer;
|
||||
ref_buf->u_buffer = sd->u_buffer;
|
||||
ref_buf->v_buffer = sd->v_buffer;
|
||||
ref_buf->use_external_refernce_buffers = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return cm->error.error_code;
|
||||
}
|
||||
|
||||
/* If any buffer updating is signaled it should be done here. */
|
||||
static void swap_frame_buffers(AV1Decoder *pbi) {
|
||||
aom_codec_err_t av1_copy_new_frame_dec(AV1_COMMON *cm,
|
||||
YV12_BUFFER_CONFIG *new_frame,
|
||||
YV12_BUFFER_CONFIG *sd) {
|
||||
const int num_planes = av1_num_planes(cm);
|
||||
|
||||
if (!equal_dimensions_and_border(new_frame, sd))
|
||||
aom_internal_error(&cm->error, AOM_CODEC_ERROR,
|
||||
"Incorrect buffer dimensions");
|
||||
else
|
||||
aom_yv12_copy_frame(new_frame, sd, num_planes);
|
||||
|
||||
return cm->error.error_code;
|
||||
}
|
||||
|
||||
/* If any buffer updating is signaled it should be done here.
|
||||
Consumes a reference to cm->new_fb_idx.
|
||||
*/
|
||||
static void swap_frame_buffers(AV1Decoder *pbi, int frame_decoded) {
|
||||
int ref_index = 0, mask;
|
||||
AV1_COMMON *const cm = &pbi->common;
|
||||
BufferPool *const pool = cm->buffer_pool;
|
||||
RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
|
||||
|
||||
lock_buffer_pool(pool);
|
||||
for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
|
||||
const int old_idx = cm->ref_frame_map[ref_index];
|
||||
// Current thread releases the holding of reference frame.
|
||||
decrease_ref_count(old_idx, frame_bufs, pool);
|
||||
|
||||
// Release the reference frame holding in the reference map for the decoding
|
||||
// of the next frame.
|
||||
if (mask & 1) decrease_ref_count(old_idx, frame_bufs, pool);
|
||||
cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
|
||||
++ref_index;
|
||||
}
|
||||
|
||||
// Current thread releases the holding of reference frame.
|
||||
for (; ref_index < REF_FRAMES && !cm->show_existing_frame; ++ref_index) {
|
||||
const int old_idx = cm->ref_frame_map[ref_index];
|
||||
decrease_ref_count(old_idx, frame_bufs, pool);
|
||||
cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
|
||||
}
|
||||
|
||||
unlock_buffer_pool(pool);
|
||||
pbi->hold_ref_buf = 0;
|
||||
cm->frame_to_show = get_frame_new_buffer(cm);
|
||||
|
||||
// TODO(zoeliu): To fix the ref frame buffer update for the scenario of
|
||||
// cm->frame_parellel_decode == 1
|
||||
if (!cm->frame_parallel_decode || !cm->show_frame) {
|
||||
if (frame_decoded) {
|
||||
lock_buffer_pool(pool);
|
||||
--frame_bufs[cm->new_fb_idx].ref_count;
|
||||
|
||||
// In ext-tile decoding, the camera frame header is only decoded once. So,
|
||||
// we don't release the references here.
|
||||
if (!pbi->camera_frame_header_ready) {
|
||||
for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
|
||||
const int old_idx = cm->ref_frame_map[ref_index];
|
||||
// Current thread releases the holding of reference frame.
|
||||
decrease_ref_count(old_idx, frame_bufs, pool);
|
||||
|
||||
// Release the reference frame holding in the reference map for the
|
||||
// decoding of the next frame.
|
||||
if (mask & 1) decrease_ref_count(old_idx, frame_bufs, pool);
|
||||
cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
|
||||
++ref_index;
|
||||
}
|
||||
|
||||
// Current thread releases the holding of reference frame.
|
||||
const int check_on_show_existing_frame =
|
||||
!cm->show_existing_frame || cm->reset_decoder_state;
|
||||
for (; ref_index < REF_FRAMES && check_on_show_existing_frame;
|
||||
++ref_index) {
|
||||
const int old_idx = cm->ref_frame_map[ref_index];
|
||||
decrease_ref_count(old_idx, frame_bufs, pool);
|
||||
cm->ref_frame_map[ref_index] = cm->next_ref_frame_map[ref_index];
|
||||
}
|
||||
}
|
||||
|
||||
YV12_BUFFER_CONFIG *cur_frame = get_frame_new_buffer(cm);
|
||||
|
||||
if (cm->show_existing_frame || cm->show_frame) {
|
||||
if (pbi->output_all_layers) {
|
||||
// Append this frame to the output queue
|
||||
if (pbi->num_output_frames >= MAX_NUM_SPATIAL_LAYERS) {
|
||||
// We can't store the new frame anywhere, so drop it and return an
|
||||
// error
|
||||
decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
|
||||
cm->error.error_code = AOM_CODEC_UNSUP_BITSTREAM;
|
||||
} else {
|
||||
pbi->output_frames[pbi->num_output_frames] = cur_frame;
|
||||
pbi->output_frame_index[pbi->num_output_frames] = cm->new_fb_idx;
|
||||
pbi->num_output_frames++;
|
||||
}
|
||||
} else {
|
||||
// Replace any existing output frame
|
||||
assert(pbi->num_output_frames == 0 || pbi->num_output_frames == 1);
|
||||
if (pbi->num_output_frames > 0) {
|
||||
decrease_ref_count((int)pbi->output_frame_index[0], frame_bufs, pool);
|
||||
}
|
||||
pbi->output_frames[0] = cur_frame;
|
||||
pbi->output_frame_index[0] = cm->new_fb_idx;
|
||||
pbi->num_output_frames = 1;
|
||||
}
|
||||
} else {
|
||||
decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
|
||||
}
|
||||
|
||||
unlock_buffer_pool(pool);
|
||||
} else {
|
||||
// Nothing was decoded, so just drop this frame buffer
|
||||
lock_buffer_pool(pool);
|
||||
decrease_ref_count(cm->new_fb_idx, frame_bufs, pool);
|
||||
unlock_buffer_pool(pool);
|
||||
}
|
||||
|
||||
// Invalidate these references until the next frame starts.
|
||||
for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) {
|
||||
cm->frame_refs[ref_index].idx = INVALID_IDX;
|
||||
cm->frame_refs[ref_index].buf = NULL;
|
||||
if (!pbi->camera_frame_header_ready) {
|
||||
pbi->hold_ref_buf = 0;
|
||||
|
||||
// Invalidate these references until the next frame starts.
|
||||
for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) {
|
||||
cm->frame_refs[ref_index].idx = INVALID_IDX;
|
||||
cm->frame_refs[ref_index].buf = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -268,7 +392,6 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
|
|||
BufferPool *volatile const pool = cm->buffer_pool;
|
||||
RefCntBuffer *volatile const frame_bufs = cm->buffer_pool->frame_bufs;
|
||||
const uint8_t *source = *psource;
|
||||
int retcode = 0;
|
||||
cm->error.error_code = AOM_CODEC_OK;
|
||||
|
||||
if (size == 0) {
|
||||
|
|
@ -286,18 +409,9 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
|
|||
}
|
||||
}
|
||||
|
||||
pbi->ready_for_new_data = 0;
|
||||
|
||||
// Find a free buffer for the new frame, releasing the reference previously
|
||||
// held.
|
||||
|
||||
// Check if the previous frame was a frame without any references to it.
|
||||
// Release frame buffer if not decoding in frame parallel mode.
|
||||
if (!cm->frame_parallel_decode && cm->new_fb_idx >= 0 &&
|
||||
frame_bufs[cm->new_fb_idx].ref_count == 0)
|
||||
pool->release_fb_cb(pool->cb_priv,
|
||||
&frame_bufs[cm->new_fb_idx].raw_frame_buffer);
|
||||
|
||||
// Find a free frame buffer. Return error if can not find any.
|
||||
cm->new_fb_idx = get_free_fb(cm);
|
||||
if (cm->new_fb_idx == INVALID_IDX) return AOM_CODEC_MEM_ERROR;
|
||||
|
|
@ -305,31 +419,20 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
|
|||
// Assign a MV array to the frame buffer.
|
||||
cm->cur_frame = &pool->frame_bufs[cm->new_fb_idx];
|
||||
|
||||
pbi->hold_ref_buf = 0;
|
||||
if (cm->frame_parallel_decode) {
|
||||
AVxWorker *const worker = pbi->frame_worker_owner;
|
||||
av1_frameworker_lock_stats(worker);
|
||||
frame_bufs[cm->new_fb_idx].frame_worker_owner = worker;
|
||||
// Reset decoding progress.
|
||||
pbi->cur_buf = &frame_bufs[cm->new_fb_idx];
|
||||
pbi->cur_buf->row = -1;
|
||||
pbi->cur_buf->col = -1;
|
||||
av1_frameworker_unlock_stats(worker);
|
||||
} else {
|
||||
pbi->cur_buf = &frame_bufs[cm->new_fb_idx];
|
||||
}
|
||||
if (!pbi->camera_frame_header_ready) pbi->hold_ref_buf = 0;
|
||||
|
||||
pbi->cur_buf = &frame_bufs[cm->new_fb_idx];
|
||||
|
||||
if (setjmp(cm->error.jmp)) {
|
||||
const AVxWorkerInterface *const winterface = aom_get_worker_interface();
|
||||
int i;
|
||||
|
||||
cm->error.setjmp = 0;
|
||||
pbi->ready_for_new_data = 1;
|
||||
|
||||
// Synchronize all threads immediately as a subsequent decode call may
|
||||
// cause a resize invalidating some allocations.
|
||||
winterface->sync(&pbi->lf_worker);
|
||||
for (i = 0; i < pbi->num_tile_workers; ++i) {
|
||||
for (i = 0; i < pbi->num_workers; ++i) {
|
||||
winterface->sync(&pbi->tile_workers[i]);
|
||||
}
|
||||
|
||||
|
|
@ -349,7 +452,10 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
|
|||
}
|
||||
|
||||
// Current thread releases the holding of reference frame.
|
||||
for (; ref_index < REF_FRAMES && !cm->show_existing_frame; ++ref_index) {
|
||||
const int check_on_show_existing_frame =
|
||||
!cm->show_existing_frame || cm->reset_decoder_state;
|
||||
for (; ref_index < REF_FRAMES && check_on_show_existing_frame;
|
||||
++ref_index) {
|
||||
const int old_idx = cm->ref_frame_map[ref_index];
|
||||
decrease_ref_count(old_idx, frame_bufs, pool);
|
||||
}
|
||||
|
|
@ -365,160 +471,72 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
|
|||
|
||||
cm->error.setjmp = 1;
|
||||
|
||||
#if !CONFIG_OBU
|
||||
av1_decode_frame_headers_and_setup(pbi, source, source + size, psource);
|
||||
if (!cm->show_existing_frame) {
|
||||
av1_decode_tg_tiles_and_wrapup(pbi, source, source + size, psource, 0,
|
||||
cm->tile_rows * cm->tile_cols - 1, 1);
|
||||
}
|
||||
#else
|
||||
av1_decode_frame_from_obus(pbi, source, source + size, psource);
|
||||
int frame_decoded =
|
||||
aom_decode_frame_from_obus(pbi, source, source + size, psource);
|
||||
|
||||
if (cm->error.error_code != AOM_CODEC_OK) return 1;
|
||||
|
||||
#if TXCOEFF_TIMER
|
||||
cm->cum_txcoeff_timer += cm->txcoeff_timer;
|
||||
fprintf(stderr,
|
||||
"txb coeff block number: %d, frame time: %ld, cum time %ld in us\n",
|
||||
cm->txb_count, cm->txcoeff_timer, cm->cum_txcoeff_timer);
|
||||
cm->txcoeff_timer = 0;
|
||||
cm->txb_count = 0;
|
||||
#endif
|
||||
|
||||
swap_frame_buffers(pbi);
|
||||
// Note: At this point, this function holds a reference to cm->new_fb_idx
|
||||
// in the buffer pool. This reference is consumed by swap_frame_buffers().
|
||||
swap_frame_buffers(pbi, frame_decoded);
|
||||
|
||||
#if CONFIG_EXT_TILE
|
||||
// For now, we only extend the frame borders when the whole frame is decoded.
|
||||
// Later, if needed, extend the border for the decoded tile on the frame
|
||||
// border.
|
||||
if (pbi->dec_tile_row == -1 && pbi->dec_tile_col == -1)
|
||||
#endif // CONFIG_EXT_TILE
|
||||
// TODO(debargha): Fix encoder side mv range, so that we can use the
|
||||
// inner border extension. As of now use the larger extension.
|
||||
// aom_extend_frame_inner_borders(cm->frame_to_show);
|
||||
aom_extend_frame_borders(cm->frame_to_show);
|
||||
if (frame_decoded) {
|
||||
pbi->decoding_first_frame = 0;
|
||||
}
|
||||
|
||||
if (cm->error.error_code != AOM_CODEC_OK) return 1;
|
||||
|
||||
aom_clear_system_state();
|
||||
|
||||
if (!cm->show_existing_frame) {
|
||||
cm->last_show_frame = cm->show_frame;
|
||||
|
||||
#if CONFIG_EXT_REFS
|
||||
// NOTE: It is not supposed to ref to any frame not used as reference
|
||||
if (cm->is_reference_frame)
|
||||
#endif // CONFIG_EXT_REFS
|
||||
cm->prev_frame = cm->cur_frame;
|
||||
|
||||
if (cm->seg.enabled && !cm->frame_parallel_decode)
|
||||
av1_swap_current_and_last_seg_map(cm);
|
||||
if (cm->seg.enabled) {
|
||||
if (cm->prev_frame && (cm->mi_rows == cm->prev_frame->mi_rows) &&
|
||||
(cm->mi_cols == cm->prev_frame->mi_cols)) {
|
||||
cm->last_frame_seg_map = cm->prev_frame->seg_map;
|
||||
} else {
|
||||
cm->last_frame_seg_map = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update progress in frame parallel decode.
|
||||
if (cm->frame_parallel_decode) {
|
||||
// Need to lock the mutex here as another thread may
|
||||
// be accessing this buffer.
|
||||
AVxWorker *const worker = pbi->frame_worker_owner;
|
||||
FrameWorkerData *const frame_worker_data = worker->data1;
|
||||
av1_frameworker_lock_stats(worker);
|
||||
|
||||
if (cm->show_frame) {
|
||||
cm->current_video_frame++;
|
||||
}
|
||||
frame_worker_data->frame_decoded = 1;
|
||||
frame_worker_data->frame_context_ready = 1;
|
||||
av1_frameworker_signal_stats(worker);
|
||||
av1_frameworker_unlock_stats(worker);
|
||||
} else {
|
||||
cm->last_width = cm->width;
|
||||
cm->last_height = cm->height;
|
||||
cm->last_tile_cols = cm->tile_cols;
|
||||
cm->last_tile_rows = cm->tile_rows;
|
||||
if (cm->show_frame) {
|
||||
cm->current_video_frame++;
|
||||
}
|
||||
}
|
||||
|
||||
cm->last_width = cm->width;
|
||||
cm->last_height = cm->height;
|
||||
cm->last_tile_cols = cm->tile_cols;
|
||||
cm->last_tile_rows = cm->tile_rows;
|
||||
cm->error.setjmp = 0;
|
||||
return retcode;
|
||||
}
|
||||
|
||||
int av1_get_raw_frame(AV1Decoder *pbi, YV12_BUFFER_CONFIG *sd) {
|
||||
AV1_COMMON *const cm = &pbi->common;
|
||||
int ret = -1;
|
||||
if (pbi->ready_for_new_data == 1) return ret;
|
||||
|
||||
pbi->ready_for_new_data = 1;
|
||||
|
||||
/* no raw frame to show!!! */
|
||||
if (!cm->show_frame) return ret;
|
||||
|
||||
*sd = *cm->frame_to_show;
|
||||
ret = 0;
|
||||
aom_clear_system_state();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int av1_get_frame_to_show(AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame) {
|
||||
AV1_COMMON *const cm = &pbi->common;
|
||||
|
||||
if (!cm->show_frame || !cm->frame_to_show) return -1;
|
||||
|
||||
*frame = *cm->frame_to_show;
|
||||
return 0;
|
||||
}
|
||||
|
||||
aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
|
||||
uint32_t sizes[8], int *count,
|
||||
int *index_size,
|
||||
aom_decrypt_cb decrypt_cb,
|
||||
void *decrypt_state) {
|
||||
// A chunk ending with a byte matching 0xc0 is an invalid chunk unless
|
||||
// it is a super frame index. If the last byte of real video compression
|
||||
// data is 0xc0 the encoder must add a 0 byte. If we have the marker but
|
||||
// not the associated matching marker byte at the front of the index we have
|
||||
// an invalid bitstream and need to return an error.
|
||||
// Get the frame at a particular index in the output queue
|
||||
int av1_get_raw_frame(AV1Decoder *pbi, size_t index, YV12_BUFFER_CONFIG **sd,
|
||||
aom_film_grain_t **grain_params) {
|
||||
RefCntBuffer *const frame_bufs = pbi->common.buffer_pool->frame_bufs;
|
||||
|
||||
uint8_t marker;
|
||||
size_t frame_sz_sum = 0;
|
||||
|
||||
assert(data_sz);
|
||||
marker = read_marker(decrypt_cb, decrypt_state, data);
|
||||
*count = 0;
|
||||
|
||||
if ((marker & 0xe0) == 0xc0) {
|
||||
const uint32_t frames = (marker & 0x7) + 1;
|
||||
const uint32_t mag = ((marker >> 3) & 0x3) + 1;
|
||||
const size_t index_sz = 2 + mag * (frames - 1);
|
||||
*index_size = (int)index_sz;
|
||||
|
||||
// This chunk is marked as having a superframe index but doesn't have
|
||||
// enough data for it, thus it's an invalid superframe index.
|
||||
if (data_sz < index_sz) return AOM_CODEC_CORRUPT_FRAME;
|
||||
|
||||
{
|
||||
const uint8_t marker2 =
|
||||
read_marker(decrypt_cb, decrypt_state, data + index_sz - 1);
|
||||
|
||||
// This chunk is marked as having a superframe index but doesn't have
|
||||
// the matching marker byte at the front of the index therefore it's an
|
||||
// invalid chunk.
|
||||
if (marker != marker2) return AOM_CODEC_CORRUPT_FRAME;
|
||||
}
|
||||
|
||||
{
|
||||
// Found a valid superframe index.
|
||||
uint32_t i, j;
|
||||
const uint8_t *x = &data[1];
|
||||
|
||||
// Frames has a maximum of 8 and mag has a maximum of 4.
|
||||
uint8_t clear_buffer[28];
|
||||
assert(sizeof(clear_buffer) >= (frames - 1) * mag);
|
||||
if (decrypt_cb) {
|
||||
decrypt_cb(decrypt_state, x, clear_buffer, (frames - 1) * mag);
|
||||
x = clear_buffer;
|
||||
}
|
||||
|
||||
for (i = 0; i < frames - 1; ++i) {
|
||||
uint32_t this_sz = 0;
|
||||
|
||||
for (j = 0; j < mag; ++j) this_sz |= (*x++) << (j * 8);
|
||||
this_sz += 1;
|
||||
sizes[i] = this_sz;
|
||||
frame_sz_sum += this_sz;
|
||||
}
|
||||
sizes[i] = (uint32_t)(data_sz - index_sz - frame_sz_sum);
|
||||
*count = frames;
|
||||
}
|
||||
}
|
||||
return AOM_CODEC_OK;
|
||||
if (index >= pbi->num_output_frames) return -1;
|
||||
*sd = pbi->output_frames[index];
|
||||
*grain_params = &frame_bufs[pbi->output_frame_index[index]].film_grain_params;
|
||||
aom_clear_system_state();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the highest-spatial-layer output
|
||||
// TODO(david.barker): What should this do?
|
||||
int av1_get_frame_to_show(AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame) {
|
||||
if (pbi->num_output_frames == 0) return -1;
|
||||
|
||||
*frame = *pbi->output_frames[pbi->num_output_frames - 1];
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
192
third_party/aom/av1/decoder/decoder.h
vendored
192
third_party/aom/av1/decoder/decoder.h
vendored
|
|
@ -12,7 +12,7 @@
|
|||
#ifndef AV1_DECODER_DECODER_H_
|
||||
#define AV1_DECODER_DECODER_H_
|
||||
|
||||
#include "./aom_config.h"
|
||||
#include "config/aom_config.h"
|
||||
|
||||
#include "aom/aom_codec.h"
|
||||
#include "aom_dsp/bitreader.h"
|
||||
|
|
@ -29,73 +29,61 @@
|
|||
#include "av1/decoder/inspection.h"
|
||||
#endif
|
||||
|
||||
#if CONFIG_PVQ
|
||||
#include "aom_dsp/entdec.h"
|
||||
#include "av1/decoder/decint.h"
|
||||
#include "av1/encoder/encodemb.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TODO(hkuang): combine this with TileWorkerData.
|
||||
typedef struct TileData {
|
||||
AV1_COMMON *cm;
|
||||
aom_reader bit_reader;
|
||||
DECLARE_ALIGNED(16, MACROBLOCKD, xd);
|
||||
typedef struct ThreadData {
|
||||
aom_reader *bit_reader;
|
||||
DECLARE_ALIGNED(32, MACROBLOCKD, xd);
|
||||
/* dqcoeff are shared by all the planes. So planes must be decoded serially */
|
||||
DECLARE_ALIGNED(16, tran_low_t, dqcoeff[MAX_TX_SQUARE]);
|
||||
#if CONFIG_PVQ
|
||||
/* forward transformed predicted image, a reference for PVQ */
|
||||
DECLARE_ALIGNED(16, tran_low_t, pvq_ref_coeff[OD_TXSIZE_MAX * OD_TXSIZE_MAX]);
|
||||
#endif
|
||||
#if CONFIG_CFL
|
||||
CFL_CTX cfl;
|
||||
#endif
|
||||
DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx);
|
||||
DECLARE_ALIGNED(16, uint8_t, color_index_map[2][MAX_SB_SQUARE]);
|
||||
#if CONFIG_MRC_TX
|
||||
DECLARE_ALIGNED(16, uint8_t, mrc_mask[MAX_SB_SQUARE]);
|
||||
#endif // CONFIG_MRC_TX
|
||||
} TileData;
|
||||
DECLARE_ALIGNED(32, tran_low_t, dqcoeff[MAX_TX_SQUARE]);
|
||||
CB_BUFFER cb_buffer_base;
|
||||
uint8_t *mc_buf[2];
|
||||
int32_t mc_buf_size;
|
||||
} ThreadData;
|
||||
|
||||
typedef struct TileWorkerData {
|
||||
struct AV1Decoder *pbi;
|
||||
typedef struct TileDataDec {
|
||||
TileInfo tile_info;
|
||||
aom_reader bit_reader;
|
||||
FRAME_COUNTS counts;
|
||||
DECLARE_ALIGNED(16, MACROBLOCKD, xd);
|
||||
/* dqcoeff are shared by all the planes. So planes must be decoded serially */
|
||||
DECLARE_ALIGNED(16, tran_low_t, dqcoeff[MAX_TX_SQUARE]);
|
||||
#if CONFIG_PVQ
|
||||
/* forward transformed predicted image, a reference for PVQ */
|
||||
DECLARE_ALIGNED(16, tran_low_t, pvq_ref_coeff[OD_TXSIZE_MAX * OD_TXSIZE_MAX]);
|
||||
#endif
|
||||
#if CONFIG_CFL
|
||||
CFL_CTX cfl;
|
||||
#endif
|
||||
FRAME_CONTEXT tctx;
|
||||
DECLARE_ALIGNED(16, uint8_t, color_index_map[2][MAX_SB_SQUARE]);
|
||||
#if CONFIG_MRC_TX
|
||||
DECLARE_ALIGNED(16, uint8_t, mrc_mask[MAX_SB_SQUARE]);
|
||||
#endif // CONFIG_MRC_TX
|
||||
struct aom_internal_error_info error_info;
|
||||
} TileWorkerData;
|
||||
DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx);
|
||||
} TileDataDec;
|
||||
|
||||
typedef struct TileBufferDec {
|
||||
const uint8_t *data;
|
||||
size_t size;
|
||||
const uint8_t *raw_data_end; // The end of the raw tile buffer in the
|
||||
// bit stream.
|
||||
int col; // only used with multi-threaded decoding
|
||||
} TileBufferDec;
|
||||
|
||||
typedef struct DataBuffer {
|
||||
const uint8_t *data;
|
||||
size_t size;
|
||||
} DataBuffer;
|
||||
|
||||
typedef struct EXTERNAL_REFERENCES {
|
||||
YV12_BUFFER_CONFIG refs[MAX_EXTERNAL_REFERENCES];
|
||||
int num;
|
||||
} EXTERNAL_REFERENCES;
|
||||
|
||||
typedef struct TileJobsDec {
|
||||
TileBufferDec *tile_buffer;
|
||||
TileDataDec *tile_data;
|
||||
} TileJobsDec;
|
||||
|
||||
typedef struct AV1DecTileMTData {
|
||||
#if CONFIG_MULTITHREAD
|
||||
pthread_mutex_t *job_mutex;
|
||||
#endif
|
||||
TileJobsDec *job_queue;
|
||||
int jobs_enqueued;
|
||||
int jobs_dequeued;
|
||||
int alloc_tile_rows;
|
||||
int alloc_tile_cols;
|
||||
} AV1DecTileMT;
|
||||
|
||||
typedef struct AV1Decoder {
|
||||
DECLARE_ALIGNED(16, MACROBLOCKD, mb);
|
||||
DECLARE_ALIGNED(32, MACROBLOCKD, mb);
|
||||
|
||||
DECLARE_ALIGNED(16, AV1_COMMON, common);
|
||||
|
||||
int ready_for_new_data;
|
||||
DECLARE_ALIGNED(32, AV1_COMMON, common);
|
||||
|
||||
int refresh_frame_flags;
|
||||
|
||||
|
|
@ -105,20 +93,38 @@ typedef struct AV1Decoder {
|
|||
|
||||
AVxWorker *frame_worker_owner; // frame_worker that owns this pbi.
|
||||
AVxWorker lf_worker;
|
||||
AV1LfSync lf_row_sync;
|
||||
AV1LrSync lr_row_sync;
|
||||
AV1LrStruct lr_ctxt;
|
||||
AVxWorker *tile_workers;
|
||||
TileWorkerData *tile_worker_data;
|
||||
TileInfo *tile_worker_info;
|
||||
int num_tile_workers;
|
||||
|
||||
TileData *tile_data;
|
||||
int num_workers;
|
||||
DecWorkerData *thread_data;
|
||||
ThreadData td;
|
||||
TileDataDec *tile_data;
|
||||
int allocated_tiles;
|
||||
|
||||
TileBufferDec tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS];
|
||||
AV1DecTileMT tile_mt_info;
|
||||
|
||||
AV1LfSync lf_row_sync;
|
||||
// Each time the decoder is called, we expect to receive a full temporal unit.
|
||||
// This can contain up to one shown frame per spatial layer in the current
|
||||
// operating point (note that some layers may be entirely omitted).
|
||||
// If the 'output_all_layers' option is true, we save all of these shown
|
||||
// frames so that they can be returned to the application. If the
|
||||
// 'output_all_layers' option is false, then we only output one image per
|
||||
// temporal unit.
|
||||
//
|
||||
// Note: The saved buffers are released at the start of the next time the
|
||||
// application calls aom_codec_decode().
|
||||
int output_all_layers;
|
||||
YV12_BUFFER_CONFIG *output_frames[MAX_NUM_SPATIAL_LAYERS];
|
||||
size_t output_frame_index[MAX_NUM_SPATIAL_LAYERS]; // Buffer pool indices
|
||||
size_t num_output_frames; // How many frames are queued up so far?
|
||||
|
||||
aom_decrypt_cb decrypt_cb;
|
||||
void *decrypt_state;
|
||||
// In order to properly support random-access decoding, we need
|
||||
// to behave slightly differently for the very first frame we decode.
|
||||
// So we track whether this is the first frame or not.
|
||||
int decoding_first_frame;
|
||||
|
||||
int allow_lowbitdepth;
|
||||
int max_threads;
|
||||
|
|
@ -127,29 +133,47 @@ typedef struct AV1Decoder {
|
|||
int hold_ref_buf; // hold the reference buffer.
|
||||
|
||||
int tile_size_bytes;
|
||||
#if CONFIG_EXT_TILE
|
||||
int tile_col_size_bytes;
|
||||
int dec_tile_row, dec_tile_col; // always -1 for non-VR tile encoding
|
||||
#endif // CONFIG_EXT_TILE
|
||||
#if CONFIG_ACCOUNTING
|
||||
int acct_enabled;
|
||||
Accounting accounting;
|
||||
#endif
|
||||
size_t uncomp_hdr_size; // Size of the uncompressed header
|
||||
size_t first_partition_size; // Size of the compressed header
|
||||
int tg_size; // Number of tiles in the current tilegroup
|
||||
int tg_start; // First tile in the current tilegroup
|
||||
size_t uncomp_hdr_size; // Size of the uncompressed header
|
||||
int tg_size; // Number of tiles in the current tilegroup
|
||||
int tg_start; // First tile in the current tilegroup
|
||||
int tg_size_bit_offset;
|
||||
int sequence_header_ready;
|
||||
#if CONFIG_INSPECTION
|
||||
aom_inspect_cb inspect_cb;
|
||||
void *inspect_ctx;
|
||||
#endif
|
||||
int operating_point;
|
||||
int current_operating_point;
|
||||
int seen_frame_header;
|
||||
|
||||
// State if the camera frame header is already decoded while
|
||||
// large_scale_tile = 1.
|
||||
int camera_frame_header_ready;
|
||||
size_t frame_header_size;
|
||||
DataBuffer obu_size_hdr;
|
||||
int output_frame_width_in_tiles_minus_1;
|
||||
int output_frame_height_in_tiles_minus_1;
|
||||
int tile_count_minus_1;
|
||||
uint32_t coded_tile_data_size;
|
||||
unsigned int ext_tile_debug; // for ext-tile software debug & testing
|
||||
EXTERNAL_REFERENCES ext_refs;
|
||||
size_t tile_list_size;
|
||||
uint8_t *tile_list_output;
|
||||
size_t buffer_sz;
|
||||
} AV1Decoder;
|
||||
|
||||
int av1_receive_compressed_data(struct AV1Decoder *pbi, size_t size,
|
||||
const uint8_t **dest);
|
||||
|
||||
int av1_get_raw_frame(struct AV1Decoder *pbi, YV12_BUFFER_CONFIG *sd);
|
||||
// Get the frame at a particular index in the output queue
|
||||
int av1_get_raw_frame(AV1Decoder *pbi, size_t index, YV12_BUFFER_CONFIG **sd,
|
||||
aom_film_grain_t **grain_params);
|
||||
|
||||
int av1_get_frame_to_show(struct AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame);
|
||||
|
||||
|
|
@ -157,29 +181,16 @@ aom_codec_err_t av1_copy_reference_dec(struct AV1Decoder *pbi, int idx,
|
|||
YV12_BUFFER_CONFIG *sd);
|
||||
|
||||
aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx,
|
||||
int use_external_ref,
|
||||
YV12_BUFFER_CONFIG *sd);
|
||||
|
||||
static INLINE uint8_t read_marker(aom_decrypt_cb decrypt_cb,
|
||||
void *decrypt_state, const uint8_t *data) {
|
||||
if (decrypt_cb) {
|
||||
uint8_t marker;
|
||||
decrypt_cb(decrypt_state, data, &marker, 1);
|
||||
return marker;
|
||||
}
|
||||
return *data;
|
||||
}
|
||||
|
||||
// This function is exposed for use in tests, as well as the inlined function
|
||||
// "read_marker".
|
||||
aom_codec_err_t av1_parse_superframe_index(const uint8_t *data, size_t data_sz,
|
||||
uint32_t sizes[8], int *count,
|
||||
int *index_size,
|
||||
aom_decrypt_cb decrypt_cb,
|
||||
void *decrypt_state);
|
||||
aom_codec_err_t av1_copy_new_frame_dec(AV1_COMMON *cm,
|
||||
YV12_BUFFER_CONFIG *new_frame,
|
||||
YV12_BUFFER_CONFIG *sd);
|
||||
|
||||
struct AV1Decoder *av1_decoder_create(BufferPool *const pool);
|
||||
|
||||
void av1_decoder_remove(struct AV1Decoder *pbi);
|
||||
void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_jobs_sync);
|
||||
|
||||
static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
|
||||
BufferPool *const pool) {
|
||||
|
|
@ -196,7 +207,6 @@ static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
|
|||
}
|
||||
}
|
||||
|
||||
#if CONFIG_EXT_REFS || CONFIG_TEMPMV_SIGNALING
|
||||
static INLINE int dec_is_ref_frame_buf(AV1Decoder *const pbi,
|
||||
RefCntBuffer *frame_buf) {
|
||||
AV1_COMMON *const cm = &pbi->common;
|
||||
|
|
@ -208,7 +218,6 @@ static INLINE int dec_is_ref_frame_buf(AV1Decoder *const pbi,
|
|||
}
|
||||
return (i < INTER_REFS_PER_FRAME);
|
||||
}
|
||||
#endif // CONFIG_EXT_REFS
|
||||
|
||||
#define ACCT_STR __func__
|
||||
static INLINE int av1_read_uniform(aom_reader *r, int n) {
|
||||
|
|
@ -222,6 +231,13 @@ static INLINE int av1_read_uniform(aom_reader *r, int n) {
|
|||
return (v << 1) - m + aom_read_literal(r, 1, ACCT_STR);
|
||||
}
|
||||
|
||||
typedef void (*palette_visitor_fn_t)(MACROBLOCKD *const xd, int plane,
|
||||
aom_reader *r);
|
||||
|
||||
void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd, int mi_row,
|
||||
int mi_col, aom_reader *r, BLOCK_SIZE bsize,
|
||||
palette_visitor_fn_t visit);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
|
|
|||
791
third_party/aom/av1/decoder/decodetxb.c
vendored
791
third_party/aom/av1/decoder/decodetxb.c
vendored
|
|
@ -9,28 +9,25 @@
|
|||
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
||||
*/
|
||||
|
||||
#include "av1/common/scan.h"
|
||||
#include "av1/decoder/decodetxb.h"
|
||||
|
||||
#include "aom_ports/mem.h"
|
||||
#include "av1/common/idct.h"
|
||||
#include "av1/common/scan.h"
|
||||
#include "av1/common/txb_common.h"
|
||||
#include "av1/decoder/decodemv.h"
|
||||
#include "av1/decoder/decodetxb.h"
|
||||
#include "av1/decoder/dsubexp.h"
|
||||
#include "av1/decoder/symbolrate.h"
|
||||
|
||||
#define ACCT_STR __func__
|
||||
|
||||
static int read_golomb(MACROBLOCKD *xd, aom_reader *r, FRAME_COUNTS *counts) {
|
||||
#if !CONFIG_SYMBOLRATE
|
||||
(void)counts;
|
||||
#endif
|
||||
static int read_golomb(MACROBLOCKD *xd, aom_reader *r) {
|
||||
int x = 1;
|
||||
int length = 0;
|
||||
int i = 0;
|
||||
|
||||
while (!i) {
|
||||
i = av1_read_record_bit(counts, r, ACCT_STR);
|
||||
i = aom_read_bit(r, ACCT_STR);
|
||||
++length;
|
||||
if (length >= 32) {
|
||||
if (length > 20) {
|
||||
aom_internal_error(xd->error_info, AOM_CODEC_CORRUPT_FRAME,
|
||||
"Invalid length in read_golomb");
|
||||
break;
|
||||
|
|
@ -39,570 +36,306 @@ static int read_golomb(MACROBLOCKD *xd, aom_reader *r, FRAME_COUNTS *counts) {
|
|||
|
||||
for (i = 0; i < length - 1; ++i) {
|
||||
x <<= 1;
|
||||
x += av1_read_record_bit(counts, r, ACCT_STR);
|
||||
x += aom_read_bit(r, ACCT_STR);
|
||||
}
|
||||
|
||||
return x - 1;
|
||||
}
|
||||
|
||||
static INLINE int read_nz_map(aom_reader *r, tran_low_t *tcoeffs, int plane,
|
||||
const int16_t *scan, TX_SIZE tx_size,
|
||||
TX_TYPE tx_type, FRAME_CONTEXT *fc,
|
||||
FRAME_COUNTS *counts) {
|
||||
TX_SIZE txs_ctx = get_txsize_context(tx_size);
|
||||
const int bwl = b_width_log2_lookup[txsize_to_bsize[tx_size]] + 2;
|
||||
const int height = tx_size_high[tx_size];
|
||||
#if CONFIG_CTX1D
|
||||
const int width = tx_size_wide[tx_size];
|
||||
const int eob_offset = width + height;
|
||||
const TX_CLASS tx_class = get_tx_class(tx_type);
|
||||
const int seg_eob =
|
||||
(tx_class == TX_CLASS_2D) ? tx_size_2d[tx_size] : eob_offset;
|
||||
#else
|
||||
const int seg_eob = tx_size_2d[tx_size];
|
||||
#endif
|
||||
const PLANE_TYPE plane_type = get_plane_type(plane);
|
||||
unsigned int(*nz_map_count)[SIG_COEF_CONTEXTS][2] =
|
||||
(counts) ? &counts->nz_map[txs_ctx][plane_type] : NULL;
|
||||
#if !LV_MAP_PROB
|
||||
aom_prob *nz_map = fc->nz_map[txs_ctx][plane_type];
|
||||
aom_prob *eob_flag = fc->eob_flag[txs_ctx][plane_type];
|
||||
#endif
|
||||
int c;
|
||||
for (c = 0; c < seg_eob; ++c) {
|
||||
int is_nz;
|
||||
int coeff_ctx = get_nz_map_ctx(tcoeffs, c, scan, bwl, height, tx_type);
|
||||
int eob_ctx = get_eob_ctx(tcoeffs, scan[c], txs_ctx, tx_type);
|
||||
|
||||
if (c < seg_eob - 1) {
|
||||
#if LV_MAP_PROB
|
||||
is_nz = av1_read_record_bin(
|
||||
counts, r, fc->nz_map_cdf[txs_ctx][plane_type][coeff_ctx], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
is_nz = aom_read(r, nz_map[coeff_ctx], ACCT_STR);
|
||||
#endif
|
||||
} else {
|
||||
is_nz = 1;
|
||||
}
|
||||
|
||||
// set non-zero coefficient map.
|
||||
tcoeffs[scan[c]] = is_nz;
|
||||
|
||||
if (c == seg_eob - 1) {
|
||||
++c;
|
||||
break;
|
||||
}
|
||||
|
||||
if (counts) ++(*nz_map_count)[coeff_ctx][is_nz];
|
||||
|
||||
if (is_nz) {
|
||||
#if LV_MAP_PROB
|
||||
int is_eob = av1_read_record_bin(
|
||||
counts, r, fc->eob_flag_cdf[txs_ctx][plane_type][eob_ctx], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
int is_eob = aom_read(r, eob_flag[eob_ctx], ACCT_STR);
|
||||
#endif
|
||||
if (counts) ++counts->eob_flag[txs_ctx][plane_type][eob_ctx][is_eob];
|
||||
if (is_eob) break;
|
||||
}
|
||||
}
|
||||
return AOMMIN(seg_eob, c + 1);
|
||||
}
|
||||
|
||||
#if CONFIG_CTX1D
|
||||
static INLINE int read_nz_map_vert(aom_reader *r, tran_low_t *tcoeffs,
|
||||
int plane, const int16_t *scan,
|
||||
const int16_t *iscan, TX_SIZE tx_size,
|
||||
TX_TYPE tx_type, FRAME_CONTEXT *fc,
|
||||
FRAME_COUNTS *counts) {
|
||||
const TX_SIZE txs_ctx = get_txsize_context(tx_size);
|
||||
const PLANE_TYPE plane_type = get_plane_type(plane);
|
||||
const TX_CLASS tx_class = get_tx_class(tx_type);
|
||||
const int bwl = b_width_log2_lookup[txsize_to_bsize[tx_size]] + 2;
|
||||
const int width = tx_size_wide[tx_size];
|
||||
const int height = tx_size_high[tx_size];
|
||||
int16_t eob_ls[MAX_HVTX_SIZE];
|
||||
int eob = 0;
|
||||
#if !LV_MAP_PROB
|
||||
aom_prob *nz_map = fc->nz_map[txs_ctx][plane_type];
|
||||
#endif
|
||||
for (int col = 0; col < width; ++col) {
|
||||
int el_ctx = get_empty_line_ctx(col, eob_ls);
|
||||
#if LV_MAP_PROB
|
||||
int empty_line = av1_read_record_bin(
|
||||
counts, r, fc->empty_line_cdf[txs_ctx][plane_type][tx_class][el_ctx], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
int empty_line = aom_read(
|
||||
r, fc->empty_line[txs_ctx][plane_type][tx_class][el_ctx], ACCT_STR);
|
||||
#endif
|
||||
if (counts)
|
||||
++counts->empty_line[txs_ctx][plane_type][tx_class][el_ctx][empty_line];
|
||||
if (!empty_line) {
|
||||
int row;
|
||||
for (row = 0; row < height; ++row) {
|
||||
if (row + 1 != height) {
|
||||
int coeff_idx = row * width + col;
|
||||
int scan_idx = iscan[coeff_idx];
|
||||
int coeff_ctx =
|
||||
get_nz_map_ctx(tcoeffs, scan_idx, scan, bwl, height, tx_type);
|
||||
#if LV_MAP_PROB
|
||||
int is_nz = av1_read_record_bin(
|
||||
counts, r, fc->nz_map_cdf[txs_ctx][plane_type][coeff_ctx], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
int is_nz = aom_read(r, nz_map[coeff_ctx], ACCT_STR);
|
||||
#endif
|
||||
if (counts) ++counts->nz_map[txs_ctx][plane_type][coeff_ctx][is_nz];
|
||||
tcoeffs[coeff_idx] = is_nz;
|
||||
if (is_nz) {
|
||||
eob = AOMMAX(eob, iscan[coeff_idx] + 1);
|
||||
if (row + 1 != height) {
|
||||
int eob_ctx = get_hv_eob_ctx(col, row, eob_ls);
|
||||
#if LV_MAP_PROB
|
||||
int is_eob = av1_read_record_bin(
|
||||
counts, r,
|
||||
fc->hv_eob_cdf[txs_ctx][plane_type][tx_class][eob_ctx], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
int is_eob = aom_read(
|
||||
r, fc->hv_eob[txs_ctx][plane_type][tx_class][eob_ctx],
|
||||
ACCT_STR);
|
||||
#endif
|
||||
if (counts)
|
||||
++counts
|
||||
->hv_eob[txs_ctx][plane_type][tx_class][eob_ctx][is_eob];
|
||||
if (is_eob) break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int coeff_idx = row * width + col;
|
||||
tcoeffs[coeff_idx] = 1;
|
||||
eob = AOMMAX(eob, iscan[coeff_idx] + 1);
|
||||
}
|
||||
}
|
||||
eob_ls[col] = AOMMIN(height, row + 1);
|
||||
} else {
|
||||
eob_ls[col] = 0;
|
||||
}
|
||||
static INLINE int rec_eob_pos(const int eob_token, const int extra) {
|
||||
int eob = k_eob_group_start[eob_token];
|
||||
if (eob > 2) {
|
||||
eob += extra;
|
||||
}
|
||||
return eob;
|
||||
}
|
||||
|
||||
static INLINE int read_nz_map_horiz(aom_reader *r, tran_low_t *tcoeffs,
|
||||
int plane, const int16_t *scan,
|
||||
const int16_t *iscan, TX_SIZE tx_size,
|
||||
TX_TYPE tx_type, FRAME_CONTEXT *fc,
|
||||
FRAME_COUNTS *counts) {
|
||||
const TX_SIZE txs_ctx = get_txsize_context(tx_size);
|
||||
const PLANE_TYPE plane_type = get_plane_type(plane);
|
||||
const TX_CLASS tx_class = get_tx_class(tx_type);
|
||||
const int bwl = b_width_log2_lookup[txsize_to_bsize[tx_size]] + 2;
|
||||
const int width = tx_size_wide[tx_size];
|
||||
const int height = tx_size_high[tx_size];
|
||||
int16_t eob_ls[MAX_HVTX_SIZE];
|
||||
int eob = 0;
|
||||
#if !LV_MAP_PROB
|
||||
aom_prob *nz_map = fc->nz_map[txs_ctx][plane_type];
|
||||
#endif
|
||||
for (int row = 0; row < height; ++row) {
|
||||
int el_ctx = get_empty_line_ctx(row, eob_ls);
|
||||
#if LV_MAP_PROB
|
||||
int empty_line = av1_read_record_bin(
|
||||
counts, r, fc->empty_line_cdf[txs_ctx][plane_type][tx_class][el_ctx], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
int empty_line = aom_read(
|
||||
r, fc->empty_line[txs_ctx][plane_type][tx_class][el_ctx], ACCT_STR);
|
||||
#endif
|
||||
if (counts)
|
||||
++counts->empty_line[txs_ctx][plane_type][tx_class][el_ctx][empty_line];
|
||||
if (!empty_line) {
|
||||
int col;
|
||||
for (col = 0; col < width; ++col) {
|
||||
if (col + 1 != width) {
|
||||
int coeff_idx = row * width + col;
|
||||
int scan_idx = iscan[coeff_idx];
|
||||
int coeff_ctx =
|
||||
get_nz_map_ctx(tcoeffs, scan_idx, scan, bwl, height, tx_type);
|
||||
#if LV_MAP_PROB
|
||||
int is_nz = av1_read_record_bin(
|
||||
counts, r, fc->nz_map_cdf[txs_ctx][plane_type][coeff_ctx], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
int is_nz = aom_read(r, nz_map[coeff_ctx], ACCT_STR);
|
||||
#endif
|
||||
if (counts) ++counts->nz_map[txs_ctx][plane_type][coeff_ctx][is_nz];
|
||||
tcoeffs[coeff_idx] = is_nz;
|
||||
if (is_nz) {
|
||||
eob = AOMMAX(eob, iscan[coeff_idx] + 1);
|
||||
int eob_ctx = get_hv_eob_ctx(row, col, eob_ls);
|
||||
#if LV_MAP_PROB
|
||||
int is_eob = av1_read_record_bin(
|
||||
counts, r,
|
||||
fc->hv_eob_cdf[txs_ctx][plane_type][tx_class][eob_ctx], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
int is_eob =
|
||||
aom_read(r, fc->hv_eob[txs_ctx][plane_type][tx_class][eob_ctx],
|
||||
ACCT_STR);
|
||||
#endif
|
||||
if (counts)
|
||||
++counts->hv_eob[txs_ctx][plane_type][tx_class][eob_ctx][is_eob];
|
||||
if (is_eob) break;
|
||||
}
|
||||
} else {
|
||||
int coeff_idx = row * width + col;
|
||||
tcoeffs[coeff_idx] = 1;
|
||||
eob = AOMMAX(eob, iscan[coeff_idx] + 1);
|
||||
}
|
||||
}
|
||||
eob_ls[row] = AOMMIN(width, col + 1);
|
||||
} else {
|
||||
eob_ls[row] = 0;
|
||||
}
|
||||
}
|
||||
return eob;
|
||||
static INLINE int get_dqv(const int16_t *dequant, int coeff_idx,
|
||||
const qm_val_t *iqmatrix) {
|
||||
int dqv = dequant[!!coeff_idx];
|
||||
if (iqmatrix != NULL)
|
||||
dqv =
|
||||
((iqmatrix[coeff_idx] * dqv) + (1 << (AOM_QM_BITS - 1))) >> AOM_QM_BITS;
|
||||
return dqv;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
|
||||
aom_reader *r, int blk_row, int blk_col, int block,
|
||||
int plane, tran_low_t *tcoeffs, TXB_CTX *txb_ctx,
|
||||
TX_SIZE tx_size, int16_t *max_scan_line, int *eob) {
|
||||
FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
|
||||
FRAME_COUNTS *counts = xd->counts;
|
||||
TX_SIZE txs_ctx = get_txsize_context(tx_size);
|
||||
PLANE_TYPE plane_type = get_plane_type(plane);
|
||||
#if !LV_MAP_PROB
|
||||
aom_prob *nz_map = ec_ctx->nz_map[txs_ctx][plane_type];
|
||||
aom_prob *eob_flag = ec_ctx->eob_flag[txs_ctx][plane_type];
|
||||
#endif
|
||||
MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
|
||||
const int seg_eob = tx_size_2d[tx_size];
|
||||
int c = 0;
|
||||
int update_eob = -1;
|
||||
const int16_t *const dequant = xd->plane[plane].seg_dequant[mbmi->segment_id];
|
||||
static INLINE void read_coeffs_reverse_2d(aom_reader *r, TX_SIZE tx_size,
|
||||
int start_si, int end_si,
|
||||
const int16_t *scan, int bwl,
|
||||
uint8_t *levels,
|
||||
base_cdf_arr base_cdf,
|
||||
br_cdf_arr br_cdf) {
|
||||
for (int c = end_si; c >= start_si; --c) {
|
||||
const int pos = scan[c];
|
||||
const int coeff_ctx = get_lower_levels_ctx_2d(levels, pos, bwl, tx_size);
|
||||
const int nsymbs = 4;
|
||||
int level = aom_read_symbol(r, base_cdf[coeff_ctx], nsymbs, ACCT_STR);
|
||||
if (level > NUM_BASE_LEVELS) {
|
||||
const int br_ctx = get_br_ctx_2d(levels, pos, bwl);
|
||||
aom_cdf_prob *cdf = br_cdf[br_ctx];
|
||||
for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) {
|
||||
const int k = aom_read_symbol(r, cdf, BR_CDF_SIZE, ACCT_STR);
|
||||
level += k;
|
||||
if (k < BR_CDF_SIZE - 1) break;
|
||||
}
|
||||
}
|
||||
levels[get_padded_idx(pos, bwl)] = level;
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE void read_coeffs_reverse(aom_reader *r, TX_SIZE tx_size,
|
||||
TX_CLASS tx_class, int start_si,
|
||||
int end_si, const int16_t *scan, int bwl,
|
||||
uint8_t *levels, base_cdf_arr base_cdf,
|
||||
br_cdf_arr br_cdf) {
|
||||
for (int c = end_si; c >= start_si; --c) {
|
||||
const int pos = scan[c];
|
||||
const int coeff_ctx =
|
||||
get_lower_levels_ctx(levels, pos, bwl, tx_size, tx_class);
|
||||
const int nsymbs = 4;
|
||||
int level = aom_read_symbol(r, base_cdf[coeff_ctx], nsymbs, ACCT_STR);
|
||||
if (level > NUM_BASE_LEVELS) {
|
||||
const int br_ctx = get_br_ctx(levels, pos, bwl, tx_class);
|
||||
aom_cdf_prob *cdf = br_cdf[br_ctx];
|
||||
for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) {
|
||||
const int k = aom_read_symbol(r, cdf, BR_CDF_SIZE, ACCT_STR);
|
||||
level += k;
|
||||
if (k < BR_CDF_SIZE - 1) break;
|
||||
}
|
||||
}
|
||||
levels[get_padded_idx(pos, bwl)] = level;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *const xd,
|
||||
aom_reader *const r, const int blk_row,
|
||||
const int blk_col, const int plane,
|
||||
const TXB_CTX *const txb_ctx,
|
||||
const TX_SIZE tx_size) {
|
||||
FRAME_CONTEXT *const ec_ctx = xd->tile_ctx;
|
||||
const int32_t max_value = (1 << (7 + xd->bd)) - 1;
|
||||
const int32_t min_value = -(1 << (7 + xd->bd));
|
||||
const TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
|
||||
const PLANE_TYPE plane_type = get_plane_type(plane);
|
||||
MB_MODE_INFO *const mbmi = xd->mi[0];
|
||||
struct macroblockd_plane *const pd = &xd->plane[plane];
|
||||
const int16_t *const dequant = pd->seg_dequant_QTX[mbmi->segment_id];
|
||||
tran_low_t *const tcoeffs = pd->dqcoeff_block + xd->cb_offset[plane];
|
||||
const int shift = av1_get_tx_scale(tx_size);
|
||||
const int bwl = b_width_log2_lookup[txsize_to_bsize[tx_size]] + 2;
|
||||
const int height = tx_size_high[tx_size];
|
||||
const int bwl = get_txb_bwl(tx_size);
|
||||
const int width = get_txb_wide(tx_size);
|
||||
const int height = get_txb_high(tx_size);
|
||||
int cul_level = 0;
|
||||
memset(tcoeffs, 0, sizeof(*tcoeffs) * seg_eob);
|
||||
|
||||
#if LV_MAP_PROB
|
||||
int all_zero = av1_read_record_bin(
|
||||
counts, r, ec_ctx->txb_skip_cdf[txs_ctx][txb_ctx->txb_skip_ctx], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
int all_zero =
|
||||
aom_read(r, ec_ctx->txb_skip[txs_ctx][txb_ctx->txb_skip_ctx], ACCT_STR);
|
||||
#endif
|
||||
if (xd->counts)
|
||||
++xd->counts->txb_skip[txs_ctx][txb_ctx->txb_skip_ctx][all_zero];
|
||||
|
||||
int dc_val = 0;
|
||||
uint8_t levels_buf[TX_PAD_2D];
|
||||
uint8_t *const levels = set_levels(levels_buf, width);
|
||||
const int all_zero = aom_read_symbol(
|
||||
r, ec_ctx->txb_skip_cdf[txs_ctx][txb_ctx->txb_skip_ctx], 2, ACCT_STR);
|
||||
eob_info *eob_data = pd->eob_data + xd->txb_offset[plane];
|
||||
uint16_t *const eob = &(eob_data->eob);
|
||||
uint16_t *const max_scan_line = &(eob_data->max_scan_line);
|
||||
*max_scan_line = 0;
|
||||
*eob = 0;
|
||||
if (all_zero) {
|
||||
*max_scan_line = 0;
|
||||
#if CONFIG_TXK_SEL
|
||||
if (plane == 0) mbmi->txk_type[(blk_row << 4) + blk_col] = DCT_DCT;
|
||||
#endif
|
||||
if (plane == 0) {
|
||||
const int txk_type_idx =
|
||||
av1_get_txk_type_index(mbmi->sb_type, blk_row, blk_col);
|
||||
mbmi->txk_type[txk_type_idx] = DCT_DCT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)blk_row;
|
||||
(void)blk_col;
|
||||
#if CONFIG_TXK_SEL
|
||||
av1_read_tx_type(cm, xd, blk_row, blk_col, block, plane,
|
||||
get_min_tx_size(tx_size), r);
|
||||
#endif
|
||||
const TX_TYPE tx_type =
|
||||
av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size);
|
||||
const SCAN_ORDER *const scan_order = get_scan(cm, tx_size, tx_type, mbmi);
|
||||
const int16_t *scan = scan_order->scan;
|
||||
memset(levels_buf, 0,
|
||||
sizeof(*levels_buf) *
|
||||
((width + TX_PAD_HOR) * (height + TX_PAD_VER) + TX_PAD_END));
|
||||
if (plane == AOM_PLANE_Y) {
|
||||
// only y plane's tx_type is transmitted
|
||||
av1_read_tx_type(cm, xd, blk_row, blk_col, tx_size, r);
|
||||
}
|
||||
const TX_TYPE tx_type = av1_get_tx_type(plane_type, xd, blk_row, blk_col,
|
||||
tx_size, cm->reduced_tx_set_used);
|
||||
const TX_CLASS tx_class = tx_type_to_class[tx_type];
|
||||
const TX_SIZE qm_tx_size = av1_get_adjusted_tx_size(tx_size);
|
||||
const qm_val_t *iqmatrix =
|
||||
IS_2D_TRANSFORM(tx_type)
|
||||
? pd->seg_iqmatrix[mbmi->segment_id][qm_tx_size]
|
||||
: cm->giqmatrix[NUM_QM_LEVELS - 1][0][qm_tx_size];
|
||||
const SCAN_ORDER *const scan_order = get_scan(tx_size, tx_type);
|
||||
const int16_t *const scan = scan_order->scan;
|
||||
int eob_extra = 0;
|
||||
int eob_pt = 1;
|
||||
|
||||
#if CONFIG_CTX1D
|
||||
const int16_t *iscan = scan_order->iscan;
|
||||
TX_CLASS tx_class = get_tx_class(tx_type);
|
||||
if (tx_class == TX_CLASS_2D) {
|
||||
*eob =
|
||||
read_nz_map(r, tcoeffs, plane, scan, tx_size, tx_type, ec_ctx, counts);
|
||||
} else {
|
||||
#if LV_MAP_PROB
|
||||
const int eob_mode = av1_read_record_bin(
|
||||
counts, r, ec_ctx->eob_mode_cdf[txs_ctx][plane_type][tx_class], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
const int eob_mode =
|
||||
aom_read(r, ec_ctx->eob_mode[txs_ctx][plane_type][tx_class], ACCT_STR);
|
||||
#endif
|
||||
if (counts) ++counts->eob_mode[txs_ctx][plane_type][tx_class][eob_mode];
|
||||
if (eob_mode == 0) {
|
||||
*eob = read_nz_map(r, tcoeffs, plane, scan, tx_size, tx_type, ec_ctx,
|
||||
counts);
|
||||
const int eob_multi_size = txsize_log2_minus4[tx_size];
|
||||
const int eob_multi_ctx = (tx_class == TX_CLASS_2D) ? 0 : 1;
|
||||
switch (eob_multi_size) {
|
||||
case 0:
|
||||
eob_pt =
|
||||
aom_read_symbol(r, ec_ctx->eob_flag_cdf16[plane_type][eob_multi_ctx],
|
||||
5, ACCT_STR) +
|
||||
1;
|
||||
break;
|
||||
case 1:
|
||||
eob_pt =
|
||||
aom_read_symbol(r, ec_ctx->eob_flag_cdf32[plane_type][eob_multi_ctx],
|
||||
6, ACCT_STR) +
|
||||
1;
|
||||
break;
|
||||
case 2:
|
||||
eob_pt =
|
||||
aom_read_symbol(r, ec_ctx->eob_flag_cdf64[plane_type][eob_multi_ctx],
|
||||
7, ACCT_STR) +
|
||||
1;
|
||||
break;
|
||||
case 3:
|
||||
eob_pt =
|
||||
aom_read_symbol(r, ec_ctx->eob_flag_cdf128[plane_type][eob_multi_ctx],
|
||||
8, ACCT_STR) +
|
||||
1;
|
||||
break;
|
||||
case 4:
|
||||
eob_pt =
|
||||
aom_read_symbol(r, ec_ctx->eob_flag_cdf256[plane_type][eob_multi_ctx],
|
||||
9, ACCT_STR) +
|
||||
1;
|
||||
break;
|
||||
case 5:
|
||||
eob_pt =
|
||||
aom_read_symbol(r, ec_ctx->eob_flag_cdf512[plane_type][eob_multi_ctx],
|
||||
10, ACCT_STR) +
|
||||
1;
|
||||
break;
|
||||
case 6:
|
||||
default:
|
||||
eob_pt = aom_read_symbol(
|
||||
r, ec_ctx->eob_flag_cdf1024[plane_type][eob_multi_ctx], 11,
|
||||
ACCT_STR) +
|
||||
1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (k_eob_offset_bits[eob_pt] > 0) {
|
||||
const int eob_ctx = eob_pt - 3;
|
||||
int bit = aom_read_symbol(
|
||||
r, ec_ctx->eob_extra_cdf[txs_ctx][plane_type][eob_ctx], 2, ACCT_STR);
|
||||
if (bit) {
|
||||
eob_extra += (1 << (k_eob_offset_bits[eob_pt] - 1));
|
||||
}
|
||||
|
||||
for (int i = 1; i < k_eob_offset_bits[eob_pt]; i++) {
|
||||
bit = aom_read_bit(r, ACCT_STR);
|
||||
if (bit) {
|
||||
eob_extra += (1 << (k_eob_offset_bits[eob_pt] - 1 - i));
|
||||
}
|
||||
}
|
||||
}
|
||||
*eob = rec_eob_pos(eob_pt, eob_extra);
|
||||
|
||||
{
|
||||
// Read the non-zero coefficient with scan index eob-1
|
||||
// TODO(angiebird): Put this into a function
|
||||
const int c = *eob - 1;
|
||||
const int pos = scan[c];
|
||||
const int coeff_ctx = get_lower_levels_ctx_eob(bwl, height, c);
|
||||
const int nsymbs = 3;
|
||||
aom_cdf_prob *cdf =
|
||||
ec_ctx->coeff_base_eob_cdf[txs_ctx][plane_type][coeff_ctx];
|
||||
int level = aom_read_symbol(r, cdf, nsymbs, ACCT_STR) + 1;
|
||||
if (level > NUM_BASE_LEVELS) {
|
||||
const int br_ctx = get_br_ctx(levels, pos, bwl, tx_class);
|
||||
for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) {
|
||||
const int k = aom_read_symbol(
|
||||
r,
|
||||
ec_ctx->coeff_br_cdf[AOMMIN(txs_ctx, TX_32X32)][plane_type][br_ctx],
|
||||
BR_CDF_SIZE, ACCT_STR);
|
||||
level += k;
|
||||
if (k < BR_CDF_SIZE - 1) break;
|
||||
}
|
||||
}
|
||||
levels[get_padded_idx(pos, bwl)] = level;
|
||||
}
|
||||
if (*eob > 1) {
|
||||
base_cdf_arr base_cdf = ec_ctx->coeff_base_cdf[txs_ctx][plane_type];
|
||||
br_cdf_arr br_cdf =
|
||||
ec_ctx->coeff_br_cdf[AOMMIN(txs_ctx, TX_32X32)][plane_type];
|
||||
if (tx_class == TX_CLASS_2D) {
|
||||
read_coeffs_reverse_2d(r, tx_size, 1, *eob - 1 - 1, scan, bwl, levels,
|
||||
base_cdf, br_cdf);
|
||||
read_coeffs_reverse(r, tx_size, tx_class, 0, 0, scan, bwl, levels,
|
||||
base_cdf, br_cdf);
|
||||
} else {
|
||||
assert(tx_class == TX_CLASS_VERT || tx_class == TX_CLASS_HORIZ);
|
||||
if (tx_class == TX_CLASS_VERT)
|
||||
*eob = read_nz_map_vert(r, tcoeffs, plane, scan, iscan, tx_size,
|
||||
tx_type, ec_ctx, counts);
|
||||
else
|
||||
*eob = read_nz_map_horiz(r, tcoeffs, plane, scan, iscan, tx_size,
|
||||
tx_type, ec_ctx, counts);
|
||||
read_coeffs_reverse(r, tx_size, tx_class, 0, *eob - 1 - 1, scan, bwl,
|
||||
levels, base_cdf, br_cdf);
|
||||
}
|
||||
}
|
||||
#else
|
||||
*eob = read_nz_map(r, tcoeffs, plane, scan, tx_size, tx_type, ec_ctx, counts);
|
||||
#endif
|
||||
*max_scan_line = *eob;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < NUM_BASE_LEVELS; ++i) {
|
||||
#if !LV_MAP_PROB
|
||||
aom_prob *coeff_base = ec_ctx->coeff_base[txs_ctx][plane_type][i];
|
||||
#endif
|
||||
update_eob = 0;
|
||||
for (c = *eob - 1; c >= 0; --c) {
|
||||
tran_low_t *v = &tcoeffs[scan[c]];
|
||||
int sign;
|
||||
int ctx;
|
||||
int16_t num_zero_coeffs = 0;
|
||||
for (int c = 0; c < *eob; ++c) {
|
||||
const int pos = scan[c];
|
||||
num_zero_coeffs = AOMMAX(num_zero_coeffs, pos);
|
||||
}
|
||||
memset(tcoeffs, 0, (num_zero_coeffs + 1) * sizeof(tcoeffs[0]));
|
||||
|
||||
if (*v <= i) continue;
|
||||
|
||||
ctx = get_base_ctx(tcoeffs, scan[c], bwl, height, i + 1);
|
||||
|
||||
#if LV_MAP_PROB
|
||||
if (av1_read_record_bin(
|
||||
counts, r, ec_ctx->coeff_base_cdf[txs_ctx][plane_type][i][ctx], 2,
|
||||
ACCT_STR))
|
||||
#else
|
||||
if (aom_read(r, coeff_base[ctx], ACCT_STR))
|
||||
#endif
|
||||
{
|
||||
*v = i + 1;
|
||||
cul_level += i + 1;
|
||||
|
||||
if (counts) ++counts->coeff_base[txs_ctx][plane_type][i][ctx][1];
|
||||
|
||||
if (c == 0) {
|
||||
int dc_sign_ctx = txb_ctx->dc_sign_ctx;
|
||||
#if LV_MAP_PROB
|
||||
sign = av1_read_record_bin(
|
||||
counts, r, ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx], 2,
|
||||
ACCT_STR);
|
||||
#else
|
||||
sign =
|
||||
aom_read(r, ec_ctx->dc_sign[plane_type][dc_sign_ctx], ACCT_STR);
|
||||
#endif
|
||||
if (counts) ++counts->dc_sign[plane_type][dc_sign_ctx][sign];
|
||||
} else {
|
||||
sign = av1_read_record_bit(counts, r, ACCT_STR);
|
||||
}
|
||||
if (sign) *v = -(*v);
|
||||
continue;
|
||||
for (int c = 0; c < *eob; ++c) {
|
||||
const int pos = scan[c];
|
||||
uint8_t sign;
|
||||
tran_low_t level = levels[get_padded_idx(pos, bwl)];
|
||||
if (level) {
|
||||
*max_scan_line = AOMMAX(*max_scan_line, pos);
|
||||
if (c == 0) {
|
||||
const int dc_sign_ctx = txb_ctx->dc_sign_ctx;
|
||||
sign = aom_read_symbol(r, ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx],
|
||||
2, ACCT_STR);
|
||||
} else {
|
||||
sign = aom_read_bit(r, ACCT_STR);
|
||||
}
|
||||
*v = i + 2;
|
||||
if (counts) ++counts->coeff_base[txs_ctx][plane_type][i][ctx][0];
|
||||
|
||||
// update the eob flag for coefficients with magnitude above 1.
|
||||
update_eob = AOMMAX(update_eob, c);
|
||||
}
|
||||
}
|
||||
|
||||
for (c = update_eob; c >= 0; --c) {
|
||||
tran_low_t *v = &tcoeffs[scan[c]];
|
||||
int sign;
|
||||
int idx;
|
||||
int ctx;
|
||||
|
||||
if (*v <= NUM_BASE_LEVELS) continue;
|
||||
|
||||
if (c == 0) {
|
||||
int dc_sign_ctx = txb_ctx->dc_sign_ctx;
|
||||
#if LV_MAP_PROB
|
||||
sign = av1_read_record_bin(
|
||||
counts, r, ec_ctx->dc_sign_cdf[plane_type][dc_sign_ctx], 2, ACCT_STR);
|
||||
#else
|
||||
sign = aom_read(r, ec_ctx->dc_sign[plane_type][dc_sign_ctx], ACCT_STR);
|
||||
#endif
|
||||
if (counts) ++counts->dc_sign[plane_type][dc_sign_ctx][sign];
|
||||
} else {
|
||||
sign = av1_read_record_bit(counts, r, ACCT_STR);
|
||||
}
|
||||
|
||||
ctx = get_br_ctx(tcoeffs, scan[c], bwl, height);
|
||||
|
||||
#if BR_NODE
|
||||
for (idx = 0; idx < BASE_RANGE_SETS; ++idx) {
|
||||
#if LV_MAP_PROB
|
||||
if (av1_read_record_bin(
|
||||
counts, r, ec_ctx->coeff_br_cdf[txs_ctx][plane_type][idx][ctx], 2,
|
||||
ACCT_STR))
|
||||
#else // LV_MAP_PROB
|
||||
if (aom_read(r, ec_ctx->coeff_br[txs_ctx][plane_type][idx][ctx],
|
||||
ACCT_STR))
|
||||
#endif // LV_MAP_PROB
|
||||
{
|
||||
int extra_bits = (1 << br_extra_bits[idx]) - 1;
|
||||
// int br_offset = aom_read_literal(r, extra_bits, ACCT_STR);
|
||||
int br_offset = 0;
|
||||
int tok;
|
||||
if (counts) ++counts->coeff_br[txs_ctx][plane_type][idx][ctx][1];
|
||||
for (tok = 0; tok < extra_bits; ++tok) {
|
||||
#if LV_MAP_PROB
|
||||
if (av1_read_record_bin(
|
||||
counts, r, ec_ctx->coeff_lps_cdf[txs_ctx][plane_type][ctx], 2,
|
||||
ACCT_STR))
|
||||
#else
|
||||
if (aom_read(r, ec_ctx->coeff_lps[txs_ctx][plane_type][ctx],
|
||||
ACCT_STR))
|
||||
#endif
|
||||
{
|
||||
br_offset = tok;
|
||||
if (counts) ++counts->coeff_lps[txs_ctx][plane_type][ctx][1];
|
||||
break;
|
||||
}
|
||||
if (counts) ++counts->coeff_lps[txs_ctx][plane_type][ctx][0];
|
||||
}
|
||||
if (tok == extra_bits) br_offset = extra_bits;
|
||||
|
||||
int br_base = br_index_to_coeff[idx];
|
||||
|
||||
*v = NUM_BASE_LEVELS + 1 + br_base + br_offset;
|
||||
cul_level += *v;
|
||||
if (sign) *v = -(*v);
|
||||
break;
|
||||
if (level >= MAX_BASE_BR_RANGE) {
|
||||
level += read_golomb(xd, r);
|
||||
}
|
||||
if (counts) ++counts->coeff_br[txs_ctx][plane_type][idx][ctx][0];
|
||||
}
|
||||
|
||||
if (idx < BASE_RANGE_SETS) continue;
|
||||
#else
|
||||
for (idx = 0; idx < COEFF_BASE_RANGE; ++idx) {
|
||||
#if LV_MAP_PROB
|
||||
if (av1_read_record_bin(counts, r,
|
||||
ec_ctx->coeff_lps_cdf[txs_ctx][plane_type][ctx],
|
||||
2, ACCT_STR))
|
||||
#else
|
||||
if (aom_read(r, ec_ctx->coeff_lps[txs_ctx][plane_type][ctx], ACCT_STR))
|
||||
#endif
|
||||
{
|
||||
*v = (idx + 1 + NUM_BASE_LEVELS);
|
||||
if (sign) *v = -(*v);
|
||||
cul_level += abs(*v);
|
||||
if (c == 0) dc_val = sign ? -level : level;
|
||||
|
||||
if (counts) ++counts->coeff_lps[txs_ctx][plane_type][ctx][1];
|
||||
break;
|
||||
// Bitmasking to clamp level to valid range:
|
||||
// The valid range for 8/10/12 bit vdieo is at most 14/16/18 bit
|
||||
level &= 0xfffff;
|
||||
cul_level += level;
|
||||
tran_low_t dq_coeff;
|
||||
// Bitmasking to clamp dq_coeff to valid range:
|
||||
// The valid range for 8/10/12 bit video is at most 17/19/21 bit
|
||||
dq_coeff = (tran_low_t)(
|
||||
(int64_t)level * get_dqv(dequant, scan[c], iqmatrix) & 0xffffff);
|
||||
dq_coeff = dq_coeff >> shift;
|
||||
if (sign) {
|
||||
dq_coeff = -dq_coeff;
|
||||
}
|
||||
if (counts) ++counts->coeff_lps[txs_ctx][plane_type][ctx][0];
|
||||
tcoeffs[pos] = clamp(dq_coeff, min_value, max_value);
|
||||
}
|
||||
if (idx < COEFF_BASE_RANGE) continue;
|
||||
#endif
|
||||
|
||||
// decode 0-th order Golomb code
|
||||
*v = read_golomb(xd, r, counts) + COEFF_BASE_RANGE + 1 + NUM_BASE_LEVELS;
|
||||
if (sign) *v = -(*v);
|
||||
cul_level += abs(*v);
|
||||
}
|
||||
|
||||
for (c = 0; c < *eob; ++c) {
|
||||
int16_t dqv = (c == 0) ? dequant[0] : dequant[1];
|
||||
tran_low_t *v = &tcoeffs[scan[c]];
|
||||
#if CONFIG_SYMBOLRATE
|
||||
av1_record_coeff(counts, abs(*v));
|
||||
#endif
|
||||
int sign = (*v) < 0;
|
||||
*v = (abs(*v) * dqv) >> shift;
|
||||
if (sign) *v = -(*v);
|
||||
}
|
||||
|
||||
cul_level = AOMMIN(63, cul_level);
|
||||
cul_level = AOMMIN(COEFF_CONTEXT_MASK, cul_level);
|
||||
|
||||
// DC value
|
||||
set_dc_sign(&cul_level, tcoeffs[0]);
|
||||
set_dc_sign(&cul_level, dc_val);
|
||||
|
||||
return cul_level;
|
||||
}
|
||||
|
||||
uint8_t av1_read_coeffs_txb_facade(AV1_COMMON *cm, MACROBLOCKD *xd,
|
||||
aom_reader *r, int row, int col, int block,
|
||||
int plane, tran_low_t *tcoeffs,
|
||||
TX_SIZE tx_size, int16_t *max_scan_line,
|
||||
int *eob) {
|
||||
MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
|
||||
struct macroblockd_plane *pd = &xd->plane[plane];
|
||||
uint8_t av1_read_coeffs_txb_facade(const AV1_COMMON *const cm,
|
||||
MACROBLOCKD *const xd, aom_reader *const r,
|
||||
const int row, const int col,
|
||||
const int plane, const TX_SIZE tx_size) {
|
||||
MB_MODE_INFO *const mbmi = xd->mi[0];
|
||||
struct macroblockd_plane *const pd = &xd->plane[plane];
|
||||
|
||||
const BLOCK_SIZE bsize = mbmi->sb_type;
|
||||
#if CONFIG_CHROMA_SUB8X8
|
||||
const BLOCK_SIZE plane_bsize =
|
||||
AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd));
|
||||
#elif CONFIG_CB4X4
|
||||
const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
|
||||
#else // CONFIG_CB4X4
|
||||
const BLOCK_SIZE plane_bsize =
|
||||
get_plane_block_size(AOMMAX(BLOCK_8X8, bsize), pd);
|
||||
#endif // CONFIG_CB4X4
|
||||
get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
|
||||
|
||||
TXB_CTX txb_ctx;
|
||||
get_txb_ctx(plane_bsize, tx_size, plane, pd->above_context + col,
|
||||
pd->left_context + row, &txb_ctx);
|
||||
uint8_t cul_level =
|
||||
av1_read_coeffs_txb(cm, xd, r, row, col, block, plane, tcoeffs, &txb_ctx,
|
||||
tx_size, max_scan_line, eob);
|
||||
#if CONFIG_ADAPT_SCAN
|
||||
PLANE_TYPE plane_type = get_plane_type(plane);
|
||||
TX_TYPE tx_type = av1_get_tx_type(plane_type, xd, row, col, block, tx_size);
|
||||
if (xd->counts && *eob > 0)
|
||||
av1_update_scan_count_facade(cm, xd->counts, tx_size, tx_type, pd->dqcoeff,
|
||||
*eob);
|
||||
#endif
|
||||
av1_set_contexts(xd, pd, plane, tx_size, cul_level, col, row);
|
||||
const uint8_t cul_level =
|
||||
av1_read_coeffs_txb(cm, xd, r, row, col, plane, &txb_ctx, tx_size);
|
||||
av1_set_contexts(xd, pd, plane, plane_bsize, tx_size, cul_level, col, row);
|
||||
return cul_level;
|
||||
}
|
||||
|
||||
#if !LV_MAP_PROB
|
||||
static void read_txb_probs(FRAME_CONTEXT *fc, const TX_SIZE tx_size,
|
||||
aom_reader *r, FRAME_COUNTS *counts) {
|
||||
#if !CONFIG_SYMBOLRATE
|
||||
(void)counts;
|
||||
#endif
|
||||
int plane, ctx, level;
|
||||
|
||||
if (av1_read_record_bit(counts, r, ACCT_STR) == 0) return;
|
||||
|
||||
for (ctx = 0; ctx < TXB_SKIP_CONTEXTS; ++ctx)
|
||||
av1_diff_update_prob(r, &fc->txb_skip[tx_size][ctx], ACCT_STR);
|
||||
|
||||
for (plane = 0; plane < PLANE_TYPES; ++plane)
|
||||
for (ctx = 0; ctx < SIG_COEF_CONTEXTS; ++ctx)
|
||||
av1_diff_update_prob(r, &fc->nz_map[tx_size][plane][ctx], ACCT_STR);
|
||||
|
||||
for (plane = 0; plane < PLANE_TYPES; ++plane)
|
||||
for (ctx = 0; ctx < EOB_COEF_CONTEXTS; ++ctx)
|
||||
av1_diff_update_prob(r, &fc->eob_flag[tx_size][plane][ctx], ACCT_STR);
|
||||
|
||||
for (level = 0; level < NUM_BASE_LEVELS; ++level)
|
||||
for (plane = 0; plane < PLANE_TYPES; ++plane)
|
||||
for (ctx = 0; ctx < COEFF_BASE_CONTEXTS; ++ctx)
|
||||
av1_diff_update_prob(r, &fc->coeff_base[tx_size][plane][level][ctx],
|
||||
ACCT_STR);
|
||||
|
||||
for (plane = 0; plane < PLANE_TYPES; ++plane)
|
||||
for (ctx = 0; ctx < LEVEL_CONTEXTS; ++ctx)
|
||||
av1_diff_update_prob(r, &fc->coeff_lps[tx_size][plane][ctx], ACCT_STR);
|
||||
}
|
||||
|
||||
void av1_read_txb_probs(FRAME_CONTEXT *fc, TX_MODE tx_mode, aom_reader *r,
|
||||
FRAME_COUNTS *counts) {
|
||||
const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode];
|
||||
TX_SIZE tx_size;
|
||||
int ctx, plane;
|
||||
|
||||
for (plane = 0; plane < PLANE_TYPES; ++plane)
|
||||
for (ctx = 0; ctx < DC_SIGN_CONTEXTS; ++ctx)
|
||||
av1_diff_update_prob(r, &fc->dc_sign[plane][ctx], ACCT_STR);
|
||||
|
||||
for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size)
|
||||
read_txb_probs(fc, tx_size, r, counts);
|
||||
}
|
||||
#endif // !LV_MAP_PROB
|
||||
|
|
|
|||
25
third_party/aom/av1/decoder/decodetxb.h
vendored
25
third_party/aom/av1/decoder/decodetxb.h
vendored
|
|
@ -12,24 +12,21 @@
|
|||
#ifndef DECODETXB_H_
|
||||
#define DECODETXB_H_
|
||||
|
||||
#include "./aom_config.h"
|
||||
#include "config/aom_config.h"
|
||||
|
||||
#include "av1/common/blockd.h"
|
||||
#include "av1/common/onyxc_int.h"
|
||||
#include "av1/common/txb_common.h"
|
||||
#include "aom_dsp/bitreader.h"
|
||||
|
||||
uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
|
||||
aom_reader *r, int blk_row, int blk_col, int block,
|
||||
int plane, tran_low_t *tcoeffs, TXB_CTX *txb_ctx,
|
||||
TX_SIZE tx_size, int16_t *max_scan_line, int *eob);
|
||||
uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *const xd,
|
||||
aom_reader *const r, const int blk_row,
|
||||
const int blk_col, const int plane,
|
||||
const TXB_CTX *const txb_ctx,
|
||||
const TX_SIZE tx_size);
|
||||
|
||||
uint8_t av1_read_coeffs_txb_facade(AV1_COMMON *cm, MACROBLOCKD *xd,
|
||||
aom_reader *r, int row, int col, int block,
|
||||
int plane, tran_low_t *tcoeffs,
|
||||
TX_SIZE tx_size, int16_t *max_scan_line,
|
||||
int *eob);
|
||||
#if !LV_MAP_PROB
|
||||
void av1_read_txb_probs(FRAME_CONTEXT *fc, TX_MODE tx_mode, aom_reader *r,
|
||||
FRAME_COUNTS *counts);
|
||||
#endif // !LV_MAP_PROB
|
||||
uint8_t av1_read_coeffs_txb_facade(const AV1_COMMON *const cm,
|
||||
MACROBLOCKD *const xd, aom_reader *const r,
|
||||
const int row, const int col,
|
||||
const int plane, const TX_SIZE tx_size);
|
||||
#endif // DECODETXB_H_
|
||||
|
|
|
|||
347
third_party/aom/av1/decoder/detokenize.c
vendored
347
third_party/aom/av1/decoder/detokenize.c
vendored
|
|
@ -9,245 +9,18 @@
|
|||
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
||||
*/
|
||||
|
||||
#include "./aom_config.h"
|
||||
#if !CONFIG_PVQ
|
||||
#include "config/aom_config.h"
|
||||
|
||||
#include "aom_mem/aom_mem.h"
|
||||
#include "aom_ports/mem.h"
|
||||
#endif // !CONFIG_PVQ
|
||||
|
||||
#include "av1/common/blockd.h"
|
||||
#include "av1/decoder/detokenize.h"
|
||||
|
||||
#define ACCT_STR __func__
|
||||
|
||||
#if !CONFIG_PVQ || CONFIG_VAR_TX
|
||||
#include "av1/common/common.h"
|
||||
#include "av1/common/entropy.h"
|
||||
#include "av1/common/idct.h"
|
||||
#endif
|
||||
|
||||
#include "av1/decoder/symbolrate.h"
|
||||
|
||||
#if !CONFIG_PVQ || CONFIG_VAR_TX
|
||||
#define EOB_CONTEXT_NODE 0
|
||||
#define ZERO_CONTEXT_NODE 1
|
||||
#define ONE_CONTEXT_NODE 2
|
||||
#define LOW_VAL_CONTEXT_NODE 0
|
||||
#define TWO_CONTEXT_NODE 1
|
||||
#define THREE_CONTEXT_NODE 2
|
||||
#define HIGH_LOW_CONTEXT_NODE 3
|
||||
#define CAT_ONE_CONTEXT_NODE 4
|
||||
#define CAT_THREEFOUR_CONTEXT_NODE 5
|
||||
#define CAT_THREE_CONTEXT_NODE 6
|
||||
#define CAT_FIVE_CONTEXT_NODE 7
|
||||
|
||||
#define INCREMENT_COUNT(token) \
|
||||
do { \
|
||||
if (counts) ++coef_counts[band][ctx][token]; \
|
||||
} while (0)
|
||||
|
||||
#if CONFIG_NEW_MULTISYMBOL
|
||||
#define READ_COEFF(counts, prob_name, cdf_name, num, r) \
|
||||
read_coeff(counts, cdf_name, num, r);
|
||||
static INLINE int read_coeff(FRAME_COUNTS *counts,
|
||||
const aom_cdf_prob *const *cdf, int n,
|
||||
aom_reader *r) {
|
||||
#if !CONFIG_SYMBOLRATE
|
||||
(void)counts;
|
||||
#endif
|
||||
int val = 0;
|
||||
int i = 0;
|
||||
int count = 0;
|
||||
while (count < n) {
|
||||
const int size = AOMMIN(n - count, 4);
|
||||
val |= av1_read_record_cdf(counts, r, cdf[i++], 1 << size, ACCT_STR)
|
||||
<< count;
|
||||
count += size;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
#else
|
||||
#define READ_COEFF(counts, prob_name, cdf_name, num, r) \
|
||||
read_coeff(counts, prob_name, num, r);
|
||||
static INLINE int read_coeff(FRAME_COUNTS *counts, const aom_prob *probs, int n,
|
||||
aom_reader *r) {
|
||||
#if !CONFIG_SYMBOLRATE
|
||||
(void)counts;
|
||||
#endif
|
||||
int i, val = 0;
|
||||
for (i = 0; i < n; ++i)
|
||||
val = (val << 1) | av1_read_record(counts, r, probs[i], ACCT_STR);
|
||||
return val;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int token_to_value(FRAME_COUNTS *counts, aom_reader *const r, int token,
|
||||
TX_SIZE tx_size, int bit_depth) {
|
||||
#if !CONFIG_HIGHBITDEPTH
|
||||
assert(bit_depth == 8);
|
||||
#endif // !CONFIG_HIGHBITDEPTH
|
||||
|
||||
switch (token) {
|
||||
case ZERO_TOKEN:
|
||||
case ONE_TOKEN:
|
||||
case TWO_TOKEN:
|
||||
case THREE_TOKEN:
|
||||
case FOUR_TOKEN: return token;
|
||||
case CATEGORY1_TOKEN:
|
||||
return CAT1_MIN_VAL +
|
||||
READ_COEFF(counts, av1_cat1_prob, av1_cat1_cdf, 1, r);
|
||||
case CATEGORY2_TOKEN:
|
||||
return CAT2_MIN_VAL +
|
||||
READ_COEFF(counts, av1_cat2_prob, av1_cat2_cdf, 2, r);
|
||||
case CATEGORY3_TOKEN:
|
||||
return CAT3_MIN_VAL +
|
||||
READ_COEFF(counts, av1_cat3_prob, av1_cat3_cdf, 3, r);
|
||||
case CATEGORY4_TOKEN:
|
||||
return CAT4_MIN_VAL +
|
||||
READ_COEFF(counts, av1_cat4_prob, av1_cat4_cdf, 4, r);
|
||||
case CATEGORY5_TOKEN:
|
||||
return CAT5_MIN_VAL +
|
||||
READ_COEFF(counts, av1_cat5_prob, av1_cat5_cdf, 5, r);
|
||||
case CATEGORY6_TOKEN: {
|
||||
const int skip_bits = (int)sizeof(av1_cat6_prob) -
|
||||
av1_get_cat6_extrabits_size(tx_size, bit_depth);
|
||||
return CAT6_MIN_VAL + READ_COEFF(counts, av1_cat6_prob + skip_bits,
|
||||
av1_cat6_cdf, 18 - skip_bits, r);
|
||||
}
|
||||
default:
|
||||
assert(0); // Invalid token.
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff,
|
||||
TX_SIZE tx_size, TX_TYPE tx_type, const int16_t *dq,
|
||||
#if CONFIG_NEW_QUANT
|
||||
dequant_val_type_nuq *dq_val,
|
||||
#else
|
||||
#if CONFIG_AOM_QM
|
||||
qm_val_t *iqm[2][TX_SIZES_ALL],
|
||||
#endif // CONFIG_AOM_QM
|
||||
#endif // CONFIG_NEW_QUANT
|
||||
int ctx, const int16_t *scan, const int16_t *nb,
|
||||
int16_t *max_scan_line, aom_reader *r) {
|
||||
FRAME_CONTEXT *ec_ctx = xd->tile_ctx;
|
||||
const int max_eob = tx_size_2d[tx_size];
|
||||
const int ref = is_inter_block(&xd->mi[0]->mbmi);
|
||||
#if CONFIG_AOM_QM && !CONFIG_NEW_QUANT
|
||||
const qm_val_t *iqmatrix = iqm[!ref][tx_size];
|
||||
#endif // CONFIG_AOM_QM
|
||||
(void)tx_type;
|
||||
int band, c = 0;
|
||||
const TX_SIZE tx_size_ctx = txsize_sqr_map[tx_size];
|
||||
aom_cdf_prob(*coef_head_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] =
|
||||
ec_ctx->coef_head_cdfs[tx_size_ctx][type][ref];
|
||||
aom_cdf_prob(*coef_tail_cdfs)[COEFF_CONTEXTS][CDF_SIZE(ENTROPY_TOKENS)] =
|
||||
ec_ctx->coef_tail_cdfs[tx_size_ctx][type][ref];
|
||||
int val = 0;
|
||||
|
||||
uint8_t token_cache[MAX_TX_SQUARE];
|
||||
const uint8_t *band_translate = get_band_translate(tx_size);
|
||||
int dq_shift;
|
||||
int v, token;
|
||||
int32_t dqv = dq[0];
|
||||
#if CONFIG_NEW_QUANT
|
||||
const tran_low_t *dqv_val = &dq_val[0][0];
|
||||
#endif // CONFIG_NEW_QUANT
|
||||
|
||||
dq_shift = av1_get_tx_scale(tx_size);
|
||||
|
||||
band = *band_translate++;
|
||||
|
||||
int more_data = 1;
|
||||
while (more_data) {
|
||||
int comb_token;
|
||||
int last_pos = (c + 1 == max_eob);
|
||||
int first_pos = (c == 0);
|
||||
|
||||
#if CONFIG_NEW_QUANT
|
||||
dqv_val = &dq_val[band][0];
|
||||
#endif // CONFIG_NEW_QUANT
|
||||
|
||||
comb_token = last_pos ? 2 * av1_read_record_bit(xd->counts, r, ACCT_STR) + 2
|
||||
: av1_read_record_symbol(
|
||||
xd->counts, r, coef_head_cdfs[band][ctx],
|
||||
HEAD_TOKENS + first_pos, ACCT_STR) +
|
||||
!first_pos;
|
||||
if (first_pos) {
|
||||
if (comb_token == 0) return 0;
|
||||
}
|
||||
token = comb_token >> 1;
|
||||
|
||||
while (!token) {
|
||||
*max_scan_line = AOMMAX(*max_scan_line, scan[c]);
|
||||
token_cache[scan[c]] = 0;
|
||||
#if CONFIG_SYMBOLRATE
|
||||
av1_record_coeff(xd->counts, 0);
|
||||
#endif
|
||||
++c;
|
||||
dqv = dq[1];
|
||||
ctx = get_coef_context(nb, token_cache, c);
|
||||
band = *band_translate++;
|
||||
|
||||
last_pos = (c + 1 == max_eob);
|
||||
|
||||
comb_token =
|
||||
last_pos
|
||||
? 2 * av1_read_record_bit(xd->counts, r, ACCT_STR) + 2
|
||||
: av1_read_record_symbol(xd->counts, r, coef_head_cdfs[band][ctx],
|
||||
HEAD_TOKENS, ACCT_STR) +
|
||||
1;
|
||||
token = comb_token >> 1;
|
||||
}
|
||||
|
||||
more_data = comb_token & 1;
|
||||
|
||||
if (token > ONE_TOKEN)
|
||||
token += av1_read_record_symbol(xd->counts, r, coef_tail_cdfs[band][ctx],
|
||||
TAIL_TOKENS, ACCT_STR);
|
||||
#if CONFIG_NEW_QUANT
|
||||
dqv_val = &dq_val[band][0];
|
||||
#endif // CONFIG_NEW_QUANT
|
||||
|
||||
*max_scan_line = AOMMAX(*max_scan_line, scan[c]);
|
||||
token_cache[scan[c]] = av1_pt_energy_class[token];
|
||||
|
||||
val = token_to_value(xd->counts, r, token, tx_size, xd->bd);
|
||||
#if CONFIG_SYMBOLRATE
|
||||
av1_record_coeff(xd->counts, val);
|
||||
#endif
|
||||
|
||||
#if CONFIG_NEW_QUANT
|
||||
v = av1_dequant_abscoeff_nuq(val, dqv, dqv_val);
|
||||
v = dq_shift ? ROUND_POWER_OF_TWO(v, dq_shift) : v;
|
||||
#else
|
||||
#if CONFIG_AOM_QM
|
||||
// Apply quant matrix only for 2D transforms
|
||||
if (IS_2D_TRANSFORM(tx_type) && iqmatrix != NULL)
|
||||
dqv = ((iqmatrix[scan[c]] * (int)dqv) + (1 << (AOM_QM_BITS - 1))) >>
|
||||
AOM_QM_BITS;
|
||||
#endif
|
||||
v = (val * dqv) >> dq_shift;
|
||||
#endif
|
||||
|
||||
v = (int)check_range(av1_read_record_bit(xd->counts, r, ACCT_STR) ? -v : v,
|
||||
xd->bd);
|
||||
|
||||
dqcoeff[scan[c]] = v;
|
||||
|
||||
++c;
|
||||
more_data &= (c < max_eob);
|
||||
if (!more_data) break;
|
||||
dqv = dq[1];
|
||||
ctx = get_coef_context(nb, token_cache, c);
|
||||
band = *band_translate++;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
#endif // !CONFIG_PVQ
|
||||
|
||||
static void decode_color_map_tokens(Av1ColorMapParam *param, aom_reader *r) {
|
||||
uint8_t color_order[PALETTE_MAX_SIZE];
|
||||
|
|
@ -263,7 +36,6 @@ static void decode_color_map_tokens(Av1ColorMapParam *param, aom_reader *r) {
|
|||
color_map[0] = av1_read_uniform(r, n);
|
||||
assert(color_map[0] < n);
|
||||
|
||||
#if CONFIG_PALETTE_THROUGHPUT
|
||||
// Run wavefront on the palette map index decoding.
|
||||
for (int i = 1; i < rows + cols - 1; ++i) {
|
||||
for (int j = AOMMIN(i, cols - 1); j >= AOMMAX(0, i - rows + 1); --j) {
|
||||
|
|
@ -283,21 +55,6 @@ static void decode_color_map_tokens(Av1ColorMapParam *param, aom_reader *r) {
|
|||
(plane_block_width - cols));
|
||||
}
|
||||
}
|
||||
#else
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
for (int j = (i == 0 ? 1 : 0); j < cols; ++j) {
|
||||
const int color_ctx = av1_get_palette_color_index_context(
|
||||
color_map, plane_block_width, i, j, n, color_order, NULL);
|
||||
const int color_idx = aom_read_symbol(
|
||||
r, color_map_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR);
|
||||
assert(color_idx >= 0 && color_idx < n);
|
||||
color_map[i * plane_block_width + j] = color_order[color_idx];
|
||||
}
|
||||
memset(color_map + i * plane_block_width + cols,
|
||||
color_map[i * plane_block_width + cols - 1],
|
||||
(plane_block_width - cols)); // Copy last column to extra columns.
|
||||
}
|
||||
#endif // CONFIG_PALETTE_THROUGHPUT
|
||||
// Copy last row to extra rows.
|
||||
for (int i = rows; i < plane_block_height; ++i) {
|
||||
memcpy(color_map + i * plane_block_width,
|
||||
|
|
@ -305,97 +62,17 @@ static void decode_color_map_tokens(Av1ColorMapParam *param, aom_reader *r) {
|
|||
}
|
||||
}
|
||||
|
||||
static void get_palette_params(const MACROBLOCKD *const xd, int plane,
|
||||
BLOCK_SIZE bsize, Av1ColorMapParam *params) {
|
||||
assert(plane == 0 || plane == 1);
|
||||
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
||||
const PALETTE_MODE_INFO *const pmi = &mbmi->palette_mode_info;
|
||||
params->color_map = xd->plane[plane].color_index_map;
|
||||
params->map_cdf = plane ? xd->tile_ctx->palette_uv_color_index_cdf
|
||||
: xd->tile_ctx->palette_y_color_index_cdf;
|
||||
params->n_colors = pmi->palette_size[plane];
|
||||
av1_get_block_dimensions(bsize, plane, xd, ¶ms->plane_width,
|
||||
¶ms->plane_height, ¶ms->rows, ¶ms->cols);
|
||||
}
|
||||
|
||||
#if CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
|
||||
static void get_mrc_params(const MACROBLOCKD *const xd, TX_SIZE tx_size,
|
||||
Av1ColorMapParam *params) {
|
||||
memset(params, 0, sizeof(*params));
|
||||
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
||||
const int is_inter = is_inter_block(mbmi);
|
||||
params->color_map = xd->mrc_mask;
|
||||
params->map_cdf = is_inter ? xd->tile_ctx->mrc_mask_inter_cdf
|
||||
: xd->tile_ctx->mrc_mask_intra_cdf;
|
||||
params->n_colors = 2;
|
||||
params->plane_width = tx_size_wide[tx_size];
|
||||
params->rows = tx_size_high[tx_size];
|
||||
params->cols = tx_size_wide[tx_size];
|
||||
}
|
||||
#endif // CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
|
||||
|
||||
void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
|
||||
aom_reader *r) {
|
||||
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
||||
assert(plane == 0 || plane == 1);
|
||||
assert(mbmi->sb_type >= BLOCK_8X8);
|
||||
Av1ColorMapParam color_map_params;
|
||||
memset(&color_map_params, 0, sizeof(color_map_params));
|
||||
get_palette_params(xd, plane, mbmi->sb_type, &color_map_params);
|
||||
decode_color_map_tokens(&color_map_params, r);
|
||||
Av1ColorMapParam params;
|
||||
params.color_map =
|
||||
xd->plane[plane].color_index_map + xd->color_index_map_offset[plane];
|
||||
params.map_cdf = plane ? xd->tile_ctx->palette_uv_color_index_cdf
|
||||
: xd->tile_ctx->palette_y_color_index_cdf;
|
||||
const MB_MODE_INFO *const mbmi = xd->mi[0];
|
||||
params.n_colors = mbmi->palette_mode_info.palette_size[plane];
|
||||
av1_get_block_dimensions(mbmi->sb_type, plane, xd, ¶ms.plane_width,
|
||||
¶ms.plane_height, ¶ms.rows, ¶ms.cols);
|
||||
decode_color_map_tokens(¶ms, r);
|
||||
}
|
||||
|
||||
#if CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
|
||||
static void decode_mrc_tokens(MACROBLOCKD *const xd, TX_TYPE tx_size,
|
||||
aom_reader *r) {
|
||||
const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
|
||||
const int is_inter = is_inter_block(mbmi);
|
||||
if ((is_inter && !SIGNAL_MRC_MASK_INTER) ||
|
||||
(!is_inter && !SIGNAL_MRC_MASK_INTRA))
|
||||
return;
|
||||
Av1ColorMapParam color_map_params;
|
||||
get_mrc_params(xd, tx_size, &color_map_params);
|
||||
decode_color_map_tokens(&color_map_params, r);
|
||||
}
|
||||
#endif // CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
|
||||
|
||||
#if !CONFIG_PVQ || CONFIG_VAR_TX
|
||||
int av1_decode_block_tokens(AV1_COMMON *cm, MACROBLOCKD *const xd, int plane,
|
||||
const SCAN_ORDER *sc, int x, int y, TX_SIZE tx_size,
|
||||
TX_TYPE tx_type, int16_t *max_scan_line,
|
||||
aom_reader *r, int seg_id) {
|
||||
struct macroblockd_plane *const pd = &xd->plane[plane];
|
||||
const int16_t *const dequant = pd->seg_dequant[seg_id];
|
||||
const int ctx =
|
||||
get_entropy_context(tx_size, pd->above_context + x, pd->left_context + y);
|
||||
#if CONFIG_NEW_QUANT
|
||||
const int ref = is_inter_block(&xd->mi[0]->mbmi);
|
||||
int dq =
|
||||
get_dq_profile_from_ctx(xd->qindex[seg_id], ctx, ref, pd->plane_type);
|
||||
#endif // CONFIG_NEW_QUANT
|
||||
|
||||
#if CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
|
||||
if (tx_type == MRC_DCT) decode_mrc_tokens(xd, tx_size, r);
|
||||
#endif // CONFIG_MRC_TX && SIGNAL_ANY_MRC_MASK
|
||||
|
||||
const int eob =
|
||||
decode_coefs(xd, pd->plane_type, pd->dqcoeff, tx_size, tx_type, dequant,
|
||||
#if CONFIG_NEW_QUANT
|
||||
pd->seg_dequant_nuq[seg_id][dq],
|
||||
#else
|
||||
#if CONFIG_AOM_QM
|
||||
pd->seg_iqmatrix[seg_id],
|
||||
#endif // CONFIG_AOM_QM
|
||||
#endif // CONFIG_NEW_QUANT
|
||||
ctx, sc->scan, sc->neighbors, max_scan_line, r);
|
||||
av1_set_contexts(xd, pd, plane, tx_size, eob > 0, x, y);
|
||||
#if CONFIG_ADAPT_SCAN
|
||||
if (xd->counts)
|
||||
av1_update_scan_count_facade(cm, xd->counts, tx_size, tx_type, pd->dqcoeff,
|
||||
eob);
|
||||
#else
|
||||
(void)cm;
|
||||
#endif
|
||||
return eob;
|
||||
}
|
||||
#endif // !CONFIG_PVQ
|
||||
|
|
|
|||
11
third_party/aom/av1/decoder/detokenize.h
vendored
11
third_party/aom/av1/decoder/detokenize.h
vendored
|
|
@ -12,10 +12,9 @@
|
|||
#ifndef AV1_DECODER_DETOKENIZE_H_
|
||||
#define AV1_DECODER_DETOKENIZE_H_
|
||||
|
||||
#include "./aom_config.h"
|
||||
#if !CONFIG_PVQ || CONFIG_VAR_TX
|
||||
#include "config/aom_config.h"
|
||||
|
||||
#include "av1/common/scan.h"
|
||||
#endif // !CONFIG_PVQ || CONFIG_VAR_TX
|
||||
#include "av1/decoder/decoder.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -24,12 +23,6 @@ extern "C" {
|
|||
|
||||
void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, aom_reader *r);
|
||||
|
||||
#if !CONFIG_PVQ || CONFIG_VAR_TX
|
||||
int av1_decode_block_tokens(AV1_COMMON *cm, MACROBLOCKD *const xd, int plane,
|
||||
const SCAN_ORDER *sc, int x, int y, TX_SIZE tx_size,
|
||||
TX_TYPE tx_type, int16_t *max_scan_line,
|
||||
aom_reader *r, int seg_id);
|
||||
#endif // !CONFIG_PVQ
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
|
|
|||
82
third_party/aom/av1/decoder/dsubexp.c
vendored
82
third_party/aom/av1/decoder/dsubexp.c
vendored
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "av1/common/entropy.h"
|
||||
|
||||
#include "av1/decoder/dsubexp.h"
|
||||
|
||||
static int inv_recenter_nonneg(int v, int m) {
|
||||
if (v > 2 * m) return v;
|
||||
|
||||
return (v & 1) ? m - ((v + 1) >> 1) : m + (v >> 1);
|
||||
}
|
||||
|
||||
#define decode_uniform(r, ACCT_STR_NAME) \
|
||||
decode_uniform_(r ACCT_STR_ARG(ACCT_STR_NAME))
|
||||
#define decode_term_subexp(r, ACCT_STR_NAME) \
|
||||
decode_term_subexp_(r ACCT_STR_ARG(ACCT_STR_NAME))
|
||||
|
||||
static int decode_uniform_(aom_reader *r ACCT_STR_PARAM) {
|
||||
const int l = 8;
|
||||
const int m = (1 << l) - 190;
|
||||
const int v = aom_read_literal(r, l - 1, ACCT_STR_NAME);
|
||||
return v < m ? v : (v << 1) - m + aom_read_bit(r, ACCT_STR_NAME);
|
||||
}
|
||||
|
||||
static int inv_remap_prob(int v, int m) {
|
||||
/* clang-format off */
|
||||
static uint8_t inv_map_table[MAX_PROB - 1] = {
|
||||
7, 20, 33, 46, 59, 72, 85, 98, 111, 124, 137, 150, 163, 176, 189,
|
||||
202, 215, 228, 241, 254, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27,
|
||||
28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
|
||||
44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60,
|
||||
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76,
|
||||
77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90, 91, 92,
|
||||
93, 94, 95, 96, 97, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
|
||||
109, 110, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 125,
|
||||
126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 138, 139, 140, 141,
|
||||
142, 143, 144, 145, 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157,
|
||||
158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
|
||||
174, 175, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 190,
|
||||
191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206,
|
||||
207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221, 222,
|
||||
223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
|
||||
239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253
|
||||
}; /* clang-format on */
|
||||
assert(v < (int)(sizeof(inv_map_table) / sizeof(inv_map_table[0])));
|
||||
v = inv_map_table[v];
|
||||
m--;
|
||||
if ((m << 1) <= MAX_PROB) {
|
||||
return 1 + inv_recenter_nonneg(v, m);
|
||||
} else {
|
||||
return MAX_PROB - inv_recenter_nonneg(v, MAX_PROB - 1 - m);
|
||||
}
|
||||
}
|
||||
|
||||
static int decode_term_subexp_(aom_reader *r ACCT_STR_PARAM) {
|
||||
if (!aom_read_bit(r, ACCT_STR_NAME))
|
||||
return aom_read_literal(r, 4, ACCT_STR_NAME);
|
||||
if (!aom_read_bit(r, ACCT_STR_NAME))
|
||||
return aom_read_literal(r, 4, ACCT_STR_NAME) + 16;
|
||||
if (!aom_read_bit(r, ACCT_STR_NAME))
|
||||
return aom_read_literal(r, 5, ACCT_STR_NAME) + 32;
|
||||
return decode_uniform(r, ACCT_STR_NAME) + 64;
|
||||
}
|
||||
|
||||
void av1_diff_update_prob_(aom_reader *r, aom_prob *p ACCT_STR_PARAM) {
|
||||
if (aom_read(r, DIFF_UPDATE_PROB, ACCT_STR_NAME)) {
|
||||
const int delp = decode_term_subexp(r, ACCT_STR_NAME);
|
||||
*p = (aom_prob)inv_remap_prob(delp, *p);
|
||||
}
|
||||
}
|
||||
32
third_party/aom/av1/decoder/dsubexp.h
vendored
32
third_party/aom/av1/decoder/dsubexp.h
vendored
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef AV1_DECODER_DSUBEXP_H_
|
||||
#define AV1_DECODER_DSUBEXP_H_
|
||||
|
||||
#include "aom_dsp/bitreader.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if CONFIG_ACCOUNTING
|
||||
#define av1_diff_update_prob(r, p, str) av1_diff_update_prob_(r, p, str)
|
||||
#else
|
||||
#define av1_diff_update_prob(r, p, str) av1_diff_update_prob_(r, p)
|
||||
#endif
|
||||
|
||||
void av1_diff_update_prob_(aom_reader *r, aom_prob *p ACCT_STR_PARAM);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
#endif // AV1_DECODER_DSUBEXP_H_
|
||||
17
third_party/aom/av1/decoder/dthread.c
vendored
17
third_party/aom/av1/decoder/dthread.c
vendored
|
|
@ -9,7 +9,8 @@
|
|||
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
||||
*/
|
||||
|
||||
#include "./aom_config.h"
|
||||
#include "config/aom_config.h"
|
||||
|
||||
#include "aom_mem/aom_mem.h"
|
||||
#include "av1/common/reconinter.h"
|
||||
#include "av1/decoder/dthread.h"
|
||||
|
|
@ -157,12 +158,8 @@ void av1_frameworker_copy_context(AVxWorker *const dst_worker,
|
|||
av1_frameworker_unlock_stats(src_worker);
|
||||
|
||||
dst_cm->bit_depth = src_cm->bit_depth;
|
||||
#if CONFIG_HIGHBITDEPTH
|
||||
dst_cm->use_highbitdepth = src_cm->use_highbitdepth;
|
||||
#endif
|
||||
#if CONFIG_EXT_REFS
|
||||
// TODO(zoeliu): To handle parallel decoding
|
||||
#endif // CONFIG_EXT_REFS
|
||||
// TODO(zoeliu): To handle parallel decoding
|
||||
dst_cm->prev_frame =
|
||||
src_cm->show_existing_frame ? src_cm->prev_frame : src_cm->cur_frame;
|
||||
dst_cm->last_width =
|
||||
|
|
@ -180,14 +177,10 @@ void av1_frameworker_copy_context(AVxWorker *const dst_worker,
|
|||
|
||||
memcpy(dst_cm->lf_info.lfthr, src_cm->lf_info.lfthr,
|
||||
(MAX_LOOP_FILTER + 1) * sizeof(loop_filter_thresh));
|
||||
dst_cm->lf.last_sharpness_level = src_cm->lf.sharpness_level;
|
||||
#if CONFIG_LOOPFILTER_LEVEL
|
||||
dst_cm->lf.sharpness_level = src_cm->lf.sharpness_level;
|
||||
dst_cm->lf.filter_level[0] = src_cm->lf.filter_level[0];
|
||||
dst_cm->lf.filter_level[1] = src_cm->lf.filter_level[1];
|
||||
#else
|
||||
dst_cm->lf.filter_level = src_cm->lf.filter_level;
|
||||
#endif
|
||||
memcpy(dst_cm->lf.ref_deltas, src_cm->lf.ref_deltas, TOTAL_REFS_PER_FRAME);
|
||||
memcpy(dst_cm->lf.ref_deltas, src_cm->lf.ref_deltas, REF_FRAMES);
|
||||
memcpy(dst_cm->lf.mode_deltas, src_cm->lf.mode_deltas, MAX_MODE_LF_DELTAS);
|
||||
dst_cm->seg = src_cm->seg;
|
||||
memcpy(dst_cm->frame_contexts, src_cm->frame_contexts,
|
||||
|
|
|
|||
10
third_party/aom/av1/decoder/dthread.h
vendored
10
third_party/aom/av1/decoder/dthread.h
vendored
|
|
@ -12,7 +12,8 @@
|
|||
#ifndef AV1_DECODER_DTHREAD_H_
|
||||
#define AV1_DECODER_DTHREAD_H_
|
||||
|
||||
#include "./aom_config.h"
|
||||
#include "config/aom_config.h"
|
||||
|
||||
#include "aom_util/aom_thread.h"
|
||||
#include "aom/internal/aom_codec_internal.h"
|
||||
|
||||
|
|
@ -22,6 +23,13 @@ extern "C" {
|
|||
|
||||
struct AV1Common;
|
||||
struct AV1Decoder;
|
||||
struct ThreadData;
|
||||
|
||||
typedef struct DecWorkerData {
|
||||
struct ThreadData *td;
|
||||
const uint8_t *data_end;
|
||||
struct aom_internal_error_info error_info;
|
||||
} DecWorkerData;
|
||||
|
||||
// WorkerData for the FrameWorker thread. It contains all the information of
|
||||
// the worker and decode structures for decoding a frame.
|
||||
|
|
|
|||
110
third_party/aom/av1/decoder/generic_decoder.c
vendored
110
third_party/aom/av1/decoder/generic_decoder.c
vendored
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "aom_dsp/bitreader.h"
|
||||
#include "av1/common/generic_code.h"
|
||||
#include "av1/common/odintrin.h"
|
||||
#include "pvq_decoder.h"
|
||||
|
||||
/** Decodes a value from 0 to N-1 (with N up to 16) based on a cdf and adapts
|
||||
* the cdf accordingly.
|
||||
*
|
||||
* @param [in,out] r multi-symbol entropy decoder
|
||||
* @param [in,out] cdf CDF of the variable (Q15)
|
||||
* @param [in] n number of values possible
|
||||
* @param [in,out] count number of symbols encoded with that cdf so far
|
||||
* @param [in] rate adaptation rate shift (smaller is faster)
|
||||
* @return decoded variable
|
||||
*/
|
||||
int aom_decode_cdf_adapt_q15_(aom_reader *r, uint16_t *cdf, int n,
|
||||
int *count, int rate ACCT_STR_PARAM) {
|
||||
int val;
|
||||
int i;
|
||||
if (*count == 0) {
|
||||
int ft;
|
||||
ft = cdf[n - 1];
|
||||
for (i = 0; i < n; i++) {
|
||||
cdf[i] = AOM_ICDF(cdf[i]*32768/ft);
|
||||
}
|
||||
}
|
||||
val = aom_read_cdf(r, cdf, n, ACCT_STR_NAME);
|
||||
aom_cdf_adapt_q15(val, cdf, n, count, rate);
|
||||
return val;
|
||||
}
|
||||
|
||||
/** Encodes a random variable using a "generic" model, assuming that the
|
||||
* distribution is one-sided (zero and up), has a single mode, and decays
|
||||
* exponentially past the model.
|
||||
*
|
||||
* @param [in,out] r multi-symbol entropy decoder
|
||||
* @param [in,out] model generic probability model
|
||||
* @param [in] x variable being encoded
|
||||
* @param [in,out] ExQ16 expectation of x (adapted)
|
||||
* @param [in] integration integration period of ExQ16 (leaky average over
|
||||
* 1<<integration samples)
|
||||
*
|
||||
* @retval decoded variable x
|
||||
*/
|
||||
int generic_decode_(aom_reader *r, generic_encoder *model,
|
||||
int *ex_q16, int integration ACCT_STR_PARAM) {
|
||||
int lg_q1;
|
||||
int shift;
|
||||
int id;
|
||||
uint16_t *cdf;
|
||||
int xs;
|
||||
int lsb;
|
||||
int x;
|
||||
lsb = 0;
|
||||
lg_q1 = log_ex(*ex_q16);
|
||||
/* If expectation is too large, shift x to ensure that
|
||||
all we have past xs=15 is the exponentially decaying tail
|
||||
of the distribution. */
|
||||
shift = OD_MAXI(0, (lg_q1 - 5) >> 1);
|
||||
/* Choose the cdf to use: we have two per "octave" of ExQ16. */
|
||||
id = OD_MINI(GENERIC_TABLES - 1, lg_q1);
|
||||
cdf = model->cdf[id];
|
||||
xs = aom_read_symbol_pvq(r, cdf, 16, ACCT_STR_NAME);
|
||||
if (xs == 15) {
|
||||
int e;
|
||||
unsigned decay;
|
||||
/* Estimate decay based on the assumption that the distribution is close
|
||||
to Laplacian for large values. We should probably have an adaptive
|
||||
estimate instead. Note: The 2* is a kludge that's not fully understood
|
||||
yet. */
|
||||
OD_ASSERT(*ex_q16 < INT_MAX >> 1);
|
||||
e = ((2**ex_q16 >> 8) + (1 << shift >> 1)) >> shift;
|
||||
decay = OD_MAXI(2, OD_MINI(254, 256*e/(e + 256)));
|
||||
xs += aom_laplace_decode_special(r, decay, ACCT_STR_NAME);
|
||||
}
|
||||
if (shift != 0) {
|
||||
int special;
|
||||
/* Because of the rounding, there's only half the number of possibilities
|
||||
for xs=0 */
|
||||
special = xs == 0;
|
||||
if (shift - special > 0) {
|
||||
lsb = aom_read_literal(r, shift - special, ACCT_STR_NAME);
|
||||
}
|
||||
lsb -= !special << (shift - 1);
|
||||
}
|
||||
x = (xs << shift) + lsb;
|
||||
generic_model_update(ex_q16, x, integration);
|
||||
OD_LOG((OD_LOG_ENTROPY_CODER, OD_LOG_DEBUG,
|
||||
"dec: %d %d %d %d %d %x", *ex_q16, x, shift, id, xs, dec->rng));
|
||||
return x;
|
||||
}
|
||||
41
third_party/aom/av1/decoder/inspection.c
vendored
41
third_party/aom/av1/decoder/inspection.c
vendored
|
|
@ -11,12 +11,7 @@
|
|||
#include "av1/decoder/decoder.h"
|
||||
#include "av1/decoder/inspection.h"
|
||||
#include "av1/common/enums.h"
|
||||
#if CONFIG_CDEF
|
||||
#include "av1/common/cdef.h"
|
||||
#endif
|
||||
#if CONFIG_CFL
|
||||
#include "av1/common/cfl.h"
|
||||
#endif
|
||||
|
||||
static void ifd_init_mi_rc(insp_frame_data *fd, int mi_cols, int mi_rows) {
|
||||
fd->mi_cols = mi_cols;
|
||||
|
|
@ -48,25 +43,29 @@ int ifd_inspect(insp_frame_data *fd, void *decoder) {
|
|||
fd->show_frame = cm->show_frame;
|
||||
fd->frame_type = cm->frame_type;
|
||||
fd->base_qindex = cm->base_qindex;
|
||||
fd->tile_mi_cols = cm->tile_width;
|
||||
fd->tile_mi_rows = cm->tile_height;
|
||||
// Set width and height of the first tile until generic support can be added
|
||||
TileInfo tile_info;
|
||||
av1_tile_set_row(&tile_info, cm, 0);
|
||||
av1_tile_set_col(&tile_info, cm, 0);
|
||||
fd->tile_mi_cols = tile_info.mi_col_end - tile_info.mi_col_start;
|
||||
fd->tile_mi_rows = tile_info.mi_row_end - tile_info.mi_row_start;
|
||||
fd->delta_q_present_flag = cm->delta_q_present_flag;
|
||||
fd->delta_q_res = cm->delta_q_res;
|
||||
#if CONFIG_ACCOUNTING
|
||||
fd->accounting = &pbi->accounting;
|
||||
#endif
|
||||
#if CONFIG_CDEF
|
||||
// TODO(negge): copy per frame CDEF data
|
||||
#endif
|
||||
// TODO(negge): copy per frame CDEF data
|
||||
int i, j;
|
||||
for (i = 0; i < MAX_SEGMENTS; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
fd->y_dequant[i][j] = cm->y_dequant[i][j];
|
||||
fd->uv_dequant[i][j] = cm->uv_dequant[i][j];
|
||||
fd->y_dequant[i][j] = cm->y_dequant_QTX[i][j];
|
||||
fd->u_dequant[i][j] = cm->u_dequant_QTX[i][j];
|
||||
fd->v_dequant[i][j] = cm->v_dequant_QTX[i][j];
|
||||
}
|
||||
}
|
||||
for (j = 0; j < cm->mi_rows; j++) {
|
||||
for (i = 0; i < cm->mi_cols; i++) {
|
||||
const MB_MODE_INFO *mbmi =
|
||||
&cm->mi_grid_visible[j * cm->mi_stride + i]->mbmi;
|
||||
const MB_MODE_INFO *mbmi = cm->mi_grid_visible[j * cm->mi_stride + i];
|
||||
insp_mi_data *mi = &fd->mi_grid[j * cm->mi_cols + i];
|
||||
// Segment
|
||||
mi->segment_id = mbmi->segment_id;
|
||||
|
|
@ -90,24 +89,19 @@ int ifd_inspect(insp_frame_data *fd, void *decoder) {
|
|||
mi->sb_type = mbmi->sb_type;
|
||||
// Skip Flag
|
||||
mi->skip = mbmi->skip;
|
||||
#if CONFIG_DUAL_FILTER
|
||||
mi->filter[0] = av1_extract_interp_filter(mbmi->interp_filters, 0);
|
||||
mi->filter[1] = av1_extract_interp_filter(mbmi->interp_filters, 1);
|
||||
#else
|
||||
mi->filter = av1_extract_interp_filter(mbmi->interp_filters, 0);
|
||||
#endif
|
||||
mi->dual_filter_type = mi->filter[0] * 3 + mi->filter[1];
|
||||
// Transform
|
||||
mi->tx_type = mbmi->tx_type;
|
||||
// TODO(anyone): extract tx type info from mbmi->txk_type[].
|
||||
mi->tx_type = DCT_DCT;
|
||||
mi->tx_size = mbmi->tx_size;
|
||||
|
||||
#if CONFIG_CDEF
|
||||
mi->cdef_level =
|
||||
cm->cdef_strengths[mbmi->cdef_strength] / CDEF_SEC_STRENGTHS;
|
||||
mi->cdef_strength =
|
||||
cm->cdef_strengths[mbmi->cdef_strength] % CDEF_SEC_STRENGTHS;
|
||||
mi->cdef_strength += mi->cdef_strength == 3;
|
||||
#endif
|
||||
#if CONFIG_CFL
|
||||
if (mbmi->uv_mode == UV_CFL_PRED) {
|
||||
mi->cfl_alpha_idx = mbmi->cfl_alpha_idx;
|
||||
mi->cfl_alpha_sign = mbmi->cfl_alpha_signs;
|
||||
|
|
@ -115,7 +109,8 @@ int ifd_inspect(insp_frame_data *fd, void *decoder) {
|
|||
mi->cfl_alpha_idx = 0;
|
||||
mi->cfl_alpha_sign = 0;
|
||||
}
|
||||
#endif
|
||||
// delta_q
|
||||
mi->current_qindex = mbmi->current_qindex;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
|
|
|||
47
third_party/aom/av1/decoder/inspection.h
vendored
47
third_party/aom/av1/decoder/inspection.h
vendored
|
|
@ -20,7 +20,9 @@ extern "C" {
|
|||
#include "av1/decoder/accounting.h"
|
||||
#endif
|
||||
|
||||
#ifndef AOM_AOMDX_H_
|
||||
typedef void (*aom_inspect_cb)(void *decoder, void *data);
|
||||
#endif
|
||||
|
||||
typedef struct insp_mv insp_mv;
|
||||
|
||||
|
|
@ -33,27 +35,21 @@ typedef struct insp_mi_data insp_mi_data;
|
|||
|
||||
struct insp_mi_data {
|
||||
insp_mv mv[2];
|
||||
int8_t ref_frame[2];
|
||||
int8_t mode;
|
||||
int8_t uv_mode;
|
||||
int8_t sb_type;
|
||||
int8_t skip;
|
||||
int8_t segment_id;
|
||||
#if CONFIG_DUAL_FILTER
|
||||
int8_t filter[2];
|
||||
#else
|
||||
int8_t filter;
|
||||
#endif
|
||||
int8_t tx_type;
|
||||
int8_t tx_size;
|
||||
#if CONFIG_CDEF
|
||||
int8_t cdef_level;
|
||||
int8_t cdef_strength;
|
||||
#endif
|
||||
#if CONFIG_CFL
|
||||
int8_t cfl_alpha_idx;
|
||||
int8_t cfl_alpha_sign;
|
||||
#endif
|
||||
int16_t ref_frame[2];
|
||||
int16_t mode;
|
||||
int16_t uv_mode;
|
||||
int16_t sb_type;
|
||||
int16_t skip;
|
||||
int16_t segment_id;
|
||||
int16_t dual_filter_type;
|
||||
int16_t filter[2];
|
||||
int16_t tx_type;
|
||||
int16_t tx_size;
|
||||
int16_t cdef_level;
|
||||
int16_t cdef_strength;
|
||||
int16_t cfl_alpha_idx;
|
||||
int16_t cfl_alpha_sign;
|
||||
int16_t current_qindex;
|
||||
};
|
||||
|
||||
typedef struct insp_frame_data insp_frame_data;
|
||||
|
|
@ -71,10 +67,11 @@ struct insp_frame_data {
|
|||
int tile_mi_rows;
|
||||
int tile_mi_cols;
|
||||
int16_t y_dequant[MAX_SEGMENTS][2];
|
||||
int16_t uv_dequant[MAX_SEGMENTS][2];
|
||||
#if CONFIG_CDEF
|
||||
// TODO(negge): add per frame CDEF data
|
||||
#endif
|
||||
int16_t u_dequant[MAX_SEGMENTS][2];
|
||||
int16_t v_dequant[MAX_SEGMENTS][2];
|
||||
// TODO(negge): add per frame CDEF data
|
||||
int delta_q_present_flag;
|
||||
int delta_q_res;
|
||||
};
|
||||
|
||||
void ifd_init(insp_frame_data *fd, int frame_width, int frame_height);
|
||||
|
|
|
|||
121
third_party/aom/av1/decoder/laplace_decoder.c
vendored
121
third_party/aom/av1/decoder/laplace_decoder.c
vendored
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
/* clang-format off */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "aom_dsp/bitreader.h"
|
||||
#include "av1/common/pvq.h"
|
||||
#include "pvq_decoder.h"
|
||||
|
||||
#define aom_decode_pvq_split(r, adapt, sum, ctx, ACCT_STR_NAME) \
|
||||
aom_decode_pvq_split_(r, adapt, sum, ctx ACCT_STR_ARG(ACCT_STR_NAME))
|
||||
|
||||
static int aom_decode_pvq_split_(aom_reader *r, od_pvq_codeword_ctx *adapt,
|
||||
int sum, int ctx ACCT_STR_PARAM) {
|
||||
int shift;
|
||||
int count;
|
||||
int msbs;
|
||||
int fctx;
|
||||
count = 0;
|
||||
if (sum == 0) return 0;
|
||||
shift = OD_MAXI(0, OD_ILOG(sum) - 3);
|
||||
fctx = 7*ctx + (sum >> shift) - 1;
|
||||
msbs = aom_read_symbol_pvq(r, adapt->pvq_split_cdf[fctx], (sum >> shift) + 1,
|
||||
ACCT_STR_NAME);
|
||||
if (shift) count = aom_read_literal(r, shift, ACCT_STR_NAME);
|
||||
count += msbs << shift;
|
||||
if (count > sum) {
|
||||
count = sum;
|
||||
#if !CONFIG_ANS
|
||||
r->ec.error = 1;
|
||||
#else
|
||||
# error "CONFIG_PVQ currently requires !CONFIG_ANS."
|
||||
#endif
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void aom_decode_band_pvq_splits(aom_reader *r, od_pvq_codeword_ctx *adapt,
|
||||
od_coeff *y, int n, int k, int level) {
|
||||
int mid;
|
||||
int count_right;
|
||||
if (n == 1) {
|
||||
y[0] = k;
|
||||
}
|
||||
else if (k == 0) {
|
||||
OD_CLEAR(y, n);
|
||||
}
|
||||
else if (k == 1 && n <= 16) {
|
||||
int cdf_id;
|
||||
int pos;
|
||||
cdf_id = od_pvq_k1_ctx(n, level == 0);
|
||||
OD_CLEAR(y, n);
|
||||
pos = aom_read_symbol_pvq(r, adapt->pvq_k1_cdf[cdf_id], n, "pvq:k1");
|
||||
y[pos] = 1;
|
||||
}
|
||||
else {
|
||||
mid = n >> 1;
|
||||
count_right = aom_decode_pvq_split(r, adapt, k, od_pvq_size_ctx(n),
|
||||
"pvq:split");
|
||||
aom_decode_band_pvq_splits(r, adapt, y, mid, k - count_right, level + 1);
|
||||
aom_decode_band_pvq_splits(r, adapt, y + mid, n - mid, count_right,
|
||||
level + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/** Decodes the tail of a Laplace-distributed variable, i.e. it doesn't
|
||||
* do anything special for the zero case.
|
||||
*
|
||||
* @param [dec] range decoder
|
||||
* @param [decay] decay factor of the distribution, i.e. pdf ~= decay^x
|
||||
*
|
||||
* @retval decoded variable x
|
||||
*/
|
||||
int aom_laplace_decode_special_(aom_reader *r, unsigned decay ACCT_STR_PARAM) {
|
||||
int pos;
|
||||
int shift;
|
||||
int xs;
|
||||
int sym;
|
||||
const uint16_t *cdf;
|
||||
shift = 0;
|
||||
/* We don't want a large decay value because that would require too many
|
||||
symbols. */
|
||||
while (decay > 235) {
|
||||
decay = (decay*decay + 128) >> 8;
|
||||
shift++;
|
||||
}
|
||||
decay = OD_MINI(decay, 254);
|
||||
decay = OD_MAXI(decay, 2);
|
||||
cdf = EXP_CDF_TABLE[(decay + 1) >> 1];
|
||||
OD_LOG((OD_LOG_PVQ, OD_LOG_DEBUG, "decay = %d\n", decay));
|
||||
xs = 0;
|
||||
do {
|
||||
sym = OD_MINI(xs, 15);
|
||||
{
|
||||
int i;
|
||||
OD_LOG((OD_LOG_PVQ, OD_LOG_DEBUG, "%d %d %d", xs, shift, sym));
|
||||
for (i = 0; i < 16; i++) {
|
||||
OD_LOG_PARTIAL((OD_LOG_PVQ, OD_LOG_DEBUG, "%d ", cdf[i]));
|
||||
}
|
||||
OD_LOG_PARTIAL((OD_LOG_PVQ, OD_LOG_DEBUG, "\n"));
|
||||
}
|
||||
sym = aom_read_cdf(r, cdf, 16, ACCT_STR_NAME);
|
||||
xs += sym;
|
||||
} while (sym >= 15);
|
||||
if (shift) pos = (xs << shift) + aom_read_literal(r, shift, ACCT_STR_NAME);
|
||||
else pos = xs;
|
||||
return pos;
|
||||
}
|
||||
907
third_party/aom/av1/decoder/obu.c
vendored
Normal file
907
third_party/aom/av1/decoder/obu.c
vendored
Normal file
|
|
@ -0,0 +1,907 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Alliance for Open Media. All rights reserved
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "config/aom_config.h"
|
||||
|
||||
#include "aom/aom_codec.h"
|
||||
#include "aom_dsp/bitreader_buffer.h"
|
||||
#include "aom_ports/mem_ops.h"
|
||||
|
||||
#include "av1/common/common.h"
|
||||
#include "av1/common/timing.h"
|
||||
#include "av1/decoder/decoder.h"
|
||||
#include "av1/decoder/decodeframe.h"
|
||||
#include "av1/decoder/obu.h"
|
||||
|
||||
// Picture prediction structures (0-12 are predefined) in scalability metadata.
|
||||
typedef enum {
|
||||
SCALABILITY_L1T2 = 0,
|
||||
SCALABILITY_L1T3 = 1,
|
||||
SCALABILITY_L2T1 = 2,
|
||||
SCALABILITY_L2T2 = 3,
|
||||
SCALABILITY_L2T3 = 4,
|
||||
SCALABILITY_S2T1 = 5,
|
||||
SCALABILITY_S2T2 = 6,
|
||||
SCALABILITY_S2T3 = 7,
|
||||
SCALABILITY_L2T1h = 8,
|
||||
SCALABILITY_L2T2h = 9,
|
||||
SCALABILITY_L2T3h = 10,
|
||||
SCALABILITY_S2T1h = 11,
|
||||
SCALABILITY_S2T2h = 12,
|
||||
SCALABILITY_S2T3h = 13,
|
||||
SCALABILITY_SS = 14
|
||||
} SCALABILITY_STRUCTURES;
|
||||
|
||||
// Returns 1 when OBU type is valid, and 0 otherwise.
|
||||
static int valid_obu_type(int obu_type) {
|
||||
int valid_type = 0;
|
||||
switch (obu_type) {
|
||||
case OBU_SEQUENCE_HEADER:
|
||||
case OBU_TEMPORAL_DELIMITER:
|
||||
case OBU_FRAME_HEADER:
|
||||
case OBU_TILE_GROUP:
|
||||
case OBU_METADATA:
|
||||
case OBU_FRAME:
|
||||
case OBU_REDUNDANT_FRAME_HEADER:
|
||||
case OBU_TILE_LIST:
|
||||
case OBU_PADDING: valid_type = 1; break;
|
||||
default: break;
|
||||
}
|
||||
return valid_type;
|
||||
}
|
||||
|
||||
// Parses OBU header and stores values in 'header'.
|
||||
static aom_codec_err_t read_obu_header(struct aom_read_bit_buffer *rb,
|
||||
int is_annexb, ObuHeader *header) {
|
||||
if (!rb || !header) return AOM_CODEC_INVALID_PARAM;
|
||||
|
||||
const ptrdiff_t bit_buffer_byte_length = rb->bit_buffer_end - rb->bit_buffer;
|
||||
if (bit_buffer_byte_length < 1) return AOM_CODEC_CORRUPT_FRAME;
|
||||
|
||||
header->size = 1;
|
||||
|
||||
if (aom_rb_read_bit(rb) != 0) {
|
||||
// Forbidden bit. Must not be set.
|
||||
return AOM_CODEC_CORRUPT_FRAME;
|
||||
}
|
||||
|
||||
header->type = (OBU_TYPE)aom_rb_read_literal(rb, 4);
|
||||
|
||||
if (!valid_obu_type(header->type)) return AOM_CODEC_CORRUPT_FRAME;
|
||||
|
||||
header->has_extension = aom_rb_read_bit(rb);
|
||||
header->has_size_field = aom_rb_read_bit(rb);
|
||||
|
||||
if (!header->has_size_field && !is_annexb) {
|
||||
// section 5 obu streams must have obu_size field set.
|
||||
return AOM_CODEC_UNSUP_BITSTREAM;
|
||||
}
|
||||
|
||||
if (aom_rb_read_bit(rb) != 0) {
|
||||
// obu_reserved_1bit must be set to 0.
|
||||
return AOM_CODEC_CORRUPT_FRAME;
|
||||
}
|
||||
|
||||
if (header->has_extension) {
|
||||
if (bit_buffer_byte_length == 1) return AOM_CODEC_CORRUPT_FRAME;
|
||||
|
||||
header->size += 1;
|
||||
header->temporal_layer_id = aom_rb_read_literal(rb, 3);
|
||||
header->spatial_layer_id = aom_rb_read_literal(rb, 2);
|
||||
if (aom_rb_read_literal(rb, 3) != 0) {
|
||||
// extension_header_reserved_3bits must be set to 0.
|
||||
return AOM_CODEC_CORRUPT_FRAME;
|
||||
}
|
||||
}
|
||||
|
||||
return AOM_CODEC_OK;
|
||||
}
|
||||
|
||||
aom_codec_err_t aom_read_obu_header(uint8_t *buffer, size_t buffer_length,
|
||||
size_t *consumed, ObuHeader *header,
|
||||
int is_annexb) {
|
||||
if (buffer_length < 1 || !consumed || !header) return AOM_CODEC_INVALID_PARAM;
|
||||
|
||||
// TODO(tomfinegan): Set the error handler here and throughout this file, and
|
||||
// confirm parsing work done via aom_read_bit_buffer is successful.
|
||||
struct aom_read_bit_buffer rb = { buffer, buffer + buffer_length, 0, NULL,
|
||||
NULL };
|
||||
aom_codec_err_t parse_result = read_obu_header(&rb, is_annexb, header);
|
||||
if (parse_result == AOM_CODEC_OK) *consumed = header->size;
|
||||
return parse_result;
|
||||
}
|
||||
|
||||
aom_codec_err_t aom_get_num_layers_from_operating_point_idc(
|
||||
int operating_point_idc, unsigned int *number_spatial_layers,
|
||||
unsigned int *number_temporal_layers) {
|
||||
// derive number of spatial/temporal layers from operating_point_idc
|
||||
|
||||
if (!number_spatial_layers || !number_temporal_layers)
|
||||
return AOM_CODEC_INVALID_PARAM;
|
||||
|
||||
if (operating_point_idc == 0) {
|
||||
*number_temporal_layers = 1;
|
||||
*number_spatial_layers = 1;
|
||||
} else {
|
||||
*number_spatial_layers = 0;
|
||||
*number_temporal_layers = 0;
|
||||
for (int j = 0; j < MAX_NUM_SPATIAL_LAYERS; j++) {
|
||||
*number_spatial_layers +=
|
||||
(operating_point_idc >> (j + MAX_NUM_TEMPORAL_LAYERS)) & 0x1;
|
||||
}
|
||||
for (int j = 0; j < MAX_NUM_TEMPORAL_LAYERS; j++) {
|
||||
*number_temporal_layers += (operating_point_idc >> j) & 0x1;
|
||||
}
|
||||
}
|
||||
|
||||
return AOM_CODEC_OK;
|
||||
}
|
||||
|
||||
static int is_obu_in_current_operating_point(AV1Decoder *pbi,
|
||||
ObuHeader obu_header) {
|
||||
if (!pbi->current_operating_point) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((pbi->current_operating_point >> obu_header.temporal_layer_id) & 0x1 &&
|
||||
(pbi->current_operating_point >> (obu_header.spatial_layer_id + 8)) &
|
||||
0x1) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t read_temporal_delimiter_obu() { return 0; }
|
||||
|
||||
// Returns a boolean that indicates success.
|
||||
static int read_bitstream_level(BitstreamLevel *bl,
|
||||
struct aom_read_bit_buffer *rb) {
|
||||
const uint8_t seq_level_idx = aom_rb_read_literal(rb, LEVEL_BITS);
|
||||
if (!is_valid_seq_level_idx(seq_level_idx)) return 0;
|
||||
bl->major = (seq_level_idx >> LEVEL_MINOR_BITS) + LEVEL_MAJOR_MIN;
|
||||
bl->minor = seq_level_idx & ((1 << LEVEL_MINOR_BITS) - 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// On success, sets pbi->sequence_header_ready to 1 and returns the number of
|
||||
// bytes read from 'rb'.
|
||||
// On failure, sets pbi->common.error.error_code and returns 0.
|
||||
static uint32_t read_sequence_header_obu(AV1Decoder *pbi,
|
||||
struct aom_read_bit_buffer *rb) {
|
||||
AV1_COMMON *const cm = &pbi->common;
|
||||
const uint32_t saved_bit_offset = rb->bit_offset;
|
||||
|
||||
// Verify rb has been configured to report errors.
|
||||
assert(rb->error_handler);
|
||||
|
||||
cm->profile = av1_read_profile(rb);
|
||||
if (cm->profile > PROFILE_2) {
|
||||
cm->error.error_code = AOM_CODEC_UNSUP_BITSTREAM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SequenceHeader *const seq_params = &cm->seq_params;
|
||||
|
||||
// Still picture or not
|
||||
seq_params->still_picture = aom_rb_read_bit(rb);
|
||||
seq_params->reduced_still_picture_hdr = aom_rb_read_bit(rb);
|
||||
// Video must have reduced_still_picture_hdr = 0
|
||||
if (!seq_params->still_picture && seq_params->reduced_still_picture_hdr) {
|
||||
cm->error.error_code = AOM_CODEC_UNSUP_BITSTREAM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (seq_params->reduced_still_picture_hdr) {
|
||||
cm->timing_info_present = 0;
|
||||
seq_params->decoder_model_info_present_flag = 0;
|
||||
seq_params->display_model_info_present_flag = 0;
|
||||
seq_params->operating_points_cnt_minus_1 = 0;
|
||||
seq_params->operating_point_idc[0] = 0;
|
||||
if (!read_bitstream_level(&seq_params->level[0], rb)) {
|
||||
cm->error.error_code = AOM_CODEC_UNSUP_BITSTREAM;
|
||||
return 0;
|
||||
}
|
||||
seq_params->tier[0] = 0;
|
||||
cm->op_params[0].decoder_model_param_present_flag = 0;
|
||||
cm->op_params[0].display_model_param_present_flag = 0;
|
||||
} else {
|
||||
cm->timing_info_present = aom_rb_read_bit(rb); // timing_info_present_flag
|
||||
if (cm->timing_info_present) {
|
||||
av1_read_timing_info_header(cm, rb);
|
||||
|
||||
seq_params->decoder_model_info_present_flag = aom_rb_read_bit(rb);
|
||||
if (seq_params->decoder_model_info_present_flag)
|
||||
av1_read_decoder_model_info(cm, rb);
|
||||
} else {
|
||||
seq_params->decoder_model_info_present_flag = 0;
|
||||
}
|
||||
seq_params->display_model_info_present_flag = aom_rb_read_bit(rb);
|
||||
seq_params->operating_points_cnt_minus_1 =
|
||||
aom_rb_read_literal(rb, OP_POINTS_CNT_MINUS_1_BITS);
|
||||
for (int i = 0; i < seq_params->operating_points_cnt_minus_1 + 1; i++) {
|
||||
seq_params->operating_point_idc[i] =
|
||||
aom_rb_read_literal(rb, OP_POINTS_IDC_BITS);
|
||||
if (!read_bitstream_level(&seq_params->level[i], rb)) {
|
||||
cm->error.error_code = AOM_CODEC_UNSUP_BITSTREAM;
|
||||
return 0;
|
||||
}
|
||||
// This is the seq_level_idx[i] > 7 check in the spec. seq_level_idx 7
|
||||
// is equivalent to level 3.3.
|
||||
if (seq_params->level[i].major > 3)
|
||||
seq_params->tier[i] = aom_rb_read_bit(rb);
|
||||
else
|
||||
seq_params->tier[i] = 0;
|
||||
if (seq_params->decoder_model_info_present_flag) {
|
||||
cm->op_params[i].decoder_model_param_present_flag = aom_rb_read_bit(rb);
|
||||
if (cm->op_params[i].decoder_model_param_present_flag)
|
||||
av1_read_op_parameters_info(cm, rb, i);
|
||||
} else {
|
||||
cm->op_params[i].decoder_model_param_present_flag = 0;
|
||||
}
|
||||
if (cm->timing_info_present &&
|
||||
(cm->timing_info.equal_picture_interval ||
|
||||
cm->op_params[i].decoder_model_param_present_flag)) {
|
||||
cm->op_params[i].bitrate = max_level_bitrate(
|
||||
cm->profile, major_minor_to_seq_level_idx(seq_params->level[i]),
|
||||
seq_params->tier[i]);
|
||||
// Level with seq_level_idx = 31 returns a high "dummy" bitrate to pass
|
||||
// the check
|
||||
if (cm->op_params[i].bitrate == 0)
|
||||
aom_internal_error(&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
|
||||
"AV1 does not support this combination of "
|
||||
"profile, level, and tier.");
|
||||
// Buffer size in bits/s is bitrate in bits/s * 1 s
|
||||
cm->op_params[i].buffer_size = cm->op_params[i].bitrate;
|
||||
}
|
||||
if (cm->timing_info_present && cm->timing_info.equal_picture_interval &&
|
||||
!cm->op_params[i].decoder_model_param_present_flag) {
|
||||
// When the decoder_model_parameters are not sent for this op, set
|
||||
// the default ones that can be used with the resource availability mode
|
||||
cm->op_params[i].decoder_buffer_delay = 70000;
|
||||
cm->op_params[i].encoder_buffer_delay = 20000;
|
||||
cm->op_params[i].low_delay_mode_flag = 0;
|
||||
}
|
||||
|
||||
if (seq_params->display_model_info_present_flag) {
|
||||
cm->op_params[i].display_model_param_present_flag = aom_rb_read_bit(rb);
|
||||
if (cm->op_params[i].display_model_param_present_flag) {
|
||||
cm->op_params[i].initial_display_delay =
|
||||
aom_rb_read_literal(rb, 4) + 1;
|
||||
if (cm->op_params[i].initial_display_delay > 10)
|
||||
aom_internal_error(
|
||||
&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
|
||||
"AV1 does not support more than 10 decoded frames delay");
|
||||
} else {
|
||||
cm->op_params[i].initial_display_delay = 10;
|
||||
}
|
||||
} else {
|
||||
cm->op_params[i].display_model_param_present_flag = 0;
|
||||
cm->op_params[i].initial_display_delay = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
// This decoder supports all levels. Choose operating point provided by
|
||||
// external means
|
||||
int operating_point = pbi->operating_point;
|
||||
if (operating_point < 0 ||
|
||||
operating_point > seq_params->operating_points_cnt_minus_1)
|
||||
operating_point = 0;
|
||||
pbi->current_operating_point =
|
||||
seq_params->operating_point_idc[operating_point];
|
||||
if (aom_get_num_layers_from_operating_point_idc(
|
||||
pbi->current_operating_point, &cm->number_spatial_layers,
|
||||
&cm->number_temporal_layers) != AOM_CODEC_OK) {
|
||||
cm->error.error_code = AOM_CODEC_ERROR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
read_sequence_header(cm, rb);
|
||||
|
||||
av1_read_color_config(cm, rb, pbi->allow_lowbitdepth);
|
||||
|
||||
cm->film_grain_params_present = aom_rb_read_bit(rb);
|
||||
|
||||
if (av1_check_trailing_bits(pbi, rb) != 0) {
|
||||
// cm->error.error_code is already set.
|
||||
return 0;
|
||||
}
|
||||
|
||||
pbi->sequence_header_ready = 1;
|
||||
|
||||
return ((rb->bit_offset - saved_bit_offset + 7) >> 3);
|
||||
}
|
||||
|
||||
static uint32_t read_frame_header_obu(AV1Decoder *pbi,
|
||||
struct aom_read_bit_buffer *rb,
|
||||
const uint8_t *data,
|
||||
const uint8_t **p_data_end,
|
||||
int trailing_bits_present) {
|
||||
av1_decode_frame_headers_and_setup(pbi, rb, data, p_data_end,
|
||||
trailing_bits_present);
|
||||
return (uint32_t)(pbi->uncomp_hdr_size);
|
||||
}
|
||||
|
||||
static int32_t read_tile_group_header(AV1Decoder *pbi,
|
||||
struct aom_read_bit_buffer *rb,
|
||||
int *start_tile, int *end_tile,
|
||||
int tile_start_implicit) {
|
||||
AV1_COMMON *const cm = &pbi->common;
|
||||
uint32_t saved_bit_offset = rb->bit_offset;
|
||||
int tile_start_and_end_present_flag = 0;
|
||||
const int num_tiles = pbi->common.tile_rows * pbi->common.tile_cols;
|
||||
|
||||
if (!pbi->common.large_scale_tile && num_tiles > 1) {
|
||||
tile_start_and_end_present_flag = aom_rb_read_bit(rb);
|
||||
}
|
||||
if (pbi->common.large_scale_tile || num_tiles == 1 ||
|
||||
!tile_start_and_end_present_flag) {
|
||||
*start_tile = 0;
|
||||
*end_tile = num_tiles - 1;
|
||||
return ((rb->bit_offset - saved_bit_offset + 7) >> 3);
|
||||
}
|
||||
if (tile_start_implicit && tile_start_and_end_present_flag) {
|
||||
aom_internal_error(
|
||||
&cm->error, AOM_CODEC_UNSUP_BITSTREAM,
|
||||
"For OBU_FRAME type obu tile_start_and_end_present_flag must be 0");
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return -1;
|
||||
}
|
||||
*start_tile =
|
||||
aom_rb_read_literal(rb, cm->log2_tile_rows + cm->log2_tile_cols);
|
||||
*end_tile = aom_rb_read_literal(rb, cm->log2_tile_rows + cm->log2_tile_cols);
|
||||
|
||||
return ((rb->bit_offset - saved_bit_offset + 7) >> 3);
|
||||
}
|
||||
|
||||
static uint32_t read_one_tile_group_obu(
|
||||
AV1Decoder *pbi, struct aom_read_bit_buffer *rb, int is_first_tg,
|
||||
const uint8_t *data, const uint8_t *data_end, const uint8_t **p_data_end,
|
||||
int *is_last_tg, int tile_start_implicit) {
|
||||
AV1_COMMON *const cm = &pbi->common;
|
||||
int start_tile, end_tile;
|
||||
int32_t header_size, tg_payload_size;
|
||||
|
||||
header_size = read_tile_group_header(pbi, rb, &start_tile, &end_tile,
|
||||
tile_start_implicit);
|
||||
if (header_size == -1) return 0;
|
||||
if (start_tile > end_tile) return header_size;
|
||||
data += header_size;
|
||||
av1_decode_tg_tiles_and_wrapup(pbi, data, data_end, p_data_end, start_tile,
|
||||
end_tile, is_first_tg);
|
||||
|
||||
tg_payload_size = (uint32_t)(*p_data_end - data);
|
||||
|
||||
// TODO(shan): For now, assume all tile groups received in order
|
||||
*is_last_tg = end_tile == cm->tile_rows * cm->tile_cols - 1;
|
||||
return header_size + tg_payload_size;
|
||||
}
|
||||
|
||||
// Only called while large_scale_tile = 1.
|
||||
static uint32_t read_and_decode_one_tile_list(AV1Decoder *pbi,
|
||||
struct aom_read_bit_buffer *rb,
|
||||
const uint8_t *data,
|
||||
const uint8_t *data_end,
|
||||
const uint8_t **p_data_end,
|
||||
int *frame_decoding_finished) {
|
||||
AV1_COMMON *const cm = &pbi->common;
|
||||
uint32_t tile_list_payload_size = 0;
|
||||
const int num_tiles = cm->tile_cols * cm->tile_rows;
|
||||
const int start_tile = 0;
|
||||
const int end_tile = num_tiles - 1;
|
||||
int i = 0;
|
||||
|
||||
// Process the tile list info.
|
||||
pbi->output_frame_width_in_tiles_minus_1 = aom_rb_read_literal(rb, 8);
|
||||
pbi->output_frame_height_in_tiles_minus_1 = aom_rb_read_literal(rb, 8);
|
||||
pbi->tile_count_minus_1 = aom_rb_read_literal(rb, 16);
|
||||
if (pbi->tile_count_minus_1 > 511) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allocate output frame buffer for the tile list.
|
||||
// TODO(yunqing): for now, copy each tile's decoded YUV data directly to the
|
||||
// output buffer. This needs to be modified according to the application
|
||||
// requirement.
|
||||
const int tile_width_in_pixels = cm->tile_width * MI_SIZE;
|
||||
const int tile_height_in_pixels = cm->tile_height * MI_SIZE;
|
||||
const int ssy = cm->subsampling_y;
|
||||
const int ssx = cm->subsampling_x;
|
||||
const int num_planes = av1_num_planes(cm);
|
||||
const size_t yplane_tile_size = tile_height_in_pixels * tile_width_in_pixels;
|
||||
const size_t uvplane_tile_size =
|
||||
(num_planes > 1)
|
||||
? (tile_height_in_pixels >> ssy) * (tile_width_in_pixels >> ssx)
|
||||
: 0;
|
||||
const size_t tile_size = (cm->use_highbitdepth ? 2 : 1) *
|
||||
(yplane_tile_size + 2 * uvplane_tile_size);
|
||||
pbi->tile_list_size = tile_size * (pbi->tile_count_minus_1 + 1);
|
||||
|
||||
if (pbi->tile_list_size > pbi->buffer_sz) {
|
||||
if (pbi->tile_list_output != NULL) aom_free(pbi->tile_list_output);
|
||||
pbi->tile_list_output = NULL;
|
||||
|
||||
pbi->tile_list_output = (uint8_t *)aom_memalign(32, pbi->tile_list_size);
|
||||
if (pbi->tile_list_output == NULL)
|
||||
aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
|
||||
"Failed to allocate the tile list output buffer");
|
||||
pbi->buffer_sz = pbi->tile_list_size;
|
||||
}
|
||||
|
||||
uint32_t tile_list_info_bytes = 4;
|
||||
tile_list_payload_size += tile_list_info_bytes;
|
||||
data += tile_list_info_bytes;
|
||||
uint8_t *output = pbi->tile_list_output;
|
||||
|
||||
for (i = 0; i <= pbi->tile_count_minus_1; i++) {
|
||||
// Process 1 tile.
|
||||
// Reset the bit reader.
|
||||
rb->bit_offset = 0;
|
||||
rb->bit_buffer = data;
|
||||
|
||||
// Read out the tile info.
|
||||
uint32_t tile_info_bytes = 5;
|
||||
// Set reference for each tile.
|
||||
int ref_idx = aom_rb_read_literal(rb, 8);
|
||||
if (ref_idx >= MAX_EXTERNAL_REFERENCES) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return 0;
|
||||
}
|
||||
av1_set_reference_dec(cm, 0, 1, &pbi->ext_refs.refs[ref_idx]);
|
||||
|
||||
pbi->dec_tile_row = aom_rb_read_literal(rb, 8);
|
||||
pbi->dec_tile_col = aom_rb_read_literal(rb, 8);
|
||||
if (pbi->dec_tile_row < 0 || pbi->dec_tile_col < 0 ||
|
||||
pbi->dec_tile_row >= cm->tile_rows ||
|
||||
pbi->dec_tile_col >= cm->tile_cols) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pbi->coded_tile_data_size = aom_rb_read_literal(rb, 16) + 1;
|
||||
data += tile_info_bytes;
|
||||
if ((size_t)(data_end - data) < pbi->coded_tile_data_size) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return 0;
|
||||
}
|
||||
|
||||
av1_decode_tg_tiles_and_wrapup(pbi, data, data + pbi->coded_tile_data_size,
|
||||
p_data_end, start_tile, end_tile, 0);
|
||||
uint32_t tile_payload_size = (uint32_t)(*p_data_end - data);
|
||||
|
||||
tile_list_payload_size += tile_info_bytes + tile_payload_size;
|
||||
|
||||
// Update data ptr for next tile decoding.
|
||||
data = *p_data_end;
|
||||
assert(data <= data_end);
|
||||
|
||||
// Copy decoded tile to the tile list output buffer.
|
||||
YV12_BUFFER_CONFIG *cur_frame = get_frame_new_buffer(cm);
|
||||
const int mi_row = pbi->dec_tile_row * cm->tile_height;
|
||||
const int mi_col = pbi->dec_tile_col * cm->tile_width;
|
||||
const int is_hbd = (cur_frame->flags & YV12_FLAG_HIGHBITDEPTH) ? 1 : 0;
|
||||
uint8_t *bufs[MAX_MB_PLANE] = { NULL, NULL, NULL };
|
||||
int strides[MAX_MB_PLANE] = { 0, 0, 0 };
|
||||
int plane;
|
||||
|
||||
for (plane = 0; plane < num_planes; ++plane) {
|
||||
int shift_x = plane > 0 ? ssx : 0;
|
||||
int shift_y = plane > 0 ? ssy : 0;
|
||||
|
||||
bufs[plane] = cur_frame->buffers[plane];
|
||||
strides[plane] =
|
||||
(plane > 0) ? cur_frame->strides[1] : cur_frame->strides[0];
|
||||
if (is_hbd) {
|
||||
bufs[plane] = (uint8_t *)CONVERT_TO_SHORTPTR(cur_frame->buffers[plane]);
|
||||
strides[plane] =
|
||||
(plane > 0) ? 2 * cur_frame->strides[1] : 2 * cur_frame->strides[0];
|
||||
}
|
||||
|
||||
bufs[plane] += mi_row * (MI_SIZE >> shift_y) * strides[plane] +
|
||||
mi_col * (MI_SIZE >> shift_x);
|
||||
|
||||
int w, h;
|
||||
w = (plane > 0 && shift_x > 0) ? ((tile_width_in_pixels + 1) >> shift_x)
|
||||
: tile_width_in_pixels;
|
||||
w *= (1 + is_hbd);
|
||||
h = (plane > 0 && shift_y > 0) ? ((tile_height_in_pixels + 1) >> shift_y)
|
||||
: tile_height_in_pixels;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < h; ++j) {
|
||||
memcpy(output, bufs[plane], w);
|
||||
bufs[plane] += strides[plane];
|
||||
output += w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*frame_decoding_finished = 1;
|
||||
return tile_list_payload_size;
|
||||
}
|
||||
|
||||
static void read_metadata_itut_t35(const uint8_t *data, size_t sz) {
|
||||
struct aom_read_bit_buffer rb = { data, data + sz, 0, NULL, NULL };
|
||||
for (size_t i = 0; i < sz; i++) {
|
||||
aom_rb_read_literal(&rb, 8);
|
||||
}
|
||||
}
|
||||
|
||||
static void read_metadata_hdr_cll(const uint8_t *data, size_t sz) {
|
||||
struct aom_read_bit_buffer rb = { data, data + sz, 0, NULL, NULL };
|
||||
aom_rb_read_literal(&rb, 16); // max_cll
|
||||
aom_rb_read_literal(&rb, 16); // max_fall
|
||||
}
|
||||
|
||||
static void read_metadata_hdr_mdcv(const uint8_t *data, size_t sz) {
|
||||
struct aom_read_bit_buffer rb = { data, data + sz, 0, NULL, NULL };
|
||||
for (int i = 0; i < 3; i++) {
|
||||
aom_rb_read_literal(&rb, 16); // primary_i_chromaticity_x
|
||||
aom_rb_read_literal(&rb, 16); // primary_i_chromaticity_y
|
||||
}
|
||||
|
||||
aom_rb_read_literal(&rb, 16); // white_point_chromaticity_x
|
||||
aom_rb_read_literal(&rb, 16); // white_point_chromaticity_y
|
||||
|
||||
aom_rb_read_unsigned_literal(&rb, 32); // luminance_max
|
||||
aom_rb_read_unsigned_literal(&rb, 32); // luminance_min
|
||||
}
|
||||
|
||||
static void scalability_structure(struct aom_read_bit_buffer *rb) {
|
||||
int spatial_layers_cnt = aom_rb_read_literal(rb, 2);
|
||||
int spatial_layer_dimensions_present_flag = aom_rb_read_literal(rb, 1);
|
||||
int spatial_layer_description_present_flag = aom_rb_read_literal(rb, 1);
|
||||
int temporal_group_description_present_flag = aom_rb_read_literal(rb, 1);
|
||||
aom_rb_read_literal(rb, 3); // reserved
|
||||
|
||||
if (spatial_layer_dimensions_present_flag) {
|
||||
int i;
|
||||
for (i = 0; i < spatial_layers_cnt + 1; i++) {
|
||||
aom_rb_read_literal(rb, 16);
|
||||
aom_rb_read_literal(rb, 16);
|
||||
}
|
||||
}
|
||||
if (spatial_layer_description_present_flag) {
|
||||
int i;
|
||||
for (i = 0; i < spatial_layers_cnt + 1; i++) {
|
||||
aom_rb_read_literal(rb, 8);
|
||||
}
|
||||
}
|
||||
if (temporal_group_description_present_flag) {
|
||||
int i, j, temporal_group_size;
|
||||
temporal_group_size = aom_rb_read_literal(rb, 8);
|
||||
for (i = 0; i < temporal_group_size; i++) {
|
||||
aom_rb_read_literal(rb, 3);
|
||||
aom_rb_read_literal(rb, 1);
|
||||
aom_rb_read_literal(rb, 1);
|
||||
int temporal_group_ref_cnt = aom_rb_read_literal(rb, 3);
|
||||
for (j = 0; j < temporal_group_ref_cnt; j++) {
|
||||
aom_rb_read_literal(rb, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void read_metadata_scalability(const uint8_t *data, size_t sz) {
|
||||
struct aom_read_bit_buffer rb = { data, data + sz, 0, NULL, NULL };
|
||||
int scalability_mode_idc = aom_rb_read_literal(&rb, 8);
|
||||
if (scalability_mode_idc == SCALABILITY_SS) {
|
||||
scalability_structure(&rb);
|
||||
}
|
||||
}
|
||||
|
||||
static void read_metadata_timecode(const uint8_t *data, size_t sz) {
|
||||
struct aom_read_bit_buffer rb = { data, data + sz, 0, NULL, NULL };
|
||||
aom_rb_read_literal(&rb, 5); // counting_type f(5)
|
||||
int full_timestamp_flag = aom_rb_read_bit(&rb); // full_timestamp_flag f(1)
|
||||
aom_rb_read_bit(&rb); // discontinuity_flag (f1)
|
||||
aom_rb_read_bit(&rb); // cnt_dropped_flag f(1)
|
||||
aom_rb_read_literal(&rb, 9); // n_frames f(9)
|
||||
if (full_timestamp_flag) {
|
||||
aom_rb_read_literal(&rb, 6); // seconds_value f(6)
|
||||
aom_rb_read_literal(&rb, 6); // minutes_value f(6)
|
||||
aom_rb_read_literal(&rb, 5); // hours_value f(5)
|
||||
} else {
|
||||
int seconds_flag = aom_rb_read_bit(&rb); // seconds_flag f(1)
|
||||
if (seconds_flag) {
|
||||
aom_rb_read_literal(&rb, 6); // seconds_value f(6)
|
||||
int minutes_flag = aom_rb_read_bit(&rb); // minutes_flag f(1)
|
||||
if (minutes_flag) {
|
||||
aom_rb_read_literal(&rb, 6); // minutes_value f(6)
|
||||
int hours_flag = aom_rb_read_bit(&rb); // hours_flag f(1)
|
||||
if (hours_flag) {
|
||||
aom_rb_read_literal(&rb, 5); // hours_value f(5)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// time_offset_length f(5)
|
||||
int time_offset_length = aom_rb_read_literal(&rb, 5);
|
||||
if (time_offset_length) {
|
||||
aom_rb_read_literal(&rb, time_offset_length); // f(time_offset_length)
|
||||
}
|
||||
}
|
||||
|
||||
static size_t read_metadata(const uint8_t *data, size_t sz) {
|
||||
size_t type_length;
|
||||
uint64_t type_value;
|
||||
OBU_METADATA_TYPE metadata_type;
|
||||
if (aom_uleb_decode(data, sz, &type_value, &type_length) < 0) {
|
||||
return sz;
|
||||
}
|
||||
metadata_type = (OBU_METADATA_TYPE)type_value;
|
||||
if (metadata_type == OBU_METADATA_TYPE_ITUT_T35) {
|
||||
read_metadata_itut_t35(data + type_length, sz - type_length);
|
||||
} else if (metadata_type == OBU_METADATA_TYPE_HDR_CLL) {
|
||||
read_metadata_hdr_cll(data + type_length, sz - type_length);
|
||||
} else if (metadata_type == OBU_METADATA_TYPE_HDR_MDCV) {
|
||||
read_metadata_hdr_mdcv(data + type_length, sz - type_length);
|
||||
} else if (metadata_type == OBU_METADATA_TYPE_SCALABILITY) {
|
||||
read_metadata_scalability(data + type_length, sz - type_length);
|
||||
} else if (metadata_type == OBU_METADATA_TYPE_TIMECODE) {
|
||||
read_metadata_timecode(data + type_length, sz - type_length);
|
||||
}
|
||||
|
||||
return sz;
|
||||
}
|
||||
|
||||
static aom_codec_err_t read_obu_size(const uint8_t *data,
|
||||
size_t bytes_available,
|
||||
size_t *const obu_size,
|
||||
size_t *const length_field_size) {
|
||||
uint64_t u_obu_size = 0;
|
||||
if (aom_uleb_decode(data, bytes_available, &u_obu_size, length_field_size) !=
|
||||
0) {
|
||||
return AOM_CODEC_CORRUPT_FRAME;
|
||||
}
|
||||
|
||||
if (u_obu_size > UINT32_MAX) return AOM_CODEC_CORRUPT_FRAME;
|
||||
*obu_size = (size_t)u_obu_size;
|
||||
return AOM_CODEC_OK;
|
||||
}
|
||||
|
||||
aom_codec_err_t aom_read_obu_header_and_size(const uint8_t *data,
|
||||
size_t bytes_available,
|
||||
int is_annexb,
|
||||
ObuHeader *obu_header,
|
||||
size_t *const payload_size,
|
||||
size_t *const bytes_read) {
|
||||
size_t length_field_size = 0, obu_size = 0;
|
||||
aom_codec_err_t status;
|
||||
|
||||
if (is_annexb) {
|
||||
// Size field comes before the OBU header, and includes the OBU header
|
||||
status =
|
||||
read_obu_size(data, bytes_available, &obu_size, &length_field_size);
|
||||
|
||||
if (status != AOM_CODEC_OK) return status;
|
||||
}
|
||||
|
||||
struct aom_read_bit_buffer rb = { data + length_field_size,
|
||||
data + bytes_available, 0, NULL, NULL };
|
||||
|
||||
status = read_obu_header(&rb, is_annexb, obu_header);
|
||||
if (status != AOM_CODEC_OK) return status;
|
||||
|
||||
if (is_annexb) {
|
||||
// Derive the payload size from the data we've already read
|
||||
if (obu_size < obu_header->size) return AOM_CODEC_CORRUPT_FRAME;
|
||||
|
||||
*payload_size = obu_size - obu_header->size;
|
||||
} else {
|
||||
// Size field comes after the OBU header, and is just the payload size
|
||||
status = read_obu_size(data + obu_header->size,
|
||||
bytes_available - obu_header->size, payload_size,
|
||||
&length_field_size);
|
||||
if (status != AOM_CODEC_OK) return status;
|
||||
}
|
||||
|
||||
*bytes_read = length_field_size + obu_header->size;
|
||||
return AOM_CODEC_OK;
|
||||
}
|
||||
|
||||
#define EXT_TILE_DEBUG 0
|
||||
// On success, returns a boolean that indicates whether the decoding of the
|
||||
// current frame is finished. On failure, sets cm->error.error_code and
|
||||
// returns -1.
|
||||
int aom_decode_frame_from_obus(struct AV1Decoder *pbi, const uint8_t *data,
|
||||
const uint8_t *data_end,
|
||||
const uint8_t **p_data_end) {
|
||||
AV1_COMMON *const cm = &pbi->common;
|
||||
int frame_decoding_finished = 0;
|
||||
int is_first_tg_obu_received = 1;
|
||||
int frame_header_size = 0;
|
||||
int seq_header_received = 0;
|
||||
size_t seq_header_size = 0;
|
||||
ObuHeader obu_header;
|
||||
memset(&obu_header, 0, sizeof(obu_header));
|
||||
pbi->seen_frame_header = 0;
|
||||
|
||||
if (data_end < data) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Reset pbi->camera_frame_header_ready to 0 if cm->large_scale_tile = 0.
|
||||
if (!cm->large_scale_tile) pbi->camera_frame_header_ready = 0;
|
||||
|
||||
// decode frame as a series of OBUs
|
||||
while (!frame_decoding_finished && !cm->error.error_code) {
|
||||
struct aom_read_bit_buffer rb;
|
||||
size_t payload_size = 0;
|
||||
size_t decoded_payload_size = 0;
|
||||
size_t obu_payload_offset = 0;
|
||||
size_t bytes_read = 0;
|
||||
const size_t bytes_available = data_end - data;
|
||||
|
||||
if (bytes_available == 0 && !pbi->seen_frame_header) {
|
||||
*p_data_end = data;
|
||||
cm->error.error_code = AOM_CODEC_OK;
|
||||
break;
|
||||
}
|
||||
|
||||
aom_codec_err_t status =
|
||||
aom_read_obu_header_and_size(data, bytes_available, cm->is_annexb,
|
||||
&obu_header, &payload_size, &bytes_read);
|
||||
|
||||
if (status != AOM_CODEC_OK) {
|
||||
cm->error.error_code = status;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Record obu size header information.
|
||||
pbi->obu_size_hdr.data = data + obu_header.size;
|
||||
pbi->obu_size_hdr.size = bytes_read - obu_header.size;
|
||||
|
||||
// Note: aom_read_obu_header_and_size() takes care of checking that this
|
||||
// doesn't cause 'data' to advance past 'data_end'.
|
||||
data += bytes_read;
|
||||
|
||||
if ((size_t)(data_end - data) < payload_size) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cm->temporal_layer_id = obu_header.temporal_layer_id;
|
||||
cm->spatial_layer_id = obu_header.spatial_layer_id;
|
||||
|
||||
if (obu_header.type != OBU_TEMPORAL_DELIMITER &&
|
||||
obu_header.type != OBU_SEQUENCE_HEADER &&
|
||||
obu_header.type != OBU_PADDING) {
|
||||
// don't decode obu if it's not in current operating mode
|
||||
if (!is_obu_in_current_operating_point(pbi, obu_header)) {
|
||||
data += payload_size;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
av1_init_read_bit_buffer(pbi, &rb, data, data_end);
|
||||
|
||||
switch (obu_header.type) {
|
||||
case OBU_TEMPORAL_DELIMITER:
|
||||
decoded_payload_size = read_temporal_delimiter_obu();
|
||||
pbi->seen_frame_header = 0;
|
||||
break;
|
||||
case OBU_SEQUENCE_HEADER:
|
||||
if (!seq_header_received) {
|
||||
decoded_payload_size = read_sequence_header_obu(pbi, &rb);
|
||||
if (cm->error.error_code != AOM_CODEC_OK) return -1;
|
||||
|
||||
seq_header_size = decoded_payload_size;
|
||||
seq_header_received = 1;
|
||||
} else {
|
||||
// Seeing another sequence header, skip as all sequence headers are
|
||||
// required to be identical except for the contents of
|
||||
// operating_parameters_info and the amount of trailing bits.
|
||||
// TODO(yaowu): verifying redundant sequence headers are identical.
|
||||
decoded_payload_size = seq_header_size;
|
||||
}
|
||||
break;
|
||||
case OBU_FRAME_HEADER:
|
||||
case OBU_REDUNDANT_FRAME_HEADER:
|
||||
case OBU_FRAME:
|
||||
// Only decode first frame header received
|
||||
if (!pbi->seen_frame_header ||
|
||||
(cm->large_scale_tile && !pbi->camera_frame_header_ready)) {
|
||||
pbi->seen_frame_header = 1;
|
||||
frame_header_size = read_frame_header_obu(
|
||||
pbi, &rb, data, p_data_end, obu_header.type != OBU_FRAME);
|
||||
if (cm->large_scale_tile) pbi->camera_frame_header_ready = 1;
|
||||
}
|
||||
decoded_payload_size = frame_header_size;
|
||||
pbi->frame_header_size = (size_t)frame_header_size;
|
||||
|
||||
if (cm->show_existing_frame) {
|
||||
frame_decoding_finished = 1;
|
||||
pbi->seen_frame_header = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
#if !EXT_TILE_DEBUG
|
||||
// In large scale tile coding, decode the common camera frame header
|
||||
// before any tile list OBU.
|
||||
if (!pbi->ext_tile_debug && pbi->camera_frame_header_ready) {
|
||||
frame_decoding_finished = 1;
|
||||
// Skip the rest of the frame data.
|
||||
decoded_payload_size = payload_size;
|
||||
// Update data_end.
|
||||
*p_data_end = data_end;
|
||||
break;
|
||||
}
|
||||
#endif // EXT_TILE_DEBUG
|
||||
|
||||
if (obu_header.type != OBU_FRAME) break;
|
||||
obu_payload_offset = frame_header_size;
|
||||
AOM_FALLTHROUGH_INTENDED; // fall through to read tile group.
|
||||
case OBU_TILE_GROUP:
|
||||
if (!pbi->seen_frame_header) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return -1;
|
||||
}
|
||||
if ((size_t)(data_end - data) < obu_payload_offset) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return -1;
|
||||
}
|
||||
decoded_payload_size += read_one_tile_group_obu(
|
||||
pbi, &rb, is_first_tg_obu_received, data + obu_payload_offset,
|
||||
data + payload_size, p_data_end, &frame_decoding_finished,
|
||||
obu_header.type == OBU_FRAME);
|
||||
is_first_tg_obu_received = 0;
|
||||
if (frame_decoding_finished) pbi->seen_frame_header = 0;
|
||||
break;
|
||||
case OBU_METADATA:
|
||||
decoded_payload_size = read_metadata(data, payload_size);
|
||||
break;
|
||||
case OBU_TILE_LIST:
|
||||
// This OBU type is purely for the large scale tile coding mode.
|
||||
// The common camera frame header has to be already decoded.
|
||||
if (!pbi->camera_frame_header_ready) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return -1;
|
||||
}
|
||||
|
||||
cm->large_scale_tile = 1;
|
||||
av1_set_single_tile_decoding_mode(cm);
|
||||
decoded_payload_size =
|
||||
read_and_decode_one_tile_list(pbi, &rb, data, data + payload_size,
|
||||
p_data_end, &frame_decoding_finished);
|
||||
if (cm->error.error_code != AOM_CODEC_OK) return -1;
|
||||
break;
|
||||
case OBU_PADDING:
|
||||
default:
|
||||
// Skip unrecognized OBUs
|
||||
decoded_payload_size = payload_size;
|
||||
break;
|
||||
}
|
||||
|
||||
// Check that the signalled OBU size matches the actual amount of data read
|
||||
if (decoded_payload_size > payload_size) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// If there are extra padding bytes, they should all be zero
|
||||
while (decoded_payload_size < payload_size) {
|
||||
uint8_t padding_byte = data[decoded_payload_size++];
|
||||
if (padding_byte != 0) {
|
||||
cm->error.error_code = AOM_CODEC_CORRUPT_FRAME;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
data += payload_size;
|
||||
}
|
||||
|
||||
return frame_decoding_finished;
|
||||
}
|
||||
#undef EXT_TILE_DEBUG
|
||||
54
third_party/aom/av1/decoder/obu.h
vendored
Normal file
54
third_party/aom/av1/decoder/obu.h
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Alliance for Open Media. All rights reserved
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef AV1_DECODER_OBU_H
|
||||
#define AV1_DECODER_OBU_H
|
||||
|
||||
#include "aom/aom_codec.h"
|
||||
#include "av1/decoder/decoder.h"
|
||||
|
||||
typedef struct {
|
||||
size_t size; // Size (1 or 2 bytes) of the OBU header (including the
|
||||
// optional OBU extension header) in the bitstream.
|
||||
OBU_TYPE type;
|
||||
int has_size_field;
|
||||
int has_extension;
|
||||
// The following fields come from the OBU extension header and therefore are
|
||||
// only used if has_extension is true.
|
||||
int temporal_layer_id;
|
||||
int spatial_layer_id;
|
||||
} ObuHeader;
|
||||
|
||||
aom_codec_err_t aom_read_obu_header(uint8_t *buffer, size_t buffer_length,
|
||||
size_t *consumed, ObuHeader *header,
|
||||
int is_annexb);
|
||||
|
||||
aom_codec_err_t aom_read_obu_header_and_size(const uint8_t *data,
|
||||
size_t bytes_available,
|
||||
int is_annexb,
|
||||
ObuHeader *obu_header,
|
||||
size_t *const payload_size,
|
||||
size_t *const bytes_read);
|
||||
|
||||
// Try to decode one frame from a buffer.
|
||||
// Returns 1 if we decoded a frame,
|
||||
// 0 if we didn't decode a frame but that's okay
|
||||
// (eg, if there was a frame but we skipped it),
|
||||
// or -1 on error
|
||||
int aom_decode_frame_from_obus(struct AV1Decoder *pbi, const uint8_t *data,
|
||||
const uint8_t *data_end,
|
||||
const uint8_t **p_data_end);
|
||||
|
||||
aom_codec_err_t aom_get_num_layers_from_operating_point_idc(
|
||||
int operating_point_idc, unsigned int *num_spatial_layers,
|
||||
unsigned int *num_temporal_layers);
|
||||
|
||||
#endif
|
||||
378
third_party/aom/av1/decoder/pvq_decoder.c
vendored
378
third_party/aom/av1/decoder/pvq_decoder.c
vendored
|
|
@ -1,378 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "./aom_config.h"
|
||||
#include "aom_dsp/bitreader.h"
|
||||
#include "aom_dsp/entcode.h"
|
||||
#include "aom_dsp/entdec.h"
|
||||
#include "av1/common/odintrin.h"
|
||||
#include "av1/common/partition.h"
|
||||
#include "av1/common/pvq_state.h"
|
||||
#include "av1/decoder/decint.h"
|
||||
#include "av1/decoder/pvq_decoder.h"
|
||||
#include "aom_ports/system_state.h"
|
||||
|
||||
int aom_read_symbol_pvq_(aom_reader *r, aom_cdf_prob *cdf, int nsymbs
|
||||
ACCT_STR_PARAM) {
|
||||
if (cdf[0] == 0)
|
||||
aom_cdf_init_q15_1D(cdf, nsymbs, CDF_SIZE(nsymbs));
|
||||
return aom_read_symbol(r, cdf, nsymbs, ACCT_STR_NAME);
|
||||
}
|
||||
|
||||
static void aom_decode_pvq_codeword(aom_reader *r, od_pvq_codeword_ctx *ctx,
|
||||
od_coeff *y, int n, int k) {
|
||||
int i;
|
||||
aom_decode_band_pvq_splits(r, ctx, y, n, k, 0);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (y[i] && aom_read_bit(r, "pvq:sign")) y[i] = -y[i];
|
||||
}
|
||||
}
|
||||
|
||||
/** Inverse of neg_interleave; decodes the interleaved gain.
|
||||
*
|
||||
* @param [in] x quantized/interleaved gain to decode
|
||||
* @param [in] ref quantized gain of the reference
|
||||
* @return original quantized gain value
|
||||
*/
|
||||
static int neg_deinterleave(int x, int ref) {
|
||||
if (x < 2*ref-1) {
|
||||
if (x & 1) return ref - 1 - (x >> 1);
|
||||
else return ref + (x >> 1);
|
||||
}
|
||||
else return x+1;
|
||||
}
|
||||
|
||||
/** Synthesizes one parition of coefficient values from a PVQ-encoded
|
||||
* vector.
|
||||
*
|
||||
* @param [out] xcoeff output coefficient partition (x in math doc)
|
||||
* @param [in] ypulse PVQ-encoded values (y in math doc); in the noref
|
||||
* case, this vector has n entries, in the
|
||||
* reference case it contains n-1 entries
|
||||
* (the m-th entry is not included)
|
||||
* @param [in] ref reference vector (prediction)
|
||||
* @param [in] n number of elements in this partition
|
||||
* @param [in] gr gain of the reference vector (prediction)
|
||||
* @param [in] noref indicates presence or lack of prediction
|
||||
* @param [in] g decoded quantized vector gain
|
||||
* @param [in] theta decoded theta (prediction error)
|
||||
* @param [in] qm QM with magnitude compensation
|
||||
* @param [in] qm_inv Inverse of QM with magnitude compensation
|
||||
*/
|
||||
static void pvq_synthesis(od_coeff *xcoeff, od_coeff *ypulse, od_val16 *r16,
|
||||
int n, od_val32 gr, int noref, od_val32 g, od_val32 theta, const int16_t *qm_inv,
|
||||
int shift) {
|
||||
int s;
|
||||
int m;
|
||||
/* Sign of the Householder reflection vector */
|
||||
s = 0;
|
||||
/* Direction of the Householder reflection vector */
|
||||
m = noref ? 0 : od_compute_householder(r16, n, gr, &s, shift);
|
||||
od_pvq_synthesis_partial(xcoeff, ypulse, r16, n, noref, g, theta, m, s,
|
||||
qm_inv);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
od_coeff *ref;
|
||||
int nb_coeffs;
|
||||
int allow_flip;
|
||||
} cfl_ctx;
|
||||
|
||||
/** Decodes a single vector of integers (eg, a partition within a
|
||||
* coefficient block) encoded using PVQ
|
||||
*
|
||||
* @param [in,out] ec range encoder
|
||||
* @param [in] q0 scale/quantizer
|
||||
* @param [in] n number of coefficients in partition
|
||||
* @param [in,out] model entropy decoder state
|
||||
* @param [in,out] adapt adaptation context
|
||||
* @param [in,out] exg ExQ16 expectation of decoded gain value
|
||||
* @param [in,out] ext ExQ16 expectation of decoded theta value
|
||||
* @param [in] ref 'reference' (prediction) vector
|
||||
* @param [out] out decoded partition
|
||||
* @param [out] noref boolean indicating absence of reference
|
||||
* @param [in] beta per-band activity masking beta param
|
||||
* @param [in] is_keyframe whether we're encoding a keyframe
|
||||
* @param [in] pli plane index
|
||||
* @param [in] cdf_ctx selects which cdf context to use
|
||||
* @param [in,out] skip_rest whether to skip further bands in each direction
|
||||
* @param [in] band index of the band being decoded
|
||||
* @param [in] band index of the band being decoded
|
||||
* @param [out] skip skip flag with range [0,1]
|
||||
* @param [in] qm QM with magnitude compensation
|
||||
* @param [in] qm_inv Inverse of QM with magnitude compensation
|
||||
*/
|
||||
static void pvq_decode_partition(aom_reader *r,
|
||||
int q0,
|
||||
int n,
|
||||
generic_encoder model[3],
|
||||
od_adapt_ctx *adapt,
|
||||
int *exg,
|
||||
int *ext,
|
||||
od_coeff *ref,
|
||||
od_coeff *out,
|
||||
int *noref,
|
||||
od_val16 beta,
|
||||
int is_keyframe,
|
||||
int pli,
|
||||
int cdf_ctx,
|
||||
cfl_ctx *cfl,
|
||||
int has_skip,
|
||||
int *skip_rest,
|
||||
int band,
|
||||
int *skip,
|
||||
const int16_t *qm,
|
||||
const int16_t *qm_inv) {
|
||||
int k;
|
||||
od_val32 qcg;
|
||||
int itheta;
|
||||
od_val32 theta;
|
||||
od_val32 gr;
|
||||
od_val32 gain_offset;
|
||||
od_coeff y[MAXN];
|
||||
int qg;
|
||||
int id;
|
||||
int i;
|
||||
od_val16 ref16[MAXN];
|
||||
int rshift;
|
||||
theta = 0;
|
||||
gr = 0;
|
||||
gain_offset = 0;
|
||||
/* Skip is per-direction. For band=0, we can use any of the flags. */
|
||||
if (skip_rest[(band + 2) % 3]) {
|
||||
qg = 0;
|
||||
if (is_keyframe) {
|
||||
itheta = -1;
|
||||
*noref = 1;
|
||||
}
|
||||
else {
|
||||
itheta = 0;
|
||||
*noref = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Jointly decode gain, itheta and noref for small values. Then we handle
|
||||
larger gain. */
|
||||
id = aom_read_symbol_pvq(r, &adapt->pvq.pvq_gaintheta_cdf[cdf_ctx][0],
|
||||
8 + 7*has_skip, "pvq:gaintheta");
|
||||
if (!is_keyframe && id >= 10) id++;
|
||||
if (is_keyframe && id >= 8) id++;
|
||||
if (id >= 8) {
|
||||
id -= 8;
|
||||
skip_rest[0] = skip_rest[1] = skip_rest[2] = 1;
|
||||
}
|
||||
qg = id & 1;
|
||||
itheta = (id >> 1) - 1;
|
||||
*noref = (itheta == -1);
|
||||
}
|
||||
/* The CfL flip bit is only decoded on the first band that has noref=0. */
|
||||
if (cfl->allow_flip && !*noref) {
|
||||
int flip;
|
||||
flip = aom_read_bit(r, "cfl:flip");
|
||||
if (flip) {
|
||||
for (i = 0; i < cfl->nb_coeffs; i++) cfl->ref[i] = -cfl->ref[i];
|
||||
}
|
||||
cfl->allow_flip = 0;
|
||||
}
|
||||
if (qg > 0) {
|
||||
int tmp;
|
||||
tmp = *exg;
|
||||
qg = 1 + generic_decode(r, &model[!*noref], &tmp, 2, "pvq:gain");
|
||||
OD_IIR_DIADIC(*exg, qg << 16, 2);
|
||||
}
|
||||
*skip = 0;
|
||||
#if defined(OD_FLOAT_PVQ)
|
||||
rshift = 0;
|
||||
#else
|
||||
/* Shift needed to make the reference fit in 15 bits, so that the Householder
|
||||
vector can fit in 16 bits. */
|
||||
rshift = OD_MAXI(0, od_vector_log_mag(ref, n) - 14);
|
||||
#endif
|
||||
for (i = 0; i < n; i++) {
|
||||
#if defined(OD_FLOAT_PVQ)
|
||||
ref16[i] = ref[i]*(double)qm[i]*OD_QM_SCALE_1;
|
||||
#else
|
||||
ref16[i] = OD_SHR_ROUND(ref[i]*qm[i], OD_QM_SHIFT + rshift);
|
||||
#endif
|
||||
}
|
||||
if(!*noref){
|
||||
/* we have a reference; compute its gain */
|
||||
od_val32 cgr;
|
||||
int icgr;
|
||||
int cfl_enabled;
|
||||
cfl_enabled = pli != 0 && is_keyframe && !OD_DISABLE_CFL;
|
||||
cgr = od_pvq_compute_gain(ref16, n, q0, &gr, beta, rshift);
|
||||
if (cfl_enabled) cgr = OD_CGAIN_SCALE;
|
||||
#if defined(OD_FLOAT_PVQ)
|
||||
icgr = (int)floor(.5 + cgr);
|
||||
#else
|
||||
icgr = OD_SHR_ROUND(cgr, OD_CGAIN_SHIFT);
|
||||
#endif
|
||||
/* quantized gain is interleave encoded when there's a reference;
|
||||
deinterleave it now */
|
||||
if (is_keyframe) qg = neg_deinterleave(qg, icgr);
|
||||
else {
|
||||
qg = neg_deinterleave(qg, icgr + 1) - 1;
|
||||
if (qg == 0) *skip = (icgr ? OD_PVQ_SKIP_ZERO : OD_PVQ_SKIP_COPY);
|
||||
}
|
||||
if (qg == icgr && itheta == 0 && !cfl_enabled) *skip = OD_PVQ_SKIP_COPY;
|
||||
gain_offset = cgr - OD_SHL(icgr, OD_CGAIN_SHIFT);
|
||||
qcg = OD_SHL(qg, OD_CGAIN_SHIFT) + gain_offset;
|
||||
/* read and decode first-stage PVQ error theta */
|
||||
if (itheta > 1) {
|
||||
int tmp;
|
||||
tmp = *ext;
|
||||
itheta = 2 + generic_decode(r, &model[2], &tmp, 2, "pvq:theta");
|
||||
OD_IIR_DIADIC(*ext, itheta << 16, 2);
|
||||
}
|
||||
theta = od_pvq_compute_theta(itheta, od_pvq_compute_max_theta(qcg, beta));
|
||||
}
|
||||
else{
|
||||
itheta = 0;
|
||||
if (!is_keyframe) qg++;
|
||||
qcg = OD_SHL(qg, OD_CGAIN_SHIFT);
|
||||
if (qg == 0) *skip = OD_PVQ_SKIP_ZERO;
|
||||
}
|
||||
|
||||
k = od_pvq_compute_k(qcg, itheta, *noref, n, beta);
|
||||
if (k != 0) {
|
||||
/* when noref==0, y is actually size n-1 */
|
||||
aom_decode_pvq_codeword(r, &adapt->pvq.pvq_codeword_ctx, y,
|
||||
n - !*noref, k);
|
||||
}
|
||||
else {
|
||||
OD_CLEAR(y, n);
|
||||
}
|
||||
if (*skip) {
|
||||
if (*skip == OD_PVQ_SKIP_COPY) OD_COPY(out, ref, n);
|
||||
else OD_CLEAR(out, n);
|
||||
}
|
||||
else {
|
||||
od_val32 g;
|
||||
g = od_gain_expand(qcg, q0, beta);
|
||||
pvq_synthesis(out, y, ref16, n, gr, *noref, g, theta, qm_inv, rshift);
|
||||
}
|
||||
/* If OD_PVQ_SKIP_ZERO or OD_PVQ_SKIP_COPY, set skip to 1 for visualization */
|
||||
if (*skip) *skip = 1;
|
||||
}
|
||||
|
||||
/** Decodes a coefficient block (except for DC) encoded using PVQ
|
||||
*
|
||||
* @param [in,out] dec daala decoder context
|
||||
* @param [in] ref 'reference' (prediction) vector
|
||||
* @param [out] out decoded partition
|
||||
* @param [in] q0 quantizer
|
||||
* @param [in] pli plane index
|
||||
* @param [in] bs log of the block size minus two
|
||||
* @param [in] beta per-band activity masking beta param
|
||||
* @param [in] is_keyframe whether we're encoding a keyframe
|
||||
* @param [out] flags bitmask of the per band skip and noref flags
|
||||
* @param [in] ac_dc_coded skip flag for the block (range 0-3)
|
||||
* @param [in] qm QM with magnitude compensation
|
||||
* @param [in] qm_inv Inverse of QM with magnitude compensation
|
||||
*/
|
||||
void od_pvq_decode(daala_dec_ctx *dec,
|
||||
od_coeff *ref,
|
||||
od_coeff *out,
|
||||
int q0,
|
||||
int pli,
|
||||
int bs,
|
||||
const od_val16 *beta,
|
||||
int is_keyframe,
|
||||
unsigned int *flags,
|
||||
PVQ_SKIP_TYPE ac_dc_coded,
|
||||
const int16_t *qm,
|
||||
const int16_t *qm_inv){
|
||||
|
||||
int noref[PVQ_MAX_PARTITIONS];
|
||||
int skip[PVQ_MAX_PARTITIONS];
|
||||
int *exg;
|
||||
int *ext;
|
||||
int nb_bands;
|
||||
int i;
|
||||
const int *off;
|
||||
int size[PVQ_MAX_PARTITIONS];
|
||||
generic_encoder *model;
|
||||
int skip_rest[3] = {0};
|
||||
cfl_ctx cfl;
|
||||
const unsigned char *pvq_qm;
|
||||
int use_masking;
|
||||
|
||||
aom_clear_system_state();
|
||||
|
||||
/*Default to skip=1 and noref=0 for all bands.*/
|
||||
for (i = 0; i < PVQ_MAX_PARTITIONS; i++) {
|
||||
noref[i] = 0;
|
||||
skip[i] = 1;
|
||||
}
|
||||
|
||||
use_masking = dec->use_activity_masking;
|
||||
|
||||
if (use_masking)
|
||||
pvq_qm = &dec->state.pvq_qm_q4[pli][0];
|
||||
else
|
||||
pvq_qm = 0;
|
||||
|
||||
exg = &dec->state.adapt->pvq.pvq_exg[pli][bs][0];
|
||||
ext = dec->state.adapt->pvq.pvq_ext + bs*PVQ_MAX_PARTITIONS;
|
||||
model = dec->state.adapt->pvq.pvq_param_model;
|
||||
nb_bands = OD_BAND_OFFSETS[bs][0];
|
||||
off = &OD_BAND_OFFSETS[bs][1];
|
||||
out[0] = ac_dc_coded & DC_CODED;
|
||||
if (ac_dc_coded < AC_CODED) {
|
||||
if (is_keyframe) for (i = 1; i < 1 << (2*bs + 4); i++) out[i] = 0;
|
||||
else for (i = 1; i < 1 << (2*bs + 4); i++) out[i] = ref[i];
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < nb_bands; i++) size[i] = off[i+1] - off[i];
|
||||
cfl.ref = ref;
|
||||
cfl.nb_coeffs = off[nb_bands];
|
||||
cfl.allow_flip = pli != 0 && is_keyframe;
|
||||
for (i = 0; i < nb_bands; i++) {
|
||||
int q;
|
||||
|
||||
if (use_masking)
|
||||
q = OD_MAXI(1, q0 * pvq_qm[od_qm_get_index(bs, i + 1)] >> 4);
|
||||
else
|
||||
q = OD_MAXI(1, q0);
|
||||
|
||||
pvq_decode_partition(dec->r, q, size[i],
|
||||
model, dec->state.adapt, exg + i, ext + i, ref + off[i], out + off[i],
|
||||
&noref[i], beta[i], is_keyframe, pli,
|
||||
(pli != 0)*OD_TXSIZES*PVQ_MAX_PARTITIONS + bs*PVQ_MAX_PARTITIONS + i,
|
||||
&cfl, i == 0 && (i < nb_bands - 1), skip_rest, i, &skip[i],
|
||||
qm + off[i], qm_inv + off[i]);
|
||||
if (i == 0 && !skip_rest[0] && bs > 0) {
|
||||
int skip_dir;
|
||||
int j;
|
||||
skip_dir = aom_read_symbol(dec->r,
|
||||
&dec->state.adapt->pvq.pvq_skip_dir_cdf[(pli != 0) + 2*(bs - 1)][0], 7,
|
||||
"pvq:skiprest");
|
||||
for (j = 0; j < 3; j++) skip_rest[j] = !!(skip_dir & (1 << j));
|
||||
}
|
||||
}
|
||||
}
|
||||
*flags = 0;
|
||||
for (i = nb_bands - 1; i >= 0; i--) {
|
||||
*flags <<= 1;
|
||||
*flags |= noref[i]&1;
|
||||
*flags <<= 1;
|
||||
*flags |= skip[i]&1;
|
||||
}
|
||||
}
|
||||
40
third_party/aom/av1/decoder/pvq_decoder.h
vendored
40
third_party/aom/av1/decoder/pvq_decoder.h
vendored
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
#if !defined(_pvq_decoder_H)
|
||||
# define _pvq_decoder_H (1)
|
||||
# include "aom_dsp/bitreader.h"
|
||||
# include "aom_dsp/entdec.h"
|
||||
# include "av1/common/pvq.h"
|
||||
# include "av1/decoder/decint.h"
|
||||
|
||||
#define aom_read_symbol_pvq(r, cdf, nsymbs, ACCT_STR_NAME) \
|
||||
aom_read_symbol_pvq_(r, cdf, nsymbs ACCT_STR_ARG(ACCT_STR_NAME))
|
||||
|
||||
int aom_read_symbol_pvq_(aom_reader *r, aom_cdf_prob *cdf, int nsymbs
|
||||
ACCT_STR_PARAM);
|
||||
|
||||
void aom_decode_band_pvq_splits(aom_reader *r, od_pvq_codeword_ctx *adapt,
|
||||
od_coeff *y, int n, int k, int level);
|
||||
|
||||
#define aom_laplace_decode_special(r, decay, ACCT_STR_NAME) \
|
||||
aom_laplace_decode_special_(r, decay ACCT_STR_ARG(ACCT_STR_NAME))
|
||||
|
||||
int aom_laplace_decode_special_(aom_reader *r, unsigned decay ACCT_STR_PARAM);
|
||||
|
||||
void od_pvq_decode(daala_dec_ctx *dec, od_coeff *ref, od_coeff *out, int q0,
|
||||
int pli, int bs, const od_val16 *beta, int is_keyframe,
|
||||
unsigned int *flags, PVQ_SKIP_TYPE ac_dc_coded, const int16_t *qm,
|
||||
const int16_t *qm_inv);
|
||||
|
||||
#endif
|
||||
88
third_party/aom/av1/decoder/symbolrate.h
vendored
88
third_party/aom/av1/decoder/symbolrate.h
vendored
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Alliance for Open Media. All rights reserved
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "aom_dsp/bitreader.h"
|
||||
|
||||
#ifndef AV1_DECODER_SYMBOLRATE_H_
|
||||
#define AV1_DECODER_SYMBOLRATE_H_
|
||||
|
||||
#if CONFIG_SYMBOLRATE
|
||||
static INLINE void av1_dump_symbol_rate(struct AV1Common *cm) {
|
||||
const FRAME_COUNTS *counts = &cm->counts;
|
||||
printf("%d %d %d %d\n", counts->coeff_num[0], counts->coeff_num[1],
|
||||
counts->symbol_num[0], counts->symbol_num[1]);
|
||||
}
|
||||
static INLINE int av1_read_record_symbol(FRAME_COUNTS *counts, aom_reader *r,
|
||||
aom_cdf_prob *cdf, int nsymbs,
|
||||
const char *str) {
|
||||
(void)str;
|
||||
if (counts) ++counts->symbol_num[0];
|
||||
return aom_read_symbol(r, cdf, nsymbs, str);
|
||||
}
|
||||
|
||||
#if CONFIG_LV_MAP
|
||||
static INLINE int av1_read_record_bin(FRAME_COUNTS *counts, aom_reader *r,
|
||||
aom_cdf_prob *cdf, int nsymbs,
|
||||
const char *str) {
|
||||
(void)str;
|
||||
if (counts) ++counts->symbol_num[0];
|
||||
return aom_read_bin(r, cdf, nsymbs, str);
|
||||
}
|
||||
#endif
|
||||
|
||||
static INLINE int av1_read_record(FRAME_COUNTS *counts, aom_reader *r, int prob,
|
||||
const char *str) {
|
||||
(void)str;
|
||||
if (counts) ++counts->symbol_num[0];
|
||||
return aom_read(r, prob, str);
|
||||
}
|
||||
|
||||
static INLINE int av1_read_record_cdf(FRAME_COUNTS *counts, aom_reader *r,
|
||||
const aom_cdf_prob *cdf, int nsymbs,
|
||||
const char *str) {
|
||||
(void)str;
|
||||
if (counts) ++counts->symbol_num[0];
|
||||
return aom_read_cdf(r, cdf, nsymbs, str);
|
||||
}
|
||||
|
||||
static INLINE int av1_read_record_bit(FRAME_COUNTS *counts, aom_reader *r,
|
||||
const char *str) {
|
||||
(void)str;
|
||||
if (counts) ++counts->symbol_num[1];
|
||||
return aom_read_bit(r, str);
|
||||
}
|
||||
|
||||
static INLINE void av1_record_coeff(FRAME_COUNTS *counts, tran_low_t qcoeff) {
|
||||
assert(qcoeff >= 0);
|
||||
if (counts) ++counts->coeff_num[qcoeff != 0];
|
||||
}
|
||||
#else // CONFIG_SYMBOLRATE
|
||||
|
||||
#define av1_read_record_symbol(counts, r, cdf, nsymbs, ACCT_STR_NAME) \
|
||||
aom_read_symbol(r, cdf, nsymbs, ACCT_STR_NAME)
|
||||
|
||||
#if CONFIG_LV_MAP
|
||||
#define av1_read_record_bin(counts, r, cdf, nsymbs, ACCT_STR_NAME) \
|
||||
aom_read_bin(r, cdf, nsymbs, ACCT_STR_NAME)
|
||||
#endif
|
||||
|
||||
#define av1_read_record(counts, r, prob, ACCT_STR_NAME) \
|
||||
aom_read(r, prob, ACCT_STR_NAME)
|
||||
|
||||
#define av1_read_record_cdf(counts, r, cdf, nsymbs, ACCT_STR_NAME) \
|
||||
aom_read_cdf(r, cdf, nsymbs, ACCT_STR_NAME)
|
||||
|
||||
#define av1_read_record_bit(counts, r, ACCT_STR_NAME) \
|
||||
aom_read_bit(r, ACCT_STR_NAME)
|
||||
|
||||
#endif // CONFIG_SYMBOLRATE
|
||||
|
||||
#endif // AV1_DECODER_SYMBOLRATE_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue