Prefer DMO Windows Media codecs over the DShow ones. They are considerably
[mplayer/greg.git] / libvo / vo_md5sum.c
blob317f3384f04020420abb45847e4770477595b39f
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 * 2006-07-02 Removed imported md5sum code and rely on libavutil now
14 * 2005-01-16 Replaced suboption parser by call to subopt-helper.
15 * 2004-09-16 Second draft. It now acts on VOCTRL_DRAW_IMAGE and does not
16 * maintain a local copy of the image if the format is YV12.
17 * Speed improvement and uses less memory.
18 * 2004-09-13 First draft.
22 /* ------------------------------------------------------------------------- */
24 /* Global Includes */
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <errno.h>
31 /* ------------------------------------------------------------------------- */
33 /* Local Includes */
35 #include "config.h"
36 #include "subopt-helper.h"
37 #include "mp_msg.h"
38 #include "video_out.h"
39 #include "video_out_internal.h"
40 #include "mplayer.h" /* for exit_player() */
41 #include "help_mp.h"
42 #ifdef USE_LIBAVUTIL_SO
43 #include "ffmpeg/md5.h"
44 #else
45 #include "libavutil/md5.h"
46 #endif
48 /* ------------------------------------------------------------------------- */
50 /* Defines */
52 /* Used for temporary buffers to store file- and pathnames */
53 #define BUFLENGTH 512
55 /* ------------------------------------------------------------------------- */
57 /* Info */
59 static vo_info_t info=
61 "md5sum of each frame",
62 "md5sum",
63 "Ivo van Poorten (ivop@euronet.nl)",
67 LIBVO_EXTERN (md5sum)
69 /* ------------------------------------------------------------------------- */
71 /* Global Variables */
73 char *md5sum_outfile = NULL;
75 FILE *md5sum_fd;
76 int framenum = 0;
78 /* ------------------------------------------------------------------------- */
80 /** \brief An error occured while writing to a file.
82 * The program failed to write data to a file.
83 * It displays a message and exits the player.
85 * \return nothing It does not return.
88 static void md5sum_write_error(void) {
89 mp_msg(MSGT_VO, MSGL_ERR, MSGTR_ErrorWritingFile, info.short_name);
90 exit_player(MSGTR_Exit_error);
93 /* ------------------------------------------------------------------------- */
95 /** \brief Pre-initialisation.
97 * This function is called before initialising the video output driver. It
98 * parses all suboptions and sets variables accordingly. If an error occurs
99 * (like an option being out of range, not having any value or an unknown
100 * option is stumbled upon) the player will exit. It also sets default
101 * values if necessary.
103 * \param arg A string containing all the suboptions passed to the video
104 * output driver.
106 * \return 0 All went well.
109 static int preinit(const char *arg)
111 opt_t subopts[] = {
112 {"outfile", OPT_ARG_MSTRZ, &md5sum_outfile, NULL, 0},
113 {NULL, 0, NULL, NULL, 0}
116 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
117 MSGTR_VO_ParsingSuboptions);
119 md5sum_outfile = strdup("md5sums");
120 if (subopt_parse(arg, subopts) != 0) {
121 return -1;
124 mp_msg(MSGT_VO, MSGL_V, "%s: outfile --> %s\n", info.short_name,
125 md5sum_outfile);
127 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
128 MSGTR_VO_SuboptionsParsedOK);
129 return 0;
132 /* ------------------------------------------------------------------------- */
134 /** \brief Configure the video output driver.
136 * This functions configures the video output driver. It opens the output
137 * file to which this driver will write all the MD5 sums. If something
138 * goes wrong, the player will exit.
140 * \return 0 All went well.
143 static int config(uint32_t width, uint32_t height, uint32_t d_width,
144 uint32_t d_height, uint32_t flags, char *title,
145 uint32_t format)
147 if (vo_config_count > 0 ) { /* Already configured */
148 return 0;
151 if ( (md5sum_fd = fopen(md5sum_outfile, "w") ) == NULL ) {
152 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s\n", info.short_name,
153 MSGTR_VO_CantCreateFile);
154 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n",
155 info.short_name, MSGTR_VO_GenericError, strerror(errno) );
156 exit_player(MSGTR_Exit_error);
159 return 0;
162 /* ------------------------------------------------------------------------- */
164 /** \brief Write MD5 sum to output file.
166 * This function writes an ASCII representation of a 16-byte hexadecimal
167 * MD5 sum to our output file. The file descriptor is a global variable.
169 * \param md5sum Sixteen bytes that represent an MD5 sum.
171 * \return None The player will exit if a write error occurs.
174 static void md5sum_output_sum(unsigned char *md5sum) {
175 int i;
177 for(i=0; i<16; i++) {
178 if ( fprintf(md5sum_fd, "%02x", md5sum[i]) < 0 ) md5sum_write_error();
180 if ( fprintf(md5sum_fd, " frame%08d\n", framenum) < 0 )
181 md5sum_write_error();
183 framenum++;
186 /* ------------------------------------------------------------------------- */
188 static int draw_frame(uint8_t *src[])
190 mp_msg(MSGT_VO, MSGL_V, "%s: draw_frame() is called!\n", info.short_name);
191 return -1;
194 /* ------------------------------------------------------------------------- */
196 static uint32_t draw_image(mp_image_t *mpi)
198 unsigned char md5sum[16];
199 uint32_t w = mpi->w;
200 uint32_t h = mpi->h;
201 uint8_t *rgbimage = mpi->planes[0];
202 uint8_t *planeY = mpi->planes[0];
203 uint8_t *planeU = mpi->planes[1];
204 uint8_t *planeV = mpi->planes[2];
205 uint32_t strideY = mpi->stride[0];
206 uint32_t strideU = mpi->stride[1];
207 uint32_t strideV = mpi->stride[2];
209 uint8_t md5_context_memory[av_md5_size];
210 struct AVMD5 *md5_context = (struct AVMD5*) md5_context_memory;
211 unsigned int i;
213 if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Planar */
214 if (mpi->flags & MP_IMGFLAG_YUV) { /* Planar YUV */
215 av_md5_init(md5_context);
216 for (i=0; i<h; i++) {
217 av_md5_update(md5_context, planeY + i * strideY, w);
219 w = w / 2;
220 h = h / 2;
221 for (i=0; i<h; i++) {
222 av_md5_update(md5_context, planeU + i * strideU, w);
223 av_md5_update(md5_context, planeV + i * strideV, w);
225 av_md5_final(md5_context, md5sum);
226 md5sum_output_sum(md5sum);
227 return VO_TRUE;
228 } else { /* Planar RGB */
229 return VO_FALSE;
231 } else { /* Packed */
232 if (mpi->flags & MP_IMGFLAG_YUV) { /* Packed YUV */
234 return VO_FALSE;
235 } else { /* Packed RGB */
236 av_md5_sum(md5sum, rgbimage, mpi->w * (mpi->bpp >> 3) * mpi->h);
237 md5sum_output_sum(md5sum);
238 return VO_TRUE;
242 return VO_FALSE;
245 /* ------------------------------------------------------------------------- */
247 static int draw_slice(uint8_t *src[], int stride[], int w, int h,
248 int x, int y)
250 return 0;
253 /* ------------------------------------------------------------------------- */
255 static int query_format(uint32_t format)
257 switch (format) {
258 case IMGFMT_RGB24:
259 case IMGFMT_YV12:
260 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
261 default:
262 return 0;
266 /* ------------------------------------------------------------------------- */
268 static int control(uint32_t request, void *data, ...)
270 switch (request) {
271 case VOCTRL_QUERY_FORMAT:
272 return query_format(*((uint32_t*)data));
273 case VOCTRL_DRAW_IMAGE:
274 return draw_image(data);
276 return VO_NOTIMPL;
279 /* ------------------------------------------------------------------------- */
281 static void uninit(void)
283 if (md5sum_outfile) {
284 free(md5sum_outfile);
285 md5sum_outfile = NULL;
287 if (md5sum_fd) fclose(md5sum_fd);
290 /* ------------------------------------------------------------------------- */
292 static void check_events(void)
296 /* ------------------------------------------------------------------------- */
298 static void draw_osd(void)
302 /* ------------------------------------------------------------------------- */
304 static void flip_page (void)
308 /* ------------------------------------------------------------------------- */
310 #undef BUFLENGTH
311 #undef MD5SUM_RGB_MODE
312 #undef MD5SUM_YUV_MODE
314 /* ------------------------------------------------------------------------- */