static const enum PixelFormat hwaccel_pixfmt_list_h264_jpeg_420[] = {
PIX_FMT_DXVA2_VLD,
PIX_FMT_VAAPI_VLD,
+ PIX_FMT_VDA_VLD,
PIX_FMT_YUVJ420P,
PIX_FMT_NONE
};
/**
- * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
+ * Check if the top & left blocks are available if needed and
+ * change the dc mode so it only uses the available blocks.
*/
int ff_h264_check_intra4x4_pred_mode(H264Context *h){
MpegEncContext * const s = &h->s;
} //FIXME cleanup like ff_h264_check_intra_pred_mode
/**
- * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
+ * Check if the top & left blocks are available if needed and
+ * change the dc mode so it only uses the available blocks.
*/
int ff_h264_check_intra_pred_mode(H264Context *h, int mode){
MpegEncContext * const s = &h->s;
static int decode_init_thread_copy(AVCodecContext *avctx){
H264Context *h= avctx->priv_data;
- if (!avctx->is_copy) return 0;
+ if (!avctx->internal->is_copy)
+ return 0;
memset(h->sps_buffers, 0, sizeof(h->sps_buffers));
memset(h->pps_buffers, 0, sizeof(h->pps_buffers));
Picture *out = s->current_picture_ptr;
Picture *cur = s->current_picture_ptr;
int i, pics, out_of_order, out_idx;
+ int invalid = 0, cnt = 0;
s->current_picture_ptr->f.qscale_type = FF_QSCALE_TYPE_H264;
s->current_picture_ptr->f.pict_type = s->pict_type;
if( s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT
&& !h->sps.bitstream_restriction_flag){
- s->avctx->has_b_frames= MAX_DELAYED_PIC_COUNT;
+ s->avctx->has_b_frames = MAX_DELAYED_PIC_COUNT - 1;
s->low_delay= 0;
}
if (cur->f.reference == 0)
cur->f.reference = DELAYED_PIC_REF;
+ /* Frame reordering. This code takes pictures from coding order and sorts
+ * them by their incremental POC value into display order. It supports POC
+ * gaps, MMCO reset codes and random resets.
+ * A "display group" can start either with a IDR frame (f.key_frame = 1),
+ * and/or can be closed down with a MMCO reset code. In sequences where
+ * there is no delay, we can't detect that (since the frame was already
+ * output to the user), so we also set h->mmco_reset to detect the MMCO
+ * reset code.
+ * FIXME: if we detect insufficient delays (as per s->avctx->has_b_frames),
+ * we increase the delay between input and output. All frames affected by
+ * the lag (e.g. those that should have been output before another frame
+ * that we already returned to the user) will be dropped. This is a bug
+ * that we will fix later. */
+ for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++) {
+ cnt += out->poc < h->last_pocs[i];
+ invalid += out->poc == INT_MIN;
+ }
+ if (!h->mmco_reset && !cur->f.key_frame && cnt + invalid == MAX_DELAYED_PIC_COUNT && cnt > 0) {
+ h->mmco_reset = 2;
+ if (pics > 1)
+ h->delayed_pic[pics - 2]->mmco_reset = 2;
+ }
+ if (h->mmco_reset || cur->f.key_frame) {
+ for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
+ h->last_pocs[i] = INT_MIN;
+ cnt = 0;
+ invalid = MAX_DELAYED_PIC_COUNT;
+ }
out = h->delayed_pic[0];
out_idx = 0;
- for (i = 1; h->delayed_pic[i] && !h->delayed_pic[i]->f.key_frame && !h->delayed_pic[i]->mmco_reset; i++)
+ for (i = 1; i < MAX_DELAYED_PIC_COUNT && h->delayed_pic[i] &&
+ !h->delayed_pic[i-1]->mmco_reset && !h->delayed_pic[i]->f.key_frame; i++)
+ {
if(h->delayed_pic[i]->poc < out->poc){
out = h->delayed_pic[i];
out_idx = i;
}
- if (s->avctx->has_b_frames == 0 && (h->delayed_pic[0]->f.key_frame || h->delayed_pic[0]->mmco_reset))
- h->next_outputed_poc= INT_MIN;
- out_of_order = out->poc < h->next_outputed_poc;
+ }
+ if (s->avctx->has_b_frames == 0 && (h->delayed_pic[0]->f.key_frame || h->mmco_reset))
+ h->next_outputed_poc = INT_MIN;
+ out_of_order = !out->f.key_frame && !h->mmco_reset && (out->poc < h->next_outputed_poc);
if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames)
{ }
else if (out_of_order && pics-1 == s->avctx->has_b_frames &&
s->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT) {
- int cnt = 0, invalid = 0;
- for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++) {
- cnt += out->poc < h->last_pocs[i];
- invalid += h->last_pocs[i] == INT_MIN;
- }
if (invalid + cnt < MAX_DELAYED_PIC_COUNT) {
s->avctx->has_b_frames = FFMAX(s->avctx->has_b_frames, cnt);
- } else if (cnt) {
- for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
- h->last_pocs[i] = INT_MIN;
}
s->low_delay = 0;
} else if (s->low_delay &&
s->avctx->has_b_frames++;
}
- if(out_of_order || pics > s->avctx->has_b_frames){
+ if(pics > s->avctx->has_b_frames){
out->f.reference &= ~DELAYED_PIC_REF;
out->owner2 = s; // for frame threading, the owner must be the second field's thread
// or else the first thread can release the picture and reuse it unsafely
h->delayed_pic[i] = h->delayed_pic[i+1];
}
memmove(h->last_pocs, &h->last_pocs[1], sizeof(*h->last_pocs) * (MAX_DELAYED_PIC_COUNT - 1));
- h->last_pocs[MAX_DELAYED_PIC_COUNT - 1] = out->poc;
+ h->last_pocs[MAX_DELAYED_PIC_COUNT - 1] = cur->poc;
if(!out_of_order && pics > s->avctx->has_b_frames){
h->next_output_pic = out;
- if (out_idx == 0 && h->delayed_pic[0] && (h->delayed_pic[0]->f.key_frame || h->delayed_pic[0]->mmco_reset)) {
- h->next_outputed_poc = INT_MIN;
- } else
- h->next_outputed_poc = out->poc;
+ if (out->mmco_reset) {
+ if (out_idx > 0) {
+ h->next_outputed_poc = out->poc;
+ h->delayed_pic[out_idx - 1]->mmco_reset = out->mmco_reset;
+ } else {
+ h->next_outputed_poc = INT_MIN;
+ }
+ } else {
+ if (out_idx == 0 && pics > 1 && h->delayed_pic[0]->f.key_frame) {
+ h->next_outputed_poc = INT_MIN;
+ } else {
+ h->next_outputed_poc = out->poc;
+ }
+ }
+ h->mmco_reset = 0;
}else{
av_log(s->avctx, AV_LOG_DEBUG, "no picture\n");
}
static void hl_decode_mb_simple_ ## bits(H264Context *h){ \
hl_decode_mb_internal(h, 1, sh); \
}
-hl_decode_mb_simple(0, 8);
-hl_decode_mb_simple(1, 16);
+hl_decode_mb_simple(0, 8)
+hl_decode_mb_simple(1, 16)
/**
* Process a macroblock; this handles edge cases, such as interlacing.
h->delayed_pic[i]->f.reference = 0;
h->delayed_pic[i]= NULL;
}
+ for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++)
+ h->last_pocs[i] = INT_MIN;
h->outputed_poc=h->next_outputed_poc= INT_MIN;
h->prev_interlaced_frame = 1;
idr(h);
}
/**
- * computes profile from profile_idc and constraint_set?_flags
+ * Compute profile from profile_idc and constraint_set?_flags.
*
* @param sps SPS
*
}
/**
- * decodes a slice header.
+ * Decode a slice header.
* This will also call MPV_common_init() and frame_start() as needed.
*
* @param h h264context
switch (h->sps.bit_depth_luma) {
case 9 :
- if (CHROMA444)
- s->avctx->pix_fmt = PIX_FMT_YUV444P9;
- else if (CHROMA422)
+ if (CHROMA444) {
+ if (s->avctx->colorspace == AVCOL_SPC_RGB) {
+ s->avctx->pix_fmt = PIX_FMT_GBRP9;
+ } else
+ s->avctx->pix_fmt = PIX_FMT_YUV444P9;
+ } else if (CHROMA422)
s->avctx->pix_fmt = PIX_FMT_YUV422P9;
else
s->avctx->pix_fmt = PIX_FMT_YUV420P9;
break;
case 10 :
- if (CHROMA444)
- s->avctx->pix_fmt = PIX_FMT_YUV444P10;
- else if (CHROMA422)
+ if (CHROMA444) {
+ if (s->avctx->colorspace == AVCOL_SPC_RGB) {
+ s->avctx->pix_fmt = PIX_FMT_GBRP10;
+ } else
+ s->avctx->pix_fmt = PIX_FMT_YUV444P10;
+ } else if (CHROMA422)
s->avctx->pix_fmt = PIX_FMT_YUV422P10;
else
s->avctx->pix_fmt = PIX_FMT_YUV420P10;
break;
default:
if (CHROMA444){
- s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P;
+ if (s->avctx->colorspace == AVCOL_SPC_RGB) {
+ s->avctx->pix_fmt = PIX_FMT_GBRP;
+ } else
+ s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P;
} else if (CHROMA422) {
s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ422P : PIX_FMT_YUV422P;
}else{
* FIXME: avoiding a memcpy would be nice, but ref handling makes many assumptions
* about there being no actual duplicates.
* FIXME: this doesn't copy padding for out-of-frame motion vectors. Given we're
- * concealing a lost frame, this probably isn't noticable by comparison, but it should
+ * concealing a lost frame, this probably isn't noticeable by comparison, but it should
* be fixed. */
if (h->short_ref_count) {
if (prev) {
/**
*
- * @return non zero if the loop filter can be skiped
+ * @return non zero if the loop filter can be skipped
*/
static int fill_filter_caches(H264Context *h, int mb_type){
MpegEncContext * const s = &h->s;
static int decode_slice(struct AVCodecContext *avctx, void *arg){
H264Context *h = *(void**)arg;
MpegEncContext * const s = &h->s;
- const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
+ const int part_mask= s->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F;
int lf_x_start = s->mb_x;
s->mb_skip_run= -1;
eos = get_cabac_terminate( &h->cabac );
if((s->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask);
if (s->mb_x >= lf_x_start) loop_filter(h, lf_x_start, s->mb_x + 1);
return 0;
}
if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) {
av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask);
return -1;
}
if( eos || s->mb_y >= s->mb_height ) {
tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask);
if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x);
return 0;
}
if(ret<0){
av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask);
return -1;
}
tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask);
return 0;
}else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask);
return -1;
}
if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){
tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
if(get_bits_count(&s->gb) == s->gb.size_in_bits ){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask);
if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x);
return 0;
}else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask);
return -1;
}
} else {
for(i = 1; i < context_count; i++) {
hx = h->thread_context[i];
- hx->s.error_recognition = avctx->error_recognition;
+ hx->s.err_recognition = avctx->err_recognition;
hx->s.error_count = 0;
}
- avctx->execute(avctx, (void *)decode_slice,
+ avctx->execute(avctx, decode_slice,
h->thread_context, NULL, context_count, sizeof(void*));
/* pull back stuff from slices to master context */
int consumed;
int dst_length;
int bit_length;
- const uint8_t *ptr;
+ uint8_t *ptr;
int i, nalsize = 0;
int err;
}
if (h->is_avc && (nalsize != consumed) && nalsize){
+ // set trailing bits in the last partial byte to zero
+ if (bit_length & 7)
+ ptr[bit_length >> 3] = ptr[bit_length >> 3] & (0xff << 8 - (bit_length & 7));
av_log(h->s.avctx, AV_LOG_DEBUG, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize);
}
av_log(h->s.avctx, AV_LOG_ERROR, "Invalid mix of idr and non-idr slices");
return -1;
}
- idr(h); //FIXME ensure we don't loose some frames if there is reordering
+ idr(h); // FIXME ensure we don't lose some frames if there is reordering
case NAL_SLICE:
init_get_bits(&hx->s.gb, ptr, bit_length);
hx->intra_gb_ptr=
}
/**
- * returns the number of bytes consumed for building the current frame
+ * Return the number of bytes consumed for building the current frame.
*/
static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){
if(pos==0) pos=1; //avoid infinite loops (i doubt that is needed but ...)