Add explanatory comments to the #endif part of multiple inclusion guards.
[mplayer/greg.git] / libvo / vo_md5sum.c
blobdacce83f36d3678f819f1518ca0b2571db642ee0
1 /* ------------------------------------------------------------------------- */
3 /*
4 * vo_md5sum.c, md5sum Video Output Driver for MPlayer
6 * Written by Ivo van Poorten. (C) Copyright 2004, 2005, 2006.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 /* ------------------------------------------------------------------------- */
26 /* Global Includes */
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <errno.h>
33 /* ------------------------------------------------------------------------- */
35 /* Local Includes */
37 #include "config.h"
38 #include "subopt-helper.h"
39 #include "mp_msg.h"
40 #include "video_out.h"
41 #include "video_out_internal.h"
42 #include "mplayer.h" /* for exit_player() */
43 #include "help_mp.h"
44 #ifdef USE_LIBAVUTIL_SO
45 #include "ffmpeg/md5.h"
46 #else
47 #include "libavutil/md5.h"
48 #endif
50 /* ------------------------------------------------------------------------- */
52 /* Defines */
54 /* Used for temporary buffers to store file- and pathnames */
55 #define BUFLENGTH 512
57 /* ------------------------------------------------------------------------- */
59 /* Info */
61 static const vo_info_t info=
63 "md5sum of each frame",
64 "md5sum",
65 "Ivo van Poorten (ivop@euronet.nl)",
69 const LIBVO_EXTERN (md5sum)
71 /* ------------------------------------------------------------------------- */
73 /* Global Variables */
75 char *md5sum_outfile = NULL;
77 FILE *md5sum_fd;
78 int framenum = 0;
80 /* ------------------------------------------------------------------------- */
82 /** \brief An error occured while writing to a file.
84 * The program failed to write data to a file.
85 * It displays a message and exits the player.
87 * \return nothing It does not return.
90 static void md5sum_write_error(void) {
91 mp_msg(MSGT_VO, MSGL_ERR, MSGTR_ErrorWritingFile, info.short_name);
92 exit_player(MSGTR_Exit_error);
95 /* ------------------------------------------------------------------------- */
97 /** \brief Pre-initialisation.
99 * This function is called before initialising the video output driver. It
100 * parses all suboptions and sets variables accordingly. If an error occurs
101 * (like an option being out of range, not having any value or an unknown
102 * option is stumbled upon) the player will exit. It also sets default
103 * values if necessary.
105 * \param arg A string containing all the suboptions passed to the video
106 * output driver.
108 * \return 0 All went well.
111 static int preinit(const char *arg)
113 opt_t subopts[] = {
114 {"outfile", OPT_ARG_MSTRZ, &md5sum_outfile, NULL, 0},
115 {NULL, 0, NULL, NULL, 0}
118 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
119 MSGTR_VO_ParsingSuboptions);
121 md5sum_outfile = strdup("md5sums");
122 if (subopt_parse(arg, subopts) != 0) {
123 return -1;
126 mp_msg(MSGT_VO, MSGL_V, "%s: outfile --> %s\n", info.short_name,
127 md5sum_outfile);
129 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
130 MSGTR_VO_SuboptionsParsedOK);
131 return 0;
134 /* ------------------------------------------------------------------------- */
136 /** \brief Configure the video output driver.
138 * This functions configures the video output driver. It opens the output
139 * file to which this driver will write all the MD5 sums. If something
140 * goes wrong, the player will exit.
142 * \return 0 All went well.
145 static int config(uint32_t width, uint32_t height, uint32_t d_width,
146 uint32_t d_height, uint32_t flags, char *title,
147 uint32_t format)
149 if (vo_config_count > 0 ) { /* Already configured */
150 return 0;
153 if ( (md5sum_fd = fopen(md5sum_outfile, "w") ) == NULL ) {
154 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s\n", info.short_name,
155 MSGTR_VO_CantCreateFile);
156 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n",
157 info.short_name, MSGTR_VO_GenericError, strerror(errno) );
158 exit_player(MSGTR_Exit_error);
161 return 0;
164 /* ------------------------------------------------------------------------- */
166 /** \brief Write MD5 sum to output file.
168 * This function writes an ASCII representation of a 16-byte hexadecimal
169 * MD5 sum to our output file. The file descriptor is a global variable.
171 * \param md5sum Sixteen bytes that represent an MD5 sum.
173 * \return None The player will exit if a write error occurs.
176 static void md5sum_output_sum(unsigned char *md5sum) {
177 int i;
179 for(i=0; i<16; i++) {
180 if ( fprintf(md5sum_fd, "%02x", md5sum[i]) < 0 ) md5sum_write_error();
182 if ( fprintf(md5sum_fd, " frame%08d\n", framenum) < 0 )
183 md5sum_write_error();
185 framenum++;
188 /* ------------------------------------------------------------------------- */
190 static int draw_frame(uint8_t *src[])
192 mp_msg(MSGT_VO, MSGL_V, "%s: draw_frame() is called!\n", info.short_name);
193 return -1;
196 /* ------------------------------------------------------------------------- */
198 static uint32_t draw_image(mp_image_t *mpi)
200 unsigned char md5sum[16];
201 uint32_t w = mpi->w;
202 uint32_t h = mpi->h;
203 uint8_t *rgbimage = mpi->planes[0];
204 uint8_t *planeY = mpi->planes[0];
205 uint8_t *planeU = mpi->planes[1];
206 uint8_t *planeV = mpi->planes[2];
207 uint32_t strideY = mpi->stride[0];
208 uint32_t strideU = mpi->stride[1];
209 uint32_t strideV = mpi->stride[2];
211 uint8_t md5_context_memory[av_md5_size];
212 struct AVMD5 *md5_context = (struct AVMD5*) md5_context_memory;
213 unsigned int i;
215 if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Planar */
216 if (mpi->flags & MP_IMGFLAG_YUV) { /* Planar YUV */
217 av_md5_init(md5_context);
218 for (i=0; i<h; i++) {
219 av_md5_update(md5_context, planeY + i * strideY, w);
221 w = w / 2;
222 h = h / 2;
223 for (i=0; i<h; i++) {
224 av_md5_update(md5_context, planeU + i * strideU, w);
225 av_md5_update(md5_context, planeV + i * strideV, w);
227 av_md5_final(md5_context, md5sum);
228 md5sum_output_sum(md5sum);
229 return VO_TRUE;
230 } else { /* Planar RGB */
231 return VO_FALSE;
233 } else { /* Packed */
234 if (mpi->flags & MP_IMGFLAG_YUV) { /* Packed YUV */
236 return VO_FALSE;
237 } else { /* Packed RGB */
238 av_md5_sum(md5sum, rgbimage, mpi->w * (mpi->bpp >> 3) * mpi->h);
239 md5sum_output_sum(md5sum);
240 return VO_TRUE;
244 return VO_FALSE;
247 /* ------------------------------------------------------------------------- */
249 static int draw_slice(uint8_t *src[], int stride[], int w, int h,
250 int x, int y)
252 return 0;
255 /* ------------------------------------------------------------------------- */
257 static int query_format(uint32_t format)
259 switch (format) {
260 case IMGFMT_RGB24:
261 case IMGFMT_YV12:
262 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
263 default:
264 return 0;
268 /* ------------------------------------------------------------------------- */
270 static int control(uint32_t request, void *data, ...)
272 switch (request) {
273 case VOCTRL_QUERY_FORMAT:
274 return query_format(*((uint32_t*)data));
275 case VOCTRL_DRAW_IMAGE:
276 return draw_image(data);
278 return VO_NOTIMPL;
281 /* ------------------------------------------------------------------------- */
283 static void uninit(void)
285 if (md5sum_outfile) {
286 free(md5sum_outfile);
287 md5sum_outfile = NULL;
289 if (md5sum_fd) fclose(md5sum_fd);
292 /* ------------------------------------------------------------------------- */
294 static void check_events(void)
298 /* ------------------------------------------------------------------------- */
300 static void draw_osd(void)
304 /* ------------------------------------------------------------------------- */
306 static void flip_page (void)
310 /* ------------------------------------------------------------------------- */
312 #undef BUFLENGTH
313 #undef MD5SUM_RGB_MODE
314 #undef MD5SUM_YUV_MODE
316 /* ------------------------------------------------------------------------- */