1 /* ------------------------------------------------------------------------- */
4 * vo_md5sum.c, md5sum Video Output Driver for MPlayer
7 * Written by Ivo van Poorten. (C) Copyright 2004, 2005.
8 * Licensed under GNU General Public License version 2.
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 /* ------------------------------------------------------------------------- */
30 /* ------------------------------------------------------------------------- */
35 #include "subopt-helper.h"
37 #include "video_out.h"
38 #include "video_out_internal.h"
39 #include "mplayer.h" /* for exit_player() */
43 /* ------------------------------------------------------------------------- */
47 /* Used for temporary buffers to store file- and pathnames */
50 /* ------------------------------------------------------------------------- */
54 static vo_info_t info
=
56 "md5sum of each frame",
58 "Ivo van Poorten (ivop@euronet.nl)",
64 /* ------------------------------------------------------------------------- */
66 /* Global Variables */
68 char *md5sum_outfile
= NULL
;
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
101 * \return 0 All went well.
104 static int preinit(const char *arg
)
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) {
119 mp_msg(MSGT_VO
, MSGL_V
, "%s: outfile --> %s\n", info
.short_name
,
122 mp_msg(MSGT_VO
, MSGL_INFO
, "%s: %s\n", info
.short_name
,
123 MSGTR_VO_SuboptionsParsedOK
);
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
,
142 if (vo_config_count
> 0 ) { /* Already configured */
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
);
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
) {
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();
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
);
189 /* ------------------------------------------------------------------------- */
191 static uint32_t draw_image(mp_image_t
*mpi
)
193 unsigned char md5sum
[16];
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
;
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
);
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
);
222 } else { /* Planar RGB */
225 } else { /* Packed */
226 if (mpi
->flags
& MP_IMGFLAG_YUV
) { /* Packed YUV */
229 } else { /* Packed RGB */
230 auth_md5Sum(md5sum
, rgbimage
, mpi
->w
* (mpi
->bpp
>> 3) * mpi
->h
);
231 md5sum_output_sum(md5sum
);
239 /* ------------------------------------------------------------------------- */
241 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
,
247 /* ------------------------------------------------------------------------- */
249 static int query_format(uint32_t format
)
254 return VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
;
260 /* ------------------------------------------------------------------------- */
262 static int control(uint32_t request
, void *data
, ...)
265 case VOCTRL_QUERY_FORMAT
:
266 return query_format(*((uint32_t*)data
));
267 case VOCTRL_DRAW_IMAGE
:
268 return draw_image(data
);
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 /* ------------------------------------------------------------------------- */
305 #undef MD5SUM_RGB_MODE
306 #undef MD5SUM_YUV_MODE
308 /* ------------------------------------------------------------------------- */