annotate libmpcodecs/vd_lzo.c @ 22063:34bc7e626d2b

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