comparison mpeg12.c @ 1096:5e6e505d8997 libavcodec

field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
author michaelni
date Wed, 05 Mar 2003 17:48:19 +0000
parents f59c3f66363b
children b7f267d168b7
comparison
equal deleted inserted replaced
1095:c7604e6291c5 1096:5e6e505d8997
1021 } 1021 }
1022 } 1022 }
1023 } 1023 }
1024 break; 1024 break;
1025 case MT_FIELD: 1025 case MT_FIELD:
1026 s->mv_type = MV_TYPE_FIELD;
1026 if (s->picture_structure == PICT_FRAME) { 1027 if (s->picture_structure == PICT_FRAME) {
1027 s->mv_type = MV_TYPE_FIELD;
1028 for(j=0;j<2;j++) { 1028 for(j=0;j<2;j++) {
1029 s->field_select[i][j] = get_bits1(&s->gb); 1029 s->field_select[i][j] = get_bits1(&s->gb);
1030 val = mpeg_decode_motion(s, s->mpeg_f_code[i][0], 1030 val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
1031 s->last_mv[i][j][0]); 1031 s->last_mv[i][j][0]);
1032 s->last_mv[i][j][0] = val; 1032 s->last_mv[i][j][0] = val;
1037 s->last_mv[i][j][1] = val << 1; 1037 s->last_mv[i][j][1] = val << 1;
1038 s->mv[i][j][1] = val; 1038 s->mv[i][j][1] = val;
1039 dprintf("fmy=%d\n", val); 1039 dprintf("fmy=%d\n", val);
1040 } 1040 }
1041 } else { 1041 } else {
1042 s->mv_type = MV_TYPE_16X16;
1043 s->field_select[i][0] = get_bits1(&s->gb); 1042 s->field_select[i][0] = get_bits1(&s->gb);
1044 for(k=0;k<2;k++) { 1043 for(k=0;k<2;k++) {
1045 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k], 1044 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
1046 s->last_mv[i][0][k]); 1045 s->last_mv[i][0][k]);
1047 s->last_mv[i][0][k] = val; 1046 s->last_mv[i][0][k] = val;
1699 s->alternate_scan = get_bits1(&s->gb); 1698 s->alternate_scan = get_bits1(&s->gb);
1700 s->repeat_first_field = get_bits1(&s->gb); 1699 s->repeat_first_field = get_bits1(&s->gb);
1701 s->chroma_420_type = get_bits1(&s->gb); 1700 s->chroma_420_type = get_bits1(&s->gb);
1702 s->progressive_frame = get_bits1(&s->gb); 1701 s->progressive_frame = get_bits1(&s->gb);
1703 1702
1703 if(s->picture_structure == PICT_FRAME)
1704 s->first_field=0;
1705 else{
1706 s->first_field ^= 1;
1707 memset(s->mbskip_table, 0, s->mb_width*s->mb_height);
1708 }
1709
1704 if(s->alternate_scan){ 1710 if(s->alternate_scan){
1705 ff_init_scantable(s, &s->inter_scantable , ff_alternate_vertical_scan); 1711 ff_init_scantable(s, &s->inter_scantable , ff_alternate_vertical_scan);
1706 ff_init_scantable(s, &s->intra_scantable , ff_alternate_vertical_scan); 1712 ff_init_scantable(s, &s->intra_scantable , ff_alternate_vertical_scan);
1707 ff_init_scantable(s, &s->intra_h_scantable, ff_alternate_vertical_scan); 1713 ff_init_scantable(s, &s->intra_h_scantable, ff_alternate_vertical_scan);
1708 ff_init_scantable(s, &s->intra_v_scantable, ff_alternate_vertical_scan); 1714 ff_init_scantable(s, &s->intra_v_scantable, ff_alternate_vertical_scan);
1769 uint8_t *buf, int buf_size) 1775 uint8_t *buf, int buf_size)
1770 { 1776 {
1771 Mpeg1Context *s1 = avctx->priv_data; 1777 Mpeg1Context *s1 = avctx->priv_data;
1772 MpegEncContext *s = &s1->mpeg_enc_ctx; 1778 MpegEncContext *s = &s1->mpeg_enc_ctx;
1773 int ret; 1779 int ret;
1780 const int field_pic= s->picture_structure != PICT_FRAME;
1774 1781
1775 start_code = (start_code - 1) & 0xff; 1782 start_code = (start_code - 1) & 0xff;
1776 if (start_code >= s->mb_height){ 1783 if (start_code >= s->mb_height){
1777 fprintf(stderr, "slice below image (%d >= %d)\n", start_code, s->mb_height); 1784 fprintf(stderr, "slice below image (%d >= %d)\n", start_code, s->mb_height);
1778 return DECODE_SLICE_ERROR; 1785 return DECODE_SLICE_ERROR;
1779 } 1786 }
1780 s->last_dc[0] = 1 << (7 + s->intra_dc_precision); 1787 s->last_dc[0] = 1 << (7 + s->intra_dc_precision);
1781 s->last_dc[1] = s->last_dc[0]; 1788 s->last_dc[1] = s->last_dc[0];
1782 s->last_dc[2] = s->last_dc[0]; 1789 s->last_dc[2] = s->last_dc[0];
1783 memset(s->last_mv, 0, sizeof(s->last_mv)); 1790 memset(s->last_mv, 0, sizeof(s->last_mv));
1791
1784 /* start frame decoding */ 1792 /* start frame decoding */
1785 if (s->first_slice) { 1793 if (s->first_slice && (s->first_field || s->picture_structure==PICT_FRAME)) {
1786 s->first_slice = 0;
1787 if(MPV_frame_start(s, avctx) < 0) 1794 if(MPV_frame_start(s, avctx) < 0)
1788 return DECODE_SLICE_FATAL_ERROR; 1795 return DECODE_SLICE_FATAL_ERROR;
1789 /* first check if we must repeat the frame */ 1796 /* first check if we must repeat the frame */
1790 s->current_picture.repeat_pict = 0; 1797 s->current_picture.repeat_pict = 0;
1791 1798
1808 s->progressive_sequence ? "pro" :"", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"", 1815 s->progressive_sequence ? "pro" :"", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"",
1809 s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors, 1816 s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors,
1810 s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :""); 1817 s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :"");
1811 } 1818 }
1812 } 1819 }
1820 s->first_slice = 0;
1813 1821
1814 init_get_bits(&s->gb, buf, buf_size*8); 1822 init_get_bits(&s->gb, buf, buf_size*8);
1815 1823
1816 s->qscale = get_qscale(s); 1824 s->qscale = get_qscale(s);
1817 /* extra slice info */ 1825 /* extra slice info */
1842 1850
1843 ret = mpeg_decode_mb(s, s->block); 1851 ret = mpeg_decode_mb(s, s->block);
1844 dprintf("ret=%d\n", ret); 1852 dprintf("ret=%d\n", ret);
1845 if (ret < 0) 1853 if (ret < 0)
1846 return -1; 1854 return -1;
1847 1855 //printf("%d %d\n", s->mb_x, s->mb_y);
1856 //FIXME this isnt the most beautifull way to solve the problem ...
1857 if(s->picture_structure!=PICT_FRAME){
1858 if(s->picture_structure == PICT_BOTTOM_FIELD){
1859 s->current_picture.data[0] += s->linesize;
1860 s->current_picture.data[1] += s->uvlinesize;
1861 s->current_picture.data[2] += s->uvlinesize;
1862 }
1863 s->linesize *= 2;
1864 s->uvlinesize *= 2;
1865 }
1848 MPV_decode_mb(s, s->block); 1866 MPV_decode_mb(s, s->block);
1867 if(s->picture_structure!=PICT_FRAME){
1868 s->linesize /= 2;
1869 s->uvlinesize /= 2;
1870 if(s->picture_structure == PICT_BOTTOM_FIELD){
1871 s->current_picture.data[0] -= s->linesize;
1872 s->current_picture.data[1] -= s->uvlinesize;
1873 s->current_picture.data[2] -= s->uvlinesize;
1874 }
1875 }
1849 1876
1850 if (++s->mb_x >= s->mb_width) { 1877 if (++s->mb_x >= s->mb_width) {
1851 ff_draw_horiz_band(s); 1878 ff_draw_horiz_band(s);
1852 1879
1853 s->mb_x = 0; 1880 s->mb_x = 0;
1873 s->mb_incr += code; 1900 s->mb_incr += code;
1874 break; 1901 break;
1875 } 1902 }
1876 } 1903 }
1877 } 1904 }
1878 if(s->mb_y >= s->mb_height){ 1905 if(s->mb_y<<field_pic >= s->mb_height){
1879 fprintf(stderr, "slice too long\n"); 1906 fprintf(stderr, "slice too long\n");
1880 return DECODE_SLICE_ERROR; 1907 return DECODE_SLICE_ERROR;
1881 } 1908 }
1882 } 1909 }
1883 eos: //end of slice 1910 eos: //end of slice
1884 1911
1885 emms_c(); 1912 emms_c();
1886 1913 //intf("%d %d %d %d\n", s->mb_y, s->mb_height, s->pict_type, s->picture_number);
1887 /* end of slice reached */ 1914 /* end of slice reached */
1888 if (/*s->mb_x == 0 &&*/ 1915 if (s->mb_y<<field_pic == s->mb_height && !s->first_field) {
1889 s->mb_y == s->mb_height) {
1890 /* end of image */ 1916 /* end of image */
1891 1917
1892 if(s->mpeg2) 1918 if(s->mpeg2)
1893 s->qscale >>=1; 1919 s->qscale >>=1;
1894 1920
2157 /* skip everything if we are in a hurry>=5 */ 2183 /* skip everything if we are in a hurry>=5 */
2158 if(avctx->hurry_up>=5) break; 2184 if(avctx->hurry_up>=5) break;
2159 2185
2160 ret = mpeg_decode_slice(avctx, picture, 2186 ret = mpeg_decode_slice(avctx, picture,
2161 start_code, s->buffer, input_size); 2187 start_code, s->buffer, input_size);
2188
2162 if (ret == DECODE_SLICE_EOP) { 2189 if (ret == DECODE_SLICE_EOP) {
2163 *data_size = sizeof(AVPicture); 2190 *data_size = sizeof(AVPicture);
2164 goto the_end; 2191 goto the_end;
2165 }else if(ret<0){ 2192 }else if(ret<0){
2166 fprintf(stderr,"Error while decoding slice\n"); 2193 fprintf(stderr,"Error while decoding slice\n");