annotate avs.c @ 5319:40af705cef7e libavcodec

AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9 Fix the bugs: 1. The quality of output because of incorrect windowing coefficients. New code for window generation. 2. Dynrng values were reset where dynrng value is present in the first block, but not in the subsequent block.
author jbr
date Sat, 14 Jul 2007 16:03:14 +0000
parents 2b72f9bc4f06
children a955fb25671d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
1 /*
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
2 * AVS video decoder.
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
3 * Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3129
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3129
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3129
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3129
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3129
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
15 * Lesser General Public License for more details.
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
16 *
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3129
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
5215
2b72f9bc4f06 license header consistency cosmetics
diego
parents: 4364
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
20 */
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
21
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
22 #include "avcodec.h"
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
23 #include "bitstream.h"
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
24
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
25
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
26 typedef struct {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
27 AVFrame picture;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
28 } avs_context_t;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
29
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
30 typedef enum {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
31 AVS_VIDEO = 0x01,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
32 AVS_AUDIO = 0x02,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
33 AVS_PALETTE = 0x03,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
34 AVS_GAME_DATA = 0x04,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
35 } avs_block_type_t;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
36
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
37 typedef enum {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
38 AVS_I_FRAME = 0x00,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
39 AVS_P_FRAME_3X3 = 0x01,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
40 AVS_P_FRAME_2X2 = 0x02,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
41 AVS_P_FRAME_2X3 = 0x03,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
42 } avs_video_sub_type_t;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
43
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
44
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
45 static int
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
46 avs_decode_frame(AVCodecContext * avctx,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
47 void *data, int *data_size, uint8_t * buf, int buf_size)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
48 {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
49 avs_context_t *const avs = avctx->priv_data;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
50 AVFrame *picture = data;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
51 AVFrame *const p = (AVFrame *) & avs->picture;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
52 uint8_t *table, *vect, *out;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
53 int i, j, x, y, stride, vect_w = 3, vect_h = 3;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
54 int sub_type;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
55 avs_block_type_t type;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
56 GetBitContext change_map;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
57
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
58 if (avctx->reget_buffer(avctx, p)) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
59 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
60 return -1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
61 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
62 p->reference = 1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
63 p->pict_type = FF_P_TYPE;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
64 p->key_frame = 0;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
65
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
66 out = avs->picture.data[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
67 stride = avs->picture.linesize[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
68
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
69 sub_type = buf[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
70 type = buf[1];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
71 buf += 4;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
72
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
73 if (type == AVS_PALETTE) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
74 int first, last;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
75 uint32_t *pal = (uint32_t *) avs->picture.data[1];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
76
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
77 first = AV_RL16(buf);
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
78 last = first + AV_RL16(buf + 2);
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
79 buf += 4;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
80 for (i=first; i<last; i++, buf+=3)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
81 pal[i] = (buf[0] << 18) | (buf[1] << 10) | (buf[2] << 2);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
82
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
83 sub_type = buf[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
84 type = buf[1];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
85 buf += 4;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
86 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
87
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
88 if (type != AVS_VIDEO)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
89 return -1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
90
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
91 switch (sub_type) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
92 case AVS_I_FRAME:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
93 p->pict_type = FF_I_TYPE;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
94 p->key_frame = 1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
95 case AVS_P_FRAME_3X3:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
96 vect_w = 3;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
97 vect_h = 3;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
98 break;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
99
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
100 case AVS_P_FRAME_2X2:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
101 vect_w = 2;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
102 vect_h = 2;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
103 break;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
104
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
105 case AVS_P_FRAME_2X3:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
106 vect_w = 2;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
107 vect_h = 3;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
108 break;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
109
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
110 default:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
111 return -1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
112 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
113
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
114 table = buf + (256 * vect_w * vect_h);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
115 if (sub_type != AVS_I_FRAME) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
116 int map_size = ((318 / vect_w + 7) / 8) * (198 / vect_h);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
117 init_get_bits(&change_map, table, map_size);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
118 table += map_size;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
119 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
120
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
121 for (y=0; y<198; y+=vect_h) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
122 for (x=0; x<318; x+=vect_w) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
123 if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
124 vect = &buf[*table++ * (vect_w * vect_h)];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
125 for (j=0; j<vect_w; j++) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
126 out[(y + 0) * stride + x + j] = vect[(0 * vect_w) + j];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
127 out[(y + 1) * stride + x + j] = vect[(1 * vect_w) + j];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
128 if (vect_h == 3)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
129 out[(y + 2) * stride + x + j] =
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
130 vect[(2 * vect_w) + j];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
131 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
132 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
133 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
134 if (sub_type != AVS_I_FRAME)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
135 align_get_bits(&change_map);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
136 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
137
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
138 *picture = *(AVFrame *) & avs->picture;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
139 *data_size = sizeof(AVPicture);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
140
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
141 return buf_size;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
142 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
143
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
144 static int avs_decode_init(AVCodecContext * avctx)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
145 {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
146 avctx->pix_fmt = PIX_FMT_PAL8;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
147 return 0;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
148 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
149
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
150 AVCodec avs_decoder = {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
151 "avs",
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
152 CODEC_TYPE_VIDEO,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
153 CODEC_ID_AVS,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
154 sizeof(avs_context_t),
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
155 avs_decode_init,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
156 NULL,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
157 NULL,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
158 avs_decode_frame,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
159 CODEC_CAP_DR1,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
160 };