@ -1986,7 +1986,7 @@ static int decode_coeffs_b(VP56RangeCoder *c, int16_t *coef, int n_coeffs,
return i ;
return i ;
}
}
static int decode_coeffs ( AVCodecContext * ctx )
static void decode_coeffs ( AVCodecContext * ctx )
{
{
VP9Context * s = ctx - > priv_data ;
VP9Context * s = ctx - > priv_data ;
VP9Block * b = s - > b ;
VP9Block * b = s - > b ;
@ -2031,10 +2031,9 @@ static int decode_coeffs(AVCodecContext *ctx)
b - > bs > BS_8x8 ?
b - > bs > BS_8x8 ?
n : 0 ] ] ;
n : 0 ] ] ;
int nnz = a [ x ] + l [ y ] ;
int nnz = a [ x ] + l [ y ] ;
if ( ( res = decode_coeffs_b ( & s - > c , s - > block + 16 * n , 16 * step ,
res = decode_coeffs_b ( & s - > c , s - > block + 16 * n , 16 * step ,
b - > tx , c , e , p , nnz , yscans [ txtp ] ,
b - > tx , c , e , p , nnz , yscans [ txtp ] ,
ynbs [ txtp ] , y_band_counts , qmul [ 0 ] ) ) < 0 )
ynbs [ txtp ] , y_band_counts , qmul [ 0 ] ) ;
return res ;
a [ x ] = l [ y ] = ! ! res ;
a [ x ] = l [ y ] = ! ! res ;
if ( b - > tx > TX_8X8 ) {
if ( b - > tx > TX_8X8 ) {
AV_WN16A ( & s - > eob [ n ] , res ) ;
AV_WN16A ( & s - > eob [ n ] , res ) ;
@ -2071,11 +2070,9 @@ static int decode_coeffs(AVCodecContext *ctx)
for ( n = 0 , y = 0 ; y < end_y ; y + = uvstep1d ) {
for ( n = 0 , y = 0 ; y < end_y ; y + = uvstep1d ) {
for ( x = 0 ; x < end_x ; x + = uvstep1d , n + = uvstep ) {
for ( x = 0 ; x < end_x ; x + = uvstep1d , n + = uvstep ) {
int nnz = a [ x ] + l [ y ] ;
int nnz = a [ x ] + l [ y ] ;
if ( ( res = decode_coeffs_b ( & s - > c , s - > uvblock [ pl ] + 16 * n ,
res = decode_coeffs_b ( & s - > c , s - > uvblock [ pl ] + 16 * n ,
16 * uvstep , b - > uvtx , c , e , p , nnz ,
16 * uvstep , b - > uvtx , c , e , p , nnz ,
uvscan , uvnb , uv_band_counts ,
uvscan , uvnb , uv_band_counts , qmul [ 1 ] ) ;
qmul [ 1 ] ) ) < 0 )
return res ;
a [ x ] = l [ y ] = ! ! res ;
a [ x ] = l [ y ] = ! ! res ;
if ( b - > uvtx > TX_8X8 ) {
if ( b - > uvtx > TX_8X8 ) {
AV_WN16A ( & s - > uveob [ pl ] [ n ] , res ) ;
AV_WN16A ( & s - > uveob [ pl ] [ n ] , res ) ;
@ -2091,8 +2088,6 @@ static int decode_coeffs(AVCodecContext *ctx)
memset ( & a [ x + 1 ] , a [ x ] , FFMIN ( end_x - x - 1 , uvstep1d - 1 ) ) ;
memset ( & a [ x + 1 ] , a [ x ] , FFMIN ( end_x - x - 1 , uvstep1d - 1 ) ) ;
}
}
}
}
return 0 ;
}
}
static av_always_inline int check_intra_mode ( VP9Context * s , int mode , uint8_t * * a ,
static av_always_inline int check_intra_mode ( VP9Context * s , int mode , uint8_t * * a ,
@ -2696,14 +2691,14 @@ static av_always_inline void mask_edges(struct VP9Filter *lflvl, int is_uv,
}
}
}
}
static int decode_b ( AVCodecContext * ctx , int row , int col ,
static void decode_b ( AVCodecContext * ctx , int row , int col ,
struct VP9Filter * lflvl , ptrdiff_t yoff , ptrdiff_t uvoff ,
struct VP9Filter * lflvl , ptrdiff_t yoff , ptrdiff_t uvoff ,
enum BlockLevel bl , enum BlockPartition bp )
enum BlockLevel bl , enum BlockPartition bp )
{
{
VP9Context * s = ctx - > priv_data ;
VP9Context * s = ctx - > priv_data ;
VP9Block * b = s - > b ;
VP9Block * b = s - > b ;
enum BlockSize bs = bl * 3 + bp ;
enum BlockSize bs = bl * 3 + bp ;
int res , y , w4 = bwh_tab [ 1 ] [ bs ] [ 0 ] , h4 = bwh_tab [ 1 ] [ bs ] [ 1 ] , lvl ;
int y , w4 = bwh_tab [ 1 ] [ bs ] [ 0 ] , h4 = bwh_tab [ 1 ] [ bs ] [ 1 ] , lvl ;
int emu [ 2 ] ;
int emu [ 2 ] ;
AVFrame * f = s - > frames [ CUR_FRAME ] . tf . f ;
AVFrame * f = s - > frames [ CUR_FRAME ] . tf . f ;
@ -2723,8 +2718,7 @@ static int decode_b(AVCodecContext *ctx, int row, int col,
b - > uvtx = b - > tx - ( w4 * 2 = = ( 1 < < b - > tx ) | | h4 * 2 = = ( 1 < < b - > tx ) ) ;
b - > uvtx = b - > tx - ( w4 * 2 = = ( 1 < < b - > tx ) | | h4 * 2 = = ( 1 < < b - > tx ) ) ;
if ( ! b - > skip ) {
if ( ! b - > skip ) {
if ( ( res = decode_coeffs ( ctx ) ) < 0 )
decode_coeffs ( ctx ) ;
return res ;
} else {
} else {
int pl ;
int pl ;
@ -2744,7 +2738,7 @@ static int decode_b(AVCodecContext *ctx, int row, int col,
s - > uveob [ 0 ] + = w4 * h4 ;
s - > uveob [ 0 ] + = w4 * h4 ;
s - > uveob [ 1 ] + = w4 * h4 ;
s - > uveob [ 1 ] + = w4 * h4 ;
return 0 ;
return ;
}
}
}
}
@ -2846,16 +2840,14 @@ static int decode_b(AVCodecContext *ctx, int row, int col,
s - > uveob [ 0 ] + = w4 * h4 ;
s - > uveob [ 0 ] + = w4 * h4 ;
s - > uveob [ 1 ] + = w4 * h4 ;
s - > uveob [ 1 ] + = w4 * h4 ;
}
}
return 0 ;
}
}
static int decode_sb ( AVCodecContext * ctx , int row , int col , struct VP9Filter * lflvl ,
static void decode_sb ( AVCodecContext * ctx , int row , int col , struct VP9Filter * lflvl ,
ptrdiff_t yoff , ptrdiff_t uvoff , enum BlockLevel bl )
ptrdiff_t yoff , ptrdiff_t uvoff , enum BlockLevel bl )
{
{
VP9Context * s = ctx - > priv_data ;
VP9Context * s = ctx - > priv_data ;
int c = ( ( s - > above_partition_ctx [ col ] > > ( 3 - bl ) ) & 1 ) |
int c = ( ( s - > above_partition_ctx [ col ] > > ( 3 - bl ) ) & 1 ) |
( ( ( s - > left_partition_ctx [ row & 0x7 ] > > ( 3 - bl ) ) & 1 ) < < 1 ) , res ;
( ( ( s - > left_partition_ctx [ row & 0x7 ] > > ( 3 - bl ) ) & 1 ) < < 1 ) ;
const uint8_t * p = s - > keyframe ? vp9_default_kf_partition_probs [ bl ] [ c ] :
const uint8_t * p = s - > keyframe ? vp9_default_kf_partition_probs [ bl ] [ c ] :
s - > prob . p . partition [ bl ] [ c ] ;
s - > prob . p . partition [ bl ] [ c ] ;
enum BlockPartition bp ;
enum BlockPartition bp ;
@ -2865,128 +2857,111 @@ static int decode_sb(AVCodecContext *ctx, int row, int col, struct VP9Filter *lf
if ( bl = = BL_8X8 ) {
if ( bl = = BL_8X8 ) {
bp = vp8_rac_get_tree ( & s - > c , vp9_partition_tree , p ) ;
bp = vp8_rac_get_tree ( & s - > c , vp9_partition_tree , p ) ;
res = decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ;
decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ;
} else if ( col + hbs < s - > cols ) { // FIXME why not <=?
} else if ( col + hbs < s - > cols ) { // FIXME why not <=?
if ( row + hbs < s - > rows ) { // FIXME why not <=?
if ( row + hbs < s - > rows ) { // FIXME why not <=?
bp = vp8_rac_get_tree ( & s - > c , vp9_partition_tree , p ) ;
bp = vp8_rac_get_tree ( & s - > c , vp9_partition_tree , p ) ;
switch ( bp ) {
switch ( bp ) {
case PARTITION_NONE :
case PARTITION_NONE :
res = decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ;
decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ;
break ;
break ;
case PARTITION_H :
case PARTITION_H :
if ( ! ( res = decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ) ) {
decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ;
yoff + = hbs * 8 * y_stride ;
yoff + = hbs * 8 * y_stride ;
uvoff + = hbs * 4 * uv_stride ;
uvoff + = hbs * 4 * uv_stride ;
res = decode_b ( ctx , row + hbs , col , lflvl , yoff , uvoff , bl , bp ) ;
decode_b ( ctx , row + hbs , col , lflvl , yoff , uvoff , bl , bp ) ;
}
break ;
break ;
case PARTITION_V :
case PARTITION_V :
if ( ! ( res = decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ) ) {
decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ;
yoff + = hbs * 8 ;
yoff + = hbs * 8 ;
uvoff + = hbs * 4 ;
uvoff + = hbs * 4 ;
res = decode_b ( ctx , row , col + hbs , lflvl , yoff , uvoff , bl , bp ) ;
decode_b ( ctx , row , col + hbs , lflvl , yoff , uvoff , bl , bp ) ;
}
break ;
break ;
case PARTITION_SPLIT :
case PARTITION_SPLIT :
if ( ! ( res = decode_sb ( ctx , row , col , lflvl , yoff , uvoff , bl + 1 ) ) ) {
decode_sb ( ctx , row , col , lflvl , yoff , uvoff , bl + 1 ) ;
if ( ! ( res = decode_sb ( ctx , row , col + hbs , lflvl ,
decode_sb ( ctx , row , col + hbs , lflvl ,
yoff + 8 * hbs , uvoff + 4 * hbs , bl + 1 ) ) ) {
yoff + 8 * hbs , uvoff + 4 * hbs , bl + 1 ) ;
yoff + = hbs * 8 * y_stride ;
yoff + = hbs * 8 * y_stride ;
uvoff + = hbs * 4 * uv_stride ;
uvoff + = hbs * 4 * uv_stride ;
if ( ! ( res = decode_sb ( ctx , row + hbs , col , lflvl ,
decode_sb ( ctx , row + hbs , col , lflvl , yoff , uvoff , bl + 1 ) ;
yoff , uvoff , bl + 1 ) ) )
decode_sb ( ctx , row + hbs , col + hbs , lflvl ,
res = decode_sb ( ctx , row + hbs , col + hbs , lflvl ,
yoff + 8 * hbs , uvoff + 4 * hbs , bl + 1 ) ;
yoff + 8 * hbs , uvoff + 4 * hbs , bl + 1 ) ;
}
}
break ;
break ;
default :
default :
av_assert0 ( 0 ) ;
av_assert0 ( 0 ) ;
}
}
} else if ( vp56_rac_get_prob_branchy ( & s - > c , p [ 1 ] ) ) {
} else if ( vp56_rac_get_prob_branchy ( & s - > c , p [ 1 ] ) ) {
bp = PARTITION_SPLIT ;
bp = PARTITION_SPLIT ;
if ( ! ( res = decode_sb ( ctx , row , col , lflvl , yoff , uvoff , bl + 1 ) ) )
decode_sb ( ctx , row , col , lflvl , yoff , uvoff , bl + 1 ) ;
res = decode_sb ( ctx , row , col + hbs , lflvl ,
decode_sb ( ctx , row , col + hbs , lflvl ,
yoff + 8 * hbs , uvoff + 4 * hbs , bl + 1 ) ;
yoff + 8 * hbs , uvoff + 4 * hbs , bl + 1 ) ;
} else {
} else {
bp = PARTITION_H ;
bp = PARTITION_H ;
res = decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ;
decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ;
}
}
} else if ( row + hbs < s - > rows ) { // FIXME why not <=?
} else if ( row + hbs < s - > rows ) { // FIXME why not <=?
if ( vp56_rac_get_prob_branchy ( & s - > c , p [ 2 ] ) ) {
if ( vp56_rac_get_prob_branchy ( & s - > c , p [ 2 ] ) ) {
bp = PARTITION_SPLIT ;
bp = PARTITION_SPLIT ;
if ( ! ( res = decode_sb ( ctx , row , col , lflvl , yoff , uvoff , bl + 1 ) ) ) {
decode_sb ( ctx , row , col , lflvl , yoff , uvoff , bl + 1 ) ;
yoff + = hbs * 8 * y_stride ;
yoff + = hbs * 8 * y_stride ;
uvoff + = hbs * 4 * uv_stride ;
uvoff + = hbs * 4 * uv_stride ;
res = decode_sb ( ctx , row + hbs , col , lflvl ,
decode_sb ( ctx , row + hbs , col , lflvl , yoff , uvoff , bl + 1 ) ;
yoff , uvoff , bl + 1 ) ;
}
} else {
} else {
bp = PARTITION_V ;
bp = PARTITION_V ;
res = decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ;
decode_b ( ctx , row , col , lflvl , yoff , uvoff , bl , bp ) ;
}
}
} else {
} else {
bp = PARTITION_SPLIT ;
bp = PARTITION_SPLIT ;
res = decode_sb ( ctx , row , col , lflvl , yoff , uvoff , bl + 1 ) ;
decode_sb ( ctx , row , col , lflvl , yoff , uvoff , bl + 1 ) ;
}
}
s - > counts . partition [ bl ] [ c ] [ bp ] + + ;
s - > counts . partition [ bl ] [ c ] [ bp ] + + ;
return res ;
}
}
static int decode_sb_mem ( AVCodecContext * ctx , int row , int col , struct VP9Filter * lflvl ,
static void decode_sb_mem ( AVCodecContext * ctx , int row , int col , struct VP9Filter * lflvl ,
ptrdiff_t yoff , ptrdiff_t uvoff , enum BlockLevel bl )
ptrdiff_t yoff , ptrdiff_t uvoff , enum BlockLevel bl )
{
{
VP9Context * s = ctx - > priv_data ;
VP9Context * s = ctx - > priv_data ;
VP9Block * b = s - > b ;
VP9Block * b = s - > b ;
ptrdiff_t hbs = 4 > > bl ;
ptrdiff_t hbs = 4 > > bl ;
AVFrame * f = s - > frames [ CUR_FRAME ] . tf . f ;
AVFrame * f = s - > frames [ CUR_FRAME ] . tf . f ;
ptrdiff_t y_stride = f - > linesize [ 0 ] , uv_stride = f - > linesize [ 1 ] ;
ptrdiff_t y_stride = f - > linesize [ 0 ] , uv_stride = f - > linesize [ 1 ] ;
int res ;
if ( bl = = BL_8X8 ) {
if ( bl = = BL_8X8 ) {
av_assert2 ( b - > bl = = BL_8X8 ) ;
av_assert2 ( b - > bl = = BL_8X8 ) ;
res = decode_b ( ctx , row , col , lflvl , yoff , uvoff , b - > bl , b - > bp ) ;
decode_b ( ctx , row , col , lflvl , yoff , uvoff , b - > bl , b - > bp ) ;
} else if ( s - > b - > bl = = bl ) {
} else if ( s - > b - > bl = = bl ) {
if ( ( res = decode_b ( ctx , row , col , lflvl , yoff , uvoff , b - > bl , b - > bp ) ) < 0 )
decode_b ( ctx , row , col , lflvl , yoff , uvoff , b - > bl , b - > bp ) ;
return res ;
if ( b - > bp = = PARTITION_H & & row + hbs < s - > rows ) {
if ( b - > bp = = PARTITION_H & & row + hbs < s - > rows ) {
yoff + = hbs * 8 * y_stride ;
yoff + = hbs * 8 * y_stride ;
uvoff + = hbs * 4 * uv_stride ;
uvoff + = hbs * 4 * uv_stride ;
res = decode_b ( ctx , row + hbs , col , lflvl , yoff , uvoff , b - > bl , b - > bp ) ;
decode_b ( ctx , row + hbs , col , lflvl , yoff , uvoff , b - > bl , b - > bp ) ;
} else if ( b - > bp = = PARTITION_V & & col + hbs < s - > cols ) {
} else if ( b - > bp = = PARTITION_V & & col + hbs < s - > cols ) {
yoff + = hbs * 8 ;
yoff + = hbs * 8 ;
uvoff + = hbs * 4 ;
uvoff + = hbs * 4 ;
res = decode_b ( ctx , row , col + hbs , lflvl , yoff , uvoff , b - > bl , b - > bp ) ;
decode_b ( ctx , row , col + hbs , lflvl , yoff , uvoff , b - > bl , b - > bp ) ;
}
}
} else {
} else {
if ( ( res = decode_sb_mem ( ctx , row , col , lflvl , yoff , uvoff , bl + 1 ) ) < 0 )
decode_sb_mem ( ctx , row , col , lflvl , yoff , uvoff , bl + 1 ) ;
return res ;
if ( col + hbs < s - > cols ) { // FIXME why not <=?
if ( col + hbs < s - > cols ) { // FIXME why not <=?
if ( row + hbs < s - > rows ) {
if ( row + hbs < s - > rows ) {
if ( ( res = decode_sb_mem ( ctx , row , col + hbs , lflvl , yoff + 8 * hbs ,
decode_sb_mem ( ctx , row , col + hbs , lflvl , yoff + 8 * hbs ,
uvoff + 4 * hbs , bl + 1 ) ) < 0 )
uvoff + 4 * hbs , bl + 1 ) ;
return res ;
yoff + = hbs * 8 * y_stride ;
yoff + = hbs * 8 * y_stride ;
uvoff + = hbs * 4 * uv_stride ;
uvoff + = hbs * 4 * uv_stride ;
if ( ( res = decode_sb_mem ( ctx , row + hbs , col , lflvl , yoff ,
decode_sb_mem ( ctx , row + hbs , col , lflvl , yoff , uvoff , bl + 1 ) ;
uvoff , bl + 1 ) ) < 0 )
decode_sb_mem ( ctx , row + hbs , col + hbs , lflvl ,
return res ;
res = decode_sb_mem ( ctx , row + hbs , col + hbs , lflvl ,
yoff + 8 * hbs , uvoff + 4 * hbs , bl + 1 ) ;
yoff + 8 * hbs , uvoff + 4 * hbs , bl + 1 ) ;
} else {
} else {
yoff + = hbs * 8 ;
yoff + = hbs * 8 ;
uvoff + = hbs * 4 ;
uvoff + = hbs * 4 ;
res = decode_sb_mem ( ctx , row , col + hbs , lflvl , yoff , uvoff , bl + 1 ) ;
decode_sb_mem ( ctx , row , col + hbs , lflvl , yoff , uvoff , bl + 1 ) ;
}
}
} else if ( row + hbs < s - > rows ) {
} else if ( row + hbs < s - > rows ) {
yoff + = hbs * 8 * y_stride ;
yoff + = hbs * 8 * y_stride ;
uvoff + = hbs * 4 * uv_stride ;
uvoff + = hbs * 4 * uv_stride ;
res = decode_sb_mem ( ctx , row + hbs , col , lflvl , yoff , uvoff , bl + 1 ) ;
decode_sb_mem ( ctx , row + hbs , col , lflvl , yoff , uvoff , bl + 1 ) ;
}
}
}
}
return res ;
}
}
static void loopfilter_sb ( AVCodecContext * ctx , struct VP9Filter * lflvl ,
static void loopfilter_sb ( AVCodecContext * ctx , struct VP9Filter * lflvl ,
@ -3652,15 +3627,11 @@ static int vp9_decode_frame(AVCodecContext *ctx, void *frame,
}
}
if ( s - > pass = = 2 ) {
if ( s - > pass = = 2 ) {
res = decode_sb_mem ( ctx , row , col , lflvl_ptr ,
decode_sb_mem ( ctx , row , col , lflvl_ptr ,
yoff2 , uvoff2 , BL_64X64 ) ;
yoff2 , uvoff2 , BL_64X64 ) ;
} else {
} else {
res = decode_sb ( ctx , row , col , lflvl_ptr ,
decode_sb ( ctx , row , col , lflvl_ptr ,
yoff2 , uvoff2 , BL_64X64 ) ;
yoff2 , uvoff2 , BL_64X64 ) ;
}
if ( res < 0 ) {
ff_thread_report_progress ( & s - > frames [ CUR_FRAME ] . tf , INT_MAX , 0 ) ;
return res ;
}
}
}
}
if ( s - > pass ! = 2 ) {
if ( s - > pass ! = 2 ) {