annotate vb.c @ 11026:f5678fb91140 libavcodec

Update comment.
author michael
date Wed, 27 Jan 2010 13:18:08 +0000
parents 3dd1cb77cc60
children 8a4984c5cacc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
1 /*
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
2 * Beam Software VB decoder
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
3 * Copyright (c) 2007 Konstantin Shishkov
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
4 *
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
5 * This file is part of FFmpeg.
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
6 *
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
11 *
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
15 * Lesser General Public License for more details.
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
16 *
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
20 */
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
21
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
22 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 7040
diff changeset
23 * @file libavcodec/vb.c
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
24 * VB Video decoder
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
25 */
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
26
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
27 #include <stdio.h>
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
28 #include <stdlib.h>
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
29
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
30 #include "avcodec.h"
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
31 #include "bytestream.h"
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
32
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
33 enum VBFlags{
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
34 VB_HAS_GMC = 0x01,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
35 VB_HAS_AUDIO = 0x04,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
36 VB_HAS_VIDEO = 0x08,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
37 VB_HAS_PALETTE = 0x10,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
38 VB_HAS_LENGTH = 0x20
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
39 };
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
40
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
41 typedef struct VBDecContext {
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
42 AVCodecContext *avctx;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
43 AVFrame pic;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
44
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
45 uint8_t *frame, *prev_frame;
10972
3dd1cb77cc60 Use AVPALETTE_COUNT instead of hard-coding 256.
reimar
parents: 10971
diff changeset
46 uint32_t pal[AVPALETTE_COUNT];
6218
michael
parents: 5847
diff changeset
47 const uint8_t *stream;
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
48 } VBDecContext;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
49
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
50 static const uint16_t vb_patterns[64] = {
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
51 0x0660, 0xFF00, 0xCCCC, 0xF000, 0x8888, 0x000F, 0x1111, 0xFEC8,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
52 0x8CEF, 0x137F, 0xF731, 0xC800, 0x008C, 0x0013, 0x3100, 0xCC00,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
53 0x00CC, 0x0033, 0x3300, 0x0FF0, 0x6666, 0x00F0, 0x0F00, 0x2222,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
54 0x4444, 0xF600, 0x8CC8, 0x006F, 0x1331, 0x318C, 0xC813, 0x33CC,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
55 0x6600, 0x0CC0, 0x0066, 0x0330, 0xF900, 0xC88C, 0x009F, 0x3113,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
56 0x6000, 0x0880, 0x0006, 0x0110, 0xCC88, 0xFC00, 0x00CF, 0x88CC,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
57 0x003F, 0x1133, 0x3311, 0xF300, 0x6FF6, 0x0603, 0x08C6, 0x8C63,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
58 0xC631, 0x6310, 0xC060, 0x0136, 0x136C, 0x36C8, 0x6C80, 0x324C
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
59 };
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
60
10963
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
61 static void vb_decode_palette(VBDecContext *c, int data_size)
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
62 {
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
63 int start, size, i;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
64
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
65 start = bytestream_get_byte(&c->stream);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
66 size = (bytestream_get_byte(&c->stream) - 1) & 0xFF;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
67 if(start + size > 255){
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
68 av_log(c->avctx, AV_LOG_ERROR, "Palette change runs beyond entry 256\n");
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
69 return;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
70 }
10963
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
71 if(size*3+2 > data_size){
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
72 av_log(c->avctx, AV_LOG_ERROR, "Palette data runs beyond chunk size\n");
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
73 return;
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
74 }
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
75 for(i = start; i <= start + size; i++)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
76 c->pal[i] = bytestream_get_be24(&c->stream);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
77 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
78
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
79 static inline int check_pixel(uint8_t *buf, uint8_t *start, uint8_t *end)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
80 {
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
81 return buf >= start && buf < end;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
82 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
83
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
84 static inline int check_line(uint8_t *buf, uint8_t *start, uint8_t *end)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
85 {
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
86 return buf >= start && (buf + 4) <= end;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
87 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
88
10963
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
89 static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int data_size, int offset)
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
90 {
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
91 uint8_t *prev, *cur;
10963
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
92 const uint8_t* data_end = buf + data_size;
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
93 int blk, blocks, t, blk2;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
94 int blocktypes = 0;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
95 int x, y, a, b;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
96 int pattype, pattern;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
97 const int width = c->avctx->width;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
98 uint8_t *pstart = c->prev_frame;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
99 uint8_t *pend = c->prev_frame + width*c->avctx->height;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
100
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
101 prev = c->prev_frame + offset;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
102 cur = c->frame;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
103
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
104 blocks = (c->avctx->width >> 2) * (c->avctx->height >> 2);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
105 blk2 = 0;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
106 for(blk = 0; blk < blocks; blk++){
10963
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
107 if(!(blk & 3)) {
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
108 if(buf >= data_end){
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
109 av_log(c->avctx, AV_LOG_ERROR, "Data pointer out of bounds\n");
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
110 return -1;
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
111 }
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
112 blocktypes = bytestream_get_byte(&buf);
10963
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
113 }
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
114 switch(blocktypes & 0xC0){
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
115 case 0x00: //skip
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
116 for(y = 0; y < 4; y++)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
117 if(check_line(prev + y*width, pstart, pend))
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
118 memcpy(cur + y*width, prev + y*width, 4);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
119 else
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
120 memset(cur + y*width, 0, 4);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
121 break;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
122 case 0x40:
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
123 t = bytestream_get_byte(&buf);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
124 if(!t){ //raw block
10963
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
125 if(buf + 16 > data_end){
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
126 av_log(c->avctx, AV_LOG_ERROR, "Insufficient data\n");
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
127 return -1;
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
128 }
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
129 for(y = 0; y < 4; y++)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
130 memcpy(cur + y*width, buf + y*4, 4);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
131 buf += 16;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
132 }else{ // motion compensation
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
133 x = ((t & 0xF)^8) - 8;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
134 y = ((t >> 4) ^8) - 8;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
135 t = x + y*width;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
136 for(y = 0; y < 4; y++)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
137 if(check_line(prev + t + y*width, pstart, pend))
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
138 memcpy(cur + y*width, prev + t + y*width, 4);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
139 else
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
140 memset(cur + y*width, 0, 4);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
141 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
142 break;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
143 case 0x80: // fill
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
144 t = bytestream_get_byte(&buf);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
145 for(y = 0; y < 4; y++)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
146 memset(cur + y*width, t, 4);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
147 break;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
148 case 0xC0: // pattern fill
10963
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
149 if(buf + 2 > data_end){
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
150 av_log(c->avctx, AV_LOG_ERROR, "Insufficient data\n");
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
151 return -1;
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
152 }
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
153 t = bytestream_get_byte(&buf);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
154 pattype = t >> 6;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
155 pattern = vb_patterns[t & 0x3F];
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
156 switch(pattype){
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
157 case 0:
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
158 a = bytestream_get_byte(&buf);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
159 b = bytestream_get_byte(&buf);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
160 for(y = 0; y < 4; y++)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
161 for(x = 0; x < 4; x++, pattern >>= 1)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
162 cur[x + y*width] = (pattern & 1) ? b : a;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
163 break;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
164 case 1:
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
165 pattern = ~pattern;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
166 case 2:
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
167 a = bytestream_get_byte(&buf);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
168 for(y = 0; y < 4; y++)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
169 for(x = 0; x < 4; x++, pattern >>= 1)
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
170 if(pattern & 1 && check_pixel(prev + x + y*width, pstart, pend))
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
171 cur[x + y*width] = prev[x + y*width];
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
172 else
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
173 cur[x + y*width] = a;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
174 break;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
175 case 3:
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
176 av_log(c->avctx, AV_LOG_ERROR, "Invalid opcode seen @%d\n",blk);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
177 return -1;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
178 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
179 break;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
180 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
181 blocktypes <<= 2;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
182 cur += 4;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
183 prev += 4;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
184 blk2++;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
185 if(blk2 == (width >> 2)){
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
186 blk2 = 0;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
187 cur += width * 3;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
188 prev += width * 3;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
189 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
190 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
191 return 0;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
192 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
193
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
194 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
195 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
196 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
197 int buf_size = avpkt->size;
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
198 VBDecContext * const c = avctx->priv_data;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
199 uint8_t *outptr, *srcptr;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
200 int i, j;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
201 int flags;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
202 uint32_t size;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
203 int rest = buf_size;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
204 int offset = 0;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
205
9821
0813b30e7db9 Get new buffer during frame decoding in VB video decoder, not only once
kostya
parents: 9355
diff changeset
206 if(c->pic.data[0])
0813b30e7db9 Get new buffer during frame decoding in VB video decoder, not only once
kostya
parents: 9355
diff changeset
207 avctx->release_buffer(avctx, &c->pic);
0813b30e7db9 Get new buffer during frame decoding in VB video decoder, not only once
kostya
parents: 9355
diff changeset
208 c->pic.reference = 1;
0813b30e7db9 Get new buffer during frame decoding in VB video decoder, not only once
kostya
parents: 9355
diff changeset
209 if(avctx->get_buffer(avctx, &c->pic) < 0){
0813b30e7db9 Get new buffer during frame decoding in VB video decoder, not only once
kostya
parents: 9355
diff changeset
210 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
0813b30e7db9 Get new buffer during frame decoding in VB video decoder, not only once
kostya
parents: 9355
diff changeset
211 return -1;
0813b30e7db9 Get new buffer during frame decoding in VB video decoder, not only once
kostya
parents: 9355
diff changeset
212 }
0813b30e7db9 Get new buffer during frame decoding in VB video decoder, not only once
kostya
parents: 9355
diff changeset
213
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
214 c->stream = buf;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
215 flags = bytestream_get_le16(&c->stream);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
216 rest -= 2;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
217
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
218 if(flags & VB_HAS_GMC){
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
219 i = (int16_t)bytestream_get_le16(&c->stream);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
220 j = (int16_t)bytestream_get_le16(&c->stream);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
221 offset = i + j * avctx->width;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
222 rest -= 4;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
223 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
224 if(flags & VB_HAS_VIDEO){
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
225 size = bytestream_get_le32(&c->stream);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
226 if(size > rest){
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
227 av_log(avctx, AV_LOG_ERROR, "Frame size is too big\n");
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
228 return -1;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
229 }
10963
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
230 vb_decode_framedata(c, c->stream, size, offset);
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
231 c->stream += size - 4;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
232 rest -= size;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
233 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
234 if(flags & VB_HAS_PALETTE){
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
235 size = bytestream_get_le32(&c->stream);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
236 if(size > rest){
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
237 av_log(avctx, AV_LOG_ERROR, "Palette size is too big\n");
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
238 return -1;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
239 }
10963
81033a080136 Check for chunk boundaries when decoding VB codec data
kostya
parents: 10962
diff changeset
240 vb_decode_palette(c, size);
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
241 rest -= size;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
242 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
243
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
244 memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
245 c->pic.palette_has_changed = flags & VB_HAS_PALETTE;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
246
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
247 outptr = c->pic.data[0];
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
248 srcptr = c->frame;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
249
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
250 for(i = 0; i < avctx->height; i++){
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
251 memcpy(outptr, srcptr, avctx->width);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
252 srcptr += avctx->width;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
253 outptr += c->pic.linesize[0];
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
254 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
255
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
256 FFSWAP(uint8_t*, c->frame, c->prev_frame);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
257
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
258 *data_size = sizeof(AVFrame);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
259 *(AVFrame*)data = c->pic;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
260
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
261 /* always report that the buffer was completely consumed */
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
262 return buf_size;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
263 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
264
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
265 static av_cold int decode_init(AVCodecContext *avctx)
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
266 {
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
267 VBDecContext * const c = avctx->priv_data;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
268
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
269 c->avctx = avctx;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
270 avctx->pix_fmt = PIX_FMT_PAL8;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
271
10967
1c3a10f94570 Zero the frame data on allocation for VB codec, e.g. the FATE sample seems to
reimar
parents: 10963
diff changeset
272 c->frame = av_mallocz(avctx->width * avctx->height);
1c3a10f94570 Zero the frame data on allocation for VB codec, e.g. the FATE sample seems to
reimar
parents: 10963
diff changeset
273 c->prev_frame = av_mallocz(avctx->width * avctx->height);
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
274
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
275 return 0;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
276 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
277
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
278 static av_cold int decode_end(AVCodecContext *avctx)
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
279 {
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
280 VBDecContext *c = avctx->priv_data;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
281
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
282 av_freep(&c->frame);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
283 av_freep(&c->prev_frame);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
284 if(c->pic.data[0])
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
285 avctx->release_buffer(avctx, &c->pic);
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
286
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
287 return 0;
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
288 }
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
289
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
290 AVCodec vb_decoder = {
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
291 "vb",
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
292 CODEC_TYPE_VIDEO,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
293 CODEC_ID_VB,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
294 sizeof(VBDecContext),
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
295 decode_init,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
296 NULL,
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
297 decode_end,
6710
a4104482ceef Add long names to many AVCodec declarations.
diego
parents: 6517
diff changeset
298 decode_frame,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6710
diff changeset
299 .long_name = NULL_IF_CONFIG_SMALL("Beam Software VB"),
5847
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
300 };
82ac47c0c6dd Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
301