annotate libmpcodecs/vd_lzo.c @ 27975:806c541d03dd

Do not draw in window if our image has not yet been adjusted to the new window size. Fixes some cases of borders not being black in fullscreen when fullscreen image is scaled down.
author reimar
date Sun, 23 Nov 2008 20:39:15 +0000
parents 1318e956c092
children 34794b885cb2
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"
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
8 #include "libavutil/lzo.h"
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
9
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
10 #define MOD_NAME "DecLZO"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
11
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
12 static vd_info_t info = {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
13 "LZO compressed Video",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
14 "lzo",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
15 "Tilmann Bitterberg",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
16 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>",
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
17 "based on liblzo: http://www.oberhumer.com/opensource/lzo/"
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
18 };
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
19
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
20 LIBVD_EXTERN(lzo)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
21
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
25 int codec;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
26 } lzo_context_t;
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 // to set/get/query special features/parameters
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
29 static int control (sh_video_t *sh, int cmd, void* arg, ...)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
30 {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
31 lzo_context_t *priv = sh->context;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
32 switch(cmd){
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
33 case VDCTRL_QUERY_FORMAT:
22062
56adbcf864de More simplification
reimar
parents: 22061
diff changeset
34 if (*(int *)arg == priv->codec) return CONTROL_TRUE;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
35 return CONTROL_FALSE;
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 return CONTROL_UNKNOWN;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
38 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
39
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
40
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
41 // init driver
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
42 static int init(sh_video_t *sh)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
43 {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
44 lzo_context_t *priv;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
45
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
46 if (sh->bih->biSizeImage <= 0) {
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
47 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
48 return 0;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
49 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
50
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
51 priv = malloc(sizeof(lzo_context_t));
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
52 if (!priv)
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
53 {
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
54 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
55 return 0;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
58 priv->buffer = malloc(priv->bufsz + LZO_OUTPUT_PADDING);
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
59 priv->codec = -1;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
60 sh->context = priv;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
61
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
62 return 1;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
63 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
64
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
65 // uninit driver
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
66 static void uninit(sh_video_t *sh)
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
67 {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
68 lzo_context_t *priv = sh->context;
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
69
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 {
22078
9fd2145ddb43 Use export type mpi, everything else is a fragile hack.
reimar
parents: 22077
diff changeset
72 free(priv->buffer);
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
73 free(priv);
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
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
76 sh->context = NULL;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
77 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
78
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
79 // decode a frame
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
80 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
81 {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
82 int r;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
83 mp_image_t* mpi;
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
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
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 if (len <= 0) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
88 return NULL; // skipped frame
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
89 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
90
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
91 r = lzo1x_decode(priv->buffer, &w, data, &len);
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
101 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
102 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
103 );
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
104
22079
d018c5b9e0e6 use ffmpeg's LZO
reimar
parents: 22078
diff changeset
105 if (w == 0) {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
106 priv->codec = IMGFMT_BGR24;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
107 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
108 } else if (w == (sh->bih->biSizeImage)/2) {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
109 priv->codec = IMGFMT_YV12;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
110 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
111 } else {
7800
1dd34db6cb92 using sh->context for private data
alex
parents: 7799
diff changeset
112 priv->codec = -1;
7729
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
113 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
114 return NULL;
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
115 }
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(!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
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
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
124 sh->disp_w, sh->disp_h);
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
125
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 if (!mpi) {
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
128 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
129 return NULL;
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
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
141 }
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
142
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
143 mp_msg (MSGT_DECVIDEO, MSGL_DBG2,
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
144 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME,
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
145 (long) len, (long)w);
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 return mpi;
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
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
150 /* vim: sw=4
36170c5a3c9a liblzo realtime video codec support (decoding only)
arpi
parents:
diff changeset
151 */