annotate avs.c @ 12478:5942c42c44e5 libavcodec

Add G.722 ADPCM audio decoder
author mstorsjo
date Thu, 09 Sep 2010 19:21:16 +0000
parents 8a4984c5cacc
children
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"
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 9355
diff changeset
23 #include "get_bits.h"
3129
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;
8298
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
28 } AvsContext;
3129
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,
8298
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
35 } AvsBlockType;
3129
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,
8298
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
42 } AvsVideoSubType;
3129
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,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8298
diff changeset
47 void *data, int *data_size, AVPacket *avpkt)
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
48 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8298
diff changeset
49 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8298
diff changeset
50 int buf_size = avpkt->size;
8298
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
51 AvsContext *const avs = avctx->priv_data;
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
52 AVFrame *picture = data;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
53 AVFrame *const p = (AVFrame *) & avs->picture;
6226
michael
parents: 5215
diff changeset
54 const uint8_t *table, *vect;
michael
parents: 5215
diff changeset
55 uint8_t *out;
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
56 int i, j, x, y, stride, vect_w = 3, vect_h = 3;
8298
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
57 AvsVideoSubType sub_type;
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
58 AvsBlockType type;
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
59 GetBitContext change_map;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
60
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
61 if (avctx->reget_buffer(avctx, p)) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
62 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
63 return -1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
64 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
65 p->reference = 1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
66 p->pict_type = FF_P_TYPE;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
67 p->key_frame = 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 out = avs->picture.data[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
70 stride = avs->picture.linesize[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
71
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
72 sub_type = buf[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
73 type = buf[1];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
74 buf += 4;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
75
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
76 if (type == AVS_PALETTE) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
77 int first, last;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
78 uint32_t *pal = (uint32_t *) avs->picture.data[1];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
79
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
80 first = AV_RL16(buf);
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
81 last = first + AV_RL16(buf + 2);
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
82 buf += 4;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
83 for (i=first; i<last; i++, buf+=3)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
84 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
85
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
86 sub_type = buf[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
87 type = buf[1];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
88 buf += 4;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
89 }
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 if (type != AVS_VIDEO)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
92 return -1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
93
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
94 switch (sub_type) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
95 case AVS_I_FRAME:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
96 p->pict_type = FF_I_TYPE;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
97 p->key_frame = 1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
98 case AVS_P_FRAME_3X3:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
99 vect_w = 3;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
100 vect_h = 3;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
101 break;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
102
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
103 case AVS_P_FRAME_2X2:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
104 vect_w = 2;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
105 vect_h = 2;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
106 break;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
107
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
108 case AVS_P_FRAME_2X3:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
109 vect_w = 2;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
110 vect_h = 3;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
111 break;
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 default:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
114 return -1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
115 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
116
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
117 table = buf + (256 * vect_w * vect_h);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
118 if (sub_type != AVS_I_FRAME) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
119 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
120 init_get_bits(&change_map, table, map_size);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
121 table += map_size;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
122 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
123
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
124 for (y=0; y<198; y+=vect_h) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
125 for (x=0; x<318; x+=vect_w) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
126 if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
127 vect = &buf[*table++ * (vect_w * vect_h)];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
128 for (j=0; j<vect_w; j++) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
129 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
130 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
131 if (vect_h == 3)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
132 out[(y + 2) * stride + x + j] =
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
133 vect[(2 * vect_w) + j];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
134 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
135 }
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 if (sub_type != AVS_I_FRAME)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
138 align_get_bits(&change_map);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
139 }
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 *picture = *(AVFrame *) & avs->picture;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
142 *data_size = sizeof(AVPicture);
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 return buf_size;
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
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6226
diff changeset
147 static av_cold int avs_decode_init(AVCodecContext * avctx)
3129
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 avctx->pix_fmt = PIX_FMT_PAL8;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
150 return 0;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
151 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
152
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
153 AVCodec avs_decoder = {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
154 "avs",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 9428
diff changeset
155 AVMEDIA_TYPE_VIDEO,
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
156 CODEC_ID_AVS,
8298
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
157 sizeof(AvsContext),
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
158 avs_decode_init,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
159 NULL,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
160 NULL,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
161 avs_decode_frame,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
162 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6712
diff changeset
163 .long_name = NULL_IF_CONFIG_SMALL("AVS (Audio Video Standard) video"),
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
164 };