Mercurial > mplayer.hg
annotate libmpcodecs/vd_lzo.c @ 34434:857f2d63af52
Add reference result for vble test file.
author | reimar |
---|---|
date | Thu, 05 Jan 2012 18:23:34 +0000 |
parents | 4c2bbab833d1 |
children |
rev | line source |
---|---|
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
1 /* |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
2 * This file is part of MPlayer. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
3 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
7 * (at your option) any later version. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
8 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
12 * GNU General Public License for more details. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
13 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
17 */ |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
29263
diff
changeset
|
18 |
7729 | 19 #include <stdio.h> |
20 #include <stdlib.h> | |
21 | |
22 #include "config.h" | |
23 #include "mp_msg.h" | |
24 | |
25 #include "vd_internal.h" | |
22079 | 26 #include "libavutil/lzo.h" |
7729 | 27 |
28 #define MOD_NAME "DecLZO" | |
29 | |
30504
cc27da5d7286
Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents:
30421
diff
changeset
|
30 static const vd_info_t info = { |
7729 | 31 "LZO compressed Video", |
32 "lzo", | |
33 "Tilmann Bitterberg", | |
34 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>", | |
35 "based on liblzo: http://www.oberhumer.com/opensource/lzo/" | |
36 }; | |
37 | |
38 LIBVD_EXTERN(lzo) | |
39 | |
7800 | 40 typedef struct { |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
41 uint8_t *buffer; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
42 int bufsz; |
7800 | 43 int codec; |
44 } lzo_context_t; | |
7729 | 45 |
46 // to set/get/query special features/parameters | |
47 static int control (sh_video_t *sh, int cmd, void* arg, ...) | |
48 { | |
7800 | 49 lzo_context_t *priv = sh->context; |
7729 | 50 switch(cmd){ |
51 case VDCTRL_QUERY_FORMAT: | |
22062 | 52 if (*(int *)arg == priv->codec) return CONTROL_TRUE; |
7729 | 53 return CONTROL_FALSE; |
54 } | |
55 return CONTROL_UNKNOWN; | |
56 } | |
57 | |
58 | |
59 // init driver | |
60 static int init(sh_video_t *sh) | |
61 { | |
7800 | 62 lzo_context_t *priv; |
7729 | 63 |
22079 | 64 if (sh->bih->biSizeImage <= 0) { |
65 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Invalid frame size\n", MOD_NAME); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28413
diff
changeset
|
66 return 0; |
7729 | 67 } |
68 | |
7800 | 69 priv = malloc(sizeof(lzo_context_t)); |
70 if (!priv) | |
71 { | |
72 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] memory allocation failed\n", MOD_NAME); | |
73 return 0; | |
74 } | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
75 priv->bufsz = sh->bih->biSizeImage; |
28413 | 76 priv->buffer = malloc(priv->bufsz + AV_LZO_OUTPUT_PADDING); |
7800 | 77 priv->codec = -1; |
78 sh->context = priv; | |
7729 | 79 |
80 return 1; | |
81 } | |
82 | |
83 // uninit driver | |
84 static void uninit(sh_video_t *sh) | |
85 { | |
7800 | 86 lzo_context_t *priv = sh->context; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28413
diff
changeset
|
87 |
7800 | 88 if (priv) |
89 { | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
90 free(priv->buffer); |
7800 | 91 free(priv); |
92 } | |
93 | |
94 sh->context = NULL; | |
7729 | 95 } |
96 | |
97 // decode a frame | |
98 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags) | |
99 { | |
100 int r; | |
101 mp_image_t* mpi; | |
7800 | 102 lzo_context_t *priv = sh->context; |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
103 int w = priv->bufsz; |
7729 | 104 |
105 if (len <= 0) { | |
106 return NULL; // skipped frame | |
107 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28413
diff
changeset
|
108 |
28413 | 109 r = av_lzo1x_decode(priv->buffer, &w, data, &len); |
22079 | 110 if (r) { |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
111 /* this should NEVER happen */ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28413
diff
changeset
|
112 mp_msg (MSGT_DECVIDEO, MSGL_ERR, |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
113 "[%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
|
114 return NULL; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
115 } |
7729 | 116 |
22077
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
117 if (priv->codec == -1) { |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
118 // detect RGB24 vs. YV12 via decoded size |
7729 | 119 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n", |
120 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage | |
121 ); | |
122 | |
22079 | 123 if (w == 0) { |
7800 | 124 priv->codec = IMGFMT_BGR24; |
31834
64ba1daa147a
various spelling fixes, found by the Debian QA tool 'lintian'
siretart
parents:
30504
diff
changeset
|
125 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec chosen is BGR24\n", MOD_NAME); |
7729 | 126 } else if (w == (sh->bih->biSizeImage)/2) { |
7800 | 127 priv->codec = IMGFMT_YV12; |
31834
64ba1daa147a
various spelling fixes, found by the Debian QA tool 'lintian'
siretart
parents:
30504
diff
changeset
|
128 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec chosen is YV12\n", MOD_NAME); |
7729 | 129 } else { |
7800 | 130 priv->codec = -1; |
7729 | 131 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME); |
132 return NULL; | |
133 } | |
134 | |
22077
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
135 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
|
136 priv->codec = -1; |
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
137 return NULL; |
40135eba142f
Avoid a static variable and instead use variable in context
reimar
parents:
22063
diff
changeset
|
138 } |
7729 | 139 } |
140 | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
141 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, |
7729 | 142 sh->disp_w, sh->disp_h); |
143 | |
144 | |
145 if (!mpi) { | |
146 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME); | |
147 return NULL; | |
148 } | |
149 | |
22078
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
150 mpi->planes[0] = priv->buffer; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
151 if (priv->codec == IMGFMT_BGR24) |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
152 mpi->stride[0] = 3 * sh->disp_w; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
153 else { |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
154 mpi->stride[0] = sh->disp_w; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
155 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
|
156 mpi->stride[2] = sh->disp_w / 2; |
9fd2145ddb43
Use export type mpi, everything else is a fragile hack.
reimar
parents:
22077
diff
changeset
|
157 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
|
158 mpi->stride[1] = sh->disp_w / 2; |
7729 | 159 } |
160 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28413
diff
changeset
|
161 mp_msg (MSGT_DECVIDEO, MSGL_DBG2, |
7729 | 162 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME, |
163 (long) len, (long)w); | |
164 | |
165 return mpi; | |
166 } |