annotate dv.c @ 794:670009af4fc2 libavcodec

avoid name clash
author bellard
date Tue, 29 Oct 2002 22:26:01 +0000
parents 044307862b4b
children 9cec9eab681f
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 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
19 #include "avcodec.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
20 #include "dsputil.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
21 #include "mpegvideo.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
22 #include "simple_idct.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
23
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
24 #define NTSC_FRAME_SIZE 120000
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
25 #define PAL_FRAME_SIZE 144000
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
26
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
27 #define TEX_VLC_BITS 9
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 typedef struct DVVideoDecodeContext {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
30 AVCodecContext *avctx;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
31 GetBitContext gb;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
32 VLC *vlc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
33 int sampling_411; /* 0 = 420, 1 = 411 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
34 int width, height;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
35 UINT8 *current_picture[3]; /* picture structure */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
36 int linesize[3];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
37 DCTELEM block[5*6][64] __align8;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
38 UINT8 dv_zigzag[2][64];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
39 UINT8 idct_permutation[64];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
40 /* XXX: move it to static storage ? */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
41 UINT8 dv_shift[2][22][64];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
42 void (*idct_put[2])(UINT8 *dest, int line_size, DCTELEM *block);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
43 } DVVideoDecodeContext;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
44
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
45 #include "dvdata.h"
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
46
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
47 static VLC dv_vlc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
48 /* XXX: also include quantization */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
49 static RL_VLC_ELEM *dv_rl_vlc[1];
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 static void dv_build_unquantize_tables(DVVideoDecodeContext *s)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
52 {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
53 int i, q, j;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
54
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
55 /* NOTE: max left shift is 6 */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
56 for(q = 0; q < 22; q++) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
57 /* 88 unquant */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
58 for(i = 1; i < 64; i++) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
59 /* 88 table */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
60 j = s->idct_permutation[i];
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
61 s->dv_shift[0][q][j] =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
62 dv_quant_shifts[q][dv_88_areas[i]] + 1;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
63 }
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
64
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
65 /* 248 unquant */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
66 for(i = 1; i < 64; i++) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
67 /* 248 table */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
68 s->dv_shift[1][q][i] =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
69 dv_quant_shifts[q][dv_248_areas[i]] + 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
70 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
71 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
72 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
73
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
74 static int dvvideo_decode_init(AVCodecContext *avctx)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
75 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
76 DVVideoDecodeContext *s = avctx->priv_data;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
77 MpegEncContext s2;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
78 static int done;
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 if (!done) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
81 int i;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
82
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
83 done = 1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
84
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
85 /* 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
86 to accelerate the parsing of partial codes */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
87 init_vlc(&dv_vlc, TEX_VLC_BITS, NB_DV_VLC,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
88 dv_vlc_len, 1, 1, dv_vlc_bits, 2, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
89
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
90 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
91 for(i = 0; i < dv_vlc.table_size; i++){
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
92 int code= dv_vlc.table[i][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
93 int len = dv_vlc.table[i][1];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
94 int level, run;
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 if(len<0){ //more bits needed
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
97 run= 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
98 level= code;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
99 } else if (code == (NB_DV_VLC - 1)) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
100 /* EOB */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
101 run = 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
102 level = 256;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
103 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
104 run= dv_vlc_run[code] + 1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
105 level= dv_vlc_level[code];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
106 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
107 dv_rl_vlc[0][i].len = len;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
108 dv_rl_vlc[0][i].level = level;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
109 dv_rl_vlc[0][i].run = run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
110 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
111 }
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
112
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
113 /* ugly way to get the idct & scantable */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
114 /* XXX: fix it */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
115 memset(&s2, 0, sizeof(MpegEncContext));
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
116 s2.avctx = 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
117 if (DCT_common_init(&s2) < 0)
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
118 return -1;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
119
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
120 s->idct_put[0] = s2.idct_put;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
121 memcpy(s->idct_permutation, s2.idct_permutation, 64);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
122 memcpy(s->dv_zigzag[0], s2.intra_scantable.permutated, 64);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
123
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
124 /* XXX: use MMX also for idct248 */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
125 s->idct_put[1] = simple_idct248_put;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
126 memcpy(s->dv_zigzag[1], dv_248_zigzag, 64);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
127
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
128 /* XXX: do it only for constant case */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
129 dv_build_unquantize_tables(s);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
130
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
131 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
132 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
133
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
134 //#define VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
135
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
136 typedef struct BlockInfo {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
137 const UINT8 *shift_table;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
138 const UINT8 *scan_table;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
139 UINT8 pos; /* position in block */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
140 UINT8 eob_reached; /* true if EOB has been reached */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
141 UINT8 dct_mode;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
142 UINT8 partial_bit_count;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
143 UINT16 partial_bit_buffer;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
144 int shift_offset;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
145 } BlockInfo;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
146
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
147 /* block size in bits */
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
148 static const UINT16 block_sizes[6] = {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
149 112, 112, 112, 112, 80, 80
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
150 };
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
151
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
152 #ifndef ALT_BITSTREAM_READER
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
153 #error only works with ALT_BITSTREAM_READER
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
154 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
155
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
156 /* decode ac coefs */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
157 static void dv_decode_ac(DVVideoDecodeContext *s,
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
158 BlockInfo *mb, INT16 *block, int last_index)
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
159 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
160 int last_re_index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
161 int shift_offset = mb->shift_offset;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
162 const UINT8 *scan_table = mb->scan_table;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
163 const UINT8 *shift_table = mb->shift_table;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
164 int pos = mb->pos;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
165 int level, pos1, sign, run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
166 int partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
167
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
168 OPEN_READER(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
169
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
170 #ifdef VLC_DEBUG
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
171 printf("start\n");
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
172 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
173
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
174 /* if we must parse a partial vlc, we do it here */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
175 partial_bit_count = mb->partial_bit_count;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
176 if (partial_bit_count > 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
177 UINT8 buf[4];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
178 UINT32 v;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
179 int l, l1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
180 GetBitContext gb1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
181
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
182 /* build the dummy bit buffer */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
183 l = 16 - partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
184 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
185 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
186 printf("show=%04x\n", SHOW_UBITS(re, &s->gb, 16));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
187 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
188 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
189 buf[0] = v >> 8;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
190 buf[1] = v;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
191 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
192 printf("v=%04x cnt=%d %04x\n",
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
193 v, partial_bit_count, (mb->partial_bit_buffer << l));
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
194 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
195 /* try to read the codeword */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
196 init_get_bits(&gb1, buf, 4);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
197 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
198 OPEN_READER(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
199 UPDATE_CACHE(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
200 GET_RL_VLC(level, run, re1, &gb1, dv_rl_vlc[0],
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
201 TEX_VLC_BITS, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
202 l = re1_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
203 CLOSE_READER(re1, &gb1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
204 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
205 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
206 printf("****run=%d level=%d size=%d\n", run, level, l);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
207 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
208 /* compute codeword length */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
209 l1 = (level != 256 && level != 0);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
210 /* if too long, we cannot parse */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
211 l -= partial_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
212 if ((re_index + l + l1) > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
213 return;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
214 /* skip read bits */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
215 last_re_index = 0; /* avoid warning */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
216 re_index += l;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
217 /* by definition, if we can read the vlc, all partial bits
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
218 will be read (otherwise we could have read the vlc before) */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
219 mb->partial_bit_count = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
220 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
221 goto handle_vlc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
222 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
223
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
224 /* get the AC coefficients until last_index is reached */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
225 for(;;) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
226 UPDATE_CACHE(re, &s->gb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
227 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
228 printf("%2d: bits=%04x index=%d\n",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
229 pos, SHOW_UBITS(re, &s->gb, 16), re_index);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
230 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
231 last_re_index = re_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
232 GET_RL_VLC(level, run, re, &s->gb, dv_rl_vlc[0],
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
233 TEX_VLC_BITS, 2);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
234 handle_vlc:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
235 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
236 printf("run=%d level=%d\n", run, level);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
237 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
238 if (level == 256) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
239 if (re_index > last_index) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
240 cannot_read:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
241 /* put position before read code */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
242 re_index = last_re_index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
243 mb->eob_reached = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
244 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
245 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
246 /* EOB */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
247 mb->eob_reached = 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
248 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
249 } else if (level != 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
250 if ((re_index + 1) > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
251 goto cannot_read;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
252 sign = SHOW_SBITS(re, &s->gb, 1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
253 level = (level ^ sign) - sign;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
254 LAST_SKIP_BITS(re, &s->gb, 1);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
255 pos += run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
256 /* error */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
257 if (pos >= 64) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
258 goto read_error;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
259 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
260 pos1 = scan_table[pos];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
261 level = level << (shift_table[pos1] + shift_offset);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
262 block[pos1] = level;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
263 // 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
264 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
265 if (re_index > last_index)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
266 goto cannot_read;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
267 /* level is zero: means run without coding. No
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
268 sign is coded */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
269 pos += run;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
270 /* error */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
271 if (pos >= 64) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
272 read_error:
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
273 #if defined(VLC_DEBUG) || 1
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
274 printf("error pos=%d\n", pos);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
275 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
276 /* for errors, we consider the eob is reached */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
277 mb->eob_reached = 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
278 break;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
279 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
280 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
281 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
282 CLOSE_READER(re, &s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
283 mb->pos = pos;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
284 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
285
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
286 static inline void bit_copy(PutBitContext *pb, GetBitContext *gb, int bits_left)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
287 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
288 while (bits_left >= 16) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
289 put_bits(pb, 16, get_bits(gb, 16));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
290 bits_left -= 16;
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 if (bits_left > 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
293 put_bits(pb, bits_left, get_bits(gb, bits_left));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
294 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
295 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
296
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
297 /* mb_x and mb_y are in units of 8 pixels */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
298 static inline void dv_decode_video_segment(DVVideoDecodeContext *s,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
299 UINT8 *buf_ptr1,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
300 const UINT16 *mb_pos_ptr)
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 int quant, dc, dct_mode, class1, j;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
303 int mb_index, mb_x, mb_y, v, last_index;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
304 DCTELEM *block, *block1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
305 int c_offset, bits_left;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
306 UINT8 *y_ptr;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
307 BlockInfo mb_data[5 * 6], *mb, *mb1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
308 void (*idct_put)(UINT8 *dest, int line_size, DCTELEM *block);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
309 UINT8 *buf_ptr;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
310 PutBitContext pb, vs_pb;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
311 UINT8 mb_bit_buffer[80 + 4]; /* allow some slack */
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
312 int mb_bit_count;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
313 UINT8 vs_bit_buffer[5 * 80 + 4]; /* allow some slack */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
314 int vs_bit_count;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
315
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
316 memset(s->block, 0, sizeof(s->block));
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
317
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
318 /* pass 1 : read DC and AC coefficients in blocks */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
319 buf_ptr = buf_ptr1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
320 block1 = &s->block[0][0];
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
321 mb1 = mb_data;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
322 init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80, NULL, NULL);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
323 vs_bit_count = 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
324 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
325 /* skip header */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
326 quant = buf_ptr[3] & 0x0f;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
327 buf_ptr += 4;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
328 init_put_bits(&pb, mb_bit_buffer, 80, NULL, NULL);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
329 mb_bit_count = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
330 mb = mb1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
331 block = block1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
332 for(j = 0;j < 6; j++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
333 /* NOTE: size is not important here */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
334 init_get_bits(&s->gb, buf_ptr, 14);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
335
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
336 /* get the dc */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
337 dc = get_bits(&s->gb, 9);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
338 dc = (dc << (32 - 9)) >> (32 - 9);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
339 dct_mode = get_bits1(&s->gb);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
340 mb->dct_mode = dct_mode;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
341 mb->scan_table = s->dv_zigzag[dct_mode];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
342 class1 = get_bits(&s->gb, 2);
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
343 mb->shift_offset = (class1 == 3);
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
344 mb->shift_table = s->dv_shift[dct_mode]
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
345 [quant + dv_quant_offset[class1]];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
346 dc = dc << 2;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
347 /* convert to unsigned because 128 is not added in the
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
348 standard IDCT */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
349 dc += 1024;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
350 block[0] = dc;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
351 last_index = block_sizes[j];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
352 buf_ptr += last_index >> 3;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
353 mb->pos = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
354 mb->partial_bit_count = 0;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
355
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
356 dv_decode_ac(s, mb, block, last_index);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
357
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
358 /* write the remaining bits in a new buffer only if the
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
359 block is finished */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
360 bits_left = last_index - s->gb.index;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
361 if (mb->eob_reached) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
362 mb->partial_bit_count = 0;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
363 mb_bit_count += bits_left;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
364 bit_copy(&pb, &s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
365 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
366 /* should be < 16 bits otherwise a codeword could have
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
367 been parsed */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
368 mb->partial_bit_count = bits_left;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
369 mb->partial_bit_buffer = get_bits(&s->gb, bits_left);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
370 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
371 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
372 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
373 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
374
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
375 flush_put_bits(&pb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
376
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
377 /* pass 2 : we can do it just after */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
378 #ifdef VLC_DEBUG
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
379 printf("***pass 2 size=%d\n", mb_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
380 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
381 block = block1;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
382 mb = mb1;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
383 init_get_bits(&s->gb, mb_bit_buffer, 80);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
384 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
385 if (!mb->eob_reached && s->gb.index < mb_bit_count) {
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
386 dv_decode_ac(s, mb, block, mb_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
387 /* if still not finished, no need to parse other blocks */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
388 if (!mb->eob_reached) {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
389 /* we could not parse the current AC coefficient,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
390 so we add the remaining bytes */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
391 bits_left = mb_bit_count - s->gb.index;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
392 if (bits_left > 0) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
393 mb->partial_bit_count += bits_left;
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
394 mb->partial_bit_buffer =
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
395 (mb->partial_bit_buffer << bits_left) |
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
396 get_bits(&s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
397 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
398 goto next_mb;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
399 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
400 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
401 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
402 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
403 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
404 /* all blocks are finished, so the extra bytes can be used at
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
405 the video segment level */
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
406 bits_left = mb_bit_count - s->gb.index;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
407 vs_bit_count += bits_left;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
408 bit_copy(&vs_pb, &s->gb, bits_left);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
409 next_mb:
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
410 mb1 += 6;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
411 block1 += 6 * 64;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
412 }
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 /* we need a pass other the whole video segment */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
415 flush_put_bits(&vs_pb);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
416
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
417 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
418 printf("***pass 3 size=%d\n", vs_bit_count);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
419 #endif
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
420 block = &s->block[0][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
421 mb = mb_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
422 init_get_bits(&s->gb, vs_bit_buffer, 5 * 80);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
423 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
424 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
425 if (!mb->eob_reached) {
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
426 #ifdef VLC_DEBUG
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
427 printf("start %d:%d\n", mb_index, j);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
428 #endif
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
429 dv_decode_ac(s, mb, block, vs_bit_count);
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
430 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
431 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
432 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
433 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
434 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
435
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
436 /* compute idct and place blocks */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
437 block = &s->block[0][0];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
438 mb = mb_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
439 for(mb_index = 0; mb_index < 5; mb_index++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
440 v = *mb_pos_ptr++;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
441 mb_x = v & 0xff;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
442 mb_y = v >> 8;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
443 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
444 if (s->sampling_411)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
445 c_offset = (mb_y * s->linesize[1] * 8) + ((mb_x >> 2) * 8);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
446 else
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
447 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
448 for(j = 0;j < 6; j++) {
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
449 idct_put = s->idct_put[mb->dct_mode];
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
450 if (j < 4) {
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
451 if (s->sampling_411 && mb_x < (704 / 8)) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
452 /* NOTE: at end of line, the macroblock is handled as 420 */
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
453 idct_put(y_ptr + (j * 8), s->linesize[0], block);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
454 } else {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
455 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
456 s->linesize[0], block);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
457 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
458 } else {
737
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
459 if (s->sampling_411 && mb_x >= (704 / 8)) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
460 uint8_t pixels[64], *c_ptr, *c_ptr1, *ptr;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
461 int y, linesize;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
462 /* NOTE: at end of line, the macroblock is handled as 420 */
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
463 idct_put(pixels, 8, block);
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
464 linesize = s->linesize[6 - j];
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
465 c_ptr = s->current_picture[6 - j] + c_offset;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
466 ptr = pixels;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
467 for(y = 0;y < 8; y++) {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
468 /* convert to 411P */
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
469 c_ptr1 = c_ptr + linesize;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
470 c_ptr1[0] = c_ptr[0] = (ptr[0] + ptr[1]) >> 1;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
471 c_ptr1[1] = c_ptr[1] = (ptr[2] + ptr[3]) >> 1;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
472 c_ptr1[2] = c_ptr[2] = (ptr[4] + ptr[5]) >> 1;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
473 c_ptr1[3] = c_ptr[3] = (ptr[6] + ptr[7]) >> 1;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
474 c_ptr += linesize * 2;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
475 ptr += 8;
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
476 }
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
477 } else {
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
478 /* don't ask me why they inverted Cb and Cr ! */
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
479 idct_put(s->current_picture[6 - j] + c_offset,
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
480 s->linesize[6 - j], block);
248a752a4c0e fixed NTSC end of line bug
bellard
parents: 734
diff changeset
481 }
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
482 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
483 block += 64;
725
eac6c71ef30f simplified parsing - added MMX idct support
bellard
parents: 723
diff changeset
484 mb++;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
485 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
486 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
487 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
488
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
489
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
490 /* NOTE: exactly one frame must be given (120000 bytes for NTSC,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
491 144000 bytes for PAL) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
492 static int dvvideo_decode_frame(AVCodecContext *avctx,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
493 void *data, int *data_size,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
494 UINT8 *buf, int buf_size)
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 DVVideoDecodeContext *s = avctx->priv_data;
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
497 int sct, dsf, apt, ds, nb_dif_segs, vs, size, width, height, i, packet_size;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
498 UINT8 *buf_ptr;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
499 const UINT16 *mb_pos_ptr;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
500 AVPicture *picture;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
501
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
502 /* parse id */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
503 init_get_bits(&s->gb, buf, buf_size);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
504 sct = get_bits(&s->gb, 3);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
505 if (sct != 0)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
506 return -1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
507 skip_bits(&s->gb, 5);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
508 get_bits(&s->gb, 4); /* dsn (sequence number */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
509 get_bits(&s->gb, 1); /* fsc (channel number) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
510 skip_bits(&s->gb, 3);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
511 get_bits(&s->gb, 8); /* dbn (diff block number 0-134) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
512
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
513 dsf = get_bits(&s->gb, 1); /* 0 = NTSC 1 = PAL */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
514 if (get_bits(&s->gb, 1) != 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, 11);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
517 apt = get_bits(&s->gb, 3); /* apt */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
518
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
519 get_bits(&s->gb, 1); /* tf1 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
520 skip_bits(&s->gb, 4);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
521 get_bits(&s->gb, 3); /* ap1 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
522
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
523 get_bits(&s->gb, 1); /* tf2 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
524 skip_bits(&s->gb, 4);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
525 get_bits(&s->gb, 3); /* ap2 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
526
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
527 get_bits(&s->gb, 1); /* tf3 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
528 skip_bits(&s->gb, 4);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
529 get_bits(&s->gb, 3); /* ap3 */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
530
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
531 /* init size */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
532 width = 720;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
533 if (dsf) {
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
534 packet_size = PAL_FRAME_SIZE;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
535 height = 576;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
536 nb_dif_segs = 12;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
537 } else {
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
538 packet_size = NTSC_FRAME_SIZE;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
539 height = 480;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
540 nb_dif_segs = 10;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
541 }
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
542 /* NOTE: we only accept several full frames */
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
543 if (buf_size < packet_size)
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
544 return -1;
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
545
733
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
546 /* XXX: is it correct to assume that 420 is always used in PAL
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
547 mode ? */
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
548 s->sampling_411 = !dsf;
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
549 if (s->sampling_411)
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
550 mb_pos_ptr = dv_place_411;
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
551 else
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
552 mb_pos_ptr = dv_place_420;
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
553
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
554 /* (re)alloc picture if needed */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
555 if (s->width != width || s->height != height) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
556 for(i=0;i<3;i++)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
557 av_freep(&s->current_picture[i]);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
558 for(i=0;i<3;i++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
559 size = width * height;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
560 s->linesize[i] = width;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
561 if (i >= 1) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
562 size >>= 2;
733
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
563 s->linesize[i] >>= s->sampling_411 ? 2 : 1;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
564 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
565 s->current_picture[i] = av_malloc(size);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
566 if (!s->current_picture[i])
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
567 return -1;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
568 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
569 s->width = width;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
570 s->height = height;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
571 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
572
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
573 /* for each DIF segment */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
574 buf_ptr = buf;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
575 for (ds = 0; ds < nb_dif_segs; ds++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
576 buf_ptr += 6 * 80; /* skip DIF segment header */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
577
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
578 for(vs = 0; vs < 27; vs++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
579 if ((vs % 3) == 0) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
580 /* skip audio block */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
581 buf_ptr += 80;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
582 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
583 dv_decode_video_segment(s, buf_ptr, mb_pos_ptr);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
584 buf_ptr += 5 * 80;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
585 mb_pos_ptr += 5;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
586 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
587 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
588
734
2d6b3e3d6c6f 10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents: 733
diff changeset
589 emms_c();
2d6b3e3d6c6f 10l - MMX/FPU state was not restored, causing nonsense fpu behaviour in caller (mplayer)
arpi_esp
parents: 733
diff changeset
590
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
591 /* return image */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
592 avctx->width = width;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
593 avctx->height = height;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
594 if (s->sampling_411)
733
7da52fc20726 DV ntsc support, 411P colorspace added
arpi_esp
parents: 726
diff changeset
595 avctx->pix_fmt = PIX_FMT_YUV411P;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
596 else
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
597 avctx->pix_fmt = PIX_FMT_YUV420P;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
598 if (dsf)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
599 avctx->frame_rate = 25 * FRAME_RATE_BASE;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
600 else
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
601 avctx->frame_rate = 30 * FRAME_RATE_BASE;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
602 *data_size = sizeof(AVPicture);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
603 picture = data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
604 for(i=0;i<3;i++) {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
605 picture->data[i] = s->current_picture[i];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
606 picture->linesize[i] = s->linesize[i];
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
607 }
738
044307862b4b support buffers containing more than one frame
bellard
parents: 737
diff changeset
608 return packet_size;
723
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
609 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
610
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
611 static int dvvideo_decode_end(AVCodecContext *avctx)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
612 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
613 DVVideoDecodeContext *s = avctx->priv_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
614 int i;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
615
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
616 for(i=0;i<3;i++)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
617 av_freep(&s->current_picture[i]);
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
618 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
619 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
620
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
621 AVCodec dvvideo_decoder = {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
622 "dvvideo",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
623 CODEC_TYPE_VIDEO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
624 CODEC_ID_DVVIDEO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
625 sizeof(DVVideoDecodeContext),
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
626 dvvideo_decode_init,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
627 NULL,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
628 dvvideo_decode_end,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
629 dvvideo_decode_frame,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
630 0,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
631 NULL
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
632 };
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
633
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
634 typedef struct DVAudioDecodeContext {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
635 AVCodecContext *avctx;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
636 GetBitContext gb;
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 } DVAudioDecodeContext;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
639
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
640 static int dvaudio_decode_init(AVCodecContext *avctx)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
641 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
642 // DVAudioDecodeContext *s = avctx->priv_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
643 return 0;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
644 }
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
645
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
646 /* NOTE: exactly one frame must be given (120000 bytes for NTSC,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
647 144000 bytes for PAL) */
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
648 static int dvaudio_decode_frame(AVCodecContext *avctx,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
649 void *data, int *data_size,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
650 UINT8 *buf, int buf_size)
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
651 {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
652 // DVAudioDecodeContext *s = avctx->priv_data;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
653 return buf_size;
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
654 }
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_end(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
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
662 AVCodec dvaudio_decoder = {
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
663 "dvaudio",
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
664 CODEC_TYPE_AUDIO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
665 CODEC_ID_DVAUDIO,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
666 sizeof(DVAudioDecodeContext),
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
667 dvaudio_decode_init,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
668 NULL,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
669 dvaudio_decode_end,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
670 dvaudio_decode_frame,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
671 0,
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
672 NULL
50f7e3bef20f first working version of DV video decoder
bellard
parents:
diff changeset
673 };