annotate cscd.c @ 12530:63edd10ad4bc libavcodec tip

Try to fix crashes introduced by r25218 r25218 made assumptions about the existence of past reference frames that weren't necessarily true.
author darkshikari
date Tue, 28 Sep 2010 09:06:22 +0000
parents 8cafb4db28cb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
1 /*
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
2 * CamStudio decoder
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
3 * Copyright (c) 2006 Reimar Doeffinger
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3060
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3060
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3060
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
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: 3060
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3060
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
15 * Lesser General Public License for more details.
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
16 *
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
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: 3060
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 3034
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
20 */
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
21 #include <stdio.h>
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
22 #include <stdlib.h>
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
23
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
24 #include "avcodec.h"
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
25
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 7823
diff changeset
26 #if CONFIG_ZLIB
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
27 #include <zlib.h>
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
28 #endif
6763
f7cbb7733146 Use full path for #includes from another directory.
diego
parents: 6710
diff changeset
29 #include "libavutil/lzo.h"
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
30
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
31 typedef struct {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
32 AVFrame pic;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
33 int linelen, height, bpp;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
34 unsigned int decomp_size;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
35 unsigned char* decomp_buf;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
36 } CamStudioContext;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
37
12482
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
38 static void copy_frame_default(AVFrame *f, const uint8_t *src, int src_stride,
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
39 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
40 int i;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
41 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
42 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
43 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
44 memcpy(dst, src, linelen);
12482
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
45 src += src_stride;
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
46 dst -= f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
47 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
48 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
49
12482
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
50 static void add_frame_default(AVFrame *f, const uint8_t *src, int src_stride,
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
51 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
52 int i, j;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
53 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
54 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
55 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
56 for (j = linelen; j; j--)
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
57 *dst++ += *src++;
12482
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
58 src += src_stride - linelen;
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
59 dst -= f->linesize[0] + linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
60 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
61 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
62
9985
266bf83f634d Replace WORDS_BIGENDIAN with HAVE_BIGENDIAN
mru
parents: 9355
diff changeset
63 #if !HAVE_BIGENDIAN
12482
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
64 #define copy_frame_16(f, s, l, h) copy_frame_default(f, s, l, l, h)
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
65 #define copy_frame_32(f, s, l, h) copy_frame_default(f, s, l, l, h)
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
66 #define add_frame_16(f, s, l, h) add_frame_default(f, s, l, l, h)
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
67 #define add_frame_32(f, s, l, h) add_frame_default(f, s, l, l, h)
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
68 #else
6312
5f4bdfd1aa0e Some consts for cscd decoder helper functions
reimar
parents: 6262
diff changeset
69 static void copy_frame_16(AVFrame *f, const uint8_t *src,
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
70 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
71 int i, j;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
72 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
73 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
74 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
75 for (j = linelen / 2; j; j--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
76 dst[0] = src[1];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
77 dst[1] = src[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
78 src += 2;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
79 dst += 2;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
80 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
81 dst -= f->linesize[0] + linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
82 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
83 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
84
6312
5f4bdfd1aa0e Some consts for cscd decoder helper functions
reimar
parents: 6262
diff changeset
85 static void copy_frame_32(AVFrame *f, const uint8_t *src,
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
86 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
87 int i, j;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
88 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
89 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
90 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
91 for (j = linelen / 4; j; j--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
92 dst[0] = src[3];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
93 dst[1] = src[2];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
94 dst[2] = src[1];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
95 dst[3] = src[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
96 src += 4;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
97 dst += 4;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
98 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
99 dst -= f->linesize[0] + linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
100 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
101 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
102
6312
5f4bdfd1aa0e Some consts for cscd decoder helper functions
reimar
parents: 6262
diff changeset
103 static void add_frame_16(AVFrame *f, const uint8_t *src,
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
104 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
105 int i, j;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
106 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
107 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
108 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
109 for (j = linelen / 2; j; j--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
110 dst[0] += src[1];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
111 dst[1] += src[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
112 src += 2;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
113 dst += 2;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
114 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
115 dst -= f->linesize[0] + linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
116 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
117 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
118
6312
5f4bdfd1aa0e Some consts for cscd decoder helper functions
reimar
parents: 6262
diff changeset
119 static void add_frame_32(AVFrame *f, const uint8_t *src,
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
120 int linelen, int height) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
121 int i, j;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
122 uint8_t *dst = f->data[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
123 dst += (height - 1) * f->linesize[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
124 for (i = height; i; i--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
125 for (j = linelen / 4; j; j--) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
126 dst[0] += src[3];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
127 dst[1] += src[2];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
128 dst[2] += src[1];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
129 dst[3] += src[0];
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
130 src += 4;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
131 dst += 4;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
132 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
133 dst -= f->linesize[0] + linelen;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
134 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
135 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
136 #endif
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
137
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
138 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8732
diff changeset
139 AVPacket *avpkt) {
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8732
diff changeset
140 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8732
diff changeset
141 int buf_size = avpkt->size;
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
142 CamStudioContext *c = avctx->priv_data;
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
143 AVFrame *picture = data;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
144
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
145 if (buf_size < 2) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
146 av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
147 return -1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
148 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
149
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
150 if (c->pic.data[0])
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
151 avctx->release_buffer(avctx, &c->pic);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
152 c->pic.reference = 1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
153 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE |
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
154 FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
155 if (avctx->get_buffer(avctx, &c->pic) < 0) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
156 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
157 return -1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
158 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
159
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
160 // decompress data
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
161 switch ((buf[0] >> 1) & 7) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
162 case 0: { // lzo compression
3034
d37065d8aeff Our own LZO (1X) implementation, under LGPL and optimized for readability.
reimar
parents: 3030
diff changeset
163 int outlen = c->decomp_size, inlen = buf_size - 2;
8732
967c0a1a60a0 Add av_ prefix to LZO stuff and thus make it officially part of the public API.
reimar
parents: 8590
diff changeset
164 if (av_lzo1x_decode(c->decomp_buf, &outlen, &buf[2], &inlen))
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
165 av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
166 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
167 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
168 case 1: { // zlib compression
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 7823
diff changeset
169 #if CONFIG_ZLIB
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
170 unsigned long dlen = c->decomp_size;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
171 if (uncompress(c->decomp_buf, &dlen, &buf[2], buf_size - 2) != Z_OK)
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
172 av_log(avctx, AV_LOG_ERROR, "error during zlib decompression\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
173 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
174 #else
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
175 av_log(avctx, AV_LOG_ERROR, "compiled without zlib support\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
176 return -1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
177 #endif
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
178 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
179 default:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
180 av_log(avctx, AV_LOG_ERROR, "unknown compression\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
181 return -1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
182 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
183
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
184 // flip upside down, add difference frame
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
185 if (buf[0] & 1) { // keyframe
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
186 c->pic.pict_type = FF_I_TYPE;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
187 c->pic.key_frame = 1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
188 switch (c->bpp) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
189 case 16:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
190 copy_frame_16(&c->pic, c->decomp_buf, c->linelen, c->height);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
191 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
192 case 32:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
193 copy_frame_32(&c->pic, c->decomp_buf, c->linelen, c->height);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
194 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
195 default:
12482
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
196 copy_frame_default(&c->pic, c->decomp_buf, FFALIGN(c->linelen, 4),
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
197 c->linelen, c->height);
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
198 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
199 } else {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
200 c->pic.pict_type = FF_P_TYPE;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
201 c->pic.key_frame = 0;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
202 switch (c->bpp) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
203 case 16:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
204 add_frame_16(&c->pic, c->decomp_buf, c->linelen, c->height);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
205 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
206 case 32:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
207 add_frame_32(&c->pic, c->decomp_buf, c->linelen, c->height);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
208 break;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
209 default:
12482
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
210 add_frame_default(&c->pic, c->decomp_buf, FFALIGN(c->linelen, 4),
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
211 c->linelen, c->height);
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
212 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
213 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
214
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
215 *picture = c->pic;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
216 *data_size = sizeof(AVFrame);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
217 return buf_size;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
218 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
219
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6312
diff changeset
220 static av_cold int decode_init(AVCodecContext *avctx) {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
221 CamStudioContext *c = avctx->priv_data;
12482
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
222 int stride;
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7040
diff changeset
223 switch (avctx->bits_per_coded_sample) {
4290
e7dfc2743e26 Fix 16 bit cscd samples, 16 bit raw means RGB555 on Windows, and the original
reimar
parents: 4289
diff changeset
224 case 16: avctx->pix_fmt = PIX_FMT_RGB555; break;
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
225 case 24: avctx->pix_fmt = PIX_FMT_BGR24; break;
4494
ce643a22f049 Replace deprecated PIX_FMT names by the newer variants.
diego
parents: 4290
diff changeset
226 case 32: avctx->pix_fmt = PIX_FMT_RGB32; break;
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
227 default:
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
228 av_log(avctx, AV_LOG_ERROR,
4289
b2a291ea653f Typo in error message
reimar
parents: 3947
diff changeset
229 "CamStudio codec error: invalid depth %i bpp\n",
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7040
diff changeset
230 avctx->bits_per_coded_sample);
12479
ca1896830b44 Fix indentation.
reimar
parents: 11560
diff changeset
231 return 1;
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
232 }
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7040
diff changeset
233 c->bpp = avctx->bits_per_coded_sample;
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
234 c->pic.data[0] = NULL;
7823
4525dcd81357 Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 7040
diff changeset
235 c->linelen = avctx->width * avctx->bits_per_coded_sample / 8;
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
236 c->height = avctx->height;
12482
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
237 stride = c->linelen;
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
238 if (avctx->bits_per_coded_sample == 24)
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
239 stride = FFALIGN(stride, 4);
8cafb4db28cb Fix 24 bpp CSCD decoding, as for Windows bitmaps in this (and only this)
reimar
parents: 12479
diff changeset
240 c->decomp_size = c->height * stride;
8732
967c0a1a60a0 Add av_ prefix to LZO stuff and thus make it officially part of the public API.
reimar
parents: 8590
diff changeset
241 c->decomp_buf = av_malloc(c->decomp_size + AV_LZO_OUTPUT_PADDING);
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
242 if (!c->decomp_buf) {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
243 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
244 return 1;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
245 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
246 return 0;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
247 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
248
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6312
diff changeset
249 static av_cold int decode_end(AVCodecContext *avctx) {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4801
diff changeset
250 CamStudioContext *c = avctx->priv_data;
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
251 av_freep(&c->decomp_buf);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
252 if (c->pic.data[0])
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
253 avctx->release_buffer(avctx, &c->pic);
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
254 return 0;
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
255 }
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
256
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
257 AVCodec cscd_decoder = {
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
258 "camstudio",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 10397
diff changeset
259 AVMEDIA_TYPE_VIDEO,
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
260 CODEC_ID_CSCD,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
261 sizeof(CamStudioContext),
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
262 decode_init,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
263 NULL,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
264 decode_end,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
265 decode_frame,
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
266 CODEC_CAP_DR1,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6763
diff changeset
267 .long_name = NULL_IF_CONFIG_SMALL("CamStudio"),
3030
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
268 };
6bc2dc147ac5 CamStudio decoder, only 32 bit lzo mode is tested
reimar
parents:
diff changeset
269