comparison mpeg12.c @ 826:ce240888252d libavcodec

cleanup
author michaelni
date Sat, 02 Nov 2002 08:55:46 +0000
parents 92c6d8b71e3b
children e460775adb38
comparison
equal deleted inserted replaced
825:92c6d8b71e3b 826:ce240888252d
1557 mpeg_decode_picture_coding_extension(s); 1557 mpeg_decode_picture_coding_extension(s);
1558 break; 1558 break;
1559 } 1559 }
1560 } 1560 }
1561 1561
1562 /* return 1 if end of frame */ 1562 #define DECODE_SLICE_FATAL_ERROR -2
1563 #define DECODE_SLICE_ERROR -1
1564 #define DECODE_SLICE_OK 0
1565 #define DECODE_SLICE_EOP 1
1566
1567 /**
1568 * decodes a slice.
1569 * @return DECODE_SLICE_FATAL_ERROR if a non recoverable error occured<br>
1570 * DECODE_SLICE_ERROR if the slice is damaged<br>
1571 * DECODE_SLICE_OK if this slice is ok<br>
1572 * DECODE_SLICE_EOP if the end of the picture is reached
1573 */
1563 static int mpeg_decode_slice(AVCodecContext *avctx, 1574 static int mpeg_decode_slice(AVCodecContext *avctx,
1564 AVPicture *pict, 1575 AVPicture *pict,
1565 int start_code, 1576 int start_code,
1566 UINT8 *buf, int buf_size) 1577 UINT8 *buf, int buf_size)
1567 { 1578 {
1570 int ret; 1581 int ret;
1571 1582
1572 start_code = (start_code - 1) & 0xff; 1583 start_code = (start_code - 1) & 0xff;
1573 if (start_code >= s->mb_height){ 1584 if (start_code >= s->mb_height){
1574 fprintf(stderr, "slice below image (%d >= %d)\n", start_code, s->mb_height); 1585 fprintf(stderr, "slice below image (%d >= %d)\n", start_code, s->mb_height);
1575 return -1; 1586 return DECODE_SLICE_ERROR;
1576 } 1587 }
1577 s->last_dc[0] = 1 << (7 + s->intra_dc_precision); 1588 s->last_dc[0] = 1 << (7 + s->intra_dc_precision);
1578 s->last_dc[1] = s->last_dc[0]; 1589 s->last_dc[1] = s->last_dc[0];
1579 s->last_dc[2] = s->last_dc[0]; 1590 s->last_dc[2] = s->last_dc[0];
1580 memset(s->last_mv, 0, sizeof(s->last_mv)); 1591 memset(s->last_mv, 0, sizeof(s->last_mv));
1581 /* start frame decoding */ 1592 /* start frame decoding */
1582 if (s->first_slice) { 1593 if (s->first_slice) {
1583 s->first_slice = 0; 1594 s->first_slice = 0;
1584 if(MPV_frame_start(s, avctx) < 0) 1595 if(MPV_frame_start(s, avctx) < 0)
1585 return -2; 1596 return DECODE_SLICE_FATAL_ERROR;
1586 } 1597 }
1587 1598
1588 init_get_bits(&s->gb, buf, buf_size); 1599 init_get_bits(&s->gb, buf, buf_size);
1589 1600
1590 s->qscale = get_qscale(s); 1601 s->qscale = get_qscale(s);
1649 } 1660 }
1650 } 1661 }
1651 } 1662 }
1652 if(s->mb_y >= s->mb_height){ 1663 if(s->mb_y >= s->mb_height){
1653 fprintf(stderr, "slice too long\n"); 1664 fprintf(stderr, "slice too long\n");
1654 return -1; 1665 return DECODE_SLICE_ERROR;
1655 } 1666 }
1656 } 1667 }
1657 eos: //end of slice 1668 eos: //end of slice
1658 1669
1659 emms_c(); 1670 emms_c();
1687 pict->data[1] = picture[1]; 1698 pict->data[1] = picture[1];
1688 pict->data[2] = picture[2]; 1699 pict->data[2] = picture[2];
1689 pict->linesize[0] = s->linesize; 1700 pict->linesize[0] = s->linesize;
1690 pict->linesize[1] = s->uvlinesize; 1701 pict->linesize[1] = s->uvlinesize;
1691 pict->linesize[2] = s->uvlinesize; 1702 pict->linesize[2] = s->uvlinesize;
1692 return 1; 1703 return DECODE_SLICE_EOP;
1693 } else { 1704 } else {
1694 return 0; 1705 return DECODE_SLICE_OK;
1695 } 1706 }
1696 } else { 1707 } else {
1697 return 0; 1708 return DECODE_SLICE_OK;
1698 } 1709 }
1699 } 1710 }
1700 1711
1701 static int mpeg1_decode_sequence(AVCodecContext *avctx, 1712 static int mpeg1_decode_sequence(AVCodecContext *avctx,
1702 UINT8 *buf, int buf_size) 1713 UINT8 *buf, int buf_size)
1900 default: 1911 default:
1901 if (start_code >= SLICE_MIN_START_CODE && 1912 if (start_code >= SLICE_MIN_START_CODE &&
1902 start_code <= SLICE_MAX_START_CODE) { 1913 start_code <= SLICE_MAX_START_CODE) {
1903 ret = mpeg_decode_slice(avctx, picture, 1914 ret = mpeg_decode_slice(avctx, picture,
1904 start_code, s->buffer, input_size); 1915 start_code, s->buffer, input_size);
1905 if (ret == 1) { 1916 if (ret == DECODE_SLICE_EOP) {
1906 /* got a picture: exit */ 1917 /* got a picture: exit */
1907 /* first check if we must repeat the frame */ 1918 /* first check if we must repeat the frame */
1908 avctx->repeat_pict = 0; 1919 avctx->repeat_pict = 0;
1909 #if 0 1920 #if 0
1910 if (s2->progressive_frame && s2->repeat_first_field) { 1921 if (s2->progressive_frame && s2->repeat_first_field) {
1928 } 1939 }
1929 *data_size = sizeof(AVPicture); 1940 *data_size = sizeof(AVPicture);
1930 goto the_end; 1941 goto the_end;
1931 }else if(ret<0){ 1942 }else if(ret<0){
1932 printf("Error while decoding slice\n"); 1943 printf("Error while decoding slice\n");
1933 if(ret<-1) return -1; 1944 if(ret==DECODE_SLICE_FATAL_ERROR) return -1;
1934 } 1945 }
1935 } 1946 }
1936 break; 1947 break;
1937 } 1948 }
1938 } 1949 }