annotate libvo/vo_mng.c @ 33411:320890c90a8a

vo_direct3d: Mark function only used within the file as static. This fixes the warning: libvo/vo_direct3d.c:984:6: warning: no previous prototype for 'vo_draw_alpha_l8a8'
author diego
date Tue, 24 May 2011 19:47:07 +0000
parents 2672587086ad
children cc3071a7c057
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33389
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
1 /*
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
2 * MPlayer output to MNG file
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
3 *
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
4 * Copyright (C) 2011 Stefan Schuermans <stefan blinkenarea org>
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
5 *
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
6 * This file is part of MPlayer.
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
7 *
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
11 * (at your option) any later version.
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
12 *
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
16 * GNU General Public License for more details.
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
17 *
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License along
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
21 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
22
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
23 #include <stdlib.h>
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
24 #include <string.h>
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
25 #include <unistd.h>
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
26 #include <fcntl.h>
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
27 #include <errno.h>
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
28 #include <sys/stat.h>
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
29 #include <sys/types.h>
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
30
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
31 #include <zlib.h>
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
32
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
33 #define MNG_INCLUDE_WRITE_PROCS
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
34 #define MNG_ACCESS_CHUNKS
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
35 #define MNG_SUPPORT_READ
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
36 #define MNG_SUPPORT_DISPLAY
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
37 #define MNG_SUPPORT_WRITE
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
38 #include <libmng.h>
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
39
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
40 #include "video_out.h"
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
41 #include "video_out_internal.h"
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
42 #include "mp_msg.h"
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
43
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
44 #define VOMNG_DEFAULT_DELAY_MS (100) /* default delay of a frame */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
45
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
46 static vo_info_t info = {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
47 .name = "MNG file",
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
48 .short_name = "mng",
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
49 .author = "Stefan Schuermans <stefan blinkenarea org>"
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
50 };
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
51
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
52 LIBVO_EXTERN(mng)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
53
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
54 /* a frame to be written to the MNG file */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
55 struct vomng_frame {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
56 mng_ptr data; /**< deflate compressed data, malloc-ed */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
57 mng_uint32 len; /**< length of compressed data */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
58 unsigned int time_ms; /**< timestamp of frame (in ms) */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
59 struct vomng_frame *next; /**< next frame */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
60 };
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
61
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
62 /* properties of MNG output */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
63 struct vomng_properties {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
64 char *out_file_name; /**< name of output file, malloc-ed */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
65 unsigned int width, height; /**< dimensions */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
66 unsigned char *canvas; /**< canvas for frame,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
67 canvas := row ... row,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
68 row := filter_id pix ... pix,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
69 pix := red green blue */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
70 struct vomng_frame *frame_first; /**< list of frames */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
71 struct vomng_frame *frame_last;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
72 int is_init; /**< if initialized */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
73 };
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
74
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
75 /* private data of MNG vo module */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
76 static struct vomng_properties vomng;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
77
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
78 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
79 * @brief libmng callback: allocate memory
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
80 * @param[in] size size of requested memory block
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
81 * @return pointer to memory block, which is initialized to zero
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
82 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
83 static mng_ptr vomng_alloc(mng_size_t size)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
84 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
85 return calloc(1, size);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
86 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
87
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
88 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
89 * @brief libmng callback: free memory
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
90 * @param[in] pointer to memory block
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
91 * @param[in] size size of requested memory block
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
92 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
93 static void vomng_free(mng_ptr ptr, mng_size_t size)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
94 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
95 free(ptr);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
96 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
97
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
98 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
99 * @brief libmng callback: open stream
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
100 * @param[in] mng libmng handle
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
101 * @return if stream could be opened
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
102 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
103 static mng_bool vomng_openstream(mng_handle mng)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
104 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
105 return MNG_TRUE; /* stream is always open wen we get here,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
106 tell libmng that everything is okay */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
107 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
108
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
109 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
110 * @brief libmng callback: stream should be closed
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
111 * @param[in] mng libmng handle
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
112 * @return if stream could be closed
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
113 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
114 static mng_bool vomng_closestream(mng_handle mng)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
115 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
116 return MNG_TRUE; /* stream will be closed later,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
117 tell libmng that everything is okay */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
118 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
119
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
120 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
121 * @brief libmng callback: write libmng data to the open stream
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
122 * @param[in] mng libmng handle
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
123 * @param[in] *buf pointer to data to write
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
124 * @param[in] size size of data to write
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
125 * @param[out] *written size of data written
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
126 * @return if data was written successfully
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
127 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
128 static mng_bool vomng_writedata(mng_handle mng, mng_ptr buf,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
129 mng_uint32 size, mng_uint32 *written)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
130 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
131 FILE *file = mng_get_userdata(mng);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
132 *written = fwrite(buf, 1, size, file);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
133 /* according to the example in libmng documentation, true is always
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
134 returned here, short writes can be detected by libmng via *written */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
135 return MNG_TRUE;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
136 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
137
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
138 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
139 * @brief compress frame data
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
140 * @param[in] width width of canvas
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
141 * @param[in] height height of canvas
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
142 * @param[in] *canvas data on canvas (including MNG filter IDs)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
143 * @param[out] *out_ptr pointer to compressed data, malloc-ed
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
144 * @param[out] *out_len length of compressed data
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
145 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
146 static void vomng_canvas_to_compressed(unsigned int width, unsigned int height,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
147 const unsigned char *canvas,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
148 mng_ptr *out_ptr, mng_uint32 *out_len)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
149 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
150 mng_uint32 raw_len;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
151 unsigned char *ptr;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
152 unsigned long len;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
153
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
154 /* default: no output */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
155 *out_ptr = NULL;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
156 *out_len = 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
157
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
158 /* raw_len := length of input data
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
159 - it will be significantly shorter than 32 bit
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
160 - the "1 +" is needed because each row starts with the filter ID */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
161 raw_len = height * (1 + width * 3);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
162
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
163 /* compress data
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
164 - compress2 output size will be smaller than raw_len * 1.001 + 12 (see
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
165 man page), so calculate the next larger integer value in len and
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
166 allocate abuffer of this size
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
167 - len will still contain a value shorter than 32 bit */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
168 len = raw_len + (raw_len + 999) / 1000 + 12;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
169 ptr = malloc(len);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
170 if (!ptr)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
171 return;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
172 compress2(ptr, &len, canvas, raw_len, Z_BEST_COMPRESSION);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
173
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
174 /* return allocated compressed data
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
175 - we have to convert the output length to a shorter data type as
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
176 libmng does not accept an unsigned long as length
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
177 - convert here, because we can see here that the conversion is safe
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
178 - see comments about raw_len and len above
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
179 - compress2 never increases value of len */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
180 *out_ptr = ptr;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
181 *out_len = len;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
182 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
183
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
184 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
185 * @brief write frame to MNG file
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
186 * @param[in] *frame the frame to write to MNG file
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
187 * @param[in] mng libmng handle
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
188 * @param[in] width width of canvas
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
189 * @param[in] height height of canvas
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
190 * @param[in] first_frame if the frame is the first one in the file
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
191 * @return 0 on success, 1 on error
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
192 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
193 static int vomng_write_frame(struct vomng_frame *frame, mng_handle mng,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
194 unsigned int width, unsigned int height,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
195 int first_frame)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
196 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
197 unsigned int delay_ms;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
198
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
199 /* determine delay */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
200 if (frame->next)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
201 delay_ms = frame->next->time_ms - frame->time_ms;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
202 else
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
203 delay_ms = VOMNG_DEFAULT_DELAY_MS; /* default delay for last frame */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
204
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
205 /* write frame headers to MNG file */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
206 if (mng_putchunk_seek(mng, 0, MNG_NULL)) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
207 mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing SEEK chunk failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
208 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
209 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
210 if (mng_putchunk_fram(mng, MNG_FALSE,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
211 /* keep canvas if not 1st frame */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
212 first_frame ? MNG_FRAMINGMODE_1
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
213 : MNG_FRAMINGMODE_NOCHANGE,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
214 0, MNG_NULL, /* no frame name */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
215 MNG_CHANGEDELAY_DEFAULT, /* change only delay */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
216 MNG_CHANGETIMOUT_NO,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
217 MNG_CHANGECLIPPING_NO,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
218 MNG_CHANGESYNCID_NO,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
219 delay_ms, /* new delay */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
220 0, /* no new timeout */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
221 0, 0, 0, 0, 0, /* no new boundary */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
222 0, 0)) { /* no count, no IDs */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
223 mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing FRAM chunk failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
224 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
225 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
226 if (mng_putchunk_defi(mng, 0, /* no ID */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
227 MNG_DONOTSHOW_VISIBLE,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
228 MNG_ABSTRACT,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
229 MNG_TRUE, 0, 0, /* top left location */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
230 MNG_FALSE, 0, 0, 0, 0)) { /* no clipping */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
231 mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing DEFI chunk failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
232 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
233 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
234 if (mng_putchunk_ihdr(mng, width, height, /* dimensions */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
235 8, MNG_COLORTYPE_RGB, /* RBG */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
236 MNG_COMPRESSION_DEFLATE,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
237 MNG_FILTER_ADAPTIVE,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
238 MNG_INTERLACE_NONE)) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
239 mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing IHDR chunk failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
240 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
241 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
242
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
243 /* write frame data */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
244 if (mng_putchunk_idat(mng, frame->len, frame->data)) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
245 mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing IDAT chunk failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
246 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
247 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
248
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
249 /* write frame footers to MNG file */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
250 if (mng_putchunk_iend(mng)) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
251 mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing IEND chunk failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
252 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
253 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
254
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
255 return 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
256 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
257
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
258 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
259 * @brief write buffered frames to MNG file
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
260 * @return 0 on success, 1 on error
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
261 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
262 static int vomng_write_file(void)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
263 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
264 FILE *file;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
265 mng_handle mng;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
266 struct vomng_frame *frame;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
267 unsigned int frames, duration_ms;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
268 int first;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
269
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
270 /* refuse to create empty MNG file */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
271 if (!vomng.frame_first || !vomng.frame_last) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
272 mp_msg(MSGT_VO, MSGL_ERR, "vomng: not creating empty file\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
273 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
274 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
275
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
276 /* create output file */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
277 file = fopen(vomng.out_file_name, "wb");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
278 if (!file) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
279 mp_msg(MSGT_VO, MSGL_ERR,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
280 "vomng: could not open output file \"%s\": %s\n",
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
281 vomng.out_file_name, strerror(errno));
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
282 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
283 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
284
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
285 /* inititalize MNG library */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
286 mng = mng_initialize(file, vomng_alloc, vomng_free, MNG_NULL);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
287 if (!mng) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
288 mp_msg(MSGT_VO, MSGL_ERR, "vomng: could not initialize libmng\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
289 fclose(file);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
290 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
291 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
292 if (mng_setcb_openstream (mng, vomng_openstream ) ||
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
293 mng_setcb_closestream(mng, vomng_closestream) ||
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
294 mng_setcb_writedata (mng, vomng_writedata )) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
295 mp_msg(MSGT_VO, MSGL_ERR, "vomng: cannot set callbacks for libmng\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
296 mng_cleanup(&mng);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
297 fclose(file);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
298 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
299 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
300
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
301 /* create new MNG image in memory */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
302 if (mng_create(mng)) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
303 mp_msg(MSGT_VO, MSGL_ERR, "vomng: cannot create MNG image in memory\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
304 mng_cleanup(&mng);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
305 fclose(file);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
306 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
307 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
308
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
309 /* determine number of frames and total duration */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
310 frames = 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
311 for (frame = vomng.frame_first; frame; frame = frame->next)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
312 frames++;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
313 duration_ms = vomng.frame_last->time_ms - vomng.frame_first->time_ms;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
314
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
315 /* write MNG header chunks */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
316 if (mng_putchunk_mhdr(mng,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
317 vomng.width, /* dimensions */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
318 vomng.height,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
319 1000, 0, /* ticks per second, layer */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
320 frames, /* number of frames */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
321 duration_ms, /* total duration */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
322 MNG_SIMPLICITY_VALID |
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
323 MNG_SIMPLICITY_SIMPLEFEATURES |
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
324 MNG_SIMPLICITY_COMPLEXFEATURES) ||
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
325 mng_putchunk_save(mng,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
326 MNG_TRUE, 0, 0) || /* empty save chunk */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
327 mng_putchunk_term(mng,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
328 MNG_TERMACTION_CLEAR, /* show last frame forever */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
329 MNG_ITERACTION_CLEAR,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
330 0, 0)) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
331 mp_msg(MSGT_VO, MSGL_ERR,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
332 "vomng: writing MHDR/SAVE/TERM chunks failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
333 mng_write(mng); /* write out buffered chunks before cleanup */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
334 mng_cleanup(&mng);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
335 fclose(file);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
336 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
337 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
338
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
339 /* write frames */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
340 first = 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
341 for (frame = vomng.frame_first; frame; frame = frame->next) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
342 if (vomng_write_frame(frame, mng, vomng.width, vomng.height, first))
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
343 break;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
344 first = 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
345 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
346 if (frame) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
347 mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing frames failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
348 mng_write(mng); /* write out buffered chunks before cleanup */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
349 mng_cleanup(&mng);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
350 fclose(file);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
351 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
352 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
353
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
354 /* write MNG end chunk */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
355 if (mng_putchunk_mend(mng)) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
356 mp_msg(MSGT_VO, MSGL_ERR, "vomng: writing end chunk failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
357 mng_write(mng); /* write out buffered chunks before cleanup */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
358 mng_cleanup(&mng);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
359 fclose(file);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
360 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
361 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
362
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
363 /* finish and cleanup */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
364 mng_write(mng); /* write out buffered chunks before cleanup */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
365 mng_cleanup(&mng);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
366 fclose(file);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
367
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
368 return 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
369 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
370
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
371 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
372 * @brief close all files and free all memory of MNG vo module
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
373 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
374 static void vomng_prop_reset(void)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
375 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
376 struct vomng_frame *frame, *next;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
377
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
378 /* we are initialized properly */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
379 if (vomng.is_init) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
380 /* write buffered frames to MNG file */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
381 if (vomng_write_file())
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
382 mp_msg(MSGT_VO, MSGL_ERR,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
383 "vomng: writing output file failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
384 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
385
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
386 /* reset state */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
387 vomng.is_init = 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
388 if (vomng.frame_first) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
389 frame = vomng.frame_first;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
390 while (frame) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
391 next = frame->next;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
392 free(frame->data);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
393 free(frame);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
394 frame = next;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
395 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
396 vomng.frame_first = NULL;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
397 vomng.frame_last = NULL;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
398 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
399 free(vomng.canvas);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
400 vomng.canvas = NULL;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
401 vomng.width = 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
402 vomng.height = 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
403 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
404
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
405 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
406 * @brief close files, free memory and delete private data of MNG von module
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
407 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
408 static void vomng_prop_cleanup(void)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
409 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
410 vomng_prop_reset();
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
411 free(vomng.out_file_name);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
412 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
413
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
414 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
415 * @brief configure MNG vo module
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
416 * @param[in] width video width
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
417 * @param[in] height video height
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
418 * @param[in] d_width (unused)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
419 * @param[in] d_height (unused)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
420 * @param[in] flags (unused)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
421 * @param[in] title (unused)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
422 * @param[in] format video frame format
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
423 * @return 0 on success, 1 on error
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
424 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
425 static int config(uint32_t width, uint32_t height,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
426 uint32_t d_width, uint32_t d_height,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
427 uint32_t flags, char *title, uint32_t format)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
428 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
429 uint32_t row_stride, y;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
430
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
431 /* reset state */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
432 vomng_prop_reset();
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
433
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
434 /* check format */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
435 if (format != IMGFMT_RGB24) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
436 mp_msg(MSGT_VO, MSGL_ERR,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
437 "vomng: config with invalid format (!= IMGFMT_RGB24)\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
438 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
439 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
440
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
441 /* allocate canvas */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
442 vomng.width = width;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
443 vomng.height = height;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
444 row_stride = 1 + width * 3; /* rows contain filter IDs */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
445 vomng.canvas = calloc(height * row_stride, 1);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
446 if (!vomng.canvas) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
447 mp_msg(MSGT_VO, MSGL_ERR, "vomng: out of memory\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
448 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
449 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
450 /* fill in filter IDs for rows */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
451 for (y = 0; y < height; y++)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
452 *(vomng.canvas + row_stride * y) = MNG_FILTER_NONE;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
453
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
454 /* we are initialized */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
455 vomng.is_init = 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
456
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
457 return 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
458 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
459
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
460 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
461 * @brief draw on screen display (unsupported for MNG vo module)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
462 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
463 static void draw_osd(void)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
464 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
465 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
466
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
467 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
468 * @brief display data currently on canvas
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
469 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
470 static void flip_page(void)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
471 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
472 unsigned int last_ms;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
473 struct vomng_frame *frame;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
474
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
475 /* get time of last frame in ms
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
476 (intensive testing showed that the time obtained from vo_pts
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
477 is the time of the previous frame) */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
478 last_ms = (unsigned int)(vo_pts / 90.0 + 0.5);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
479
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
480 /* set time of last frame */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
481 if (vomng.frame_last)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
482 vomng.frame_last->time_ms = last_ms;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
483
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
484 /* create new frame */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
485 frame = calloc(1, sizeof(*frame));
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
486 if (!frame) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
487 mp_msg(MSGT_VO, MSGL_ERR, "vomng: out of memory\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
488 return;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
489 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
490 /* time of frame is not yet known (see comment about vo_pts about 20
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
491 lines above), approximate time using time of last frame and the
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
492 default frame delay */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
493 frame->time_ms = last_ms + VOMNG_DEFAULT_DELAY_MS;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
494 frame->next = NULL;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
495
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
496 /* compress canvas data */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
497 vomng_canvas_to_compressed(vomng.width, vomng.height, vomng.canvas,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
498 &frame->data, &frame->len);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
499 if (!frame->data) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
500 mp_msg(MSGT_VO, MSGL_ERR, "vomng: compressing frame failed\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
501 free(frame);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
502 return;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
503 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
504
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
505 /* add frame to list */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
506 if (!vomng.frame_first || !vomng.frame_last) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
507 vomng.frame_first = frame;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
508 vomng.frame_last = frame;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
509 } else {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
510 vomng.frame_last->next = frame;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
511 vomng.frame_last = frame;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
512 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
513 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
514
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
515 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
516 * @brief put frame data onto canvas (not supported)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
517 * @return always 1 to indicate error
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
518 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
519 static int draw_frame(uint8_t *src[])
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
520 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
521 /* draw_frame() not supported
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
522 * VFCAP_ACCEPT_STRIDE is set for format
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
523 * so draw_slice() will be called instead of this function */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
524 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
525 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
526
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
527 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
528 * @brief deinitialize MNG vo module
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
529 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
530 static void uninit(void)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
531 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
532 vomng_prop_cleanup();
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
533 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
534
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
535 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
536 * @brief deal with events (not supported)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
537 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
538 static void check_events(void)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
539 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
540 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
541
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
542 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
543 * @brief put a slice of frame data onto canvas
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
544 * @param[in] srcimg pointer to data
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
545 * @param[in] stride line stride in data
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
546 * @param[in] wf frame slice width
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
547 * @param[in] hf frame slice height
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
548 * @param[in] xf leftmost x coordinate of frame slice
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
549 * @param[in] yf topmost y coordinate of frame slice
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
550 * @return always 0 to indicate success
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
551 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
552 static int draw_slice(uint8_t *srcimg[], int stride[],
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
553 int wf, int hf, int xf, int yf)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
554 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
555 uint8_t *line_ptr;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
556 int line_len, row_stride, y;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
557
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
558 /* put pixel data from slice to canvas */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
559 line_ptr = srcimg[0];
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
560 line_len = stride[0];
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
561 row_stride = 1 + vomng.width * 3; /* rows contain filter IDs */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
562 for (y = 0; y < hf; y++)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
563 memcpy(vomng.canvas + (yf + y) * row_stride + 1 + xf * 3,
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
564 line_ptr + y * line_len, wf * 3);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
565
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
566 return 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
567 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
568
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
569 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
570 * @brief pre-initialize MNG vo module
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
571 * @param[in] *arg arguments passed to MNG vo module (output file name)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
572 * @return 0 on success, 1 on error
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
573 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
574 static int preinit(const char *arg)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
575 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
576 /* get name of output file */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
577 if (!arg || !*arg) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
578 mp_msg(MSGT_VO, MSGL_ERR, "vomng: MNG output file must be given,"
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
579 " example: -vo mng:output.mng\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
580 vomng_prop_cleanup();
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
581 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
582 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
583 vomng.out_file_name = strdup(arg);
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
584 if (!vomng.out_file_name) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
585 mp_msg(MSGT_VO, MSGL_ERR, "vomng: out of memory\n");
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
586 vomng_prop_cleanup();
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
587 return 1;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
588 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
589
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
590 return 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
591 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
592
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
593 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
594 * @brief get supported formats
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
595 * @param[in] format format to check support for
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
596 * @return acceptance flags
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
597 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
598 static int query_format(uint32_t format)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
599 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
600 if (format == IMGFMT_RGB24)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
601 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW |
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
602 VFCAP_ACCEPT_STRIDE;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
603 return 0;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
604 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
605
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
606 /**
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
607 * @brief handle control stuff
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
608 * @param[in] request control request
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
609 * @param[in] *data data (dependent on control request)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
610 * @return response to control request
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
611 */
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
612 static int control(uint32_t request, void *data)
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
613 {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
614 switch (request) {
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
615 case VOCTRL_QUERY_FORMAT:
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
616 return query_format(*((uint32_t *)data));
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
617 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
618 return VO_NOTIMPL;
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
619 }
2672587086ad Add MNG output support.
cboesch
parents:
diff changeset
620