7 #include "vd_internal.h"
12 #include "native/minilzo.h"
13 #define lzo_malloc malloc
17 #define MOD_NAME "DecLZO"
19 static vd_info_t info
= {
20 "LZO compressed Video",
23 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>",
24 "based on liblzo: http://www.oberhumer.com/opensource/lzo/"
34 // to set/get/query special features/parameters
35 static int control (sh_video_t
*sh
, int cmd
, void* arg
, ...)
37 lzo_context_t
*priv
= sh
->context
;
38 //printf("[%s] Query!! (%s)\n", MOD_NAME, (codec==IMGFMT_BGR24)?"BGR":"none");
39 //printf("[%s] Query!! (%s)\n", MOD_NAME, (codec==IMGFMT_YV12)?"YV12":"none");
41 case VDCTRL_QUERY_FORMAT
:
42 if( (*((int*)arg
)) == IMGFMT_BGR24
&& priv
->codec
== IMGFMT_BGR24
) return CONTROL_TRUE
;
43 if( (*((int*)arg
)) == IMGFMT_YV12
&& priv
->codec
== IMGFMT_YV12
) return CONTROL_TRUE
;
46 return CONTROL_UNKNOWN
;
51 static int init(sh_video_t
*sh
)
55 if (lzo_init() != LZO_E_OK
) {
56 mp_msg (MSGT_DECVIDEO
, MSGL_ERR
, "[%s] lzo_init() failed\n", MOD_NAME
);
60 priv
= malloc(sizeof(lzo_context_t
));
63 mp_msg (MSGT_DECVIDEO
, MSGL_ERR
, "[%s] memory allocation failed\n", MOD_NAME
);
69 priv
->wrkmem
= (lzo_bytep
) lzo_malloc(LZO1X_1_MEM_COMPRESS
);
71 if (priv
->wrkmem
== NULL
) {
72 mp_msg (MSGT_DECVIDEO
, MSGL_ERR
, "[%s] Cannot alloc work memory\n", MOD_NAME
);
80 static void uninit(sh_video_t
*sh
)
82 lzo_context_t
*priv
= sh
->context
;
87 lzo_free(priv
->wrkmem
);
94 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
97 static mp_image_t
* decode(sh_video_t
*sh
,void* data
,int len
,int flags
)
99 static int init_done
= 0;
103 lzo_context_t
*priv
= sh
->context
;
106 return NULL
; // skipped frame
113 // decompress one frame to see if its
114 // either YV12 or RGB24
115 if (!tmp
) tmp
= lzo_malloc(sh
->bih
->biSizeImage
);
117 mp_msg (MSGT_DECVIDEO
, MSGL_V
, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n",
118 MOD_NAME
, sh
->bih
->biBitCount
, sh
->format
, data
, len
, sh
->bih
->biSizeImage
121 /* decompress the frame */
122 w
= sh
->bih
->biSizeImage
;
123 r
= lzo1x_decompress_safe (data
, len
, tmp
, &w
, priv
->wrkmem
);
127 /* this should NEVER happen */
128 mp_msg (MSGT_DECVIDEO
, MSGL_ERR
,
129 "[%s] internal error - decompression failed: %d\n", MOD_NAME
, r
);
133 if (w
== (sh
->bih
->biSizeImage
)) {
134 priv
->codec
= IMGFMT_BGR24
;
135 mp_msg (MSGT_DECVIDEO
, MSGL_V
, "[%s] codec choosen is BGR24\n", MOD_NAME
);
136 } else if (w
== (sh
->bih
->biSizeImage
)/2) {
137 priv
->codec
= IMGFMT_YV12
;
138 mp_msg (MSGT_DECVIDEO
, MSGL_V
, "[%s] codec choosen is YV12\n", MOD_NAME
);
141 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"[%s] Unsupported out_fmt\n", MOD_NAME
);
145 if(!mpcodecs_config_vo(sh
,sh
->disp_w
,sh
->disp_h
,priv
->codec
)) return NULL
;
149 mpi
= mpcodecs_get_image(sh
, MP_IMGTYPE_TEMP
, 0,
150 sh
->disp_w
, sh
->disp_h
);
154 mp_msg (MSGT_DECVIDEO
, MSGL_ERR
, "[%s] mpcodecs_get_image failed\n", MOD_NAME
);
159 r
= lzo1x_decompress_safe (data
, len
, mpi
->planes
[0], &w
, priv
->wrkmem
);
161 /* this should NEVER happen */
162 mp_msg (MSGT_DECVIDEO
, MSGL_ERR
,
163 "[%s] internal error - decompression failed: %d\n", MOD_NAME
, r
);
167 mp_msg (MSGT_DECVIDEO
, MSGL_DBG2
,
168 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME
,
169 (long) len
, (long)w
);