annotate libmpcodecs/vd_lzo.c @ 26026:a1e19c442cab

Create standard multiple inclusion guards.
author diego
date Thu, 21 Feb 2008 22:57:10 +0000
parents d018c5b9e0e6
children 1318e956c092
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
1 #include <stdio.h>
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
2 #include <stdlib.h>
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
3
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
4 #include "config.h"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
5 #include "mp_msg.h"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
6
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
7 #include "vd_internal.h"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
8
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
9 #ifdef USE_LIBAVUTIL_SO
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
10 #include <ffmpeg/lzo.h>
7799
daeb5f93ce82 support to use minilzo lib alternatively
alex
parents: 7729
diff changeset
11 #else
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
12 #include "libavutil/lzo.h"
7799
daeb5f93ce82 support to use minilzo lib alternatively
alex
parents: 7729
diff changeset
13 #endif
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
14
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
15 #define MOD_NAME "DecLZO"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
16
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
17 static vd_info_t info = {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
18 "LZO compressed Video",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
19 "lzo",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
20 "Tilmann Bitterberg",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
21 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
22 "based on liblzo: http://www.oberhumer.com/opensource/lzo/"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
23 };
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 LIBVD_EXTERN(lzo)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
26
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
30 int codec;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
31 } lzo_context_t;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
32
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
33 // to set/get/query special features/parameters
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
34 static int control (sh_video_t *sh, int cmd, void* arg, ...)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
35 {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
36 lzo_context_t *priv = sh->context;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
37 switch(cmd){
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
38 case VDCTRL_QUERY_FORMAT:
22062
56adbcf864de More simplification
reimar
parents: 22061
diff changeset
39 if (*(int *)arg == priv->codec) return CONTROL_TRUE;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
40 return CONTROL_FALSE;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
41 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
42 return CONTROL_UNKNOWN;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
43 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
44
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 // init driver
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
47 static int init(sh_video_t *sh)
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;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
50
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
51 if (sh->bih->biSizeImage <= 0) {
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
52 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Invalid frame size\n", MOD_NAME);
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
53 return 0;
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
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
56 priv = malloc(sizeof(lzo_context_t));
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
57 if (!priv)
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
58 {
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
59 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
60 return 0;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
63 priv->buffer = malloc(priv->bufsz + LZO_OUTPUT_PADDING);
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
64 priv->codec = -1;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
65 sh->context = priv;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
66
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
67 return 1;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
68 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
69
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
70 // uninit driver
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
71 static void uninit(sh_video_t *sh)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
72 {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
73 lzo_context_t *priv = sh->context;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
74
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
75 if (priv)
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
76 {
22078
9fd2145ddb43 Use export type mpi, everything else is a fragile hack.
reimar
parents: 22077
diff changeset
77 free(priv->buffer);
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
78 free(priv);
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
79 }
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
80
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
81 sh->context = NULL;
7729
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
84 // decode a frame
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
85 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
86 {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
87 int r;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
88 mp_image_t* mpi;
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
91
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
92 if (len <= 0) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
93 return NULL; // skipped frame
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
94 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
95
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
96 r = lzo1x_decode(priv->buffer, &w, data, &len);
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
106 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
107 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
108 );
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
109
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
110 if (w == 0) {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
111 priv->codec = IMGFMT_BGR24;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
112 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is BGR24\n", MOD_NAME);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
113 } else if (w == (sh->bih->biSizeImage)/2) {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
114 priv->codec = IMGFMT_YV12;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
115 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is YV12\n", MOD_NAME);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
116 } else {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
117 priv->codec = -1;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
118 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
119 return NULL;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
120 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
126 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
129 sh->disp_w, sh->disp_h);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
130
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
131
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
132 if (!mpi) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
133 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
134 return NULL;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
135 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
146 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
147
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
148 mp_msg (MSGT_DECVIDEO, MSGL_DBG2,
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
149 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME,
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
150 (long) len, (long)w);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
151
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
152 return mpi;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
153 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
154
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
155 /* vim: sw=4
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
156 */