* Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
* Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
*
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "bitstream.h"
#include "golomb.h"
#include "mpegvideo.h"
+#include "cavs.h"
#include "cavsdata.h"
typedef struct {
int qp;
int qp_fixed;
int cbp;
+ ScanTable scantable;
/** intra prediction is done with un-deblocked samples
they are saved here before deblocking the MB */
uint8_t *top_border_y, *top_border_u, *top_border_v;
- uint8_t left_border_y[16], left_border_u[10], left_border_v[10];
+ uint8_t left_border_y[26], left_border_u[10], left_border_v[10];
+ uint8_t intern_border_y[26];
uint8_t topleft_border_y, topleft_border_u, topleft_border_v;
void (*intra_pred_l[8])(uint8_t *d,uint8_t *top,uint8_t *left,int stride);
int scale_den[2]; ///< for scaling neighbouring MVs
int got_keyframe;
+ DCTELEM *block;
} AVSContext;
/*****************************************************************************
}
#define SET_PARAMS \
- alpha = alpha_tab[clip(qp_avg + h->alpha_offset,0,63)]; \
- beta = beta_tab[clip(qp_avg + h->beta_offset, 0,63)]; \
- tc = tc_tab[clip(qp_avg + h->alpha_offset,0,63)];
+ alpha = alpha_tab[av_clip(qp_avg + h->alpha_offset,0,63)]; \
+ beta = beta_tab[av_clip(qp_avg + h->beta_offset, 0,63)]; \
+ tc = tc_tab[av_clip(qp_avg + h->alpha_offset,0,63)];
/**
* in-loop deblocking filter for a single macroblock
memcpy(&h->top_border_u[h->mbx*10+1], h->cu + 7* h->c_stride,8);
memcpy(&h->top_border_v[h->mbx*10+1], h->cv + 7* h->c_stride,8);
for(i=0;i<8;i++) {
- h->left_border_y[i*2+0] = *(h->cy + 15 + (i*2+0)*h->l_stride);
- h->left_border_y[i*2+1] = *(h->cy + 15 + (i*2+1)*h->l_stride);
+ h->left_border_y[i*2+1] = *(h->cy + 15 + (i*2+0)*h->l_stride);
+ h->left_border_y[i*2+2] = *(h->cy + 15 + (i*2+1)*h->l_stride);
h->left_border_u[i+1] = *(h->cu + 7 + i*h->c_stride);
h->left_border_v[i+1] = *(h->cv + 7 + i*h->c_stride);
}
****************************************************************************/
static inline void load_intra_pred_luma(AVSContext *h, uint8_t *top,
- uint8_t *left, int block) {
+ uint8_t **left, int block) {
int i;
switch(block) {
case 0:
- memcpy(&left[1],h->left_border_y,16);
- left[0] = left[1];
- left[17] = left[16];
+ *left = h->left_border_y;
+ h->left_border_y[0] = h->left_border_y[1];
+ memset(&h->left_border_y[17],h->left_border_y[16],9);
memcpy(&top[1],&h->top_border_y[h->mbx*16],16);
top[17] = top[16];
top[0] = top[1];
if((h->flags & A_AVAIL) && (h->flags & B_AVAIL))
- left[0] = top[0] = h->topleft_border_y;
+ h->left_border_y[0] = top[0] = h->topleft_border_y;
break;
case 1:
+ *left = h->intern_border_y;
for(i=0;i<8;i++)
- left[i+1] = *(h->cy + 7 + i*h->l_stride);
- memset(&left[9],left[8],9);
- left[0] = left[1];
+ h->intern_border_y[i+1] = *(h->cy + 7 + i*h->l_stride);
+ memset(&h->intern_border_y[9],h->intern_border_y[8],9);
+ h->intern_border_y[0] = h->intern_border_y[1];
memcpy(&top[1],&h->top_border_y[h->mbx*16+8],8);
if(h->flags & C_AVAIL)
memcpy(&top[9],&h->top_border_y[(h->mbx + 1)*16],8);
top[17] = top[16];
top[0] = top[1];
if(h->flags & B_AVAIL)
- left[0] = top[0] = h->top_border_y[h->mbx*16+7];
+ h->intern_border_y[0] = top[0] = h->top_border_y[h->mbx*16+7];
break;
case 2:
- memcpy(&left[1],&h->left_border_y[8],8);
- memset(&left[9],left[8],9);
+ *left = &h->left_border_y[8];
memcpy(&top[1],h->cy + 7*h->l_stride,16);
top[17] = top[16];
- left[0] = h->left_border_y[7];
top[0] = top[1];
if(h->flags & A_AVAIL)
- top[0] = left[0];
+ top[0] = h->left_border_y[8];
break;
case 3:
- for(i=0;i<9;i++)
- left[i] = *(h->cy + 7 + (i+7)*h->l_stride);
- memset(&left[9],left[8],9);
+ *left = &h->intern_border_y[8];
+ for(i=0;i<8;i++)
+ h->intern_border_y[i+9] = *(h->cy + 7 + (i+8)*h->l_stride);
+ memset(&h->intern_border_y[17],h->intern_border_y[16],9);
memcpy(&top[0],h->cy + 7 + 7*h->l_stride,9);
memset(&top[9],top[8],9);
break;
int x,y,ia;
int ih = 0;
int iv = 0;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
for(x=0; x<4; x++) {
ih += (x+1)*(top[5+x]-top[3-x]);
int dqm = dequant_mul[qp];
int dqs = dequant_shift[qp];
int dqa = 1 << (dqs - 1);
- const uint8_t *scantab = ff_zigzag_direct;
- DCTELEM block[64];
+ const uint8_t *scantab = h->scantable.permutated;
+ DCTELEM *block = h->block;
- memset(block,0,64*sizeof(DCTELEM));
for(i=0;i<65;i++) {
level_code = get_ue_code(gb,r->golomb_order);
if(level_code >= ESCAPE_CODE) {
GetBitContext *gb = &h->s.gb;
int block, pred_mode_uv;
uint8_t top[18];
- uint8_t left[18];
+ uint8_t *left = NULL;
uint8_t *d;
init_mb(h);
/* luma intra prediction interleaved with residual decode/transform/add */
for(block=0;block<4;block++) {
d = h->cy + h->luma_scan[block];
- load_intra_pred_luma(h, top, left, block);
+ load_intra_pred_luma(h, top, &left, block);
h->intra_pred_l[h->pred_mode_Y[scan3x3[block]]]
(d, top, left, h->l_stride);
if(h->cbp & (1<<block))
enum mb_t mb_type;
if (!s->context_initialized) {
+ s->avctx->idct_algo = FF_IDCT_CAVS;
if (MPV_common_init(s) < 0)
return -1;
+ ff_init_scantable(s->dsp.idct_permutation,&h->scantable,ff_zigzag_direct);
}
get_bits(&s->gb,16);//bbv_dwlay
if(h->stc == PIC_PB_START_CODE) {
/* alloc space for co-located MVs and types */
h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(vector_t));
h->col_type_base = av_malloc(h->mb_width*h->mb_height);
+ h->block = av_mallocz(64*sizeof(DCTELEM));
}
static int decode_seq_header(AVSContext *h) {
MpegEncContext *s = &h->s;
- extern const AVRational ff_frame_rate_tab[];
int frame_rate_code;
h->profile = get_bits(&s->gb,8);
return 0;
}
-/**
- * finds the end of the current frame in the bitstream.
- * @return the position of the first byte of the next frame, or -1
- */
-int ff_cavs_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) {
- int pic_found, i;
- uint32_t state;
-
- pic_found= pc->frame_start_found;
- state= pc->state;
-
- i=0;
- if(!pic_found){
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state == PIC_I_START_CODE || state == PIC_PB_START_CODE){
- i++;
- pic_found=1;
- break;
- }
- }
- }
-
- if(pic_found){
- /* EOF considered as end of frame */
- if (buf_size == 0)
- return 0;
- for(; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if((state&0xFFFFFF00) == 0x100){
- if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
- pc->frame_start_found=0;
- pc->state=-1;
- return i-3;
- }
- }
- }
- }
- pc->frame_start_found= pic_found;
- pc->state= state;
- return END_NOT_FOUND;
-}
-
-void ff_cavs_flush(AVCodecContext * avctx) {
+static void cavs_flush(AVCodecContext * avctx) {
AVSContext *h = avctx->priv_data;
h->got_keyframe = 0;
}
return FFMAX(0, buf_ptr - buf - s->parse_context.last_index);
input_size = (buf_end - buf_ptr)*8;
switch(stc) {
- case SEQ_START_CODE:
+ case CAVS_START_CODE:
init_get_bits(&s->gb, buf_ptr, input_size);
decode_seq_header(h);
break;
av_free(h->top_border_v);
av_free(h->col_mv);
av_free(h->col_type_base);
+ av_free(h->block);
return 0;
}
cavs_decode_end,
cavs_decode_frame,
CODEC_CAP_DR1 | CODEC_CAP_DELAY,
- .flush= ff_cavs_flush,
+ .flush= cavs_flush,
};