annotate dv.c @ 1598:932d306bf1dc libavcodec

av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
author michael
date Mon, 03 Nov 2003 13:26:22 +0000
parents e08df4d22d27
children 59f2fa833449
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;
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
38 AVFrame picture;
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
39
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
40 uint8_t dv_zigzag[2][64];
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
41 uint8_t dv_idct_shift[2][22][64];
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
42 uint8_t dv_dct_shift[2][22][64];
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
43
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
44 void (*get_pixels)(DCTELEM *block, const uint8_t *pixels, int line_size);
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
45 void (*fdct[2])(DCTELEM *block);
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
46 void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block);
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
47
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
48 GetBitContext gb;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
49 DCTELEM block[5*6][64] __align8;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
50 } DVVideoDecodeContext;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
51
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
52 #define TEX_VLC_BITS 9
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
53 /* XXX: also include quantization */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
54 static RL_VLC_ELEM *dv_rl_vlc[1];
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
55 static VLC_TYPE dv_vlc_codes[15][23];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
56
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
57 static void dv_build_unquantize_tables(DVVideoDecodeContext *s, uint8_t* perm)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
58 {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
59 int i, q, j;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
60
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
61 /* NOTE: max left shift is 6 */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
62 for(q = 0; q < 22; q++) {
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
63 /* 88DCT */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
64 for(i = 1; i < 64; i++) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
65 /* 88 table */
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
66 j = perm[i];
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
67 s->dv_idct_shift[0][q][j] =
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
68 dv_quant_shifts[q][dv_88_areas[i]] + 1;
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
69 s->dv_dct_shift[0][q][i] =
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
70 dv_quant_shifts[q][dv_88_areas[ff_zigzag_direct[i]]] + 4;
725
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
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
73 /* 248DCT */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
74 for(i = 1; i < 64; i++) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
75 /* 248 table */
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
76 s->dv_idct_shift[1][q][i] =
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
77 dv_quant_shifts[q][dv_248_areas[i]] + 1;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
78 s->dv_dct_shift[1][q][i] =
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
79 dv_quant_shifts[q][dv_248_areas[ff_zigzag248_direct[i]]] + 4;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
80 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
81 }
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
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
84 static int dvvideo_init(AVCodecContext *avctx)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
85 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
86 DVVideoDecodeContext *s = avctx->priv_data;
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
87 DSPContext dsp;
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
88 static int done=0;
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
89 int i;
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 if (!done) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
92 int i;
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
93 VLC dv_vlc;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
94
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
95 done = 1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
96
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
97 /* 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
98 to accelerate the parsing of partial codes */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
99 init_vlc(&dv_vlc, TEX_VLC_BITS, NB_DV_VLC,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
100 dv_vlc_len, 1, 1, dv_vlc_bits, 2, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
101
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
102 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
103 for(i = 0; i < dv_vlc.table_size; i++){
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
104 int code= dv_vlc.table[i][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
105 int len = dv_vlc.table[i][1];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
106 int level, run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
107
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
108 if(len<0){ //more bits needed
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= code;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
111 } else if (code == (NB_DV_VLC - 1)) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
112 /* EOB */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
113 run = 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
114 level = 256;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
115 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
116 run= dv_vlc_run[code] + 1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
117 level= dv_vlc_level[code];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
118 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
119 dv_rl_vlc[0][i].len = len;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
120 dv_rl_vlc[0][i].level = level;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
121 dv_rl_vlc[0][i].run = run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
122 }
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
123
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
124 memset(dv_vlc_codes, 0xff, sizeof(dv_vlc_codes));
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
125 for (i = 0; i < NB_DV_VLC - 1; i++) {
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
126 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
127 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
128 }
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
129 }
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
130
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
131 /* Generic DSP setup */
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
132 dsputil_init(&dsp, avctx);
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
133 s->get_pixels = dsp.get_pixels;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
134
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
135 /* 88DCT setup */
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
136 s->fdct[0] = dsp.fdct;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
137 s->idct_put[0] = dsp.idct_put;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
138 for (i=0; i<64; i++)
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
139 s->dv_zigzag[0][i] = dsp.idct_permutation[ff_zigzag_direct[i]];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
140
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
141 /* 248DCT setup */
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
142 s->fdct[1] = dsp.fdct248;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
143 s->idct_put[1] = simple_idct248_put; // FIXME: need to add it to DSP
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
144 memcpy(s->dv_zigzag[1], ff_zigzag248_direct, 64);
725
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 */
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
147 dv_build_unquantize_tables(s, dsp.idct_permutation);
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;
1543
7542cb99b950 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 1540
diff changeset
152 avctx->coded_frame = &s->picture;
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
153
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
154 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
155 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
156
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
157 // #define VLC_DEBUG
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
158
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
159 typedef struct BlockInfo {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
160 const uint8_t *shift_table;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
161 const uint8_t *scan_table;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
162 uint8_t pos; /* position in block */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
163 uint8_t eob_reached; /* true if EOB has been reached */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
164 uint8_t dct_mode;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
165 uint8_t partial_bit_count;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
166 uint16_t partial_bit_buffer;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
167 int shift_offset;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
168 } BlockInfo;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
169
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
170 /* block size in bits */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
171 static const uint16_t block_sizes[6] = {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
172 112, 112, 112, 112, 80, 80
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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
175 #ifndef ALT_BITSTREAM_READER
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
176 #warning only works with ALT_BITSTREAM_READER
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
177 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
178
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
179 /* decode ac coefs */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
180 static void dv_decode_ac(DVVideoDecodeContext *s,
1008
fb6cbb8a04a3 fixing DCTELEM != short
michaelni
parents: 949
diff changeset
181 BlockInfo *mb, DCTELEM *block, int last_index)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
182 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
183 int last_re_index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
184 int shift_offset = mb->shift_offset;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
185 const uint8_t *scan_table = mb->scan_table;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
186 const uint8_t *shift_table = mb->shift_table;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
187 int pos = mb->pos;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
188 int level, pos1, sign, run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
189 int partial_bit_count;
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
190 #ifndef ALT_BITSTREAM_READER //FIXME
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
191 int re_index=0;
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
192 int re1_index=0;
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
193 #endif
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
194 OPEN_READER(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
195
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
196 #ifdef VLC_DEBUG
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
197 printf("start\n");
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
198 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
199
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
200 /* if we must parse a partial vlc, we do it here */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
201 partial_bit_count = mb->partial_bit_count;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
202 if (partial_bit_count > 0) {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
203 uint8_t buf[4];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
204 uint32_t v;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
205 int l, l1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
206 GetBitContext gb1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
207
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
208 /* build the dummy bit buffer */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
209 l = 16 - partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
210 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
211 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
212 printf("show=%04x\n", SHOW_UBITS(re, &s->gb, 16));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
213 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
214 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
215 buf[0] = v >> 8;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
216 buf[1] = v;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
217 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
218 printf("v=%04x cnt=%d %04x\n",
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
219 v, partial_bit_count, (mb->partial_bit_buffer << l));
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
220 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
221 /* 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
222 init_get_bits(&gb1, buf, 4*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
223 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
224 OPEN_READER(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
225 UPDATE_CACHE(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
226 GET_RL_VLC(level, run, re1, &gb1, dv_rl_vlc[0],
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
227 TEX_VLC_BITS, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
228 l = re1_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
229 CLOSE_READER(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
230 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
231 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
232 printf("****run=%d level=%d size=%d\n", run, level, l);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
233 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
234 /* compute codeword length */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
235 l1 = (level != 256 && level != 0);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
236 /* if too long, we cannot parse */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
237 l -= partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
238 if ((re_index + l + l1) > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
239 return;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
240 /* skip read bits */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
241 last_re_index = 0; /* avoid warning */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
242 re_index += l;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
243 /* by definition, if we can read the vlc, all partial bits
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
244 will be read (otherwise we could have read the vlc before) */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
245 mb->partial_bit_count = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
246 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
247 goto handle_vlc;
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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
250 /* get the AC coefficients until last_index is reached */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
251 for(;;) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
252 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
253 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
254 printf("%2d: bits=%04x index=%d\n",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
255 pos, SHOW_UBITS(re, &s->gb, 16), re_index);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
256 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
257 last_re_index = re_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
258 GET_RL_VLC(level, run, re, &s->gb, dv_rl_vlc[0],
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
259 TEX_VLC_BITS, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
260 handle_vlc:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
261 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
262 printf("run=%d level=%d\n", run, level);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
263 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
264 if (level == 256) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
265 if (re_index > last_index) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
266 cannot_read:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
267 /* put position before read code */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
268 re_index = last_re_index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
269 mb->eob_reached = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
270 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
271 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
272 /* EOB */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
273 mb->eob_reached = 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
274 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
275 } else if (level != 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
276 if ((re_index + 1) > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
277 goto cannot_read;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
278 sign = SHOW_SBITS(re, &s->gb, 1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
279 level = (level ^ sign) - sign;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
280 LAST_SKIP_BITS(re, &s->gb, 1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
281 pos += run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
282 /* error */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
283 if (pos >= 64) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
284 goto read_error;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
285 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
286 pos1 = scan_table[pos];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
287 level = level << (shift_table[pos1] + shift_offset);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
288 block[pos1] = level;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
289 // 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
290 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
291 if (re_index > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
292 goto cannot_read;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
293 /* level is zero: means run without coding. No
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
294 sign is coded */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
295 pos += run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
296 /* error */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
297 if (pos >= 64) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
298 read_error:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
299 #if defined(VLC_DEBUG) || 1
1598
932d306bf1dc av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1567
diff changeset
300 av_log(NULL, AV_LOG_ERROR, "error pos=%d\n", pos);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
301 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
302 /* for errors, we consider the eob is reached */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
303 mb->eob_reached = 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
304 break;
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 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
308 CLOSE_READER(re, &s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
309 mb->pos = pos;
723
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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
312 static inline void bit_copy(PutBitContext *pb, GetBitContext *gb, int bits_left)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
313 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
314 while (bits_left >= 16) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
315 put_bits(pb, 16, get_bits(gb, 16));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
316 bits_left -= 16;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
317 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
318 if (bits_left > 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
319 put_bits(pb, bits_left, get_bits(gb, bits_left));
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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
323 /* mb_x and mb_y are in units of 8 pixels */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
324 static inline void dv_decode_video_segment(DVVideoDecodeContext *s,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
325 uint8_t *buf_ptr1,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
326 const uint16_t *mb_pos_ptr)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
327 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
328 int quant, dc, dct_mode, class1, j;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
329 int mb_index, mb_x, mb_y, v, last_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
330 DCTELEM *block, *block1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
331 int c_offset, bits_left;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
332 uint8_t *y_ptr;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
333 BlockInfo mb_data[5 * 6], *mb, *mb1;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
334 void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block);
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
335 uint8_t *buf_ptr;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
336 PutBitContext pb, vs_pb;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
337 uint8_t mb_bit_buffer[80 + 4]; /* allow some slack */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
338 int mb_bit_count;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
339 uint8_t vs_bit_buffer[5 * 80 + 4]; /* allow some slack */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
340 int vs_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
341
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
342 memset(s->block, 0, sizeof(s->block));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
343
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
344 /* pass 1 : read DC and AC coefficients in blocks */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
345 buf_ptr = buf_ptr1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
346 block1 = &s->block[0][0];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
347 mb1 = mb_data;
1522
79dddc5cd990 removed the obsolete and unused parameters of init_put_bits
alex
parents: 1507
diff changeset
348 init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
349 vs_bit_count = 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
350 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
351 /* skip header */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
352 quant = buf_ptr[3] & 0x0f;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
353 buf_ptr += 4;
1522
79dddc5cd990 removed the obsolete and unused parameters of init_put_bits
alex
parents: 1507
diff changeset
354 init_put_bits(&pb, mb_bit_buffer, 80);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
355 mb_bit_count = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
356 mb = mb1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
357 block = block1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
358 for(j = 0;j < 6; j++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
359 /* 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
360 init_get_bits(&s->gb, buf_ptr, 14*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
361
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
362 /* get the dc */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
363 dc = get_bits(&s->gb, 9);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
364 dc = (dc << (32 - 9)) >> (32 - 9);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
365 dct_mode = get_bits1(&s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
366 mb->dct_mode = dct_mode;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
367 mb->scan_table = s->dv_zigzag[dct_mode];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
368 class1 = get_bits(&s->gb, 2);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
369 mb->shift_offset = (class1 == 3);
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
370 mb->shift_table = s->dv_idct_shift[dct_mode]
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
371 [quant + dv_quant_offset[class1]];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
372 dc = dc << 2;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
373 /* convert to unsigned because 128 is not added in the
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
374 standard IDCT */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
375 dc += 1024;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
376 block[0] = dc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
377 last_index = block_sizes[j];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
378 buf_ptr += last_index >> 3;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
379 mb->pos = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
380 mb->partial_bit_count = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
381
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
382 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
383 printf("MB block: %d, %d ", mb_index, j);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
384 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
385 dv_decode_ac(s, mb, block, last_index);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
386
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
387 /* write the remaining bits in a new buffer only if the
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
388 block is finished */
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
389 bits_left = last_index - get_bits_count(&s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
390 if (mb->eob_reached) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
391 mb->partial_bit_count = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
392 mb_bit_count += bits_left;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
393 bit_copy(&pb, &s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
394 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
395 /* should be < 16 bits otherwise a codeword could have
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
396 been parsed */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
397 mb->partial_bit_count = bits_left;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
398 mb->partial_bit_buffer = get_bits(&s->gb, bits_left);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
399 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
400 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
401 mb++;
723
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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
404 flush_put_bits(&pb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
405
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
406 /* pass 2 : we can do it just after */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
407 #ifdef VLC_DEBUG
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
408 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
409 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
410 block = block1;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
411 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
412 init_get_bits(&s->gb, mb_bit_buffer, 80*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
413 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
414 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
415 dv_decode_ac(s, mb, block, mb_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
416 /* if still not finished, no need to parse other blocks */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
417 if (!mb->eob_reached) {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
418 /* we could not parse the current AC coefficient,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
419 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
420 bits_left = mb_bit_count - get_bits_count(&s->gb);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
421 if (bits_left > 0) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
422 mb->partial_bit_count += bits_left;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
423 mb->partial_bit_buffer =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
424 (mb->partial_bit_buffer << bits_left) |
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
425 get_bits(&s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
426 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
427 goto next_mb;
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 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
430 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
431 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
432 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
433 /* all blocks are finished, so the extra bytes can be used at
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
434 the video segment level */
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
435 bits_left = mb_bit_count - get_bits_count(&s->gb);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
436 vs_bit_count += bits_left;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
437 bit_copy(&vs_pb, &s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
438 next_mb:
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
439 mb1 += 6;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
440 block1 += 6 * 64;
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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
443 /* we need a pass other the whole video segment */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
444 flush_put_bits(&vs_pb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
445
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
446 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
447 printf("***pass 3 size=%d\n", vs_bit_count);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
448 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
449 block = &s->block[0][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
450 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
451 init_get_bits(&s->gb, vs_bit_buffer, 5 * 80*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
452 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
453 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
454 if (!mb->eob_reached) {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
455 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
456 printf("start %d:%d\n", mb_index, j);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
457 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
458 dv_decode_ac(s, mb, block, vs_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
459 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
460 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
461 mb++;
723
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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
465 /* compute idct and place blocks */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
466 block = &s->block[0][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
467 mb = mb_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
468 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
469 v = *mb_pos_ptr++;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
470 mb_x = v & 0xff;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
471 mb_y = v >> 8;
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
472 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
473 if (s->sys->pix_fmt == PIX_FMT_YUV411P)
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
474 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
475 else
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
476 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
477 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
478 idct_put = s->idct_put[mb->dct_mode];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
479 if (j < 4) {
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
480 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
481 /* 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
482 idct_put(y_ptr + (j * 8), s->picture.linesize[0], block);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
483 } else {
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
484 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
485 s->picture.linesize[0], block);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
486 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
487 } else {
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
488 if (s->sys->pix_fmt == PIX_FMT_YUV411P && mb_x >= (704 / 8)) {
1540
a0086452b9d8 * fix for a trivial 100l declaration typo
romansh
parents: 1537
diff changeset
489 uint64_t aligned_pixels[64/8];
1537
michael
parents: 1522
diff changeset
490 uint8_t *pixels= (uint8_t*)aligned_pixels;
1540
a0086452b9d8 * fix for a trivial 100l declaration typo
romansh
parents: 1537
diff changeset
491 uint8_t *c_ptr, *c_ptr1, *ptr;
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
492 int y, linesize;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
493 /* NOTE: at end of line, the macroblock is handled as 420 */
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
494 idct_put(pixels, 8, block);
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
495 linesize = s->picture.linesize[6 - j];
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
496 c_ptr = s->picture.data[6 - j] + c_offset;
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
497 ptr = pixels;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
498 for(y = 0;y < 8; y++) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
499 /* convert to 411P */
1270
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
500 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
501 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
502 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
503 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
504 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
505 c_ptr += linesize;
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
506 ptr += 8;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
507 }
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
508 } else {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
509 /* 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
510 idct_put(s->picture.data[6 - j] + c_offset,
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
511 s->picture.linesize[6 - j], block);
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
512 }
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 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
515 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
516 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
517 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
518 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
519
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
520 /* 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
521 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
522 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
523 int sign = l >> 8;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
524 int level = (l ^ sign) - sign;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
525 int size;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
526
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
527 sign = (sign & 1);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
528
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
529 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
530 *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
531 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
532 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
533 else {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
534 if (level < 23) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
535 *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
536 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
537 } else {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
538 *vlc = 0xfe00 | (level << 1) | sign;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
539 size = 16;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
540 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
541
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
542 switch(run) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
543 case 0:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
544 break;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
545 case 1:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
546 case 2:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
547 *vlc |= ((0x7ce | (run - 1)) << size);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
548 size += 11;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
549 break;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
550 case 3:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
551 case 4:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
552 case 5:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
553 case 6:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
554 *vlc |= ((0xfac | (run - 3)) << size);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
555 size += 12;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
556 break;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
557 default:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
558 *vlc |= ((0x1f80 | (run - 1)) << size);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
559 size += 13;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
560 break;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
561 }
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 return size;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
565 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
566
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
567 typedef struct EncBlockInfo {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
568 int qno;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
569 int cno;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
570 int dct_mode;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
571 int block_size;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
572 DCTELEM *mb;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
573 PutBitContext pb;
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
574 const uint8_t* zigzag_scan;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
575 uint8_t *dv_shift;
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
576 } EncBlockInfo;
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 int dv_bits_left(EncBlockInfo* bi)
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 return (bi->block_size - get_bit_count(&bi->pb));
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
581 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
582
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
583 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
584 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
585 int i, level, size, run = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
586 uint32_t vlc;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
587 PutBitContext* cpb = &bi->pb;
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
588 int bias = (bi->cno == 3);
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
589
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
590 for (i=1; i<64; i++) {
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
591 level = bi->mb[bi->zigzag_scan[i]] / (1<<(bi->dv_shift[i] + bias));
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
592 if (level != 0) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
593 size = dv_rl2vlc(run, level, &vlc);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
594 put_vlc:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
595
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
596 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
597 printf(" %3d:%3d", run, level);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
598 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
599 if (cpb == &bi->pb && size > dv_bits_left(bi)) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
600 size -= dv_bits_left(bi);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
601 put_bits(cpb, dv_bits_left(bi), vlc >> size);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
602 vlc = vlc & ((1<<size)-1);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
603 cpb = heap;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
604 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
605 put_bits(cpb, size, vlc);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
606 run = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
607 } else
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
608 run++;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
609 }
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 if (i == 64) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
612 size = 4; vlc = 6; /* End Of Block stamp */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
613 goto put_vlc;
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 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
616
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
617 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
618 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
619 int i;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
620 GetBitContext gb;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
621
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
622 init_get_bits(&gb, extra_data, extra_bits);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
623
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
624 for (i=0; i<count; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
625 int bits_left = dv_bits_left(bi);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
626 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
627 if (bits_left)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
628 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
629 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
630 if (bits_left > extra_bits) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
631 bit_copy(&bi->pb, &gb, extra_bits);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
632 extra_bits = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
633 break;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
634 } else
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
635 bit_copy(&bi->pb, &gb, bits_left);
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 extra_bits -= bits_left;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
638 bi++;
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 if (extra_bits > 0 && heap)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
642 bit_copy(heap, &gb, extra_bits);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
643 }
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 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
646 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
647 int i, max_ac = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
648
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
649 for (i=1; i<64; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
650 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
651 if (max_ac < ac)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
652 max_ac = ac;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
653 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
654 if (max_ac < 12)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
655 bi->cno = j;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
656 else if (max_ac < 24)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
657 bi->cno = j + 1;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
658 else if (max_ac < 36)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
659 bi->cno = j + 2;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
660 else
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
661 bi->cno = j + 3;
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 if (bi->cno > 3)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
664 bi->cno = 3;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
665 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
666
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
667 #define SQ(a) ((a)*(a))
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
668 static int dv_score_lines(DCTELEM *s, int stride) {
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
669 int score=0;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
670 int x, y;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
671
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
672 for(y=0; y<4; y++) {
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
673 for(x=0; x<8; x+=4){
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
674 score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride])
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
675 +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]);
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
676 }
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
677 s+= stride;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
678 }
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
679
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
680 return score;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
681 }
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
682
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
683 /*
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
684 * This is a very rough initial implementaion. The performance is
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
685 * horrible and the weighting is missing. But it's missing from the
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
686 * decoding step also -- so at least we're on the same page with decoder ;-)
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
687 */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
688 static inline void dv_encode_video_segment(DVVideoDecodeContext *s,
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
689 uint8_t *dif,
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
690 const uint16_t *mb_pos_ptr)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
691 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
692 int mb_index, i, j, v;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
693 int mb_x, mb_y, c_offset, linesize;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
694 uint8_t* y_ptr;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
695 uint8_t* data;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
696 int do_edge_wrap;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
697 DCTELEM *block;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
698 EncBlockInfo enc_blks[5*6];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
699 EncBlockInfo* enc_blk;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
700 int free_vs_bits;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
701 int extra_bits;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
702 PutBitContext extra_vs;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
703 uint8_t extra_vs_data[5*6*128];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
704 uint8_t extra_mb_data[6*128];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
705
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
706 int QNO = 15;
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 /* Stage 1 -- doing DCT on 5 MBs */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
709 block = &s->block[0][0];
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
710 enc_blk = &enc_blks[0];
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
711 for(mb_index = 0; mb_index < 5; mb_index++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
712 v = *mb_pos_ptr++;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
713 mb_x = v & 0xff;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
714 mb_y = v >> 8;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
715 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
716 c_offset = (s->sys->pix_fmt == PIX_FMT_YUV411P) ?
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
717 ((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
718 (((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
719 do_edge_wrap = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
720 for(j = 0;j < 6; j++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
721 if (j < 4) { /* Four Y blocks */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
722 /* 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
723 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
724 data = y_ptr + (j * 8);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
725 } else {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
726 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
727 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
728 linesize = s->picture.linesize[0];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
729 } else { /* Cr and Cb blocks */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
730 /* 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
731 data = s->picture.data[6 - j] + c_offset;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
732 linesize = s->picture.linesize[6 - j];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
733 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
734 do_edge_wrap = 1;
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 /* 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
738 if (do_edge_wrap) { /* Edge wrap copy: 4x16 -> 8x8 */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
739 uint8_t* d;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
740 DCTELEM *b = block;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
741 for (i=0;i<8;i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
742 d = data + 8 * linesize;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
743 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
744 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
745 data += linesize;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
746 b += 8;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
747 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
748 } else { /* Simple copy: 8x8 -> 8x8 */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
749 s->get_pixels(block, data, linesize);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
750 }
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
751
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
752 if (dv_score_lines(block, 8) + dv_score_lines(block+8*4, 8) - 100 >
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
753 dv_score_lines(block, 16) + dv_score_lines(block+8, 16)) {
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
754 enc_blk->dct_mode = 1;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
755 enc_blk->zigzag_scan = ff_zigzag248_direct;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
756 } else {
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
757 enc_blk->dct_mode = 0;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
758 enc_blk->zigzag_scan = ff_zigzag_direct;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
759 }
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
760 enc_blk->mb = block;
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
761 enc_blk->block_size = block_sizes[j];
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
762
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
763 s->fdct[enc_blk->dct_mode](block);
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
764
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
765 dv_set_class_number(enc_blk, j/4*(j%2));
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
766
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
767 block += 64;
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
768 enc_blk++;
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
769 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
770 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
771
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
772 /* Stage 2 -- encoding by trial-and-error */
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
773 encode_vs:
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
774 enc_blk = &enc_blks[0];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
775 for (i=0; i<5; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
776 uint8_t* p = dif + i*80 + 4;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
777 for (j=0; j<6; j++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
778 enc_blk->qno = QNO;
1567
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
779 enc_blk->dv_shift = &(s->dv_dct_shift[0]
e08df4d22d27 * introducing dct248 into the DSP context.
romansh
parents: 1547
diff changeset
780 [QNO + dv_quant_offset[enc_blk->cno]][0]);
1522
79dddc5cd990 removed the obsolete and unused parameters of init_put_bits
alex
parents: 1507
diff changeset
781 init_put_bits(&enc_blk->pb, p, block_sizes[j]/8);
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
782 enc_blk++;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
783 p += block_sizes[j]/8;
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 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
786
1522
79dddc5cd990 removed the obsolete and unused parameters of init_put_bits
alex
parents: 1507
diff changeset
787 init_put_bits(&extra_vs, extra_vs_data, sizeof(extra_vs_data));
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
788 free_vs_bits = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
789 enc_blk = &enc_blks[0];
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
790 for (i=0; i<5; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
791 PutBitContext extra_mb;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
792 EncBlockInfo* enc_blk2 = enc_blk;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
793 int free_mb_bits = 0;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
794
1522
79dddc5cd990 removed the obsolete and unused parameters of init_put_bits
alex
parents: 1507
diff changeset
795 init_put_bits(&extra_mb, extra_mb_data, sizeof(extra_mb_data));
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
796 dif[i*80 + 3] = enc_blk->qno;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
797
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
798 for (j=0; j<6; j++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
799 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
800
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
801 put_bits(&enc_blk->pb, 9, dc);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
802 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
803 put_bits(&enc_blk->pb, 2, enc_blk->cno);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
804
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
805 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
806 printf("[%d, %d]: ", i, j);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
807 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
808 dv_encode_ac(enc_blk, &extra_mb);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
809 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
810 printf("\n");
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
811 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
812
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
813 free_mb_bits += dv_bits_left(enc_blk);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
814 enc_blk++;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
815 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
816
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
817 /* 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
818 extra_bits = get_bit_count(&extra_mb);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
819 if (free_mb_bits > extra_bits)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
820 free_vs_bits += free_mb_bits - extra_bits;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
821
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
822 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
823 flush_put_bits(&extra_mb);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
824 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
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
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
828 /* 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
829 extra_bits = get_bit_count(&extra_vs);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
830 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
831 QNO--;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
832 goto encode_vs;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
833 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
834
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
835 if (extra_bits) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
836 flush_put_bits(&extra_vs);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
837 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
838 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
839
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
840 for (i=0; i<6*5; i++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
841 flush_put_bits(&enc_blks[i].pb);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
842 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
843 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
844 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
845 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
846 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
847
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
848 /* NOTE: exactly one frame must be given (120000 bytes for NTSC,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
849 144000 bytes for PAL) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
850 static int dvvideo_decode_frame(AVCodecContext *avctx,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
851 void *data, int *data_size,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
852 uint8_t *buf, int buf_size)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
853 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
854 DVVideoDecodeContext *s = avctx->priv_data;
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
855 int ds, vs;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
856 const uint16_t *mb_pos_ptr;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
857
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
858 s->sys = dv_frame_profile(buf);
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
859 if (!s->sys || buf_size < s->sys->frame_size)
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
860 return -1; /* NOTE: we only accept several full frames */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
861
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
862
1228
d63e0185a90f release buffer cleanup
michaelni
parents: 1222
diff changeset
863 if(s->picture.data[0])
d63e0185a90f release buffer cleanup
michaelni
parents: 1222
diff changeset
864 avctx->release_buffer(avctx, &s->picture);
d63e0185a90f release buffer cleanup
michaelni
parents: 1222
diff changeset
865
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
866 s->picture.reference = 0;
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
867 avctx->pix_fmt = s->sys->pix_fmt;
1507
f4cf270b98ae * recommiting change from SF CVS
romansh
parents: 1493
diff changeset
868 avctx->width = s->sys->width;
f4cf270b98ae * recommiting change from SF CVS
romansh
parents: 1493
diff changeset
869 avctx->height = s->sys->height;
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
870 if(avctx->get_buffer(avctx, &s->picture) < 0) {
1598
932d306bf1dc av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1567
diff changeset
871 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
872 return -1;
835
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
873 }
1543
7542cb99b950 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 1540
diff changeset
874 s->picture.interlaced_frame = 1;
1547
0183874861fd bottom_field_first -> top_field_first
michael
parents: 1543
diff changeset
875 s->picture.top_field_first = 0;
835
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
876
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
877 /* for each DIF segment */
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
878 mb_pos_ptr = s->sys->video_place;
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
879 for (ds = 0; ds < s->sys->difseg_size; ds++) {
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
880 buf += 6 * 80; /* skip DIF segment header */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
881
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
882 for(vs = 0; vs < 27; vs++) {
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
883 if ((vs % 3) == 0)
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
884 buf += 80; /* skip audio block */
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
885
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
886 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
887 printf("********************* %d, %d **********************\n", ds, vs);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
888 #endif
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
889 dv_decode_video_segment(s, buf, mb_pos_ptr);
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
890 buf += 5 * 80;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
891 mb_pos_ptr += 5;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
892 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
893 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
894
734
2d6b3e3d6c6f 10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents: 733
diff changeset
895 emms_c();
2d6b3e3d6c6f 10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents: 733
diff changeset
896
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
897 /* return image */
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
898 *data_size = sizeof(AVFrame);
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
899 *(AVFrame*)data= s->picture;
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
900
1489
337d13aee605 * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 1416
diff changeset
901 return s->sys->frame_size;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
902 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
903
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
904 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
905 void *data)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
906 {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
907 DVVideoDecodeContext *s = c->priv_data;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
908 const uint16_t *mb_pos_ptr;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
909 int ds, vs;
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 s->sys = dv_codec_profile(c);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
912 if (!s->sys)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
913 return -1;
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 c->pix_fmt = s->sys->pix_fmt;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
916 s->picture = *((AVFrame *)data);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
917
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
918 /* for each DIF segment */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
919 mb_pos_ptr = s->sys->video_place;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
920 for (ds = 0; ds < s->sys->difseg_size; ds++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
921 buf += 6 * 80; /* skip DIF segment header */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
922
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
923 for(vs = 0; vs < 27; vs++) {
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
924 if ((vs % 3) == 0)
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
925 buf += 80; /* skip audio block */
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
926
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
927 #ifdef VLC_DEBUG
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
928 printf("********************* %d, %d **********************\n", ds, vs);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
929 #endif
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
930 dv_encode_video_segment(s, buf, mb_pos_ptr);
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
931 buf += 5 * 80;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
932 mb_pos_ptr += 5;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
933 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
934 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
935
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
936 emms_c();
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
937 return s->sys->frame_size;
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
938 }
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
939
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
940 static int dvvideo_end(AVCodecContext *avctx)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
941 {
1214
327c5a36dfe7 fixing mixed dr1 + internal buffers
michaelni
parents: 1167
diff changeset
942 avcodec_default_free_buffers(avctx);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
943 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
944 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
945
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
946 AVCodec dvvideo_decoder = {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
947 "dvvideo",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
948 CODEC_TYPE_VIDEO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
949 CODEC_ID_DVVIDEO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
950 sizeof(DVVideoDecodeContext),
1493
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
951 dvvideo_init,
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
952 dvvideo_encode_frame,
ad7e62df9962 * preAlpha DV encoding support -- there's still a truckload
romansh
parents: 1489
diff changeset
953 dvvideo_end,
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
954 dvvideo_decode_frame,
835
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
955 CODEC_CAP_DR1,
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
956 NULL
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
957 };