Mercurial > mplayer.hg
annotate libmpcodecs/vd_zlib.c @ 5549:7bed3fb6a3be
query_format debug moved 1 verbose level down
author | arpi |
---|---|
date | Wed, 10 Apr 2002 23:23:19 +0000 |
parents | 652ec33400fd |
children | e9bd97d5c5cc |
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 { | |
5279 | 34 vd_zlib_ctx *ctx = sh->context; |
5262 | 35 switch(cmd) |
36 { | |
37 case VDCTRL_QUERY_FORMAT: | |
38 { | |
5279 | 39 if (*((int*)arg) == (IMGFMT_BGR|ctx->depth)) |
5278 | 40 return(CONTROL_TRUE); |
41 else | |
42 return(CONTROL_FALSE); | |
5262 | 43 } |
44 } | |
45 return(CONTROL_UNKNOWN); | |
46 } | |
47 | |
48 // init driver | |
49 static int init(sh_video_t *sh) | |
50 { | |
51 int zret; | |
52 vd_zlib_ctx *ctx; | |
53 | |
54 ctx = sh->context = malloc(sizeof(vd_zlib_ctx)); | |
55 if (!ctx) | |
56 return(0); | |
57 memset(ctx, 0, sizeof(vd_zlib_ctx)); | |
58 | |
59 ctx->width = sh->bih->biWidth; | |
60 ctx->height = sh->bih->biHeight; | |
61 ctx->depth = sh->bih->biBitCount; | |
62 | |
63 ctx->zstrm.zalloc = (alloc_func)NULL; | |
64 ctx->zstrm.zfree = (free_func)NULL; | |
65 ctx->zstrm.opaque = (voidpf)NULL; | |
66 | |
67 zret = inflateInit(&ctx->zstrm); | |
68 if (zret != Z_OK) | |
69 { | |
70 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[vd_zlib] inflate init error: %d\n", | |
71 zret); | |
72 return(NULL); | |
73 } | |
74 | |
75 if (!mpcodecs_config_vo(sh, ctx->width, ctx->height, IMGFMT_BGR|ctx->depth)) | |
76 return(NULL); | |
77 | |
78 | |
79 return(1); | |
80 } | |
81 | |
82 // uninit driver | |
83 static void uninit(sh_video_t *sh) | |
84 { | |
85 vd_zlib_ctx *ctx = sh->context; | |
86 | |
87 inflateEnd(&ctx->zstrm); | |
88 if (ctx) | |
89 free(ctx); | |
90 } | |
91 | |
92 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
93 | |
94 // decode a frame | |
95 static mp_image_t* decode(sh_video_t *sh, void* data, int len, int flags) | |
96 { | |
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
|
97 mp_image_t *mpi; |
5262 | 98 vd_zlib_ctx *ctx = sh->context; |
99 int zret; | |
100 int decomp_size = ctx->width*ctx->height*((ctx->depth+7)/8); | |
101 z_stream *zstrm = &ctx->zstrm; | |
102 | |
103 if (len <= 0) | |
104 return(NULL); // skipped frame | |
105 | |
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
|
106 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
|
107 if (!mpi) return(NULL); |
5276 | 108 |
5262 | 109 zstrm->next_in = data; |
110 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
|
111 zstrm->next_out = mpi->planes[0]; |
5262 | 112 zstrm->avail_out = decomp_size; |
113 | |
114 mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "[vd_zlib] input: %p (%d bytes), output: %p (%d bytes)\n", | |
115 zstrm->next_in, zstrm->avail_in, zstrm->next_out, zstrm->avail_out); | |
116 | |
117 zret = inflate(zstrm, Z_NO_FLUSH); | |
118 if ((zret != Z_OK) && (zret != Z_STREAM_END)) | |
119 { | |
120 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "[vd_zlib] inflate error: %d\n", | |
121 zret); | |
122 return(NULL); | |
123 } | |
124 | |
125 if (decomp_size != (int)zstrm->total_out) | |
126 { | |
127 mp_msg(MSGT_DECVIDEO, MSGL_WARN, "[vd_zlib] decoded size differs (%d != %d)\n", | |
128 decomp_size, zstrm->total_out); | |
129 return(NULL); | |
130 } | |
131 | |
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
|
132 return mpi; |
5262 | 133 } |
134 #endif |