Mercurial > mplayer.hg
annotate libmpcodecs/vd_lzo.c @ 22078:9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
author | reimar |
---|---|
date | Wed, 31 Jan 2007 22:17:52 +0000 |
parents | 40135eba142f |
children | d018c5b9e0e6 |
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; | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
31 uint8_t *buffer; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
32 int bufsz; |
7800 | 33 int codec; |
34 } lzo_context_t; | |
7729 | 35 |
36 // to set/get/query special features/parameters | |
37 static int control (sh_video_t *sh, int cmd, void* arg, ...) | |
38 { | |
7800 | 39 lzo_context_t *priv = sh->context; |
7729 | 40 switch(cmd){ |
41 case VDCTRL_QUERY_FORMAT: | |
22062 | 42 if (*(int *)arg == priv->codec) return CONTROL_TRUE; |
7729 | 43 return CONTROL_FALSE; |
44 } | |
45 return CONTROL_UNKNOWN; | |
46 } | |
47 | |
48 | |
49 // init driver | |
50 static int init(sh_video_t *sh) | |
51 { | |
7800 | 52 lzo_context_t *priv; |
7729 | 53 |
54 if (lzo_init() != LZO_E_OK) { | |
7800 | 55 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] lzo_init() failed\n", MOD_NAME); |
7729 | 56 return 0; |
57 } | |
58 | |
7800 | 59 priv = malloc(sizeof(lzo_context_t)); |
60 if (!priv) | |
61 { | |
62 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] memory allocation failed\n", MOD_NAME); | |
63 return 0; | |
64 } | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
65 priv->bufsz = sh->bih->biSizeImage; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
66 priv->buffer = malloc(priv->bufsz); |
7800 | 67 priv->codec = -1; |
68 sh->context = priv; | |
7729 | 69 |
7800 | 70 priv->wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS); |
71 | |
72 if (priv->wrkmem == NULL) { | |
7729 | 73 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Cannot alloc work memory\n", MOD_NAME); |
74 return 0; | |
75 } | |
76 | |
77 return 1; | |
78 } | |
79 | |
80 // uninit driver | |
81 static void uninit(sh_video_t *sh) | |
82 { | |
7800 | 83 lzo_context_t *priv = sh->context; |
84 | |
85 if (priv) | |
86 { | |
87 if (priv->wrkmem) | |
88 lzo_free(priv->wrkmem); | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
89 free(priv->buffer); |
7800 | 90 free(priv); |
91 } | |
92 | |
93 sh->context = NULL; | |
7729 | 94 } |
95 | |
96 // decode a frame | |
97 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags) | |
98 { | |
99 int r; | |
100 mp_image_t* mpi; | |
7800 | 101 lzo_context_t *priv = sh->context; |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
102 int w = priv->bufsz; |
7729 | 103 |
104 if (len <= 0) { | |
105 return NULL; // skipped frame | |
106 } | |
107 | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
108 r = lzo1x_decompress_safe (data, len, priv->buffer, &w, priv->wrkmem); |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
109 if (r != LZO_E_OK) { |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
110 /* this should NEVER happen */ |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
111 mp_msg (MSGT_DECVIDEO, MSGL_ERR, |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
112 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r); |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
113 return NULL; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
114 } |
7729 | 115 |
22077
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
116 if (priv->codec == -1) { |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
117 // detect RGB24 vs. YV12 via decoded size |
7729 | 118 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n", |
119 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage | |
120 ); | |
121 | |
122 if (w == (sh->bih->biSizeImage)) { | |
7800 | 123 priv->codec = IMGFMT_BGR24; |
7729 | 124 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is BGR24\n", MOD_NAME); |
125 } else if (w == (sh->bih->biSizeImage)/2) { | |
7800 | 126 priv->codec = IMGFMT_YV12; |
7729 | 127 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is YV12\n", MOD_NAME); |
128 } else { | |
7800 | 129 priv->codec = -1; |
7729 | 130 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME); |
131 return NULL; | |
132 } | |
133 | |
22077
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
134 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
|
135 priv->codec = -1; |
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
136 return NULL; |
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
137 } |
7729 | 138 } |
139 | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
140 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, |
7729 | 141 sh->disp_w, sh->disp_h); |
142 | |
143 | |
144 if (!mpi) { | |
145 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME); | |
146 return NULL; | |
147 } | |
148 | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
149 mpi->planes[0] = priv->buffer; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
150 if (priv->codec == IMGFMT_BGR24) |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
151 mpi->stride[0] = 3 * sh->disp_w; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
152 else { |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
153 mpi->stride[0] = sh->disp_w; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
154 mpi->planes[2] = priv->buffer + sh->disp_w*sh->disp_h; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
155 mpi->stride[2] = sh->disp_w / 2; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
156 mpi->planes[1] = priv->buffer + sh->disp_w*sh->disp_h*5/4; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
157 mpi->stride[1] = sh->disp_w / 2; |
7729 | 158 } |
159 | |
160 mp_msg (MSGT_DECVIDEO, MSGL_DBG2, | |
161 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME, | |
162 (long) len, (long)w); | |
163 | |
164 return mpi; | |
165 } | |
166 | |
167 /* vim: sw=4 | |
168 */ |