annotate libmpcodecs/vd_lzo.c @ 36537:3b2228019b6a

vo_bl: update copyright header. Patch by Stefan Schuermans [stefan blinkenarea org].
author reimar
date Sun, 19 Jan 2014 12:06:04 +0000
parents 4c2bbab833d1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
19 #include <stdio.h>
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
20 #include <stdlib.h>
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
21
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
22 #include "config.h"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
23 #include "mp_msg.h"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
24
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
25 #include "vd_internal.h"
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
26 #include "libavutil/lzo.h"
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
27
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
28 #define MOD_NAME "DecLZO"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
31 "LZO compressed Video",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
32 "lzo",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
33 "Tilmann Bitterberg",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
34 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
35 "based on liblzo: http://www.oberhumer.com/opensource/lzo/"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
36 };
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
37
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
38 LIBVD_EXTERN(lzo)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
39
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
43 int codec;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
44 } lzo_context_t;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
45
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
46 // to set/get/query special features/parameters
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
47 static int control (sh_video_t *sh, int cmd, void* arg, ...)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
48 {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
49 lzo_context_t *priv = sh->context;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
50 switch(cmd){
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
51 case VDCTRL_QUERY_FORMAT:
22062
56adbcf864de More simplification
reimar
parents: 22061
diff changeset
52 if (*(int *)arg == priv->codec) return CONTROL_TRUE;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
53 return CONTROL_FALSE;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
54 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
55 return CONTROL_UNKNOWN;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
56 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
57
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
58
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
59 // init driver
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
60 static int init(sh_video_t *sh)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
61 {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
62 lzo_context_t *priv;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
63
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
64 if (sh->bih->biSizeImage <= 0) {
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
67 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
68
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
69 priv = malloc(sizeof(lzo_context_t));
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
70 if (!priv)
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
71 {
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
72 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] memory allocation failed\n", MOD_NAME);
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
73 return 0;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
34794b885cb2 Adapt to lzo changes in libavutil
reimar
parents: 26069
diff changeset
76 priv->buffer = malloc(priv->bufsz + AV_LZO_OUTPUT_PADDING);
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
77 priv->codec = -1;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
78 sh->context = priv;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
79
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
80 return 1;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
81 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
82
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
83 // uninit driver
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
84 static void uninit(sh_video_t *sh)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
85 {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
86 lzo_context_t *priv = sh->context;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28413
diff changeset
87
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
88 if (priv)
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
89 {
22078
9fd2145ddb43 Use export type mpi, everything else is a fragile hack.
reimar
parents: 22077
diff changeset
90 free(priv->buffer);
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
91 free(priv);
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
92 }
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
93
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
94 sh->context = NULL;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
95 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
96
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
97 // decode a frame
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
98 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
99 {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
100 int r;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
101 mp_image_t* mpi;
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
104
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
105 if (len <= 0) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
106 return NULL; // skipped frame
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
107 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28413
diff changeset
108
28413
34794b885cb2 Adapt to lzo changes in libavutil
reimar
parents: 26069
diff changeset
109 r = av_lzo1x_decode(priv->buffer, &w, data, &len);
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
119 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
120 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
121 );
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
122
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
123 if (w == 0) {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
126 } else if (w == (sh->bih->biSizeImage)/2) {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
129 } else {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
130 priv->codec = -1;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
131 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
132 return NULL;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
133 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
139 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
142 sh->disp_w, sh->disp_h);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
143
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
144
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
145 if (!mpi) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
146 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
147 return NULL;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
148 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
159 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
160
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28413
diff changeset
161 mp_msg (MSGT_DECVIDEO, MSGL_DBG2,
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
162 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME,
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
163 (long) len, (long)w);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
164
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
165 return mpi;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
166 }