annotate libmpcodecs/vd_lzo.c @ 17048:9e02b9cb171b

Fix URL escaping to correctly handle URL containing an ip6 address or escaped special chars like & or ;
author albeu
date Sat, 26 Nov 2005 15:57:39 +0000
parents 9fc45fe0d444
children c7b1b78f14bd
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 //printf("[%s] Query!! (%s)\n", MOD_NAME, (codec==IMGFMT_BGR24)?"BGR":"none");
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
39 //printf("[%s] Query!! (%s)\n", MOD_NAME, (codec==IMGFMT_YV12)?"YV12":"none");
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
40 switch(cmd){
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
41 case VDCTRL_QUERY_FORMAT:
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
42 if( (*((int*)arg)) == IMGFMT_BGR24 && priv->codec == IMGFMT_BGR24) return CONTROL_TRUE;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
43 if( (*((int*)arg)) == IMGFMT_YV12 && priv->codec == IMGFMT_YV12) return CONTROL_TRUE;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
44 return CONTROL_FALSE;
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 return CONTROL_UNKNOWN;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
47 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
48
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
49
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
50 // init driver
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
51 static int init(sh_video_t *sh)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
52 {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
53 lzo_context_t *priv;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
54
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
55 if (lzo_init() != LZO_E_OK) {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
56 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
57 return 0;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
58 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
59
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
60 priv = malloc(sizeof(lzo_context_t));
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
61 if (!priv)
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 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
64 return 0;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
65 }
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
66 priv->codec = -1;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
67 sh->context = priv;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
68
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
69 priv->wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS);
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
70
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
71 if (priv->wrkmem == NULL) {
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
72 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
73 return 0;
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 return 1;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
77 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
78
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
79 // uninit driver
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
80 static void uninit(sh_video_t *sh)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
81 {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
82 lzo_context_t *priv = sh->context;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
83
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
84 if (priv)
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
85 {
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
86 if (priv->wrkmem)
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
87 lzo_free(priv->wrkmem);
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
88 free(priv);
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
89 }
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
90
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
91 sh->context = NULL;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
92 }
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 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
95
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
96 // decode a frame
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
97 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
98 {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
99 static int init_done = 0;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
100 int r;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
101 mp_image_t* mpi;
8123
9fc45fe0d444 *HUGE* set of compiler warning fixes, unused variables removal
arpi
parents: 7959
diff changeset
102 int w;
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
103 lzo_context_t *priv = sh->context;
7729
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 (len <= 0) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
106 return NULL; // skipped frame
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
109
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
110 if (!init_done) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
111 lzo_byte *tmp=NULL;
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 // decompress one frame to see if its
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
114 // either YV12 or RGB24
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
115 if (!tmp) tmp = lzo_malloc(sh->bih->biSizeImage);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
116
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
117 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
118 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
119 );
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
120
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
121 /* decompress the frame */
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
122 r = lzo1x_decompress (data, len, tmp, &w, priv->wrkmem);
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
123
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
124 if (r != LZO_E_OK) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
125 /* this should NEVER happen */
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
126 mp_msg (MSGT_DECVIDEO, MSGL_ERR,
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
127 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
128 return NULL;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
129 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
130
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
131 if (w == (sh->bih->biSizeImage)) {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
132 priv->codec = IMGFMT_BGR24;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
133 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
134 } else if (w == (sh->bih->biSizeImage)/2) {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
135 priv->codec = IMGFMT_YV12;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
136 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
137 } else {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
138 priv->codec = -1;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
139 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
140 return NULL;
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
7941
0c8d85e22ff5 config_vo error handling
arpi
parents: 7800
diff changeset
143 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
144 init_done++;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
145 free(tmp);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
146 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
147
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
148 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0,
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
149 sh->disp_w, sh->disp_h);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
150
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
151
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
152 if (!mpi) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
153 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
154 return NULL;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
155 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
156
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
157 r = lzo1x_decompress (data, len, mpi->planes[0], &w, priv->wrkmem);
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
158 if (r != LZO_E_OK) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
159 /* this should NEVER happen */
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
160 mp_msg (MSGT_DECVIDEO, MSGL_ERR,
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
161 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
162 return NULL;
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
165 mp_msg (MSGT_DECVIDEO, MSGL_DBG2,
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
166 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME,
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
167 (long) len, (long)w);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
168
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
169 return mpi;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
170 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
171
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
172 /* vim: sw=4
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
173 */