*/
/**
- * @file h264.c
+ * @file libavcodec/h264.c
* H.264 / AVC / MPEG4 part10 codec.
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#include "h264data.h"
#include "h264_parser.h"
#include "golomb.h"
+#include "mathops.h"
#include "rectangle.h"
#include "vdpau_internal.h"
#include "cabac.h"
-#ifdef ARCH_X86
+#if ARCH_X86
#include "x86/h264_i386.h"
#endif
printf("%2X ", src[i]);
#endif
-#ifdef HAVE_FAST_UNALIGNED
-# ifdef HAVE_FAST_64BIT
+#if HAVE_FAST_UNALIGNED
+# if HAVE_FAST_64BIT
# define RS 7
for(i=0; i+1<length; i+=9){
if(!((~*(uint64_t*)(src+i) & (*(uint64_t*)(src+i) - 0x0100010001000101ULL)) & 0x8000800080008080ULL))
qpix_op[luma_xy](dest_y + delta, src_y + delta, h->mb_linesize);
}
- if(ENABLE_GRAY && s->flags&CODEC_FLAG_GRAY) return;
+ if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return;
if(MB_FIELD){
// chroma offset when predicting from a field of opposite parity
if(avctx->codec_id == CODEC_ID_SVQ3)
avctx->pix_fmt= PIX_FMT_YUVJ420P;
- else if(avctx->codec_id == CODEC_ID_H264_VDPAU)
+ else if(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
avctx->pix_fmt= PIX_FMT_VDPAU_H264;
else
avctx->pix_fmt= PIX_FMT_YUV420P;
if(!MB_MBAFF){
*(uint64_t*)(h->top_borders[0][s->mb_x]+ 0)= *(uint64_t*)(src_y + 15*linesize);
*(uint64_t*)(h->top_borders[0][s->mb_x]+ 8)= *(uint64_t*)(src_y +8+15*linesize);
- if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+ if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
*(uint64_t*)(h->top_borders[0][s->mb_x]+16)= *(uint64_t*)(src_cb+7*uvlinesize);
*(uint64_t*)(h->top_borders[0][s->mb_x]+24)= *(uint64_t*)(src_cr+7*uvlinesize);
}
}else{
if(!MB_MBAFF){
h->left_border[0]= h->top_borders[0][s->mb_x][15];
- if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+ if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
h->left_border[34 ]= h->top_borders[0][s->mb_x][16+7 ];
h->left_border[34+18]= h->top_borders[0][s->mb_x][16+8+7];
}
*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+0)= *(uint64_t*)(src_y + 16*linesize);
*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+8)= *(uint64_t*)(src_y +8+16*linesize);
- if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+ if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
h->left_border[uvoffset+34 ]= h->top_borders[top_idx][s->mb_x][16+7];
h->left_border[uvoffset+34+18]= h->top_borders[top_idx][s->mb_x][24+7];
for(i=1; i<9 - skiplast; i++){
}
}
- if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+ if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
if(deblock_left){
for(i = !deblock_top; i<8; i++){
XCHG(h->left_border[uvoffset+34 +i*step], src_cb[i*uvlinesize], temp8, xchg);
int *block_offset = &h->block_offset[0];
const int transform_bypass = !simple && (s->qscale == 0 && h->sps.transform_bypass);
/* is_h264 should always be true if SVQ3 is disabled. */
- const int is_h264 = !ENABLE_SVQ3_DECODER || simple || s->codec_id == CODEC_ID_H264;
+ const int is_h264 = !CONFIG_SVQ3_DECODER || simple || s->codec_id == CODEC_ID_H264;
void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride);
void (*idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride);
if(h->deblocking_filter)
xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1, simple);
- if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+ if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize);
h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize);
}
}
}
- if((simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)) && (h->cbp&0x30)){
+ if((simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) && (h->cbp&0x30)){
uint8_t *dest[2] = {dest_cb, dest_cr};
if(transform_bypass){
if(IS_INTRA(mb_type) && h->sps.profile_idc==244 && (h->chroma_pred_mode==VERT_PRED8x8 || h->chroma_pred_mode==HOR_PRED8x8)){
MpegEncContext * const s = &h->s;
const int mb_xy= h->mb_xy;
const int mb_type= s->current_picture.mb_type[mb_xy];
- int is_complex = ENABLE_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;
-
- if(ENABLE_H264_ENCODER && !s->decode)
- return;
+ int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;
if (is_complex)
hl_decode_mb_complex(h);
chroma_def = 1<<h->chroma_log2_weight_denom;
for(list=0; list<2; list++){
+ h->luma_weight_flag[list] = 0;
+ h->chroma_weight_flag[list] = 0;
for(i=0; i<h->ref_count[list]; i++){
int luma_weight_flag, chroma_weight_flag;
h->luma_weight[list][i]= get_se_golomb(&s->gb);
h->luma_offset[list][i]= get_se_golomb(&s->gb);
if( h->luma_weight[list][i] != luma_def
- || h->luma_offset[list][i] != 0)
+ || h->luma_offset[list][i] != 0) {
h->use_weight= 1;
+ h->luma_weight_flag[list]= 1;
+ }
}else{
h->luma_weight[list][i]= luma_def;
h->luma_offset[list][i]= 0;
h->chroma_weight[list][i][j]= get_se_golomb(&s->gb);
h->chroma_offset[list][i][j]= get_se_golomb(&s->gb);
if( h->chroma_weight[list][i][j] != chroma_def
- || h->chroma_offset[list][i][j] != 0)
+ || h->chroma_offset[list][i][j] != 0) {
h->use_weight_chroma= 1;
+ h->chroma_weight_flag[list]= 1;
+ }
}
}else{
int j;
static void implicit_weight_table(H264Context *h){
MpegEncContext * const s = &h->s;
- int ref0, ref1;
+ int ref0, ref1, i;
int cur_poc = s->current_picture_ptr->poc;
if( h->ref_count[0] == 1 && h->ref_count[1] == 1
h->use_weight_chroma= 2;
h->luma_log2_weight_denom= 5;
h->chroma_log2_weight_denom= 5;
+ for (i = 0; i < 2; i++) {
+ h->luma_weight_flag[i] = 0;
+ h->chroma_weight_flag[i] = 0;
+ }
for(ref0=0; ref0 < h->ref_count[0]; ref0++){
int poc0 = h->ref_list[0][ref0].poc;
}
}
if(s->dsp.h264_idct8_add == ff_h264_idct8_add_c){
- memcpy(h->zigzag_scan8x8, zigzag_scan8x8, 64*sizeof(uint8_t));
+ memcpy(h->zigzag_scan8x8, ff_zigzag_direct, 64*sizeof(uint8_t));
memcpy(h->zigzag_scan8x8_cavlc, zigzag_scan8x8_cavlc, 64*sizeof(uint8_t));
memcpy(h->field_scan8x8, field_scan8x8, 64*sizeof(uint8_t));
memcpy(h->field_scan8x8_cavlc, field_scan8x8_cavlc, 64*sizeof(uint8_t));
}else{
for(i=0; i<64; i++){
#define T(x) (x>>3) | ((x&7)<<3)
- h->zigzag_scan8x8[i] = T(zigzag_scan8x8[i]);
+ h->zigzag_scan8x8[i] = T(ff_zigzag_direct[i]);
h->zigzag_scan8x8_cavlc[i] = T(zigzag_scan8x8_cavlc[i]);
h->field_scan8x8[i] = T(field_scan8x8[i]);
h->field_scan8x8_cavlc[i] = T(field_scan8x8_cavlc[i]);
}
if(h->sps.transform_bypass){ //FIXME same ugly
h->zigzag_scan_q0 = zigzag_scan;
- h->zigzag_scan8x8_q0 = zigzag_scan8x8;
+ h->zigzag_scan8x8_q0 = ff_zigzag_direct;
h->zigzag_scan8x8_cavlc_q0 = zigzag_scan8x8_cavlc;
h->field_scan_q0 = field_scan;
h->field_scan8x8_q0 = field_scan8x8;
pred_weight_table(h);
else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE)
implicit_weight_table(h);
- else
+ else {
h->use_weight = 0;
+ for (i = 0; i < 2; i++) {
+ h->luma_weight_flag[i] = 0;
+ h->chroma_weight_flag[i] = 0;
+ }
+ }
if(h->nal_ref_idc)
decode_ref_pic_marking(h0, &s->gb);
uint8_t *last_coeff_ctx_base;
uint8_t *abs_level_m1_ctx_base;
-#ifndef ARCH_X86
+#if !ARCH_X86
#define CABAC_ON_STACK
#endif
#ifdef CABAC_ON_STACK
index[coeff_count++] = last;\
}
const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD];
-#if defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS)
+#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index, sig_off);
} else {
coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index);
}
-#ifndef CONFIG_SMALL
+#if !CONFIG_SMALL
static void decode_cabac_residual_dc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) {
decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 1);
}
#endif
static void decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) {
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, cat == 0 || cat == 3);
#else
if( cat == 0 || cat == 3 ) decode_cabac_residual_dc(h, block, cat, n, scantable, qmul, max_coeff);
const int mb_type = s->current_picture.mb_type[mb_xy];
const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4;
int first_vertical_edge_done = 0;
- int dir;
+ av_unused int dir;
//for sufficiently low qp, filtering wouldn't do anything
//this is a conservative estimate: could also check beta_offset and more accurate chroma_qp
filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, rqp );
}
-#ifdef CONFIG_SMALL
+#if CONFIG_SMALL
for( dir = 0; dir < 2; dir++ )
filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, dir ? 0 : first_vertical_edge_done, dir);
#else
s->mb_skip_run= -1;
h->is_complex = FRAME_MBAFF || s->picture_structure != PICT_FRAME || s->codec_id != CODEC_ID_H264 ||
- (ENABLE_GRAY && (s->flags&CODEC_FLAG_GRAY)) || (ENABLE_H264_ENCODER && s->encoding);
+ (CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));
if( h->pps.cabac ) {
int i;
}while(get_bits(&s->gb, 8) == 255);
switch(type){
- case 1: // Picture timing SEI
+ case SEI_TYPE_PIC_TIMING: // Picture timing SEI
if(decode_picture_timing(h) < 0)
return -1;
break;
- case 5:
+ case SEI_TYPE_USER_DATA_UNREGISTERED:
if(decode_unregistered_user_data(h, size) < 0)
return -1;
break;
const uint8_t *jvt_list, const uint8_t *fallback_list){
MpegEncContext * const s = &h->s;
int i, last = 8, next = 8;
- const uint8_t *scan = size == 16 ? zigzag_scan : zigzag_scan8x8;
+ const uint8_t *scan = size == 16 ? zigzag_scan : ff_zigzag_direct;
if(!get_bits1(&s->gb)) /* matrix not written, we use the predicted one */
memcpy(factors, fallback_list, size*sizeof(uint8_t));
else
if(sps->profile_idc >= 100){ //high profile
sps->chroma_format_idc= get_ue_golomb_31(&s->gb);
if(sps->chroma_format_idc == 3)
- get_bits1(&s->gb); //residual_color_transform_flag
- get_ue_golomb(&s->gb); //bit_depth_luma_minus8
- get_ue_golomb(&s->gb); //bit_depth_chroma_minus8
+ sps->residual_color_transform_flag = get_bits1(&s->gb);
+ sps->bit_depth_luma = get_ue_golomb(&s->gb) + 8;
+ sps->bit_depth_chroma = get_ue_golomb(&s->gb) + 8;
sps->transform_bypass = get_bits1(&s->gb);
decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8);
}else{
((const char*[]){"Gray","420","422","444"})[sps->chroma_format_idc]
);
}
+
av_free(h->sps_buffers[sps_id]);
h->sps_buffers[sps_id]= sps;
return 0;
H264Context *hx;
int i;
- if(avctx->codec_id == CODEC_ID_H264_VDPAU)
+ if(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
return;
if(context_count == 1) {
decode_slice(avctx, &h);
&& (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=FF_B_TYPE)
&& (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==FF_I_TYPE)
&& avctx->skip_frame < AVDISCARD_ALL){
- if(ENABLE_H264_VDPAU_DECODER && avctx->codec_id == CODEC_ID_H264_VDPAU){
+ if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){
static const uint8_t start_code[] = {0x00, 0x00, 0x01};
- ff_vdpau_h264_add_data_chunk(h, start_code, sizeof(start_code));
- ff_vdpau_h264_add_data_chunk(h, &buf[buf_index - consumed], consumed );
+ ff_vdpau_add_data_chunk(s, start_code, sizeof(start_code));
+ ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed], consumed );
}else
context_count++;
}
s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264;
s->current_picture_ptr->pict_type= s->pict_type;
+ if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
+ ff_vdpau_h264_set_reference_frames(s);
+
if(!s->dropable) {
execute_ref_pic_marking(h, h->mmco, h->mmco_index);
h->prev_poc_msb= h->poc_msb;
h->prev_frame_num_offset= h->frame_num_offset;
h->prev_frame_num= h->frame_num;
- if (ENABLE_H264_VDPAU_DECODER && avctx->codec_id == CODEC_ID_H264_VDPAU)
- ff_vdpau_h264_picture_complete(h);
+ if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
+ ff_vdpau_h264_picture_complete(s);
/*
* FIXME: Error handling code does not seem to support interlaced
* past end by one (callers fault) and resync_mb_y != 0
* causes problems for the first MB line, too.
*/
- if (avctx->codec_id != CODEC_ID_H264_VDPAU && !FIELD_PICTURE)
+ if (!FIELD_PICTURE)
ff_er_frame_end(s);
MPV_frame_end(s);
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
};
-#ifdef CONFIG_H264_VDPAU_DECODER
+#if CONFIG_H264_VDPAU_DECODER
AVCodec h264_vdpau_decoder = {
"h264_vdpau",
CODEC_TYPE_VIDEO,
- CODEC_ID_H264_VDPAU,
+ CODEC_ID_H264,
sizeof(H264Context),
decode_init,
NULL,
};
#endif
-#ifdef CONFIG_SVQ3_DECODER
+#if CONFIG_SVQ3_DECODER
#include "svq3.c"
#endif