Mercurial > mplayer.hg
annotate libmpcodecs/vd_zlib.c @ 5277:7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
author | arpi |
---|---|
date | Sat, 23 Mar 2002 16:56:05 +0000 |
parents | 8037d34ce806 |
children | a11cd73811a8 |
rev | line source |
---|---|
5262 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "config.h" | |
5 | |
6 #ifdef HAVE_ZLIB | |
7 #include "mp_msg.h" | |
8 | |
9 #include <zlib.h> | |
10 | |
11 #include "vd_internal.h" | |
12 | |
13 static vd_info_t info = { | |
14 "zlib decoder (avizlib)", | |
15 "zlib", | |
16 VFM_ZLIB, | |
17 "Alex", | |
18 "based on vd_ijpg.c", | |
19 "uses zlib, supports only BGR24 (as AVIzlib)" | |
20 }; | |
21 | |
22 LIBVD_EXTERN(zlib) | |
23 | |
24 typedef struct { | |
25 int width; | |
26 int height; | |
27 int depth; | |
28 z_stream zstrm; | |
29 } vd_zlib_ctx; | |
30 | |
31 // to set/get/query special features/parameters | |
32 static int control(sh_video_t *sh, int cmd, void *arg, ...) | |
33 { | |
34 switch(cmd) | |
35 { | |
36 case VDCTRL_QUERY_FORMAT: | |
37 { | |
38 *((int*)arg) = IMGFMT_BGR24; | |
39 return(CONTROL_TRUE); | |
40 } | |
41 } | |
42 return(CONTROL_UNKNOWN); | |
43 } | |
44 | |
45 // init driver | |
46 static int init(sh_video_t *sh) | |
47 { | |
48 int zret; | |
49 vd_zlib_ctx *ctx; | |
50 | |
51 ctx = sh->context = malloc(sizeof(vd_zlib_ctx)); | |
52 if (!ctx) | |
53 return(0); | |
54 memset(ctx, 0, sizeof(vd_zlib_ctx)); | |
55 | |
56 ctx->width = sh->bih->biWidth; | |
57 ctx->height = sh->bih->biHeight; | |
58 ctx->depth = sh->bih->biBitCount; | |
59 | |
60 ctx->zstrm.zalloc = (alloc_func)NULL; | |
61 ctx->zstrm.zfree = (free_func)NULL; | |
62 ctx->zstrm.opaque = (voidpf)NULL; | |
63 | |
64 zret = inflateInit(&ctx->zstrm); | |
65 if (zret != Z_OK) | |
66 { | |
67 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[vd_zlib] inflate init error: %d\n", | |
68 zret); | |
69 return(NULL); | |
70 } | |
71 | |
72 if (!mpcodecs_config_vo(sh, ctx->width, ctx->height, IMGFMT_BGR|ctx->depth)) | |
73 return(NULL); | |
74 | |
75 | |
76 return(1); | |
77 } | |
78 | |
79 // uninit driver | |
80 static void uninit(sh_video_t *sh) | |
81 { | |
82 vd_zlib_ctx *ctx = sh->context; | |
83 | |
84 inflateEnd(&ctx->zstrm); | |
85 if (ctx) | |
86 free(ctx); | |
87 } | |
88 | |
89 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
90 | |
91 // decode a frame | |
92 static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags) | |
93 { | |
5277
7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
arpi
parents:
5276
diff
changeset
|
94 mp_image_t *mpi; |
5262 | 95 vd_zlib_ctx *ctx = sh->context; |
96 int zret; | |
97 int decomp_size = ctx->width*ctx->height*((ctx->depth+7)/8); | |
98 z_stream *zstrm = &ctx->zstrm; | |
99 | |
100 if (len <= 0) | |
101 return(NULL); // skipped frame | |
102 | |
5277
7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
arpi
parents:
5276
diff
changeset
|
103 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, ctx->width, ctx->height); |
7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
arpi
parents:
5276
diff
changeset
|
104 if (!mpi) return(NULL); |
5276 | 105 |
5262 | 106 zstrm->next_in = data; |
107 zstrm->avail_in = len; | |
5277
7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
arpi
parents:
5276
diff
changeset
|
108 zstrm->next_out = mpi->planes[0]; |
5262 | 109 zstrm->avail_out = decomp_size; |
110 | |
111 mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "[vd_zlib] input: %p (%d bytes), output: %p (%d bytes)\n", | |
112 zstrm->next_in, zstrm->avail_in, zstrm->next_out, zstrm->avail_out); | |
113 | |
114 zret = inflate(zstrm, Z_NO_FLUSH); | |
115 if ((zret != Z_OK) && (zret != Z_STREAM_END)) | |
116 { | |
117 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[vd_zlib] inflate error: %d\n", | |
118 zret); | |
119 return(NULL); | |
120 } | |
121 | |
122 if (decomp_size != (int)zstrm->total_out) | |
123 { | |
124 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[vd_zlib] decoded size differs (%d != %d)\n", | |
125 decomp_size, zstrm->total_out); | |
126 return(NULL); | |
127 } | |
128 | |
5277
7df9fc3308ac
10l. IMGFLAG_ALLOCATED shouldn't be set from vd driver\! - it's for internal use by the core
arpi
parents:
5276
diff
changeset
|
129 return mpi; |
5262 | 130 } |
131 #endif |