annotate dv.c @ 1506:e0c02032d0f2 libavcodec

support a few more types of VQA files
author melanson
date Sat, 11 Oct 2003 01:11:29 +0000
parents ad7e62df9962
children f4cf270b98ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
1 /*
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
2 * DV decoder
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
3 * Copyright (c) 2002 Fabrice Bellard.
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
4 *
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
5 * DV encoder
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
6 * Copyright (c) 2003 Roman Shaposhnik.
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
7 *
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
8 * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
9 * of DV technical info.
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
10 *
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
11 * This library is free software; you can redistribute it and/or
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
12 * modify it under the terms of the GNU Lesser General Public
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
13 * License as published by the Free Software Foundation; either
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
14 * version 2 of the License, or (at your option) any later version.
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
15 *
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
16 * This library is distributed in the hope that it will be useful,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
19 * Lesser General Public License for more details.
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
20 *
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
21 * You should have received a copy of the GNU Lesser General Public
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
22 * License along with this library; if not, write to the Free Software
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
24 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
25
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
26 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
27 * @file dv.c
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
28 * DV codec.
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
29 */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
30 #include "avcodec.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
31 #include "dsputil.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
32 #include "mpegvideo.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
33 #include "simple_idct.h"
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
34 #include "dvdata.h"
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
35
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
36 typedef struct DVVideoDecodeContext {
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
37 const DVprofile* sys;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
38 GetBitContext gb;
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
39 AVFrame picture;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
40 DCTELEM block[5*6][64] __align8;
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
41
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
42 /* FIXME: the following is extracted from DSP */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
43 uint8_t dv_zigzag[2][64];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
44 uint8_t idct_permutation[64];
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
45 void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size);
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
46 void (*fdct)(DCTELEM *block);
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
47
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
48 /* XXX: move it to static storage ? */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
49 uint8_t dv_shift[2][22][64];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
50 void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
51 } DVVideoDecodeContext;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
52
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
53 #define TEX_VLC_BITS 9
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
54 /* XXX: also include quantization */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
55 static RL_VLC_ELEM *dv_rl_vlc[1];
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
56 static VLC_TYPE dv_vlc_codes[15][23];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
57
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
58 static void dv_build_unquantize_tables(DVVideoDecodeContext *s)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
59 {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
60 int i, q, j;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
61
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
62 /* NOTE: max left shift is 6 */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
63 for(q = 0; q < 22; q++) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
64 /* 88 unquant */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
65 for(i = 1; i < 64; i++) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
66 /* 88 table */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
67 j = s->idct_permutation[i];
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
68 s->dv_shift[0][q][j] =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
69 dv_quant_shifts[q][dv_88_areas[i]] + 1;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
70 }
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
71
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
72 /* 248 unquant */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
73 for(i = 1; i < 64; i++) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
74 /* 248 table */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
75 s->dv_shift[1][q][i] =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
76 dv_quant_shifts[q][dv_248_areas[i]] + 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
77 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
78 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
79 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
80
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
81 static int dvvideo_init(AVCodecContext *avctx)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
82 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
83 DVVideoDecodeContext *s = avctx->priv_data;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
84 MpegEncContext s2;
1070
6da5ae9ee199 more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents: 1064
diff changeset
85 static int done=0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
86
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
87 if (!done) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
88 int i;
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
89 VLC dv_vlc;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
90
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
91 done = 1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
92
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
93 /* NOTE: as a trick, we use the fact the no codes are unused
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
94 to accelerate the parsing of partial codes */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
95 init_vlc(&dv_vlc, TEX_VLC_BITS, NB_DV_VLC,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
96 dv_vlc_len, 1, 1, dv_vlc_bits, 2, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
97
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
98 dv_rl_vlc[0] = av_malloc(dv_vlc.table_size * sizeof(RL_VLC_ELEM));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
99 for(i = 0; i < dv_vlc.table_size; i++){
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
100 int code= dv_vlc.table[i][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
101 int len = dv_vlc.table[i][1];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
102 int level, run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
103
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
104 if(len<0){ //more bits needed
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
105 run= 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
106 level= code;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
107 } else if (code == (NB_DV_VLC - 1)) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
108 /* EOB */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
109 run = 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
110 level = 256;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
111 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
112 run= dv_vlc_run[code] + 1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
113 level= dv_vlc_level[code];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
114 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
115 dv_rl_vlc[0][i].len = len;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
116 dv_rl_vlc[0][i].level = level;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
117 dv_rl_vlc[0][i].run = run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
118 }
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
119
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
120 memset(dv_vlc_codes, 0xff, sizeof(dv_vlc_codes));
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
121 for (i = 0; i < NB_DV_VLC - 1; i++) {
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
122 if (dv_vlc_run[i] < 15 && dv_vlc_level[i] < 23 && dv_vlc_len[i] < 15)
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
123 dv_vlc_codes[dv_vlc_run[i]][dv_vlc_level[i]] = i;
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
124 }
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
125 }
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
126
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
127 /* ugly way to get the idct & scantable */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
128 /* XXX: fix it */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
129 memset(&s2, 0, sizeof(MpegEncContext));
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
130 s2.avctx = avctx;
1092
f59c3f66363b MpegEncContext.(i)dct_* -> DspContext.(i)dct_*
michaelni
parents: 1087
diff changeset
131 dsputil_init(&s2.dsp, avctx);
726
a91203b34e71 moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents: 725
diff changeset
132 if (DCT_common_init(&s2) < 0)
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
133 return -1;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
134
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
135 s->get_pixels = s2.dsp.get_pixels;
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
136 s->fdct = s2.dsp.fdct;
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
137
1092
f59c3f66363b MpegEncContext.(i)dct_* -> DspContext.(i)dct_*
michaelni
parents: 1087
diff changeset
138 s->idct_put[0] = s2.dsp.idct_put;
f59c3f66363b MpegEncContext.(i)dct_* -> DspContext.(i)dct_*
michaelni
parents: 1087
diff changeset
139 memcpy(s->idct_permutation, s2.dsp.idct_permutation, 64);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
140 memcpy(s->dv_zigzag[0], s2.intra_scantable.permutated, 64);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
141
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
142 /* XXX: use MMX also for idct248 */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
143 s->idct_put[1] = simple_idct248_put;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
144 memcpy(s->dv_zigzag[1], dv_248_zigzag, 64);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
145
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
146 /* XXX: do it only for constant case */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
147 dv_build_unquantize_tables(s);
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
148
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
149 /* FIXME: I really don't think this should be here */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
150 if (dv_codec_profile(avctx))
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
151 avctx->pix_fmt = dv_codec_profile(avctx)->pix_fmt;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
152
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
153 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
154 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
155
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
156 // #define VLC_DEBUG
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
157
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
158 typedef struct BlockInfo {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
159 const uint8_t *shift_table;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
160 const uint8_t *scan_table;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
161 uint8_t pos; /* position in block */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
162 uint8_t eob_reached; /* true if EOB has been reached */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
163 uint8_t dct_mode;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
164 uint8_t partial_bit_count;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
165 uint16_t partial_bit_buffer;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
166 int shift_offset;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
167 } BlockInfo;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
168
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
169 /* block size in bits */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
170 static const uint16_t block_sizes[6] = {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
171 112, 112, 112, 112, 80, 80
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
172 };
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
173
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
174 #ifndef ALT_BITSTREAM_READER
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
175 #warning only works with ALT_BITSTREAM_READER
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
176 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
177
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
178 /* decode ac coefs */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
179 static void dv_decode_ac(DVVideoDecodeContext *s,
1008
fb6cbb8a04a3 fixing DCTELEM != short
michaelni
parents: 949
diff changeset
180 BlockInfo *mb, DCTELEM *block, int last_index)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
181 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
182 int last_re_index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
183 int shift_offset = mb->shift_offset;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
184 const uint8_t *scan_table = mb->scan_table;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
185 const uint8_t *shift_table = mb->shift_table;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
186 int pos = mb->pos;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
187 int level, pos1, sign, run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
188 int partial_bit_count;
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
189 #ifndef ALT_BITSTREAM_READER //FIXME
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
190 int re_index=0;
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
191 int re1_index=0;
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
192 #endif
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
193 OPEN_READER(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
194
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
195 #ifdef VLC_DEBUG
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
196 printf("start\n");
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
197 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
198
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
199 /* if we must parse a partial vlc, we do it here */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
200 partial_bit_count = mb->partial_bit_count;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
201 if (partial_bit_count > 0) {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
202 uint8_t buf[4];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
203 uint32_t v;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
204 int l, l1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
205 GetBitContext gb1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
206
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
207 /* build the dummy bit buffer */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
208 l = 16 - partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
209 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
210 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
211 printf("show=%04x\n", SHOW_UBITS(re, &s->gb, 16));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
212 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
213 v = (mb->partial_bit_buffer << l) | SHOW_UBITS(re, &s->gb, l);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
214 buf[0] = v >> 8;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
215 buf[1] = v;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
216 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
217 printf("v=%04x cnt=%d %04x\n",
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
218 v, partial_bit_count, (mb->partial_bit_buffer << l));
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
219 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
220 /* try to read the codeword */
1025
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 1008
diff changeset
221 init_get_bits(&gb1, buf, 4*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
222 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
223 OPEN_READER(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
224 UPDATE_CACHE(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
225 GET_RL_VLC(level, run, re1, &gb1, dv_rl_vlc[0],
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
226 TEX_VLC_BITS, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
227 l = re1_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
228 CLOSE_READER(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
229 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
230 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
231 printf("****run=%d level=%d size=%d\n", run, level, l);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
232 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
233 /* compute codeword length */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
234 l1 = (level != 256 && level != 0);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
235 /* if too long, we cannot parse */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
236 l -= partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
237 if ((re_index + l + l1) > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
238 return;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
239 /* skip read bits */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
240 last_re_index = 0; /* avoid warning */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
241 re_index += l;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
242 /* by definition, if we can read the vlc, all partial bits
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
243 will be read (otherwise we could have read the vlc before) */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
244 mb->partial_bit_count = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
245 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
246 goto handle_vlc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
247 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
248
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
249 /* get the AC coefficients until last_index is reached */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
250 for(;;) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
251 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
252 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
253 printf("%2d: bits=%04x index=%d\n",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
254 pos, SHOW_UBITS(re, &s->gb, 16), re_index);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
255 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
256 last_re_index = re_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
257 GET_RL_VLC(level, run, re, &s->gb, dv_rl_vlc[0],
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
258 TEX_VLC_BITS, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
259 handle_vlc:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
260 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
261 printf("run=%d level=%d\n", run, level);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
262 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
263 if (level == 256) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
264 if (re_index > last_index) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
265 cannot_read:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
266 /* put position before read code */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
267 re_index = last_re_index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
268 mb->eob_reached = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
269 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
270 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
271 /* EOB */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
272 mb->eob_reached = 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
273 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
274 } else if (level != 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
275 if ((re_index + 1) > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
276 goto cannot_read;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
277 sign = SHOW_SBITS(re, &s->gb, 1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
278 level = (level ^ sign) - sign;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
279 LAST_SKIP_BITS(re, &s->gb, 1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
280 pos += run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
281 /* error */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
282 if (pos >= 64) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
283 goto read_error;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
284 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
285 pos1 = scan_table[pos];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
286 level = level << (shift_table[pos1] + shift_offset);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
287 block[pos1] = level;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
288 // printf("run=%d level=%d shift=%d\n", run, level, shift_table[pos1]);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
289 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
290 if (re_index > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
291 goto cannot_read;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
292 /* level is zero: means run without coding. No
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
293 sign is coded */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
294 pos += run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
295 /* error */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
296 if (pos >= 64) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
297 read_error:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
298 #if defined(VLC_DEBUG) || 1
1222
adcc6f345202 making it nicer to the client who doesn't expect errors messages in stdout
romansh
parents: 1221
diff changeset
299 fprintf(stderr, "error pos=%d\n", pos);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
300 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
301 /* for errors, we consider the eob is reached */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
302 mb->eob_reached = 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
303 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
304 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
305 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
306 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
307 CLOSE_READER(re, &s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
308 mb->pos = pos;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
309 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
310
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
311 static inline void bit_copy(PutBitContext *pb, GetBitContext *gb, int bits_left)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
312 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
313 while (bits_left >= 16) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
314 put_bits(pb, 16, get_bits(gb, 16));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
315 bits_left -= 16;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
316 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
317 if (bits_left > 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
318 put_bits(pb, bits_left, get_bits(gb, bits_left));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
319 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
320 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
321
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
322 /* mb_x and mb_y are in units of 8 pixels */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
323 static inline void dv_decode_video_segment(DVVideoDecodeContext *s,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
324 uint8_t *buf_ptr1,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
325 const uint16_t *mb_pos_ptr)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
326 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
327 int quant, dc, dct_mode, class1, j;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
328 int mb_index, mb_x, mb_y, v, last_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
329 DCTELEM *block, *block1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
330 int c_offset, bits_left;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
331 uint8_t *y_ptr;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
332 BlockInfo mb_data[5 * 6], *mb, *mb1;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
333 void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block);
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
334 uint8_t *buf_ptr;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
335 PutBitContext pb, vs_pb;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
336 uint8_t mb_bit_buffer[80 + 4]; /* allow some slack */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
337 int mb_bit_count;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
338 uint8_t vs_bit_buffer[5 * 80 + 4]; /* allow some slack */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
339 int vs_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
340
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
341 memset(s->block, 0, sizeof(s->block));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
342
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
343 /* pass 1 : read DC and AC coefficients in blocks */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
344 buf_ptr = buf_ptr1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
345 block1 = &s->block[0][0];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
346 mb1 = mb_data;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
347 init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80, NULL, NULL);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
348 vs_bit_count = 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
349 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
350 /* skip header */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
351 quant = buf_ptr[3] & 0x0f;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
352 buf_ptr += 4;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
353 init_put_bits(&pb, mb_bit_buffer, 80, NULL, NULL);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
354 mb_bit_count = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
355 mb = mb1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
356 block = block1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
357 for(j = 0;j < 6; j++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
358 /* NOTE: size is not important here */
1025
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 1008
diff changeset
359 init_get_bits(&s->gb, buf_ptr, 14*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
360
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
361 /* get the dc */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
362 dc = get_bits(&s->gb, 9);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
363 dc = (dc << (32 - 9)) >> (32 - 9);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
364 dct_mode = get_bits1(&s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
365 mb->dct_mode = dct_mode;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
366 mb->scan_table = s->dv_zigzag[dct_mode];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
367 class1 = get_bits(&s->gb, 2);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
368 mb->shift_offset = (class1 == 3);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
369 mb->shift_table = s->dv_shift[dct_mode]
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
370 [quant + dv_quant_offset[class1]];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
371 dc = dc << 2;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
372 /* convert to unsigned because 128 is not added in the
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
373 standard IDCT */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
374 dc += 1024;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
375 block[0] = dc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
376 last_index = block_sizes[j];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
377 buf_ptr += last_index >> 3;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
378 mb->pos = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
379 mb->partial_bit_count = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
380
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
381 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
382 printf("MB block: %d, %d ", mb_index, j);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
383 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
384 dv_decode_ac(s, mb, block, last_index);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
385
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
386 /* write the remaining bits in a new buffer only if the
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
387 block is finished */
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
388 bits_left = last_index - get_bits_count(&s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
389 if (mb->eob_reached) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
390 mb->partial_bit_count = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
391 mb_bit_count += bits_left;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
392 bit_copy(&pb, &s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
393 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
394 /* should be < 16 bits otherwise a codeword could have
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
395 been parsed */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
396 mb->partial_bit_count = bits_left;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
397 mb->partial_bit_buffer = get_bits(&s->gb, bits_left);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
398 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
399 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
400 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
401 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
402
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
403 flush_put_bits(&pb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
404
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
405 /* pass 2 : we can do it just after */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
406 #ifdef VLC_DEBUG
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
407 printf("***pass 2 size=%d MB#=%d\n", mb_bit_count, mb_index);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
408 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
409 block = block1;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
410 mb = mb1;
1025
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 1008
diff changeset
411 init_get_bits(&s->gb, mb_bit_buffer, 80*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
412 for(j = 0;j < 6; j++) {
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
413 if (!mb->eob_reached && get_bits_count(&s->gb) < mb_bit_count) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
414 dv_decode_ac(s, mb, block, mb_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
415 /* if still not finished, no need to parse other blocks */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
416 if (!mb->eob_reached) {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
417 /* we could not parse the current AC coefficient,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
418 so we add the remaining bytes */
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
419 bits_left = mb_bit_count - get_bits_count(&s->gb);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
420 if (bits_left > 0) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
421 mb->partial_bit_count += bits_left;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
422 mb->partial_bit_buffer =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
423 (mb->partial_bit_buffer << bits_left) |
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
424 get_bits(&s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
425 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
426 goto next_mb;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
427 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
428 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
429 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
430 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
431 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
432 /* all blocks are finished, so the extra bytes can be used at
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
433 the video segment level */
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
434 bits_left = mb_bit_count - get_bits_count(&s->gb);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
435 vs_bit_count += bits_left;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
436 bit_copy(&vs_pb, &s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
437 next_mb:
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
438 mb1 += 6;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
439 block1 += 6 * 64;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
440 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
441
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
442 /* we need a pass other the whole video segment */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
443 flush_put_bits(&vs_pb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
444
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
445 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
446 printf("***pass 3 size=%d\n", vs_bit_count);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
447 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
448 block = &s->block[0][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
449 mb = mb_data;
1025
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 1008
diff changeset
450 init_get_bits(&s->gb, vs_bit_buffer, 5 * 80*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
451 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
452 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
453 if (!mb->eob_reached) {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
454 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
455 printf("start %d:%d\n", mb_index, j);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
456 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
457 dv_decode_ac(s, mb, block, vs_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
458 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
459 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
460 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
461 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
462 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
463
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
464 /* compute idct and place blocks */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
465 block = &s->block[0][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
466 mb = mb_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
467 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
468 v = *mb_pos_ptr++;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
469 mb_x = v & 0xff;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
470 mb_y = v >> 8;
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
471 y_ptr = s->picture.data[0] + (mb_y * s->picture.linesize[0] * 8) + (mb_x * 8);
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
472 if (s->sys->pix_fmt == PIX_FMT_YUV411P)
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
473 c_offset = (mb_y * s->picture.linesize[1] * 8) + ((mb_x >> 2) * 8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
474 else
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
475 c_offset = ((mb_y >> 1) * s->picture.linesize[1] * 8) + ((mb_x >> 1) * 8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
476 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
477 idct_put = s->idct_put[mb->dct_mode];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
478 if (j < 4) {
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
479 if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x < (704 / 8)) {
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
480 /* NOTE: at end of line, the macroblock is handled as 420 */
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
481 idct_put(y_ptr + (j * 8), s->picture.linesize[0], block);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
482 } else {
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
483 idct_put(y_ptr + ((j & 1) * 8) + ((j >> 1) * 8 * s->picture.linesize[0]),
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
484 s->picture.linesize[0], block);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
485 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
486 } else {
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
487 if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) {
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
488 uint8_t pixels[64], *c_ptr, *c_ptr1, *ptr;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
489 int y, linesize;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
490 /* NOTE: at end of line, the macroblock is handled as 420 */
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
491 idct_put(pixels, 8, block);
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
492 linesize = s->picture.linesize[6 - j];
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
493 c_ptr = s->picture.data[6 - j] + c_offset;
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
494 ptr = pixels;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
495 for(y = 0;y < 8; y++) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
496 /* convert to 411P */
1270
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
497 c_ptr1 = c_ptr + 8*linesize;
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
498 c_ptr[0]= ptr[0]; c_ptr1[0]= ptr[4];
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
499 c_ptr[1]= ptr[1]; c_ptr1[1]= ptr[5];
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
500 c_ptr[2]= ptr[2]; c_ptr1[2]= ptr[6];
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
501 c_ptr[3]= ptr[3]; c_ptr1[3]= ptr[7];
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
502 c_ptr += linesize;
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
503 ptr += 8;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
504 }
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
505 } else {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
506 /* don't ask me why they inverted Cb and Cr ! */
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
507 idct_put(s->picture.data[6 - j] + c_offset,
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
508 s->picture.linesize[6 - j], block);
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
509 }
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
510 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
511 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
512 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
513 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
514 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
515 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
516
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
517 /* Converts run and level (where level != 0) pair into vlc, returning bit size */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
518 static inline int dv_rl2vlc(int run, int l, uint32_t* vlc)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
519 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
520 int sign = l >> 8;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
521 int level = (l ^ sign) - sign;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
522 int size;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
523
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
524 sign = (sign & 1);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
525
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
526 if (run < 15 && level < 23 && dv_vlc_codes[run][level] != -1) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
527 *vlc = (dv_vlc_bits[dv_vlc_codes[run][level]] << 1) | sign;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
528 size = dv_vlc_len[dv_vlc_codes[run][level]] + 1;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
529 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
530 else {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
531 if (level < 23) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
532 *vlc = (dv_vlc_bits[dv_vlc_codes[0][level]] << 1) | sign;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
533 size = dv_vlc_len[dv_vlc_codes[0][level]] + 1;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
534 } else {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
535 *vlc = 0xfe00 | (level << 1) | sign;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
536 size = 16;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
537 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
538
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
539 switch(run) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
540 case 0:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
541 break;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
542 case 1:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
543 case 2:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
544 *vlc |= ((0x7ce | (run - 1)) << size);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
545 size += 11;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
546 break;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
547 case 3:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
548 case 4:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
549 case 5:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
550 case 6:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
551 *vlc |= ((0xfac | (run - 3)) << size);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
552 size += 12;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
553 break;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
554 default:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
555 *vlc |= ((0x1f80 | (run - 1)) << size);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
556 size += 13;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
557 break;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
558 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
559 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
560
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
561 return size;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
562 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
563
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
564 typedef struct EncBlockInfo {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
565 int qno;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
566 int cno;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
567 int dct_mode;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
568 int block_size;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
569 DCTELEM *mb;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
570 PutBitContext pb;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
571 } EncBlockInfo;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
572
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
573 static inline int dv_bits_left(EncBlockInfo* bi)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
574 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
575 return (bi->block_size - get_bit_count(&bi->pb));
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
576 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
577
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
578 static inline void dv_encode_ac(EncBlockInfo* bi, PutBitContext* heap)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
579 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
580 int i, level, size, run = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
581 uint32_t vlc;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
582 PutBitContext* cpb = &bi->pb;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
583
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
584 for (i=1; i<64; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
585 level = bi->mb[ff_zigzag_direct[i]] /
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
586 (1<<(dv_quant_shifts[bi->qno + dv_quant_offset[bi->cno]]
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
587 [dv_88_areas[ff_zigzag_direct[i]]] + 4 + (bi->cno == 3)));
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
588 if (level != 0) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
589 size = dv_rl2vlc(run, level, &vlc);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
590 put_vlc:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
591
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
592 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
593 printf(" %3d:%3d", run, level);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
594 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
595 if (cpb == &bi->pb && size > dv_bits_left(bi)) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
596 size -= dv_bits_left(bi);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
597 put_bits(cpb, dv_bits_left(bi), vlc >> size);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
598 vlc = vlc & ((1<<size)-1);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
599 cpb = heap;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
600 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
601 put_bits(cpb, size, vlc);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
602 run = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
603 } else
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
604 run++;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
605 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
606
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
607 if (i == 64) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
608 size = 4; vlc = 6; /* End Of Block stamp */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
609 goto put_vlc;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
610 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
611 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
612
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
613 static inline void dv_redistr_bits(EncBlockInfo* bi, int count, uint8_t* extra_data, int extra_bits, PutBitContext* heap)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
614 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
615 int i;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
616 GetBitContext gb;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
617
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
618 init_get_bits(&gb, extra_data, extra_bits);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
619
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
620 for (i=0; i<count; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
621 int bits_left = dv_bits_left(bi);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
622 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
623 if (bits_left)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
624 printf("------------> inserting %d bytes in %d:%d\n", bits_left, i/6, i%6);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
625 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
626 if (bits_left > extra_bits) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
627 bit_copy(&bi->pb, &gb, extra_bits);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
628 extra_bits = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
629 break;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
630 } else
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
631 bit_copy(&bi->pb, &gb, bits_left);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
632
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
633 extra_bits -= bits_left;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
634 bi++;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
635 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
636
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
637 if (extra_bits > 0 && heap)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
638 bit_copy(heap, &gb, extra_bits);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
639 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
640
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
641 static inline void dv_set_class_number(EncBlockInfo* bi, int j)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
642 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
643 int i, max_ac = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
644
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
645 for (i=1; i<64; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
646 int ac = abs(bi->mb[ff_zigzag_direct[i]]) / 4;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
647 if (max_ac < ac)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
648 max_ac = ac;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
649 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
650 if (max_ac < 12)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
651 bi->cno = j;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
652 else if (max_ac < 24)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
653 bi->cno = j + 1;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
654 else if (max_ac < 36)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
655 bi->cno = j + 2;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
656 else
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
657 bi->cno = j + 3;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
658
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
659 if (bi->cno > 3)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
660 bi->cno = 3;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
661 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
662
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
663 /*
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
664 * This is a very rough initial implementaion. The performance is
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
665 * horrible and some features are missing, mainly 2-4-8 DCT encoding.
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
666 * The weighting is missing as well, but it's missing from the decoding
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
667 * step also -- so at least we're on the same page with decoder ;-)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
668 */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
669 static inline void dv_encode_video_segment(DVVideoDecodeContext *s,
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
670 uint8_t *dif,
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
671 const uint16_t *mb_pos_ptr)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
672 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
673 int mb_index, i, j, v;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
674 int mb_x, mb_y, c_offset, linesize;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
675 uint8_t* y_ptr;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
676 uint8_t* data;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
677 int do_edge_wrap;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
678 DCTELEM *block;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
679 EncBlockInfo enc_blks[5*6];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
680 EncBlockInfo* enc_blk;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
681 int free_vs_bits;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
682 int extra_bits;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
683 PutBitContext extra_vs;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
684 uint8_t extra_vs_data[5*6*128];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
685 uint8_t extra_mb_data[6*128];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
686
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
687 int QNO = 15;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
688
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
689 /* Stage 1 -- doing DCT on 5 MBs */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
690 block = &s->block[0][0];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
691 for(mb_index = 0; mb_index < 5; mb_index++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
692 v = *mb_pos_ptr++;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
693 mb_x = v & 0xff;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
694 mb_y = v >> 8;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
695 y_ptr = s->picture.data[0] + (mb_y * s->picture.linesize[0] * 8) + (mb_x * 8);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
696 c_offset = (s->sys->pix_fmt == PIX_FMT_YUV411P) ?
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
697 ((mb_y * s->picture.linesize[1] * 8) + ((mb_x >> 2) * 8)) :
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
698 (((mb_y >> 1) * s->picture.linesize[1] * 8) + ((mb_x >> 1) * 8));
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
699 do_edge_wrap = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
700 for(j = 0;j < 6; j++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
701 if (j < 4) { /* Four Y blocks */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
702 /* NOTE: at end of line, the macroblock is handled as 420 */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
703 if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x < (704 / 8)) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
704 data = y_ptr + (j * 8);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
705 } else {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
706 data = y_ptr + ((j & 1) * 8) + ((j >> 1) * 8 * s->picture.linesize[0]);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
707 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
708 linesize = s->picture.linesize[0];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
709 } else { /* Cr and Cb blocks */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
710 /* don't ask Fabrice why they inverted Cb and Cr ! */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
711 data = s->picture.data[6 - j] + c_offset;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
712 linesize = s->picture.linesize[6 - j];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
713 if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8))
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
714 do_edge_wrap = 1;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
715 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
716
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
717 /* Everything is set up -- now just copy data -> DCT block */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
718 if (do_edge_wrap) { /* Edge wrap copy: 4x16 -> 8x8 */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
719 uint8_t* d;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
720 DCTELEM *b = block;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
721 for (i=0;i<8;i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
722 d = data + 8 * linesize;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
723 b[0] = data[0]; b[1] = data[1]; b[2] = data[2]; b[3] = data[3];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
724 b[4] = d[0]; b[5] = d[1]; b[6] = d[2]; b[7] = d[3];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
725 data += linesize;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
726 b += 8;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
727 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
728 } else { /* Simple copy: 8x8 -> 8x8 */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
729 s->get_pixels(block, data, linesize);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
730 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
731
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
732 s->fdct(block);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
733
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
734 block += 64;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
735 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
736 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
737
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
738 /* Stage 2 -- setup for encoding phase */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
739 enc_blk = &enc_blks[0];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
740 block = &s->block[0][0];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
741 for (i=0; i<5; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
742 for (j=0; j<6; j++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
743 enc_blk->mb = block;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
744 enc_blk->dct_mode = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
745 enc_blk->block_size = block_sizes[j];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
746
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
747 dv_set_class_number(enc_blk, j/4*(j%2));
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
748
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
749 block += 64;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
750 enc_blk++;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
751 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
752 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
753
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
754 /* Stage 3 -- encoding by trial-and-error */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
755 encode_vs:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
756 enc_blk = &enc_blks[0];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
757 for (i=0; i<5; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
758 uint8_t* p = dif + i*80 + 4;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
759 for (j=0; j<6; j++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
760 enc_blk->qno = QNO;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
761 init_put_bits(&enc_blk->pb, p, block_sizes[j]/8, NULL, NULL);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
762 enc_blk++;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
763 p += block_sizes[j]/8;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
764 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
765 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
766
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
767 init_put_bits(&extra_vs, extra_vs_data, sizeof(extra_vs_data), NULL, NULL);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
768 free_vs_bits = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
769 enc_blk = &enc_blks[0];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
770 for (i=0; i<5; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
771 PutBitContext extra_mb;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
772 EncBlockInfo* enc_blk2 = enc_blk;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
773 int free_mb_bits = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
774
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
775 init_put_bits(&extra_mb, extra_mb_data, sizeof(extra_mb_data), NULL, NULL);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
776 dif[i*80 + 3] = enc_blk->qno;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
777
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
778 for (j=0; j<6; j++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
779 uint16_t dc = ((enc_blk->mb[0] >> 3) - 1024) >> 2;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
780
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
781 put_bits(&enc_blk->pb, 9, dc);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
782 put_bits(&enc_blk->pb, 1, enc_blk->dct_mode);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
783 put_bits(&enc_blk->pb, 2, enc_blk->cno);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
784
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
785 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
786 printf("[%d, %d]: ", i, j);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
787 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
788 dv_encode_ac(enc_blk, &extra_mb);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
789 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
790 printf("\n");
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
791 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
792
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
793 free_mb_bits += dv_bits_left(enc_blk);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
794 enc_blk++;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
795 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
796
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
797 /* We can't flush extra_mb just yet -- since it'll round up bit number */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
798 extra_bits = get_bit_count(&extra_mb);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
799 if (free_mb_bits > extra_bits)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
800 free_vs_bits += free_mb_bits - extra_bits;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
801
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
802 if (extra_bits) { /* FIXME: speed up things when free_mb_bits == 0 */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
803 flush_put_bits(&extra_mb);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
804 dv_redistr_bits(enc_blk2, 6, extra_mb_data, extra_bits, &extra_vs);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
805 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
806 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
807
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
808 /* We can't flush extra_mb just yet -- since it'll round up bit number */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
809 extra_bits = get_bit_count(&extra_vs);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
810 if (extra_bits > free_vs_bits && QNO) { /* FIXME: very crude trial-and-error */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
811 QNO--;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
812 goto encode_vs;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
813 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
814
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
815 if (extra_bits) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
816 flush_put_bits(&extra_vs);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
817 dv_redistr_bits(&enc_blks[0], 5*6, extra_vs_data, extra_bits, NULL);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
818 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
819
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
820 for (i=0; i<6*5; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
821 flush_put_bits(&enc_blks[i].pb);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
822 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
823 printf("[%d:%d] qno=%d cno=%d\n", i/6, i%6, enc_blks[i].qno, enc_blks[i].cno);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
824 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
825 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
826 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
827
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
828 /* NOTE: exactly one frame must be given (120000 bytes for NTSC,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
829 144000 bytes for PAL) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
830 static int dvvideo_decode_frame(AVCodecContext *avctx,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
831 void *data, int *data_size,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
832 uint8_t *buf, int buf_size)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
833 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
834 DVVideoDecodeContext *s = avctx->priv_data;
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
835 int ds, vs;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
836 const uint16_t *mb_pos_ptr;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
837
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
838 s->sys = dv_frame_profile(buf);
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
839 if (!s->sys || buf_size < s->sys->frame_size)
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
840 return -1; /* NOTE: we only accept several full frames */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
841
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
842
1228
d63e0185a90f release buffer cleanup
michaelni
parents: 1222
diff changeset
843 if(s->picture.data[0])
d63e0185a90f release buffer cleanup
michaelni
parents: 1222
diff changeset
844 avctx->release_buffer(avctx, &s->picture);
d63e0185a90f release buffer cleanup
michaelni
parents: 1222
diff changeset
845
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
846 s->picture.reference = 0;
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
847 avctx->pix_fmt = s->sys->pix_fmt;
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
848 if(avctx->get_buffer(avctx, &s->picture) < 0) {
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
849 fprintf(stderr, "get_buffer() failed\n");
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
850 return -1;
835
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
851 }
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
852
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
853 /* for each DIF segment */
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
854 mb_pos_ptr = s->sys->video_place;
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
855 for (ds = 0; ds < s->sys->difseg_size; ds++) {
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
856 buf += 6 * 80; /* skip DIF segment header */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
857
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
858 for(vs = 0; vs < 27; vs++) {
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
859 if ((vs % 3) == 0)
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
860 buf += 80; /* skip audio block */
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
861
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
862 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
863 printf("********************* %d, %d **********************\n", ds, vs);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
864 #endif
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
865 dv_decode_video_segment(s, buf, mb_pos_ptr);
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
866 buf += 5 * 80;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
867 mb_pos_ptr += 5;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
868 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
869 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
870
734
2d6b3e3d6c6f 10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents: 733
diff changeset
871 emms_c();
2d6b3e3d6c6f 10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents: 733
diff changeset
872
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
873 /* return image */
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
874 *data_size = sizeof(AVFrame);
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
875 *(AVFrame*)data= s->picture;
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
876
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
877 return s->sys->frame_size;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
878 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
879
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
880 static int dvvideo_encode_frame(AVCodecContext *c, uint8_t *buf, int buf_size,
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
881 void *data)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
882 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
883 DVVideoDecodeContext *s = c->priv_data;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
884 const uint16_t *mb_pos_ptr;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
885 int ds, vs;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
886
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
887 s->sys = dv_codec_profile(c);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
888 if (!s->sys)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
889 return -1;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
890
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
891 c->pix_fmt = s->sys->pix_fmt;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
892 s->picture = *((AVFrame *)data);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
893
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
894 /* for each DIF segment */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
895 mb_pos_ptr = s->sys->video_place;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
896 for (ds = 0; ds < s->sys->difseg_size; ds++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
897 buf += 6 * 80; /* skip DIF segment header */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
898
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
899 for(vs = 0; vs < 27; vs++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
900 if ((vs % 3) == 0)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
901 buf += 80; /* skip audio block */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
902
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
903 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
904 printf("********************* %d, %d **********************\n", ds, vs);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
905 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
906 dv_encode_video_segment(s, buf, mb_pos_ptr);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
907 buf += 5 * 80;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
908 mb_pos_ptr += 5;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
909 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
910 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
911
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
912 emms_c();
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
913 return s->sys->frame_size;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
914 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
915
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
916 static int dvvideo_end(AVCodecContext *avctx)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
917 {
1214
327c5a36dfe7 fixing mixed dr1 + internal buffers
michaelni
parents: 1167
diff changeset
918 avcodec_default_free_buffers(avctx);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
919 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
920 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
921
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
922 AVCodec dvvideo_decoder = {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
923 "dvvideo",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
924 CODEC_TYPE_VIDEO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
925 CODEC_ID_DVVIDEO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
926 sizeof(DVVideoDecodeContext),
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
927 dvvideo_init,
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
928 dvvideo_encode_frame,
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
929 dvvideo_end,
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
930 dvvideo_decode_frame,
835
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
931 CODEC_CAP_DR1,
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
932 NULL
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
933 };