font_load_ft.c: fix possible crash with recent Fontconfig
[mplayer.git] / libvo / vo_md5sum.c
blobdc3487ef3b501d386c339766e0b258a4b537d852
1 /* ------------------------------------------------------------------------- */
3 /*
4 * md5sum video output driver
6 * Copyright (C) 2004, 2005, 2006 Ivo van Poorten
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 /* ------------------------------------------------------------------------- */
27 /* Global Includes */
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <errno.h>
34 /* ------------------------------------------------------------------------- */
36 /* Local Includes */
38 #include "config.h"
39 #include "subopt-helper.h"
40 #include "mp_msg.h"
41 #include "video_out.h"
42 #include "video_out_internal.h"
43 #include "mplayer.h" /* for exit_player_bad() */
44 #include "libavutil/md5.h"
46 /* ------------------------------------------------------------------------- */
48 /* Info */
50 static const vo_info_t info=
52 "md5sum of each frame",
53 "md5sum",
54 "Ivo van Poorten (ivop@euronet.nl)",
58 const LIBVO_EXTERN (md5sum)
60 /* ------------------------------------------------------------------------- */
62 /* Global Variables */
64 char *md5sum_outfile = NULL;
66 FILE *md5sum_fd;
67 int framenum = 0;
69 /* ------------------------------------------------------------------------- */
71 /** \brief An error occured while writing to a file.
73 * The program failed to write data to a file.
74 * It displays a message and exits the player.
76 * \return nothing It does not return.
79 static void md5sum_write_error(void) {
80 mp_tmsg(MSGT_VO, MSGL_ERR, "%s: Error writing file.\n", info.short_name);
81 exit_player_bad(_("Fatal error"));
84 /* ------------------------------------------------------------------------- */
86 /** \brief Pre-initialisation.
88 * This function is called before initialising the video output driver. It
89 * parses all suboptions and sets variables accordingly. If an error occurs
90 * (like an option being out of range, not having any value or an unknown
91 * option is stumbled upon) the player will exit. It also sets default
92 * values if necessary.
94 * \param arg A string containing all the suboptions passed to the video
95 * output driver.
97 * \return 0 All went well.
100 static int preinit(const char *arg)
102 const opt_t subopts[] = {
103 {"outfile", OPT_ARG_MSTRZ, &md5sum_outfile, NULL},
104 {NULL, 0, NULL, NULL}
107 mp_msg(MSGT_VO, MSGL_V, "%s: %s\n", info.short_name,
108 "Parsing suboptions.");
110 md5sum_outfile = strdup("md5sums");
111 if (subopt_parse(arg, subopts) != 0) {
112 return -1;
115 mp_msg(MSGT_VO, MSGL_V, "%s: outfile --> %s\n", info.short_name,
116 md5sum_outfile);
118 mp_msg(MSGT_VO, MSGL_V, "%s: %s\n", info.short_name,
119 "Suboptions parsed OK.");
120 return 0;
123 /* ------------------------------------------------------------------------- */
125 /** \brief Configure the video output driver.
127 * This functions configures the video output driver. It opens the output
128 * file to which this driver will write all the MD5 sums. If something
129 * goes wrong, the player will exit.
131 * \return 0 All went well.
134 static int config(uint32_t width, uint32_t height, uint32_t d_width,
135 uint32_t d_height, uint32_t flags, char *title,
136 uint32_t format)
138 if (vo_config_count > 0 ) { /* Already configured */
139 return 0;
142 if ( (md5sum_fd = fopen(md5sum_outfile, "w") ) == NULL ) {
143 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s\n", info.short_name,
144 _("Unable to create output file."));
145 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n",
146 info.short_name, _("This error has occurred"), strerror(errno) );
147 exit_player_bad(_("Fatal error"));
150 return 0;
153 /* ------------------------------------------------------------------------- */
155 /** \brief Write MD5 sum to output file.
157 * This function writes an ASCII representation of a 16-byte hexadecimal
158 * MD5 sum to our output file. The file descriptor is a global variable.
160 * \param md5sum Sixteen bytes that represent an MD5 sum.
162 * \return None The player will exit if a write error occurs.
165 static void md5sum_output_sum(unsigned char *md5sum) {
166 int i;
168 for(i=0; i<16; i++) {
169 if ( fprintf(md5sum_fd, "%02x", md5sum[i]) < 0 ) md5sum_write_error();
171 if ( fprintf(md5sum_fd, " frame%08d\n", framenum) < 0 )
172 md5sum_write_error();
174 framenum++;
177 /* ------------------------------------------------------------------------- */
179 static int draw_frame(uint8_t *src[])
181 mp_msg(MSGT_VO, MSGL_V, "%s: draw_frame() is called!\n", info.short_name);
182 return -1;
185 /* ------------------------------------------------------------------------- */
187 static uint32_t draw_image(mp_image_t *mpi)
189 unsigned char md5sum[16];
190 uint32_t w = mpi->w;
191 uint32_t h = mpi->h;
192 uint8_t *rgbimage = mpi->planes[0];
193 uint8_t *planeY = mpi->planes[0];
194 uint8_t *planeU = mpi->planes[1];
195 uint8_t *planeV = mpi->planes[2];
196 uint32_t strideY = mpi->stride[0];
197 uint32_t strideU = mpi->stride[1];
198 uint32_t strideV = mpi->stride[2];
200 uint8_t md5_context_memory[av_md5_size];
201 struct AVMD5 *md5_context = (struct AVMD5*) md5_context_memory;
202 unsigned int i;
204 if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Planar */
205 if (mpi->flags & MP_IMGFLAG_YUV) { /* Planar YUV */
206 av_md5_init(md5_context);
207 for (i=0; i<h; i++) {
208 av_md5_update(md5_context, planeY + i * strideY, w);
210 w = w / 2;
211 h = h / 2;
212 for (i=0; i<h; i++) {
213 av_md5_update(md5_context, planeU + i * strideU, w);
215 for (i=0; i<h; i++) {
216 av_md5_update(md5_context, planeV + i * strideV, w);
218 av_md5_final(md5_context, md5sum);
219 md5sum_output_sum(md5sum);
220 return VO_TRUE;
221 } else { /* Planar RGB */
222 return VO_FALSE;
224 } else { /* Packed */
225 if (mpi->flags & MP_IMGFLAG_YUV) { /* Packed YUV */
227 return VO_FALSE;
228 } else { /* Packed RGB */
229 av_md5_sum(md5sum, rgbimage, mpi->w * (mpi->bpp >> 3) * mpi->h);
230 md5sum_output_sum(md5sum);
231 return VO_TRUE;
235 return VO_FALSE;
238 /* ------------------------------------------------------------------------- */
240 static int draw_slice(uint8_t *src[], int stride[], int w, int h,
241 int x, int y)
243 return 0;
246 /* ------------------------------------------------------------------------- */
248 static int query_format(uint32_t format)
250 switch (format) {
251 case IMGFMT_RGB24:
252 case IMGFMT_YV12:
253 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
254 default:
255 return 0;
259 /* ------------------------------------------------------------------------- */
261 static int control(uint32_t request, void *data)
263 switch (request) {
264 case VOCTRL_QUERY_FORMAT:
265 return query_format(*((uint32_t*)data));
266 case VOCTRL_DRAW_IMAGE:
267 return draw_image(data);
269 return VO_NOTIMPL;
272 /* ------------------------------------------------------------------------- */
274 static void uninit(void)
276 free(md5sum_outfile);
277 md5sum_outfile = NULL;
278 if (md5sum_fd) fclose(md5sum_fd);
281 /* ------------------------------------------------------------------------- */
283 static void check_events(void)
287 /* ------------------------------------------------------------------------- */
289 static void draw_osd(void)
293 /* ------------------------------------------------------------------------- */
295 static void flip_page (void)