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