2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "vd_internal.h"
26 #include "libavutil/lzo.h"
28 #define MOD_NAME "DecLZO"
30 static const vd_info_t info
= {
31 "LZO compressed Video",
34 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>",
35 "based on liblzo: http://www.oberhumer.com/opensource/lzo/"
46 // to set/get/query special features/parameters
47 static int control (sh_video_t
*sh
, int cmd
, void* arg
, ...)
49 lzo_context_t
*priv
= sh
->context
;
51 case VDCTRL_QUERY_FORMAT
:
52 if (*(int *)arg
== priv
->codec
) return CONTROL_TRUE
;
55 return CONTROL_UNKNOWN
;
60 static int init(sh_video_t
*sh
)
64 if (sh
->bih
->biSizeImage
<= 0) {
65 mp_msg (MSGT_DECVIDEO
, MSGL_ERR
, "[%s] Invalid frame size\n", MOD_NAME
);
69 priv
= malloc(sizeof(lzo_context_t
));
72 mp_msg (MSGT_DECVIDEO
, MSGL_ERR
, "[%s] memory allocation failed\n", MOD_NAME
);
75 priv
->bufsz
= sh
->bih
->biSizeImage
;
76 priv
->buffer
= malloc(priv
->bufsz
+ AV_LZO_OUTPUT_PADDING
);
84 static void uninit(sh_video_t
*sh
)
86 lzo_context_t
*priv
= sh
->context
;
98 static mp_image_t
* decode(sh_video_t
*sh
,void* data
,int len
,int flags
)
102 lzo_context_t
*priv
= sh
->context
;
106 return NULL
; // skipped frame
109 r
= av_lzo1x_decode(priv
->buffer
, &w
, data
, &len
);
111 /* this should NEVER happen */
112 mp_msg (MSGT_DECVIDEO
, MSGL_ERR
,
113 "[%s] internal error - decompression failed: %d\n", MOD_NAME
, r
);
117 if (priv
->codec
== -1) {
118 // detect RGB24 vs. YV12 via decoded size
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
124 priv
->codec
= IMGFMT_BGR24
;
125 mp_msg (MSGT_DECVIDEO
, MSGL_V
, "[%s] codec choosen is BGR24\n", MOD_NAME
);
126 } else if (w
== (sh
->bih
->biSizeImage
)/2) {
127 priv
->codec
= IMGFMT_YV12
;
128 mp_msg (MSGT_DECVIDEO
, MSGL_V
, "[%s] codec choosen is YV12\n", MOD_NAME
);
131 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"[%s] Unsupported out_fmt\n", MOD_NAME
);
135 if(!mpcodecs_config_vo(sh
,sh
->disp_w
,sh
->disp_h
,priv
->codec
)) {
141 mpi
= mpcodecs_get_image(sh
, MP_IMGTYPE_EXPORT
, 0,
142 sh
->disp_w
, sh
->disp_h
);
146 mp_msg (MSGT_DECVIDEO
, MSGL_ERR
, "[%s] mpcodecs_get_image failed\n", MOD_NAME
);
150 mpi
->planes
[0] = priv
->buffer
;
151 if (priv
->codec
== IMGFMT_BGR24
)
152 mpi
->stride
[0] = 3 * sh
->disp_w
;
154 mpi
->stride
[0] = sh
->disp_w
;
155 mpi
->planes
[2] = priv
->buffer
+ sh
->disp_w
*sh
->disp_h
;
156 mpi
->stride
[2] = sh
->disp_w
/ 2;
157 mpi
->planes
[1] = priv
->buffer
+ sh
->disp_w
*sh
->disp_h
*5/4;
158 mpi
->stride
[1] = sh
->disp_w
/ 2;
161 mp_msg (MSGT_DECVIDEO
, MSGL_DBG2
,
162 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME
,
163 (long) len
, (long)w
);