Mercurial > mplayer.hg
annotate libmpcodecs/vd_lzo.c @ 22077:40135eba142f
Avoid a static variable and instead use variable in context
author | reimar |
---|---|
date | Wed, 31 Jan 2007 22:15:51 +0000 |
parents | 34bc7e626d2b |
children | 9fd2145ddb43 |
rev | line source |
---|---|
7729 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "config.h" | |
5 #include "mp_msg.h" | |
6 | |
7 #include "vd_internal.h" | |
8 | |
7959 | 9 #ifdef USE_LIBLZO |
7729 | 10 #include <lzo1x.h> |
7799 | 11 #else |
12 #include "native/minilzo.h" | |
13 #define lzo_malloc malloc | |
14 #define lzo_free free | |
15 #endif | |
7729 | 16 |
17 #define MOD_NAME "DecLZO" | |
18 | |
19 static vd_info_t info = { | |
20 "LZO compressed Video", | |
21 "lzo", | |
22 "Tilmann Bitterberg", | |
23 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>", | |
24 "based on liblzo: http://www.oberhumer.com/opensource/lzo/" | |
25 }; | |
26 | |
27 LIBVD_EXTERN(lzo) | |
28 | |
7800 | 29 typedef struct { |
30 lzo_byte *wrkmem; | |
31 int codec; | |
32 } lzo_context_t; | |
7729 | 33 |
34 // to set/get/query special features/parameters | |
35 static int control (sh_video_t *sh, int cmd, void* arg, ...) | |
36 { | |
7800 | 37 lzo_context_t *priv = sh->context; |
7729 | 38 switch(cmd){ |
39 case VDCTRL_QUERY_FORMAT: | |
22062 | 40 if (*(int *)arg == priv->codec) return CONTROL_TRUE; |
7729 | 41 return CONTROL_FALSE; |
42 } | |
43 return CONTROL_UNKNOWN; | |
44 } | |
45 | |
46 | |
47 // init driver | |
48 static int init(sh_video_t *sh) | |
49 { | |
7800 | 50 lzo_context_t *priv; |
7729 | 51 |
52 if (lzo_init() != LZO_E_OK) { | |
7800 | 53 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] lzo_init() failed\n", MOD_NAME); |
7729 | 54 return 0; |
55 } | |
56 | |
7800 | 57 priv = malloc(sizeof(lzo_context_t)); |
58 if (!priv) | |
59 { | |
60 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] memory allocation failed\n", MOD_NAME); | |
61 return 0; | |
62 } | |
63 priv->codec = -1; | |
64 sh->context = priv; | |
7729 | 65 |
7800 | 66 priv->wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS); |
67 | |
68 if (priv->wrkmem == NULL) { | |
7729 | 69 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Cannot alloc work memory\n", MOD_NAME); |
70 return 0; | |
71 } | |
72 | |
73 return 1; | |
74 } | |
75 | |
76 // uninit driver | |
77 static void uninit(sh_video_t *sh) | |
78 { | |
7800 | 79 lzo_context_t *priv = sh->context; |
80 | |
81 if (priv) | |
82 { | |
83 if (priv->wrkmem) | |
84 lzo_free(priv->wrkmem); | |
85 free(priv); | |
86 } | |
87 | |
88 sh->context = NULL; | |
7729 | 89 } |
90 | |
91 // decode a frame | |
92 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags) | |
93 { | |
94 int r; | |
95 mp_image_t* mpi; | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7959
diff
changeset
|
96 int w; |
7800 | 97 lzo_context_t *priv = sh->context; |
7729 | 98 |
99 if (len <= 0) { | |
100 return NULL; // skipped frame | |
101 } | |
102 | |
103 | |
22077
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
104 if (priv->codec == -1) { |
22061 | 105 lzo_byte *tmp = lzo_malloc(sh->bih->biSizeImage); |
7729 | 106 |
107 // decompress one frame to see if its | |
108 // either YV12 or RGB24 | |
109 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n", | |
110 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage | |
111 ); | |
112 | |
113 /* decompress the frame */ | |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17768
diff
changeset
|
114 w = sh->bih->biSizeImage; |
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17768
diff
changeset
|
115 r = lzo1x_decompress_safe (data, len, tmp, &w, priv->wrkmem); |
17768
c7b1b78f14bd
free tmp earlier, it is not needed below and might leak on errors otherwise
reimar
parents:
8123
diff
changeset
|
116 free(tmp); |
7729 | 117 |
118 if (r != LZO_E_OK) { | |
119 /* this should NEVER happen */ | |
120 mp_msg (MSGT_DECVIDEO, MSGL_ERR, | |
121 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r); | |
122 return NULL; | |
123 } | |
124 | |
125 if (w == (sh->bih->biSizeImage)) { | |
7800 | 126 priv->codec = IMGFMT_BGR24; |
7729 | 127 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is BGR24\n", MOD_NAME); |
128 } else if (w == (sh->bih->biSizeImage)/2) { | |
7800 | 129 priv->codec = IMGFMT_YV12; |
7729 | 130 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is YV12\n", MOD_NAME); |
131 } else { | |
7800 | 132 priv->codec = -1; |
7729 | 133 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME); |
134 return NULL; | |
135 } | |
136 | |
22077
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
137 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,priv->codec)) { |
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
138 priv->codec = -1; |
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
139 return NULL; |
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
140 } |
7729 | 141 } |
142 | |
143 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, | |
144 sh->disp_w, sh->disp_h); | |
145 | |
146 | |
147 if (!mpi) { | |
148 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME); | |
149 return NULL; | |
150 } | |
151 | |
22060 | 152 w = (mpi->w * mpi->h * mpi->bpp) / 8; |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17768
diff
changeset
|
153 r = lzo1x_decompress_safe (data, len, mpi->planes[0], &w, priv->wrkmem); |
7729 | 154 if (r != LZO_E_OK) { |
155 /* this should NEVER happen */ | |
156 mp_msg (MSGT_DECVIDEO, MSGL_ERR, | |
157 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r); | |
158 return NULL; | |
159 } | |
160 | |
161 mp_msg (MSGT_DECVIDEO, MSGL_DBG2, | |
162 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME, | |
163 (long) len, (long)w); | |
164 | |
165 return mpi; | |
166 } | |
167 | |
168 /* vim: sw=4 | |
169 */ |