vp9/decoder,vp9/*.[hc]: apply clang-format
Change-Id: Ic38ea06c7b2fb3e8e94a4c0910e82672a1acaea7
This commit is contained in:
parent
8ff40f8bec
commit
08131055e4
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,6 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef VP9_DECODER_VP9_DECODEFRAME_H_
|
||||
#define VP9_DECODER_VP9_DECODEFRAME_H_
|
||||
|
||||
@ -22,13 +21,12 @@ struct VP9Decoder;
|
||||
struct vpx_read_bit_buffer;
|
||||
|
||||
int vp9_read_sync_code(struct vpx_read_bit_buffer *const rb);
|
||||
void vp9_read_frame_size(struct vpx_read_bit_buffer *rb,
|
||||
int *width, int *height);
|
||||
void vp9_read_frame_size(struct vpx_read_bit_buffer *rb, int *width,
|
||||
int *height);
|
||||
BITSTREAM_PROFILE vp9_read_profile(struct vpx_read_bit_buffer *rb);
|
||||
|
||||
void vp9_decode_frame(struct VP9Decoder *pbi,
|
||||
const uint8_t *data, const uint8_t *data_end,
|
||||
const uint8_t **p_data_end);
|
||||
void vp9_decode_frame(struct VP9Decoder *pbi, const uint8_t *data,
|
||||
const uint8_t *data_end, const uint8_t **p_data_end);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
@ -33,29 +33,26 @@ static PREDICTION_MODE read_intra_mode_y(VP9_COMMON *cm, MACROBLOCKD *xd,
|
||||
const PREDICTION_MODE y_mode =
|
||||
read_intra_mode(r, cm->fc->y_mode_prob[size_group]);
|
||||
FRAME_COUNTS *counts = xd->counts;
|
||||
if (counts)
|
||||
++counts->y_mode[size_group][y_mode];
|
||||
if (counts) ++counts->y_mode[size_group][y_mode];
|
||||
return y_mode;
|
||||
}
|
||||
|
||||
static PREDICTION_MODE read_intra_mode_uv(VP9_COMMON *cm, MACROBLOCKD *xd,
|
||||
vpx_reader *r,
|
||||
PREDICTION_MODE y_mode) {
|
||||
const PREDICTION_MODE uv_mode = read_intra_mode(r,
|
||||
cm->fc->uv_mode_prob[y_mode]);
|
||||
const PREDICTION_MODE uv_mode =
|
||||
read_intra_mode(r, cm->fc->uv_mode_prob[y_mode]);
|
||||
FRAME_COUNTS *counts = xd->counts;
|
||||
if (counts)
|
||||
++counts->uv_mode[y_mode][uv_mode];
|
||||
if (counts) ++counts->uv_mode[y_mode][uv_mode];
|
||||
return uv_mode;
|
||||
}
|
||||
|
||||
static PREDICTION_MODE read_inter_mode(VP9_COMMON *cm, MACROBLOCKD *xd,
|
||||
vpx_reader *r, int ctx) {
|
||||
const int mode = vpx_read_tree(r, vp9_inter_mode_tree,
|
||||
cm->fc->inter_mode_probs[ctx]);
|
||||
const int mode =
|
||||
vpx_read_tree(r, vp9_inter_mode_tree, cm->fc->inter_mode_probs[ctx]);
|
||||
FRAME_COUNTS *counts = xd->counts;
|
||||
if (counts)
|
||||
++counts->inter_mode[ctx][mode];
|
||||
if (counts) ++counts->inter_mode[ctx][mode];
|
||||
|
||||
return NEARESTMV + mode;
|
||||
}
|
||||
@ -76,8 +73,7 @@ static TX_SIZE read_selected_tx_size(VP9_COMMON *cm, MACROBLOCKD *xd,
|
||||
tx_size += vpx_read(r, tx_probs[2]);
|
||||
}
|
||||
|
||||
if (counts)
|
||||
++get_tx_counts(max_tx_size, ctx, &counts->tx)[tx_size];
|
||||
if (counts) ++get_tx_counts(max_tx_size, ctx, &counts->tx)[tx_size];
|
||||
return (TX_SIZE)tx_size;
|
||||
}
|
||||
|
||||
@ -105,8 +101,8 @@ static int dec_get_segment_id(const VP9_COMMON *cm, const uint8_t *segment_ids,
|
||||
return segment_id;
|
||||
}
|
||||
|
||||
static void set_segment_id(VP9_COMMON *cm, int mi_offset,
|
||||
int x_mis, int y_mis, int segment_id) {
|
||||
static void set_segment_id(VP9_COMMON *cm, int mi_offset, int x_mis, int y_mis,
|
||||
int segment_id) {
|
||||
int x, y;
|
||||
|
||||
assert(segment_id >= 0 && segment_id < MAX_SEGMENTS);
|
||||
@ -118,24 +114,23 @@ static void set_segment_id(VP9_COMMON *cm, int mi_offset,
|
||||
|
||||
static void copy_segment_id(const VP9_COMMON *cm,
|
||||
const uint8_t *last_segment_ids,
|
||||
uint8_t *current_segment_ids,
|
||||
int mi_offset, int x_mis, int y_mis) {
|
||||
uint8_t *current_segment_ids, int mi_offset,
|
||||
int x_mis, int y_mis) {
|
||||
int x, y;
|
||||
|
||||
for (y = 0; y < y_mis; y++)
|
||||
for (x = 0; x < x_mis; x++)
|
||||
current_segment_ids[mi_offset + y * cm->mi_cols + x] = last_segment_ids ?
|
||||
last_segment_ids[mi_offset + y * cm->mi_cols + x] : 0;
|
||||
current_segment_ids[mi_offset + y * cm->mi_cols + x] =
|
||||
last_segment_ids ? last_segment_ids[mi_offset + y * cm->mi_cols + x]
|
||||
: 0;
|
||||
}
|
||||
|
||||
static int read_intra_segment_id(VP9_COMMON *const cm, int mi_offset,
|
||||
int x_mis, int y_mis,
|
||||
vpx_reader *r) {
|
||||
static int read_intra_segment_id(VP9_COMMON *const cm, int mi_offset, int x_mis,
|
||||
int y_mis, vpx_reader *r) {
|
||||
struct segmentation *const seg = &cm->seg;
|
||||
int segment_id;
|
||||
|
||||
if (!seg->enabled)
|
||||
return 0; // Default for disabled segmentation
|
||||
if (!seg->enabled) return 0; // Default for disabled segmentation
|
||||
|
||||
if (!seg->update_map) {
|
||||
copy_segment_id(cm, cm->last_frame_seg_map, cm->current_frame_seg_map,
|
||||
@ -156,12 +151,12 @@ static int read_inter_segment_id(VP9_COMMON *const cm, MACROBLOCKD *const xd,
|
||||
int predicted_segment_id, segment_id;
|
||||
const int mi_offset = mi_row * cm->mi_cols + mi_col;
|
||||
|
||||
if (!seg->enabled)
|
||||
return 0; // Default for disabled segmentation
|
||||
if (!seg->enabled) return 0; // Default for disabled segmentation
|
||||
|
||||
predicted_segment_id = cm->last_frame_seg_map ?
|
||||
dec_get_segment_id(cm, cm->last_frame_seg_map, mi_offset, x_mis, y_mis) :
|
||||
0;
|
||||
predicted_segment_id = cm->last_frame_seg_map
|
||||
? dec_get_segment_id(cm, cm->last_frame_seg_map,
|
||||
mi_offset, x_mis, y_mis)
|
||||
: 0;
|
||||
|
||||
if (!seg->update_map) {
|
||||
copy_segment_id(cm, cm->last_frame_seg_map, cm->current_frame_seg_map,
|
||||
@ -172,8 +167,8 @@ static int read_inter_segment_id(VP9_COMMON *const cm, MACROBLOCKD *const xd,
|
||||
if (seg->temporal_update) {
|
||||
const vpx_prob pred_prob = vp9_get_pred_prob_seg_id(seg, xd);
|
||||
mi->seg_id_predicted = vpx_read(r, pred_prob);
|
||||
segment_id = mi->seg_id_predicted ? predicted_segment_id
|
||||
: read_segment_id(r, seg);
|
||||
segment_id =
|
||||
mi->seg_id_predicted ? predicted_segment_id : read_segment_id(r, seg);
|
||||
} else {
|
||||
segment_id = read_segment_id(r, seg);
|
||||
}
|
||||
@ -181,24 +176,23 @@ static int read_inter_segment_id(VP9_COMMON *const cm, MACROBLOCKD *const xd,
|
||||
return segment_id;
|
||||
}
|
||||
|
||||
static int read_skip(VP9_COMMON *cm, const MACROBLOCKD *xd,
|
||||
int segment_id, vpx_reader *r) {
|
||||
static int read_skip(VP9_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
|
||||
vpx_reader *r) {
|
||||
if (segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)) {
|
||||
return 1;
|
||||
} else {
|
||||
const int ctx = vp9_get_skip_context(xd);
|
||||
const int skip = vpx_read(r, cm->fc->skip_probs[ctx]);
|
||||
FRAME_COUNTS *counts = xd->counts;
|
||||
if (counts)
|
||||
++counts->skip[ctx][skip];
|
||||
if (counts) ++counts->skip[ctx][skip];
|
||||
return skip;
|
||||
}
|
||||
}
|
||||
|
||||
static void read_intra_frame_mode_info(VP9_COMMON *const cm,
|
||||
MACROBLOCKD *const xd,
|
||||
int mi_row, int mi_col, vpx_reader *r,
|
||||
int x_mis, int y_mis) {
|
||||
MACROBLOCKD *const xd, int mi_row,
|
||||
int mi_col, vpx_reader *r, int x_mis,
|
||||
int y_mis) {
|
||||
MODE_INFO *const mi = xd->mi[0];
|
||||
const MODE_INFO *above_mi = xd->above_mi;
|
||||
const MODE_INFO *left_mi = xd->left_mi;
|
||||
@ -232,15 +226,14 @@ static void read_intra_frame_mode_info(VP9_COMMON *const cm,
|
||||
read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, 2));
|
||||
break;
|
||||
default:
|
||||
mi->mode = read_intra_mode(r,
|
||||
get_y_mode_probs(mi, above_mi, left_mi, 0));
|
||||
mi->mode = read_intra_mode(r, get_y_mode_probs(mi, above_mi, left_mi, 0));
|
||||
}
|
||||
|
||||
mi->uv_mode = read_intra_mode(r, vp9_kf_uv_mode_prob[mi->mode]);
|
||||
}
|
||||
|
||||
static int read_mv_component(vpx_reader *r,
|
||||
const nmv_component *mvcomp, int usehp) {
|
||||
static int read_mv_component(vpx_reader *r, const nmv_component *mvcomp,
|
||||
int usehp) {
|
||||
int mag, d, fr, hp;
|
||||
const int sign = vpx_read(r, mvcomp->sign);
|
||||
const int mv_class = vpx_read_tree(r, vp9_mv_class_tree, mvcomp->classes);
|
||||
@ -255,18 +248,16 @@ static int read_mv_component(vpx_reader *r,
|
||||
const int n = mv_class + CLASS0_BITS - 1; // number of bits
|
||||
|
||||
d = 0;
|
||||
for (i = 0; i < n; ++i)
|
||||
d |= vpx_read(r, mvcomp->bits[i]) << i;
|
||||
for (i = 0; i < n; ++i) d |= vpx_read(r, mvcomp->bits[i]) << i;
|
||||
mag = CLASS0_SIZE << (mv_class + 2);
|
||||
}
|
||||
|
||||
// Fractional part
|
||||
fr = vpx_read_tree(r, vp9_mv_fp_tree, class0 ? mvcomp->class0_fp[d]
|
||||
: mvcomp->fp);
|
||||
fr = vpx_read_tree(r, vp9_mv_fp_tree,
|
||||
class0 ? mvcomp->class0_fp[d] : mvcomp->fp);
|
||||
|
||||
// High precision part (if hp is not used, the default value of the hp is 1)
|
||||
hp = usehp ? vpx_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp)
|
||||
: 1;
|
||||
hp = usehp ? vpx_read(r, class0 ? mvcomp->class0_hp : mvcomp->hp) : 1;
|
||||
|
||||
// Result
|
||||
mag += ((d << 3) | (fr << 1) | hp) + 1;
|
||||
@ -274,8 +265,8 @@ static int read_mv_component(vpx_reader *r,
|
||||
}
|
||||
|
||||
static INLINE void read_mv(vpx_reader *r, MV *mv, const MV *ref,
|
||||
const nmv_context *ctx,
|
||||
nmv_context_counts *counts, int allow_hp) {
|
||||
const nmv_context *ctx, nmv_context_counts *counts,
|
||||
int allow_hp) {
|
||||
const MV_JOINT_TYPE joint_type =
|
||||
(MV_JOINT_TYPE)vpx_read_tree(r, vp9_mv_joint_tree, ctx->joints);
|
||||
const int use_hp = allow_hp && use_mv_hp(ref);
|
||||
@ -301,8 +292,7 @@ static REFERENCE_MODE read_block_reference_mode(VP9_COMMON *cm,
|
||||
const REFERENCE_MODE mode =
|
||||
(REFERENCE_MODE)vpx_read(r, cm->fc->comp_inter_prob[ctx]);
|
||||
FRAME_COUNTS *counts = xd->counts;
|
||||
if (counts)
|
||||
++counts->comp_inter[ctx][mode];
|
||||
if (counts) ++counts->comp_inter[ctx][mode];
|
||||
return mode; // SINGLE_REFERENCE or COMPOUND_REFERENCE
|
||||
} else {
|
||||
return cm->reference_mode;
|
||||
@ -311,8 +301,8 @@ static REFERENCE_MODE read_block_reference_mode(VP9_COMMON *cm,
|
||||
|
||||
// Read the referncence frame
|
||||
static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd,
|
||||
vpx_reader *r,
|
||||
int segment_id, MV_REFERENCE_FRAME ref_frame[2]) {
|
||||
vpx_reader *r, int segment_id,
|
||||
MV_REFERENCE_FRAME ref_frame[2]) {
|
||||
FRAME_CONTEXT *const fc = cm->fc;
|
||||
FRAME_COUNTS *counts = xd->counts;
|
||||
|
||||
@ -327,20 +317,17 @@ static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd,
|
||||
const int idx = cm->ref_frame_sign_bias[cm->comp_fixed_ref];
|
||||
const int ctx = vp9_get_pred_context_comp_ref_p(cm, xd);
|
||||
const int bit = vpx_read(r, fc->comp_ref_prob[ctx]);
|
||||
if (counts)
|
||||
++counts->comp_ref[ctx][bit];
|
||||
if (counts) ++counts->comp_ref[ctx][bit];
|
||||
ref_frame[idx] = cm->comp_fixed_ref;
|
||||
ref_frame[!idx] = cm->comp_var_ref[bit];
|
||||
} else if (mode == SINGLE_REFERENCE) {
|
||||
const int ctx0 = vp9_get_pred_context_single_ref_p1(xd);
|
||||
const int bit0 = vpx_read(r, fc->single_ref_prob[ctx0][0]);
|
||||
if (counts)
|
||||
++counts->single_ref[ctx0][0][bit0];
|
||||
if (counts) ++counts->single_ref[ctx0][0][bit0];
|
||||
if (bit0) {
|
||||
const int ctx1 = vp9_get_pred_context_single_ref_p2(xd);
|
||||
const int bit1 = vpx_read(r, fc->single_ref_prob[ctx1][1]);
|
||||
if (counts)
|
||||
++counts->single_ref[ctx1][1][bit1];
|
||||
if (counts) ++counts->single_ref[ctx1][1][bit1];
|
||||
ref_frame[0] = bit1 ? ALTREF_FRAME : GOLDEN_FRAME;
|
||||
} else {
|
||||
ref_frame[0] = LAST_FRAME;
|
||||
@ -353,16 +340,14 @@ static void read_ref_frames(VP9_COMMON *const cm, MACROBLOCKD *const xd,
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE INTERP_FILTER read_switchable_interp_filter(
|
||||
VP9_COMMON *const cm, MACROBLOCKD *const xd,
|
||||
static INLINE INTERP_FILTER read_switchable_interp_filter(VP9_COMMON *const cm,
|
||||
MACROBLOCKD *const xd,
|
||||
vpx_reader *r) {
|
||||
const int ctx = get_pred_context_switchable_interp(xd);
|
||||
const INTERP_FILTER type =
|
||||
(INTERP_FILTER)vpx_read_tree(r, vp9_switchable_interp_tree,
|
||||
cm->fc->switchable_interp_prob[ctx]);
|
||||
const INTERP_FILTER type = (INTERP_FILTER)vpx_read_tree(
|
||||
r, vp9_switchable_interp_tree, cm->fc->switchable_interp_prob[ctx]);
|
||||
FRAME_COUNTS *counts = xd->counts;
|
||||
if (counts)
|
||||
++counts->switchable_interp[ctx][type];
|
||||
if (counts) ++counts->switchable_interp[ctx][type];
|
||||
return type;
|
||||
}
|
||||
|
||||
@ -379,19 +364,16 @@ static void read_intra_block_mode_info(VP9_COMMON *const cm,
|
||||
mi->mode = mi->bmi[3].as_mode;
|
||||
break;
|
||||
case BLOCK_4X8:
|
||||
mi->bmi[0].as_mode = mi->bmi[2].as_mode = read_intra_mode_y(cm, xd,
|
||||
r, 0);
|
||||
mi->bmi[0].as_mode = mi->bmi[2].as_mode = read_intra_mode_y(cm, xd, r, 0);
|
||||
mi->bmi[1].as_mode = mi->bmi[3].as_mode = mi->mode =
|
||||
read_intra_mode_y(cm, xd, r, 0);
|
||||
break;
|
||||
case BLOCK_8X4:
|
||||
mi->bmi[0].as_mode = mi->bmi[1].as_mode = read_intra_mode_y(cm, xd,
|
||||
r, 0);
|
||||
mi->bmi[0].as_mode = mi->bmi[1].as_mode = read_intra_mode_y(cm, xd, r, 0);
|
||||
mi->bmi[2].as_mode = mi->bmi[3].as_mode = mi->mode =
|
||||
read_intra_mode_y(cm, xd, r, 0);
|
||||
break;
|
||||
default:
|
||||
mi->mode = read_intra_mode_y(cm, xd, r, size_group_lookup[bsize]);
|
||||
default: mi->mode = read_intra_mode_y(cm, xd, r, size_group_lookup[bsize]);
|
||||
}
|
||||
|
||||
mi->uv_mode = read_intra_mode_uv(cm, xd, r, mi->mode);
|
||||
@ -405,8 +387,8 @@ static void read_intra_block_mode_info(VP9_COMMON *const cm,
|
||||
}
|
||||
|
||||
static INLINE int is_mv_valid(const MV *mv) {
|
||||
return mv->row > MV_LOW && mv->row < MV_UPP &&
|
||||
mv->col > MV_LOW && mv->col < MV_UPP;
|
||||
return mv->row > MV_LOW && mv->row < MV_UPP && mv->col > MV_LOW &&
|
||||
mv->col < MV_UPP;
|
||||
}
|
||||
|
||||
static INLINE void copy_mv_pair(int_mv *dst, const int_mv *src) {
|
||||
@ -418,9 +400,8 @@ static INLINE void zero_mv_pair(int_mv *dst) {
|
||||
}
|
||||
|
||||
static INLINE int assign_mv(VP9_COMMON *cm, MACROBLOCKD *xd,
|
||||
PREDICTION_MODE mode,
|
||||
int_mv mv[2], int_mv ref_mv[2],
|
||||
int_mv near_nearest_mv[2],
|
||||
PREDICTION_MODE mode, int_mv mv[2],
|
||||
int_mv ref_mv[2], int_mv near_nearest_mv[2],
|
||||
int is_compound, int allow_hp, vpx_reader *r) {
|
||||
int i;
|
||||
int ret = 1;
|
||||
@ -445,9 +426,7 @@ static INLINE int assign_mv(VP9_COMMON *cm, MACROBLOCKD *xd,
|
||||
zero_mv_pair(mv);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return 0;
|
||||
}
|
||||
default: { return 0; }
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -460,8 +439,7 @@ static int read_is_inter_block(VP9_COMMON *const cm, MACROBLOCKD *const xd,
|
||||
const int ctx = get_intra_inter_context(xd);
|
||||
const int is_inter = vpx_read(r, cm->fc->intra_inter_prob[ctx]);
|
||||
FRAME_COUNTS *counts = xd->counts;
|
||||
if (counts)
|
||||
++counts->intra_inter[ctx][is_inter];
|
||||
if (counts) ++counts->intra_inter[ctx][is_inter];
|
||||
return is_inter;
|
||||
}
|
||||
}
|
||||
@ -496,8 +474,7 @@ static void fpm_sync(void *const data, int mi_row) {
|
||||
} \
|
||||
} else { \
|
||||
(mv_ref_list)[(refmv_count)++] = (mv); \
|
||||
if (early_break) \
|
||||
goto Done; \
|
||||
if (early_break) goto Done; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@ -510,8 +487,7 @@ static void fpm_sync(void *const data, int mi_row) {
|
||||
if ((mbmi)->ref_frame[0] != ref_frame) \
|
||||
ADD_MV_REF_LIST_EB(scale_mv((mbmi), 0, ref_frame, ref_sign_bias), \
|
||||
refmv_count, mv_ref_list, Done); \
|
||||
if (has_second_ref(mbmi) && \
|
||||
(mbmi)->ref_frame[1] != ref_frame && \
|
||||
if (has_second_ref(mbmi) && (mbmi)->ref_frame[1] != ref_frame && \
|
||||
(mbmi)->mv[1].as_int != (mbmi)->mv[0].as_int) \
|
||||
ADD_MV_REF_LIST_EB(scale_mv((mbmi), 1, ref_frame, ref_sign_bias), \
|
||||
refmv_count, mv_ref_list, Done); \
|
||||
@ -523,14 +499,16 @@ static void fpm_sync(void *const data, int mi_row) {
|
||||
static int dec_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd,
|
||||
PREDICTION_MODE mode, MV_REFERENCE_FRAME ref_frame,
|
||||
const POSITION *const mv_ref_search,
|
||||
int_mv *mv_ref_list,
|
||||
int mi_row, int mi_col, int block, int is_sub8x8,
|
||||
find_mv_refs_sync sync, void *const data) {
|
||||
int_mv *mv_ref_list, int mi_row, int mi_col,
|
||||
int block, int is_sub8x8, find_mv_refs_sync sync,
|
||||
void *const data) {
|
||||
const int *ref_sign_bias = cm->ref_frame_sign_bias;
|
||||
int i, refmv_count = 0;
|
||||
int different_ref_found = 0;
|
||||
const MV_REF *const prev_frame_mvs = cm->use_prev_frame_mvs ?
|
||||
cm->prev_frame->mvs + mi_row * cm->mi_cols + mi_col : NULL;
|
||||
const MV_REF *const prev_frame_mvs =
|
||||
cm->use_prev_frame_mvs
|
||||
? cm->prev_frame->mvs + mi_row * cm->mi_cols + mi_col
|
||||
: NULL;
|
||||
const TileInfo *const tile = &xd->tile;
|
||||
// If mode is nearestmv or newmv (uses nearestmv as a reference) then stop
|
||||
// searching after the first mv is found.
|
||||
@ -654,8 +632,7 @@ static int dec_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd,
|
||||
|
||||
Done:
|
||||
// Clamp vectors
|
||||
for (i = 0; i < refmv_count; ++i)
|
||||
clamp_mv_ref(&mv_ref_list[i].as_mv, xd);
|
||||
for (i = 0; i < refmv_count; ++i) clamp_mv_ref(&mv_ref_list[i].as_mv, xd);
|
||||
|
||||
return refmv_count;
|
||||
}
|
||||
@ -673,14 +650,12 @@ static void append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
|
||||
|
||||
assert(MAX_MV_REF_CANDIDATES == 2);
|
||||
|
||||
refmv_count = dec_find_mv_refs(cm, xd, b_mode, mi->ref_frame[ref],
|
||||
mv_ref_search, mv_list, mi_row, mi_col, block,
|
||||
1, NULL, NULL);
|
||||
refmv_count =
|
||||
dec_find_mv_refs(cm, xd, b_mode, mi->ref_frame[ref], mv_ref_search,
|
||||
mv_list, mi_row, mi_col, block, 1, NULL, NULL);
|
||||
|
||||
switch (block) {
|
||||
case 0:
|
||||
best_sub8x8->as_int = mv_list[refmv_count - 1].as_int;
|
||||
break;
|
||||
case 0: best_sub8x8->as_int = mv_list[refmv_count - 1].as_int; break;
|
||||
case 1:
|
||||
case 2:
|
||||
if (b_mode == NEARESTMV) {
|
||||
@ -711,14 +686,13 @@ static void append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(0 && "Invalid block index.");
|
||||
default: assert(0 && "Invalid block index.");
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t get_mode_context(const VP9_COMMON *cm, const MACROBLOCKD *xd,
|
||||
const POSITION *const mv_ref_search,
|
||||
int mi_row, int mi_col) {
|
||||
const POSITION *const mv_ref_search, int mi_row,
|
||||
int mi_col) {
|
||||
int i;
|
||||
int context_counter = 0;
|
||||
const TileInfo *const tile = &xd->tile;
|
||||
@ -739,8 +713,8 @@ static uint8_t get_mode_context(const VP9_COMMON *cm, const MACROBLOCKD *xd,
|
||||
|
||||
static void read_inter_block_mode_info(VP9Decoder *const pbi,
|
||||
MACROBLOCKD *const xd,
|
||||
MODE_INFO *const mi,
|
||||
int mi_row, int mi_col, vpx_reader *r) {
|
||||
MODE_INFO *const mi, int mi_row,
|
||||
int mi_col, vpx_reader *r) {
|
||||
VP9_COMMON *const cm = &pbi->common;
|
||||
const BLOCK_SIZE bsize = mi->sb_type;
|
||||
const int allow_hp = cm->allow_high_precision_mv;
|
||||
@ -776,9 +750,9 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi,
|
||||
const MV_REFERENCE_FRAME frame = mi->ref_frame[ref];
|
||||
int refmv_count;
|
||||
|
||||
refmv_count = dec_find_mv_refs(cm, xd, mi->mode, frame, mv_ref_search,
|
||||
tmp_mvs, mi_row, mi_col, -1, 0,
|
||||
fpm_sync, (void *)pbi);
|
||||
refmv_count =
|
||||
dec_find_mv_refs(cm, xd, mi->mode, frame, mv_ref_search, tmp_mvs,
|
||||
mi_row, mi_col, -1, 0, fpm_sync, (void *)pbi);
|
||||
|
||||
dec_find_best_ref_mvs(allow_hp, tmp_mvs, &best_ref_mvs[ref],
|
||||
refmv_count);
|
||||
@ -813,10 +787,8 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi,
|
||||
break;
|
||||
}
|
||||
|
||||
if (num_4x4_h == 2)
|
||||
mi->bmi[j + 2] = mi->bmi[j];
|
||||
if (num_4x4_w == 2)
|
||||
mi->bmi[j + 1] = mi->bmi[j];
|
||||
if (num_4x4_h == 2) mi->bmi[j + 2] = mi->bmi[j];
|
||||
if (num_4x4_w == 2) mi->bmi[j + 1] = mi->bmi[j];
|
||||
}
|
||||
}
|
||||
|
||||
@ -830,15 +802,15 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi,
|
||||
}
|
||||
|
||||
static void read_inter_frame_mode_info(VP9Decoder *const pbi,
|
||||
MACROBLOCKD *const xd,
|
||||
int mi_row, int mi_col, vpx_reader *r,
|
||||
int x_mis, int y_mis) {
|
||||
MACROBLOCKD *const xd, int mi_row,
|
||||
int mi_col, vpx_reader *r, int x_mis,
|
||||
int y_mis) {
|
||||
VP9_COMMON *const cm = &pbi->common;
|
||||
MODE_INFO *const mi = xd->mi[0];
|
||||
int inter_block;
|
||||
|
||||
mi->segment_id = read_inter_segment_id(cm, xd, mi_row, mi_col, r, x_mis,
|
||||
y_mis);
|
||||
mi->segment_id =
|
||||
read_inter_segment_id(cm, xd, mi_row, mi_col, r, x_mis, y_mis);
|
||||
mi->skip = read_skip(cm, xd, mi->segment_id, r);
|
||||
inter_block = read_is_inter_block(cm, xd, mi->segment_id, r);
|
||||
mi->tx_size = read_tx_size(cm, xd, !mi->skip || !inter_block, r);
|
||||
@ -854,9 +826,8 @@ static INLINE void copy_ref_frame_pair(MV_REFERENCE_FRAME *dst,
|
||||
memcpy(dst, src, sizeof(*dst) * 2);
|
||||
}
|
||||
|
||||
void vp9_read_mode_info(VP9Decoder *const pbi, MACROBLOCKD *xd,
|
||||
int mi_row, int mi_col, vpx_reader *r,
|
||||
int x_mis, int y_mis) {
|
||||
void vp9_read_mode_info(VP9Decoder *const pbi, MACROBLOCKD *xd, int mi_row,
|
||||
int mi_col, vpx_reader *r, int x_mis, int y_mis) {
|
||||
VP9_COMMON *const cm = &pbi->common;
|
||||
MODE_INFO *const mi = xd->mi[0];
|
||||
MV_REF *frame_mvs = cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col;
|
||||
|
@ -19,9 +19,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void vp9_read_mode_info(VP9Decoder *const pbi, MACROBLOCKD *xd,
|
||||
int mi_row, int mi_col, vpx_reader *r,
|
||||
int x_mis, int y_mis);
|
||||
void vp9_read_mode_info(VP9Decoder *const pbi, MACROBLOCKD *xd, int mi_row,
|
||||
int mi_col, vpx_reader *r, int x_mis, int y_mis);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
@ -57,12 +57,10 @@ static void vp9_dec_setup_mi(VP9_COMMON *cm) {
|
||||
|
||||
static int vp9_dec_alloc_mi(VP9_COMMON *cm, int mi_size) {
|
||||
cm->mip = vpx_calloc(mi_size, sizeof(*cm->mip));
|
||||
if (!cm->mip)
|
||||
return 1;
|
||||
if (!cm->mip) return 1;
|
||||
cm->mi_alloc_size = mi_size;
|
||||
cm->mi_grid_base = (MODE_INFO **)vpx_calloc(mi_size, sizeof(MODE_INFO *));
|
||||
if (!cm->mi_grid_base)
|
||||
return 1;
|
||||
if (!cm->mi_grid_base) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -77,8 +75,7 @@ VP9Decoder *vp9_decoder_create(BufferPool *const pool) {
|
||||
VP9Decoder *volatile const pbi = vpx_memalign(32, sizeof(*pbi));
|
||||
VP9_COMMON *volatile const cm = pbi ? &pbi->common : NULL;
|
||||
|
||||
if (!cm)
|
||||
return NULL;
|
||||
if (!cm) return NULL;
|
||||
|
||||
vp9_zero(*pbi);
|
||||
|
||||
@ -90,11 +87,10 @@ VP9Decoder *vp9_decoder_create(BufferPool *const pool) {
|
||||
|
||||
cm->error.setjmp = 1;
|
||||
|
||||
CHECK_MEM_ERROR(cm, cm->fc,
|
||||
(FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc)));
|
||||
CHECK_MEM_ERROR(cm, cm->frame_contexts,
|
||||
(FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS,
|
||||
sizeof(*cm->frame_contexts)));
|
||||
CHECK_MEM_ERROR(cm, cm->fc, (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc)));
|
||||
CHECK_MEM_ERROR(
|
||||
cm, cm->frame_contexts,
|
||||
(FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, sizeof(*cm->frame_contexts)));
|
||||
|
||||
pbi->need_resync = 1;
|
||||
once(initialize_dec);
|
||||
@ -126,8 +122,7 @@ VP9Decoder *vp9_decoder_create(BufferPool *const pool) {
|
||||
void vp9_decoder_remove(VP9Decoder *pbi) {
|
||||
int i;
|
||||
|
||||
if (!pbi)
|
||||
return;
|
||||
if (!pbi) return;
|
||||
|
||||
vpx_get_worker_interface()->end(&pbi->lf_worker);
|
||||
vpx_free(pbi->lf_worker.data1);
|
||||
@ -176,14 +171,12 @@ vpx_codec_err_t vp9_copy_reference_dec(VP9Decoder *pbi,
|
||||
else
|
||||
vp8_yv12_copy_frame(cfg, sd);
|
||||
} else {
|
||||
vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
|
||||
"Invalid reference frame");
|
||||
vpx_internal_error(&cm->error, VPX_CODEC_ERROR, "Invalid reference frame");
|
||||
}
|
||||
|
||||
return cm->error.error_code;
|
||||
}
|
||||
|
||||
|
||||
vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
|
||||
VP9_REFFRAME ref_frame_flag,
|
||||
YV12_BUFFER_CONFIG *sd) {
|
||||
@ -206,8 +199,7 @@ vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
|
||||
} else if (ref_frame_flag == VP9_ALT_FLAG) {
|
||||
idx = cm->ref_frame_map[2];
|
||||
} else {
|
||||
vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
|
||||
"Invalid reference frame");
|
||||
vpx_internal_error(&cm->error, VPX_CODEC_ERROR, "Invalid reference frame");
|
||||
return cm->error.error_code;
|
||||
}
|
||||
|
||||
@ -273,8 +265,8 @@ static void swap_frame_buffers(VP9Decoder *pbi) {
|
||||
cm->frame_refs[ref_index].idx = -1;
|
||||
}
|
||||
|
||||
int vp9_receive_compressed_data(VP9Decoder *pbi,
|
||||
size_t size, const uint8_t **psource) {
|
||||
int vp9_receive_compressed_data(VP9Decoder *pbi, size_t size,
|
||||
const uint8_t **psource) {
|
||||
VP9_COMMON *volatile const cm = &pbi->common;
|
||||
BufferPool *volatile const pool = cm->buffer_pool;
|
||||
RefCntBuffer *volatile const frame_bufs = cm->buffer_pool->frame_bufs;
|
||||
@ -301,8 +293,8 @@ int vp9_receive_compressed_data(VP9Decoder *pbi,
|
||||
|
||||
// Check if the previous frame was a frame without any references to it.
|
||||
// Release frame buffer if not decoding in frame parallel mode.
|
||||
if (!pbi->frame_parallel_decode && cm->new_fb_idx >= 0
|
||||
&& frame_bufs[cm->new_fb_idx].ref_count == 0)
|
||||
if (!pbi->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.
|
||||
@ -330,7 +322,6 @@ int vp9_receive_compressed_data(VP9Decoder *pbi,
|
||||
pbi->cur_buf = &frame_bufs[cm->new_fb_idx];
|
||||
}
|
||||
|
||||
|
||||
if (setjmp(cm->error.jmp)) {
|
||||
const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
|
||||
int i;
|
||||
@ -425,14 +416,12 @@ int vp9_get_raw_frame(VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
|
||||
(void)*flags;
|
||||
#endif
|
||||
|
||||
if (pbi->ready_for_new_data == 1)
|
||||
return ret;
|
||||
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;
|
||||
if (!cm->show_frame) return ret;
|
||||
|
||||
pbi->ready_for_new_data = 1;
|
||||
|
||||
@ -451,8 +440,7 @@ int vp9_get_raw_frame(VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
|
||||
return ret;
|
||||
}
|
||||
|
||||
vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
|
||||
size_t data_sz,
|
||||
vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data, size_t data_sz,
|
||||
uint32_t sizes[8], int *count,
|
||||
vpx_decrypt_cb decrypt_cb,
|
||||
void *decrypt_state) {
|
||||
@ -475,18 +463,16 @@ vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
|
||||
|
||||
// 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 VPX_CODEC_CORRUPT_FRAME;
|
||||
if (data_sz < index_sz) return VPX_CODEC_CORRUPT_FRAME;
|
||||
|
||||
{
|
||||
const uint8_t marker2 = read_marker(decrypt_cb, decrypt_state,
|
||||
data + data_sz - index_sz);
|
||||
const uint8_t marker2 =
|
||||
read_marker(decrypt_cb, decrypt_state, data + data_sz - index_sz);
|
||||
|
||||
// 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 VPX_CODEC_CORRUPT_FRAME;
|
||||
if (marker != marker2) return VPX_CODEC_CORRUPT_FRAME;
|
||||
}
|
||||
|
||||
{
|
||||
@ -505,8 +491,7 @@ vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
|
||||
for (i = 0; i < frames; ++i) {
|
||||
uint32_t this_sz = 0;
|
||||
|
||||
for (j = 0; j < mag; ++j)
|
||||
this_sz |= ((uint32_t)(*x++)) << (j * 8);
|
||||
for (j = 0; j < mag; ++j) this_sz |= ((uint32_t)(*x++)) << (j * 8);
|
||||
sizes[i] = this_sz;
|
||||
}
|
||||
*count = frames;
|
||||
|
@ -78,8 +78,8 @@ typedef struct VP9Decoder {
|
||||
int hold_ref_buf; // hold the reference buffer.
|
||||
} VP9Decoder;
|
||||
|
||||
int vp9_receive_compressed_data(struct VP9Decoder *pbi,
|
||||
size_t size, const uint8_t **dest);
|
||||
int vp9_receive_compressed_data(struct VP9Decoder *pbi, size_t size,
|
||||
const uint8_t **dest);
|
||||
|
||||
int vp9_get_raw_frame(struct VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
|
||||
vp9_ppflags_t *flags);
|
||||
@ -93,8 +93,7 @@ vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
|
||||
YV12_BUFFER_CONFIG *sd);
|
||||
|
||||
static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
|
||||
void *decrypt_state,
|
||||
const uint8_t *data) {
|
||||
void *decrypt_state, const uint8_t *data) {
|
||||
if (decrypt_cb) {
|
||||
uint8_t marker;
|
||||
decrypt_cb(decrypt_state, data, &marker, 1);
|
||||
@ -105,8 +104,7 @@ static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
|
||||
|
||||
// This function is exposed for use in tests, as well as the inlined function
|
||||
// "read_marker".
|
||||
vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
|
||||
size_t data_sz,
|
||||
vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data, size_t data_sz,
|
||||
uint32_t sizes[8], int *count,
|
||||
vpx_decrypt_cb decrypt_cb,
|
||||
void *decrypt_state);
|
||||
|
@ -26,19 +26,16 @@
|
||||
|
||||
#define INCREMENT_COUNT(token) \
|
||||
do { \
|
||||
if (counts) \
|
||||
++coef_counts[band][ctx][token]; \
|
||||
if (counts) ++coef_counts[band][ctx][token]; \
|
||||
} while (0)
|
||||
|
||||
static INLINE int read_coeff(const vpx_prob *probs, int n, vpx_reader *r) {
|
||||
int i, val = 0;
|
||||
for (i = 0; i < n; ++i)
|
||||
val = (val << 1) | vpx_read(r, probs[i]);
|
||||
for (i = 0; i < n; ++i) val = (val << 1) | vpx_read(r, probs[i]);
|
||||
return val;
|
||||
}
|
||||
|
||||
static int decode_coefs(const MACROBLOCKD *xd,
|
||||
PLANE_TYPE type,
|
||||
static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type,
|
||||
tran_low_t *dqcoeff, TX_SIZE tx_size, const int16_t *dq,
|
||||
int ctx, const int16_t *scan, const int16_t *nb,
|
||||
vpx_reader *r) {
|
||||
@ -59,14 +56,14 @@ static int decode_coefs(const MACROBLOCKD *xd,
|
||||
int16_t dqv = dq[0];
|
||||
const uint8_t *const cat6_prob =
|
||||
#if CONFIG_VP9_HIGHBITDEPTH
|
||||
(xd->bd == VPX_BITS_12) ? vp9_cat6_prob_high12 :
|
||||
(xd->bd == VPX_BITS_10) ? vp9_cat6_prob_high12 + 2 :
|
||||
(xd->bd == VPX_BITS_12)
|
||||
? vp9_cat6_prob_high12
|
||||
: (xd->bd == VPX_BITS_10) ? vp9_cat6_prob_high12 + 2 :
|
||||
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||
vp9_cat6_prob;
|
||||
const int cat6_bits =
|
||||
#if CONFIG_VP9_HIGHBITDEPTH
|
||||
(xd->bd == VPX_BITS_12) ? 18 :
|
||||
(xd->bd == VPX_BITS_10) ? 16 :
|
||||
(xd->bd == VPX_BITS_12) ? 18 : (xd->bd == VPX_BITS_10) ? 16 :
|
||||
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||
14;
|
||||
|
||||
@ -79,8 +76,7 @@ static int decode_coefs(const MACROBLOCKD *xd,
|
||||
int val = -1;
|
||||
band = *band_translate++;
|
||||
prob = coef_probs[band][ctx];
|
||||
if (counts)
|
||||
++eob_branch_count[band][ctx];
|
||||
if (counts) ++eob_branch_count[band][ctx];
|
||||
if (!vpx_read(r, prob[EOB_CONTEXT_NODE])) {
|
||||
INCREMENT_COUNT(EOB_MODEL_TOKEN);
|
||||
break;
|
||||
@ -91,8 +87,7 @@ static int decode_coefs(const MACROBLOCKD *xd,
|
||||
dqv = dq[1];
|
||||
token_cache[scan[c]] = 0;
|
||||
++c;
|
||||
if (c >= max_eob)
|
||||
return c; // zero tokens at the end (no eob token)
|
||||
if (c >= max_eob) return c; // zero tokens at the end (no eob token)
|
||||
ctx = get_coef_context(nb, token_cache, c);
|
||||
band = *band_translate++;
|
||||
prob = coef_probs[band][ctx];
|
||||
@ -109,9 +104,7 @@ static int decode_coefs(const MACROBLOCKD *xd,
|
||||
switch (token) {
|
||||
case TWO_TOKEN:
|
||||
case THREE_TOKEN:
|
||||
case FOUR_TOKEN:
|
||||
val = token;
|
||||
break;
|
||||
case FOUR_TOKEN: val = token; break;
|
||||
case CATEGORY1_TOKEN:
|
||||
val = CAT1_MIN_VAL + read_coeff(vp9_cat1_prob, 1, r);
|
||||
break;
|
||||
@ -135,8 +128,7 @@ static int decode_coefs(const MACROBLOCKD *xd,
|
||||
v = (val * dqv) >> dq_shift;
|
||||
#if CONFIG_COEFFICIENT_RANGE_CHECKING
|
||||
#if CONFIG_VP9_HIGHBITDEPTH
|
||||
dqcoeff[scan[c]] = highbd_check_range((vpx_read_bit(r) ? -v : v),
|
||||
xd->bd);
|
||||
dqcoeff[scan[c]] = highbd_check_range((vpx_read_bit(r) ? -v : v), xd->bd);
|
||||
#else
|
||||
dqcoeff[scan[c]] = check_range(vpx_read_bit(r) ? -v : v);
|
||||
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||
|
@ -8,7 +8,6 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef VP9_DECODER_VP9_DETOKENIZE_H_
|
||||
#define VP9_DECODER_VP9_DETOKENIZE_H_
|
||||
|
||||
@ -20,10 +19,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int vp9_decode_block_tokens(MACROBLOCKD *xd,
|
||||
int plane, const scan_order *sc,
|
||||
int x, int y,
|
||||
TX_SIZE tx_size, vpx_reader *r,
|
||||
int vp9_decode_block_tokens(MACROBLOCKD *xd, int plane, const scan_order *sc,
|
||||
int x, int y, TX_SIZE tx_size, vpx_reader *r,
|
||||
int seg_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -15,8 +15,7 @@
|
||||
#include "vp9/decoder/vp9_dsubexp.h"
|
||||
|
||||
static int inv_recenter_nonneg(int v, int m) {
|
||||
if (v > 2 * m)
|
||||
return v;
|
||||
if (v > 2 * m) return v;
|
||||
|
||||
return (v & 1) ? m - ((v + 1) >> 1) : m + (v >> 1);
|
||||
}
|
||||
@ -59,12 +58,9 @@ static int inv_remap_prob(int v, int m) {
|
||||
}
|
||||
|
||||
static int decode_term_subexp(vpx_reader *r) {
|
||||
if (!vpx_read_bit(r))
|
||||
return vpx_read_literal(r, 4);
|
||||
if (!vpx_read_bit(r))
|
||||
return vpx_read_literal(r, 4) + 16;
|
||||
if (!vpx_read_bit(r))
|
||||
return vpx_read_literal(r, 5) + 32;
|
||||
if (!vpx_read_bit(r)) return vpx_read_literal(r, 4);
|
||||
if (!vpx_read_bit(r)) return vpx_read_literal(r, 4) + 16;
|
||||
if (!vpx_read_bit(r)) return vpx_read_literal(r, 5) + 32;
|
||||
return decode_uniform(r) + 64;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef VP9_DECODER_VP9_DSUBEXP_H_
|
||||
#define VP9_DECODER_VP9_DSUBEXP_H_
|
||||
|
||||
|
@ -62,8 +62,7 @@ void vp9_frameworker_signal_stats(VPxWorker *const worker) {
|
||||
void vp9_frameworker_wait(VPxWorker *const worker, RefCntBuffer *const ref_buf,
|
||||
int row) {
|
||||
#if CONFIG_MULTITHREAD
|
||||
if (!ref_buf)
|
||||
return;
|
||||
if (!ref_buf) return;
|
||||
|
||||
#ifndef BUILDING_WITH_TSAN
|
||||
// The following line of code will get harmless tsan error but it is the key
|
||||
@ -150,8 +149,9 @@ void vp9_frameworker_copy_context(VPxWorker *const dst_worker,
|
||||
&src_worker_data->stats_mutex);
|
||||
}
|
||||
|
||||
dst_cm->last_frame_seg_map = src_cm->seg.enabled ?
|
||||
src_cm->current_frame_seg_map : src_cm->last_frame_seg_map;
|
||||
dst_cm->last_frame_seg_map = src_cm->seg.enabled
|
||||
? src_cm->current_frame_seg_map
|
||||
: src_cm->last_frame_seg_map;
|
||||
dst_worker_data->pbi->need_resync = src_worker_data->pbi->need_resync;
|
||||
vp9_frameworker_unlock_stats(src_worker);
|
||||
|
||||
@ -159,17 +159,18 @@ void vp9_frameworker_copy_context(VPxWorker *const dst_worker,
|
||||
#if CONFIG_VP9_HIGHBITDEPTH
|
||||
dst_cm->use_highbitdepth = src_cm->use_highbitdepth;
|
||||
#endif
|
||||
dst_cm->prev_frame = src_cm->show_existing_frame ?
|
||||
src_cm->prev_frame : src_cm->cur_frame;
|
||||
dst_cm->last_width = !src_cm->show_existing_frame ?
|
||||
src_cm->width : src_cm->last_width;
|
||||
dst_cm->last_height = !src_cm->show_existing_frame ?
|
||||
src_cm->height : src_cm->last_height;
|
||||
dst_cm->prev_frame =
|
||||
src_cm->show_existing_frame ? src_cm->prev_frame : src_cm->cur_frame;
|
||||
dst_cm->last_width =
|
||||
!src_cm->show_existing_frame ? src_cm->width : src_cm->last_width;
|
||||
dst_cm->last_height =
|
||||
!src_cm->show_existing_frame ? src_cm->height : src_cm->last_height;
|
||||
dst_cm->subsampling_x = src_cm->subsampling_x;
|
||||
dst_cm->subsampling_y = src_cm->subsampling_y;
|
||||
dst_cm->frame_type = src_cm->frame_type;
|
||||
dst_cm->last_show_frame = !src_cm->show_existing_frame ?
|
||||
src_cm->show_frame : src_cm->last_show_frame;
|
||||
dst_cm->last_show_frame = !src_cm->show_existing_frame
|
||||
? src_cm->show_frame
|
||||
: src_cm->last_show_frame;
|
||||
for (i = 0; i < REF_FRAMES; ++i)
|
||||
dst_cm->ref_frame_map[i] = src_cm->next_ref_frame_map[i];
|
||||
|
||||
|
@ -105,8 +105,8 @@ struct vpx_codec_alg_priv {
|
||||
BufferPool *buffer_pool;
|
||||
};
|
||||
|
||||
static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx,
|
||||
const struct vpx_internal_error_info *error) {
|
||||
static vpx_codec_err_t update_error_state(
|
||||
vpx_codec_alg_priv_t *ctx, const struct vpx_internal_error_info *error) {
|
||||
const vpx_codec_err_t res = error->error_code;
|
||||
|
||||
if (res != VPX_CODEC_OK)
|
||||
@ -115,29 +115,31 @@ static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx,
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
#undef ERROR
|
||||
#define ERROR(str) do {\
|
||||
#define ERROR(str) \
|
||||
do { \
|
||||
ctx->base.err_detail = str; \
|
||||
return VPX_CODEC_INVALID_PARAM; \
|
||||
} while (0)
|
||||
|
||||
#define RANGE_CHECK(p, memb, lo, hi) do {\
|
||||
#define RANGE_CHECK(p, memb, lo, hi) \
|
||||
do { \
|
||||
if (!(((p)->memb == lo || (p)->memb > (lo)) && (p)->memb <= hi)) \
|
||||
ERROR(#memb " out of range [" #lo ".." #hi "]"); \
|
||||
} while (0)
|
||||
|
||||
#define RANGE_CHECK_HI(p, memb, hi) do {\
|
||||
if (!((p)->memb <= (hi))) \
|
||||
ERROR(#memb " out of range [.."#hi"]");\
|
||||
#define RANGE_CHECK_HI(p, memb, hi) \
|
||||
do { \
|
||||
if (!((p)->memb <= (hi))) ERROR(#memb " out of range [.." #hi "]"); \
|
||||
} while (0)
|
||||
|
||||
#define RANGE_CHECK_LO(p, memb, lo) do {\
|
||||
if (!((p)->memb >= (lo))) \
|
||||
ERROR(#memb " out of range ["#lo"..]");\
|
||||
#define RANGE_CHECK_LO(p, memb, lo) \
|
||||
do { \
|
||||
if (!((p)->memb >= (lo))) ERROR(#memb " out of range [" #lo "..]"); \
|
||||
} while (0)
|
||||
|
||||
#define RANGE_CHECK_BOOL(p, memb) do {\
|
||||
#define RANGE_CHECK_BOOL(p, memb) \
|
||||
do { \
|
||||
if (!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean"); \
|
||||
} while (0)
|
||||
|
||||
@ -191,8 +193,8 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
|
||||
level != LEVEL_2_1 && level != LEVEL_3 && level != LEVEL_3_1 &&
|
||||
level != LEVEL_4 && level != LEVEL_4_1 && level != LEVEL_5 &&
|
||||
level != LEVEL_5_1 && level != LEVEL_5_2 && level != LEVEL_6 &&
|
||||
level != LEVEL_6_1 && level != LEVEL_6_2 &&
|
||||
level != LEVEL_UNKNOWN && level != LEVEL_MAX)
|
||||
level != LEVEL_6_1 && level != LEVEL_6_2 && level != LEVEL_UNKNOWN &&
|
||||
level != LEVEL_MAX)
|
||||
ERROR("target_level is invalid");
|
||||
}
|
||||
|
||||
@ -202,8 +204,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
|
||||
unsigned int sl, tl;
|
||||
for (sl = 1; sl < cfg->ss_number_layers; ++sl) {
|
||||
for (tl = 1; tl < cfg->ts_number_layers; ++tl) {
|
||||
const int layer =
|
||||
LAYER_IDS_TO_IDX(sl, tl, cfg->ts_number_layers);
|
||||
const int layer = LAYER_IDS_TO_IDX(sl, tl, cfg->ts_number_layers);
|
||||
if (cfg->layer_target_bitrate[layer] <
|
||||
cfg->layer_target_bitrate[layer - 1])
|
||||
ERROR("ts_target_bitrate entries are not increasing");
|
||||
@ -222,8 +223,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
|
||||
cfg->g_pass == VPX_RC_LAST_PASS) {
|
||||
unsigned int i, alt_ref_sum = 0;
|
||||
for (i = 0; i < cfg->ss_number_layers; ++i) {
|
||||
if (cfg->ss_enable_auto_alt_ref[i])
|
||||
++alt_ref_sum;
|
||||
if (cfg->ss_enable_auto_alt_ref[i]) ++alt_ref_sum;
|
||||
}
|
||||
if (alt_ref_sum > REF_FRAMES - cfg->ss_number_layers)
|
||||
ERROR("Not enough ref buffers for svc alt ref frames");
|
||||
@ -235,10 +235,10 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
|
||||
|
||||
// VP9 does not support a lower bound on the keyframe interval in
|
||||
// automatic keyframe placement mode.
|
||||
if (cfg->kf_mode != VPX_KF_DISABLED &&
|
||||
cfg->kf_min_dist != cfg->kf_max_dist &&
|
||||
if (cfg->kf_mode != VPX_KF_DISABLED && cfg->kf_min_dist != cfg->kf_max_dist &&
|
||||
cfg->kf_min_dist > 0)
|
||||
ERROR("kf_min_dist not supported in auto mode, use 0 "
|
||||
ERROR(
|
||||
"kf_min_dist not supported in auto mode, use 0 "
|
||||
"or kf_max_dist instead.");
|
||||
|
||||
RANGE_CHECK(extra_cfg, enable_auto_alt_ref, 0, 2);
|
||||
@ -252,8 +252,8 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
|
||||
RANGE_CHECK(extra_cfg, cq_level, 0, 63);
|
||||
RANGE_CHECK(cfg, g_bit_depth, VPX_BITS_8, VPX_BITS_12);
|
||||
RANGE_CHECK(cfg, g_input_bit_depth, 8, 12);
|
||||
RANGE_CHECK(extra_cfg, content,
|
||||
VP9E_CONTENT_DEFAULT, VP9E_CONTENT_INVALID - 1);
|
||||
RANGE_CHECK(extra_cfg, content, VP9E_CONTENT_DEFAULT,
|
||||
VP9E_CONTENT_INVALID - 1);
|
||||
|
||||
// TODO(yaowu): remove this when ssim tuning is implemented for vp9
|
||||
if (extra_cfg->tuning == VP8_TUNE_SSIM)
|
||||
@ -285,7 +285,8 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
|
||||
for (i = 0; i < (int)cfg->ss_number_layers; ++i) {
|
||||
unsigned int layer_id;
|
||||
if (n_packets_per_layer[i] < 2) {
|
||||
ERROR("rc_twopass_stats_in requires at least two packets for each "
|
||||
ERROR(
|
||||
"rc_twopass_stats_in requires at least two packets for each "
|
||||
"layer.");
|
||||
}
|
||||
|
||||
@ -293,8 +294,8 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
|
||||
n_packets - cfg->ss_number_layers + i;
|
||||
layer_id = (int)stats->spatial_layer_id;
|
||||
|
||||
if (layer_id >= cfg->ss_number_layers
|
||||
||(unsigned int)(stats->count + 0.5) !=
|
||||
if (layer_id >= cfg->ss_number_layers ||
|
||||
(unsigned int)(stats->count + 0.5) !=
|
||||
n_packets_per_layer[layer_id] - 1)
|
||||
ERROR("rc_twopass_stats_in missing EOS stats packet");
|
||||
}
|
||||
@ -319,8 +320,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
|
||||
cfg->g_bit_depth > VPX_BITS_8) {
|
||||
ERROR("Codec high bit-depth not supported in profile < 2");
|
||||
}
|
||||
if (cfg->g_profile <= (unsigned int)PROFILE_1 &&
|
||||
cfg->g_input_bit_depth > 8) {
|
||||
if (cfg->g_profile <= (unsigned int)PROFILE_1 && cfg->g_input_bit_depth > 8) {
|
||||
ERROR("Source high bit-depth not supported in profile < 2");
|
||||
}
|
||||
if (cfg->g_profile > (unsigned int)PROFILE_1 &&
|
||||
@ -328,8 +328,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
|
||||
ERROR("Codec bit-depth 8 not supported in profile > 1");
|
||||
}
|
||||
RANGE_CHECK(extra_cfg, color_space, VPX_CS_UNKNOWN, VPX_CS_SRGB);
|
||||
RANGE_CHECK(extra_cfg, color_range,
|
||||
VPX_CR_STUDIO_RANGE, VPX_CR_FULL_RANGE);
|
||||
RANGE_CHECK(extra_cfg, color_range, VPX_CR_STUDIO_RANGE, VPX_CR_FULL_RANGE);
|
||||
return VPX_CODEC_OK;
|
||||
}
|
||||
|
||||
@ -338,13 +337,13 @@ static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx,
|
||||
switch (img->fmt) {
|
||||
case VPX_IMG_FMT_YV12:
|
||||
case VPX_IMG_FMT_I420:
|
||||
case VPX_IMG_FMT_I42016:
|
||||
break;
|
||||
case VPX_IMG_FMT_I42016: break;
|
||||
case VPX_IMG_FMT_I422:
|
||||
case VPX_IMG_FMT_I444:
|
||||
case VPX_IMG_FMT_I440:
|
||||
if (ctx->cfg.g_profile != (unsigned int)PROFILE_1) {
|
||||
ERROR("Invalid image format. I422, I444, I440 images are "
|
||||
ERROR(
|
||||
"Invalid image format. I422, I444, I440 images are "
|
||||
"not supported in profile.");
|
||||
}
|
||||
break;
|
||||
@ -353,12 +352,14 @@ static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx,
|
||||
case VPX_IMG_FMT_I44016:
|
||||
if (ctx->cfg.g_profile != (unsigned int)PROFILE_1 &&
|
||||
ctx->cfg.g_profile != (unsigned int)PROFILE_3) {
|
||||
ERROR("Invalid image format. 16-bit I422, I444, I440 images are "
|
||||
ERROR(
|
||||
"Invalid image format. 16-bit I422, I444, I440 images are "
|
||||
"not supported in profile.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ERROR("Invalid image format. Only YV12, I420, I422, I444 images are "
|
||||
ERROR(
|
||||
"Invalid image format. Only YV12, I420, I422, I444 images are "
|
||||
"supported.");
|
||||
break;
|
||||
}
|
||||
@ -386,8 +387,7 @@ static int get_image_bps(const vpx_image_t *img) {
|
||||
}
|
||||
|
||||
static vpx_codec_err_t set_encoder_config(
|
||||
VP9EncoderConfig *oxcf,
|
||||
const vpx_codec_enc_cfg_t *cfg,
|
||||
VP9EncoderConfig *oxcf, const vpx_codec_enc_cfg_t *cfg,
|
||||
const struct vp9_extracfg *extra_cfg) {
|
||||
const int is_vbr = cfg->rc_end_usage == VPX_VBR;
|
||||
int sl, tl;
|
||||
@ -399,25 +399,18 @@ static vpx_codec_err_t set_encoder_config(
|
||||
oxcf->input_bit_depth = cfg->g_input_bit_depth;
|
||||
// guess a frame rate if out of whack, use 30
|
||||
oxcf->init_framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num;
|
||||
if (oxcf->init_framerate > 180)
|
||||
oxcf->init_framerate = 30;
|
||||
if (oxcf->init_framerate > 180) oxcf->init_framerate = 30;
|
||||
|
||||
oxcf->mode = GOOD;
|
||||
|
||||
switch (cfg->g_pass) {
|
||||
case VPX_RC_ONE_PASS:
|
||||
oxcf->pass = 0;
|
||||
break;
|
||||
case VPX_RC_FIRST_PASS:
|
||||
oxcf->pass = 1;
|
||||
break;
|
||||
case VPX_RC_LAST_PASS:
|
||||
oxcf->pass = 2;
|
||||
break;
|
||||
case VPX_RC_ONE_PASS: oxcf->pass = 0; break;
|
||||
case VPX_RC_FIRST_PASS: oxcf->pass = 1; break;
|
||||
case VPX_RC_LAST_PASS: oxcf->pass = 2; break;
|
||||
}
|
||||
|
||||
oxcf->lag_in_frames = cfg->g_pass == VPX_RC_FIRST_PASS ? 0
|
||||
: cfg->g_lag_in_frames;
|
||||
oxcf->lag_in_frames =
|
||||
cfg->g_pass == VPX_RC_FIRST_PASS ? 0 : cfg->g_lag_in_frames;
|
||||
oxcf->rc_mode = cfg->rc_end_usage;
|
||||
|
||||
// Convert target bandwidth from Kbit/s to Bit/s
|
||||
@ -440,8 +433,9 @@ static vpx_codec_err_t set_encoder_config(
|
||||
oxcf->scaled_frame_height = cfg->rc_scaled_height;
|
||||
if (cfg->rc_resize_allowed == 1) {
|
||||
oxcf->resize_mode =
|
||||
(oxcf->scaled_frame_width == 0 || oxcf->scaled_frame_height == 0) ?
|
||||
RESIZE_DYNAMIC : RESIZE_FIXED;
|
||||
(oxcf->scaled_frame_width == 0 || oxcf->scaled_frame_height == 0)
|
||||
? RESIZE_DYNAMIC
|
||||
: RESIZE_FIXED;
|
||||
} else {
|
||||
oxcf->resize_mode = RESIZE_NONE;
|
||||
}
|
||||
@ -456,8 +450,8 @@ static vpx_codec_err_t set_encoder_config(
|
||||
oxcf->two_pass_vbrmin_section = cfg->rc_2pass_vbr_minsection_pct;
|
||||
oxcf->two_pass_vbrmax_section = cfg->rc_2pass_vbr_maxsection_pct;
|
||||
|
||||
oxcf->auto_key = cfg->kf_mode == VPX_KF_AUTO &&
|
||||
cfg->kf_min_dist != cfg->kf_max_dist;
|
||||
oxcf->auto_key =
|
||||
cfg->kf_mode == VPX_KF_AUTO && cfg->kf_min_dist != cfg->kf_max_dist;
|
||||
|
||||
oxcf->key_freq = cfg->kf_max_dist;
|
||||
|
||||
@ -506,8 +500,8 @@ static vpx_codec_err_t set_encoder_config(
|
||||
|
||||
oxcf->ss_number_layers = cfg->ss_number_layers;
|
||||
oxcf->ts_number_layers = cfg->ts_number_layers;
|
||||
oxcf->temporal_layering_mode = (enum vp9e_temporal_layering_mode)
|
||||
cfg->temporal_layering_mode;
|
||||
oxcf->temporal_layering_mode =
|
||||
(enum vp9e_temporal_layering_mode)cfg->temporal_layering_mode;
|
||||
|
||||
oxcf->target_level = extra_cfg->target_level;
|
||||
|
||||
@ -528,8 +522,8 @@ static vpx_codec_err_t set_encoder_config(
|
||||
}
|
||||
if (oxcf->ts_number_layers > 1) {
|
||||
for (tl = 0; tl < VPX_TS_MAX_LAYERS; ++tl) {
|
||||
oxcf->ts_rate_decimator[tl] = cfg->ts_rate_decimator[tl] ?
|
||||
cfg->ts_rate_decimator[tl] : 1;
|
||||
oxcf->ts_rate_decimator[tl] =
|
||||
cfg->ts_rate_decimator[tl] ? cfg->ts_rate_decimator[tl] : 1;
|
||||
}
|
||||
} else if (oxcf->ts_number_layers == 1) {
|
||||
oxcf->ts_rate_decimator[0] = 1;
|
||||
@ -601,8 +595,7 @@ static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx,
|
||||
vp9_change_config(ctx->cpi, &ctx->oxcf);
|
||||
}
|
||||
|
||||
if (force_key)
|
||||
ctx->next_frame_flags |= VPX_EFLAG_FORCE_KF;
|
||||
if (force_key) ctx->next_frame_flags |= VPX_EFLAG_FORCE_KF;
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -610,8 +603,7 @@ static vpx_codec_err_t encoder_set_config(vpx_codec_alg_priv_t *ctx,
|
||||
static vpx_codec_err_t ctrl_get_quantizer(vpx_codec_alg_priv_t *ctx,
|
||||
va_list args) {
|
||||
int *const arg = va_arg(args, int *);
|
||||
if (arg == NULL)
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
if (arg == NULL) return VPX_CODEC_INVALID_PARAM;
|
||||
*arg = vp9_get_quantizer(ctx->cpi);
|
||||
return VPX_CODEC_OK;
|
||||
}
|
||||
@ -619,8 +611,7 @@ static vpx_codec_err_t ctrl_get_quantizer(vpx_codec_alg_priv_t *ctx,
|
||||
static vpx_codec_err_t ctrl_get_quantizer64(vpx_codec_alg_priv_t *ctx,
|
||||
va_list args) {
|
||||
int *const arg = va_arg(args, int *);
|
||||
if (arg == NULL)
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
if (arg == NULL) return VPX_CODEC_INVALID_PARAM;
|
||||
*arg = vp9_qindex_to_quantizer(vp9_get_quantizer(ctx->cpi));
|
||||
return VPX_CODEC_OK;
|
||||
}
|
||||
@ -736,11 +727,10 @@ static vpx_codec_err_t ctrl_set_rc_max_inter_bitrate_pct(
|
||||
return update_extra_cfg(ctx, &extra_cfg);
|
||||
}
|
||||
|
||||
static vpx_codec_err_t ctrl_set_rc_gf_cbr_boost_pct(
|
||||
vpx_codec_alg_priv_t *ctx, va_list args) {
|
||||
static vpx_codec_err_t ctrl_set_rc_gf_cbr_boost_pct(vpx_codec_alg_priv_t *ctx,
|
||||
va_list args) {
|
||||
struct vp9_extracfg extra_cfg = ctx->extra_cfg;
|
||||
extra_cfg.gf_cbr_boost_pct =
|
||||
CAST(VP9E_SET_GF_CBR_BOOST_PCT, args);
|
||||
extra_cfg.gf_cbr_boost_pct = CAST(VP9E_SET_GF_CBR_BOOST_PCT, args);
|
||||
return update_extra_cfg(ctx, &extra_cfg);
|
||||
}
|
||||
|
||||
@ -808,16 +798,13 @@ static vpx_codec_err_t encoder_init(vpx_codec_ctx_t *ctx,
|
||||
|
||||
if (ctx->priv == NULL) {
|
||||
vpx_codec_alg_priv_t *const priv = vpx_calloc(1, sizeof(*priv));
|
||||
if (priv == NULL)
|
||||
return VPX_CODEC_MEM_ERROR;
|
||||
if (priv == NULL) return VPX_CODEC_MEM_ERROR;
|
||||
|
||||
ctx->priv = (vpx_codec_priv_t *)priv;
|
||||
ctx->priv->init_flags = ctx->init_flags;
|
||||
ctx->priv->enc.total_encoders = 1;
|
||||
priv->buffer_pool =
|
||||
(BufferPool *)vpx_calloc(1, sizeof(BufferPool));
|
||||
if (priv->buffer_pool == NULL)
|
||||
return VPX_CODEC_MEM_ERROR;
|
||||
priv->buffer_pool = (BufferPool *)vpx_calloc(1, sizeof(BufferPool));
|
||||
if (priv->buffer_pool == NULL) return VPX_CODEC_MEM_ERROR;
|
||||
|
||||
#if CONFIG_MULTITHREAD
|
||||
if (pthread_mutex_init(&priv->buffer_pool->pool_mutex, NULL)) {
|
||||
@ -876,7 +863,8 @@ static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx,
|
||||
|
||||
// Convert duration parameter from stream timebase to microseconds.
|
||||
const uint64_t duration_us = (uint64_t)duration * 1000000 *
|
||||
(uint64_t)cfg->g_timebase.num /(uint64_t)cfg->g_timebase.den;
|
||||
(uint64_t)cfg->g_timebase.num /
|
||||
(uint64_t)cfg->g_timebase.den;
|
||||
|
||||
// If the deadline is more that the duration this frame is to be shown,
|
||||
// use good quality mode. Otherwise use realtime mode.
|
||||
@ -885,11 +873,8 @@ static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx,
|
||||
new_mode = BEST;
|
||||
}
|
||||
break;
|
||||
case VPX_RC_FIRST_PASS:
|
||||
break;
|
||||
case VPX_RC_LAST_PASS:
|
||||
new_mode = deadline > 0 ? GOOD : BEST;
|
||||
break;
|
||||
case VPX_RC_FIRST_PASS: break;
|
||||
case VPX_RC_LAST_PASS: new_mode = deadline > 0 ? GOOD : BEST; break;
|
||||
}
|
||||
|
||||
if (deadline == VPX_DL_REALTIME) {
|
||||
@ -918,8 +903,7 @@ static int write_superframe_index(vpx_codec_alg_priv_t *ctx) {
|
||||
|
||||
// Choose the magnitude
|
||||
for (mag = 0, mask = 0xff; mag < 4; mag++) {
|
||||
if (ctx->pending_frame_magnitude < mask)
|
||||
break;
|
||||
if (ctx->pending_frame_magnitude < mask) break;
|
||||
mask <<= 8;
|
||||
mask |= 0xff;
|
||||
}
|
||||
@ -982,12 +966,11 @@ static vpx_codec_frame_flags_t get_frame_pkt_flags(const VP9_COMP *cpi,
|
||||
(cpi->use_svc &&
|
||||
cpi->svc.layer_context[cpi->svc.spatial_layer_id *
|
||||
cpi->svc.number_temporal_layers +
|
||||
cpi->svc.temporal_layer_id].is_key_frame)
|
||||
)
|
||||
cpi->svc.temporal_layer_id]
|
||||
.is_key_frame))
|
||||
flags |= VPX_FRAME_IS_KEY;
|
||||
|
||||
if (cpi->droppable)
|
||||
flags |= VPX_FRAME_IS_DROPPABLE;
|
||||
if (cpi->droppable) flags |= VPX_FRAME_IS_DROPPABLE;
|
||||
|
||||
return flags;
|
||||
}
|
||||
@ -1014,8 +997,7 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
|
||||
// instance for its status to determine the compressed data size.
|
||||
data_sz = ctx->cfg.g_w * ctx->cfg.g_h * get_image_bps(img) / 8 *
|
||||
(cpi->multi_arf_allowed ? 8 : 2);
|
||||
if (data_sz < kMinCompressedSize)
|
||||
data_sz = kMinCompressedSize;
|
||||
if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize;
|
||||
if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) {
|
||||
ctx->cx_data_sz = data_sz;
|
||||
free(ctx->cx_data);
|
||||
@ -1066,16 +1048,15 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
|
||||
unsigned char *cx_data;
|
||||
|
||||
// Set up internal flags
|
||||
if (ctx->base.init_flags & VPX_CODEC_USE_PSNR)
|
||||
cpi->b_calculate_psnr = 1;
|
||||
if (ctx->base.init_flags & VPX_CODEC_USE_PSNR) cpi->b_calculate_psnr = 1;
|
||||
|
||||
if (img != NULL) {
|
||||
res = image2yuvconfig(img, &sd);
|
||||
|
||||
// Store the original flags in to the frame buffer. Will extract the
|
||||
// key frame flag when we actually encode this frame.
|
||||
if (vp9_receive_raw_frame(cpi, flags | ctx->next_frame_flags,
|
||||
&sd, dst_time_stamp, dst_end_time_stamp)) {
|
||||
if (vp9_receive_raw_frame(cpi, flags | ctx->next_frame_flags, &sd,
|
||||
dst_time_stamp, dst_end_time_stamp)) {
|
||||
res = update_error_state(ctx, &cpi->common.error);
|
||||
}
|
||||
ctx->next_frame_flags = 0;
|
||||
@ -1102,25 +1083,24 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
|
||||
}
|
||||
|
||||
while (cx_data_sz >= ctx->cx_data_sz / 2 &&
|
||||
-1 != vp9_get_compressed_data(cpi, &lib_flags, &size,
|
||||
cx_data, &dst_time_stamp,
|
||||
&dst_end_time_stamp, !img)) {
|
||||
-1 != vp9_get_compressed_data(cpi, &lib_flags, &size, cx_data,
|
||||
&dst_time_stamp, &dst_end_time_stamp,
|
||||
!img)) {
|
||||
if (size) {
|
||||
vpx_codec_cx_pkt_t pkt;
|
||||
|
||||
#if CONFIG_SPATIAL_SVC
|
||||
if (cpi->use_svc)
|
||||
cpi->svc.layer_context[cpi->svc.spatial_layer_id *
|
||||
cpi->svc.number_temporal_layers].layer_size += size;
|
||||
cpi->svc.number_temporal_layers]
|
||||
.layer_size += size;
|
||||
#endif
|
||||
|
||||
// Pack invisible frames with the next visible frame
|
||||
if (!cpi->common.show_frame ||
|
||||
(cpi->use_svc &&
|
||||
cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1)
|
||||
) {
|
||||
if (ctx->pending_cx_data == 0)
|
||||
ctx->pending_cx_data = cx_data;
|
||||
cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1)) {
|
||||
if (ctx->pending_cx_data == 0) ctx->pending_cx_data = cx_data;
|
||||
ctx->pending_cx_data_sz += size;
|
||||
ctx->pending_frame_sizes[ctx->pending_frame_count++] = size;
|
||||
ctx->pending_frame_magnitude |= size;
|
||||
@ -1129,11 +1109,10 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
|
||||
|
||||
if (ctx->output_cx_pkt_cb.output_cx_pkt) {
|
||||
pkt.kind = VPX_CODEC_CX_FRAME_PKT;
|
||||
pkt.data.frame.pts = ticks_to_timebase_units(timebase,
|
||||
dst_time_stamp);
|
||||
pkt.data.frame.duration =
|
||||
(unsigned long)ticks_to_timebase_units(timebase,
|
||||
dst_end_time_stamp - dst_time_stamp);
|
||||
pkt.data.frame.pts =
|
||||
ticks_to_timebase_units(timebase, dst_time_stamp);
|
||||
pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units(
|
||||
timebase, dst_end_time_stamp - dst_time_stamp);
|
||||
pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags);
|
||||
pkt.data.frame.buf = ctx->pending_cx_data;
|
||||
pkt.data.frame.sz = size;
|
||||
@ -1150,9 +1129,8 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
|
||||
// Add the frame packet to the list of returned packets.
|
||||
pkt.kind = VPX_CODEC_CX_FRAME_PKT;
|
||||
pkt.data.frame.pts = ticks_to_timebase_units(timebase, dst_time_stamp);
|
||||
pkt.data.frame.duration =
|
||||
(unsigned long)ticks_to_timebase_units(timebase,
|
||||
dst_end_time_stamp - dst_time_stamp);
|
||||
pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units(
|
||||
timebase, dst_end_time_stamp - dst_time_stamp);
|
||||
pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags);
|
||||
|
||||
if (ctx->pending_cx_data) {
|
||||
@ -1287,7 +1265,6 @@ static vpx_codec_err_t ctrl_set_previewpp(vpx_codec_alg_priv_t *ctx,
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static vpx_image_t *encoder_get_preview(vpx_codec_alg_priv_t *ctx) {
|
||||
YV12_BUFFER_CONFIG sd;
|
||||
vp9_ppflags_t flags;
|
||||
@ -1316,14 +1293,13 @@ static vpx_codec_err_t ctrl_set_roi_map(vpx_codec_alg_priv_t *ctx,
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
}
|
||||
|
||||
|
||||
static vpx_codec_err_t ctrl_set_active_map(vpx_codec_alg_priv_t *ctx,
|
||||
va_list args) {
|
||||
vpx_active_map_t *const map = va_arg(args, vpx_active_map_t *);
|
||||
|
||||
if (map) {
|
||||
if (!vp9_set_active_map(ctx->cpi, map->active_map,
|
||||
(int)map->rows, (int)map->cols))
|
||||
if (!vp9_set_active_map(ctx->cpi, map->active_map, (int)map->rows,
|
||||
(int)map->cols))
|
||||
return VPX_CODEC_OK;
|
||||
else
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
@ -1337,8 +1313,8 @@ static vpx_codec_err_t ctrl_get_active_map(vpx_codec_alg_priv_t *ctx,
|
||||
vpx_active_map_t *const map = va_arg(args, vpx_active_map_t *);
|
||||
|
||||
if (map) {
|
||||
if (!vp9_get_active_map(ctx->cpi, map->active_map,
|
||||
(int)map->rows, (int)map->cols))
|
||||
if (!vp9_get_active_map(ctx->cpi, map->active_map, (int)map->rows,
|
||||
(int)map->cols))
|
||||
return VPX_CODEC_OK;
|
||||
else
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
@ -1352,8 +1328,8 @@ static vpx_codec_err_t ctrl_set_scale_mode(vpx_codec_alg_priv_t *ctx,
|
||||
vpx_scaling_mode_t *const mode = va_arg(args, vpx_scaling_mode_t *);
|
||||
|
||||
if (mode) {
|
||||
const int res = vp9_set_internal_size(ctx->cpi,
|
||||
(VPX_SCALING)mode->h_scaling_mode,
|
||||
const int res =
|
||||
vp9_set_internal_size(ctx->cpi, (VPX_SCALING)mode->h_scaling_mode,
|
||||
(VPX_SCALING)mode->v_scaling_mode);
|
||||
return (res == 0) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM;
|
||||
} else {
|
||||
@ -1374,10 +1350,8 @@ static vpx_codec_err_t ctrl_set_svc(vpx_codec_alg_priv_t *ctx, va_list args) {
|
||||
vp9_set_svc(ctx->cpi, data);
|
||||
|
||||
if (data == 1 &&
|
||||
(cfg->g_pass == VPX_RC_FIRST_PASS ||
|
||||
cfg->g_pass == VPX_RC_LAST_PASS) &&
|
||||
cfg->ss_number_layers > 1 &&
|
||||
cfg->ts_number_layers > 1) {
|
||||
(cfg->g_pass == VPX_RC_FIRST_PASS || cfg->g_pass == VPX_RC_LAST_PASS) &&
|
||||
cfg->ss_number_layers > 1 && cfg->ts_number_layers > 1) {
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
}
|
||||
return VPX_CODEC_OK;
|
||||
@ -1431,8 +1405,7 @@ static vpx_codec_err_t ctrl_set_svc_parameters(vpx_codec_alg_priv_t *ctx,
|
||||
for (tl = 0; tl < cpi->svc.number_temporal_layers; ++tl) {
|
||||
const int layer =
|
||||
LAYER_IDS_TO_IDX(sl, tl, cpi->svc.number_temporal_layers);
|
||||
LAYER_CONTEXT *lc =
|
||||
&cpi->svc.layer_context[layer];
|
||||
LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer];
|
||||
lc->max_q = params->max_quantizers[layer];
|
||||
lc->min_q = params->min_quantizers[layer];
|
||||
lc->scaling_factor_num = params->scaling_factor_num[sl];
|
||||
@ -1551,9 +1524,9 @@ static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
|
||||
};
|
||||
|
||||
static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = {
|
||||
{ 0,
|
||||
{
|
||||
0,
|
||||
{ // NOLINT
|
||||
// NOLINT
|
||||
0, // g_usage
|
||||
8, // g_threads
|
||||
0, // g_profile
|
||||
@ -1610,8 +1583,7 @@ static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = {
|
||||
{ 0 }, // ts_layer_id
|
||||
{ 0 }, // layer_taget_bitrate
|
||||
0 // temporal_layering_mode
|
||||
}
|
||||
},
|
||||
} },
|
||||
};
|
||||
|
||||
#ifndef VERSION_STRING
|
||||
@ -1627,14 +1599,16 @@ CODEC_INTERFACE(vpx_codec_vp9_cx) = {
|
||||
encoder_init, // vpx_codec_init_fn_t
|
||||
encoder_destroy, // vpx_codec_destroy_fn_t
|
||||
encoder_ctrl_maps, // vpx_codec_ctrl_fn_map_t
|
||||
{ // NOLINT
|
||||
{
|
||||
// NOLINT
|
||||
NULL, // vpx_codec_peek_si_fn_t
|
||||
NULL, // vpx_codec_get_si_fn_t
|
||||
NULL, // vpx_codec_decode_fn_t
|
||||
NULL, // vpx_codec_frame_get_fn_t
|
||||
NULL // vpx_codec_set_fb_fn_t
|
||||
},
|
||||
{ // NOLINT
|
||||
{
|
||||
// NOLINT
|
||||
1, // 1 cfg map
|
||||
encoder_usage_cfg_map, // vpx_codec_enc_cfg_map_t
|
||||
encoder_encode, // vpx_codec_encode_fn_t
|
||||
|
@ -41,8 +41,7 @@ static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx,
|
||||
if (!ctx->priv) {
|
||||
vpx_codec_alg_priv_t *const priv =
|
||||
(vpx_codec_alg_priv_t *)vpx_calloc(1, sizeof(*priv));
|
||||
if (priv == NULL)
|
||||
return VPX_CODEC_MEM_ERROR;
|
||||
if (priv == NULL) return VPX_CODEC_MEM_ERROR;
|
||||
|
||||
ctx->priv = (vpx_codec_priv_t *)priv;
|
||||
ctx->priv->init_flags = ctx->init_flags;
|
||||
@ -51,7 +50,9 @@ static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx,
|
||||
// Only do frame parallel decode when threads > 1.
|
||||
priv->frame_parallel_decode =
|
||||
(ctx->config.dec && (ctx->config.dec->threads > 1) &&
|
||||
(ctx->init_flags & VPX_CODEC_USE_FRAME_THREADING)) ? 1 : 0;
|
||||
(ctx->init_flags & VPX_CODEC_USE_FRAME_THREADING))
|
||||
? 1
|
||||
: 0;
|
||||
if (ctx->config.dec) {
|
||||
priv->cfg = *ctx->config.dec;
|
||||
ctx->config.dec = &priv->cfg;
|
||||
@ -102,11 +103,10 @@ static vpx_codec_err_t decoder_destroy(vpx_codec_alg_priv_t *ctx) {
|
||||
return VPX_CODEC_OK;
|
||||
}
|
||||
|
||||
static int parse_bitdepth_colorspace_sampling(
|
||||
BITSTREAM_PROFILE profile, struct vpx_read_bit_buffer *rb) {
|
||||
static int parse_bitdepth_colorspace_sampling(BITSTREAM_PROFILE profile,
|
||||
struct vpx_read_bit_buffer *rb) {
|
||||
vpx_color_space_t color_space;
|
||||
if (profile >= PROFILE_2)
|
||||
rb->bit_offset += 1; // Bit-depth 10 or 12.
|
||||
if (profile >= PROFILE_2) rb->bit_offset += 1; // Bit-depth 10 or 12.
|
||||
color_space = (vpx_color_space_t)vpx_rb_read_literal(rb, 3);
|
||||
if (color_space != VPX_CS_SRGB) {
|
||||
rb->bit_offset += 1; // [16,235] (including xvycc) vs [0,255] range.
|
||||
@ -125,17 +125,13 @@ static int parse_bitdepth_colorspace_sampling(
|
||||
return 1;
|
||||
}
|
||||
|
||||
static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
|
||||
unsigned int data_sz,
|
||||
vpx_codec_stream_info_t *si,
|
||||
int *is_intra_only,
|
||||
vpx_decrypt_cb decrypt_cb,
|
||||
void *decrypt_state) {
|
||||
static vpx_codec_err_t decoder_peek_si_internal(
|
||||
const uint8_t *data, unsigned int data_sz, vpx_codec_stream_info_t *si,
|
||||
int *is_intra_only, vpx_decrypt_cb decrypt_cb, void *decrypt_state) {
|
||||
int intra_only_flag = 0;
|
||||
uint8_t clear_buffer[10];
|
||||
|
||||
if (data + data_sz <= data)
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
if (data + data_sz <= data) return VPX_CODEC_INVALID_PARAM;
|
||||
|
||||
si->is_kf = 0;
|
||||
si->w = si->h = 0;
|
||||
@ -148,8 +144,7 @@ static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
|
||||
|
||||
// A maximum of 6 bits are needed to read the frame marker, profile and
|
||||
// show_existing_frame.
|
||||
if (data_sz < 1)
|
||||
return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
if (data_sz < 1) return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
|
||||
{
|
||||
int show_frame;
|
||||
@ -158,17 +153,14 @@ static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
|
||||
const int frame_marker = vpx_rb_read_literal(&rb, 2);
|
||||
const BITSTREAM_PROFILE profile = vp9_read_profile(&rb);
|
||||
|
||||
if (frame_marker != VP9_FRAME_MARKER)
|
||||
return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
if (frame_marker != VP9_FRAME_MARKER) return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
|
||||
if (profile >= MAX_PROFILES)
|
||||
return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
if (profile >= MAX_PROFILES) return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
|
||||
if (vpx_rb_read_bit(&rb)) { // show an existing frame
|
||||
// If profile is > 2 and show_existing_frame is true, then at least 1 more
|
||||
// byte (6+3=9 bits) is needed.
|
||||
if (profile > 2 && data_sz < 2)
|
||||
return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
if (profile > 2 && data_sz < 2) return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
vpx_rb_read_literal(&rb, 3); // Frame buffer to show.
|
||||
return VPX_CODEC_OK;
|
||||
}
|
||||
@ -176,16 +168,14 @@ static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
|
||||
// For the rest of the function, a maximum of 9 more bytes are needed
|
||||
// (computed by taking the maximum possible bits needed in each case). Note
|
||||
// that this has to be updated if we read any more bits in this function.
|
||||
if (data_sz < 10)
|
||||
return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
if (data_sz < 10) return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
|
||||
si->is_kf = !vpx_rb_read_bit(&rb);
|
||||
show_frame = vpx_rb_read_bit(&rb);
|
||||
error_resilient = vpx_rb_read_bit(&rb);
|
||||
|
||||
if (si->is_kf) {
|
||||
if (!vp9_read_sync_code(&rb))
|
||||
return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
if (!vp9_read_sync_code(&rb)) return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
|
||||
if (!parse_bitdepth_colorspace_sampling(profile, &rb))
|
||||
return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
@ -196,8 +186,7 @@ static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
|
||||
rb.bit_offset += error_resilient ? 0 : 2; // reset_frame_context
|
||||
|
||||
if (intra_only_flag) {
|
||||
if (!vp9_read_sync_code(&rb))
|
||||
return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
if (!vp9_read_sync_code(&rb)) return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
if (profile > PROFILE_0) {
|
||||
if (!parse_bitdepth_colorspace_sampling(profile, &rb))
|
||||
return VPX_CODEC_UNSUP_BITSTREAM;
|
||||
@ -207,8 +196,7 @@ static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_intra_only != NULL)
|
||||
*is_intra_only = intra_only_flag;
|
||||
if (is_intra_only != NULL) *is_intra_only = intra_only_flag;
|
||||
return VPX_CODEC_OK;
|
||||
}
|
||||
|
||||
@ -234,8 +222,8 @@ static void set_error_detail(vpx_codec_alg_priv_t *ctx,
|
||||
ctx->base.err_detail = error;
|
||||
}
|
||||
|
||||
static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx,
|
||||
const struct vpx_internal_error_info *error) {
|
||||
static vpx_codec_err_t update_error_state(
|
||||
vpx_codec_alg_priv_t *ctx, const struct vpx_internal_error_info *error) {
|
||||
if (error->error_code)
|
||||
set_error_detail(ctx, error->has_detail ? error->detail : NULL);
|
||||
|
||||
@ -278,10 +266,8 @@ static void set_default_ppflags(vp8_postproc_cfg_t *cfg) {
|
||||
cfg->noise_level = 0;
|
||||
}
|
||||
|
||||
static void set_ppflags(const vpx_codec_alg_priv_t *ctx,
|
||||
vp9_ppflags_t *flags) {
|
||||
flags->post_proc_flag =
|
||||
ctx->postproc_cfg.post_proc_flag;
|
||||
static void set_ppflags(const vpx_codec_alg_priv_t *ctx, vp9_ppflags_t *flags) {
|
||||
flags->post_proc_flag = ctx->postproc_cfg.post_proc_flag;
|
||||
|
||||
flags->deblocking_level = ctx->postproc_cfg.deblocking_level;
|
||||
flags->noise_level = ctx->postproc_cfg.noise_level;
|
||||
@ -292,10 +278,8 @@ static int frame_worker_hook(void *arg1, void *arg2) {
|
||||
const uint8_t *data = frame_worker_data->data;
|
||||
(void)arg2;
|
||||
|
||||
frame_worker_data->result =
|
||||
vp9_receive_compressed_data(frame_worker_data->pbi,
|
||||
frame_worker_data->data_size,
|
||||
&data);
|
||||
frame_worker_data->result = vp9_receive_compressed_data(
|
||||
frame_worker_data->pbi, frame_worker_data->data_size, &data);
|
||||
frame_worker_data->data_end = data;
|
||||
|
||||
if (frame_worker_data->pbi->frame_parallel_decode) {
|
||||
@ -344,8 +328,7 @@ static vpx_codec_err_t init_decoder(vpx_codec_alg_priv_t *ctx) {
|
||||
ctx->flushed = 0;
|
||||
|
||||
ctx->buffer_pool = (BufferPool *)vpx_calloc(1, sizeof(BufferPool));
|
||||
if (ctx->buffer_pool == NULL)
|
||||
return VPX_CODEC_MEM_ERROR;
|
||||
if (ctx->buffer_pool == NULL) return VPX_CODEC_MEM_ERROR;
|
||||
|
||||
#if CONFIG_MULTITHREAD
|
||||
if (pthread_mutex_init(&ctx->buffer_pool->pool_mutex, NULL)) {
|
||||
@ -354,8 +337,8 @@ static vpx_codec_err_t init_decoder(vpx_codec_alg_priv_t *ctx) {
|
||||
}
|
||||
#endif
|
||||
|
||||
ctx->frame_workers = (VPxWorker *)
|
||||
vpx_malloc(ctx->num_frame_workers * sizeof(*ctx->frame_workers));
|
||||
ctx->frame_workers = (VPxWorker *)vpx_malloc(ctx->num_frame_workers *
|
||||
sizeof(*ctx->frame_workers));
|
||||
if (ctx->frame_workers == NULL) {
|
||||
set_error_detail(ctx, "Failed to allocate frame_workers");
|
||||
return VPX_CODEC_MEM_ERROR;
|
||||
@ -411,8 +394,7 @@ static vpx_codec_err_t init_decoder(vpx_codec_alg_priv_t *ctx) {
|
||||
|
||||
// If postprocessing was enabled by the application and a
|
||||
// configuration has not been provided, default it.
|
||||
if (!ctx->postproc_cfg_set &&
|
||||
(ctx->base.init_flags & VPX_CODEC_USE_POSTPROC))
|
||||
if (!ctx->postproc_cfg_set && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC))
|
||||
set_default_ppflags(&ctx->postproc_cfg);
|
||||
|
||||
init_buffer_callbacks(ctx);
|
||||
@ -442,11 +424,9 @@ static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx,
|
||||
const vpx_codec_err_t res =
|
||||
decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only,
|
||||
ctx->decrypt_cb, ctx->decrypt_state);
|
||||
if (res != VPX_CODEC_OK)
|
||||
return res;
|
||||
if (res != VPX_CODEC_OK) return res;
|
||||
|
||||
if (!ctx->si.is_kf && !is_intra_only)
|
||||
return VPX_CODEC_ERROR;
|
||||
if (!ctx->si.is_kf && !is_intra_only) return VPX_CODEC_ERROR;
|
||||
}
|
||||
|
||||
if (!ctx->frame_parallel_decode) {
|
||||
@ -541,8 +521,7 @@ static void wait_worker_and_cache_frame(vpx_codec_alg_priv_t *ctx) {
|
||||
frame_worker_data->user_priv);
|
||||
ctx->frame_cache[ctx->frame_cache_write].img.fb_priv =
|
||||
frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv;
|
||||
ctx->frame_cache_write =
|
||||
(ctx->frame_cache_write + 1) % FRAME_CACHE_SIZE;
|
||||
ctx->frame_cache_write = (ctx->frame_cache_write + 1) % FRAME_CACHE_SIZE;
|
||||
++ctx->num_cache_frames;
|
||||
}
|
||||
}
|
||||
@ -567,14 +546,12 @@ static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
|
||||
// Initialize the decoder workers on the first frame.
|
||||
if (ctx->frame_workers == NULL) {
|
||||
const vpx_codec_err_t res = init_decoder(ctx);
|
||||
if (res != VPX_CODEC_OK)
|
||||
return res;
|
||||
if (res != VPX_CODEC_OK) return res;
|
||||
}
|
||||
|
||||
res = vp9_parse_superframe_index(data, data_sz, frame_sizes, &frame_count,
|
||||
ctx->decrypt_cb, ctx->decrypt_state);
|
||||
if (res != VPX_CODEC_OK)
|
||||
return res;
|
||||
if (res != VPX_CODEC_OK) return res;
|
||||
|
||||
if (ctx->frame_parallel_decode) {
|
||||
// Decode in frame parallel mode. When decoding in this mode, the frame
|
||||
@ -587,8 +564,8 @@ static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
|
||||
for (i = 0; i < frame_count; ++i) {
|
||||
const uint8_t *data_start_copy = data_start;
|
||||
const uint32_t frame_size = frame_sizes[i];
|
||||
if (data_start < data
|
||||
|| frame_size > (uint32_t) (data_end - data_start)) {
|
||||
if (data_start < data ||
|
||||
frame_size > (uint32_t)(data_end - data_start)) {
|
||||
set_error_detail(ctx, "Invalid frame size in index");
|
||||
return VPX_CODEC_CORRUPT_FRAME;
|
||||
}
|
||||
@ -605,10 +582,9 @@ static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
|
||||
}
|
||||
}
|
||||
|
||||
res = decode_one(ctx, &data_start_copy, frame_size, user_priv,
|
||||
deadline);
|
||||
if (res != VPX_CODEC_OK)
|
||||
return res;
|
||||
res =
|
||||
decode_one(ctx, &data_start_copy, frame_size, user_priv, deadline);
|
||||
if (res != VPX_CODEC_OK) return res;
|
||||
data_start += frame_size;
|
||||
}
|
||||
} else {
|
||||
@ -625,8 +601,7 @@ static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
|
||||
}
|
||||
|
||||
res = decode_one(ctx, &data, data_sz, user_priv, deadline);
|
||||
if (res != VPX_CODEC_OK)
|
||||
return res;
|
||||
if (res != VPX_CODEC_OK) return res;
|
||||
}
|
||||
} else {
|
||||
// Decode in serial mode.
|
||||
@ -637,33 +612,30 @@ static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
|
||||
const uint8_t *data_start_copy = data_start;
|
||||
const uint32_t frame_size = frame_sizes[i];
|
||||
vpx_codec_err_t res;
|
||||
if (data_start < data
|
||||
|| frame_size > (uint32_t) (data_end - data_start)) {
|
||||
if (data_start < data ||
|
||||
frame_size > (uint32_t)(data_end - data_start)) {
|
||||
set_error_detail(ctx, "Invalid frame size in index");
|
||||
return VPX_CODEC_CORRUPT_FRAME;
|
||||
}
|
||||
|
||||
res = decode_one(ctx, &data_start_copy, frame_size, user_priv,
|
||||
deadline);
|
||||
if (res != VPX_CODEC_OK)
|
||||
return res;
|
||||
res =
|
||||
decode_one(ctx, &data_start_copy, frame_size, user_priv, deadline);
|
||||
if (res != VPX_CODEC_OK) return res;
|
||||
|
||||
data_start += frame_size;
|
||||
}
|
||||
} else {
|
||||
while (data_start < data_end) {
|
||||
const uint32_t frame_size = (uint32_t)(data_end - data_start);
|
||||
const vpx_codec_err_t res = decode_one(ctx, &data_start, frame_size,
|
||||
user_priv, deadline);
|
||||
if (res != VPX_CODEC_OK)
|
||||
return res;
|
||||
const vpx_codec_err_t res =
|
||||
decode_one(ctx, &data_start, frame_size, user_priv, deadline);
|
||||
if (res != VPX_CODEC_OK) return res;
|
||||
|
||||
// Account for suboptimal termination by the encoder.
|
||||
while (data_start < data_end) {
|
||||
const uint8_t marker = read_marker(ctx->decrypt_cb,
|
||||
ctx->decrypt_state, data_start);
|
||||
if (marker)
|
||||
break;
|
||||
const uint8_t marker =
|
||||
read_marker(ctx->decrypt_cb, ctx->decrypt_state, data_start);
|
||||
if (marker) break;
|
||||
++data_start;
|
||||
}
|
||||
}
|
||||
@ -699,8 +671,7 @@ static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx,
|
||||
if (ctx->num_cache_frames > 0) {
|
||||
release_last_output_frame(ctx);
|
||||
ctx->last_show_frame = ctx->frame_cache[ctx->frame_cache_read].fb_idx;
|
||||
if (ctx->need_resync)
|
||||
return NULL;
|
||||
if (ctx->need_resync) return NULL;
|
||||
img = &ctx->frame_cache[ctx->frame_cache_read].img;
|
||||
ctx->frame_cache_read = (ctx->frame_cache_read + 1) % FRAME_CACHE_SIZE;
|
||||
--ctx->num_cache_frames;
|
||||
@ -714,8 +685,7 @@ static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx,
|
||||
YV12_BUFFER_CONFIG sd;
|
||||
vp9_ppflags_t flags = { 0, 0, 0 };
|
||||
const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
|
||||
VPxWorker *const worker =
|
||||
&ctx->frame_workers[ctx->next_output_worker_id];
|
||||
VPxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
|
||||
FrameWorkerData *const frame_worker_data =
|
||||
(FrameWorkerData *)worker->data1;
|
||||
ctx->next_output_worker_id =
|
||||
@ -735,8 +705,7 @@ static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx,
|
||||
RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
|
||||
release_last_output_frame(ctx);
|
||||
ctx->last_show_frame = frame_worker_data->pbi->common.new_fb_idx;
|
||||
if (ctx->need_resync)
|
||||
return NULL;
|
||||
if (ctx->need_resync) return NULL;
|
||||
yuvconfig2image(&ctx->img, &sd, frame_worker_data->user_priv);
|
||||
ctx->img.fb_priv = frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv;
|
||||
img = &ctx->img;
|
||||
@ -747,8 +716,7 @@ static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx,
|
||||
frame_worker_data->received_frame = 0;
|
||||
++ctx->available_threads;
|
||||
ctx->need_resync = 1;
|
||||
if (ctx->flushed != 1)
|
||||
return NULL;
|
||||
if (ctx->flushed != 1) return NULL;
|
||||
}
|
||||
} while (ctx->next_output_worker_id != ctx->next_submit_worker_id);
|
||||
}
|
||||
@ -756,8 +724,7 @@ static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx,
|
||||
}
|
||||
|
||||
static vpx_codec_err_t decoder_set_fb_fn(
|
||||
vpx_codec_alg_priv_t *ctx,
|
||||
vpx_get_frame_buffer_cb_fn_t cb_get,
|
||||
vpx_codec_alg_priv_t *ctx, vpx_get_frame_buffer_cb_fn_t cb_get,
|
||||
vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
|
||||
if (cb_get == NULL || cb_release == NULL) {
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
@ -1022,8 +989,7 @@ static vpx_codec_err_t ctrl_set_byte_alignment(vpx_codec_alg_priv_t *ctx,
|
||||
ctx->byte_alignment = byte_alignment;
|
||||
if (ctx->frame_workers) {
|
||||
VPxWorker *const worker = ctx->frame_workers;
|
||||
FrameWorkerData *const frame_worker_data =
|
||||
(FrameWorkerData *)worker->data1;
|
||||
FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
|
||||
frame_worker_data->pbi->common.byte_alignment = byte_alignment;
|
||||
}
|
||||
return VPX_CODEC_OK;
|
||||
@ -1079,14 +1045,16 @@ CODEC_INTERFACE(vpx_codec_vp9_dx) = {
|
||||
decoder_init, // vpx_codec_init_fn_t
|
||||
decoder_destroy, // vpx_codec_destroy_fn_t
|
||||
decoder_ctrl_maps, // vpx_codec_ctrl_fn_map_t
|
||||
{ // NOLINT
|
||||
{
|
||||
// NOLINT
|
||||
decoder_peek_si, // vpx_codec_peek_si_fn_t
|
||||
decoder_get_si, // vpx_codec_get_si_fn_t
|
||||
decoder_decode, // vpx_codec_decode_fn_t
|
||||
decoder_get_frame, // vpx_codec_frame_get_fn_t
|
||||
decoder_set_fb_fn, // vpx_codec_set_fb_fn_t
|
||||
},
|
||||
{ // NOLINT
|
||||
{
|
||||
// NOLINT
|
||||
0,
|
||||
NULL, // vpx_codec_enc_cfg_map_t
|
||||
NULL, // vpx_codec_encode_fn_t
|
||||
|
@ -91,10 +91,10 @@ static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
|
||||
yv12->y_width = img->d_w;
|
||||
yv12->y_height = img->d_h;
|
||||
|
||||
yv12->uv_width = img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2
|
||||
: yv12->y_width;
|
||||
yv12->uv_height = img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2
|
||||
: yv12->y_height;
|
||||
yv12->uv_width =
|
||||
img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2 : yv12->y_width;
|
||||
yv12->uv_height =
|
||||
img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2 : yv12->y_height;
|
||||
yv12->uv_crop_width = yv12->uv_width;
|
||||
yv12->uv_crop_height = yv12->uv_height;
|
||||
|
||||
@ -135,12 +135,9 @@ static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
|
||||
|
||||
static VP9_REFFRAME ref_frame_to_vp9_reframe(vpx_ref_frame_type_t frame) {
|
||||
switch (frame) {
|
||||
case VP8_LAST_FRAME:
|
||||
return VP9_LAST_FLAG;
|
||||
case VP8_GOLD_FRAME:
|
||||
return VP9_GOLD_FLAG;
|
||||
case VP8_ALTR_FRAME:
|
||||
return VP9_ALT_FLAG;
|
||||
case VP8_LAST_FRAME: return VP9_LAST_FLAG;
|
||||
case VP8_GOLD_FRAME: return VP9_GOLD_FLAG;
|
||||
case VP8_ALTR_FRAME: return VP9_ALT_FLAG;
|
||||
}
|
||||
assert(0 && "Invalid Reference Frame");
|
||||
return VP9_LAST_FLAG;
|
||||
|
Loading…
x
Reference in New Issue
Block a user