}
/* init common dct for both encoder and decoder */
-static int DCT_common_init(MpegEncContext *s)
+int ff_dct_common_init(MpegEncContext *s)
{
s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;
MPV_common_init_mmi(s);
#elif defined(ARCH_ARMV4L)
MPV_common_init_armv4l(s);
-#elif defined(ARCH_POWERPC)
- MPV_common_init_ppc(s);
+#elif defined(HAVE_ALTIVEC)
+ MPV_common_init_altivec(s);
#elif defined(ARCH_BFIN)
MPV_common_init_bfin(s);
#endif
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))
*/
int MPV_common_init(MpegEncContext *s)
{
- int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
+ int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y, threads;
s->mb_height = (s->height + 15) / 16;
return -1;
dsputil_init(&s->dsp, s->avctx);
- DCT_common_init(s);
+ ff_dct_common_init(s);
s->flags= s->avctx->flags;
s->flags2= s->avctx->flags2;
s->context_initialized = 1;
s->thread_context[0]= s;
- for(i=1; i<s->avctx->thread_count; i++){
+ threads = s->avctx->thread_count;
+
+ for(i=1; i<threads; i++){
s->thread_context[i]= av_malloc(sizeof(MpegEncContext));
memcpy(s->thread_context[i], s, sizeof(MpegEncContext));
}
- for(i=0; i<s->avctx->thread_count; i++){
+ for(i=0; i<threads; i++){
if(init_duplicate_context(s->thread_context[i], s) < 0)
goto fail;
s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count;
}
}
- 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;
}
pic= (AVFrame*)&s->picture[i];
}
- pic->reference= (s->pict_type != B_TYPE || s->codec_id == CODEC_ID_H264)
- && !s->dropable ? 3 : 0;
+ pic->reference= 0;
+ if (!s->dropable){
+ if (s->codec_id == CODEC_ID_H264)
+ pic->reference = s->picture_structure;
+ else if (s->pict_type != B_TYPE)
+ pic->reference = 3;
+ }
pic->coded_picture_number= s->coded_picture_number++;
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){
ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
src_x, src_y<<field_based, h_edge_pos, v_edge_pos);
ptr_y = s->edge_emu_buffer;
- if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based,
uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1);
sy <<= 2 - lowres;
pix_op[lowres-1](dest_y, ptr_y, linesize, h, sx, sy);
- if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
uvsx <<= 2 - lowres;
uvsy <<= 2 - lowres;
pix_op[lowres](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy);
my += s->mv[dir][i][1];
}
- if(!(s->flags&CODEC_FLAG_GRAY))
+ if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my);
break;
case MV_TYPE_FIELD:
add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
- if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
if (s->chroma_y_shift){
add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);
add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize);
- if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
if(s->chroma_y_shift){//Chroma420
add_dct(s, block[4], 4, dest_cb, uvlinesize);
add_dct(s, block[5], 5, dest_cr, uvlinesize);
put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
- if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
if(s->chroma_y_shift){
put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]);
s->dsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]);
- if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
if(s->chroma_y_shift){
s->dsp.idct_put(dest_cb, uvlinesize, block[4]);
s->dsp.idct_put(dest_cr, uvlinesize, block[5]);