CHECKED_ALLOCZ(pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2) //the +2 is for the slice end check
CHECKED_ALLOCZ(pic->qscale_table , mb_array_size * sizeof(uint8_t))
- CHECKED_ALLOCZ(pic->mb_type_base , big_mb_num * sizeof(uint32_t))
- pic->mb_type= pic->mb_type_base + s->mb_stride+1;
+ CHECKED_ALLOCZ(pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t))
+ pic->mb_type= pic->mb_type_base + 2*s->mb_stride+1;
if(s->out_format == FMT_H264){
for(i=0; i<2; i++){
CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t))
s->context_initialized = 1;
s->thread_context[0]= s;
- /* h264 does thread context setup itself, but it needs context[0]
- * to be fully initialized for the error resilience code */
- threads = s->codec_id == CODEC_ID_H264 ? 1 : s->avctx->thread_count;
+ threads = s->avctx->thread_count;
for(i=1; i<threads; i++){
s->thread_context[i]= av_malloc(sizeof(MpegEncContext));
}
}
- assert(0);
+ av_log(s->avctx, AV_LOG_FATAL, "Internal error, picture buffer overflow\n");
+ /* We could return -1, but the codec would crash trying to draw into a
+ * non-existing frame anyway. This is safer than waiting for a random crash.
+ * Also the return of this is never useful, an encoder must only allocate
+ * as much as allowed in the specification. This has no relationship to how
+ * much libavcodec could allocate (and MAX_PICTURE_COUNT is always large
+ * enough for such valid streams).
+ * Plus, a decoder has to check stream validity and remove frames if too
+ * many reference frames are around. Waiting for "OOM" is not correct at
+ * all. Similarly, missing reference frames have to be replaced by
+ * interpolated/MC frames, anything else is a bug in the codec ...
+ */
+ abort();
return -1;
}
assert(s->pict_type == I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0]));
- if(s->picture_structure!=PICT_FRAME){
+ if(s->picture_structure!=PICT_FRAME && s->out_format != FMT_H264){
int i;
for(i=0; i<4; i++){
if(s->picture_structure == PICT_BOTTOM_FIELD){