annotate dv.c @ 1371:a0c0bee12abf libavcodec

bitstream changes to match JM7.2
author michaelni
date Wed, 23 Jul 2003 00:32:50 +0000
parents f5318caa93f4
children 8edad1e372d1
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
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
160 #warning only works with ALT_BITSTREAM_READER
723
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;
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
174 #ifndef ALT_BITSTREAM_READER //FIXME
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
175 int re_index=0;
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
176 int re1_index=0;
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
177 #endif
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
178 OPEN_READER(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
179
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
180 #ifdef VLC_DEBUG
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
181 printf("start\n");
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
182 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
183
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
184 /* if we must parse a partial vlc, we do it here */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
185 partial_bit_count = mb->partial_bit_count;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
186 if (partial_bit_count > 0) {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
187 uint8_t buf[4];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
188 uint32_t v;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
189 int l, l1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
190 GetBitContext gb1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
191
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
192 /* build the dummy bit buffer */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
193 l = 16 - partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
194 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
195 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
196 printf("show=%04x\n", SHOW_UBITS(re, &s->gb, 16));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
197 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
198 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
199 buf[0] = v >> 8;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
200 buf[1] = v;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
201 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
202 printf("v=%04x cnt=%d %04x\n",
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
203 v, partial_bit_count, (mb->partial_bit_buffer << l));
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
204 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
205 /* 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
206 init_get_bits(&gb1, buf, 4*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
207 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
208 OPEN_READER(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
209 UPDATE_CACHE(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
210 GET_RL_VLC(level, run, re1, &gb1, dv_rl_vlc[0],
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
211 TEX_VLC_BITS, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
212 l = re1_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
213 CLOSE_READER(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
214 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
215 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
216 printf("****run=%d level=%d size=%d\n", run, level, l);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
217 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
218 /* compute codeword length */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
219 l1 = (level != 256 && level != 0);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
220 /* if too long, we cannot parse */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
221 l -= partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
222 if ((re_index + l + l1) > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
223 return;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
224 /* skip read bits */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
225 last_re_index = 0; /* avoid warning */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
226 re_index += l;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
227 /* by definition, if we can read the vlc, all partial bits
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
228 will be read (otherwise we could have read the vlc before) */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
229 mb->partial_bit_count = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
230 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
231 goto handle_vlc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
232 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
233
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
234 /* get the AC coefficients until last_index is reached */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
235 for(;;) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
236 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
237 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
238 printf("%2d: bits=%04x index=%d\n",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
239 pos, SHOW_UBITS(re, &s->gb, 16), re_index);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
240 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
241 last_re_index = re_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
242 GET_RL_VLC(level, run, re, &s->gb, dv_rl_vlc[0],
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
243 TEX_VLC_BITS, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
244 handle_vlc:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
245 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
246 printf("run=%d level=%d\n", run, level);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
247 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
248 if (level == 256) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
249 if (re_index > last_index) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
250 cannot_read:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
251 /* put position before read code */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
252 re_index = last_re_index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
253 mb->eob_reached = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
254 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
255 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
256 /* EOB */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
257 mb->eob_reached = 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
258 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
259 } else if (level != 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
260 if ((re_index + 1) > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
261 goto cannot_read;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
262 sign = SHOW_SBITS(re, &s->gb, 1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
263 level = (level ^ sign) - sign;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
264 LAST_SKIP_BITS(re, &s->gb, 1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
265 pos += run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
266 /* error */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
267 if (pos >= 64) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
268 goto read_error;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
269 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
270 pos1 = scan_table[pos];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
271 level = level << (shift_table[pos1] + shift_offset);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
272 block[pos1] = level;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
273 // 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
274 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
275 if (re_index > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
276 goto cannot_read;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
277 /* level is zero: means run without coding. No
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
278 sign is coded */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
279 pos += run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
280 /* error */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
281 if (pos >= 64) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
282 read_error:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
283 #if defined(VLC_DEBUG) || 1
1222
adcc6f345202 making it nicer to the client who doesn't expect errors messages in stdout
romansh
parents: 1221
diff changeset
284 fprintf(stderr, "error pos=%d\n", pos);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
285 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
286 /* for errors, we consider the eob is reached */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
287 mb->eob_reached = 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
288 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
289 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
290 }
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 CLOSE_READER(re, &s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
293 mb->pos = pos;
723
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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
296 static inline void bit_copy(PutBitContext *pb, GetBitContext *gb, int bits_left)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
297 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
298 while (bits_left >= 16) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
299 put_bits(pb, 16, get_bits(gb, 16));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
300 bits_left -= 16;
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 if (bits_left > 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
303 put_bits(pb, bits_left, get_bits(gb, bits_left));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
304 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
305 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
306
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
307 /* mb_x and mb_y are in units of 8 pixels */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
308 static inline void dv_decode_video_segment(DVVideoDecodeContext *s,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
309 uint8_t *buf_ptr1,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
310 const uint16_t *mb_pos_ptr)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
311 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
312 int quant, dc, dct_mode, class1, j;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
313 int mb_index, mb_x, mb_y, v, last_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
314 DCTELEM *block, *block1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
315 int c_offset, bits_left;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
316 uint8_t *y_ptr;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
317 BlockInfo mb_data[5 * 6], *mb, *mb1;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
318 void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block);
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
319 uint8_t *buf_ptr;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
320 PutBitContext pb, vs_pb;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
321 uint8_t mb_bit_buffer[80 + 4]; /* allow some slack */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
322 int mb_bit_count;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
323 uint8_t vs_bit_buffer[5 * 80 + 4]; /* allow some slack */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
324 int vs_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
325
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
326 memset(s->block, 0, sizeof(s->block));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
327
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
328 /* pass 1 : read DC and AC coefficients in blocks */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
329 buf_ptr = buf_ptr1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
330 block1 = &s->block[0][0];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
331 mb1 = mb_data;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
332 init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80, NULL, NULL);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
333 vs_bit_count = 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
334 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
335 /* skip header */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
336 quant = buf_ptr[3] & 0x0f;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
337 buf_ptr += 4;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
338 init_put_bits(&pb, mb_bit_buffer, 80, NULL, NULL);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
339 mb_bit_count = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
340 mb = mb1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
341 block = block1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
342 for(j = 0;j < 6; j++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
343 /* 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
344 init_get_bits(&s->gb, buf_ptr, 14*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
345
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
346 /* get the dc */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
347 dc = get_bits(&s->gb, 9);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
348 dc = (dc << (32 - 9)) >> (32 - 9);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
349 dct_mode = get_bits1(&s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
350 mb->dct_mode = dct_mode;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
351 mb->scan_table = s->dv_zigzag[dct_mode];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
352 class1 = get_bits(&s->gb, 2);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
353 mb->shift_offset = (class1 == 3);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
354 mb->shift_table = s->dv_shift[dct_mode]
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
355 [quant + dv_quant_offset[class1]];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
356 dc = dc << 2;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
357 /* convert to unsigned because 128 is not added in the
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
358 standard IDCT */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
359 dc += 1024;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
360 block[0] = dc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
361 last_index = block_sizes[j];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
362 buf_ptr += last_index >> 3;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
363 mb->pos = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
364 mb->partial_bit_count = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
365
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
366 dv_decode_ac(s, mb, block, last_index);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
367
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
368 /* write the remaining bits in a new buffer only if the
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
369 block is finished */
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
370 bits_left = last_index - get_bits_count(&s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
371 if (mb->eob_reached) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
372 mb->partial_bit_count = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
373 mb_bit_count += bits_left;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
374 bit_copy(&pb, &s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
375 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
376 /* should be < 16 bits otherwise a codeword could have
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
377 been parsed */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
378 mb->partial_bit_count = bits_left;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
379 mb->partial_bit_buffer = get_bits(&s->gb, bits_left);
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 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
382 mb++;
723
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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
385 flush_put_bits(&pb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
386
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
387 /* pass 2 : we can do it just after */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
388 #ifdef VLC_DEBUG
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
389 printf("***pass 2 size=%d\n", mb_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
390 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
391 block = block1;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
392 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
393 init_get_bits(&s->gb, mb_bit_buffer, 80*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
394 for(j = 0;j < 6; j++) {
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
395 if (!mb->eob_reached && get_bits_count(&s->gb) < mb_bit_count) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
396 dv_decode_ac(s, mb, block, mb_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
397 /* if still not finished, no need to parse other blocks */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
398 if (!mb->eob_reached) {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
399 /* we could not parse the current AC coefficient,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
400 so we add the remaining bytes */
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
401 bits_left = mb_bit_count - get_bits_count(&s->gb);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
402 if (bits_left > 0) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
403 mb->partial_bit_count += bits_left;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
404 mb->partial_bit_buffer =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
405 (mb->partial_bit_buffer << bits_left) |
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
406 get_bits(&s->gb, bits_left);
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 goto next_mb;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
409 }
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 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
412 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
413 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
414 /* all blocks are finished, so the extra bytes can be used at
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
415 the video segment level */
1256
b8e1c17b8d7d some libmpeg2 style bitstream reader fixes (no dv doesnt yet work with it)
michaelni
parents: 1228
diff changeset
416 bits_left = mb_bit_count - get_bits_count(&s->gb);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
417 vs_bit_count += bits_left;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
418 bit_copy(&vs_pb, &s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
419 next_mb:
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
420 mb1 += 6;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
421 block1 += 6 * 64;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
422 }
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 /* we need a pass other the whole video segment */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
425 flush_put_bits(&vs_pb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
426
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
427 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
428 printf("***pass 3 size=%d\n", vs_bit_count);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
429 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
430 block = &s->block[0][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
431 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
432 init_get_bits(&s->gb, vs_bit_buffer, 5 * 80*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
433 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
434 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
435 if (!mb->eob_reached) {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
436 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
437 printf("start %d:%d\n", mb_index, j);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
438 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
439 dv_decode_ac(s, mb, block, vs_bit_count);
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 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
442 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
443 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
444 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
445
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
446 /* compute idct and place blocks */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
447 block = &s->block[0][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
448 mb = mb_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
449 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
450 v = *mb_pos_ptr++;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
451 mb_x = v & 0xff;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
452 mb_y = v >> 8;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
453 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
454 if (s->sampling_411)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
455 c_offset = (mb_y * s->linesize[1] * 8) + ((mb_x >> 2) * 8);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
456 else
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
457 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
458 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
459 idct_put = s->idct_put[mb->dct_mode];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
460 if (j < 4) {
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
461 if (s->sampling_411 && mb_x < (704 / 8)) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
462 /* NOTE: at end of line, the macroblock is handled as 420 */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
463 idct_put(y_ptr + (j * 8), s->linesize[0], block);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
464 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
465 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
466 s->linesize[0], block);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
467 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
468 } else {
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
469 if (s->sampling_411 && mb_x >= (704 / 8)) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
470 uint8_t pixels[64], *c_ptr, *c_ptr1, *ptr;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
471 int y, linesize;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
472 /* NOTE: at end of line, the macroblock is handled as 420 */
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
473 idct_put(pixels, 8, block);
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
474 linesize = s->linesize[6 - j];
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
475 c_ptr = s->current_picture[6 - j] + c_offset;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
476 ptr = pixels;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
477 for(y = 0;y < 8; y++) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
478 /* convert to 411P */
1270
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
479 c_ptr1 = c_ptr + 8*linesize;
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
480 c_ptr[0]= ptr[0]; c_ptr1[0]= ptr[4];
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
481 c_ptr[1]= ptr[1]; c_ptr1[1]= ptr[5];
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
482 c_ptr[2]= ptr[2]; c_ptr1[2]= ptr[6];
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
483 c_ptr[3]= ptr[3]; c_ptr1[3]= ptr[7];
f5318caa93f4 seems i guessed correctly (last 411 chroma block isnt scaled but cut and reordered)
michaelni
parents: 1256
diff changeset
484 c_ptr += linesize;
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
485 ptr += 8;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
486 }
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
487 } else {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
488 /* don't ask me why they inverted Cb and Cr ! */
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
489 idct_put(s->current_picture[6 - j] + c_offset,
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
490 s->linesize[6 - j], block);
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
491 }
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 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
494 mb++;
723
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 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
498
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
499
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
500 /* NOTE: exactly one frame must be given (120000 bytes for NTSC,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
501 144000 bytes for PAL) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
502 static int dvvideo_decode_frame(AVCodecContext *avctx,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
503 void *data, int *data_size,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
504 uint8_t *buf, int buf_size)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
505 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
506 DVVideoDecodeContext *s = avctx->priv_data;
862
058194d7ade6 * fixing some minor const warnings
kabi
parents: 853
diff changeset
507 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
508 uint8_t *buf_ptr;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
509 const uint16_t *mb_pos_ptr;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
510
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
511 /* 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
512 init_get_bits(&s->gb, buf, buf_size*8);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
513 sct = get_bits(&s->gb, 3);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
514 if (sct != 0)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
515 return -1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
516 skip_bits(&s->gb, 5);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
517 get_bits(&s->gb, 4); /* dsn (sequence number */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
518 get_bits(&s->gb, 1); /* fsc (channel number) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
519 skip_bits(&s->gb, 3);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
520 get_bits(&s->gb, 8); /* dbn (diff block number 0-134) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
521
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
522 dsf = get_bits(&s->gb, 1); /* 0 = NTSC 1 = PAL */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
523 if (get_bits(&s->gb, 1) != 0)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
524 return -1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
525 skip_bits(&s->gb, 11);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
526 apt = get_bits(&s->gb, 3); /* apt */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
527
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
528 get_bits(&s->gb, 1); /* tf1 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
529 skip_bits(&s->gb, 4);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
530 get_bits(&s->gb, 3); /* ap1 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
531
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
532 get_bits(&s->gb, 1); /* tf2 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
533 skip_bits(&s->gb, 4);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
534 get_bits(&s->gb, 3); /* ap2 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
535
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
536 get_bits(&s->gb, 1); /* tf3 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
537 skip_bits(&s->gb, 4);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
538 get_bits(&s->gb, 3); /* ap3 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
539
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
540 /* init size */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
541 width = 720;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
542 if (dsf) {
1126
77ccf7fe3bd0 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 1106
diff changeset
543 avctx->frame_rate = 25;
1221
867d8f0bede6 * fixing NTSC frame rate for DV streams
romansh
parents: 1214
diff changeset
544 avctx->frame_rate_base = 1;
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
545 packet_size = PAL_FRAME_SIZE;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
546 height = 576;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
547 nb_dif_segs = 12;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
548 } else {
1221
867d8f0bede6 * fixing NTSC frame rate for DV streams
romansh
parents: 1214
diff changeset
549 avctx->frame_rate = 30000;
867d8f0bede6 * fixing NTSC frame rate for DV streams
romansh
parents: 1214
diff changeset
550 avctx->frame_rate_base = 1001;
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
551 packet_size = NTSC_FRAME_SIZE;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
552 height = 480;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
553 nb_dif_segs = 10;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
554 }
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
555 /* NOTE: we only accept several full frames */
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
556 if (buf_size < packet_size)
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
557 return -1;
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
558
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
559 /* 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
560 * 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
561 * 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
562 */
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
563 s->sampling_411 = !dsf || apt;
848
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
564 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
565 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
566 avctx->pix_fmt = PIX_FMT_YUV411P;
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
567 } else {
733
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
568 mb_pos_ptr = dv_place_420;
848
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
569 avctx->pix_fmt = PIX_FMT_YUV420P;
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
570 }
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
571
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
572 avctx->width = width;
c075abb7fb3c 10l - set pixelfmt (colorspace) _before_ calling get_buffer() callback
arpi_esp
parents: 835
diff changeset
573 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
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 /* 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
576 * 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
577 * 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
578 */
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 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
580 ((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
581 (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
582 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
583 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
584 avctx->aspect_ratio = 4.0 / 3.0;
733
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
585
1228
d63e0185a90f release buffer cleanup
michaelni
parents: 1222
diff changeset
586 if(s->picture.data[0])
d63e0185a90f release buffer cleanup
michaelni
parents: 1222
diff changeset
587 avctx->release_buffer(avctx, &s->picture);
d63e0185a90f release buffer cleanup
michaelni
parents: 1222
diff changeset
588
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
589 s->picture.reference= 0;
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
590 if(avctx->get_buffer(avctx, &s->picture) < 0) {
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
591 fprintf(stderr, "get_buffer() failed\n");
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
592 return -1;
835
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
593 }
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
594
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
595 for(i=0;i<3;i++) {
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
596 s->current_picture[i] = s->picture.data[i];
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
597 s->linesize[i] = s->picture.linesize[i];
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
598 if (!s->current_picture[i])
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
599 return -1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
600 }
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
601 s->width = width;
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
602 s->height = height;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
603
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
604 /* for each DIF segment */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
605 buf_ptr = buf;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
606 for (ds = 0; ds < nb_dif_segs; ds++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
607 buf_ptr += 6 * 80; /* skip DIF segment header */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
608
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
609 for(vs = 0; vs < 27; vs++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
610 if ((vs % 3) == 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
611 /* skip audio block */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
612 buf_ptr += 80;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
613 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
614 dv_decode_video_segment(s, buf_ptr, mb_pos_ptr);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
615 buf_ptr += 5 * 80;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
616 mb_pos_ptr += 5;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
617 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
618 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
619
734
2d6b3e3d6c6f 10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents: 733
diff changeset
620 emms_c();
2d6b3e3d6c6f 10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents: 733
diff changeset
621
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
622 /* return image */
925
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
623 *data_size = sizeof(AVFrame);
7fccaa0d699d AVVideoFrame -> AVFrame
michaelni
parents: 903
diff changeset
624 *(AVFrame*)data= s->picture;
903
22ee74da2cd3 cleanup
michaelni
parents: 864
diff changeset
625
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
626 return packet_size;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
627 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
628
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
629 static int dvvideo_decode_end(AVCodecContext *avctx)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
630 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
631 DVVideoDecodeContext *s = avctx->priv_data;
1214
327c5a36dfe7 fixing mixed dr1 + internal buffers
michaelni
parents: 1167
diff changeset
632
327c5a36dfe7 fixing mixed dr1 + internal buffers
michaelni
parents: 1167
diff changeset
633 avcodec_default_free_buffers(avctx);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
634
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
635 return 0;
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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
638 AVCodec dvvideo_decoder = {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
639 "dvvideo",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
640 CODEC_TYPE_VIDEO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
641 CODEC_ID_DVVIDEO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
642 sizeof(DVVideoDecodeContext),
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
643 dvvideo_decode_init,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
644 NULL,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
645 dvvideo_decode_end,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
646 dvvideo_decode_frame,
835
9cec9eab681f * DR1 support
kabi
parents: 738
diff changeset
647 CODEC_CAP_DR1,
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
648 NULL
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
649 };
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
650
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
651 typedef struct DVAudioDecodeContext {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
652 AVCodecContext *avctx;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
653 GetBitContext gb;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
654 } DVAudioDecodeContext;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
655
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
656 static int dvaudio_decode_init(AVCodecContext *avctx)
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 // DVAudioDecodeContext *s = avctx->priv_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
659 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
660 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
661
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
662 static uint16_t dv_audio_12to16(uint16_t sample)
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
663 {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
664 uint16_t shift, result;
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
665
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
666 sample = (sample < 0x800) ? sample : sample | 0xf000;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
667 shift = (sample & 0xf00) >> 8;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
668
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
669 if (shift < 0x2 || shift > 0xd) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
670 result = sample;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
671 } else if (shift < 0x8) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
672 shift--;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
673 result = (sample - (256 * shift)) << shift;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
674 } else {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
675 shift = 0xe - shift;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
676 result = ((sample + ((256 * shift) + 1)) << shift) - 1;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
677 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
678
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
679 return result;
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
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
682 /* NOTE: exactly one frame must be given (120000 bytes for NTSC,
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
683 144000 bytes for PAL)
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
684
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
685 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
686 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
687 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
688 to deal with them.
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
689 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
690 3. Audio is always returned as 16bit linear samples: 12bit
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
691 nonlinear samples are converted into 16bit linear ones.
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
692 */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
693 static int dvaudio_decode_frame(AVCodecContext *avctx,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
694 void *data, int *data_size,
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
695 uint8_t *buf, int buf_size)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
696 {
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
697 DVVideoDecodeContext *s = avctx->priv_data;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
698 const uint16_t (*unshuffle)[9];
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
699 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
700 uint16_t lc, rc;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
701 uint8_t *buf_ptr;
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
702
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
703 /* 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
704 init_get_bits(&s->gb, &buf[AAUX_AS_OFFSET], 5*8);
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
705 i = get_bits(&s->gb, 8);
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
706 if (i != 0x50) { /* No audio ? */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
707 *data_size = 0;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
708 return buf_size;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
709 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
710
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
711 get_bits(&s->gb, 1); /* 0 - locked audio, 1 - unlocked audio */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
712 skip_bits(&s->gb, 1);
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
713 smpls = get_bits(&s->gb, 6); /* samples in this frame - min. samples */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
714
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
715 skip_bits(&s->gb, 8);
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, 2);
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
718 sys = get_bits(&s->gb, 1); /* 0 - 60 fields, 1 = 50 fields */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
719 skip_bits(&s->gb, 5);
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
720
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
721 get_bits(&s->gb, 1); /* 0 - emphasis on, 1 - emphasis off */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
722 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
723 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
724 quant = get_bits(&s->gb, 3); /* 0 - 16bit linear, 1 - 12bit nonlinear */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
725
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
726 if (quant > 1)
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
727 return -1; /* Unsupported quantization */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
728
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
729 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
730 avctx->channels = 2;
1221
867d8f0bede6 * fixing NTSC frame rate for DV streams
romansh
parents: 1214
diff changeset
731 avctx->bit_rate = avctx->channels * avctx->sample_rate * 16;
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
732 // What about:
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
733 // avctx->frame_size =
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
734
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
735 *data_size = (dv_audio_min_samples[sys][freq] + smpls) *
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
736 avctx->channels * 2;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
737
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
738 if (sys) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
739 nb_dif_segs = 12;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
740 stride = 108;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
741 unshuffle = dv_place_audio50;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
742 } else {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
743 nb_dif_segs = 10;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
744 stride = 90;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
745 unshuffle = dv_place_audio60;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
746 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
747
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
748 /* for each DIF segment */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
749 buf_ptr = buf;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
750 for (difseg = 0; difseg < nb_dif_segs; difseg++) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
751 buf_ptr += 6 * 80; /* skip DIF segment header */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
752 for (ad = 0; ad < 9; ad++) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
753
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
754 for (dp = 8; dp < 80; dp+=2) {
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
755 if (quant == 0) { /* 16bit quantization */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
756 i = unshuffle[difseg][ad] + (dp - 8)/2 * stride;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
757 ((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
758 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
759 ((short *)data)[i] = 0;
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
760 } else { /* 12bit quantization */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
761 if (difseg >= nb_dif_segs/2)
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
762 goto out; /* We're not doing 4ch at this time */
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
763
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
764 lc = ((uint16_t)buf_ptr[dp] << 4) |
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
765 ((uint16_t)buf_ptr[dp+2] >> 4);
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
766 rc = ((uint16_t)buf_ptr[dp+1] << 4) |
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1036
diff changeset
767 ((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
768 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
769 rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
1036
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
770
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
771 i = unshuffle[difseg][ad] + (dp - 8)/3 * stride;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
772 ((short *)data)[i] = lc;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
773 i = unshuffle[difseg+nb_dif_segs/2][ad] + (dp - 8)/3 * stride;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
774 ((short *)data)[i] = rc;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
775 ++dp;
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
776 }
c7922c5becf6 DV audio decoder by Roman Shaposhnick
bellard
parents: 1025
diff changeset
777 }
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 buf_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
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 }
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 out:
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
784 return buf_size;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
785 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
786
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
787 static int dvaudio_decode_end(AVCodecContext *avctx)
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 // DVAudioDecodeContext *s = avctx->priv_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
790 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
791 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
792
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
793 AVCodec dvaudio_decoder = {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
794 "dvaudio",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
795 CODEC_TYPE_AUDIO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
796 CODEC_ID_DVAUDIO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
797 sizeof(DVAudioDecodeContext),
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
798 dvaudio_decode_init,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
799 NULL,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
800 dvaudio_decode_end,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
801 dvaudio_decode_frame,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
802 0,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
803 NULL
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
804 };