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 * 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 /* ------------------------------------------------------------------------- */
31 /* ------------------------------------------------------------------------- */
36 #include "subopt-helper.h"
38 #include "video_out.h"
39 #include "video_out_internal.h"
40 #include "mplayer.h" /* for exit_player() */
42 #ifdef USE_LIBAVUTIL_SO
43 #include "ffmpeg/md5.h"
45 #include "libavutil/md5.h"
48 /* ------------------------------------------------------------------------- */
52 /* Used for temporary buffers to store file- and pathnames */
55 /* ------------------------------------------------------------------------- */
59 static vo_info_t info
=
61 "md5sum of each frame",
63 "Ivo van Poorten (ivop@euronet.nl)",
69 /* ------------------------------------------------------------------------- */
71 /* Global Variables */
73 char *md5sum_outfile
= NULL
;
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
106 * \return 0 All went well.
109 static int preinit(const char *arg
)
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) {
124 mp_msg(MSGT_VO
, MSGL_V
, "%s: outfile --> %s\n", info
.short_name
,
127 mp_msg(MSGT_VO
, MSGL_INFO
, "%s: %s\n", info
.short_name
,
128 MSGTR_VO_SuboptionsParsedOK
);
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
,
147 if (vo_config_count
> 0 ) { /* Already configured */
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
);
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
) {
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();
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
);
194 /* ------------------------------------------------------------------------- */
196 static uint32_t draw_image(mp_image_t
*mpi
)
198 unsigned char md5sum
[16];
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
;
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
);
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
);
228 } else { /* Planar RGB */
231 } else { /* Packed */
232 if (mpi
->flags
& MP_IMGFLAG_YUV
) { /* Packed YUV */
235 } else { /* Packed RGB */
236 av_md5_sum(md5sum
, rgbimage
, mpi
->w
* (mpi
->bpp
>> 3) * mpi
->h
);
237 md5sum_output_sum(md5sum
);
245 /* ------------------------------------------------------------------------- */
247 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
,
253 /* ------------------------------------------------------------------------- */
255 static int query_format(uint32_t format
)
260 return VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
;
266 /* ------------------------------------------------------------------------- */
268 static int control(uint32_t request
, void *data
, ...)
271 case VOCTRL_QUERY_FORMAT
:
272 return query_format(*((uint32_t*)data
));
273 case VOCTRL_DRAW_IMAGE
:
274 return draw_image(data
);
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 /* ------------------------------------------------------------------------- */
311 #undef MD5SUM_RGB_MODE
312 #undef MD5SUM_YUV_MODE
314 /* ------------------------------------------------------------------------- */