Mercurial > libavcodec.hg
comparison mpeg12.c @ 647:22b22723805e libavcodec
support decoding of the last mpeg "packet" even if no startcode is immedeatly afterwards (fixes bugs with mpeg in avi)
new behavior is only activated if CODEC_FLAG_NOT_TRUNCATED is set
author | michaelni |
---|---|
date | Fri, 06 Sep 2002 22:30:16 +0000 |
parents | f449913e8419 |
children | 20810b0193ef |
comparison
equal
deleted
inserted
replaced
646:f87dc45d921d | 647:22b22723805e |
---|---|
582 static VLC mbincr_vlc; | 582 static VLC mbincr_vlc; |
583 static VLC mb_ptype_vlc; | 583 static VLC mb_ptype_vlc; |
584 static VLC mb_btype_vlc; | 584 static VLC mb_btype_vlc; |
585 static VLC mb_pat_vlc; | 585 static VLC mb_pat_vlc; |
586 | 586 |
587 void mpeg1_init_vlc(MpegEncContext *s) | 587 static void init_vlcs(MpegEncContext *s) |
588 { | 588 { |
589 static int done = 0; | 589 static int done = 0; |
590 | 590 |
591 if (!done) { | 591 if (!done) { |
592 done = 1; | 592 done = 1; |
1258 { | 1258 { |
1259 Mpeg1Context *s = avctx->priv_data; | 1259 Mpeg1Context *s = avctx->priv_data; |
1260 | 1260 |
1261 s->mpeg_enc_ctx.flags= avctx->flags; | 1261 s->mpeg_enc_ctx.flags= avctx->flags; |
1262 common_init(&s->mpeg_enc_ctx); | 1262 common_init(&s->mpeg_enc_ctx); |
1263 init_vlcs(&s->mpeg_enc_ctx); | |
1263 | 1264 |
1264 s->header_state = 0xff; | 1265 s->header_state = 0xff; |
1265 s->mpeg_enc_ctx_allocated = 0; | 1266 s->mpeg_enc_ctx_allocated = 0; |
1266 s->buffer_size = PICTURE_BUFFER_SIZE; | 1267 s->buffer_size = PICTURE_BUFFER_SIZE; |
1267 s->start_code = -1; | 1268 s->start_code = -1; |
1466 MpegEncContext *s = &s1->mpeg_enc_ctx; | 1467 MpegEncContext *s = &s1->mpeg_enc_ctx; |
1467 int ret; | 1468 int ret; |
1468 | 1469 |
1469 start_code = (start_code - 1) & 0xff; | 1470 start_code = (start_code - 1) & 0xff; |
1470 if (start_code >= s->mb_height){ | 1471 if (start_code >= s->mb_height){ |
1471 fprintf(stderr, "slice below image\n"); | 1472 fprintf(stderr, "slice below image (%d >= %d)\n", start_code, s->mb_height); |
1472 return -1; | 1473 return -1; |
1473 } | 1474 } |
1474 s->last_dc[0] = 1 << (7 + s->intra_dc_precision); | 1475 s->last_dc[0] = 1 << (7 + s->intra_dc_precision); |
1475 s->last_dc[1] = s->last_dc[0]; | 1476 s->last_dc[1] = s->last_dc[0]; |
1476 s->last_dc[2] = s->last_dc[0]; | 1477 s->last_dc[2] = s->last_dc[0]; |
1588 s->frame_rate = avctx->frame_rate; | 1589 s->frame_rate = avctx->frame_rate; |
1589 avctx->bit_rate = s->bit_rate; | 1590 avctx->bit_rate = s->bit_rate; |
1590 | 1591 |
1591 if (MPV_common_init(s) < 0) | 1592 if (MPV_common_init(s) < 0) |
1592 return -1; | 1593 return -1; |
1593 mpeg1_init_vlc(s); | |
1594 s1->mpeg_enc_ctx_allocated = 1; | 1594 s1->mpeg_enc_ctx_allocated = 1; |
1595 } | 1595 } |
1596 | 1596 |
1597 skip_bits(&s->gb, 10); /* vbv_buffer_size */ | 1597 skip_bits(&s->gb, 10); /* vbv_buffer_size */ |
1598 skip_bits(&s->gb, 1); | 1598 skip_bits(&s->gb, 1); |
1709 if (start_code_found) | 1709 if (start_code_found) |
1710 s->start_code = code; | 1710 s->start_code = code; |
1711 } else { | 1711 } else { |
1712 memcpy(s->buf_ptr, buf_start, len); | 1712 memcpy(s->buf_ptr, buf_start, len); |
1713 s->buf_ptr += len; | 1713 s->buf_ptr += len; |
1714 | 1714 if( (s2->flags&CODEC_FLAG_NOT_TRUNCATED) && (!start_code_found) |
1715 && s->buf_ptr+4<s->buffer+s->buffer_size){ | |
1716 start_code_found= 1; | |
1717 code= 0x1FF; | |
1718 s->header_state=0xFF; | |
1719 s->buf_ptr[0]=0; | |
1720 s->buf_ptr[1]=0; | |
1721 s->buf_ptr[2]=1; | |
1722 s->buf_ptr[3]=0xFF; | |
1723 s->buf_ptr+=4; | |
1724 } | |
1715 if (start_code_found) { | 1725 if (start_code_found) { |
1716 /* prepare data for next start code */ | 1726 /* prepare data for next start code */ |
1717 input_size = s->buf_ptr - s->buffer; | 1727 input_size = s->buf_ptr - s->buffer; |
1718 start_code = s->start_code; | 1728 start_code = s->start_code; |
1719 s->buf_ptr = s->buffer; | 1729 s->buf_ptr = s->buffer; |