comparison libmpcodecs/vd_lzo.c @ 7729:36170c5a3c9a

liblzo realtime video codec support (decoding only) patch by Tilmann Bitterberg <transcode@tibit.org>
author arpi
date Sun, 13 Oct 2002 21:40:10 +0000
parents
children daeb5f93ce82
comparison
equal deleted inserted replaced
7728:64b5604195c5 7729:36170c5a3c9a
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "config.h"
5 #include "mp_msg.h"
6
7 #include "vd_internal.h"
8
9 #include <lzo1x.h>
10
11 #define MOD_NAME "DecLZO"
12
13 static vd_info_t info = {
14 "LZO compressed Video",
15 "lzo",
16 "Tilmann Bitterberg",
17 "Transcode development team <http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/>",
18 "based on liblzo: http://www.oberhumer.com/opensource/lzo/"
19 };
20
21 LIBVD_EXTERN(lzo)
22
23
24 static lzo_byte *wrkmem=NULL;
25 static int codec = -1;
26
27 // to set/get/query special features/parameters
28 static int control (sh_video_t *sh, int cmd, void* arg, ...)
29 {
30
31 //printf("[%s] Query!! (%s)\n", MOD_NAME, (codec==IMGFMT_BGR24)?"BGR":"none");
32 //printf("[%s] Query!! (%s)\n", MOD_NAME, (codec==IMGFMT_YV12)?"YV12":"none");
33 switch(cmd){
34 case VDCTRL_QUERY_FORMAT:
35 if( (*((int*)arg)) == IMGFMT_BGR24 && codec == IMGFMT_BGR24) return CONTROL_TRUE;
36 if( (*((int*)arg)) == IMGFMT_YV12 && codec == IMGFMT_YV12) return CONTROL_TRUE;
37 return CONTROL_FALSE;
38 }
39 return CONTROL_UNKNOWN;
40 }
41
42
43 // init driver
44 static int init(sh_video_t *sh)
45 {
46
47 if (lzo_init() != LZO_E_OK) {
48 mp_msg (MSGT_DECVIDEO, MSGL_WARN, "[%s] lzo_init() failed\n", MOD_NAME);
49 return 0;
50 }
51
52 if (!wrkmem) wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS);
53
54 if (wrkmem == NULL) {
55 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] Cannot alloc work memory\n", MOD_NAME);
56 return 0;
57 }
58
59 return 1;
60 }
61
62 // uninit driver
63 static void uninit(sh_video_t *sh)
64 {
65 if (wrkmem) { lzo_free(wrkmem); wrkmem = NULL;}
66 }
67
68 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
69
70 // decode a frame
71 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags)
72 {
73 static int init_done = 0;
74 int r;
75 int cb = 1;
76 int cr = 2;
77 mp_image_t* mpi;
78 int w, h;
79
80 if (len <= 0) {
81 return NULL; // skipped frame
82 }
83
84
85 if (!init_done) {
86 lzo_byte *tmp=NULL;
87
88 // decompress one frame to see if its
89 // either YV12 or RGB24
90 if (!tmp) tmp = lzo_malloc(sh->bih->biSizeImage);
91
92 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] 2 depth %d, format %d data %p len (%d) (%d)\n",
93 MOD_NAME, sh->bih->biBitCount, sh->format, data, len, sh->bih->biSizeImage
94 );
95
96 /* decompress the frame */
97 r = lzo1x_decompress (data, len, tmp, &w, wrkmem);
98
99 if (r != LZO_E_OK) {
100 /* this should NEVER happen */
101 mp_msg (MSGT_DECVIDEO, MSGL_ERR,
102 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r);
103 return NULL;
104 }
105
106 if (w == (sh->bih->biSizeImage)) {
107 codec = IMGFMT_BGR24;
108 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is BGR24\n", MOD_NAME);
109 } else if (w == (sh->bih->biSizeImage)/2) {
110 codec = IMGFMT_YV12;
111 mp_msg (MSGT_DECVIDEO, MSGL_V, "[%s] codec choosen is YV12\n", MOD_NAME);
112 } else {
113 codec = -1;
114 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"[%s] Unsupported out_fmt\n", MOD_NAME);
115 return NULL;
116 }
117
118 mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,codec);
119 init_done++;
120 free(tmp);
121 }
122
123 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0,
124 sh->disp_w, sh->disp_h);
125
126
127 if (!mpi) {
128 mp_msg (MSGT_DECVIDEO, MSGL_ERR, "[%s] mpcodecs_get_image failed\n", MOD_NAME);
129 return NULL;
130 }
131
132 r = lzo1x_decompress (data, len, mpi->planes[0], &w, wrkmem);
133 if (r != LZO_E_OK) {
134 /* this should NEVER happen */
135 mp_msg (MSGT_DECVIDEO, MSGL_ERR,
136 "[%s] internal error - decompression failed: %d\n", MOD_NAME, r);
137 return NULL;
138 }
139
140 mp_msg (MSGT_DECVIDEO, MSGL_DBG2,
141 "[%s] decompressed %lu bytes into %lu bytes\n", MOD_NAME,
142 (long) len, (long)w);
143
144 return mpi;
145 }
146
147 /* vim: sw=4
148 */