annotate libvo/vo_mng.c @ 36813:c3809c28a4e0

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