Mercurial > mplayer.hg
annotate libmpcodecs/vd_lzo.c @ 13255:3cc935e177d2
Sorry, typo
author | kraymer |
---|---|
date | Sun, 05 Sep 2004 22:01:23 +0000 |
parents | 9fc45fe0d444 |
children | c7b1b78f14bd |
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 //printf("[%s] Query!! (%s)\n", MOD_NAME, (codec==IMGFMT_BGR24)?"BGR":"none"); |
39 //printf("[%s] Query!! (%s)\n", MOD_NAME, (codec==IMGFMT_YV12)?"YV12":"none"); | |
40 switch(cmd){ | |
41 case VDCTRL_QUERY_FORMAT: | |
7800 | 42 if( (*((int*)arg)) == IMGFMT_BGR24 && priv->codec == IMGFMT_BGR24) return CONTROL_TRUE; |
43 if( (*((int*)arg)) == IMGFMT_YV12 && priv->codec == IMGFMT_YV12) return CONTROL_TRUE; | |
7729 | 44 return CONTROL_FALSE; |
45 } | |
46 return CONTROL_UNKNOWN; | |
47 } | |
48 | |
49 | |
50 // init driver | |
51 static int init(sh_video_t *sh) | |
52 { | |
7800 | 53 lzo_context_t *priv; |
7729 | 54 |
55 if (lzo_init() != LZO_E_OK) { | |
7800 | 56 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] lzo_init() failed\n", MOD_NAME); |
7729 | 57 return 0; |
58 } | |
59 | |
7800 | 60 priv = malloc(sizeof(lzo_context_t)); |
61 if (!priv) | |
62 { | |
63 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] memory allocation failed\n", MOD_NAME); | |
64 return 0; | |
65 } | |
66 priv->codec = -1; | |
67 sh->context = priv; | |
7729 | 68 |
7800 | 69 priv->wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS); |
70 | |
71 if (priv->wrkmem == NULL) { | |
7729 | 72 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Cannot alloc work memory\n", MOD_NAME); |
73 return 0; | |
74 } | |
75 | |
76 return 1; | |
77 } | |
78 | |
79 // uninit driver | |
80 static void uninit(sh_video_t *sh) | |
81 { | |
7800 | 82 lzo_context_t *priv = sh->context; |
83 | |
84 if (priv) | |
85 { | |
86 if (priv->wrkmem) | |
87 lzo_free(priv->wrkmem); | |
88 free(priv); | |
89 } | |
90 | |
91 sh->context = NULL; | |
7729 | 92 } |
93 | |
94 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
95 | |
96 // decode a frame | |
97 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags) | |
98 { | |
99 static int init_done = 0; | |
100 int r; | |
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 | 103 lzo_context_t *priv = sh->context; |
7729 | 104 |
105 if (len <= 0) { | |
106 return NULL; // skipped frame | |
107 } | |
108 | |
109 | |
110 if (!init_done) { | |
111 lzo_byte *tmp=NULL; | |
112 | |
113 // decompress one frame to see if its | |
114 // either YV12 or RGB24 | |
115 if (!tmp) tmp = lzo_malloc(sh->bih->biSizeImage); | |
116 | |
117 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n", | |
118 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage | |
119 ); | |
120 | |
121 /* decompress the frame */ | |
7800 | 122 r = lzo1x_decompress (data, len, tmp, &w, priv->wrkmem); |
7729 | 123 |
124 if (r != LZO_E_OK) { | |
125 /* this should NEVER happen */ | |
126 mp_msg (MSGT_DECVIDEO, MSGL_ERR, | |
127 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r); | |
128 return NULL; | |
129 } | |
130 | |
131 if (w == (sh->bih->biSizeImage)) { | |
7800 | 132 priv->codec = IMGFMT_BGR24; |
7729 | 133 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is BGR24\n", MOD_NAME); |
134 } else if (w == (sh->bih->biSizeImage)/2) { | |
7800 | 135 priv->codec = IMGFMT_YV12; |
7729 | 136 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is YV12\n", MOD_NAME); |
137 } else { | |
7800 | 138 priv->codec = -1; |
7729 | 139 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME); |
140 return NULL; | |
141 } | |
142 | |
7941 | 143 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,priv->codec)) return NULL; |
7729 | 144 init_done++; |
145 free(tmp); | |
146 } | |
147 | |
148 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, | |
149 sh->disp_w, sh->disp_h); | |
150 | |
151 | |
152 if (!mpi) { | |
153 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME); | |
154 return NULL; | |
155 } | |
156 | |
7800 | 157 r = lzo1x_decompress (data, len, mpi->planes[0], &w, priv->wrkmem); |
7729 | 158 if (r != LZO_E_OK) { |
159 /* this should NEVER happen */ | |
160 mp_msg (MSGT_DECVIDEO, MSGL_ERR, | |
161 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r); | |
162 return NULL; | |
163 } | |
164 | |
165 mp_msg (MSGT_DECVIDEO, MSGL_DBG2, | |
166 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME, | |
167 (long) len, (long)w); | |
168 | |
169 return mpi; | |
170 } | |
171 | |
172 /* vim: sw=4 | |
173 */ |