Mercurial > mplayer.hg
annotate libmpcodecs/vd_lzo.c @ 23253:aeef449e5923
libdha is no more.
author | diego |
---|---|
date | Tue, 08 May 2007 17:43:24 +0000 |
parents | d018c5b9e0e6 |
children | 1318e956c092 |
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 | |
22079 | 9 #ifdef USE_LIBAVUTIL_SO |
10 #include <ffmpeg/lzo.h> | |
7799 | 11 #else |
22079 | 12 #include "libavutil/lzo.h" |
7799 | 13 #endif |
7729 | 14 |
15 #define MOD_NAME "DecLZO" | |
16 | |
17 static vd_info_t info = { | |
18 "LZO compressed Video", | |
19 "lzo", | |
20 "Tilmann Bitterberg", | |
21 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>", | |
22 "based on liblzo: http://www.oberhumer.com/opensource/lzo/" | |
23 }; | |
24 | |
25 LIBVD_EXTERN(lzo) | |
26 | |
7800 | 27 typedef struct { |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
28 uint8_t *buffer; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
29 int bufsz; |
7800 | 30 int codec; |
31 } lzo_context_t; | |
7729 | 32 |
33 // to set/get/query special features/parameters | |
34 static int control (sh_video_t *sh, int cmd, void* arg, ...) | |
35 { | |
7800 | 36 lzo_context_t *priv = sh->context; |
7729 | 37 switch(cmd){ |
38 case VDCTRL_QUERY_FORMAT: | |
22062 | 39 if (*(int *)arg == priv->codec) return CONTROL_TRUE; |
7729 | 40 return CONTROL_FALSE; |
41 } | |
42 return CONTROL_UNKNOWN; | |
43 } | |
44 | |
45 | |
46 // init driver | |
47 static int init(sh_video_t *sh) | |
48 { | |
7800 | 49 lzo_context_t *priv; |
7729 | 50 |
22079 | 51 if (sh->bih->biSizeImage <= 0) { |
52 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Invalid frame size\n", MOD_NAME); | |
7729 | 53 return 0; |
54 } | |
55 | |
7800 | 56 priv = malloc(sizeof(lzo_context_t)); |
57 if (!priv) | |
58 { | |
59 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] memory allocation failed\n", MOD_NAME); | |
60 return 0; | |
61 } | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
62 priv->bufsz = sh->bih->biSizeImage; |
22079 | 63 priv->buffer = malloc(priv->bufsz + LZO_OUTPUT_PADDING); |
7800 | 64 priv->codec = -1; |
65 sh->context = priv; | |
7729 | 66 |
67 return 1; | |
68 } | |
69 | |
70 // uninit driver | |
71 static void uninit(sh_video_t *sh) | |
72 { | |
7800 | 73 lzo_context_t *priv = sh->context; |
74 | |
75 if (priv) | |
76 { | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
77 free(priv->buffer); |
7800 | 78 free(priv); |
79 } | |
80 | |
81 sh->context = NULL; | |
7729 | 82 } |
83 | |
84 // decode a frame | |
85 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags) | |
86 { | |
87 int r; | |
88 mp_image_t* mpi; | |
7800 | 89 lzo_context_t *priv = sh->context; |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
90 int w = priv->bufsz; |
7729 | 91 |
92 if (len <= 0) { | |
93 return NULL; // skipped frame | |
94 } | |
95 | |
22079 | 96 r = lzo1x_decode(priv->buffer, &w, data, &len); |
97 if (r) { | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
98 /* this should NEVER happen */ |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
99 mp_msg (MSGT_DECVIDEO, MSGL_ERR, |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
100 "[%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
|
101 return NULL; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
102 } |
7729 | 103 |
22077
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
104 if (priv->codec == -1) { |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
105 // detect RGB24 vs. YV12 via decoded size |
7729 | 106 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n", |
107 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage | |
108 ); | |
109 | |
22079 | 110 if (w == 0) { |
7800 | 111 priv->codec = IMGFMT_BGR24; |
7729 | 112 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is BGR24\n", MOD_NAME); |
113 } else if (w == (sh->bih->biSizeImage)/2) { | |
7800 | 114 priv->codec = IMGFMT_YV12; |
7729 | 115 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is YV12\n", MOD_NAME); |
116 } else { | |
7800 | 117 priv->codec = -1; |
7729 | 118 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME); |
119 return NULL; | |
120 } | |
121 | |
22077
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
122 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
|
123 priv->codec = -1; |
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
124 return NULL; |
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
125 } |
7729 | 126 } |
127 | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
128 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, |
7729 | 129 sh->disp_w, sh->disp_h); |
130 | |
131 | |
132 if (!mpi) { | |
133 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME); | |
134 return NULL; | |
135 } | |
136 | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
137 mpi->planes[0] = priv->buffer; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
138 if (priv->codec == IMGFMT_BGR24) |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
139 mpi->stride[0] = 3 * sh->disp_w; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
140 else { |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
141 mpi->stride[0] = sh->disp_w; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
142 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
|
143 mpi->stride[2] = sh->disp_w / 2; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
144 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
|
145 mpi->stride[1] = sh->disp_w / 2; |
7729 | 146 } |
147 | |
148 mp_msg (MSGT_DECVIDEO, MSGL_DBG2, | |
149 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME, | |
150 (long) len, (long)w); | |
151 | |
152 return mpi; | |
153 } | |
154 | |
155 /* vim: sw=4 | |
156 */ |