* Copyright (c) 2001 Juan J. Sierralta P.
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This library is free software; you can redistribute it and/or
+ * ac prediction encoding, B-frame support, error resilience, optimizations,
+ * qpel decoding, gmc decoding, interlaced decoding
+ * by Michael Niedermayer <michaelni@gmx.at>
+ *
+ * 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
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * ac prediction encoding, b-frame support, error resilience, optimizations,
- * qpel decoding, gmc decoding, interlaced decoding,
- * by Michael Niedermayer <michaelni@gmx.at>
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
//#define DEBUG
#include <limits.h>
-#include "common.h"
#include "dsputil.h"
#include "avcodec.h"
#include "mpegvideo.h"
static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block,
int n, int dc, uint8_t *scan_table,
PutBitContext *dc_pb, PutBitContext *ac_pb);
+static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc,
+ uint8_t *scan_table);
#endif
static int h263_decode_motion(MpegEncContext * s, int pred, int fcode);
static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr);
static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
int n, int coded, int intra, int rvlc);
-static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc,
- uint8_t *scan_table);
-static int h263_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr);
#ifdef CONFIG_ENCODERS
+static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr);
static void mpeg4_encode_visual_object_header(MpegEncContext * s);
static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number);
#endif //CONFIG_ENCODERS
static uint16_t uni_DCtab_lum_bits[512];
static uint16_t uni_DCtab_chrom_bits[512];
-static uint8_t (*mv_penalty)[MAX_MV*2+1]= NULL;
+static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1];
static uint8_t fcode_tab[MAX_MV*2+1];
static uint8_t umv_fcode_tab[MAX_MV*2+1];
*/
#endif
+static uint8_t static_rl_table_store[5][2][2*MAX_RUN + MAX_LEVEL + 3];
+
#if 0 //3IV1 is quite rare and it slows things down a tiny bit
-#define IS_3IV1 s->avctx->codec_tag == ff_get_fourcc("3IV1")
+#define IS_3IV1 s->codec_tag == ff_get_fourcc("3IV1")
#else
#define IS_3IV1 0
#endif
return format;
}
+static void show_pict_info(MpegEncContext *s){
+ av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n",
+ s->qscale, av_get_pict_type_char(s->pict_type),
+ s->gb.size_in_bits, 1-s->no_rounding,
+ s->obmc ? " AP" : "",
+ s->umvplus ? " UMV" : "",
+ s->h263_long_vectors ? " LONG" : "",
+ s->h263_plus ? " +" : "",
+ s->h263_aic ? " AIC" : "",
+ s->alt_inter_vlc ? " AIV" : "",
+ s->modified_quant ? " MQ" : "",
+ s->loop_filter ? " LOOP" : "",
+ s->h263_slice_structured ? " SS" : "",
+ s->avctx->time_base.den, s->avctx->time_base.num
+ );
+}
+
#ifdef CONFIG_ENCODERS
static void aspect_to_info(MpegEncContext * s, AVRational aspect){
for(i=0; i<2; i++){
int div, error;
div= (s->avctx->time_base.num*1800000LL + 500LL*s->avctx->time_base.den) / ((1000LL+i)*s->avctx->time_base.den);
- div= clip(1, div, 127);
- error= ABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div);
+ div= av_clip(div, 1, 127);
+ error= FFABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div);
if(error < best_error){
best_error= error;
best_divisor= div;
(coded_frame_rate_base * (int64_t)s->avctx->time_base.den);
put_bits(&s->pb, 8, temp_ref & 0xff); /* TemporalReference */
- put_bits(&s->pb, 1, 1); /* marker */
- put_bits(&s->pb, 1, 0); /* h263 id */
- put_bits(&s->pb, 1, 0); /* split screen off */
- put_bits(&s->pb, 1, 0); /* camera off */
- put_bits(&s->pb, 1, 0); /* freeze picture release off */
+ put_bits(&s->pb, 1, 1); /* marker */
+ put_bits(&s->pb, 1, 0); /* h263 id */
+ put_bits(&s->pb, 1, 0); /* split screen off */
+ put_bits(&s->pb, 1, 0); /* camera off */
+ put_bits(&s->pb, 1, 0); /* freeze picture release off */
format = h263_get_picture_format(s->width, s->height);
if (!s->h263_plus) {
/* By now UMV IS DISABLED ON H.263v1, since the restrictions
of H.263v1 UMV implies to check the predicted MV after
calculation of the current MB to see if we're on the limits */
- put_bits(&s->pb, 1, 0); /* Unrestricted Motion Vector: off */
- put_bits(&s->pb, 1, 0); /* SAC: off */
- put_bits(&s->pb, 1, s->obmc); /* Advanced Prediction */
- put_bits(&s->pb, 1, 0); /* only I/P frames, no PB frame */
+ put_bits(&s->pb, 1, 0); /* Unrestricted Motion Vector: off */
+ put_bits(&s->pb, 1, 0); /* SAC: off */
+ put_bits(&s->pb, 1, s->obmc); /* Advanced Prediction */
+ put_bits(&s->pb, 1, 0); /* only I/P frames, no PB frame */
put_bits(&s->pb, 5, s->qscale);
- put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
+ put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
} else {
int ufep=1;
/* H.263v2 */
put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
/* This should be here if PLUSPTYPE */
- put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
+ put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
- if (format == 7) {
+ if (format == 7) {
/* Custom Picture Format (CPFMT) */
aspect_to_info(s, s->avctx->sample_aspect_ratio);
if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){
put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num);
put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den);
- }
+ }
}
if(s->custom_pcf){
if(ufep){
put_bits(&s->pb, 5, s->qscale);
}
- put_bits(&s->pb, 1, 0); /* no PEI */
+ put_bits(&s->pb, 1, 0); /* no PEI */
if(s->h263_slice_structured){
put_bits(&s->pb, 1, 1);
}
}
+/**
+ * init s->current_picture.qscale_table from s->lambda_table
+ */
+static void ff_init_qscale_tab(MpegEncContext *s){
+ int8_t * const qscale_table= s->current_picture.qscale_table;
+ int i;
+
+ for(i=0; i<s->mb_num; i++){
+ unsigned int lam= s->lambda_table[ s->mb_index2xy[i] ];
+ int qp= (lam*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
+ qscale_table[ s->mb_index2xy[i] ]= av_clip(qp, s->avctx->qmin, s->avctx->qmax);
+ }
+}
+
/**
* modify qscale so that encoding is acually possible in h263 (limit difference to -2..2)
*/
int i;
int8_t * const qscale_table= s->current_picture.qscale_table;
+ ff_init_qscale_tab(s);
+
for(i=1; i<s->mb_num; i++){
if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i-1] ] >2)
qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i-1] ]+2;
int mb_xy= s->mb_index2xy[i];
if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTER4V)){
- s->mb_type[mb_xy]&= ~CANDIDATE_MB_TYPE_INTER4V;
s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_INTER;
}
}
for(i=1; i<s->mb_num; i++){
int mb_xy= s->mb_index2xy[i];
if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_DIRECT)){
- s->mb_type[mb_xy]&= ~CANDIDATE_MB_TYPE_DIRECT;
s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_BIDIR;
}
}
}
#endif //CONFIG_ENCODERS
+
+#define tab_size ((signed)(sizeof(s->direct_scale_mv[0])/sizeof(int16_t)))
+#define tab_bias (tab_size/2)
+
+void ff_mpeg4_init_direct_mv(MpegEncContext *s){
+ int i;
+ for(i=0; i<tab_size; i++){
+ s->direct_scale_mv[0][i] = (i-tab_bias)*s->pb_time/s->pp_time;
+ s->direct_scale_mv[1][i] = (i-tab_bias)*(s->pb_time-s->pp_time)/s->pp_time;
+ }
+}
+
+static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my, int i){
+ int xy= s->block_index[i];
+ uint16_t time_pp= s->pp_time;
+ uint16_t time_pb= s->pb_time;
+ int p_mx, p_my;
+
+ p_mx= s->next_picture.motion_val[0][xy][0];
+ if((unsigned)(p_mx + tab_bias) < tab_size){
+ s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias] + mx;
+ s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx
+ : s->direct_scale_mv[1][p_mx + tab_bias];
+ }else{
+ s->mv[0][i][0] = p_mx*time_pb/time_pp + mx;
+ s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx
+ : p_mx*(time_pb - time_pp)/time_pp;
+ }
+ p_my= s->next_picture.motion_val[0][xy][1];
+ if((unsigned)(p_my + tab_bias) < tab_size){
+ s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias] + my;
+ s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my
+ : s->direct_scale_mv[1][p_my + tab_bias];
+ }else{
+ s->mv[0][i][1] = p_my*time_pb/time_pp + my;
+ s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my
+ : p_my*(time_pb - time_pp)/time_pp;
+ }
+}
+
+#undef tab_size
+#undef tab_bias
+
/**
*
* @return the mb_type
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){
const int mb_index= s->mb_x + s->mb_y*s->mb_stride;
const int colocated_mb_type= s->next_picture.mb_type[mb_index];
- int xy= s->block_index[0];
uint16_t time_pp= s->pp_time;
uint16_t time_pb= s->pb_time;
int i;
//FIXME avoid divides
+ // try special case with shifts for 1 and 3 B-frames?
if(IS_8X8(colocated_mb_type)){
s->mv_type = MV_TYPE_8X8;
for(i=0; i<4; i++){
- xy= s->block_index[i];
- s->mv[0][i][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp + mx;
- s->mv[0][i][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp + my;
- s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->next_picture.motion_val[0][xy][0]
- : s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
- s->mv[1][i][1] = my ? s->mv[0][i][1] - s->next_picture.motion_val[0][xy][1]
- : s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
+ ff_mpeg4_set_one_direct_mv(s, mx, my, i);
}
return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1;
} else if(IS_INTERLACED(colocated_mb_type)){
s->mv_type = MV_TYPE_FIELD;
for(i=0; i<2; i++){
int field_select= s->next_picture.ref_index[0][s->block_index[2*i]];
+ s->field_select[0][i]= field_select;
+ s->field_select[1][i]= i;
if(s->top_field_first){
time_pp= s->pp_field_time - field_select + i;
time_pb= s->pb_field_time - field_select + i;
}
return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED;
}else{
- s->mv[0][0][0] = s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp + mx;
- s->mv[0][0][1] = s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp + my;
- s->mv[1][0][0] = s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = mx ? s->mv[0][0][0] - s->next_picture.motion_val[0][xy][0]
- : s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
- s->mv[1][0][1] = s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = my ? s->mv[0][0][1] - s->next_picture.motion_val[0][xy][1]
- : s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
+ ff_mpeg4_set_one_direct_mv(s, mx, my, 0);
+ s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->mv[0][0][0];
+ s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->mv[0][0][1];
+ s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = s->mv[1][0][0];
+ s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = s->mv[1][0][1];
if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample)
s->mv_type= MV_TYPE_16X16;
else
}
void mpeg4_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
+ DCTELEM block[6][64],
+ int motion_x, int motion_y)
{
int cbpc, cbpy, pred_x, pred_y;
PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb;
int i, cbp;
if(s->pict_type==B_TYPE){
- static const int mb_type_table[8]= {-1, 2, 3, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */
+ static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */
int mb_type= mb_type_table[s->mv_dir];
if(s->mb_x==0){
return;
}
- put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */
+ put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */
put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ //FIXME merge
put_bits(&s->pb, mb_type+1, 1); // this table is so simple that we don't need it :)
if(cbp) put_bits(&s->pb, 6, cbp);
if(pic==NULL || pic->pict_type!=B_TYPE) break;
- b_pic= pic->data[0] + offset + 16; //FIXME +16
- diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
+ b_pic= pic->data[0] + offset;
+ if(pic->type != FF_BUFFER_TYPE_SHARED)
+ b_pic+= INPLACE_OFFSET;
+ diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
if(diff>s->qscale*70){ //FIXME check that 70 is optimal
s->mb_skipped=0;
break;
}
}
- put_bits(&s->pb, 1, 0); /* mb coded */
+ put_bits(&s->pb, 1, 0); /* mb coded */
cbpc = cbp & 3;
cbpy = cbp >> 2;
cbpy ^= 0xf;
int dc_diff[6]; //dc values with the dc prediction subtracted
int dir[6]; //prediction direction
int zigzag_last_index[6];
- uint8_t *scan_table[6];
+ uint8_t *scan_table[6];
int i;
for(i=0; i<6; i++){
intra_MCBPC_code[cbpc]);
} else {
if(s->dquant) cbpc+=8;
- put_bits(&s->pb, 1, 0); /* mb coded */
+ put_bits(&s->pb, 1, 0); /* mb coded */
put_bits(&s->pb,
inter_MCBPC_bits[cbpc + 4],
inter_MCBPC_code[cbpc + 4]);
}
void h263_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
+ DCTELEM block[6][64],
+ int motion_x, int motion_y)
{
int cbpc, cbpy, i, cbp, pred_x, pred_y;
int16_t pred_dc;
int16_t rec_intradc[6];
- uint16_t *dc_ptr[6];
+ int16_t *dc_ptr[6];
const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1);
const int dquant_code[5]= {1,0,9,2,3};
return;
}
- put_bits(&s->pb, 1, 0); /* mb coded */
+ put_bits(&s->pb, 1, 0); /* mb coded */
cbpc = cbp & 3;
cbpy = cbp >> 2;
intra_MCBPC_code[cbpc]);
} else {
if(s->dquant) cbpc+=8;
- put_bits(&s->pb, 1, 0); /* mb coded */
+ put_bits(&s->pb, 1, 0); /* mb coded */
put_bits(&s->pb,
inter_MCBPC_bits[cbpc + 4],
inter_MCBPC_code[cbpc + 4]);
}
if (s->h263_aic) {
/* XXX: currently, we do not try to use ac prediction */
- put_bits(&s->pb, 1, 0); /* no AC prediction */
+ put_bits(&s->pb, 1, 0); /* no AC prediction */
}
cbpy = cbp >> 2;
put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
}
}
-static int h263_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr)
+#ifdef CONFIG_ENCODERS
+static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr)
{
int x, y, wrap, a, c, pred_dc, scale;
- int16_t *dc_val, *ac_val;
+ int16_t *dc_val;
/* find prediction */
if (n < 4) {
y = 2 * s->mb_y + ((n & 2) >> 1);
wrap = s->b8_stride;
dc_val = s->dc_val[0];
- ac_val = s->ac_val[0][0];
scale = s->y_dc_scale;
} else {
x = s->mb_x;
y = s->mb_y;
wrap = s->mb_stride;
dc_val = s->dc_val[n - 4 + 1];
- ac_val = s->ac_val[n - 4 + 1][0];
scale = s->c_dc_scale;
}
/* B C
*dc_val_ptr = &dc_val[x + y * wrap];
return pred_dc;
}
+#endif /* CONFIG_ENCODERS */
static void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n)
{
int f_code;
int mv;
- if(mv_penalty==NULL)
- mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) );
-
for(f_code=1; f_code<=MAX_FCODE; f_code++){
for(mv=-MAX_MV; mv<=MAX_MV; mv++){
int len;
if(code<33){
len= mvtab[code][1] + 1 + bit_size;
}else{
- len= mvtab[32][1] + 2 + bit_size;
+ len= mvtab[32][1] + av_log2(code>>5) + 2 + bit_size;
}
}
umv_fcode_tab[mv]= 1;
}
}
-#endif
-
-#ifdef CONFIG_ENCODERS
static void init_uni_dc_tab(void)
{
v = abs(level);
while (v) {
v >>= 1;
- size++;
+ size++;
}
if (level < 0)
}
}
-#endif //CONFIG_ENCODERS
-
-#ifdef CONFIG_ENCODERS
static void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){
int slevel, run, last;
init_uni_dc_tab();
- init_rl(&rl_inter, 1);
- init_rl(&rl_intra, 1);
- init_rl(&rl_intra_aic, 1);
+ init_rl(&rl_inter, static_rl_table_store[0]);
+ init_rl(&rl_intra, static_rl_table_store[1]);
+ init_rl(&rl_intra_aic, static_rl_table_store[2]);
init_uni_mpeg4_rl_tab(&rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);
init_uni_mpeg4_rl_tab(&rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);
}
}
}
-#endif
-
-#ifdef CONFIG_ENCODERS
/***************************************************/
/**
}
/* must be called before writing the header */
-void ff_set_mpeg4_time(MpegEncContext * s, int picture_number){
- int time_div, time_mod;
-
- assert(s->current_picture_ptr->pts != AV_NOPTS_VALUE);
- s->time= s->current_picture_ptr->pts*s->avctx->time_base.num;
-
- time_div= s->time/s->avctx->time_base.den;
- time_mod= s->time%s->avctx->time_base.den;
-
+void ff_set_mpeg4_time(MpegEncContext * s){
if(s->pict_type==B_TYPE){
- s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
- assert(s->pb_time > 0 && s->pb_time < s->pp_time);
+ ff_mpeg4_init_direct_mv(s);
}else{
s->last_time_base= s->time_base;
- s->time_base= time_div;
- s->pp_time= s->time - s->last_non_b_time;
- s->last_non_b_time= s->time;
- assert(picture_number==0 || s->pp_time > 0);
+ s->time_base= s->time/s->avctx->time_base.den;
}
}
{
int vo_ver_id;
+ if (!ENABLE_MPEG4_ENCODER) return;
+
if(s->max_b_frames || s->quarter_sample){
vo_ver_id= 5;
s->vo_type= ADV_SIMPLE_VO_TYPE;
put_bits(&s->pb, 16, 0);
put_bits(&s->pb, 16, 0x120 + vol_number); /* video obj layer */
- put_bits(&s->pb, 1, 0); /* random access vol */
- put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */
+ put_bits(&s->pb, 1, 0); /* random access vol */
+ put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */
if(s->workaround_bugs & FF_BUG_MS) {
- put_bits(&s->pb, 1, 0); /* is obj layer id= no */
+ put_bits(&s->pb, 1, 0); /* is obj layer id= no */
} else {
- put_bits(&s->pb, 1, 1); /* is obj layer id= yes */
- put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */
- put_bits(&s->pb, 3, 1); /* is obj layer priority */
+ put_bits(&s->pb, 1, 1); /* is obj layer id= yes */
+ put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */
+ put_bits(&s->pb, 3, 1); /* is obj layer priority */
}
aspect_to_info(s, s->avctx->sample_aspect_ratio);
}
if(s->workaround_bugs & FF_BUG_MS) { //
- put_bits(&s->pb, 1, 0); /* vol control parameters= no @@@ */
+ put_bits(&s->pb, 1, 0); /* vol control parameters= no @@@ */
} else {
- put_bits(&s->pb, 1, 1); /* vol control parameters= yes */
- put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */
+ put_bits(&s->pb, 1, 1); /* vol control parameters= yes */
+ put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */
put_bits(&s->pb, 1, s->low_delay);
- put_bits(&s->pb, 1, 0); /* vbv parameters= no */
+ put_bits(&s->pb, 1, 0); /* vbv parameters= no */
}
- put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */
- put_bits(&s->pb, 1, 1); /* marker bit */
+ put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */
+ put_bits(&s->pb, 1, 1); /* marker bit */
put_bits(&s->pb, 16, s->avctx->time_base.den);
if (s->time_increment_bits < 1)
s->time_increment_bits = 1;
- put_bits(&s->pb, 1, 1); /* marker bit */
- put_bits(&s->pb, 1, 0); /* fixed vop rate=no */
- put_bits(&s->pb, 1, 1); /* marker bit */
- put_bits(&s->pb, 13, s->width); /* vol width */
- put_bits(&s->pb, 1, 1); /* marker bit */
- put_bits(&s->pb, 13, s->height); /* vol height */
- put_bits(&s->pb, 1, 1); /* marker bit */
+ put_bits(&s->pb, 1, 1); /* marker bit */
+ put_bits(&s->pb, 1, 0); /* fixed vop rate=no */
+ put_bits(&s->pb, 1, 1); /* marker bit */
+ put_bits(&s->pb, 13, s->width); /* vol width */
+ put_bits(&s->pb, 1, 1); /* marker bit */
+ put_bits(&s->pb, 13, s->height); /* vol height */
+ put_bits(&s->pb, 1, 1); /* marker bit */
put_bits(&s->pb, 1, s->progressive_sequence ? 0 : 1);
- put_bits(&s->pb, 1, 1); /* obmc disable */
+ put_bits(&s->pb, 1, 1); /* obmc disable */
if (vo_ver_id == 1) {
- put_bits(&s->pb, 1, s->vol_sprite_usage); /* sprite enable */
+ put_bits(&s->pb, 1, s->vol_sprite_usage); /* sprite enable */
}else{
- put_bits(&s->pb, 2, s->vol_sprite_usage); /* sprite enable */
+ put_bits(&s->pb, 2, s->vol_sprite_usage); /* sprite enable */
}
- put_bits(&s->pb, 1, 0); /* not 8 bit == false */
- put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/
+ put_bits(&s->pb, 1, 0); /* not 8 bit == false */
+ put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/
if(s->mpeg_quant){
ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
if (vo_ver_id != 1)
put_bits(&s->pb, 1, s->quarter_sample);
- put_bits(&s->pb, 1, 1); /* complexity estimation disable */
+ put_bits(&s->pb, 1, 1); /* complexity estimation disable */
s->resync_marker= s->rtp_mode;
put_bits(&s->pb, 1, s->resync_marker ? 0 : 1);/* resync marker disable */
put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0);
if(s->data_partitioning){
- put_bits(&s->pb, 1, 0); /* no rvlc */
+ put_bits(&s->pb, 1, 0); /* no rvlc */
}
if (vo_ver_id != 1){
- put_bits(&s->pb, 1, 0); /* newpred */
- put_bits(&s->pb, 1, 0); /* reduced res vop */
+ put_bits(&s->pb, 1, 0); /* newpred */
+ put_bits(&s->pb, 1, 0); /* reduced res vop */
}
- put_bits(&s->pb, 1, 0); /* scalability */
+ put_bits(&s->pb, 1, 0); /* scalability */
ff_mpeg4_stuffing(&s->pb);
/* user data */
if(!(s->flags & CODEC_FLAG_BITEXACT)){
put_bits(&s->pb, 16, 0);
- put_bits(&s->pb, 16, 0x1B2); /* user_data */
- ff_put_string(&s->pb, LIBAVCODEC_IDENT, 0);
+ put_bits(&s->pb, 16, 0x1B2); /* user_data */
+ ff_put_string(&s->pb, LIBAVCODEC_IDENT, 0);
}
}
//printf("num:%d rate:%d base:%d\n", s->picture_number, s->time_base.den, FRAME_RATE_BASE);
- put_bits(&s->pb, 16, 0); /* vop header */
- put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */
- put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */
+ put_bits(&s->pb, 16, 0); /* vop header */
+ put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */
+ put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */
assert(s->time>=0);
time_div= s->time/s->avctx->time_base.den;
put_bits(&s->pb, 1, 0);
- put_bits(&s->pb, 1, 1); /* marker */
- put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */
- put_bits(&s->pb, 1, 1); /* marker */
- put_bits(&s->pb, 1, 1); /* vop coded */
+ put_bits(&s->pb, 1, 1); /* marker */
+ put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */
+ put_bits(&s->pb, 1, 1); /* marker */
+ put_bits(&s->pb, 1, 1); /* vop coded */
if ( s->pict_type == P_TYPE
|| (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) {
- put_bits(&s->pb, 1, s->no_rounding); /* rounding type */
+ put_bits(&s->pb, 1, s->no_rounding); /* rounding type */
}
- put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */
+ put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */
if(!s->progressive_sequence){
put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first);
put_bits(&s->pb, 1, s->alternate_scan);
put_bits(&s->pb, 5, s->qscale);
if (s->pict_type != I_TYPE)
- put_bits(&s->pb, 3, s->f_code); /* fcode_for */
+ put_bits(&s->pb, 3, s->f_code); /* fcode_for */
if (s->pict_type == B_TYPE)
- put_bits(&s->pb, 3, s->b_code); /* fcode_back */
+ put_bits(&s->pb, 3, s->b_code); /* fcode_back */
// printf("****frame %d\n", picture_number);
}
#endif //CONFIG_ENCODERS
-/**
- * set qscale and update qscale dependant variables.
- */
-void ff_set_qscale(MpegEncContext * s, int qscale)
-{
- if (qscale < 1)
- qscale = 1;
- else if (qscale > 31)
- qscale = 31;
-
- s->qscale = qscale;
- s->chroma_qscale= s->chroma_qscale_table[qscale];
-
- s->y_dc_scale= s->y_dc_scale_table[ qscale ];
- s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ];
-}
-
/**
* predicts the dc.
* encoding quantized level -> quantized diff
static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding)
{
int a, b, c, wrap, pred, scale, ret;
- uint16_t *dc_val;
+ int16_t *dc_val;
/* find prediction */
if (n < 4) {
- scale = s->y_dc_scale;
+ scale = s->y_dc_scale;
} else {
- scale = s->c_dc_scale;
+ scale = s->c_dc_scale;
}
if(IS_3IV1)
scale= 8;
}
if (abs(a - b) < abs(b - c)) {
- pred = c;
+ pred = c;
*dir_ptr = 1; /* top */
} else {
- pred = a;
+ pred = a;
*dir_ptr = 0; /* left */
}
/* we assume pred is positive */
// if(level<-255 || level>255) printf("dc overflow\n");
level+=256;
if (n < 4) {
- /* luminance */
- put_bits(s, uni_DCtab_lum_len[level], uni_DCtab_lum_bits[level]);
+ /* luminance */
+ put_bits(s, uni_DCtab_lum_len[level], uni_DCtab_lum_bits[level]);
} else {
- /* chrominance */
- put_bits(s, uni_DCtab_chrom_len[level], uni_DCtab_chrom_bits[level]);
+ /* chrominance */
+ put_bits(s, uni_DCtab_chrom_len[level], uni_DCtab_chrom_bits[level]);
}
#else
int size, v;
size = 0;
v = abs(level);
while (v) {
- v >>= 1;
- size++;
+ v >>= 1;
+ size++;
}
if (n < 4) {
- /* luminance */
- put_bits(&s->pb, DCtab_lum[size][1], DCtab_lum[size][0]);
+ /* luminance */
+ put_bits(&s->pb, DCtab_lum[size][1], DCtab_lum[size][0]);
} else {
- /* chrominance */
- put_bits(&s->pb, DCtab_chrom[size][1], DCtab_chrom[size][0]);
+ /* chrominance */
+ put_bits(&s->pb, DCtab_chrom[size][1], DCtab_chrom[size][0]);
}
/* encode remaining bits */
if (size > 0) {
- if (level < 0)
- level = (-level) ^ ((1 << size) - 1);
- put_bits(&s->pb, size, level);
- if (size > 8)
- put_bits(&s->pb, 1, 1);
+ if (level < 0)
+ level = (-level) ^ ((1 << size) - 1);
+ put_bits(&s->pb, size, level);
+ if (size > 8)
+ put_bits(&s->pb, 1, 1);
}
#endif
}
const int last_index = s->block_last_index[n];
if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away
- /* mpeg4 based DC predictor */
- mpeg4_encode_dc(dc_pb, intra_dc, n);
+ /* mpeg4 based DC predictor */
+ mpeg4_encode_dc(dc_pb, intra_dc, n);
if(last_index<1) return;
- i = 1;
+ i = 1;
rl = &rl_intra;
bits_tab= uni_mpeg4_intra_rl_bits;
len_tab = uni_mpeg4_intra_rl_len;
} else {
if(last_index<0) return;
- i = 0;
+ i = 0;
rl = &rl_inter;
bits_tab= uni_mpeg4_inter_rl_bits;
len_tab = uni_mpeg4_inter_rl_len;
last_non_zero = i - 1;
#if 1
for (; i < last_index; i++) {
- int level = block[ scan_table[i] ];
- if (level) {
- int run = i - last_non_zero - 1;
+ int level = block[ scan_table[i] ];
+ if (level) {
+ int run = i - last_non_zero - 1;
level+=64;
if((level&(~127)) == 0){
const int index= UNI_MPEG4_ENC_INDEX(0, run, level);
}else{ //ESC3
put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(0<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1);
}
- last_non_zero = i;
- }
+ last_non_zero = i;
+ }
}
/*if(i<=last_index)*/{
- int level = block[ scan_table[i] ];
+ int level = block[ scan_table[i] ];
int run = i - last_non_zero - 1;
level+=64;
if((level&(~127)) == 0){
}
#else
for (; i <= last_index; i++) {
- const int slevel = block[ scan_table[i] ];
- if (slevel) {
+ const int slevel = block[ scan_table[i] ];
+ if (slevel) {
int level;
- int run = i - last_non_zero - 1;
- last = (i == last_index);
- sign = 0;
- level = slevel;
- if (level < 0) {
- sign = 1;
- level = -level;
- }
+ int run = i - last_non_zero - 1;
+ last = (i == last_index);
+ sign = 0;
+ level = slevel;
+ if (level < 0) {
+ sign = 1;
+ level = -level;
+ }
code = get_rl_index(rl, last, run, level);
put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
if (code == rl->n) {
} else {
put_bits(ac_pb, 1, sign);
}
- last_non_zero = i;
- }
+ last_non_zero = i;
+ }
}
#endif
}
int len=0;
if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away
- /* mpeg4 based DC predictor */
- len += mpeg4_get_dc_length(intra_dc, n);
+ /* mpeg4 based DC predictor */
+ len += mpeg4_get_dc_length(intra_dc, n);
if(last_index<1) return len;
- i = 1;
+ i = 1;
rl = &rl_intra;
len_tab = uni_mpeg4_intra_rl_len;
} else {
if(last_index<0) return 0;
- i = 0;
+ i = 0;
rl = &rl_inter;
len_tab = uni_mpeg4_inter_rl_len;
}
/* AC coefs */
last_non_zero = i - 1;
for (; i < last_index; i++) {
- int level = block[ scan_table[i] ];
- if (level) {
- int run = i - last_non_zero - 1;
+ int level = block[ scan_table[i] ];
+ if (level) {
+ int run = i - last_non_zero - 1;
level+=64;
if((level&(~127)) == 0){
const int index= UNI_MPEG4_ENC_INDEX(0, run, level);
}else{ //ESC3
len += 7+2+1+6+1+12+1;
}
- last_non_zero = i;
- }
+ last_non_zero = i;
+ }
}
/*if(i<=last_index)*/{
- int level = block[ scan_table[i] ];
+ int level = block[ scan_table[i] ];
int run = i - last_non_zero - 1;
level+=64;
if((level&(~127)) == 0){
static VLC h263_mbtype_b_vlc;
static VLC cbpc_b_vlc;
-void init_vlc_rl(RLTable *rl, int use_static)
-{
- int i, q;
-
- /* Return if static table is already initialized */
- if(use_static && rl->rl_vlc[0])
- return;
-
- init_vlc(&rl->vlc, 9, rl->n + 1,
- &rl->table_vlc[0][1], 4, 2,
- &rl->table_vlc[0][0], 4, 2, use_static);
-
-
- for(q=0; q<32; q++){
- int qmul= q*2;
- int qadd= (q-1)|1;
-
- if(q==0){
- qmul=1;
- qadd=0;
- }
- if(use_static)
- rl->rl_vlc[q]= av_mallocz_static(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
- else
- rl->rl_vlc[q]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
- for(i=0; i<rl->vlc.table_size; i++){
- int code= rl->vlc.table[i][0];
- int len = rl->vlc.table[i][1];
- int level, run;
-
- if(len==0){ // illegal code
- run= 66;
- level= MAX_LEVEL;
- }else if(len<0){ //more bits needed
- run= 0;
- level= code;
- }else{
- if(code==rl->n){ //esc
- run= 66;
- level= 0;
- }else{
- run= rl->table_run [code] + 1;
- level= rl->table_level[code] * qmul + qadd;
- if(code >= rl->last) run+=192;
- }
- }
- rl->rl_vlc[q][i].len= len;
- rl->rl_vlc[q][i].level= level;
- rl->rl_vlc[q][i].run= run;
- }
- }
-}
-
/* init vlcs */
/* XXX: find a better solution to handle static init */
init_vlc(&mv_vlc, MV_VLC_BITS, 33,
&mvtab[0][1], 2, 1,
&mvtab[0][0], 2, 1, 1);
- init_rl(&rl_inter, 1);
- init_rl(&rl_intra, 1);
- init_rl(&rvlc_rl_inter, 1);
- init_rl(&rvlc_rl_intra, 1);
- init_rl(&rl_intra_aic, 1);
+ init_rl(&rl_inter, static_rl_table_store[0]);
+ init_rl(&rl_intra, static_rl_table_store[1]);
+ init_rl(&rvlc_rl_inter, static_rl_table_store[3]);
+ init_rl(&rvlc_rl_intra, static_rl_table_store[4]);
+ init_rl(&rl_intra_aic, static_rl_table_store[2]);
init_vlc_rl(&rl_inter, 1);
init_vlc_rl(&rl_intra, 1);
init_vlc_rl(&rvlc_rl_inter, 1);
* @return 0 if not
*/
static inline int mpeg4_is_resync(MpegEncContext *s){
- const int bits_count= get_bits_count(&s->gb);
+ int bits_count= get_bits_count(&s->gb);
+ int v= show_bits(&s->gb, 16);
if(s->workaround_bugs&FF_BUG_NO_PADDING){
return 0;
}
+ while(v<=0xFF){
+ if(s->pict_type==B_TYPE || (v>>(8-s->pict_type)!=1) || s->partitioned_frame)
+ break;
+ skip_bits(&s->gb, 8+s->pict_type);
+ bits_count+= 8+s->pict_type;
+ v= show_bits(&s->gb, 16);
+ }
+
if(bits_count + 8 >= s->gb.size_in_bits){
- int v= show_bits(&s->gb, 8);
+ v>>=8;
v|= 0x7F >> (7-(bits_count&7));
if(v==0x7F)
return 1;
}else{
- if(show_bits(&s->gb, 16) == ff_mpeg4_resync_prefix[bits_count&7]){
+ if(v == ff_mpeg4_resync_prefix[bits_count&7]){
int len;
GetBitContext gb= s->gb;
//FIXME reduced res stuff here
if (s->pict_type != I_TYPE) {
- int f_code = get_bits(&s->gb, 3); /* fcode_for */
+ int f_code = get_bits(&s->gb, 3); /* fcode_for */
if(f_code==0){
av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (f_code=0)\n");
}
if(ret>=0)
return 0;
}
- //ok, it's not where its supposed to be ...
+ //OK, it's not where it is supposed to be ...
s->gb= s->last_resync_gb;
align_get_bits(&s->gb);
left= s->gb.size_in_bits - get_bits_count(&s->gb);
mb_type= s->current_picture.mb_type[xy];
cbp = s->cbp_table[xy];
+ s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold;
+
if(s->current_picture.qscale_table[xy] != s->qscale){
ff_set_qscale(s, s->current_picture.qscale_table[xy] );
}
return -1;
}
cbp = (cbpc & 3) | (cbpy << 2);
+
+ s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold;
+
if (dquant) {
ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
}
i += run;
if (i >= 64){
if(s->alt_inter_vlc && rl == &rl_inter && !s->mb_intra){
- //looks like a hack but no, it's the way its supposed to work ...
+ //Looks like a hack but no, it's the way it is supposed to work ...
rl = &rl_intra_aic;
i = 0;
s->gb= gb;
//Note intra & rvlc should be optimized away if this is inlined
if(intra) {
- if(s->qscale < s->intra_dc_threshold){
- /* DC coef */
+ if(s->use_intra_dc_vlc){
+ /* DC coef */
if(s->partitioned_frame){
level = s->dc_val[0][ s->block_index[n] ];
if(n<4) level= FASTDIV((level + (s->y_dc_scale>>1)), s->y_dc_scale);
i = 0;
}else{
i = -1;
+ ff_mpeg4_pred_dc(s, n, 0, &dc_pred_dir, 0);
}
if (!coded)
goto not_coded;
#if 0
if(s->error_resilience >= FF_ER_COMPLIANT){
- const int abs_level= ABS(level);
+ const int abs_level= FFABS(level);
if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
const int run1= run - rl->max_run[last][abs_level] - 1;
if(abs_level <= rl->max_level[last][run]){
}
}
#endif
- if (level>0) level= level * qmul + qadd;
+ if (level>0) level= level * qmul + qadd;
else level= level * qmul - qadd;
if((unsigned)(level + 2048) > 4095){
}
not_coded:
if (intra) {
- if(s->qscale >= s->intra_dc_threshold){
+ if(!s->use_intra_dc_vlc){
block[0] = ff_mpeg4_pred_dc(s, n, block[0], &dc_pred_dir, 0);
- if(i == -1) i=0;
+ i -= i>>31; //if(i == -1) i=0;
}
mpeg4_pred_ac(s, block, n, dc_pred_dir);
}
if (get_bits1(&s->gb) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");
- return -1; /* h263 id */
+ return -1; /* h263 id */
}
- skip_bits1(&s->gb); /* split screen off */
- skip_bits1(&s->gb); /* camera off */
- skip_bits1(&s->gb); /* freeze picture release off */
+ skip_bits1(&s->gb); /* split screen off */
+ skip_bits1(&s->gb); /* camera off */
+ skip_bits1(&s->gb); /* freeze picture release off */
format = get_bits(&s->gb, 3);
/*
0 forbidden
1 sub-QCIF
10 QCIF
- 7 extended PTYPE (PLUSPTYPE)
+ 7 extended PTYPE (PLUSPTYPE)
*/
if (format != 7 && format != 6) {
if (get_bits1(&s->gb) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "H263 SAC not supported\n");
- return -1; /* SAC: off */
+ return -1; /* SAC: off */
}
s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
s->unrestricted_mv = s->h263_long_vectors || s->obmc;
if (get_bits1(&s->gb) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "H263 PB frame not supported\n");
- return -1; /* not PB frame */
+ return -1; /* not PB frame */
}
s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
- skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
+ skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
s->width = width;
s->height = height;
if (ufep == 1) {
/* OPPTYPE */
format = get_bits(&s->gb, 3);
- dprintf("ufep=1, format: %d\n", format);
+ dprintf(s->avctx, "ufep=1, format: %d\n", format);
s->custom_pcf= get_bits1(&s->gb);
- s->umvplus = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */
+ s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */
if (get_bits1(&s->gb) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
}
if (format == 6) {
/* Custom Picture Format (CPFMT) */
s->aspect_ratio_info = get_bits(&s->gb, 4);
- dprintf("aspect: %d\n", s->aspect_ratio_info);
+ dprintf(s->avctx, "aspect: %d\n", s->aspect_ratio_info);
/* aspect ratios:
0 - forbidden
1 - 1:1
width = (get_bits(&s->gb, 9) + 1) * 4;
skip_bits1(&s->gb);
height = get_bits(&s->gb, 9) * 4;
- dprintf("\nH.263+ Custom picture: %dx%d\n",width,height);
+ dprintf(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) {
/* aspected dimensions */
s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);
}
if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n",
- s->qscale, av_get_pict_type_char(s->pict_type),
- s->gb.size_in_bits, 1-s->no_rounding,
- s->obmc ? " AP" : "",
- s->umvplus ? " UMV" : "",
- s->h263_long_vectors ? " LONG" : "",
- s->h263_plus ? " +" : "",
- s->h263_aic ? " AIC" : "",
- s->alt_inter_vlc ? " AIV" : "",
- s->modified_quant ? " MQ" : "",
- s->loop_filter ? " LOOP" : "",
- s->h263_slice_structured ? " SS" : "",
- s->avctx->time_base.den, s->avctx->time_base.num
- );
+ show_pict_info(s);
}
#if 1
- if (s->pict_type == I_TYPE && s->avctx->codec_tag == ff_get_fourcc("ZYGO")){
+ if (s->pict_type == I_TYPE && s->codec_tag == ff_get_fourcc("ZYGO")){
int i,j;
for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
av_log(s->avctx, AV_LOG_DEBUG, "\n");
int length;
int x=0, y=0;
- length= get_vlc(gb, &sprite_trajectory);
+ length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3);
if(length){
x= get_xbits(gb, length);
}
if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(gb); /* marker bit */
- length= get_vlc(gb, &sprite_trajectory);
+ length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3);
if(length){
y=get_xbits(gb, length);
}
}
s->low_delay= get_bits1(gb);
if(get_bits1(gb)){ /* vbv parameters */
- get_bits(gb, 15); /* first_half_bitrate */
- skip_bits1(gb); /* marker */
- get_bits(gb, 15); /* latter_half_bitrate */
- skip_bits1(gb); /* marker */
- get_bits(gb, 15); /* first_half_vbv_buffer_size */
- skip_bits1(gb); /* marker */
- get_bits(gb, 3); /* latter_half_vbv_buffer_size */
- get_bits(gb, 11); /* first_half_vbv_occupancy */
- skip_bits1(gb); /* marker */
- get_bits(gb, 15); /* latter_half_vbv_occupancy */
- skip_bits1(gb); /* marker */
+ get_bits(gb, 15); /* first_half_bitrate */
+ skip_bits1(gb); /* marker */
+ get_bits(gb, 15); /* latter_half_bitrate */
+ skip_bits1(gb); /* marker */
+ get_bits(gb, 15); /* first_half_vbv_buffer_size */
+ skip_bits1(gb); /* marker */
+ get_bits(gb, 3); /* latter_half_vbv_buffer_size */
+ get_bits(gb, 11); /* first_half_vbv_occupancy */
+ skip_bits1(gb); /* marker */
+ get_bits(gb, 15); /* latter_half_vbv_occupancy */
+ skip_bits1(gb); /* marker */
}
}else{
// set low delay flag only once the smartest? low delay detection won't be overriden
skip_bits1(gb); /* marker */
height = get_bits(gb, 13);
skip_bits1(gb); /* marker */
- if(width && height && !(s->width && s->avctx->codec_tag == ff_get_fourcc("MP4S"))){ /* they should be non zero but who knows ... */
+ if(width && height && !(s->width && s->codec_tag == ff_get_fourcc("MP4S"))){ /* they should be non zero but who knows ... */
s->width = width;
s->height = height;
// printf("width/height: %d %d\n", width, height);
s->progressive_sequence=
s->progressive_frame= get_bits1(gb)^1;
+ s->interlaced_dct=0;
if(!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO))
av_log(s->avctx, AV_LOG_INFO, "MPEG4 OBMC not supported (very likely buggy encoder)\n"); /* OBMC Disable */
if (vo_ver_id == 1) {
skip_bits1(gb); /* marker */
}
s->num_sprite_warping_points= get_bits(gb, 6);
+ if(s->num_sprite_warping_points > 3){
+ av_log(s->avctx, AV_LOG_ERROR, "%d sprite_warping_points\n", s->num_sprite_warping_points);
+ s->num_sprite_warping_points= 0;
+ return -1;
+ }
s->sprite_warping_accuracy = get_bits(gb, 2);
s->sprite_brightness_change= get_bits1(gb);
if(s->vol_sprite_usage==STATIC_SPRITE)
/* load custom intra matrix */
if(get_bits1(gb)){
int last=0;
- for(i=0; i<64; i++){
+ for(i=0; i<64; i++){
int j;
v= get_bits(gb, 8);
if(v==0) break;
/* replicate last value */
for(; i<64; i++){
- int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
+ int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
s->intra_matrix[j]= last;
s->chroma_intra_matrix[j]= last;
}
/* load custom non intra matrix */
if(get_bits1(gb)){
int last=0;
- for(i=0; i<64; i++){
+ for(i=0; i<64; i++){
int j;
v= get_bits(gb, 8);
if(v==0) break;
/* replicate last value */
for(; i<64; i++){
- int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
+ int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
s->inter_matrix[j]= last;
s->chroma_inter_matrix[j]= last;
}
int ver = 0, build = 0, ver2 = 0, ver3 = 0;
char last;
- for(i=0; i<255 && gb->index < gb->size_in_bits; i++){
+ for(i=0; i<255 && get_bits_count(gb) < gb->size_in_bits; i++){
if(show_bits(gb, 23) == 0) break;
buf[i]= get_bits(gb, 8);
}
static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){
int time_incr, time_increment;
- s->pict_type = get_bits(gb, 2) + I_TYPE; /* pict type: I = 0 , P = 1 */
+ s->pict_type = get_bits(gb, 2) + I_TYPE; /* pict type: I = 0 , P = 1 */
if(s->pict_type==B_TYPE && s->low_delay && s->vol_control_parameters==0 && !(s->flags & CODEC_FLAG_LOW_DELAY)){
av_log(s->avctx, AV_LOG_ERROR, "low_delay flag incorrectly, clearing it\n");
s->low_delay=0;
// printf("messed up order, maybe after seeking? skipping current b frame\n");
return FRAME_SKIPPED;
}
+ ff_mpeg4_init_direct_mv(s);
if(s->t_frame==0) s->t_frame= s->pb_time;
if(s->t_frame==0) s->t_frame=1; // 1/0 protection
- ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2;
s->pb_field_time= ( ROUNDED_DIV(s->time, s->t_frame)
- ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2;
+ if(!s->progressive_sequence){
+ if(s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1)
+ return FRAME_SKIPPED;
+ }
}
-//av_log(s->avctx, AV_LOG_DEBUG, "last nonb %Ld last_base %d time %Ld pp %d pb %d t %d ppf %d pbf %d\n", s->last_non_b_time, s->last_time_base, s->time, s->pp_time, s->pb_time, s->t_frame, s->pp_field_time, s->pb_field_time);
+//av_log(s->avctx, AV_LOG_DEBUG, "last nonb %"PRId64" last_base %d time %"PRId64" pp %d pb %d t %d ppf %d pbf %d\n", s->last_non_b_time, s->last_time_base, s->time, s->pp_time, s->pb_time, s->t_frame, s->pp_field_time, s->pb_field_time);
if(s->avctx->time_base.num)
s->current_picture_ptr->pts= (s->time + s->avctx->time_base.num/2) / s->avctx->time_base.num;
av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n");
return FRAME_SKIPPED;
}
-//printf("time %d %d %d || %Ld %Ld %Ld\n", s->time_increment_bits, s->avctx->time_base.den, s->time_base,
+//printf("time %d %d %d || %"PRId64" %"PRId64" %"PRId64"\n", s->time_increment_bits, s->avctx->time_base.den, s->time_base,
//s->time, s->last_non_b_time, s->last_non_b_time - s->pp_time);
if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == P_TYPE
|| (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) {
/* rounding type for motion estimation */
- s->no_rounding = get_bits1(gb);
+ s->no_rounding = get_bits1(gb);
} else {
- s->no_rounding = 0;
+ s->no_rounding = 0;
}
//FIXME reduced res stuff
}
if (s->pict_type != I_TYPE) {
- s->f_code = get_bits(gb, 3); /* fcode_for */
+ s->f_code = get_bits(gb, 3); /* fcode_for */
if(s->f_code==0){
av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (f_code=0)\n");
return -1; // makes no sense to continue, as the MV decoding will break very quickly
/* search next start code */
align_get_bits(gb);
- if(s->avctx->codec_tag == ff_get_fourcc("WV1F") && show_bits(gb, 24) == 0x575630){
+ if(s->codec_tag == ff_get_fourcc("WV1F") && show_bits(gb, 24) == 0x575630){
skip_bits(gb, 24);
if(get_bits(gb, 8) == 0xF0)
return decode_vop_header(s, gb);
if (get_bits1(&s->gb) != 1) {
av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n");
- return -1; /* marker */
+ return -1; /* marker */
}
if (get_bits1(&s->gb) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n");
- return -1; /* h263 id */
+ return -1; /* h263 id */
}
- skip_bits1(&s->gb); /* split screen off */
- skip_bits1(&s->gb); /* camera off */
- skip_bits1(&s->gb); /* freeze picture release off */
+ skip_bits1(&s->gb); /* split screen off */
+ skip_bits1(&s->gb); /* camera off */
+ skip_bits1(&s->gb); /* freeze picture release off */
format = get_bits(&s->gb, 3);
if (format != 7) {
if (get_bits1(&s->gb) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
- return -1; /* SAC: off */
- }
- if (get_bits1(&s->gb) != 0) {
- s->obmc= 1;
- av_log(s->avctx, AV_LOG_ERROR, "Advanced Prediction Mode not supported\n");
-// return -1; /* advanced prediction mode: off */
+ return -1; /* SAC: off */
}
+ s->obmc= get_bits1(&s->gb);
if (get_bits1(&s->gb) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "PB frame mode no supported\n");
- return -1; /* PB frame mode */
+ return -1; /* PB frame mode */
}
/* skip unknown header garbage */
skip_bits(&s->gb, 41);
s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
- skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
+ skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
/* PEI */
while (get_bits1(&s->gb) != 0) {
s->y_dc_scale_table=
s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
+ if(s->avctx->debug&FF_DEBUG_PICT_INFO)
+ show_pict_info(s);
+
return 0;
}
if (s->dropable)
s->pict_type = P_TYPE;
- skip_bits1(&s->gb); /* deblocking flag */
+ skip_bits1(&s->gb); /* deblocking flag */
s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
s->h263_plus = 0;