Merge svn changes up to r30463
[mplayer/kovensky.git] / libvo / vo_md5sum.c
blobb279ea5ad659f24629ca4ae493d8cb246a88639a
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 "help_mp.h"
45 #include "libavutil/md5.h"
47 /* ------------------------------------------------------------------------- */
49 /* Defines */
51 /* Used for temporary buffers to store file- and pathnames */
52 #define BUFLENGTH 512
54 /* ------------------------------------------------------------------------- */
56 /* Info */
58 static const vo_info_t info=
60 "md5sum of each frame",
61 "md5sum",
62 "Ivo van Poorten (ivop@euronet.nl)",
66 const LIBVO_EXTERN (md5sum)
68 /* ------------------------------------------------------------------------- */
70 /* Global Variables */
72 char *md5sum_outfile = NULL;
74 FILE *md5sum_fd;
75 int framenum = 0;
77 /* ------------------------------------------------------------------------- */
79 /** \brief An error occured while writing to a file.
81 * The program failed to write data to a file.
82 * It displays a message and exits the player.
84 * \return nothing It does not return.
87 static void md5sum_write_error(void) {
88 mp_tmsg(MSGT_VO, MSGL_ERR, "%s: Error writing file.\n", info.short_name);
89 exit_player_bad(_("Fatal error"));
92 /* ------------------------------------------------------------------------- */
94 /** \brief Pre-initialisation.
96 * This function is called before initialising the video output driver. It
97 * parses all suboptions and sets variables accordingly. If an error occurs
98 * (like an option being out of range, not having any value or an unknown
99 * option is stumbled upon) the player will exit. It also sets default
100 * values if necessary.
102 * \param arg A string containing all the suboptions passed to the video
103 * output driver.
105 * \return 0 All went well.
108 static int preinit(const char *arg)
110 const opt_t subopts[] = {
111 {"outfile", OPT_ARG_MSTRZ, &md5sum_outfile, NULL},
112 {NULL, 0, NULL, NULL}
115 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
116 _("Parsing suboptions."));
118 md5sum_outfile = strdup("md5sums");
119 if (subopt_parse(arg, subopts) != 0) {
120 return -1;
123 mp_msg(MSGT_VO, MSGL_V, "%s: outfile --> %s\n", info.short_name,
124 md5sum_outfile);
126 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
127 _("Suboptions parsed OK."));
128 return 0;
131 /* ------------------------------------------------------------------------- */
133 /** \brief Configure the video output driver.
135 * This functions configures the video output driver. It opens the output
136 * file to which this driver will write all the MD5 sums. If something
137 * goes wrong, the player will exit.
139 * \return 0 All went well.
142 static int config(uint32_t width, uint32_t height, uint32_t d_width,
143 uint32_t d_height, uint32_t flags, char *title,
144 uint32_t format)
146 if (vo_config_count > 0 ) { /* Already configured */
147 return 0;
150 if ( (md5sum_fd = fopen(md5sum_outfile, "w") ) == NULL ) {
151 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s\n", info.short_name,
152 _("Unable to create output file."));
153 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n",
154 info.short_name, _("This error has occurred"), strerror(errno) );
155 exit_player_bad(_("Fatal error"));
158 return 0;
161 /* ------------------------------------------------------------------------- */
163 /** \brief Write MD5 sum to output file.
165 * This function writes an ASCII representation of a 16-byte hexadecimal
166 * MD5 sum to our output file. The file descriptor is a global variable.
168 * \param md5sum Sixteen bytes that represent an MD5 sum.
170 * \return None The player will exit if a write error occurs.
173 static void md5sum_output_sum(unsigned char *md5sum) {
174 int i;
176 for(i=0; i<16; i++) {
177 if ( fprintf(md5sum_fd, "%02x", md5sum[i]) < 0 ) md5sum_write_error();
179 if ( fprintf(md5sum_fd, " frame%08d\n", framenum) < 0 )
180 md5sum_write_error();
182 framenum++;
185 /* ------------------------------------------------------------------------- */
187 static int draw_frame(uint8_t *src[])
189 mp_msg(MSGT_VO, MSGL_V, "%s: draw_frame() is called!\n", info.short_name);
190 return -1;
193 /* ------------------------------------------------------------------------- */
195 static uint32_t draw_image(mp_image_t *mpi)
197 unsigned char md5sum[16];
198 uint32_t w = mpi->w;
199 uint32_t h = mpi->h;
200 uint8_t *rgbimage = mpi->planes[0];
201 uint8_t *planeY = mpi->planes[0];
202 uint8_t *planeU = mpi->planes[1];
203 uint8_t *planeV = mpi->planes[2];
204 uint32_t strideY = mpi->stride[0];
205 uint32_t strideU = mpi->stride[1];
206 uint32_t strideV = mpi->stride[2];
208 uint8_t md5_context_memory[av_md5_size];
209 struct AVMD5 *md5_context = (struct AVMD5*) md5_context_memory;
210 unsigned int i;
212 if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Planar */
213 if (mpi->flags & MP_IMGFLAG_YUV) { /* Planar YUV */
214 av_md5_init(md5_context);
215 for (i=0; i<h; i++) {
216 av_md5_update(md5_context, planeY + i * strideY, w);
218 w = w / 2;
219 h = h / 2;
220 for (i=0; i<h; i++) {
221 av_md5_update(md5_context, planeU + i * strideU, w);
222 av_md5_update(md5_context, planeV + i * strideV, w);
224 av_md5_final(md5_context, md5sum);
225 md5sum_output_sum(md5sum);
226 return VO_TRUE;
227 } else { /* Planar RGB */
228 return VO_FALSE;
230 } else { /* Packed */
231 if (mpi->flags & MP_IMGFLAG_YUV) { /* Packed YUV */
233 return VO_FALSE;
234 } else { /* Packed RGB */
235 av_md5_sum(md5sum, rgbimage, mpi->w * (mpi->bpp >> 3) * mpi->h);
236 md5sum_output_sum(md5sum);
237 return VO_TRUE;
241 return VO_FALSE;
244 /* ------------------------------------------------------------------------- */
246 static int draw_slice(uint8_t *src[], int stride[], int w, int h,
247 int x, int y)
249 return 0;
252 /* ------------------------------------------------------------------------- */
254 static int query_format(uint32_t format)
256 switch (format) {
257 case IMGFMT_RGB24:
258 case IMGFMT_YV12:
259 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
260 default:
261 return 0;
265 /* ------------------------------------------------------------------------- */
267 static int control(uint32_t request, void *data)
269 switch (request) {
270 case VOCTRL_QUERY_FORMAT:
271 return query_format(*((uint32_t*)data));
272 case VOCTRL_DRAW_IMAGE:
273 return draw_image(data);
275 return VO_NOTIMPL;
278 /* ------------------------------------------------------------------------- */
280 static void uninit(void)
282 if (md5sum_outfile) {
283 free(md5sum_outfile);
284 md5sum_outfile = NULL;
286 if (md5sum_fd) fclose(md5sum_fd);
289 /* ------------------------------------------------------------------------- */
291 static void check_events(void)
295 /* ------------------------------------------------------------------------- */
297 static void draw_osd(void)
301 /* ------------------------------------------------------------------------- */
303 static void flip_page (void)
307 /* ------------------------------------------------------------------------- */
309 #undef BUFLENGTH
310 #undef MD5SUM_RGB_MODE
311 #undef MD5SUM_YUV_MODE
313 /* ------------------------------------------------------------------------- */