typo fixes
[mplayer/greg.git] / libvo / vo_md5sum.c
blobfec9209ee4ba6099a0598f3521dcf45bd55ce5c2
1 /* ------------------------------------------------------------------------- */
3 /*
4 * vo_md5sum.c, md5sum Video Output Driver for MPlayer
6 *
7 * Written by Ivo van Poorten. (C) Copyright 2004, 2005.
8 * Licensed under GNU General Public License version 2.
11 * Changelog
13 * 2005-01-16 Replaced suboption parser by call to subopt-helper.
14 * 2004-09-16 Second draft. It now acts on VOCTRL_DRAW_IMAGE and does not
15 * maintain a local copy of the image if the format is YV12.
16 * Speed improvement and uses less memory.
17 * 2004-09-13 First draft.
21 /* ------------------------------------------------------------------------- */
23 /* Global Includes */
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <errno.h>
30 /* ------------------------------------------------------------------------- */
32 /* Local Includes */
34 #include "config.h"
35 #include "subopt-helper.h"
36 #include "mp_msg.h"
37 #include "video_out.h"
38 #include "video_out_internal.h"
39 #include "mplayer.h" /* for exit_player() */
40 #include "help_mp.h"
41 #include "md5sum.h"
43 /* ------------------------------------------------------------------------- */
45 /* Defines */
47 /* Used for temporary buffers to store file- and pathnames */
48 #define BUFLENGTH 512
50 /* ------------------------------------------------------------------------- */
52 /* Info */
54 static vo_info_t info=
56 "md5sum of each frame",
57 "md5sum",
58 "Ivo van Poorten (ivop@euronet.nl)",
62 LIBVO_EXTERN (md5sum)
64 /* ------------------------------------------------------------------------- */
66 /* Global Variables */
68 char *md5sum_outfile = NULL;
70 FILE *md5sum_fd;
71 int framenum = 0;
73 /* ------------------------------------------------------------------------- */
75 /** \brief An error occured while writing to a file.
77 * The program failed to write data to a file.
78 * It displays a message and exits the player.
80 * \return nothing It does not return.
83 void md5sum_write_error(void) {
84 mp_msg(MSGT_VO, MSGL_ERR, MSGTR_ErrorWritingFile, info.short_name);
85 exit_player(MSGTR_Exit_error);
88 /* ------------------------------------------------------------------------- */
90 /** \brief Pre-initialisation.
92 * This function is called before initialising the video output driver. It
93 * parses all suboptions and sets variables accordingly. If an error occurs
94 * (like an option being out of range, not having any value or an unknown
95 * option is stumbled upon) the player will exit. It also sets default
96 * values if necessary.
98 * \param arg A string containing all the suboptions passed to the video
99 * output driver.
101 * \return 0 All went well.
104 static int preinit(const char *arg)
106 opt_t subopts[] = {
107 {"outfile", OPT_ARG_MSTRZ, &md5sum_outfile, NULL, 0},
108 {NULL, 0, NULL, NULL, 0}
111 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
112 MSGTR_VO_ParsingSuboptions);
114 md5sum_outfile = strdup("md5sums");
115 if (subopt_parse(arg, subopts) != 0) {
116 return -1;
119 mp_msg(MSGT_VO, MSGL_V, "%s: outfile --> %s\n", info.short_name,
120 md5sum_outfile);
122 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
123 MSGTR_VO_SuboptionsParsedOK);
124 return 0;
127 /* ------------------------------------------------------------------------- */
129 /** \brief Configure the video output driver.
131 * This functions configures the video output driver. It opens the output
132 * file to which this driver will write all the MD5 sums. If something
133 * goes wrong, the player will exit.
135 * \return 0 All went well.
138 static int config(uint32_t width, uint32_t height, uint32_t d_width,
139 uint32_t d_height, uint32_t flags, char *title,
140 uint32_t format)
142 if (vo_config_count > 0 ) { /* Already configured */
143 return 0;
146 if ( (md5sum_fd = fopen(md5sum_outfile, "w") ) == NULL ) {
147 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s\n", info.short_name,
148 MSGTR_VO_CantCreateFile);
149 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n",
150 info.short_name, MSGTR_VO_GenericError, strerror(errno) );
151 exit_player(MSGTR_Exit_error);
154 return 0;
157 /* ------------------------------------------------------------------------- */
159 /** \brief Write MD5 sum to output file.
161 * This function writes an ASCII representation of a 16-byte hexadecimal
162 * MD5 sum to our output file. The file descriptor is a global variable.
164 * \param md5sum Sixteen bytes that represent an MD5 sum.
166 * \return None The player will exit if a write error occurs.
169 static void md5sum_output_sum(unsigned char *md5sum) {
170 int i;
172 for(i=0; i<16; i++) {
173 if ( fprintf(md5sum_fd, "%02x", md5sum[i]) < 0 ) md5sum_write_error();
175 if ( fprintf(md5sum_fd, " frame%08d\n", framenum) < 0 )
176 md5sum_write_error();
178 framenum++;
181 /* ------------------------------------------------------------------------- */
183 static int draw_frame(uint8_t *src[])
185 mp_msg(MSGT_VO, MSGL_V, "%s: draw_frame() is called!\n", info.short_name);
186 return -1;
189 /* ------------------------------------------------------------------------- */
191 static uint32_t draw_image(mp_image_t *mpi)
193 unsigned char md5sum[16];
194 uint32_t w = mpi->w;
195 uint32_t h = mpi->h;
196 uint8_t *rgbimage = mpi->planes[0];
197 uint8_t *planeY = mpi->planes[0];
198 uint8_t *planeU = mpi->planes[1];
199 uint8_t *planeV = mpi->planes[2];
200 uint32_t strideY = mpi->stride[0];
201 uint32_t strideU = mpi->stride[1];
202 uint32_t strideV = mpi->stride[2];
204 auth_md5Ctx md5_context;
205 unsigned int i;
207 if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Planar */
208 if (mpi->flags & MP_IMGFLAG_YUV) { /* Planar YUV */
209 auth_md5InitCtx(&md5_context);
210 for (i=0; i<h; i++) {
211 auth_md5SumCtx(&md5_context, planeY + i * strideY, w);
213 w = w / 2;
214 h = h / 2;
215 for (i=0; i<h; i++) {
216 auth_md5SumCtx(&md5_context, planeU + i * strideU, w);
217 auth_md5SumCtx(&md5_context, planeV + i * strideV, w);
219 auth_md5CloseCtx(&md5_context, md5sum);
220 md5sum_output_sum(md5sum);
221 return VO_TRUE;
222 } else { /* Planar RGB */
223 return VO_FALSE;
225 } else { /* Packed */
226 if (mpi->flags & MP_IMGFLAG_YUV) { /* Packed YUV */
228 return VO_FALSE;
229 } else { /* Packed RGB */
230 auth_md5Sum(md5sum, rgbimage, mpi->w * (mpi->bpp >> 3) * mpi->h);
231 md5sum_output_sum(md5sum);
232 return VO_TRUE;
236 return VO_FALSE;
239 /* ------------------------------------------------------------------------- */
241 static int draw_slice(uint8_t *src[], int stride[], int w, int h,
242 int x, int y)
244 return 0;
247 /* ------------------------------------------------------------------------- */
249 static int query_format(uint32_t format)
251 switch (format) {
252 case IMGFMT_RGB24:
253 case IMGFMT_YV12:
254 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
255 default:
256 return 0;
260 /* ------------------------------------------------------------------------- */
262 static int control(uint32_t request, void *data, ...)
264 switch (request) {
265 case VOCTRL_QUERY_FORMAT:
266 return query_format(*((uint32_t*)data));
267 case VOCTRL_DRAW_IMAGE:
268 return draw_image(data);
270 return VO_NOTIMPL;
273 /* ------------------------------------------------------------------------- */
275 static void uninit(void)
277 if (md5sum_outfile) {
278 free(md5sum_outfile);
279 md5sum_outfile = NULL;
281 if (md5sum_fd) fclose(md5sum_fd);
284 /* ------------------------------------------------------------------------- */
286 static void check_events(void)
290 /* ------------------------------------------------------------------------- */
292 static void draw_osd(void)
296 /* ------------------------------------------------------------------------- */
298 static void flip_page (void)
302 /* ------------------------------------------------------------------------- */
304 #undef BUFLENGTH
305 #undef MD5SUM_RGB_MODE
306 #undef MD5SUM_YUV_MODE
308 /* ------------------------------------------------------------------------- */