* Copyright (c) 2001 Juan J. Sierralta P
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav 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.1 of the License, or (at your option) any later version.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav 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 FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * @file libavcodec/ituh263enc.c
- * h263 encoder.
+ * @file
+ * h263 bitstream encoder.
*/
//#define DEBUG
#include "unary.h"
#include "flv.h"
#include "mpeg4video.h"
+#include "internal.h"
//#undef NDEBUG
//#include <assert.h>
19, 2, 1, 34, 35, 36
};
-int h263_get_picture_format(int width, int height)
-{
- if (width == 128 && height == 96)
- return 1;
- else if (width == 176 && height == 144)
- return 2;
- else if (width == 352 && height == 288)
- return 3;
- else if (width == 704 && height == 576)
- return 4;
- else if (width == 1408 && height == 1152)
- return 5;
- else
- return 7;
-}
-
/**
- * Returns the 4 bit value that specifies the given aspect ratio.
+ * Return the 4 bit value that specifies the given aspect ratio.
* This may be one of the standard aspect ratios or it specifies
* that the aspect will be stored explicitly later.
*/
coded_frame_rate= 1800000;
coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
- align_put_bits(&s->pb);
+ avpriv_align_put_bits(&s->pb);
/* Update the pointer to last GOB */
s->ptr_lastgob = put_bits_ptr(&s->pb);
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);
+ format = ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), s->width, s->height);
if (!s->h263_plus) {
/* H.263v1 */
put_bits(&s->pb, 3, format);
- put_bits(&s->pb, 1, (s->pict_type == FF_P_TYPE));
+ put_bits(&s->pb, 1, (s->pict_type == AV_PICTURE_TYPE_P));
/* 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, 3, 7);
put_bits(&s->pb,3,ufep); /* Update Full Extended PTYPE */
- if (format == 7)
+ if (format == 8)
put_bits(&s->pb,3,6); /* Custom Source Format */
else
put_bits(&s->pb, 3, format);
put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
put_bits(&s->pb,3,0); /* Reserved */
- put_bits(&s->pb, 3, s->pict_type == FF_P_TYPE);
+ put_bits(&s->pb, 3, s->pict_type == AV_PICTURE_TYPE_P);
put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */
put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */
/* This should be here if PLUSPTYPE */
put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
- if (format == 7) {
+ if (format == 8) {
/* Custom Picture Format (CPFMT) */
s->aspect_ratio_info= ff_h263_aspect_to_info(s->avctx->sample_aspect_ratio);
}
/**
- * Encodes a group of blocks header.
+ * Encode a group of blocks header.
*/
void h263_encode_gob_header(MpegEncContext * s, int mb_line)
{
put_bits(&s->pb, 1, 1);
put_bits(&s->pb, 5, s->qscale); /* GQUANT */
put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */
+ put_bits(&s->pb, 2, s->pict_type == AV_PICTURE_TYPE_I); /* GFID */
}else{
int gob_number= mb_line / s->gob_index;
put_bits(&s->pb, 5, gob_number); /* GN */
- put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */
+ put_bits(&s->pb, 2, s->pict_type == AV_PICTURE_TYPE_I); /* GFID */
put_bits(&s->pb, 5, s->qscale); /* GQUANT */
}
}
*/
void ff_clean_h263_qscales(MpegEncContext *s){
int i;
- int8_t * const qscale_table= s->current_picture.qscale_table;
+ int8_t * const qscale_table = s->current_picture.f.qscale_table;
ff_init_qscale_tab(s);
/* motion vectors: 8x8 mode*/
h263_pred_motion(s, i, 0, &pred_x, &pred_y);
- motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0];
- motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1];
+ motion_x = s->current_picture.f.motion_val[0][s->block_index[i]][0];
+ motion_y = s->current_picture.f.motion_val[0][s->block_index[i]][1];
if (!s->umvplus) {
ff_h263_encode_motion_vector(s, motion_x - pred_x,
motion_y - pred_y, 1);
}
cbpc = cbp & 3;
- if (s->pict_type == FF_I_TYPE) {
+ if (s->pict_type == AV_PICTURE_TYPE_I) {
if(s->dquant) cbpc+=4;
put_bits(&s->pb,
ff_h263_intra_MCBPC_bits[cbpc],
void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code)
{
- int range, l, bit_size, sign, code, bits;
+ int range, bit_size, sign, code, bits;
if (val == 0) {
/* zero vector */
bit_size = f_code - 1;
range = 1 << bit_size;
/* modulo encoding */
- l= INT_BIT - 6 - bit_size;
- val = (val<<l)>>l;
+ val = sign_extend(val, 6 + bit_size);
sign = val>>31;
val= (val^sign)-sign;
sign&=1;