annotate dv.c @ 1186:4f0072371bb9 libavcodec

10l (hadamard fix)
author michaelni
date Mon, 14 Apr 2003 09:58:16 +0000
parents 35b80080b2db
children 327c5a36dfe7
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 *
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
9 *
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
14 *
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
18 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
19
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
20 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
21 * @file dv.c
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
22 * DV decoder.
1e39f273ecd6 per file doxy
michaelni
parents: 1092
diff changeset
23 */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
24 #include "avcodec.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
25 #include "dsputil.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
26 #include "mpegvideo.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
27 #include "simple_idct.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
28
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
29 #define NTSC_FRAME_SIZE 120000
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
30 #define PAL_FRAME_SIZE 144000
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
31
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
32 #define TEX_VLC_BITS 9
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
33
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
34 typedef struct DVVideoDecodeContext {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
35 AVCodecContext *avctx;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
36 GetBitContext gb;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
37 VLC *vlc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
38 int sampling_411; /* 0 = 420, 1 = 411 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
39 int width, height;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
40 uint8_t *current_picture[3]; /* picture structure */
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
41 AVFrame picture;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
42 int linesize[3];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
43 DCTELEM block[5*6][64] __align8;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
44 uint8_t dv_zigzag[2][64];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
45 uint8_t idct_permutation[64];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
46 /* XXX: move it to static storage ? */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
47 uint8_t dv_shift[2][22][64];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
48 void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
49 } DVVideoDecodeContext;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
50
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
51 #include "dvdata.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
52
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
53 static VLC dv_vlc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
54 /* XXX: also include quantization */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
55 static RL_VLC_ELEM *dv_rl_vlc[1];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
56
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
57 static void dv_build_unquantize_tables(DVVideoDecodeContext *s)
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++) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
63 /* 88 unquant */
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 */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
66 j = s->idct_permutation[i];
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
67 s->dv_shift[0][q][j] =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
68 dv_quant_shifts[q][dv_88_areas[i]] + 1;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
69 }
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
70
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
71 /* 248 unquant */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
72 for(i = 1; i < 64; i++) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
73 /* 248 table */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
74 s->dv_shift[1][q][i] =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
75 dv_quant_shifts[q][dv_248_areas[i]] + 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
76 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
77 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
78 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
79
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
80 static int dvvideo_decode_init(AVCodecContext *avctx)
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 DVVideoDecodeContext *s = avctx->priv_data;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
83 MpegEncContext s2;
1070
6da5ae9ee199 more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents: 1064
diff changeset
84 static int done=0;
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 if (!done) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
87 int i;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
88
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
89 done = 1;
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 /* 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
92 to accelerate the parsing of partial codes */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
93 init_vlc(&dv_vlc, TEX_VLC_BITS, NB_DV_VLC,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
94 dv_vlc_len, 1, 1, dv_vlc_bits, 2, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
95
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
96 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
97 for(i = 0; i < dv_vlc.table_size; i++){
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
98 int code= dv_vlc.table[i][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
99 int len = dv_vlc.table[i][1];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
100 int level, run;
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 if(len<0){ //more bits needed
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
103 run= 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
104 level= code;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
105 } else if (code == (NB_DV_VLC - 1)) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
106 /* EOB */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
107 run = 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
108 level = 256;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
109 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
110 run= dv_vlc_run[code] + 1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
111 level= dv_vlc_level[code];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
112 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
113 dv_rl_vlc[0][i].len = len;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
114 dv_rl_vlc[0][i].level = level;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
115 dv_rl_vlc[0][i].run = run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
116 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
117 }
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
118
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
119 /* ugly way to get the idct & scantable */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
120 /* XXX: fix it */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
121 memset(&s2, 0, sizeof(MpegEncContext));
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
122 s2.avctx = avctx;
1092
f59c3f66363b MpegEncContext.(i)dct_* -> DspContext.(i)dct_*
michaelni
parents: 1087
diff changeset
123 dsputil_init(&s2.dsp, avctx);
726
a91203b34e71 moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents: 725
diff changeset
124 if (DCT_common_init(&s2) < 0)
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
125 return -1;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
126
1092
f59c3f66363b MpegEncContext.(i)dct_* -> DspContext.(i)dct_*
michaelni
parents: 1087
diff changeset
127 s->idct_put[0] = s2.dsp.idct_put;
f59c3f66363b MpegEncContext.(i)dct_* -> DspContext.(i)dct_*
michaelni
parents: 1087
diff changeset
128 memcpy(s->idct_permutation, s2.dsp.idct_permutation, 64);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
129 memcpy(s->dv_zigzag[0], s2.intra_scantable.permutated, 64);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
130
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
131 /* XXX: use MMX also for idct248 */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
132 s->idct_put[1] = simple_idct248_put;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
133 memcpy(s->dv_zigzag[1], dv_248_zigzag, 64);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
134
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
135 /* XXX: do it only for constant case */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
136 dv_build_unquantize_tables(s);
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
137
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
138 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
139 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
140
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
141 //#define VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
142
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
143 typedef struct BlockInfo {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
144 const uint8_t *shift_table;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
145 const uint8_t *scan_table;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
146 uint8_t pos; /* position in block */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
147 uint8_t eob_reached; /* true if EOB has been reached */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
148 uint8_t dct_mode;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
149 uint8_t partial_bit_count;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
150 uint16_t partial_bit_buffer;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
151 int shift_offset;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
152 } BlockInfo;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
153
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
154 /* block size in bits */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
155 static const uint16_t block_sizes[6] = {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
156 112, 112, 112, 112, 80, 80
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
157 };
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
158
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
159 #ifndef ALT_BITSTREAM_READER
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
160 #error only works with ALT_BITSTREAM_READER
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
161 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
162
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
163 /* decode ac coefs */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
164 static void dv_decode_ac(DVVideoDecodeContext *s,
1008
fb6cbb8a04a3 fixing DCTELEM != short
michaelni
parents: 949
diff changeset
165 BlockInfo *mb, DCTELEM *block, int last_index)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
166 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
167 int last_re_index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
168 int shift_offset = mb->shift_offset;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
169 const uint8_t *scan_table = mb->scan_table;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
170 const uint8_t *shift_table = mb->shift_table;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
171 int pos = mb->pos;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
172 int level, pos1, sign, run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
173 int partial_bit_count;
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 OPEN_READER(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
176
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
177 #ifdef VLC_DEBUG
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
178 printf("start\n");
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
179 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
180
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
181 /* if we must parse a partial vlc, we do it here */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
182 partial_bit_count = mb->partial_bit_count;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
183 if (partial_bit_count > 0) {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
184 uint8_t buf[4];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
185 uint32_t v;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
186 int l, l1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
187 GetBitContext gb1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
188
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
189 /* build the dummy bit buffer */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
190 l = 16 - partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
191 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
192 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
193 printf("show=%04x\n", SHOW_UBITS(re, &s->gb, 16));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
194 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
195 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
196 buf[0] = v >> 8;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
197 buf[1] = v;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
198 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
199 printf("v=%04x cnt=%d %04x\n",
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
200 v, partial_bit_count, (mb->partial_bit_buffer << l));
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
201 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
202 /* 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
203 init_get_bits(&gb1, buf, 4*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
204 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
205 OPEN_READER(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
206 UPDATE_CACHE(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
207 GET_RL_VLC(level, run, re1, &gb1, dv_rl_vlc[0],
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
208 TEX_VLC_BITS, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
209 l = re1_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
210 CLOSE_READER(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
211 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
212 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
213 printf("****run=%d level=%d size=%d\n", run, level, l);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
214 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
215 /* compute codeword length */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
216 l1 = (level != 256 && level != 0);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
217 /* if too long, we cannot parse */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
218 l -= partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
219 if ((re_index + l + l1) > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
220 return;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
221 /* skip read bits */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
222 last_re_index = 0; /* avoid warning */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
223 re_index += l;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
224 /* by definition, if we can read the vlc, all partial bits
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
225 will be read (otherwise we could have read the vlc before) */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
226 mb->partial_bit_count = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
227 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
228 goto handle_vlc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
229 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
230
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
231 /* get the AC coefficients until last_index is reached */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
232 for(;;) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
233 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
234 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
235 printf("%2d: bits=%04x index=%d\n",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
236 pos, SHOW_UBITS(re, &s->gb, 16), re_index);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
237 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
238 last_re_index = re_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
239 GET_RL_VLC(level, run, re, &s->gb, dv_rl_vlc[0],
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
240 TEX_VLC_BITS, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
241 handle_vlc:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
242 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
243 printf("run=%d level=%d\n", run, level);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
244 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
245 if (level == 256) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
246 if (re_index > last_index) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
247 cannot_read:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
248 /* put position before read code */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
249 re_index = last_re_index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
250 mb->eob_reached = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
251 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
252 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
253 /* EOB */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
254 mb->eob_reached = 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
255 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
256 } else if (level != 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
257 if ((re_index + 1) > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
258 goto cannot_read;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
259 sign = SHOW_SBITS(re, &s->gb, 1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
260 level = (level ^ sign) - sign;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
261 LAST_SKIP_BITS(re, &s->gb, 1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
262 pos += run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
263 /* error */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
264 if (pos >= 64) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
265 goto read_error;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
266 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
267 pos1 = scan_table[pos];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
268 level = level << (shift_table[pos1] + shift_offset);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
269 block[pos1] = level;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
270 // 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
271 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
272 if (re_index > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
273 goto cannot_read;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
274 /* level is zero: means run without coding. No
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
275 sign is coded */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
276 pos += run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
277 /* error */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
278 if (pos >= 64) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
279 read_error:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
280 #if defined(VLC_DEBUG) || 1
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
281 printf("error pos=%d\n", pos);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
282 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
283 /* for errors, we consider the eob is reached */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
284 mb->eob_reached = 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
285 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
286 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
287 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
288 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
289 CLOSE_READER(re, &s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
290 mb->pos = pos;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
291 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
292
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
293 static inline void bit_copy(PutBitContext *pb, GetBitContext *gb, int bits_left)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
294 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
295 while (bits_left >= 16) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
296 put_bits(pb, 16, get_bits(gb, 16));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
297 bits_left -= 16;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
298 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
299 if (bits_left > 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
300 put_bits(pb, bits_left, get_bits(gb, bits_left));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
301 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
302 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
303
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
304 /* mb_x and mb_y are in units of 8 pixels */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
305 static inline void dv_decode_video_segment(DVVideoDecodeContext *s,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
306 uint8_t *buf_ptr1,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
307 const uint16_t *mb_pos_ptr)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
308 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
309 int quant, dc, dct_mode, class1, j;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
310 int mb_index, mb_x, mb_y, v, last_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
311 DCTELEM *block, *block1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
312 int c_offset, bits_left;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
313 uint8_t *y_ptr;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
314 BlockInfo mb_data[5 * 6], *mb, *mb1;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
315 void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block);
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
316 uint8_t *buf_ptr;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
317 PutBitContext pb, vs_pb;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
318 uint8_t mb_bit_buffer[80 + 4]; /* allow some slack */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
319 int mb_bit_count;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
320 uint8_t vs_bit_buffer[5 * 80 + 4]; /* allow some slack */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
321 int vs_bit_count;
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 memset(s->block, 0, sizeof(s->block));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
324
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
325 /* pass 1 : read DC and AC coefficients in blocks */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
326 buf_ptr = buf_ptr1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
327 block1 = &s->block[0][0];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
328 mb1 = mb_data;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
329 init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80, NULL, NULL);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
330 vs_bit_count = 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
331 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
332 /* skip header */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
333 quant = buf_ptr[3] & 0x0f;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
334 buf_ptr += 4;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
335 init_put_bits(&pb, mb_bit_buffer, 80, NULL, NULL);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
336 mb_bit_count = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
337 mb = mb1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
338 block = block1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
339 for(j = 0;j < 6; j++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
340 /* 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
341 init_get_bits(&s->gb, buf_ptr, 14*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
342
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
343 /* get the dc */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
344 dc = get_bits(&s->gb, 9);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
345 dc = (dc << (32 - 9)) >> (32 - 9);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
346 dct_mode = get_bits1(&s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
347 mb->dct_mode = dct_mode;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
348 mb->scan_table = s->dv_zigzag[dct_mode];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
349 class1 = get_bits(&s->gb, 2);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
350 mb->shift_offset = (class1 == 3);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
351 mb->shift_table = s->dv_shift[dct_mode]
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
352 [quant + dv_quant_offset[class1]];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
353 dc = dc << 2;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
354 /* convert to unsigned because 128 is not added in the
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
355 standard IDCT */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
356 dc += 1024;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
357 block[0] = dc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
358 last_index = block_sizes[j];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
359 buf_ptr += last_index >> 3;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
360 mb->pos = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
361 mb->partial_bit_count = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
362
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
363 dv_decode_ac(s, mb, block, last_index);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
364
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
365 /* write the remaining bits in a new buffer only if the
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
366 block is finished */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
367 bits_left = last_index - s->gb.index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
368 if (mb->eob_reached) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
369 mb->partial_bit_count = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
370 mb_bit_count += bits_left;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
371 bit_copy(&pb, &s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
372 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
373 /* should be < 16 bits otherwise a codeword could have
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
374 been parsed */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
375 mb->partial_bit_count = bits_left;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
376 mb->partial_bit_buffer = get_bits(&s->gb, bits_left);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
377 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
378 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
379 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
380 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
381
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
382 flush_put_bits(&pb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
383
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
384 /* pass 2 : we can do it just after */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
385 #ifdef VLC_DEBUG
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
386 printf("***pass 2 size=%d\n", mb_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
387 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
388 block = block1;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
389 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
390 init_get_bits(&s->gb, mb_bit_buffer, 80*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
391 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
392 if (!mb->eob_reached && s->gb.index < mb_bit_count) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
393 dv_decode_ac(s, mb, block, mb_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
394 /* if still not finished, no need to parse other blocks */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
395 if (!mb->eob_reached) {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
396 /* we could not parse the current AC coefficient,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
397 so we add the remaining bytes */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
398 bits_left = mb_bit_count - s->gb.index;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
399 if (bits_left > 0) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
400 mb->partial_bit_count += bits_left;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
401 mb->partial_bit_buffer =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
402 (mb->partial_bit_buffer << bits_left) |
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
403 get_bits(&s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
404 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
405 goto next_mb;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
406 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
407 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
408 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
409 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
410 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
411 /* all blocks are finished, so the extra bytes can be used at
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
412 the video segment level */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
413 bits_left = mb_bit_count - s->gb.index;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
414 vs_bit_count += bits_left;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
415 bit_copy(&vs_pb, &s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
416 next_mb:
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
417 mb1 += 6;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
418 block1 += 6 * 64;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
419 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
420
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
421 /* we need a pass other the whole video segment */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
422 flush_put_bits(&vs_pb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
423
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
424 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
425 printf("***pass 3 size=%d\n", vs_bit_count);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
426 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
427 block = &s->block[0][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
428 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
429 init_get_bits(&s->gb, vs_bit_buffer, 5 * 80*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
430 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
431 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
432 if (!mb->eob_reached) {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
433 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
434 printf("start %d:%d\n", mb_index, j);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
435 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
436 dv_decode_ac(s, mb, block, vs_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
437 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
438 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
439 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
440 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
441 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
442
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
443 /* compute idct and place blocks */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
444 block = &s->block[0][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
445 mb = mb_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
446 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
447 v = *mb_pos_ptr++;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
448 mb_x = v & 0xff;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
449 mb_y = v >> 8;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
450 y_ptr = s->current_picture[0] + (mb_y * s->linesize[0] * 8) + (mb_x * 8);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
451 if (s->sampling_411)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
452 c_offset = (mb_y * s->linesize[1] * 8) + ((mb_x >> 2) * 8);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
453 else
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
454 c_offset = ((mb_y >> 1) * s->linesize[1] * 8) + ((mb_x >> 1) * 8);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
455 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
456 idct_put = s->idct_put[mb->dct_mode];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
457 if (j < 4) {
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
458 if (s->sampling_411 && mb_x < (704 / 8)) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
459 /* NOTE: at end of line, the macroblock is handled as 420 */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
460 idct_put(y_ptr + (j * 8), s->linesize[0], block);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
461 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
462 idct_put(y_ptr + ((j & 1) * 8) + ((j >> 1) * 8 * s->linesize[0]),
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
463 s->linesize[0], block);
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 } else {
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
466 if (s->sampling_411 && mb_x >= (704 / 8)) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
467 uint8_t pixels[64], *c_ptr, *c_ptr1, *ptr;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
468 int y, linesize;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
469 /* NOTE: at end of line, the macroblock is handled as 420 */
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
470 idct_put(pixels, 8, block);
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
471 linesize = s->linesize[6 - j];
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
472 c_ptr = s->current_picture[6 - j] + c_offset;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
473 ptr = pixels;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
474 for(y = 0;y < 8; y++) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
475 /* convert to 411P */
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
476 c_ptr1 = c_ptr + linesize;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
477 c_ptr1[0] = c_ptr[0] = (ptr[0] + ptr[1]) >> 1;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
478 c_ptr1[1] = c_ptr[1] = (ptr[2] + ptr[3]) >> 1;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
479 c_ptr1[2] = c_ptr[2] = (ptr[4] + ptr[5]) >> 1;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
480 c_ptr1[3] = c_ptr[3] = (ptr[6] + ptr[7]) >> 1;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
481 c_ptr += linesize * 2;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
482 ptr += 8;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
483 }
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
484 } else {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
485 /* don't ask me why they inverted Cb and Cr ! */
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
486 idct_put(s->current_picture[6 - j] + c_offset,
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
487 s->linesize[6 - j], block);
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
488 }
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
489 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
490 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
491 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
492 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
493 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
494 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
495
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
496
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
497 /* NOTE: exactly one frame must be given (120000 bytes for NTSC,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
498 144000 bytes for PAL) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
499 static int dvvideo_decode_frame(AVCodecContext *avctx,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
500 void *data, int *data_size,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
501 uint8_t *buf, int buf_size)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
502 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
503 DVVideoDecodeContext *s = avctx->priv_data;
862
058194d7ade6 * fixing some minor const warnings
kabi
parents: 853
diff changeset
504 int sct, dsf, apt, ds, nb_dif_segs, vs, width, height, i, packet_size;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
505 uint8_t *buf_ptr;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
506 const uint16_t *mb_pos_ptr;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
507
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
508 /* parse id */
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
509 init_get_bits(&s->gb, buf, buf_size*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
510 sct = get_bits(&s->gb, 3);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
511 if (sct != 0)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
512 return -1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
513 skip_bits(&s->gb, 5);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
514 get_bits(&s->gb, 4); /* dsn (sequence number */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
515 get_bits(&s->gb, 1); /* fsc (channel number) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
516 skip_bits(&s->gb, 3);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
517 get_bits(&s->gb, 8); /* dbn (diff block number 0-134) */
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 dsf = get_bits(&s->gb, 1); /* 0 = NTSC 1 = PAL */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
520 if (get_bits(&s->gb, 1) != 0)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
521 return -1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
522 skip_bits(&s->gb, 11);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
523 apt = get_bits(&s->gb, 3); /* apt */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
524
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
525 get_bits(&s->gb, 1); /* tf1 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
526 skip_bits(&s->gb, 4);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
527 get_bits(&s->gb, 3); /* ap1 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
528
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
529 get_bits(&s->gb, 1); /* tf2 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
530 skip_bits(&s->gb, 4);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
531 get_bits(&s->gb, 3); /* ap2 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
532
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
533 get_bits(&s->gb, 1); /* tf3 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
534 skip_bits(&s->gb, 4);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
535 get_bits(&s->gb, 3); /* ap3 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
536
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
537 /* init size */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
538 width = 720;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
539 if (dsf) {
1126
77ccf7fe3bd0 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 1106
diff changeset
540 avctx->frame_rate = 25;
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
541 packet_size = PAL_FRAME_SIZE;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
542 height = 576;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
543 nb_dif_segs = 12;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
544 } else {
1126
77ccf7fe3bd0 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 1106
diff changeset
545 avctx->frame_rate = 30;
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
546 packet_size = NTSC_FRAME_SIZE;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
547 height = 480;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
548 nb_dif_segs = 10;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
549 }
1126
77ccf7fe3bd0 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 1106
diff changeset
550 avctx->frame_rate_base= 1;
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
551 /* NOTE: we only accept several full frames */
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
552 if (buf_size < packet_size)
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
553 return -1;
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
554
1087
7f10d38721ed support for PAL 4:1:1 SMPTE 314M DV streams patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1070
diff changeset
555 /* NTSC[dsf == 0] is always 720x480, 4:1:1
7f10d38721ed support for PAL 4:1:1 SMPTE 314M DV streams patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1070
diff changeset
556 * PAL[dsf == 1] is always 720x576, 4:2:0 for IEC 68134[apt == 0]
7f10d38721ed support for PAL 4:1:1 SMPTE 314M DV streams patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1070
diff changeset
557 * but for the SMPTE 314M[apt == 1] it is 720x576, 4:1:1
7f10d38721ed support for PAL 4:1:1 SMPTE 314M DV streams patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1070
diff changeset
558 */
7f10d38721ed support for PAL 4:1:1 SMPTE 314M DV streams patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1070
diff changeset
559 s->sampling_411 = !dsf || apt;
848
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
560 if (s->sampling_411) {
1087
7f10d38721ed support for PAL 4:1:1 SMPTE 314M DV streams patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1070
diff changeset
561 mb_pos_ptr = dsf ? dv_place_411P : dv_place_411;
848
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
562 avctx->pix_fmt = PIX_FMT_YUV411P;
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
563 } else {
733
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
564 mb_pos_ptr = dv_place_420;
848
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
565 avctx->pix_fmt = PIX_FMT_YUV420P;
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
566 }
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
567
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
568 avctx->width = width;
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
569 avctx->height = height;
1167
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
570
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
571 /* Once again, this is pretty complicated by the fact that the same
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
572 * field is used differently by IEC 68134[apt == 0] and
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
573 * SMPTE 314M[apt == 1].
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
574 */
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
575 if (buf[VAUX_TC61_OFFSET] == 0x61 &&
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
576 ((apt == 0 && (buf[VAUX_TC61_OFFSET + 2] & 0x07) == 0x07) ||
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
577 (apt == 1 && (buf[VAUX_TC61_OFFSET + 2] & 0x07) == 0x02)))
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
578 avctx->aspect_ratio = 16.0 / 9.0;
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
579 else
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
580 avctx->aspect_ratio = 4.0 / 3.0;
733
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
581
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
582 s->picture.reference= 0;
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
583 if(avctx->get_buffer(avctx, &s->picture) < 0) {
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
584 fprintf(stderr, "get_buffer() failed\n");
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
585 return -1;
835
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
586 }
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
587
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
588 for(i=0;i<3;i++) {
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
589 s->current_picture[i] = s->picture.data[i];
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
590 s->linesize[i] = s->picture.linesize[i];
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
591 if (!s->current_picture[i])
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
592 return -1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
593 }
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
594 s->width = width;
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
595 s->height = height;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
596
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
597 /* for each DIF segment */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
598 buf_ptr = buf;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
599 for (ds = 0; ds < nb_dif_segs; ds++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
600 buf_ptr += 6 * 80; /* skip DIF segment header */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
601
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
602 for(vs = 0; vs < 27; vs++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
603 if ((vs % 3) == 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
604 /* skip audio block */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
605 buf_ptr += 80;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
606 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
607 dv_decode_video_segment(s, buf_ptr, mb_pos_ptr);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
608 buf_ptr += 5 * 80;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
609 mb_pos_ptr += 5;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
610 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
611 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
612
734
2d6b3e3d6c6f 10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents: 733
diff changeset
613 emms_c();
2d6b3e3d6c6f 10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents: 733
diff changeset
614
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
615 /* return image */
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
616 *data_size = sizeof(AVFrame);
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
617 *(AVFrame*)data= s->picture;
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
618
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
619 avctx->release_buffer(avctx, &s->picture);
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
620
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
621 return packet_size;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
622 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
623
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
624 static int dvvideo_decode_end(AVCodecContext *avctx)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
625 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
626 DVVideoDecodeContext *s = avctx->priv_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
627 int i;
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
628
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
629 if(avctx->get_buffer == avcodec_default_get_buffer){
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
630 for(i=0; i<4; i++){
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
631 av_freep(&s->picture.base[i]);
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
632 s->picture.data[i]= NULL;
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
633 }
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
634 av_freep(&s->picture.opaque);
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
635 }
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
636
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
637 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
638 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
639
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
640 AVCodec dvvideo_decoder = {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
641 "dvvideo",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
642 CODEC_TYPE_VIDEO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
643 CODEC_ID_DVVIDEO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
644 sizeof(DVVideoDecodeContext),
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
645 dvvideo_decode_init,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
646 NULL,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
647 dvvideo_decode_end,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
648 dvvideo_decode_frame,
835
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
649 CODEC_CAP_DR1,
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
650 NULL
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
651 };
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
652
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
653 typedef struct DVAudioDecodeContext {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
654 AVCodecContext *avctx;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
655 GetBitContext gb;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
656 } DVAudioDecodeContext;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
657
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
658 static int dvaudio_decode_init(AVCodecContext *avctx)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
659 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
660 // DVAudioDecodeContext *s = avctx->priv_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
661 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
662 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
663
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
664 static uint16_t dv_audio_12to16(uint16_t sample)
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
665 {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
666 uint16_t shift, result;
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
667
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
668 sample = (sample < 0x800) ? sample : sample | 0xf000;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
669 shift = (sample & 0xf00) >> 8;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
670
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
671 if (shift < 0x2 || shift > 0xd) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
672 result = sample;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
673 } else if (shift < 0x8) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
674 shift--;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
675 result = (sample - (256 * shift)) << shift;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
676 } else {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
677 shift = 0xe - shift;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
678 result = ((sample + ((256 * shift) + 1)) << shift) - 1;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
679 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
680
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
681 return result;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
682 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
683
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
684 /* NOTE: exactly one frame must be given (120000 bytes for NTSC,
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
685 144000 bytes for PAL)
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
686
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
687 There's a couple of assumptions being made here:
1167
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
688 1. By default we silence erroneous (0x8000/16bit 0x800/12bit)
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
689 audio samples. We can pass them upwards when ffmpeg will be ready
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
690 to deal with them.
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
691 2. We don't do software emphasis.
1167
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
692 3. Audio is always returned as 16bit linear samples: 12bit
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
693 nonlinear samples are converted into 16bit linear ones.
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
694 */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
695 static int dvaudio_decode_frame(AVCodecContext *avctx,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
696 void *data, int *data_size,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
697 uint8_t *buf, int buf_size)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
698 {
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
699 DVVideoDecodeContext *s = avctx->priv_data;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
700 const uint16_t (*unshuffle)[9];
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
701 int smpls, freq, quant, sys, stride, difseg, ad, dp, nb_dif_segs, i;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
702 uint16_t lc, rc;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
703 uint8_t *buf_ptr;
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
704
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
705 /* parse id */
1167
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
706 init_get_bits(&s->gb, &buf[AAUX_AS_OFFSET], 5*8);
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
707 i = get_bits(&s->gb, 8);
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
708 if (i != 0x50) { /* No audio ? */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
709 *data_size = 0;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
710 return buf_size;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
711 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
712
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
713 get_bits(&s->gb, 1); /* 0 - locked audio, 1 - unlocked audio */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
714 skip_bits(&s->gb, 1);
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
715 smpls = get_bits(&s->gb, 6); /* samples in this frame - min. samples */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
716
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
717 skip_bits(&s->gb, 8);
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
718
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
719 skip_bits(&s->gb, 2);
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
720 sys = get_bits(&s->gb, 1); /* 0 - 60 fields, 1 = 50 fields */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
721 skip_bits(&s->gb, 5);
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
722
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
723 get_bits(&s->gb, 1); /* 0 - emphasis on, 1 - emphasis off */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
724 get_bits(&s->gb, 1); /* 0 - reserved, 1 - emphasis time constant 50/15us */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
725 freq = get_bits(&s->gb, 3); /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
726 quant = get_bits(&s->gb, 3); /* 0 - 16bit linear, 1 - 12bit nonlinear */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
727
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
728 if (quant > 1)
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
729 return -1; /* Unsupported quantization */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
730
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
731 avctx->sample_rate = dv_audio_frequency[freq];
1156
48efa413ac81 AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1126
diff changeset
732 avctx->channels = 2;
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
733 // What about:
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
734 // avctx->bit_rate =
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
735 // avctx->frame_size =
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
736
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
737 *data_size = (dv_audio_min_samples[sys][freq] + smpls) *
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
738 avctx->channels * 2;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
739
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
740 if (sys) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
741 nb_dif_segs = 12;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
742 stride = 108;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
743 unshuffle = dv_place_audio50;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
744 } else {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
745 nb_dif_segs = 10;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
746 stride = 90;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
747 unshuffle = dv_place_audio60;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
748 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
749
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
750 /* for each DIF segment */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
751 buf_ptr = buf;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
752 for (difseg = 0; difseg < nb_dif_segs; difseg++) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
753 buf_ptr += 6 * 80; /* skip DIF segment header */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
754 for (ad = 0; ad < 9; ad++) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
755
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
756 for (dp = 8; dp < 80; dp+=2) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
757 if (quant == 0) { /* 16bit quantization */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
758 i = unshuffle[difseg][ad] + (dp - 8)/2 * stride;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
759 ((short *)data)[i] = (buf_ptr[dp] << 8) | buf_ptr[dp+1];
1167
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
760 if (((unsigned short *)data)[i] == 0x8000)
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
761 ((short *)data)[i] = 0;
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
762 } else { /* 12bit quantization */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
763 if (difseg >= nb_dif_segs/2)
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
764 goto out; /* We're not doing 4ch at this time */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
765
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
766 lc = ((uint16_t)buf_ptr[dp] << 4) |
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
767 ((uint16_t)buf_ptr[dp+2] >> 4);
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
768 rc = ((uint16_t)buf_ptr[dp+1] << 4) |
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
769 ((uint16_t)buf_ptr[dp+2] & 0x0f);
1167
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
770 lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
35b80080b2db support for DV aspect ratio and erroneous audio patch by (Dan Dennedy (dan at dennedy dot org) and Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 1156
diff changeset
771 rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
772
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
773 i = unshuffle[difseg][ad] + (dp - 8)/3 * stride;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
774 ((short *)data)[i] = lc;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
775 i = unshuffle[difseg+nb_dif_segs/2][ad] + (dp - 8)/3 * stride;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
776 ((short *)data)[i] = rc;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
777 ++dp;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
778 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
779 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
780
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
781 buf_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
782 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
783 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
784
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
785 out:
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
786 return buf_size;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
787 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
788
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
789 static int dvaudio_decode_end(AVCodecContext *avctx)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
790 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
791 // DVAudioDecodeContext *s = avctx->priv_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
792 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
793 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
794
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
795 AVCodec dvaudio_decoder = {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
796 "dvaudio",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
797 CODEC_TYPE_AUDIO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
798 CODEC_ID_DVAUDIO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
799 sizeof(DVAudioDecodeContext),
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
800 dvaudio_decode_init,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
801 NULL,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
802 dvaudio_decode_end,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
803 dvaudio_decode_frame,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
804 0,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
805 NULL
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
806 };