* 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
*/
+/**
+ * @file mpegvideo.c
+ * The simplest mpeg encoder (well, it was the simplest!).
+ */
+
#include <ctype.h>
#include <limits.h>
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
-#include "simple_idct.h"
#ifdef USE_FASTMEMCPY
#include "fastmemcpy.h"
//#undef NDEBUG
//#include <assert.h>
+#ifdef CONFIG_ENCODERS
static void encode_picture(MpegEncContext *s, int picture_number);
+#endif //CONFIG_ENCODERS
static void dct_unquantize_mpeg1_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void dct_unquantize_mpeg2_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
static void dct_unquantize_h263_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale);
-static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w);
+static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w);
+#ifdef CONFIG_ENCODERS
static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
+#endif //CONFIG_ENCODERS
-void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c;
+void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_edges_c;
/* enable all paranoid tests for rounding, overflows, etc... */
4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247
};
-/* Input permutation for the simple_idct_mmx */
-static const uint8_t simple_mmx_permutation[64]={
- 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
- 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
- 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
- 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
- 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
- 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
- 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
- 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
-};
-
static const uint8_t h263_chroma_roundtab[16] = {
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
};
-static UINT16 (*default_mv_penalty)[MAX_MV*2+1]=NULL;
-static UINT8 default_fcode_tab[MAX_MV*2+1];
+#ifdef CONFIG_ENCODERS
+static uint16_t (*default_mv_penalty)[MAX_MV*2+1]=NULL;
+static uint8_t default_fcode_tab[MAX_MV*2+1];
enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1};
static void convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64],
- const UINT16 *quant_matrix, int bias, int qmin, int qmax)
+ const uint16_t *quant_matrix, int bias, int qmin, int qmax)
{
int qscale;
for(qscale=qmin; qscale<=qmax; qscale++){
int i;
- if (s->fdct == ff_jpeg_fdct_islow) {
+ if (s->dsp.fdct == ff_jpeg_fdct_islow) {
for(i=0;i<64;i++) {
- const int j= s->idct_permutation[i];
+ const int j= s->dsp.idct_permutation[i];
/* 16 <= qscale * quant_matrix[i] <= 7905 */
/* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
/* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
/* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
- qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) /
+ qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) /
(qscale * quant_matrix[j]));
}
- } else if (s->fdct == fdct_ifast) {
+ } else if (s->dsp.fdct == fdct_ifast) {
for(i=0;i<64;i++) {
- const int j= s->idct_permutation[i];
+ const int j= s->dsp.idct_permutation[i];
/* 16 <= qscale * quant_matrix[i] <= 7905 */
/* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
/* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
/* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
- qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 14)) /
+ qmat[qscale][i] = (int)((uint64_t_C(1) << (QMAT_SHIFT + 14)) /
(aanscales[i] * qscale * quant_matrix[j]));
}
} else {
for(i=0;i<64;i++) {
- const int j= s->idct_permutation[i];
+ const int j= s->dsp.idct_permutation[i];
/* We can safely suppose that 16 <= quant_matrix[i] <= 255
So 16 <= qscale * quant_matrix[i] <= 7905
so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905
so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67
*/
- qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j]));
+ qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j]));
// qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]);
qmat16[qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]);
}
}
}
+#endif //CONFIG_ENCODERS
+
// move into common.c perhaps
#define CHECKED_ALLOCZ(p, size)\
{\
}\
}
-void ff_init_scantable(MpegEncContext *s, ScanTable *st, const UINT8 *src_scantable){
+void ff_init_scantable(MpegEncContext *s, ScanTable *st, const uint8_t *src_scantable){
int i;
int end;
for(i=0; i<64; i++){
int j;
j = src_scantable[i];
- st->permutated[i] = s->idct_permutation[j];
+ st->permutated[i] = s->dsp.idct_permutation[j];
#ifdef ARCH_POWERPC
st->inverse[j] = i;
#endif
}
}
-/* XXX: those functions should be suppressed ASAP when all IDCTs are
- converted */
-// *FIXME* this is ugly hack using local static
-static void (*ff_put_pixels_clamped)(const DCTELEM *block, UINT8 *pixels, int line_size);
-static void (*ff_add_pixels_clamped)(const DCTELEM *block, UINT8 *pixels, int line_size);
-static void ff_jref_idct_put(UINT8 *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct (block);
- ff_put_pixels_clamped(block, dest, line_size);
-}
-static void ff_jref_idct_add(UINT8 *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct (block);
- ff_add_pixels_clamped(block, dest, line_size);
-}
-
/* init common dct for both encoder and decoder */
int DCT_common_init(MpegEncContext *s)
{
- int i;
-
- ff_put_pixels_clamped = s->dsp.put_pixels_clamped;
- ff_add_pixels_clamped = s->dsp.add_pixels_clamped;
-
s->dct_unquantize_h263 = dct_unquantize_h263_c;
s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c;
s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c;
- s->dct_quantize= dct_quantize_c;
-
- if(s->avctx->dct_algo==FF_DCT_FASTINT)
- s->fdct = fdct_ifast;
- else
- s->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
- if(s->avctx->idct_algo==FF_IDCT_INT){
- s->idct_put= ff_jref_idct_put;
- s->idct_add= ff_jref_idct_add;
- s->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
- }else{ //accurate/default
- s->idct_put= simple_idct_put;
- s->idct_add= simple_idct_add;
- s->idct_permutation_type= FF_NO_IDCT_PERM;
- }
+#ifdef CONFIG_ENCODERS
+ s->dct_quantize= dct_quantize_c;
+#endif
#ifdef HAVE_MMX
MPV_common_init_mmx(s);
MPV_common_init_ppc(s);
#endif
+#ifdef CONFIG_ENCODERS
s->fast_dct_quantize= s->dct_quantize;
if(s->flags&CODEC_FLAG_TRELLIS_QUANT){
s->dct_quantize= dct_quantize_trellis_c; //move before MPV_common_init_*
}
- switch(s->idct_permutation_type){
- case FF_NO_IDCT_PERM:
- for(i=0; i<64; i++)
- s->idct_permutation[i]= i;
- break;
- case FF_LIBMPEG2_IDCT_PERM:
- for(i=0; i<64; i++)
- s->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
- break;
- case FF_SIMPLE_IDCT_PERM:
- for(i=0; i<64; i++)
- s->idct_permutation[i]= simple_mmx_permutation[i];
- break;
- case FF_TRANSPOSE_IDCT_PERM:
- for(i=0; i<64; i++)
- s->idct_permutation[i]= ((i&7)<<3) | (i>>3);
- break;
- default:
- fprintf(stderr, "Internal error, IDCT permutation not set\n");
- return -1;
- }
-
+#endif //CONFIG_ENCODERS
/* load & permutate scantables
note: only wmv uses differnt ones
ff_init_scantable(s, &s->intra_h_scantable, ff_alternate_horizontal_scan);
ff_init_scantable(s, &s->intra_v_scantable, ff_alternate_vertical_scan);
+ s->picture_structure= PICT_FRAME;
+
return 0;
}
if(pic->qscale_table==NULL){
if (s->encoding) {
- CHECKED_ALLOCZ(pic->mb_var , s->mb_num * sizeof(INT16))
- CHECKED_ALLOCZ(pic->mc_mb_var, s->mb_num * sizeof(INT16))
- CHECKED_ALLOCZ(pic->mb_mean , s->mb_num * sizeof(INT8))
+ CHECKED_ALLOCZ(pic->mb_var , s->mb_num * sizeof(int16_t))
+ CHECKED_ALLOCZ(pic->mc_mb_var, s->mb_num * sizeof(int16_t))
+ CHECKED_ALLOCZ(pic->mb_mean , s->mb_num * sizeof(int8_t))
CHECKED_ALLOCZ(pic->mb_cmp_score, s->mb_num * sizeof(int32_t))
}
- CHECKED_ALLOCZ(pic->mbskip_table , s->mb_num * sizeof(UINT8)+1) //the +1 is for the slice end check
- CHECKED_ALLOCZ(pic->qscale_table , s->mb_num * sizeof(UINT8))
+ CHECKED_ALLOCZ(pic->mbskip_table , s->mb_num * sizeof(uint8_t)+1) //the +1 is for the slice end check
+ CHECKED_ALLOCZ(pic->qscale_table , s->mb_num * sizeof(uint8_t))
pic->qstride= s->mb_width;
}
{
int y_size, c_size, yc_size, i;
- dsputil_init(&s->dsp, s->avctx->dsp_mask);
+ dsputil_init(&s->dsp, s->avctx);
DCT_common_init(s);
s->flags= s->avctx->flags;
int mv_table_size= (s->mb_width+2)*(s->mb_height+2);
/* Allocate MV tables */
- CHECKED_ALLOCZ(s->p_mv_table , mv_table_size * 2 * sizeof(INT16))
- CHECKED_ALLOCZ(s->b_forw_mv_table , mv_table_size * 2 * sizeof(INT16))
- CHECKED_ALLOCZ(s->b_back_mv_table , mv_table_size * 2 * sizeof(INT16))
- CHECKED_ALLOCZ(s->b_bidir_forw_mv_table , mv_table_size * 2 * sizeof(INT16))
- CHECKED_ALLOCZ(s->b_bidir_back_mv_table , mv_table_size * 2 * sizeof(INT16))
- CHECKED_ALLOCZ(s->b_direct_mv_table , mv_table_size * 2 * sizeof(INT16))
+ CHECKED_ALLOCZ(s->p_mv_table , mv_table_size * 2 * sizeof(int16_t))
+ CHECKED_ALLOCZ(s->b_forw_mv_table , mv_table_size * 2 * sizeof(int16_t))
+ CHECKED_ALLOCZ(s->b_back_mv_table , mv_table_size * 2 * sizeof(int16_t))
+ CHECKED_ALLOCZ(s->b_bidir_forw_mv_table , mv_table_size * 2 * sizeof(int16_t))
+ CHECKED_ALLOCZ(s->b_bidir_back_mv_table , mv_table_size * 2 * sizeof(int16_t))
+ CHECKED_ALLOCZ(s->b_direct_mv_table , mv_table_size * 2 * sizeof(int16_t))
//FIXME should be linesize instead of s->width*2 but that isnt known before get_buffer()
CHECKED_ALLOCZ(s->me.scratchpad, s->width*2*16*3*sizeof(uint8_t))
CHECKED_ALLOCZ(s->avctx->stats_out, 256);
}
- CHECKED_ALLOCZ(s->error_status_table, s->mb_num*sizeof(UINT8))
+ CHECKED_ALLOCZ(s->error_status_table, s->mb_num*sizeof(uint8_t))
if (s->out_format == FMT_H263 || s->encoding) {
int size;
/* Allocate MB type table */
- CHECKED_ALLOCZ(s->mb_type , s->mb_num * sizeof(UINT8))
+ CHECKED_ALLOCZ(s->mb_type , s->mb_num * sizeof(uint8_t))
/* MV prediction */
size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
- CHECKED_ALLOCZ(s->motion_val, size * 2 * sizeof(INT16));
+ CHECKED_ALLOCZ(s->motion_val, size * 2 * sizeof(int16_t));
}
if(s->codec_id==CODEC_ID_MPEG4){
/* interlaced direct mode decoding tables */
- CHECKED_ALLOCZ(s->field_mv_table, s->mb_num*2*2 * sizeof(INT16))
- CHECKED_ALLOCZ(s->field_select_table, s->mb_num*2* sizeof(INT8))
+ CHECKED_ALLOCZ(s->field_mv_table, s->mb_num*2*2 * sizeof(int16_t))
+ CHECKED_ALLOCZ(s->field_select_table, s->mb_num*2* sizeof(int8_t))
}
/* 4mv b frame decoding table */
//note this is needed for h263 without b frames too (segfault on damaged streams otherwise)
- CHECKED_ALLOCZ(s->co_located_type_table, s->mb_num * sizeof(UINT8))
+ CHECKED_ALLOCZ(s->co_located_type_table, s->mb_num * sizeof(uint8_t))
if (s->out_format == FMT_H263) {
/* ac values */
- CHECKED_ALLOCZ(s->ac_val[0], yc_size * sizeof(INT16) * 16);
+ CHECKED_ALLOCZ(s->ac_val[0], yc_size * sizeof(int16_t) * 16);
s->ac_val[1] = s->ac_val[0] + y_size;
s->ac_val[2] = s->ac_val[1] + c_size;
CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE);
/* cbp, ac_pred, pred_dir */
- CHECKED_ALLOCZ(s->cbp_table , s->mb_num * sizeof(UINT8))
- CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(UINT8))
+ CHECKED_ALLOCZ(s->cbp_table , s->mb_num * sizeof(uint8_t))
+ CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(uint8_t))
}
if (s->h263_pred || s->h263_plus || !s->encoding) {
/* dc values */
//MN: we need these for error resilience of intra-frames
- CHECKED_ALLOCZ(s->dc_val[0], yc_size * sizeof(INT16));
+ CHECKED_ALLOCZ(s->dc_val[0], yc_size * sizeof(int16_t));
s->dc_val[1] = s->dc_val[0] + y_size;
s->dc_val[2] = s->dc_val[1] + c_size;
for(i=0;i<yc_size;i++)
s->context_initialized = 0;
}
+#ifdef CONFIG_ENCODERS
+
/* init video encoder */
int MPV_encode_init(AVCodecContext *avctx)
{
avctx->delay=0;
s->low_delay=1;
break;
+#ifdef CONFIG_RISKY
case CODEC_ID_H263:
if (h263_get_picture_format(s->width, s->height) == 7) {
printf("Input picture size isn't suitable for h263 codec! try h263+\n");
case CODEC_ID_H263P:
s->out_format = FMT_H263;
s->h263_plus = 1;
- s->unrestricted_mv = 1;
- s->h263_aic = 1;
-
+ /* Fx */
+ s->unrestricted_mv=(avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0;
+ s->h263_aic= (avctx->flags & CODEC_FLAG_H263P_AIC) ? 1:0;
+ /* /Fx */
/* These are just to be sure */
- s->umvplus = 0;
- s->umvplus_dec = 0;
+ s->umvplus = 1;
avctx->delay=0;
s->low_delay=1;
break;
avctx->delay=0;
s->low_delay=1;
break;
+#endif
default:
return -1;
}
int i;
done=1;
- default_mv_penalty= av_mallocz( sizeof(UINT16)*(MAX_FCODE+1)*(2*MAX_MV+1) );
- memset(default_mv_penalty, 0, sizeof(UINT16)*(MAX_FCODE+1)*(2*MAX_MV+1));
- memset(default_fcode_tab , 0, sizeof(UINT8)*(2*MAX_MV+1));
+ default_mv_penalty= av_mallocz( sizeof(uint16_t)*(MAX_FCODE+1)*(2*MAX_MV+1) );
+ memset(default_mv_penalty, 0, sizeof(uint16_t)*(MAX_FCODE+1)*(2*MAX_MV+1));
+ memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1));
for(i=-16; i<16; i++){
default_fcode_tab[i + MAX_MV]= 1;
ff_init_me(s);
#ifdef CONFIG_ENCODERS
+#ifdef CONFIG_RISKY
if (s->out_format == FMT_H263)
h263_encode_init(s);
- else if (s->out_format == FMT_MPEG1)
- ff_mpeg1_encode_init(s);
if(s->msmpeg4_version)
ff_msmpeg4_encode_init(s);
#endif
+ if (s->out_format == FMT_MPEG1)
+ ff_mpeg1_encode_init(s);
+#endif
/* init default q matrix */
for(i=0;i<64;i++) {
- int j= s->idct_permutation[i];
+ int j= s->dsp.idct_permutation[i];
+#ifdef CONFIG_RISKY
if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){
s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];
s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i];
}else if(s->out_format == FMT_H263){
s->intra_matrix[j] =
s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
- }else{ /* mpeg1 */
+ }else
+#endif
+ { /* mpeg1 */
s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];
s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
}
return 0;
}
+#endif //CONFIG_ENCODERS
+
+void init_rl(RLTable *rl)
+{
+ int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1];
+ uint8_t index_run[MAX_RUN+1];
+ int last, run, level, start, end, i;
+
+ /* compute max_level[], max_run[] and index_run[] */
+ for(last=0;last<2;last++) {
+ if (last == 0) {
+ start = 0;
+ end = rl->last;
+ } else {
+ start = rl->last;
+ end = rl->n;
+ }
+
+ memset(max_level, 0, MAX_RUN + 1);
+ memset(max_run, 0, MAX_LEVEL + 1);
+ memset(index_run, rl->n, MAX_RUN + 1);
+ for(i=start;i<end;i++) {
+ run = rl->table_run[i];
+ level = rl->table_level[i];
+ if (index_run[run] == rl->n)
+ index_run[run] = i;
+ if (level > max_level[run])
+ max_level[run] = level;
+ if (run > max_run[level])
+ max_run[level] = run;
+ }
+ rl->max_level[last] = av_malloc(MAX_RUN + 1);
+ memcpy(rl->max_level[last], max_level, MAX_RUN + 1);
+ rl->max_run[last] = av_malloc(MAX_LEVEL + 1);
+ memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1);
+ rl->index_run[last] = av_malloc(MAX_RUN + 1);
+ memcpy(rl->index_run[last], index_run, MAX_RUN + 1);
+ }
+}
+
/* draw the edges of width 'w' of an image of size width, height */
//FIXME check that this is ok for mpeg4 interlaced
-static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w)
+static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w)
{
- UINT8 *ptr, *last_line;
+ uint8_t *ptr, *last_line;
int i;
last_line = buf + (height - 1) * wrap;
}
}
+#ifdef CONFIG_ENCODERS
+
static int get_sae(uint8_t *src, int ref, int stride){
int x,y;
int acc=0;
return pbBufPtr(&s->pb) - s->pb.buf;
}
+#endif //CONFIG_ENCODERS
+
static inline void gmc1_motion(MpegEncContext *s,
- UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
int dest_offset,
- UINT8 **ref_picture, int src_offset)
+ uint8_t **ref_picture, int src_offset)
{
- UINT8 *ptr;
+ uint8_t *ptr;
int offset, src_x, src_y, linesize, uvlinesize;
int motion_x, motion_y;
int emu=0;
}
static inline void gmc_motion(MpegEncContext *s,
- UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
int dest_offset,
- UINT8 **ref_picture, int src_offset)
+ uint8_t **ref_picture, int src_offset)
{
- UINT8 *ptr;
+ uint8_t *ptr;
int linesize, uvlinesize;
const int a= s->sprite_warping_accuracy;
int ox, oy;
}
-void ff_emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h,
+void ff_emulated_edge_mc(MpegEncContext *s, uint8_t *src, int linesize, int block_w, int block_h,
int src_x, int src_y, int w, int h){
int x, y;
int start_y, start_x, end_y, end_x;
- UINT8 *buf= s->edge_emu_buffer;
+ uint8_t *buf= s->edge_emu_buffer;
if(src_y>= h){
src+= (h-1-src_y)*linesize;
/* apply one mpeg motion vector to the three components */
static inline void mpeg_motion(MpegEncContext *s,
- UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
int dest_offset,
- UINT8 **ref_picture, int src_offset,
+ uint8_t **ref_picture, int src_offset,
int field_based, op_pixels_func (*pix_op)[4],
int motion_x, int motion_y, int h)
{
- UINT8 *ptr;
+ uint8_t *ptr;
int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize;
int emu=0;
#if 0
}
static inline void qpel_motion(MpegEncContext *s,
- UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
int dest_offset,
- UINT8 **ref_picture, int src_offset,
+ uint8_t **ref_picture, int src_offset,
int field_based, op_pixels_func (*pix_op)[4],
qpel_mc_func (*qpix_op)[16],
int motion_x, int motion_y, int h)
{
- UINT8 *ptr;
+ uint8_t *ptr;
int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize;
int emu=0;
if(field_based){
mx= motion_x/2;
my= motion_y>>1;
+ }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){
+ static const int rtab[8]= {0,0,1,1,0,0,0,1};
+ mx= (motion_x>>1) + rtab[motion_x&7];
+ my= (motion_y>>1) + rtab[motion_y&7];
}else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){
mx= (motion_x>>1)|(motion_x&1);
my= (motion_y>>1)|(motion_y&1);
}
mx= (mx>>1)|(mx&1);
my= (my>>1)|(my&1);
+
dxy= (mx&1) | ((my&1)<<1);
mx>>=1;
my>>=1;
}
static inline void MPV_motion(MpegEncContext *s,
- UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr,
- int dir, UINT8 **ref_picture,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int dir, uint8_t **ref_picture,
op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16])
{
int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y;
int mb_x, mb_y, i;
- UINT8 *ptr, *dest;
+ uint8_t *ptr, *dest;
int emu=0;
mb_x = s->mb_x;
switch(s->mv_type) {
case MV_TYPE_16X16:
+#ifdef CONFIG_RISKY
if(s->mcsel){
if(s->real_sprite_warping_points==1){
gmc1_motion(s, dest_y, dest_cb, dest_cr, 0,
ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
ref_picture, pix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 16);
- }else{
+ }else
+#endif
+ {
mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
ref_picture, 0,
0, pix_op,
s->mv[dir][1][0], s->mv[dir][1][1], 8);
}
} else {
-
+ int offset;
+ if(s->picture_structure == s->field_select[dir][0] + 1 || s->pict_type == B_TYPE || s->first_field){
+ offset= s->field_select[dir][0] ? s->linesize/2 : 0;
+ }else{
+ ref_picture= s->current_picture.data;
+ offset= s->field_select[dir][0] ? s->linesize/2 : -s->linesize/2;
+ }
+ mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
+ ref_picture, offset,
+ 0, pix_op,
+ s->mv[dir][0][0], s->mv[dir][0][1], 16);
}
break;
}
/* put block[] to dest[] */
static inline void put_dct(MpegEncContext *s,
- DCTELEM *block, int i, UINT8 *dest, int line_size)
+ DCTELEM *block, int i, uint8_t *dest, int line_size)
{
s->dct_unquantize(s, block, i, s->qscale);
- s->idct_put (dest, line_size, block);
+ s->dsp.idct_put (dest, line_size, block);
}
/* add block[] to dest[] */
static inline void add_dct(MpegEncContext *s,
- DCTELEM *block, int i, UINT8 *dest, int line_size)
+ DCTELEM *block, int i, uint8_t *dest, int line_size)
{
if (s->block_last_index[i] >= 0) {
- s->idct_add (dest, line_size, block);
+ s->dsp.idct_add (dest, line_size, block);
}
}
static inline void add_dequant_dct(MpegEncContext *s,
- DCTELEM *block, int i, UINT8 *dest, int line_size)
+ DCTELEM *block, int i, uint8_t *dest, int line_size)
{
if (s->block_last_index[i] >= 0) {
s->dct_unquantize(s, block, i, s->qscale);
- s->idct_add (dest, line_size, block);
+ s->dsp.idct_add (dest, line_size, block);
}
}
s->dc_val[0][xy + wrap] =
s->dc_val[0][xy + 1 + wrap] = 1024;
/* ac pred */
- memset(s->ac_val[0][xy ], 0, 32 * sizeof(INT16));
- memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(INT16));
+ memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t));
+ memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t));
if (s->msmpeg4_version>=3) {
s->coded_block[xy ] =
s->coded_block[xy + 1 ] =
s->dc_val[1][xy] =
s->dc_val[2][xy] = 1024;
/* ac pred */
- memset(s->ac_val[1][xy], 0, 16 * sizeof(INT16));
- memset(s->ac_val[2][xy], 0, 16 * sizeof(INT16));
+ memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t));
+ memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t));
s->mbintra_table[s->mb_x + s->mb_y*s->mb_width]= 0;
}
}
if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { //FIXME precalc
- UINT8 *dest_y, *dest_cb, *dest_cr;
+ uint8_t *dest_y, *dest_cb, *dest_cr;
int dct_linesize, dct_offset;
op_pixels_func (*op_pix)[4];
qpel_mc_func (*op_qpix)[16];
/* skip only during decoding as we might trash the buffers during encoding a bit */
if(!s->encoding){
- UINT8 *mbskip_ptr = &s->mbskip_table[mb_xy];
+ uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
const int age= s->current_picture.age;
assert(age);
}else
s->mb_skiped= 0;
- if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band){
+ if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME){ //FIXME precalc
dest_y = s->current_picture.data[0] + mb_x * 16;
dest_cb = s->current_picture.data[1] + mb_x * 8;
dest_cr = s->current_picture.data[2] + mb_x * 8;
add_dct(s, block[4], 4, dest_cb, s->uvlinesize);
add_dct(s, block[5], 5, dest_cr, s->uvlinesize);
}
- } else{
+ }
+#ifdef CONFIG_RISKY
+ else{
ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
}
+#endif
} else {
/* dct only in intra block */
if(s->encoding || !(s->mpeg2 || s->codec_id==CODEC_ID_MPEG1VIDEO)){
put_dct(s, block[5], 5, dest_cr, s->uvlinesize);
}
}else{
- s->idct_put(dest_y , dct_linesize, block[0]);
- s->idct_put(dest_y + 8, dct_linesize, block[1]);
- s->idct_put(dest_y + dct_offset , dct_linesize, block[2]);
- s->idct_put(dest_y + dct_offset + 8, dct_linesize, block[3]);
+ s->dsp.idct_put(dest_y , dct_linesize, block[0]);
+ s->dsp.idct_put(dest_y + 8, dct_linesize, block[1]);
+ s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]);
+ s->dsp.idct_put(dest_y + dct_offset + 8, dct_linesize, block[3]);
if(!(s->flags&CODEC_FLAG_GRAY)){
- s->idct_put(dest_cb, s->uvlinesize, block[4]);
- s->idct_put(dest_cr, s->uvlinesize, block[5]);
+ s->dsp.idct_put(dest_cb, s->uvlinesize, block[4]);
+ s->dsp.idct_put(dest_cr, s->uvlinesize, block[5]);
}
}
}
}
}
+#ifdef CONFIG_ENCODERS
+
static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold)
{
static const char tab[64]=
if (level>maxlevel) level=maxlevel;
else if(level<minlevel) level=minlevel;
- block[j]= level;
- }
-}
-
-static inline void requantize_coeffs(MpegEncContext *s, DCTELEM block[64], int oldq, int newq, int n)
-{
- int i;
-
- if(s->mb_intra){
- i=1; //skip clipping of intra dc
- //FIXME requantize, note (mpeg1/h263/h263p-aic dont need it,...)
- }else
- i=0;
-
- for(;i<=s->block_last_index[n]; i++){
- const int j = s->intra_scantable.permutated[i];
- int level = block[j];
-
- block[j]= ROUNDED_DIV(level*oldq, newq);
- }
- for(i=s->block_last_index[n]; i>=0; i--){
- const int j = s->intra_scantable.permutated[i];
- if(block[j]) break;
+ block[j]= level;
}
- s->block_last_index[n]= i;
}
-static inline void auto_requantize_coeffs(MpegEncContext *s, DCTELEM block[6][64])
-{
- int i,n, newq;
- const int maxlevel= s->max_qcoeff;
- const int minlevel= s->min_qcoeff;
- int largest=0, smallest=0;
-
- assert(s->adaptive_quant);
-
- for(n=0; n<6; n++){
- if(s->mb_intra){
- i=1; //skip clipping of intra dc
- //FIXME requantize, note (mpeg1/h263/h263p-aic dont need it,...)
- }else
- i=0;
-
- for(;i<=s->block_last_index[n]; i++){
- const int j = s->intra_scantable.permutated[i];
- int level = block[n][j];
- if(largest < level) largest = level;
- if(smallest > level) smallest= level;
- }
- }
-
- for(newq=s->qscale+1; newq<32; newq++){
- if( ROUNDED_DIV(smallest*s->qscale, newq) >= minlevel
- && ROUNDED_DIV(largest *s->qscale, newq) <= maxlevel)
- break;
- }
-
- if(s->out_format==FMT_H263){
- /* h263 like formats cannot change qscale by more than 2 easiely */
- if(s->avctx->qmin + 2 < newq)
- newq= s->avctx->qmin + 2;
- }
-
- for(n=0; n<6; n++){
- requantize_coeffs(s, block[n], s->qscale, newq, n);
- clip_coeffs(s, block[n], s->block_last_index[n]);
- }
-
- s->dquant+= newq - s->qscale;
- s->qscale= newq;
-}
#if 0
-static int pix_vcmp16x8(UINT8 *s, int stride){ //FIXME move to dsputil & optimize
+static int pix_vcmp16x8(uint8_t *s, int stride){ //FIXME move to dsputil & optimize
int score=0;
int x,y;
return score;
}
-static int pix_diff_vcmp16x8(UINT8 *s1, UINT8*s2, int stride){ //FIXME move to dsputil & optimize
+static int pix_diff_vcmp16x8(uint8_t *s1, uint8_t*s2, int stride){ //FIXME move to dsputil & optimize
int score=0;
int x,y;
#else
#define SQ(a) ((a)*(a))
-static int pix_vcmp16x8(UINT8 *s, int stride){ //FIXME move to dsputil & optimize
+static int pix_vcmp16x8(uint8_t *s, int stride){ //FIXME move to dsputil & optimize
int score=0;
int x,y;
return score;
}
-static int pix_diff_vcmp16x8(UINT8 *s1, UINT8*s2, int stride){ //FIXME move to dsputil & optimize
+static int pix_diff_vcmp16x8(uint8_t *s1, uint8_t*s2, int stride){ //FIXME move to dsputil & optimize
int score=0;
int x,y;
#endif
-void ff_draw_horiz_band(MpegEncContext *s){
+#endif //CONFIG_ENCODERS
+
+/**
+ *
+ * @param h is the normal height, this will be reduced automatically if needed for the last row
+ */
+void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
if ( s->avctx->draw_horiz_band
&& (s->last_picture.data[0] || s->low_delay) ) {
- UINT8 *src_ptr[3];
- int y, h, offset;
- y = s->mb_y * 16;
- h = s->height - y;
- if (h > 16)
- h = 16;
-
- if(s->pict_type==B_TYPE)
+ uint8_t *src_ptr[3];
+ int offset;
+ h= FFMIN(h, s->height - y);
+
+ if(s->pict_type==B_TYPE && s->picture_structure == PICT_FRAME)
offset = 0;
else
offset = y * s->linesize;
}
}
+#ifdef CONFIG_ENCODERS
+
static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
{
const int mb_x= s->mb_x;
}
if (s->mb_intra) {
- UINT8 *ptr;
+ uint8_t *ptr;
int wrap_y;
int emu=0;
}else{
op_pixels_func (*op_pix)[4];
qpel_mc_func (*op_qpix)[16];
- UINT8 *dest_y, *dest_cb, *dest_cr;
- UINT8 *ptr_y, *ptr_cb, *ptr_cr;
+ uint8_t *dest_y, *dest_cb, *dest_cr;
+ uint8_t *ptr_y, *ptr_cb, *ptr_cr;
int wrap_y, wrap_c;
int emu=0;
s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale;
}
-#ifdef CONFIG_ENCODERS
/* huffman encode */
switch(s->codec_id){ //FIXME funct ptr could be slightly faster
case CODEC_ID_MPEG1VIDEO:
mpeg1_encode_mb(s, s->block, motion_x, motion_y); break;
+#ifdef CONFIG_RISKY
case CODEC_ID_MPEG4:
mpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
case CODEC_ID_MSMPEG4V2:
msmpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
case CODEC_ID_WMV2:
ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break;
- case CODEC_ID_MJPEG:
- mjpeg_encode_mb(s, s->block); break;
case CODEC_ID_H263:
case CODEC_ID_H263P:
case CODEC_ID_RV10:
h263_encode_mb(s, s->block, motion_x, motion_y); break;
+#endif
+ case CODEC_ID_MJPEG:
+ mjpeg_encode_mb(s, s->block); break;
default:
assert(0);
}
-#endif
}
-void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length)
+#endif //CONFIG_ENCODERS
+
+/**
+ * combines the (truncated) bitstream to a complete frame
+ * @returns -1 if no complete frame could be created
+ */
+int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size){
+ ParseContext *pc= &s->parse_context;
+
+ pc->last_index= pc->index;
+
+ if(next==-1){
+ pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ memcpy(&pc->buffer[pc->index], *buf, *buf_size);
+ pc->index += *buf_size;
+ return -1;
+ }
+
+ if(pc->index){
+ pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
+
+ memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE );
+ pc->index = 0;
+ *buf= pc->buffer;
+ *buf_size= pc->last_index + next;
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_ENCODERS
+void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length)
{
int bytes= length>>4;
int bits= length&15;
int i;
int bits;
MpegEncContext best_s, backup_s;
- UINT8 bit_buf[2][3000];
- UINT8 bit_buf2[2][3000];
- UINT8 bit_buf_tex[2][3000];
+ uint8_t bit_buf[2][3000];
+ uint8_t bit_buf2[2][3000];
+ uint8_t bit_buf_tex[2][3000];
PutBitContext pb[2], pb2[2], tex_pb[2];
for(i=0; i<2; i++){
s->current_picture.mb_var_sum = 0;
s->current_picture.mc_mb_var_sum = 0;
+#ifdef CONFIG_RISKY
/* we need to initialize some time vars before we can encode b-frames */
- if (s->h263_pred && !s->h263_msmpeg4)
+ // RAL: Condition added for MPEG1VIDEO
+ if (s->codec_id == CODEC_ID_MPEG1VIDEO || (s->h263_pred && !s->h263_msmpeg4))
ff_set_mpeg4_time(s, s->picture_number);
-
+#endif
+
s->scene_change_score=0;
s->qscale= (int)(s->frame_qscale + 0.5); //FIXME qscale / ... stuff for ME ratedistoration
- if(s->msmpeg4_version){
- if(s->pict_type==I_TYPE)
- s->no_rounding=1;
- else if(s->flipflop_rounding)
- s->no_rounding ^= 1;
- }else if(s->out_format == FMT_H263){
- if(s->pict_type==I_TYPE)
- s->no_rounding=0;
- else if(s->pict_type!=B_TYPE)
+ if(s->pict_type==I_TYPE){
+ if(s->msmpeg4_version) s->no_rounding=1;
+ else s->no_rounding=0;
+ }else if(s->pict_type!=B_TYPE){
+ if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4)
s->no_rounding ^= 1;
}
+
/* Estimate motion for every MB */
s->mb_intra=0; //for the rate distoration & bit compare functions
if(s->pict_type != I_TYPE){
}else /* if(s->pict_type == I_TYPE) */{
/* I-Frame */
//FIXME do we need to zero them?
- memset(s->motion_val[0], 0, sizeof(INT16)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2);
- memset(s->p_mv_table , 0, sizeof(INT16)*(s->mb_width+2)*(s->mb_height+2)*2);
- memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height);
+ memset(s->motion_val[0], 0, sizeof(int16_t)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2);
+ memset(s->p_mv_table , 0, sizeof(int16_t)*(s->mb_width+2)*(s->mb_height+2)*2);
+ memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_width*s->mb_height);
if(!s->fixed_qscale){
/* finding spatial complexity for I-frame rate control */
if(s->scene_change_score > 0 && s->pict_type == P_TYPE){
s->pict_type= I_TYPE;
- memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height);
+ memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_width*s->mb_height);
//printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum);
}
- if(s->pict_type==P_TYPE || s->pict_type==S_TYPE)
- s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER);
- ff_fix_long_p_mvs(s);
- if(s->pict_type==B_TYPE){
- s->f_code= ff_get_best_fcode(s, s->b_forw_mv_table, MB_TYPE_FORWARD);
- s->b_code= ff_get_best_fcode(s, s->b_back_mv_table, MB_TYPE_BACKWARD);
+ if(!s->umvplus){
+ if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) {
+ s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER);
+
+ ff_fix_long_p_mvs(s);
+ }
+
+ if(s->pict_type==B_TYPE){
+ int a, b;
+
+ a = ff_get_best_fcode(s, s->b_forw_mv_table, MB_TYPE_FORWARD);
+ b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, MB_TYPE_BIDIR);
+ s->f_code = FFMAX(a, b);
- ff_fix_long_b_mvs(s, s->b_forw_mv_table, s->f_code, MB_TYPE_FORWARD);
- ff_fix_long_b_mvs(s, s->b_back_mv_table, s->b_code, MB_TYPE_BACKWARD);
- ff_fix_long_b_mvs(s, s->b_bidir_forw_mv_table, s->f_code, MB_TYPE_BIDIR);
- ff_fix_long_b_mvs(s, s->b_bidir_back_mv_table, s->b_code, MB_TYPE_BIDIR);
+ a = ff_get_best_fcode(s, s->b_back_mv_table, MB_TYPE_BACKWARD);
+ b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, MB_TYPE_BIDIR);
+ s->b_code = FFMAX(a, b);
+
+ ff_fix_long_b_mvs(s, s->b_forw_mv_table, s->f_code, MB_TYPE_FORWARD);
+ ff_fix_long_b_mvs(s, s->b_back_mv_table, s->b_code, MB_TYPE_BACKWARD);
+ ff_fix_long_b_mvs(s, s->b_bidir_forw_mv_table, s->f_code, MB_TYPE_BIDIR);
+ ff_fix_long_b_mvs(s, s->b_bidir_back_mv_table, s->b_code, MB_TYPE_BIDIR);
+ }
}
if (s->fixed_qscale)
s->frame_qscale = ff_rate_estimate_qscale(s);
if(s->adaptive_quant){
+#ifdef CONFIG_RISKY
switch(s->codec_id){
case CODEC_ID_MPEG4:
ff_clean_mpeg4_qscales(s);
ff_clean_h263_qscales(s);
break;
}
+#endif
s->qscale= s->current_picture.qscale_table[0];
}else
/* for mjpeg, we do include qscale in the matrix */
s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0];
for(i=1;i<64;i++){
- int j= s->idct_permutation[i];
+ int j= s->dsp.idct_permutation[i];
s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3);
}
case FMT_MJPEG:
mjpeg_picture_header(s);
break;
+#ifdef CONFIG_RISKY
case FMT_H263:
if (s->codec_id == CODEC_ID_WMV2)
ff_wmv2_encode_picture_header(s, picture_number);
else
h263_encode_picture_header(s, picture_number);
break;
+#endif
case FMT_MPEG1:
mpeg1_encode_picture_header(s, picture_number);
break;
s->mb_incr = 1;
s->last_mv[0][0][0] = 0;
s->last_mv[0][0][1] = 0;
+ s->last_mv[1][0][0] = 0;
+ s->last_mv[1][0][1] = 0;
+
+ s->last_mv_dir = 0;
+#ifdef CONFIG_RISKY
if (s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P)
s->gob_index = ff_h263_get_gob_height(s);
if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame)
ff_mpeg4_init_partitions(s);
+#endif
s->resync_mb_x=0;
s->resync_mb_y=0;
s->block_index[5]++;
/* write gob / video packet header */
+#ifdef CONFIG_RISKY
if(s->rtp_mode){
int current_packet_size, is_gob_start;
s->resync_mb_y=mb_y;
}
}
+#endif
if( (s->resync_mb_x == s->mb_x)
&& s->resync_mb_y+1 == s->mb_y){
s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
s->mb_intra= 0;
+#ifdef CONFIG_RISKY
ff_mpeg4_set_direct_mv(s, mx, my);
+#endif
encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_DIRECT, pb, pb2, tex_pb,
&dmin, &next_block, mx, my);
}
if(mb_type&MB_TYPE_INTRA){
- s->mv_dir = MV_DIR_FORWARD;
+ s->mv_dir = 0;
s->mv_type = MV_TYPE_16X16;
s->mb_intra= 1;
s->mv[0][0][0] = 0;
switch(mb_type){
case MB_TYPE_INTRA:
- s->mv_dir = MV_DIR_FORWARD;
+ s->mv_dir = 0;
s->mb_intra= 1;
motion_x= s->mv[0][0][0] = 0;
motion_y= s->mv[0][0][1] = 0;
s->mb_intra= 0;
motion_x=s->b_direct_mv_table[xy][0];
motion_y=s->b_direct_mv_table[xy][1];
+#ifdef CONFIG_RISKY
ff_mpeg4_set_direct_mv(s, motion_x, motion_y);
+#endif
break;
case MB_TYPE_BIDIR:
s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
motion_x=motion_y=0; //gcc warning fix
printf("illegal MB type\n");
}
+
encode_mb(s, motion_x, motion_y);
+
+ // RAL: Update last macrobloc type
+ s->last_mv_dir = s->mv_dir;
}
+
/* clean the MV table in IPS frames for direct mode in B frames */
if(s->mb_intra /* && I,P,S_TYPE */){
s->p_mv_table[xy][0]=0;
}
emms_c();
+#ifdef CONFIG_RISKY
if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame)
ff_mpeg4_merge_partitions(s);
if(s->codec_id==CODEC_ID_MPEG4)
ff_mpeg4_stuffing(&s->pb);
+#endif
//if (s->gob_number)
// fprintf(stderr,"\nNumber of GOB: %d", s->gob_number);
DCTELEM *block, int n,
int qscale, int *overflow){
const int *qmat;
- const UINT8 *scantable= s->intra_scantable.scantable;
+ const uint8_t *scantable= s->intra_scantable.scantable;
int max=0;
unsigned int threshold1, threshold2;
int bias=0;
int score_limit=0;
int left_limit= 0;
- s->fdct (block);
+ s->dsp.fdct (block);
qmul= qscale*16;
qadd= ((qscale-1)|1)*8;
unquant_coeff= level*qmul - qadd;
}
}else{ //MPEG1
- j= s->idct_permutation[ scantable[i + start_i] ]; //FIXME optimize
+ j= s->dsp.idct_permutation[ scantable[i + start_i] ]; //FIXME optimize
if(s->mb_intra){
if (level < 0) {
unquant_coeff = (int)((-level) * qscale * s->intra_matrix[j]) >> 3;
i= last_i;
assert(last_level);
//FIXME use permutated scantable
- block[ s->idct_permutation[ scantable[last_non_zero] ] ]= last_level;
+ block[ s->dsp.idct_permutation[ scantable[last_non_zero] ] ]= last_level;
i -= last_run + 1;
for(;i>0 ; i -= run_tab[i] + 1){
- const int j= s->idct_permutation[ scantable[i - 1 + start_i] ];
+ const int j= s->dsp.idct_permutation[ scantable[i - 1 + start_i] ];
block[j]= level_tab[i];
assert(block[j]);
{
int i, j, level, last_non_zero, q;
const int *qmat;
- const UINT8 *scantable= s->intra_scantable.scantable;
+ const uint8_t *scantable= s->intra_scantable.scantable;
int bias;
int max=0;
unsigned int threshold1, threshold2;
- s->fdct (block);
+ s->dsp.fdct (block);
if (s->mb_intra) {
if (!s->h263_aic) {
*overflow= s->max_qcoeff < max; //overflow might have happend
/* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
- if (s->idct_permutation_type != FF_NO_IDCT_PERM)
- ff_block_permute(block, s->idct_permutation, scantable, last_non_zero);
+ if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM)
+ ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero);
return last_non_zero;
}
+#endif //CONFIG_ENCODERS
+
static void dct_unquantize_mpeg1_c(MpegEncContext *s,
DCTELEM *block, int n, int qscale)
{
int i, level, nCoeffs;
- const UINT16 *quant_matrix;
+ const uint16_t *quant_matrix;
nCoeffs= s->block_last_index[n];
DCTELEM *block, int n, int qscale)
{
int i, level, nCoeffs;
- const UINT16 *quant_matrix;
+ const uint16_t *quant_matrix;
if(s->alternate_scan) nCoeffs= 63;
else nCoeffs= s->block_last_index[n];
nCoeffs= 63; //does not allways use zigzag table
} else {
i = 0;
- nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
+ nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
}
for(;i<=nCoeffs;i++) {
}
}
+
char ff_get_pict_type_char(int pict_type){
switch(pict_type){
case I_TYPE: return 'I';
}
}
+extern const AVOption common_options[2];
+static const AVOption mpeg4_options[] =
+{
+ AVOPTION_CODEC_INT("bitrate", "desired video bitrate", bit_rate, 4, 240000000, 800000),
+ AVOPTION_CODEC_FLAG("vhq", "very high quality", flags, CODEC_FLAG_HQ, 0),
+ AVOPTION_CODEC_INT("ratetol", "number of bits the bitstream is allowed to diverge from the reference"
+ "the reference can be CBR (for CBR pass1) or VBR (for pass2)",
+ bit_rate_tolerance, 4, 240000000, 8000),
+ AVOPTION_CODEC_INT("qmin", "minimum quantizer", qmin, 1, 31, 2),
+ AVOPTION_CODEC_INT("qmax", "maximum quantizer", qmax, 1, 31, 31),
+ AVOPTION_CODEC_STRING("rc_eq", "rate control equation",
+ rc_eq, "tex^qComp,option1,options2", 0),
+ AVOPTION_CODEC_INT("rc_minrate", "rate control minimum bitrate",
+ rc_min_rate, 4, 24000000, 0),
+ AVOPTION_CODEC_INT("rc_maxrate", "rate control maximum bitrate",
+ rc_max_rate, 4, 24000000, 0),
+ AVOPTION_CODEC_FLAG("psnr", "calculate PSNR of compressed frames",
+ flags, CODEC_FLAG_PSNR, 0),
+ AVOPTION_CODEC_RCOVERRIDE("rc_override", "ratecontrol override (=startframe,endframe,qscale,quality_factor)",
+ rc_override),
+ AVOPTION_SUB(common_options),
+ AVOPTION_END()
+};
+
+#ifdef CONFIG_ENCODERS
+
AVCodec mpeg1video_encoder = {
"mpeg1video",
CODEC_TYPE_VIDEO,
MPV_encode_end,
};
+#ifdef CONFIG_RISKY
+
AVCodec h263_encoder = {
"h263",
CODEC_TYPE_VIDEO,
MPV_encode_end,
};
-AVCodec mjpeg_encoder = {
- "mjpeg",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MJPEG,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
-};
-
AVCodec mpeg4_encoder = {
"mpeg4",
CODEC_TYPE_VIDEO,
MPV_encode_init,
MPV_encode_picture,
MPV_encode_end,
+ .options = mpeg4_options,
};
AVCodec msmpeg4v1_encoder = {
MPV_encode_end,
};
+#endif
+
+AVCodec mjpeg_encoder = {
+ "mjpeg",
+ CODEC_TYPE_VIDEO,
+ CODEC_ID_MJPEG,
+ sizeof(MpegEncContext),
+ MPV_encode_init,
+ MPV_encode_picture,
+ MPV_encode_end,
+};
+
+#endif //CONFIG_ENCODERS
+