comparison mpeg12.c @ 903:22ee74da2cd3 libavcodec

cleanup adding AVVideoFrame moving quality, pict_type, key_frame, qscale_table, ... to AVVideoFrame removing obsolete variables in AVCodecContext skiping of MBs in b frames correctly initalizing AVCodecContext picture buffer cleanup
author michaelni
date Wed, 04 Dec 2002 10:04:03 +0000
parents 653d9419ea01
children 4b2c86f1fee9
comparison
equal deleted inserted replaced
902:6acc8394960d 903:22ee74da2cd3
132 unsigned int vbv_buffer_size; 132 unsigned int vbv_buffer_size;
133 unsigned int fps, v; 133 unsigned int fps, v;
134 int n; 134 int n;
135 UINT64 time_code; 135 UINT64 time_code;
136 136
137 if (s->picture_in_gop_number == 0) { 137 if (s->current_picture.key_frame) {
138 /* mpeg1 header repeated every gop */ 138 /* mpeg1 header repeated every gop */
139 put_header(s, SEQ_START_CODE); 139 put_header(s, SEQ_START_CODE);
140 140
141 /* search closest frame rate */ 141 /* search closest frame rate */
142 { 142 {
1357 s->start_code = -1; 1357 s->start_code = -1;
1358 s->buf_ptr = s->buffer; 1358 s->buf_ptr = s->buffer;
1359 s->mpeg_enc_ctx.picture_number = 0; 1359 s->mpeg_enc_ctx.picture_number = 0;
1360 s->repeat_field = 0; 1360 s->repeat_field = 0;
1361 s->mpeg_enc_ctx.codec_id= avctx->codec->id; 1361 s->mpeg_enc_ctx.codec_id= avctx->codec->id;
1362 avctx->mbskip_table= s->mpeg_enc_ctx.mbskip_table;
1363 return 0; 1362 return 0;
1364 } 1363 }
1365 1364
1366 /* return the 8 bit start code value and update the search 1365 /* return the 8 bit start code value and update the search
1367 state. Return -1 if no start code found */ 1366 state. Return -1 if no start code found */
1401 1400
1402 ref = get_bits(&s->gb, 10); /* temporal ref */ 1401 ref = get_bits(&s->gb, 10); /* temporal ref */
1403 s->pict_type = get_bits(&s->gb, 3); 1402 s->pict_type = get_bits(&s->gb, 3);
1404 dprintf("pict_type=%d number=%d\n", s->pict_type, s->picture_number); 1403 dprintf("pict_type=%d number=%d\n", s->pict_type, s->picture_number);
1405 1404
1406 avctx->pict_type= s->pict_type;
1407 avctx->key_frame= s->pict_type == I_TYPE;
1408
1409 skip_bits(&s->gb, 16); 1405 skip_bits(&s->gb, 16);
1410 if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { 1406 if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
1411 s->full_pel[0] = get_bits1(&s->gb); 1407 s->full_pel[0] = get_bits1(&s->gb);
1412 f_code = get_bits(&s->gb, 3); 1408 f_code = get_bits(&s->gb, 3);
1413 if (f_code == 0) 1409 if (f_code == 0)
1421 if (f_code == 0) 1417 if (f_code == 0)
1422 return -1; 1418 return -1;
1423 s->mpeg_f_code[1][0] = f_code; 1419 s->mpeg_f_code[1][0] = f_code;
1424 s->mpeg_f_code[1][1] = f_code; 1420 s->mpeg_f_code[1][1] = f_code;
1425 } 1421 }
1422 s->current_picture.pict_type= s->pict_type;
1423 s->current_picture.key_frame= s->pict_type == I_TYPE;
1426 s->y_dc_scale = 8; 1424 s->y_dc_scale = 8;
1427 s->c_dc_scale = 8; 1425 s->c_dc_scale = 8;
1428 s->first_slice = 1; 1426 s->first_slice = 1;
1429 return 0; 1427 return 0;
1430 } 1428 }
1574 * DECODE_SLICE_ERROR if the slice is damaged<br> 1572 * DECODE_SLICE_ERROR if the slice is damaged<br>
1575 * DECODE_SLICE_OK if this slice is ok<br> 1573 * DECODE_SLICE_OK if this slice is ok<br>
1576 * DECODE_SLICE_EOP if the end of the picture is reached 1574 * DECODE_SLICE_EOP if the end of the picture is reached
1577 */ 1575 */
1578 static int mpeg_decode_slice(AVCodecContext *avctx, 1576 static int mpeg_decode_slice(AVCodecContext *avctx,
1579 AVPicture *pict, 1577 AVVideoFrame *pict,
1580 int start_code, 1578 int start_code,
1581 UINT8 *buf, int buf_size) 1579 UINT8 *buf, int buf_size)
1582 { 1580 {
1583 Mpeg1Context *s1 = avctx->priv_data; 1581 Mpeg1Context *s1 = avctx->priv_data;
1584 MpegEncContext *s = &s1->mpeg_enc_ctx; 1582 MpegEncContext *s = &s1->mpeg_enc_ctx;
1675 1673
1676 /* end of slice reached */ 1674 /* end of slice reached */
1677 if (/*s->mb_x == 0 &&*/ 1675 if (/*s->mb_x == 0 &&*/
1678 s->mb_y == s->mb_height) { 1676 s->mb_y == s->mb_height) {
1679 /* end of image */ 1677 /* end of image */
1680 UINT8 **picture; 1678
1679 if(s->mpeg2)
1680 s->qscale >>=1;
1681 1681
1682 MPV_frame_end(s); 1682 MPV_frame_end(s);
1683 1683
1684 if (s->pict_type == B_TYPE) { 1684 if (s->pict_type == B_TYPE) {
1685 picture = s->current_picture; 1685 *pict= *(AVVideoFrame*)&s->current_picture;
1686 avctx->quality = s->qscale;
1687 } else { 1686 } else {
1687 s->picture_number++;
1688 /* latency of 1 frame for I and P frames */ 1688 /* latency of 1 frame for I and P frames */
1689 /* XXX: use another variable than picture_number */ 1689 /* XXX: use another variable than picture_number */
1690 if (s->picture_number == 0) { 1690 if (s->picture_number == 1) {
1691 picture = NULL; 1691 return DECODE_SLICE_OK;
1692 } else { 1692 } else {
1693 picture = s->last_picture; 1693 *pict= *(AVVideoFrame*)&s->last_picture;
1694 avctx->quality = s->last_qscale; 1694 }
1695 } 1695 }
1696 s->last_qscale = s->qscale; 1696 return DECODE_SLICE_EOP;
1697 s->picture_number++;
1698 }
1699 if(s->mpeg2)
1700 avctx->quality>>=1;
1701 if (picture) {
1702 pict->data[0] = picture[0];
1703 pict->data[1] = picture[1];
1704 pict->data[2] = picture[2];
1705 pict->linesize[0] = s->linesize;
1706 pict->linesize[1] = s->uvlinesize;
1707 pict->linesize[2] = s->uvlinesize;
1708 return DECODE_SLICE_EOP;
1709 } else {
1710 return DECODE_SLICE_OK;
1711 }
1712 } else { 1697 } else {
1713 return DECODE_SLICE_OK; 1698 return DECODE_SLICE_OK;
1714 } 1699 }
1715 } 1700 }
1716 1701
1825 UINT8 *buf, int buf_size) 1810 UINT8 *buf, int buf_size)
1826 { 1811 {
1827 Mpeg1Context *s = avctx->priv_data; 1812 Mpeg1Context *s = avctx->priv_data;
1828 UINT8 *buf_end, *buf_ptr, *buf_start; 1813 UINT8 *buf_end, *buf_ptr, *buf_start;
1829 int len, start_code_found, ret, code, start_code, input_size; 1814 int len, start_code_found, ret, code, start_code, input_size;
1830 AVPicture *picture = data; 1815 AVVideoFrame *picture = data;
1831 MpegEncContext *s2 = &s->mpeg_enc_ctx; 1816 MpegEncContext *s2 = &s->mpeg_enc_ctx;
1832 1817
1833 dprintf("fill_buffer\n"); 1818 dprintf("fill_buffer\n");
1834 1819
1835 *data_size = 0; 1820 *data_size = 0;
1836 1821
1837 /* special case for last picture */ 1822 /* special case for last picture */
1838 if (buf_size == 0) { 1823 if (buf_size == 0) {
1839 if (s2->picture_number > 0) { 1824 if (s2->picture_number > 0) {
1840 picture->data[0] = s2->next_picture[0]; 1825 *picture= *(AVVideoFrame*)&s2->next_picture;
1841 picture->data[1] = s2->next_picture[1]; 1826
1842 picture->data[2] = s2->next_picture[2]; 1827 *data_size = sizeof(AVVideoFrame);
1843 picture->linesize[0] = s2->linesize;
1844 picture->linesize[1] = s2->uvlinesize;
1845 picture->linesize[2] = s2->uvlinesize;
1846 *data_size = sizeof(AVPicture);
1847 } 1828 }
1848 return 0; 1829 return 0;
1849 } 1830 }
1850 1831
1851 buf_ptr = buf; 1832 buf_ptr = buf;