annotate avs.c @ 8783:e91ea98d868a libavcodec

Add SEI recovery point frame counter to H264Context and use it when setting key_frame. Patch by Ivan Schreter schreter A gmx D net
author cehoyos
date Mon, 09 Feb 2009 23:04:16 +0000
parents 2dcc437528fa
children 54bc8a2727b0
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;
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,
6226
michael
parents: 5215
diff changeset
47 void *data, int *data_size, const uint8_t * buf, int buf_size)
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
48 {
8298
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
49 AvsContext *const avs = avctx->priv_data;
3129
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;
6226
michael
parents: 5215
diff changeset
52 const uint8_t *table, *vect;
michael
parents: 5215
diff changeset
53 uint8_t *out;
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
54 int i, j, x, y, stride, vect_w = 3, vect_h = 3;
8298
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
55 AvsVideoSubType sub_type;
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
56 AvsBlockType type;
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
57 GetBitContext change_map;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
58
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
59 if (avctx->reget_buffer(avctx, p)) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
60 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
61 return -1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
62 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
63 p->reference = 1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
64 p->pict_type = FF_P_TYPE;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
65 p->key_frame = 0;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
66
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
67 out = avs->picture.data[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
68 stride = avs->picture.linesize[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
69
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
70 sub_type = buf[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
71 type = buf[1];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
72 buf += 4;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
73
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
74 if (type == AVS_PALETTE) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
75 int first, last;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
76 uint32_t *pal = (uint32_t *) avs->picture.data[1];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
77
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
78 first = AV_RL16(buf);
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 3947
diff changeset
79 last = first + AV_RL16(buf + 2);
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
80 buf += 4;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
81 for (i=first; i<last; i++, buf+=3)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
82 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
83
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
84 sub_type = buf[0];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
85 type = buf[1];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
86 buf += 4;
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
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
89 if (type != AVS_VIDEO)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
90 return -1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
91
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
92 switch (sub_type) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
93 case AVS_I_FRAME:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
94 p->pict_type = FF_I_TYPE;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
95 p->key_frame = 1;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
96 case AVS_P_FRAME_3X3:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
97 vect_w = 3;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
98 vect_h = 3;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
99 break;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
100
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
101 case AVS_P_FRAME_2X2:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
102 vect_w = 2;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
103 vect_h = 2;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
104 break;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
105
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
106 case AVS_P_FRAME_2X3:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
107 vect_w = 2;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
108 vect_h = 3;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
109 break;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
110
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
111 default:
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
112 return -1;
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
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
115 table = buf + (256 * vect_w * vect_h);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
116 if (sub_type != AVS_I_FRAME) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
117 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
118 init_get_bits(&change_map, table, map_size);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
119 table += map_size;
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
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
122 for (y=0; y<198; y+=vect_h) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
123 for (x=0; x<318; x+=vect_w) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
124 if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
125 vect = &buf[*table++ * (vect_w * vect_h)];
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
126 for (j=0; j<vect_w; j++) {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
127 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
128 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
129 if (vect_h == 3)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
130 out[(y + 2) * stride + x + j] =
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
131 vect[(2 * vect_w) + j];
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 }
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
135 if (sub_type != AVS_I_FRAME)
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
136 align_get_bits(&change_map);
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
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
139 *picture = *(AVFrame *) & avs->picture;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
140 *data_size = sizeof(AVPicture);
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
141
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
142 return buf_size;
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
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6226
diff changeset
145 static av_cold int avs_decode_init(AVCodecContext * avctx)
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
146 {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
147 avctx->pix_fmt = PIX_FMT_PAL8;
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
148 return 0;
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
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
151 AVCodec avs_decoder = {
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
152 "avs",
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
153 CODEC_TYPE_VIDEO,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
154 CODEC_ID_AVS,
8298
2dcc437528fa avoid POSIX reserved _t suffix
aurel
parents: 7040
diff changeset
155 sizeof(AvsContext),
3129
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
156 avs_decode_init,
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 NULL,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
159 avs_decode_frame,
0ebbd476ba32 complete AVS playback system (from Creature Shock computer game),
melanson
parents:
diff changeset
160 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6712
diff changeset
161 .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
162 };