annotate libvo/vo_mng.c @ 34697:ac6b38cd0d45

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