pic->hwaccel_picture_private = pic->hwaccel_priv_buf->data;
}
}
+ if (!h->avctx->hwaccel && CONFIG_GRAY && h->flags & CODEC_FLAG_GRAY && pic->f.data[2]) {
+ int h_chroma_shift, v_chroma_shift;
+ av_pix_fmt_get_chroma_sub_sample(pic->f.format,
+ &h_chroma_shift, &v_chroma_shift);
+
+ for(i=0; i<FF_CEIL_RSHIFT(h->avctx->height, v_chroma_shift); i++) {
+ memset(pic->f.data[1] + pic->f.linesize[1]*i,
+ 0x80, FF_CEIL_RSHIFT(h->avctx->width, h_chroma_shift));
+ memset(pic->f.data[2] + pic->f.linesize[2]*i,
+ 0x80, FF_CEIL_RSHIFT(h->avctx->width, h_chroma_shift));
+ }
+ }
if (!h->qscale_table_pool) {
ret = init_table_pools(h);
h->is_avc = 1;
if (size < 7) {
- av_log(avctx, AV_LOG_ERROR, "avcC too short\n");
+ av_log(avctx, AV_LOG_ERROR,
+ "avcC %d too short\n", size);
return AVERROR_INVALIDDATA;
}
/* sps and pps in the avcC always have length coded with 2 bytes,
ret = ff_h264_alloc_tables(h);
if (ret < 0) {
- av_log(dst, AV_LOG_ERROR, "Could not allocate memory for h264\n");
+ av_log(dst, AV_LOG_ERROR, "Could not allocate memory\n");
return ret;
}
ret = context_init(h);
ff_dsputil_init(&h->dsp, h->avctx);
ff_videodsp_init(&h->vdsp, h->sps.bit_depth_luma);
} else {
- av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n",
+ av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth %d\n",
h->sps.bit_depth_luma);
return AVERROR_INVALIDDATA;
}
break;
default:
av_log(h->avctx, AV_LOG_ERROR,
- "Unsupported bit depth: %d\n", h->sps.bit_depth_luma);
+ "Unsupported bit depth %d\n", h->sps.bit_depth_luma);
return AVERROR_INVALIDDATA;
}
}
init_scan_tables(h);
ret = ff_h264_alloc_tables(h);
if (ret < 0) {
- av_log(h->avctx, AV_LOG_ERROR,
- "Could not allocate memory for h264\n");
+ av_log(h->avctx, AV_LOG_ERROR, "Could not allocate memory\n");
return ret;
}
max_slices = FFMIN(MAX_THREADS, h->mb_height);
else
max_slices = MAX_THREADS;
- av_log(h->avctx, AV_LOG_WARNING, "too many threads/slices (%d),"
+ av_log(h->avctx, AV_LOG_WARNING, "too many threads/slices %d,"
" reducing to %d\n", nb_slices, max_slices);
nb_slices = max_slices;
}
/**
* Decode a slice header.
- * This will also call ff_MPV_common_init() and frame_start() as needed.
+ * This will (re)intialize the decoder and call h264_frame_start() as needed.
*
* @param h h264context
* @param h0 h264 master context (differs from 'h' when doing sliced based
slice_type = get_ue_golomb_31(&h->gb);
if (slice_type > 9) {
av_log(h->avctx, AV_LOG_ERROR,
- "slice type too large (%d) at %d %d\n",
+ "slice type %d too large at %d %d\n",
slice_type, h->mb_x, h->mb_y);
return AVERROR_INVALIDDATA;
}
pps_id = get_ue_golomb(&h->gb);
if (pps_id >= MAX_PPS_COUNT) {
- av_log(h->avctx, AV_LOG_ERROR, "pps_id %d out of range\n", pps_id);
+ av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", pps_id);
return AVERROR_INVALIDDATA;
}
if (!h0->pps_buffers[pps_id]) {
return AVERROR_INVALIDDATA;
}
- if (h->pps.sps_id != h->current_sps_id ||
+ if (h->pps.sps_id != h->sps.sps_id ||
+ h->pps.sps_id != h->current_sps_id ||
h0->sps_buffers[h->pps.sps_id]->new) {
- h->sps = *h0->sps_buffers[h->pps.sps_id];
+ h->sps = *h0->sps_buffers[h->pps.sps_id];
if (h->mb_width != h->sps.mb_width ||
h->mb_height != h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag) ||
must_reinit ||
needs_reinit)) {
if (h != h0) {
- av_log(h->avctx, AV_LOG_ERROR, "changing width/height on "
- "slice %d\n", h0->current_slice + 1);
+ av_log(h->avctx, AV_LOG_ERROR,
+ "changing width %d -> %d / height %d -> %d on "
+ "slice %d\n",
+ h->width, h->avctx->coded_width,
+ h->height, h->avctx->coded_height,
+ h0->current_slice + 1);
return AVERROR_INVALIDDATA;
}
return AVERROR_INVALIDDATA;
} else if (!h0->cur_pic_ptr) {
av_log(h->avctx, AV_LOG_ERROR,
- "unset cur_pic_ptr on %d. slice\n",
+ "unset cur_pic_ptr on slice %d\n",
h0->current_slice + 1);
return AVERROR_INVALIDDATA;
}
if (h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac) {
tmp = get_ue_golomb_31(&h->gb);
if (tmp > 2) {
- av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n");
+ av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp);
return AVERROR_INVALIDDATA;
}
h->cabac_init_idc = tmp;
get_se_golomb(&h->gb); /* slice_qs_delta */
h->deblocking_filter = 1;
- h->slice_alpha_c0_offset = 52;
- h->slice_beta_offset = 52;
+ h->slice_alpha_c0_offset = 0;
+ h->slice_beta_offset = 0;
if (h->pps.deblocking_filter_parameters_present) {
tmp = get_ue_golomb_31(&h->gb);
if (tmp > 2) {
h->deblocking_filter ^= 1; // 1<->0
if (h->deblocking_filter) {
- h->slice_alpha_c0_offset += get_se_golomb(&h->gb) << 1;
- h->slice_beta_offset += get_se_golomb(&h->gb) << 1;
- if (h->slice_alpha_c0_offset > 104U ||
- h->slice_beta_offset > 104U) {
+ h->slice_alpha_c0_offset = get_se_golomb(&h->gb) * 2;
+ h->slice_beta_offset = get_se_golomb(&h->gb) * 2;
+ if (h->slice_alpha_c0_offset > 12 ||
+ h->slice_alpha_c0_offset < -12 ||
+ h->slice_beta_offset > 12 ||
+ h->slice_beta_offset < -12) {
av_log(h->avctx, AV_LOG_ERROR,
"deblocking filter parameters %d %d out of range\n",
h->slice_alpha_c0_offset, h->slice_beta_offset);
}
}
}
- h->qp_thresh = 15 + 52 -
+ h->qp_thresh = 15 -
FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset) -
FFMAX3(0,
h->pps.chroma_qp_index_offset[0],
h->ref_count[0], h->ref_count[1],
h->qscale,
h->deblocking_filter,
- h->slice_alpha_c0_offset / 2 - 26, h->slice_beta_offset / 2 - 26,
+ h->slice_alpha_c0_offset, h->slice_beta_offset,
h->use_weight,
h->use_weight == 1 && h->use_weight_chroma ? "c" : "",
h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");
av_log(h->avctx, AV_LOG_DEBUG, "bytestream overread %td\n", h->cabac.bytestream_end - h->cabac.bytestream);
if (ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 4) {
av_log(h->avctx, AV_LOG_ERROR,
- "error while decoding MB %d %d, bytestream (%td)\n",
+ "error while decoding MB %d %d, bytestream %td\n",
h->mb_x, h->mb_y,
h->cabac.bytestream_end - h->cabac.bytestream);
er_add_slice(h, h->resync_mb_x, h->resync_mb_y, h->mb_x,
static int output_frame(H264Context *h, AVFrame *dst, Picture *srcp)
{
AVFrame *src = &srcp->f;
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src->format);
int i;
int ret = av_frame_ref(dst, src);
if (ret < 0)
if (!srcp->crop)
return 0;
- for (i = 0; i < 3; i++) {
- int hshift = (i > 0) ? h->chroma_x_shift : 0;
- int vshift = (i > 0) ? h->chroma_y_shift : 0;
+ for (i = 0; i < desc->nb_components; i++) {
+ int hshift = (i > 0) ? desc->log2_chroma_w : 0;
+ int vshift = (i > 0) ? desc->log2_chroma_h : 0;
int off = ((srcp->crop_left >> hshift) << h->pixel_shift) +
(srcp->crop_top >> vshift) * dst->linesize[i];
dst->data[i] += off;