1 /* ------------------------------------------------------------------------- */
4 * md5sum video output driver
6 * Copyright (C) 2004, 2005, 2006 Ivo van Poorten
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 /* ------------------------------------------------------------------------- */
34 /* ------------------------------------------------------------------------- */
39 #include "subopt-helper.h"
41 #include "video_out.h"
42 #include "video_out_internal.h"
43 #include "mplayer.h" /* for exit_player_bad() */
44 #include "libavutil/md5.h"
46 /* ------------------------------------------------------------------------- */
50 /* Used for temporary buffers to store file- and pathnames */
53 /* ------------------------------------------------------------------------- */
57 static const vo_info_t info
=
59 "md5sum of each frame",
61 "Ivo van Poorten (ivop@euronet.nl)",
65 const LIBVO_EXTERN (md5sum
)
67 /* ------------------------------------------------------------------------- */
69 /* Global Variables */
71 char *md5sum_outfile
= NULL
;
76 /* ------------------------------------------------------------------------- */
78 /** \brief An error occured while writing to a file.
80 * The program failed to write data to a file.
81 * It displays a message and exits the player.
83 * \return nothing It does not return.
86 static void md5sum_write_error(void) {
87 mp_tmsg(MSGT_VO
, MSGL_ERR
, "%s: Error writing file.\n", info
.short_name
);
88 exit_player_bad(_("Fatal error"));
91 /* ------------------------------------------------------------------------- */
93 /** \brief Pre-initialisation.
95 * This function is called before initialising the video output driver. It
96 * parses all suboptions and sets variables accordingly. If an error occurs
97 * (like an option being out of range, not having any value or an unknown
98 * option is stumbled upon) the player will exit. It also sets default
99 * values if necessary.
101 * \param arg A string containing all the suboptions passed to the video
104 * \return 0 All went well.
107 static int preinit(const char *arg
)
109 const opt_t subopts
[] = {
110 {"outfile", OPT_ARG_MSTRZ
, &md5sum_outfile
, NULL
},
111 {NULL
, 0, NULL
, NULL
}
114 mp_msg(MSGT_VO
, MSGL_V
, "%s: %s\n", info
.short_name
,
115 "Parsing suboptions.");
117 md5sum_outfile
= strdup("md5sums");
118 if (subopt_parse(arg
, subopts
) != 0) {
122 mp_msg(MSGT_VO
, MSGL_V
, "%s: outfile --> %s\n", info
.short_name
,
125 mp_msg(MSGT_VO
, MSGL_V
, "%s: %s\n", info
.short_name
,
126 "Suboptions parsed OK.");
130 /* ------------------------------------------------------------------------- */
132 /** \brief Configure the video output driver.
134 * This functions configures the video output driver. It opens the output
135 * file to which this driver will write all the MD5 sums. If something
136 * goes wrong, the player will exit.
138 * \return 0 All went well.
141 static int config(uint32_t width
, uint32_t height
, uint32_t d_width
,
142 uint32_t d_height
, uint32_t flags
, char *title
,
145 if (vo_config_count
> 0 ) { /* Already configured */
149 if ( (md5sum_fd
= fopen(md5sum_outfile
, "w") ) == NULL
) {
150 mp_msg(MSGT_VO
, MSGL_ERR
, "\n%s: %s\n", info
.short_name
,
151 _("Unable to create output file."));
152 mp_msg(MSGT_VO
, MSGL_ERR
, "%s: %s: %s\n",
153 info
.short_name
, _("This error has occurred"), strerror(errno
) );
154 exit_player_bad(_("Fatal error"));
160 /* ------------------------------------------------------------------------- */
162 /** \brief Write MD5 sum to output file.
164 * This function writes an ASCII representation of a 16-byte hexadecimal
165 * MD5 sum to our output file. The file descriptor is a global variable.
167 * \param md5sum Sixteen bytes that represent an MD5 sum.
169 * \return None The player will exit if a write error occurs.
172 static void md5sum_output_sum(unsigned char *md5sum
) {
175 for(i
=0; i
<16; i
++) {
176 if ( fprintf(md5sum_fd
, "%02x", md5sum
[i
]) < 0 ) md5sum_write_error();
178 if ( fprintf(md5sum_fd
, " frame%08d\n", framenum
) < 0 )
179 md5sum_write_error();
184 /* ------------------------------------------------------------------------- */
186 static int draw_frame(uint8_t *src
[])
188 mp_msg(MSGT_VO
, MSGL_V
, "%s: draw_frame() is called!\n", info
.short_name
);
192 /* ------------------------------------------------------------------------- */
194 static uint32_t draw_image(mp_image_t
*mpi
)
196 unsigned char md5sum
[16];
199 uint8_t *rgbimage
= mpi
->planes
[0];
200 uint8_t *planeY
= mpi
->planes
[0];
201 uint8_t *planeU
= mpi
->planes
[1];
202 uint8_t *planeV
= mpi
->planes
[2];
203 uint32_t strideY
= mpi
->stride
[0];
204 uint32_t strideU
= mpi
->stride
[1];
205 uint32_t strideV
= mpi
->stride
[2];
207 uint8_t md5_context_memory
[av_md5_size
];
208 struct AVMD5
*md5_context
= (struct AVMD5
*) md5_context_memory
;
211 if (mpi
->flags
& MP_IMGFLAG_PLANAR
) { /* Planar */
212 if (mpi
->flags
& MP_IMGFLAG_YUV
) { /* Planar YUV */
213 av_md5_init(md5_context
);
214 for (i
=0; i
<h
; i
++) {
215 av_md5_update(md5_context
, planeY
+ i
* strideY
, w
);
219 for (i
=0; i
<h
; i
++) {
220 av_md5_update(md5_context
, planeU
+ i
* strideU
, w
);
222 for (i
=0; i
<h
; i
++) {
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 /* ------------------------------------------------------------------------- */